removed extract(). enhanced parameter parsing.

This commit is contained in:
messju
2003-12-19 17:20:19 +00:00
parent f6bb3389f6
commit 36ac900ceb
3 changed files with 164 additions and 99 deletions

View File

@@ -29,53 +29,75 @@
*/ */
function smarty_block_textformat($params, $content, &$smarty) function smarty_block_textformat($params, $content, &$smarty)
{ {
$style = null; if (is_null($content)) {
$indent = 0; return;
$indent_first = 0; }
$indent_char = ' ';
$wrap = 80;
$wrap_char = "\n";
$wrap_cut = false;
$assign = null;
if($content == null) { $style = null;
return true; $indent = 0;
} $indent_first = 0;
$indent_char = ' ';
$wrap = 80;
$wrap_char = "\n";
$wrap_cut = false;
$assign = null;
extract($params); foreach ($params as $_key => $_val) {
switch ($_key) {
case 'style':
case 'indent_char':
case 'wrap_char':
case 'assign':
$$_key = (string)$_val;
break;
if($style == 'email') { case 'indent':
$wrap = 72; case 'indent_first':
} case 'wrap':
$$_key = (int)$_val;
break;
// split into paragraphs case 'wrap_cut':
$paragraphs = preg_split('![\r\n][\r\n]!',$content); $$_key = (bool)$_val;
$output = ''; break;
foreach($paragraphs as $paragraph) { default:
if($paragraph == '') { $smarty->trigger_error("textformat: unknown attribute '$_key'");
continue; }
} }
// convert mult. spaces & special chars to single space
$paragraph = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'),array(' ',''),$paragraph);
// indent first line
if($indent_first > 0) {
$paragraph = str_repeat($indent_char,$indent_first) . $paragraph;
}
// wordwrap sentences
$paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
// indent lines
if($indent > 0) {
$paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph);
}
$output .= $paragraph . $wrap_char . $wrap_char;
}
if($assign != null) { if ($style == 'email') {
$smarty->assign($assign,$output); $wrap = 72;
} else { }
return $output;
} // split into paragraphs
$paragraphs = preg_split('![\r\n][\r\n]!',$content);
$output = '';
foreach ($paragraphs as $paragraph) {
if ($paragraph == '') {
continue;
}
// convert mult. spaces & special chars to single space
$paragraph = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'),array(' ',''),$paragraph);
// indent first line
if($indent_first > 0) {
$paragraph = str_repeat($indent_char,$indent_first) . $paragraph;
}
// wordwrap sentences
$paragraph = wordwrap($paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
// indent lines
if($indent > 0) {
$paragraph = preg_replace('!^!m',str_repeat($indent_char,$indent),$paragraph);
}
$output .= $paragraph . $wrap_char . $wrap_char;
}
if ($assign) {
$smarty->assign($assign,$output);
} else {
return $output;
}
} }
/* vim: set expandtab: */ /* vim: set expandtab: */

View File

