diff options
Diffstat (limited to 'includes/sys_template.php')
-rw-r--r-- | includes/sys_template.php | 296 |
1 files changed, 160 insertions, 136 deletions
diff --git a/includes/sys_template.php b/includes/sys_template.php index 3679328b..059d3169 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -8,16 +8,17 @@ $themes = [ '3' => "Engelsystem 32c3 (2015)", "2" => "Engelsystem cccamp15", "0" => "Engelsystem light", - "1" => "Engelsystem dark" + "1" => "Engelsystem dark" ]; /** * Display muted (grey) text. * - * @param string $text + * @param string $text */ -function mute($text) { - return '<span class="text-muted">' . $text . '</span>'; +function mute($text) +{ + return '<span class="text-muted">' . $text . '</span>'; } /** @@ -28,84 +29,96 @@ function mute($text) { * @param string $class * default, primary, info, success, warning, danger */ -function label($content, $class = 'default') { - return '<span class="label label-' . $class . '">' . $content . '</span>'; +function label($content, $class = 'default') +{ + return '<span class="label label-' . $class . '">' . $content . '</span>'; } -function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '') { - return '<div class="progress"><div class="progress-bar ' . $class . '" role="progressbar" aria-valuenow="' . $valuenow . '" aria-valuemin="' . $valuemin . '" aria-valuemax="' . $valuemax . '" style="width: ' . floor(($valuenow - $valuemin) * 100 / ($valuemax - $valuemin)) . '%">' . $content . '</div></div>'; +function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '') +{ + return '<div class="progress"><div class="progress-bar ' . $class . '" role="progressbar" aria-valuenow="' . $valuenow . '" aria-valuemin="' . $valuemin . '" aria-valuemax="' . $valuemax . '" style="width: ' . floor(($valuenow - $valuemin) * 100 / ($valuemax - $valuemin)) . '%">' . $content . '</div></div>'; } /** * Render glyphicon * - * @param string $glyph_name + * @param string $glyph_name */ -function glyph($glyph_name) { - return ' <span class="glyphicon glyphicon-' . $glyph_name . '"></span> '; +function glyph($glyph_name) +{ + return ' <span class="glyphicon glyphicon-' . $glyph_name . '"></span> '; } /** * Renders a tick or a cross by given boolean * - * @param boolean $boolean + * @param boolean $boolean */ -function glyph_bool($boolean) { - return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>'; +function glyph_bool($boolean) +{ + return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>'; } -function div($class, $content = [], $dom_id = "") { - if (is_array($content)) { - $content = join("\n", $content); - } - $dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : ''; - return '<div' . $dom_id . ' class="' . $class . '">' . $content . '</div>'; +function div($class, $content = [], $dom_id = "") +{ + if (is_array($content)) { + $content = join("\n", $content); + } + $dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : ''; + return '<div' . $dom_id . ' class="' . $class . '">' . $content . '</div>'; } -function heading($content, $number = 1) { - return "<h" . $number . ">" . $content . "</h" . $number . ">"; +function heading($content, $number = 1) +{ + return "<h" . $number . ">" . $content . "</h" . $number . ">"; } /** * Render a toolbar. * - * @param array $items + * @param array $items * @return string */ -function toolbar($items = [], $right = false) { - return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>'; +function toolbar($items = [], $right = false) +{ + return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>'; } -function toolbar_pills($items) { - return '<ul class="nav nav-pills">' . join("\n", $items) . '</ul>'; +function toolbar_pills($items) +{ + return '<ul class="nav nav-pills">' . join("\n", $items) . '</ul>'; } /** * Render a link for a toolbar. * - * @param string $href - * @param string $glyphicon - * @param string $label - * @param bool $selected + * @param string $href + * @param string $glyphicon + * @param string $label + * @param bool $selected * @return string */ -function toolbar_item_link($href, $glyphicon, $label, $selected = false) { - return '<li class="' . ($selected ? 'active' : '') . '"><a href="' . $href . '">' . ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '') . $label . '</a></li>'; +function toolbar_item_link($href, $glyphicon, $label, $selected = false) +{ + return '<li class="' . ($selected ? 'active' : '') . '"><a href="' . $href . '">' . ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '') . $label . '</a></li>'; } -function toolbar_item_divider() { - return '<li class="divider"></li>'; +function toolbar_item_divider() +{ + return '<li class="divider"></li>'; } -function toolbar_dropdown($glyphicon, $label, $submenu, $class = '') { - return '<li class="dropdown ' . $class . '"> +function toolbar_dropdown($glyphicon, $label, $submenu, $class = '') +{ + return '<li class="dropdown ' . $class . '"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">' . ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '') . $label . ' <span class="caret"></span></a> <ul class="dropdown-menu" role="menu">' . join("\n", $submenu) . '</ul></li>'; } -function toolbar_popover($glyphicon, $label, $content, $class = '') { - $dom_id = md5(microtime() . $glyphicon . $label); - return '<li class="dropdown messages ' . $class . '"> +function toolbar_popover($glyphicon, $label, $content, $class = '') +{ + $dom_id = md5(microtime() . $glyphicon . $label); + return '<li class="dropdown messages ' . $class . '"> <a id="' . $dom_id . '" href="#" tabindex="0">' . ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '') . $label . ' <span class="caret"></span></a> <script type="text/javascript"> $(function(){ @@ -125,154 +138,165 @@ function toolbar_popover($glyphicon, $label, $content, $class = '') { * Generiert HTML Code für eine "Seite". * Fügt dazu die übergebenen Elemente zusammen. */ -function page($elements) { - return join($elements); +function page($elements) +{ + return join($elements); } /** * Generiert HTML Code für eine "Seite" mit zentraler Überschrift * Fügt dazu die übergebenen Elemente zusammen. */ -function page_with_title($title, $elements) { - return '<div class="col-md-12"><h1>' . $title . '</h1>' . join($elements) . '</div>'; +function page_with_title($title, $elements) +{ + return '<div class="col-md-12"><h1>' . $title . '</h1>' . join($elements) . '</div>'; } /** * Rendert eine Datentabelle */ -function table($columns, $rows_raw, $data = true) { - // If only one column is given +function table($columns, $rows_raw, $data = true) +{ + // If only one column is given if (! is_array($columns)) { - $rows = []; - foreach ($rows_raw as $row) { - $rows[] = [ - 'col' => $row + $rows = []; + foreach ($rows_raw as $row) { + $rows[] = [ + 'col' => $row ]; - } - return render_table([ - 'col' => $columns + } + return render_table([ + 'col' => $columns ], $rows, $data); } - return render_table($columns, $rows_raw, $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); - } +function render_table($columns, $rows, $data = true) +{ + if (count($rows) == 0) { + return info(_("No data found."), true); + } - $html = '<table class="table table-striped' . ($data ? ' data' : '') . '">'; - $html .= '<thead><tr>'; - foreach ($columns as $key => $column) { - $html .= '<th class="column_' . $key . '">' . $column . '</th>'; - } - $html .= '</tr></thead>'; - $html .= '<tbody>'; - foreach ($rows as $row) { - $html .= '<tr>'; + $html = '<table class="table table-striped' . ($data ? ' data' : '') . '">'; + $html .= '<thead><tr>'; foreach ($columns as $key => $column) { - $value = " "; - if (isset($row[$key])) { - $value = $row[$key]; - } - $html .= '<td class="column_' . $key . '">' . $value . '</td>'; + $html .= '<th class="column_' . $key . '">' . $column . '</th>'; } - $html .= '</tr>'; - } - $html .= '</tbody>'; - $html .= '</table>'; - return $html; + $html .= '</tr></thead>'; + $html .= '<tbody>'; + foreach ($rows as $row) { + $html .= '<tr>'; + foreach ($columns as $key => $column) { + $value = " "; + if (isset($row[$key])) { + $value = $row[$key]; + } + $html .= '<td class="column_' . $key . '">' . $value . '</td>'; + } + $html .= '</tr>'; + } + $html .= '</tbody>'; + $html .= '</table>'; + return $html; } /** * Rendert einen Knopf */ -function button($href, $label, $class = "") { - return '<a href="' . $href . '" class="btn btn-default ' . $class . '">' . $label . '</a>'; +function button($href, $label, $class = "") +{ + return '<a href="' . $href . '" class="btn btn-default ' . $class . '">' . $label . '</a>'; } /** * Rendert einen Knopf mit Glyph */ -function button_glyph($href, $glyph, $class = "") { - return button($href, glyph($glyph), $class); +function button_glyph($href, $glyph, $class = "") +{ + return button($href, glyph($glyph), $class); } /** * Rendert eine Toolbar mit Knöpfen */ -function buttons($buttons = []) { - return '<div class="form-group">' . table_buttons($buttons) . '</div>'; +function buttons($buttons = []) +{ + return '<div class="form-group">' . table_buttons($buttons) . '</div>'; } -function table_buttons($buttons = []) { - return '<div class="btn-group">' . join(' ', $buttons) . '</div>'; +function table_buttons($buttons = []) +{ + return '<div class="btn-group">' . join(' ', $buttons) . '</div>'; } // Load and render template -function template_render($file, $data) { - if (file_exists($file)) { - $template = file_get_contents($file); - if (is_array($data)) { - foreach ($data as $name => $content) { - $template = str_replace("%" . $name . "%", $content, $template); - } +function template_render($file, $data) +{ + if (file_exists($file)) { + $template = file_get_contents($file); + if (is_array($data)) { + foreach ($data as $name => $content) { + $template = str_replace("%" . $name . "%", $content, $template); + } + } + return $template; } - return $template; - } - engelsystem_error("Cannot find template file «" . $file . "»."); + engelsystem_error("Cannot find template file «" . $file . "»."); } -function shorten($str, $length = 50) { - if (strlen($str) < $length) { - return $str; - } - return '<span title="' . htmlentities($str, ENT_COMPAT, 'UTF-8') . '">' . substr($str, 0, $length - 3) . '...</span>'; +function shorten($str, $length = 50) +{ + if (strlen($str) < $length) { + return $str; + } + return '<span title="' . htmlentities($str, ENT_COMPAT, 'UTF-8') . '">' . substr($str, 0, $length - 3) . '...</span>'; } -function table_body($array) { - $html = ""; - foreach ($array as $line) { - $html .= "<tr>"; - if (is_array($line)) { - foreach ($line as $td) { - $html .= "<td>" . $td . "</td>"; - } - } else { - $html .= "<td>" . $line . "</td>"; +function table_body($array) +{ + $html = ""; + foreach ($array as $line) { + $html .= "<tr>"; + if (is_array($line)) { + foreach ($line as $td) { + $html .= "<td>" . $td . "</td>"; + } + } else { + $html .= "<td>" . $line . "</td>"; + } + $html .= "</tr>"; } - $html .= "</tr>"; - } - return $html; + return $html; } -function ReplaceSmilies($neueckig) { - $neueckig = str_replace(";o))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig); - $neueckig = str_replace(":-))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig); - $neueckig = str_replace(";o)", "<img src=\"pic/smiles/icon_wind.gif\">", $neueckig); - $neueckig = str_replace(":)", "<img src=\"pic/smiles/icon_smile.gif\">", $neueckig); - $neueckig = str_replace(":-)", "<img src=\"pic/smiles/icon_smile.gif\">", $neueckig); - $neueckig = str_replace(":(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig); - $neueckig = str_replace(":-(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig); - $neueckig = str_replace(":o(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig); - $neueckig = str_replace(":o)", "<img src=\"pic/smiles/icon_lol.gif\">", $neueckig); - $neueckig = str_replace(";o(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig); - $neueckig = str_replace(";(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig); - $neueckig = str_replace(";-(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig); - $neueckig = str_replace("8)", "<img src=\"pic/smiles/icon_rolleyes.gif\">", $neueckig); - $neueckig = str_replace("8o)", "<img src=\"pic/smiles/icon_rolleyes.gif\">", $neueckig); - $neueckig = str_replace(":P", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig); - $neueckig = str_replace(":-P", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig); - $neueckig = str_replace(":oP", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig); - $neueckig = str_replace(";P", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig); - $neueckig = str_replace(";oP", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig); - $neueckig = str_replace("?)", "<img src=\"pic/smiles/icon_question.gif\">", $neueckig); +function ReplaceSmilies($neueckig) +{ + $neueckig = str_replace(";o))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig); + $neueckig = str_replace(":-))", "<img src=\"pic/smiles/icon_redface.gif\">", $neueckig); + $neueckig = str_replace(";o)", "<img src=\"pic/smiles/icon_wind.gif\">", $neueckig); + $neueckig = str_replace(":)", "<img src=\"pic/smiles/icon_smile.gif\">", $neueckig); + $neueckig = str_replace(":-)", "<img src=\"pic/smiles/icon_smile.gif\">", $neueckig); + $neueckig = str_replace(":(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig); + $neueckig = str_replace(":-(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig); + $neueckig = str_replace(":o(", "<img src=\"pic/smiles/icon_sad.gif\">", $neueckig); + $neueckig = str_replace(":o)", "<img src=\"pic/smiles/icon_lol.gif\">", $neueckig); + $neueckig = str_replace(";o(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig); + $neueckig = str_replace(";(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig); + $neueckig = str_replace(";-(", "<img src=\"pic/smiles/icon_cry.gif\">", $neueckig); + $neueckig = str_replace("8)", "<img src=\"pic/smiles/icon_rolleyes.gif\">", $neueckig); + $neueckig = str_replace("8o)", "<img src=\"pic/smiles/icon_rolleyes.gif\">", $neueckig); + $neueckig = str_replace(":P", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig); + $neueckig = str_replace(":-P", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig); + $neueckig = str_replace(":oP", "<img src=\"pic/smiles/icon_evil.gif\">", $neueckig); + $neueckig = str_replace(";P", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig); + $neueckig = str_replace(";oP", "<img src=\"pic/smiles/icon_mad.gif\">", $neueckig); + $neueckig = str_replace("?)", "<img src=\"pic/smiles/icon_question.gif\">", $neueckig); - return $neueckig; + return $neueckig; } -?> |