diff options
| author | uwetews <uwe.tews@googlemail.com> | 2018-08-19 02:35:46 +0200 |
|---|---|---|
| committer | uwetews <uwe.tews@googlemail.com> | 2018-08-19 02:35:46 +0200 |
| commit | 799b5cb3424f798f133839fbfdc09b613703cdfe (patch) | |
| tree | 2b721d5436da45c194f9dcdfd62f79265018d729 /libs/plugins/function.html_table.php | |
| parent | b5e5085391100f26656276e091a0b8034e9f13c9 (diff) | |
| download | smarty-799b5cb3424f798f133839fbfdc09b613703cdfe.tar.gz smarty-799b5cb3424f798f133839fbfdc09b613703cdfe.tar.bz2 smarty-799b5cb3424f798f133839fbfdc09b613703cdfe.zip | |
- fix PSR-2 coding standards and PHPDoc blocks https://github.com/smarty-php/smarty/pull/452
https://github.com/smarty-php/smarty/pull/475
https://github.com/smarty-php/smarty/pull/473
- bugfix PHP5.2 compatibility https://github.com/smarty-php/smarty/pull/472
Diffstat (limited to 'libs/plugins/function.html_table.php')
| -rw-r--r-- | libs/plugins/function.html_table.php | 89 |
1 files changed, 36 insertions, 53 deletions
diff --git a/libs/plugins/function.html_table.php b/libs/plugins/function.html_table.php index acd53d17..ae61e83d 100644 --- a/libs/plugins/function.html_table.php +++ b/libs/plugins/function.html_table.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_table} function plugin * Type: function @@ -60,54 +59,46 @@ 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; - break; - - case 'cols': - if (is_array($_value) && !empty($_value)) { - $cols = $_value; - $cols_count = count($_value); - } elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) { - $cols = explode(',', $_value); - $cols_count = count($cols); - } elseif (!empty($_value)) { - $cols_count = (int) $_value; - } else { - $cols_count = $cols; - } - break; - - case 'rows': - $$_key = (int) $_value; - break; - - case 'table_attr': - case 'trailpad': - case 'hdir': - case 'vdir': - case 'inner': - case 'caption': - $$_key = (string) $_value; - break; - - case 'tr_attr': - case 'td_attr': - case 'th_attr': - $$_key = $_value; - break; + case 'loop': + $$_key = (array)$_value; + break; + case 'cols': + if (is_array($_value) && !empty($_value)) { + $cols = $_value; + $cols_count = count($_value); + } elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) { + $cols = explode(',', $_value); + $cols_count = count($cols); + } elseif (!empty($_value)) { + $cols_count = (int)$_value; + } else { + $cols_count = $cols; + } + break; + case 'rows': + $$_key = (int)$_value; + break; + case 'table_attr': + case 'trailpad': + case 'hdir': + case 'vdir': + case 'inner': + case 'caption': + $$_key = (string)$_value; + break; + case 'tr_attr': + case 'td_attr': + case 'th_attr': + $$_key = $_value; + break; } } - $loop_count = count($loop); if (empty($params[ 'rows' ])) { /* no rows specified */ @@ -118,37 +109,30 @@ function smarty_function_html_table($params) $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); $output .= "<thead><tr>\n"; - - for ($r = 0; $r < $cols_count; $r ++) { + for ($r = 0; $r < $cols_count; $r++) { $output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>'; $output .= $cols[ $r ]; $output .= "</th>\n"; } $output .= "</tr></thead>\n"; } - $output .= "<tbody>\n"; - for ($r = 0; $r < $rows; $r ++) { + 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; - - for ($c = 0; $c < $cols_count; $c ++) { + 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 .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[ $x ] . "</td>\n"; } else { @@ -159,9 +143,9 @@ function smarty_function_html_table($params) } $output .= "</tbody>\n"; $output .= "</table>\n"; - return $output; } + /** * @param $name * @param $var @@ -176,6 +160,5 @@ function smarty_function_html_table_cycle($name, $var, $no) } else { $ret = $var[ $no % count($var) ]; } - return ($ret) ? ' ' . $ret : ''; } |
