diff --git a/includes/sys_template.php b/includes/sys_template.php index 829d45bc..bf2e7027 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -341,25 +341,30 @@ function page_with_title($title, $elements) { function table($columns, $rows_raw, $data = true) { // If only one column is given if (! is_array($columns)) { - $columns = [ - 'col' => $columns - ]; - $rows = []; - foreach ($rows_raw as $row) + foreach ($rows_raw as $row) { $rows[] = [ 'col' => $row ]; - } else { - $rows = $rows_raw; + } + return render_table([ + 'col' => $columns + ], $rows, $data); } + return render_table($columns, $rows_raw, $data); +} + +/** + * Helper for rendering a html-table. + * use table() + */ +function render_table($columns, $rows, $data = true) { if (count($rows) == 0) { return info(_("No data found."), true); } - $html = ""; - $html .= '
' . $column . ' | '; @@ -421,10 +426,11 @@ function template_render($file, $data) { engelsystem_error("Cannot find template file «" . $file . "»."); } -function shorten($str) { - if (strlen($str) < 50) +function shorten($str, $length = 50) { + if (strlen($str) < $length) { return $str; - return '' . substr($str, 0, 47) . '...'; + } + return '' . substr($str, 0, $length - 3) . '...'; } function table_body($array) {
---|