From eab8a101e7a3fcbb41e01a574985e06c5a3775de Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 18 Oct 2018 02:40:38 +0200 Subject: Updating Smarty --- lib/smarty3/plugins/function.html_table.php | 72 ++++++++++++----------------- 1 file changed, 30 insertions(+), 42 deletions(-) (limited to 'lib/smarty3/plugins/function.html_table.php') diff --git a/lib/smarty3/plugins/function.html_table.php b/lib/smarty3/plugins/function.html_table.php index 42e23e7..ae61e83 100644 --- a/lib/smarty3/plugins/function.html_table.php +++ b/lib/smarty3/plugins/function.html_table.php @@ -5,15 +5,14 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_table} function plugin - * Type: function
- * Name: html_table
- * Date: Feb 17, 2003
- * Purpose: make an html table from an array of data
+ * Type: function + * Name: html_table + * Date: Feb 17, 2003 + * Purpose: make an html table from an array of data * Params: - *
+ *
  * - loop       - array to loop through
  * - cols       - number of columns, comma separated list of column names
  *                or array of column names
@@ -28,19 +27,18 @@
  * - hdir       - horizontal direction (default: "right", means left-to-right)
  * - inner      - inner loop (default "cols": print $loop line by line,
  *                $loop will be printed column by column otherwise)
- * 
+ * * Examples: - *
+ *
  * {table loop=$data}
  * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
  * {table loop=$data cols="first,second,third" tr_attr=$colors}
- * 
* - * @author Monte Ohrt - * @author credit to Messju Mohr - * @author credit to boots - * @version 1.1 - * @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table} + * @author Monte Ohrt + * @author credit to Messju Mohr + * @author credit to boots + * @version 1.1 + * @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table} * (Smarty online manual) * * @param array $params parameters @@ -61,19 +59,15 @@ function smarty_function_html_table($params) $inner = 'cols'; $caption = ''; $loop = null; - if (!isset($params[ 'loop' ])) { trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING); - return; } - foreach ($params as $_key => $_value) { switch ($_key) { case 'loop': - $$_key = (array) $_value; + $$_key = (array)$_value; break; - case 'cols': if (is_array($_value) && !empty($_value)) { $cols = $_value; @@ -82,25 +76,22 @@ function smarty_function_html_table($params) $cols = explode(',', $_value); $cols_count = count($cols); } elseif (!empty($_value)) { - $cols_count = (int) $_value; + $cols_count = (int)$_value; } else { $cols_count = $cols; } break; - case 'rows': - $$_key = (int) $_value; + $$_key = (int)$_value; break; - case 'table_attr': case 'trailpad': case 'hdir': case 'vdir': case 'inner': case 'caption': - $$_key = (string) $_value; + $$_key = (string)$_value; break; - case 'tr_attr': case 'td_attr': case 'th_attr': @@ -108,7 +99,6 @@ function smarty_function_html_table($params) break; } } - $loop_count = count($loop); if (empty($params[ 'rows' ])) { /* no rows specified */ @@ -119,37 +109,30 @@ function smarty_function_html_table($params) $cols_count = ceil($loop_count / $rows); } } - $output = "\n"; - if (!empty($caption)) { $output .= '\n"; } - if (is_array($cols)) { - $cols = ($hdir == 'right') ? $cols : array_reverse($cols); + $cols = ($hdir === 'right') ? $cols : array_reverse($cols); $output .= "\n"; - - for ($r = 0; $r < $cols_count; $r ++) { + for ($r = 0; $r < $cols_count; $r++) { $output .= ''; $output .= $cols[ $r ]; $output .= "\n"; } $output .= "\n"; } - $output .= "\n"; - for ($r = 0; $r < $rows; $r ++) { + for ($r = 0; $r < $rows; $r++) { $output .= "\n"; - $rx = ($vdir == 'down') ? $r * $cols_count : ($rows - 1 - $r) * $cols_count; - - for ($c = 0; $c < $cols_count; $c ++) { - $x = ($hdir == 'right') ? $rx + $c : $rx + $cols_count - 1 - $c; - if ($inner != 'cols') { + $rx = ($vdir === 'down') ? $r * $cols_count : ($rows - 1 - $r) * $cols_count; + for ($c = 0; $c < $cols_count; $c++) { + $x = ($hdir === 'right') ? $rx + $c : $rx + $cols_count - 1 - $c; + if ($inner !== 'cols') { /* shuffle x to loop over rows*/ $x = floor($x / $cols_count) + ($x % $cols_count) * $rows; } - if ($x < $loop_count) { $output .= "" . $loop[ $x ] . "\n"; } else { @@ -160,10 +143,16 @@ function smarty_function_html_table($params) } $output .= "\n"; $output .= "
' . $caption . "
\n"; - return $output; } +/** + * @param $name + * @param $var + * @param $no + * + * @return string + */ function smarty_function_html_table_cycle($name, $var, $no) { if (!is_array($var)) { @@ -171,6 +160,5 @@ function smarty_function_html_table_cycle($name, $var, $no) } else { $ret = $var[ $no % count($var) ]; } - return ($ret) ? ' ' . $ret : ''; } -- cgit v1.2.3