doti3/bar/src/base/block.php
2019-01-28 11:13:11 +01:00

101 lines
1.8 KiB
PHP

<?php
/**
* Get the hexa code of a color by its label.
*
* @param string $label
*
* @return string
*/
function color($label)
{
$colors = [
'music' => '#cccccc',
'date' => '#E9F1FF',
'info' => '#E9F1FF',
'critical' => '#FF474A',
'warning' => '#FF6836',
'normal' => '#B3FF6C',
];
return $colors[$label] ?? $colors['info'];
}
/**
* Create emoji with padding.
*
* @param mixed $char
*/
function pemoji($char)
{
return '<span font=\'FontAwesome\'> '.IntlChar::chr($char).' </span>';
}
/**
* Create emoji.
*
* @param mixed $char
*/
function emoji($char)
{
return '<span font=\'FontAwesome\'>'.IntlChar::chr($char).'</span>';
}
/**
* Creates span with padding.
*
* @param string $text
* @param string $foreground
* @param string $background
*
* @return string
*/
function pspan($text, $foreground = null, $background = null)
{
return span(sprintf(' %s ', $text), $foreground, $background);
}
/**
* Creates span.
*
* @param string $text
* @param string $foreground
* @param string $background
*
* @return string
*/
function span($text, $foreground = null, $background = null)
{
return sprintf(
'<span background=\'%s\' foreground=\'%s\'>%s</span>',
$background ?? '#333333',
$foreground ?? color('normal'),
$text
);
}
/**
* Returns a json of a block.
*
* @param string $name
* @param array $options
*
* @return string
*/
function block(string $name, array $options = [])
{
$options = array_merge(
[
'full_text' => '',
'align' => 'left',
'name' => $name,
'urgent' => false,
'separator' => false,
'separator_block_width' => 0,
],
$options
);
return stripslashes(json_encode($options, JSON_UNESCAPED_UNICODE));
}