@@ -53,13 +53,33 @@ function smarty_function_html_table($params, &$smarty)
$hdir = 'right'; $hdir = 'right';
$inner = 'cols'; $inner = 'cols';
extract($params); if (!isset($params['loop'])) {
if (!isset($loop)) {
$smarty->trigger_error("html_table: missing 'loop' parameter"); $smarty->trigger_error("html_table: missing 'loop' parameter");
return; return;
} }
foreach ($params as $_key=>$_value) {
switch ($_key) {
case 'loop':
$$_key = (array)$_value;
break;
case 'cols':
case 'rows':
$$_key = (int)$_value;
break;
case 'table_attr':
case 'tr_attr':
case 'td_attr':
case 'trailpad':
case 'hdir':
case 'vdir':
$$_key = (string)$_value;
break;
}
}
$loop_count = count($loop); $loop_count = count($loop);
if (empty($params['rows'])) { if (empty($params['rows'])) {
/* no rows specified */ /* no rows specified */

View File

@@ -20,7 +20,77 @@
*/ */
function smarty_function_popup($params, &$smarty) function smarty_function_popup($params, &$smarty)
{ {
extract($params); $append = '';
foreach ($params as $_key=>$_value) {
switch ($_key) {
case 'text':
case 'trigger':
$$_key = (string)$_value;
break;
case 'caption':
case 'closetext':
case 'status':
$append .= ',' . strtoupper($_key) . "','" . str_replace("'","\'",$_value) . "'";
break;
case 'fgcolor':
case 'bgcolor':
case 'textcolor':
case 'capcolor':
case 'closecolor':
case 'textfont':
case 'captionfont':
case 'closefont':
case 'textsize':
case 'captionsize':
case 'closesize':
case 'width':
case 'height':
case 'border':
case 'offsetx':
case 'offsety':
case 'fgbackground':
case 'bgbackground':
case 'inarray':
case 'caparray':
case 'capicon':
case 'snapx':
case 'snapy':
case 'fixx':
case 'fixy':
case 'background':
case 'padx':
case 'pady':
case 'frame':
case 'timeout':
case 'delay':
$append .= ',' . strtoupper($_key) . "','$_value'";
break;
case 'sticky':
case 'left':
case 'right':
case 'center':
case 'above':
case 'below':
case 'noclose':
case 'autostatus':
case 'autostatuscap':
case 'fullhtml':
case 'hauto':
case 'vauto':
if ($_value) $append .= ',' . strtoupper($_key);
break;
case 'function':
$append .= ',' . strtoupper($_key) . "',$_value";
break;
default:
$smarty->trigger_error("[popup] unknown parameter $_key", E_USER_WARNING);
}
}
if (empty($text) && !isset($inarray) && empty($function)) { if (empty($text) && !isset($inarray) && empty($function)) {
$smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required"); $smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required");
@@ -30,56 +100,9 @@ function smarty_function_popup($params, &$smarty)
if (empty($trigger)) { $trigger = "onmouseover"; } if (empty($trigger)) { $trigger = "onmouseover"; }
$retval = $trigger . '="return overlib(\''.preg_replace(array("!'!","![\r\n]!"),array("\'",'\r'),$text).'\''; $retval = $trigger . '="return overlib(\''.preg_replace(array("!'!","![\r\n]!"),array("\'",'\r'),$text).'\'';
if ($sticky) { $retval .= ",STICKY"; } $retval .= $append . ');" onmouseout="nd();"';
if (!empty($caption)) { $retval .= ",CAPTION,'".str_replace("'","\'",$caption)."'"; }
if (!empty($fgcolor)) { $retval .= ",FGCOLOR,'$fgcolor'"; }
if (!empty($bgcolor)) { $retval .= ",BGCOLOR,'$bgcolor'"; }
if (!empty($textcolor)) { $retval .= ",TEXTCOLOR,'$textcolor'"; }
if (!empty($capcolor)) { $retval .= ",CAPCOLOR,'$capcolor'"; }
if (!empty($closecolor)) { $retval .= ",CLOSECOLOR,'$closecolor'"; }
if (!empty($textfont)) { $retval .= ",TEXTFONT,'$textfont'"; }
if (!empty($captionfont)) { $retval .= ",CAPTIONFONT,'$captionfont'"; }
if (!empty($closefont)) { $retval .= ",CLOSEFONT,'$closefont'"; }
if (!empty($textsize)) { $retval .= ",TEXTSIZE,$textsize"; }
if (!empty($captionsize)) { $retval .= ",CAPTIONSIZE,$captionsize"; }
if (!empty($closesize)) { $retval .= ",CLOSESIZE,$closesize"; }
if (!empty($width)) { $retval .= ",WIDTH,$width"; }
if (!empty($height)) { $retval .= ",HEIGHT,$height"; }
if (!empty($left)) { $retval .= ",LEFT"; }
if (!empty($right)) { $retval .= ",RIGHT"; }
if (!empty($center)) { $retval .= ",CENTER"; }
if (!empty($above)) { $retval .= ",ABOVE"; }
if (!empty($below)) { $retval .= ",BELOW"; }
if (isset($border)) { $retval .= ",BORDER,$border"; }
if (isset($offsetx)) { $retval .= ",OFFSETX,$offsetx"; }
if (isset($offsety)) { $retval .= ",OFFSETY,$offsety"; }
if (!empty($fgbackground)) { $retval .= ",FGBACKGROUND,'$fgbackground'"; }
if (!empty($bgbackground)) { $retval .= ",BGBACKGROUND,'$bgbackground'"; }
if (!empty($closetext)) { $retval .= ",CLOSETEXT,'".str_replace("'","\'",$closetext)."'"; }
if (!empty($noclose)) { $retval .= ",NOCLOSE"; }
if (!empty($status)) { $retval .= ",STATUS,'".str_replace("'","\'",$status)."'"; }
if (!empty($autostatus)) { $retval .= ",AUTOSTATUS"; }
if (!empty($autostatuscap)) { $retval .= ",AUTOSTATUSCAP"; }
if (isset($inarray)) { $retval .= ",INARRAY,'$inarray'"; }
if (isset($caparray)) { $retval .= ",CAPARRAY,'$caparray'"; }
if (!empty($capicon)) { $retval .= ",CAPICON,'$capicon'"; }
if (!empty($snapx)) { $retval .= ",SNAPX,$snapx"; }
if (!empty($snapy)) { $retval .= ",SNAPY,$snapy"; }
if (isset($fixx)) { $retval .= ",FIXX,$fixx"; }
if (isset($fixy)) { $retval .= ",FIXY,$fixy"; }
if (!empty($background)) { $retval .= ",BACKGROUND,'$background'"; }
if (!empty($padx)) { $retval .= ",PADX,$padx"; }
if (!empty($pady)) { $retval .= ",PADY,$pady"; }
if (!empty($fullhtml)) { $retval .= ",FULLHTML"; }
if (!empty($frame)) { $retval .= ",FRAME,'$frame'"; }
if (isset($timeout)) { $retval .= ",TIMEOUT,$timeout"; }
if (!empty($function)) { $retval .= ",FUNCTION,'$function'"; }
if (isset($delay)) { $retval .= ",DELAY,$delay"; }
if (!empty($hauto)) { $retval .= ",HAUTO"; }
if (!empty($vauto)) { $retval .= ",VAUTO"; }
$retval .= ');" onmouseout="nd();"';
return $retval; return $retval;
} }
/* vim: set expandtab: */ /* vim: set expandtab: */