diff options
author | emkael <emkael@tlen.pl> | 2018-10-18 02:39:34 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-10-18 02:39:42 +0200 |
commit | ab5d8d4e07bb3c8230d0285ef8902ef1979fce51 (patch) | |
tree | 0b955e585cb2fdbc7207392a5f2c97d610b6a5bc /lib/smarty/plugins/function.html_table.php | |
parent | c055ce2ab60c6582bad3e5babcb1d00384fde78a (diff) |
Updating Smarty
Diffstat (limited to 'lib/smarty/plugins/function.html_table.php')
-rw-r--r-- | lib/smarty/plugins/function.html_table.php | 85 |
1 files changed, 36 insertions, 49 deletions
diff --git a/lib/smarty/plugins/function.html_table.php b/lib/smarty/plugins/function.html_table.php index 6b9cb9d..ae61e83 100644 --- a/lib/smarty/plugins/function.html_table.php +++ b/lib/smarty/plugins/function.html_table.php @@ -2,19 +2,17 @@ /** * Smarty plugin * - * @package Smarty + * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_table} function plugin - * - * Type: function<br> - * Name: html_table<br> - * Date: Feb 17, 2003<br> - * Purpose: make an html table from an array of data<br> + * Type: function + * Name: html_table + * Date: Feb 17, 2003 + * Purpose: make an html table from an array of data * Params: - * <pre> + * * - loop - array to loop through * - cols - number of columns, comma separated list of column names * or array of column names @@ -29,25 +27,25 @@ * - 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) - * </pre> + * * Examples: - * <pre> + * * {table loop=$data} * {table loop=$data cols=4 tr_attr='"bgcolor=red"'} * {table loop=$data cols="first,second,third" tr_attr=$colors} - * </pre> * - * @author Monte Ohrt <monte at ohrt dot com> - * @author credit to Messju Mohr <messju at lammfellpuschen dot de> - * @author credit to boots <boots dot smarty at yahoo dot com> + * @author Monte Ohrt <monte at ohrt dot com> + * @author credit to Messju Mohr <messju at lammfellpuschen dot de> + * @author credit to boots <boots dot smarty at yahoo dot com> * @version 1.1 - * @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table} - * (Smarty online manual) - * @param array $params parameters - * @param Smarty_Internal_Template $template template object + * @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table} + * (Smarty online manual) + * + * @param array $params parameters + * * @return string */ -function smarty_function_html_table($params, $template) +function smarty_function_html_table($params) { $table_attr = 'border="1"'; $tr_attr = ''; @@ -61,18 +59,15 @@ function smarty_function_html_table($params, $template) $inner = 'cols'; $caption = ''; $loop = null; - - if (!isset($params['loop'])) { - trigger_error("html_table: missing 'loop' parameter",E_USER_WARNING); + 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; break; - case 'cols': if (is_array($_value) && !empty($_value)) { $cols = $_value; @@ -86,11 +81,9 @@ function smarty_function_html_table($params, $template) $cols_count = $cols; } break; - case 'rows': $$_key = (int)$_value; break; - case 'table_attr': case 'trailpad': case 'hdir': @@ -99,7 +92,6 @@ function smarty_function_html_table($params, $template) case 'caption': $$_key = (string)$_value; break; - case 'tr_attr': case 'td_attr': case 'th_attr': @@ -107,50 +99,42 @@ function smarty_function_html_table($params, $template) break; } } - $loop_count = count($loop); - if (empty($params['rows'])) { + if (empty($params[ 'rows' ])) { /* no rows specified */ $rows = ceil($loop_count / $cols_count); - } elseif (empty($params['cols'])) { - if (!empty($params['rows'])) { + } elseif (empty($params[ 'cols' ])) { + if (!empty($params[ 'rows' ])) { /* no cols specified, but rows */ $cols_count = ceil($loop_count / $rows); } } - $output = "<table $table_attr>\n"; - if (!empty($caption)) { $output .= '<caption>' . $caption . "</caption>\n"; } - if (is_array($cols)) { - $cols = ($hdir == 'right') ? $cols : array_reverse($cols); + $cols = ($hdir === 'right') ? $cols : array_reverse($cols); $output .= "<thead><tr>\n"; - for ($r = 0; $r < $cols_count; $r++) { $output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>'; - $output .= $cols[$r]; + $output .= $cols[ $r ]; $output .= "</th>\n"; } $output .= "</tr></thead>\n"; } - $output .= "<tbody>\n"; for ($r = 0; $r < $rows; $r++) { $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n"; - $rx = ($vdir == 'down') ? $r * $cols_count : ($rows-1 - $r) * $cols_count; - + $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') { + $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 .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n"; + $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[ $x ] . "</td>\n"; } else { $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n"; } @@ -159,19 +143,22 @@ function smarty_function_html_table($params, $template) } $output .= "</tbody>\n"; $output .= "</table>\n"; - return $output; } +/** + * @param $name + * @param $var + * @param $no + * + * @return string + */ function smarty_function_html_table_cycle($name, $var, $no) { if (!is_array($var)) { $ret = $var; } else { - $ret = $var[$no % count($var)]; + $ret = $var[ $no % count($var) ]; } - return ($ret) ? ' ' . $ret : ''; } - -?>
\ No newline at end of file |