engelsystem/includes/sys_template.php

422 lines
11 KiB
PHP
Raw Normal View History

2011-06-02 00:48:29 +02:00
<?php
2011-12-26 18:28:57 +01:00
/**
* Liste der verfügbaren Themes
*/
2016-09-30 17:08:20 +02:00
$themes = [
2017-01-03 14:12:17 +01:00
'4' => 'Engelsystem 33c3 (2016)',
'3' => 'Engelsystem 32c3 (2015)',
'2' => 'Engelsystem cccamp15',
'0' => 'Engelsystem light',
'1' => 'Engelsystem dark'
2016-09-30 17:08:20 +02:00
];
2011-12-26 18:28:57 +01:00
2014-12-22 20:06:37 +01:00
/**
* Display muted (grey) text.
*
2017-01-02 03:57:23 +01:00
* @param string $text
2017-01-03 03:22:48 +01:00
* @return string
2014-12-22 20:06:37 +01:00
*/
2017-01-02 03:57:23 +01:00
function mute($text)
{
return '<span class="text-muted">' . $text . '</span>';
2014-12-22 20:06:37 +01:00
}
2016-11-14 17:58:15 +01:00
/**
* Renders a bootstrap label with given content and class.
*
2017-01-03 03:22:48 +01:00
* @param string $content The text
* @param string $class default, primary, info, success, warning, danger
* @return string
2016-11-14 17:58:15 +01:00
*/
2017-01-02 03:57:23 +01:00
function label($content, $class = 'default')
{
return '<span class="label label-' . $class . '">' . $content . '</span>';
2016-11-14 17:58:15 +01:00
}
2017-01-03 03:22:48 +01:00
/**
* @param int $valuemin
* @param int $valuemax
* @param int $valuenow
* @param string $class
* @param string $content
* @return string
*/
2017-01-02 03:57:23 +01:00
function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '')
{
2017-01-03 03:22:48 +01:00
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>';
2014-12-19 22:41:55 +01:00
}
2014-09-28 14:50:08 +02:00
/**
* Render glyphicon
*
2017-01-02 03:57:23 +01:00
* @param string $glyph_name
2017-01-03 03:22:48 +01:00
* @return string
2014-09-28 14:50:08 +02:00
*/
2017-01-02 03:57:23 +01:00
function glyph($glyph_name)
{
return ' <span class="glyphicon glyphicon-' . $glyph_name . '"></span> ';
2014-09-28 14:50:08 +02:00
}
/**
* Renders a tick or a cross by given boolean
*
2017-01-02 03:57:23 +01:00
* @param boolean $boolean
2017-01-03 03:22:48 +01:00
* @return string
2014-09-28 14:50:08 +02:00
*/
2017-01-02 03:57:23 +01:00
function glyph_bool($boolean)
{
return '<span class="text-' . ($boolean ? 'success' : 'danger') . '">' . glyph($boolean ? 'ok' : 'remove') . '</span>';
2014-09-28 14:50:08 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @param string $class
* @param array $content
* @param string $dom_id
* @return string
*/
2017-01-03 14:12:17 +01:00
function div($class, $content = [], $dom_id = '')
2017-01-02 03:57:23 +01:00
{
if (is_array($content)) {
$content = join("\n", $content);
}
$dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : '';
return '<div' . $dom_id . ' class="' . $class . '">' . $content . '</div>';
2014-08-23 01:55:18 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @param string $content
* @param int $number
* @return string
*/
2017-01-02 03:57:23 +01:00
function heading($content, $number = 1)
{
2017-01-03 14:12:17 +01:00
return '<h' . $number . '>' . $content . '</h' . $number . '>';
}
2013-10-13 00:52:44 +02:00
/**
* Render a toolbar.
*
2017-01-02 03:57:23 +01:00
* @param array $items
2017-01-03 03:22:48 +01:00
* @param bool $right
2013-10-13 00:52:44 +02:00
* @return string
*/
2017-01-02 03:57:23 +01:00
function toolbar($items = [], $right = false)
{
return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>';
2013-10-13 00:52:44 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @param string[] $items
* @return string
*/
2017-01-02 03:57:23 +01:00
function toolbar_pills($items)
{
return '<ul class="nav nav-pills">' . join("\n", $items) . '</ul>';
}
2013-10-13 00:52:44 +02:00
/**
* Render a link for a toolbar.
*
2017-01-02 03:57:23 +01:00
* @param string $href
* @param string $glyphicon
* @param string $label
2017-01-02 15:43:36 +01:00
* @param bool $selected
2013-10-13 00:52:44 +02:00
* @return string
*/
2017-01-02 03:57:23 +01:00
function toolbar_item_link($href, $glyphicon, $label, $selected = false)
{
2017-01-03 03:22:48 +01:00
return '<li class="' . ($selected ? 'active' : '') . '">'
. '<a href="' . $href . '">'
. ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '')
. $label
. '</a>'
. '</li>';
2014-08-22 22:34:13 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @return string
*/
2017-01-02 03:57:23 +01:00
function toolbar_item_divider()
{
return '<li class="divider"></li>';
2014-09-24 15:11:50 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @param string $glyphicon
* @param string $label
* @param array $submenu
* @param string $class
* @return string
*/
2017-01-02 03:57:23 +01:00
function toolbar_dropdown($glyphicon, $label, $submenu, $class = '')
{
return '<li class="dropdown ' . $class . '">
2017-01-03 03:22:48 +01:00
<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>';
2014-08-23 02:16:12 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @param string $glyphicon
* @param string $label
* @param string[] $content
* @param string $class
* @return string
*/
2017-01-02 03:57:23 +01:00
function toolbar_popover($glyphicon, $label, $content, $class = '')
{
$dom_id = md5(microtime() . $glyphicon . $label);
return '<li class="dropdown messages ' . $class . '">
2017-01-03 03:22:48 +01:00
<a id="' . $dom_id . '" href="#" tabindex="0">'
. ($glyphicon != '' ? '<span class="glyphicon glyphicon-' . $glyphicon . '"></span> ' : '')
. $label
. ' <span class="caret"></span></a>
2014-12-06 22:26:56 +01:00
<script type="text/javascript">
$(function(){
2016-09-29 12:45:06 +02:00
$("#' . $dom_id . '").popover({
trigger: "focus",
html: true,
content: "' . addslashes(join('', $content)) . '",
placement: "bottom",
container: "#navbar-collapse-1"
})
});
2014-12-06 22:26:56 +01:00
</script></li>';
}
2011-12-21 22:20:06 +01:00
/**
2013-10-13 00:52:44 +02:00
* Generiert HTML Code für eine "Seite".
* Fügt dazu die übergebenen Elemente zusammen.
2017-01-03 03:22:48 +01:00
*
* @param string[] $elements
* @return string
2011-12-21 22:20:06 +01:00
*/
2017-01-02 03:57:23 +01:00
function page($elements)
{
return join($elements);
2011-12-21 22:20:06 +01:00
}
2014-08-22 22:34:13 +02:00
/**
* Generiert HTML Code für eine "Seite" mit zentraler Überschrift
* Fügt dazu die übergebenen Elemente zusammen.
2017-01-03 03:22:48 +01:00
*
* @param string $title
* @param string[] $elements
* @return string
2014-08-22 22:34:13 +02:00
*/
2017-01-02 03:57:23 +01:00
function page_with_title($title, $elements)
{
return '<div class="col-md-12"><h1>' . $title . '</h1>' . join($elements) . '</div>';
2014-08-22 22:34:13 +02:00
}
2011-12-21 22:20:06 +01:00
/**
* Rendert eine Datentabelle
2017-01-03 03:22:48 +01:00
*
* @param array|string $columns
* @param array[] $rows_raw
* @param bool $data
* @return string
2011-12-21 22:20:06 +01:00
*/
2017-01-02 03:57:23 +01:00
function table($columns, $rows_raw, $data = true)
{
// If only one column is given
2017-01-02 15:43:36 +01:00
if (!is_array($columns)) {
$rows = [];
foreach ($rows_raw as $row) {
$rows[] = [
'col' => $row
];
}
return render_table([
'col' => $columns
], $rows, $data);
}
2017-01-02 03:57:23 +01:00
return render_table($columns, $rows_raw, $data);
2016-09-30 17:38:26 +02:00
}
/**
* Helper for rendering a html-table.
* use table()
2017-01-03 03:22:48 +01:00
*
* @param string[] $columns
* @param array[] $rows
* @param bool $data
* @return string
2016-09-30 17:38:26 +02:00
*/
2017-01-02 03:57:23 +01:00
function render_table($columns, $rows, $data = true)
{
if (count($rows) == 0) {
return info(_("No data found."), true);
}
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
$html = '<table class="table table-striped' . ($data ? ' data' : '') . '">';
$html .= '<thead><tr>';
foreach ($columns as $key => $column) {
2017-01-02 03:57:23 +01:00
$html .= '<th class="column_' . $key . '">' . $column . '</th>';
}
2017-01-02 03:57:23 +01:00
$html .= '</tr></thead>';
$html .= '<tbody>';
foreach ($rows as $row) {
$html .= '<tr>';
foreach ($columns as $key => $column) {
$value = "&nbsp;";
if (isset($row[$key])) {
$value = $row[$key];
}
$html .= '<td class="column_' . $key . '">' . $value . '</td>';
}
$html .= '</tr>';
}
$html .= '</tbody>';
$html .= '</table>';
return $html;
2011-12-21 22:20:06 +01:00
}
/**
* Rendert einen Knopf
2017-01-03 03:22:48 +01:00
*
* @param string $href
* @param string $label
* @param string $class
* @return string
2011-12-21 22:20:06 +01:00
*/
2017-01-03 14:12:17 +01:00
function button($href, $label, $class = '')
2017-01-02 03:57:23 +01:00
{
return '<a href="' . $href . '" class="btn btn-default ' . $class . '">' . $label . '</a>';
2011-12-21 22:20:06 +01:00
}
2014-12-06 17:41:16 +01:00
/**
* Rendert einen Knopf mit Glyph
2017-01-03 03:22:48 +01:00
*
* @param string $href
* @param string $glyph
* @param string $class
* @return string
2014-12-06 17:41:16 +01:00
*/
2017-01-03 14:12:17 +01:00
function button_glyph($href, $glyph, $class = '')
2017-01-02 03:57:23 +01:00
{
return button($href, glyph($glyph), $class);
2014-12-06 22:26:56 +01:00
}
2014-12-06 17:41:16 +01:00
2011-12-21 22:20:06 +01:00
/**
* Rendert eine Toolbar mit Knöpfen
2017-01-03 03:22:48 +01:00
*
* @param array $buttons
* @return string
2011-12-21 22:20:06 +01:00
*/
2017-01-02 03:57:23 +01:00
function buttons($buttons = [])
{
return '<div class="form-group">' . table_buttons($buttons) . '</div>';
2014-09-28 14:50:08 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @param array $buttons
* @return string
*/
2017-01-02 03:57:23 +01:00
function table_buttons($buttons = [])
{
return '<div class="btn-group">' . join(' ', $buttons) . '</div>';
2011-12-21 22:20:06 +01:00
}
2017-01-03 03:22:48 +01:00
/**
* Load and render template
*
* @param string $file
* @param string $data
* @return string
*/
2017-01-02 03:57:23 +01:00
function template_render($file, $data)
{
if (file_exists($file)) {
$template = file_get_contents($file);
if (is_array($data)) {
foreach ($data as $name => $content) {
2017-01-03 14:12:17 +01:00
$template = str_replace('%' . $name . '%', $content, $template);
2017-01-02 03:57:23 +01:00
}
}
return $template;
}
2017-01-03 14:12:17 +01:00
engelsystem_error('Cannot find template file &laquo;' . $file . '&raquo;.');
2017-01-03 03:22:48 +01:00
return '';
2011-06-02 00:48:29 +02:00
}
2011-06-02 16:56:45 +02:00
2017-01-03 03:22:48 +01:00
/**
* @param string $str
* @param int $length
* @return string
*/
2017-01-02 03:57:23 +01:00
function shorten($str, $length = 50)
{
if (strlen($str) < $length) {
return $str;
}
2017-01-02 15:43:36 +01:00
return '<span title="' . htmlentities($str, ENT_COMPAT, 'UTF-8') . '">'
. substr($str, 0, $length - 3)
. '...</span>';
2011-07-13 14:29:40 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @param array[] $array
* @return string
*/
2017-01-02 03:57:23 +01:00
function table_body($array)
{
2017-01-03 14:12:17 +01:00
$html = '';
2017-01-02 03:57:23 +01:00
foreach ($array as $line) {
2017-01-03 14:12:17 +01:00
$html .= '<tr>';
2017-01-02 03:57:23 +01:00
if (is_array($line)) {
foreach ($line as $td) {
2017-01-03 14:12:17 +01:00
$html .= '<td>' . $td . '</td>';
2017-01-02 03:57:23 +01:00
}
} else {
2017-01-03 14:12:17 +01:00
$html .= '<td>' . $line . '</td>';
2017-01-02 03:57:23 +01:00
}
2017-01-03 14:12:17 +01:00
$html .= '</tr>';
}
2017-01-02 03:57:23 +01:00
return $html;
2011-07-11 20:40:27 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @param string $msg
* @return mixed
*/
function ReplaceSmilies($msg)
2017-01-02 03:57:23 +01:00
{
2017-01-03 14:12:17 +01:00
$msg = str_replace(';o))', '<img src="pic/smiles/icon_redface.gif">', $msg);
$msg = str_replace(':-))', '<img src="pic/smiles/icon_redface.gif">', $msg);
$msg = str_replace(';o)', '<img src="pic/smiles/icon_wind.gif">', $msg);
$msg = str_replace(':)', '<img src="pic/smiles/icon_smile.gif">', $msg);
$msg = str_replace(':-)', '<img src="pic/smiles/icon_smile.gif">', $msg);
$msg = str_replace(':(', '<img src="pic/smiles/icon_sad.gif">', $msg);
$msg = str_replace(':-(', '<img src="pic/smiles/icon_sad.gif">', $msg);
$msg = str_replace(':o(', '<img src="pic/smiles/icon_sad.gif">', $msg);
$msg = str_replace(':o)', '<img src="pic/smiles/icon_lol.gif">', $msg);
$msg = str_replace(';o(', '<img src="pic/smiles/icon_cry.gif">', $msg);
$msg = str_replace(';(', '<img src="pic/smiles/icon_cry.gif">', $msg);
$msg = str_replace(';-(', '<img src="pic/smiles/icon_cry.gif">', $msg);
$msg = str_replace('8)', '<img src="pic/smiles/icon_rolleyes.gif">', $msg);
$msg = str_replace('8o)', '<img src="pic/smiles/icon_rolleyes.gif">', $msg);
$msg = str_replace(':P', '<img src="pic/smiles/icon_evil.gif">', $msg);
$msg = str_replace(':-P', '<img src="pic/smiles/icon_evil.gif">', $msg);
$msg = str_replace(':oP', '<img src="pic/smiles/icon_evil.gif">', $msg);
$msg = str_replace(';P', '<img src="pic/smiles/icon_mad.gif">', $msg);
$msg = str_replace(';oP', '<img src="pic/smiles/icon_mad.gif">', $msg);
$msg = str_replace('?)', '<img src="pic/smiles/icon_question.gif">', $msg);
2017-01-02 15:43:36 +01:00
2017-01-03 03:22:48 +01:00
return $msg;
}