mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
removed extract(). enhanced parameter parsing.
This commit is contained in:
@@ -29,53 +29,75 @@
|
||||
*/
|
||||
function smarty_block_textformat($params, $content, &$smarty)
|
||||
{
|
||||
$style = null;
|
||||
$indent = 0;
|
||||
$indent_first = 0;
|
||||
$indent_char = ' ';
|
||||
$wrap = 80;
|
||||
$wrap_char = "\n";
|
||||
$wrap_cut = false;
|
||||
$assign = null;
|
||||
if (is_null($content)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if($content == null) {
|
||||
return true;
|
||||
}
|
||||
$style = null;
|
||||
$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') {
|
||||
$wrap = 72;
|
||||
}
|
||||
case 'indent':
|
||||
case 'indent_first':
|
||||
case 'wrap':
|
||||
$$_key = (int)$_val;
|
||||
break;
|
||||
|
||||
// split into paragraphs
|
||||
$paragraphs = preg_split('![\r\n][\r\n]!',$content);
|
||||
$output = '';
|
||||
case 'wrap_cut':
|
||||
$$_key = (bool)$_val;
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
default:
|
||||
$smarty->trigger_error("textformat: unknown attribute '$_key'");
|
||||
}
|
||||
}
|
||||
|
||||
if($assign != null) {
|
||||
$smarty->assign($assign,$output);
|
||||
} else {
|
||||
return $output;
|
||||
}
|
||||
if ($style == 'email') {
|
||||
$wrap = 72;
|
||||
}
|
||||
|
||||
// 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: */
|
||||
|
@@ -53,13 +53,33 @@ function smarty_function_html_table($params, &$smarty)
|
||||
$hdir = 'right';
|
||||
$inner = 'cols';
|
||||
|
||||
extract($params);
|
||||
|
||||
if (!isset($loop)) {
|
||||
if (!isset($params['loop'])) {
|
||||
$smarty->trigger_error("html_table: missing 'loop' parameter");
|
||||
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);
|
||||
if (empty($params['rows'])) {
|
||||
/* no rows specified */
|
||||
|
@@ -20,7 +20,77 @@
|
||||
*/
|
||||
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)) {
|
||||
$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"; }
|
||||
|
||||
$retval = $trigger . '="return overlib(\''.preg_replace(array("!'!","![\r\n]!"),array("\'",'\r'),$text).'\'';
|
||||
if ($sticky) { $retval .= ",STICKY"; }
|
||||
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();"';
|
||||
$retval .= $append . ');" onmouseout="nd();"';
|
||||
|
||||
return $retval;
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
Reference in New Issue
Block a user