0, and success if number == 0.
*
* @param string $label
* @param string $number
* @param string $style default, warning, danger or success. Optional.
* @return string
*/
function stats($label, $number, $style = null)
{
if (empty($style)) {
if ($number > 0) {
$style = 'danger';
} else {
$style = 'success';
}
}
return div('stats stats-' . $style, [
$label,
div('number', [
$number
])
]);
}
/**
* Renders tabs from the array. Array key is tab name, array value is tab content.
*
* @param array $tabs
* @param int $selected The selected tab, default 0
* @return string HTML
*/
function tabs($tabs, $selected = 0)
{
$tab_header = [];
$tab_content = [];
foreach ($tabs as $header => $content) {
$class = '';
if (count($tab_header) == $selected) {
$class = 'active';
}
$tab_header[] = '
'
. $header . '';
$tab_content[] = '';
}
return div('', [
'' . join($tab_header) . '
',
'' . join($tab_content) . '
'
]);
}
/**
* Display muted (grey) text.
*
* @param string $text
* @return string
*/
function mute($text)
{
return '' . $text . '';
}
/**
* Renders a bootstrap label with given content and class.
*
* @param string $content The text
* @param string $class default, primary, info, success, warning, danger
* @return string
*/
function label($content, $class = 'default')
{
return '' . $content . '';
}
/**
* @param int $valuemin
* @param int $valuemax
* @param int $valuenow
* @param string $class
* @param string $content
* @return string
*/
function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '')
{
return ''
. '
'
. $content . ''
. '
'
. '
';
}
/**
* Render glyphicon
*
* @param string $glyph_name
* @return string
*/
function glyph($glyph_name)
{
return ' ';
}
/**
* Renders a tick or a cross by given boolean
*
* @param boolean $boolean
* @return string
*/
function glyph_bool($boolean)
{
return ''
. glyph($boolean ? 'ok' : 'remove')
. '';
}
/**
* @param string $class
* @param array $content
* @param string $dom_id
* @return string
*/
function div($class, $content = [], $dom_id = '')
{
if (is_array($content)) {
$content = join("\n", $content);
}
$dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : '';
return '' . $content . '
';
}
/**
* @param string $content
* @param int $number
* @return string
*/
function heading($content, $number = 1)
{
return '' . $content . '';
}
/**
* Render a toolbar.
*
* @param array $items
* @param bool $right
* @return string
*/
function toolbar($items = [], $right = false)
{
return '' . join("\n", $items) . '
';
}
/**
* @param string[] $items
* @return string
*/
function toolbar_pills($items)
{
return '' . join("\n", $items) . '
';
}
/**
* Render a link for a toolbar.
*
* @param string $href
* @param string $glyphicon
* @param string $label
* @param bool $selected
* @return string
*/
function toolbar_item_link($href, $glyphicon, $label, $selected = false)
{
return ''
. ''
. ($glyphicon != '' ? ' ' : '')
. $label
. ''
. '';
}
/**
* @return string
*/
function toolbar_item_divider()
{
return '';
}
/**
* @param string $glyphicon
* @param string $label
* @param array $submenu
* @param string $class
* @return string
*/
function toolbar_dropdown($glyphicon, $label, $submenu, $class = '')
{
return '
'
. ($glyphicon != '' ? ' ' : '')
. $label
. '
';
}
/**
* @param string $glyphicon
* @param string $label
* @param string[] $content
* @param string $class
* @return string
*/
function toolbar_popover($glyphicon, $label, $content, $class = '')
{
$dom_id = md5(microtime() . $glyphicon . $label);
return '
'
. ($glyphicon != '' ? ' ' : '')
. $label
. '
';
}
/**
* Generiert HTML Code für eine "Seite".
* Fügt dazu die übergebenen Elemente zusammen.
*
* @param string[] $elements
* @return string
*/
function page($elements)
{
return join($elements);
}
/**
* Generiert HTML Code für eine "Seite" mit zentraler Überschrift
* Fügt dazu die übergebenen Elemente zusammen.
*
* @param string $title
* @param string[] $elements
* @return string
*/
function page_with_title($title, $elements)
{
return '' . $title . '
' . join($elements) . '';
}
/**
* Renders a description based on the data arrays key and values as label an description.
*
* @param array $data
* @return string
*/
function description($data)
{
$elements = [];
foreach ($data as $label => $description) {
if (!empty($label) && !empty($description)) {
$elements[] = '' . $label . '' . $description . '';
}
}
return '' . join($elements) . '
';
}
/**
* Rendert eine Datentabelle
*
* @param array|string $columns
* @param array[] $rows_raw
* @param bool $data
* @return string
*/
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
];
}
return render_table([
'col' => $columns
], $rows, $data);
}
return render_table($columns, $rows_raw, $data);
}
/**
* Helper for rendering a html-table.
* use table()
*
* @param string[] $columns
* @param array[] $rows
* @param bool $data
* @return string
*/
function render_table($columns, $rows, $data = true)
{
if (count($rows) == 0) {
return info(_('No data found.'), true);
}
$html = '';
$html .= '';
foreach ($columns as $key => $column) {
$html .= '' . $column . ' | ';
}
$html .= '
';
$html .= '';
foreach ($rows as $row) {
$html .= '';
foreach ($columns as $key => $column) {
$value = " ";
if (isset($row[$key])) {
$value = $row[$key];
}
$html .= '' . $value . ' | ';
}
$html .= '
';
}
$html .= '';
$html .= '
';
return $html;
}
/**
* Rendert einen Knopf
*
* @param string $href
* @param string $label
* @param string $class
* @return string
*/
function button($href, $label, $class = '')
{
return '' . $label . '';
}
/**
* Rendert einen Knopf mit JavaScript onclick Handler
*
* @param string $javascript
* @param string $label
* @param string $class
* @return string
*/
function button_js($javascript, $label, $class = '')
{
return '' . $label . '';
}
/**
* Rendert einen Knopf mit Glyph
*
* @param string $href
* @param string $glyph
* @param string $class
* @return string
*/
function button_glyph($href, $glyph, $class = '')
{
return button($href, glyph($glyph), $class);
}
/**
* Rendert eine Toolbar mit Knöpfen
*
* @param array $buttons
* @return string
*/
function buttons($buttons = [])
{
return '' . table_buttons($buttons) . '
';
}
/**
* @param array $buttons
* @return string
*/
function table_buttons($buttons = [])
{
return '' . join(' ', $buttons) . '
';
}
/**
* @param string $str
* @param int $length
* @return string
*/
function shorten($str, $length = 50)
{
if (strlen($str) < $length) {
return $str;
}
return ''
. substr($str, 0, $length - 3)
. '...';
}
/**
* @param array[] $array
* @return string
*/
function table_body($array)
{
$html = '';
foreach ($array as $line) {
$html .= '';
if (is_array($line)) {
foreach ($line as $td) {
$html .= '' . $td . ' | ';
}
} else {
$html .= '' . $line . ' | ';
}
$html .= '
';
}
return $html;
}
/**
* @param string $msg
* @return mixed
*/
function ReplaceSmilies($msg)
{
/** @var Assets $assets */
$assets = app('twig.extension.assets');
foreach (
[
';o))' => 'redface',
':-))' => 'redface',
';o)' => 'wind',
':)' => 'smile',
':-)' => 'smile',
':(' => 'sad',
':-(' => 'sad',
':o(' => 'sad',
':o)' => 'lol',
':D' => 'lol',
';o(' => 'cry',
';(' => 'cry',
';-(' => 'cry',
'8)' => 'rolleyes',
'8o)' => 'rolleyes',
':P' => 'evil',
':-P' => 'evil',
':oP' => 'evil',
';P' => 'mad',
';oP' => 'mad',
'?)' => 'question',
] as $search => $replace
) {
$msg = str_ireplace($search, sprintf(
'',
sprintf($assets->getAsset('assets/emojis/%s.gif'), $replace)
), $msg);
}
return $msg;
}