summaryrefslogtreecommitdiff
path: root/lib/smarty3/plugins/function.html_table.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-10-18 02:40:38 +0200
committeremkael <emkael@tlen.pl>2018-10-18 02:40:38 +0200
commiteab8a101e7a3fcbb41e01a574985e06c5a3775de (patch)
tree60f201da5984b0c3638d10da02bba42b61aa3177 /lib/smarty3/plugins/function.html_table.php
parent7f38be342c1495aeca418286c15c25c18ac9e142 (diff)
Updating Smarty
Diffstat (limited to 'lib/smarty3/plugins/function.html_table.php')
-rw-r--r--lib/smarty3/plugins/function.html_table.php72
1 files changed, 30 insertions, 42 deletions
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<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
@@ -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)
- * </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>
- * @version 1.1
- * @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table}
+ * @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
@@ -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 = "<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 ++) {
+ 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 ++) {
- $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 .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[ $x ] . "</td>\n";
} else {
@@ -160,10 +143,16 @@ function smarty_function_html_table($params)
}
$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)) {
@@ -171,6 +160,5 @@ function smarty_function_html_table_cycle($name, $var, $no)
} else {
$ret = $var[ $no % count($var) ];
}
-
return ($ret) ? ' ' . $ret : '';
}