cvs: smarty /libs/plugins block.textformat.php function.html_table.php function.popup.php

"Messju Mohr" <[email protected]>
Newsgroups gmane.comp.php.cvs.smarty
Message-ID <cvsmessju1071854419@cvsserver>
messju		Fri Dec 19 12:20:19 2003 EDT

  Modified files:              
    /smarty/libs/plugins	block.textformat.php function.html_table.php 
                        	function.popup.php 
  Log:
  removed extract(). enhanced parameter parsing.

-- 
Smarty CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
messju-20031219122019.txt (text/plain, 10.5 KB)
Index: smarty/libs/plugins/block.textformat.php
diff -u smarty/libs/plugins/block.textformat.php:1.6 smarty/libs/plugins/block.textformat.php:1.7
--- smarty/libs/plugins/block.textformat.php:1.6	Tue Jun 24 05:27:59 2003
+++ smarty/libs/plugins/block.textformat.php	Fri Dec 19 12:20:19 2003
@@ -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($content == null) {
-		return true;
-	}
-
-    extract($params);
-
-	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 != null) {
-		$smarty->assign($assign,$output);
-	} else {
-		return $output;
-	}
+    if (is_null($content)) {
+        return;
+    }
+
+    $style = null;
+    $indent = 0;
+    $indent_first = 0;
+    $indent_char = ' ';
+    $wrap = 80;
+    $wrap_char = "\n";
+    $wrap_cut = false;
+    $assign = null;
+    
+    foreach ($params as $_key => $_val) {
+        switch ($_key) {
+            case 'style':
+            case 'indent_char':
+            case 'wrap_char':
+            case 'assign':
+                $$_key = (string)$_val;
+                break;
+
+            case 'indent':
+            case 'indent_first':
+            case 'wrap':
+                $$_key = (int)$_val;
+                break;
+
+            case 'wrap_cut':
+                $$_key = (bool)$_val;
+                break;
+
+            default:
+                $smarty->trigger_error("textformat: unknown attribute '$_key'");
+        }
+    }
+
+    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: */
Index: smarty/libs/plugins/function.html_table.php
diff -u smarty/libs/plugins/function.html_table.php:1.6 smarty/libs/plugins/function.html_table.php:1.7
--- smarty/libs/plugins/function.html_table.php:1.6	Fri Aug 29 04:51:25 2003
+++ smarty/libs/plugins/function.html_table.php	Fri Dec 19 12:20:19 2003
@@ -53,13 +53,33 @@
     $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 */
@@ -91,7 +111,7 @@
             }
         }
         $output .= "</tr>\n";
-    }            
+    }
     $output .= "</table>\n";
     
     return $output;
Index: smarty/libs/plugins/function.popup.php
diff -u smarty/libs/plugins/function.popup.php:1.9 smarty/libs/plugins/function.popup.php:1.10
--- smarty/libs/plugins/function.popup.php:1.9	Sun Apr 20 17:12:03 2003
+++ smarty/libs/plugins/function.popup.php	Fri Dec 19 12:20:19 2003
@@ -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 @@
     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();"';
-	
-	return $retval;
+    $retval .= $append . ');" onmouseout="nd();"';
+
+    return $retval;
 }
 
 /* vim: set expandtab: */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.