setMarkupEscaped($escape) # escapes markup (HTML)
->setBreaksEnabled(TRUE) # enables automatic line breaks
->text($markdown);
return '
'.PHP_EOL.$html.PHP_EOL.'
';
}
// Single line (used for messages, eventlogs)
$html = $parsedown
->setMarkupEscaped($escape) # escapes markup (HTML)
->setBreaksEnabled(TRUE) # enables automatic line breaks
->line($markdown);
//print_vars($html);
return '
' . $html . '';
}
/**
* Generate icon html tag
*
* @param string $icon Icon name in definitions (ie: flag) or by css class (ie: sprite-flag)
* @param string $class Additional class(es) for changing main icon view
* @param array $attribs Url/link extended attributes (ie data-*, class, style)
*
* @return string HTML icon tag like
or emoji style :flag-us: ->
🇺🇸
*/
function get_icon($icon, $class = '', $attribs = [])
{
global $config;
// Passed already html icon tag, return as is
if (str_contains_array($icon, [ '<', '>' ])) { return $icon; }
$icon = trim(strtolower($icon));
if (isset($config['icon'][$icon]))
{
// Defined icons
$icon = $config['icon'][$icon];
}
elseif (!strlen($icon))
{
// Empty icon, return empty string
return '';
}
// Emoji styled icons, ie :flag-us:
if (preg_match('/^:[\w\-_]+:$/', $icon))
{
// icon-emoji is pseudo class, for styling emoji as other icons
return '
' . get_icon_emoji($icon) . '';
}
// Append glyphicon main class if these icons used
if (str_starts($icon, 'glyphicon-'))
{
$icon = 'glyphicon '.$icon;
}
if ($class)
{
// Additional classes
$attribs['class'] = array_merge((array)$class, (array)$attribs['class']);
}
$attribs['class'] = array_merge([ $icon ], (array)$attribs['class']);
return '
';
}
/**
* Generate emoji icon (ie html hex entity)
*
* @param string $emoji Emoji name in definitions (ie: flag-us or :flag-us:)
* @param string $type Type of emoji for return (currently only html supported)
* @param array $attribs Url/link extended attributes (currently unused)
*
* @return string Emoji in requested type, for html ie: :flag-us: -> 🇺🇸
*/
function get_icon_emoji($emoji, $type = 'html', $attribs = [])
{
global $config;
// Emoji definitions not loaded by default!
// Load of first request
if (!isset($config['emoji']['zero']))
{
include_once $config['install_dir'] . '/includes/definitions/emoji.inc.php';
}
$emoji_name = strtolower(trim($emoji, ": \t\n\r\0\x0B"));
// Unknown emoji name, return original string
if (!isset($config['emoji'][$emoji_name]))
{
return $emoji;
}
$type = strtolower($type);
$entry = $config['emoji'][$emoji_name];
switch ($type)
{
case 'unified':
case 'non_qualified':
$return = escape_html($entry[$type]);
break;
case 'html':
default:
// 26A0-FE0F -> ⚠️
$emoji_html = explode('-', escape_html($entry['unified'])); // escaping for prevent pass to definitions html code
$return = '' . implode(';', $emoji_html) . ';';
}
return $return;
}
/**
* Generate icon html tag with country flag
*
* @param string $country Country name or code
*
* @return string HTML icon tag like
*/
function get_icon_country($country)
{
global $config;
// Unificate country name
$country = country_from_code($country);
// Find ISO 2 country code (must be first in definitions)
$code = strtolower(array_search($country, $config['rewrites']['countries']));
if (empty($code))
{
return get_icon('location');
}
return '
';
}
function print_json_status($status, $message = '', $array = []) {
if (!in_array($status, [ 'ok', 'failed', 'warning' ])) {
$status = 'failed';
}
$return = [ 'status' => $status, 'message' => $message ];
if (safe_count($array)) {
if (isset($array['message']) && empty($message)) {
// prefer not empty message
unset($return['message']);
}
$return = array_merge($return, $array);
}
header('Content-Type: application/json');
print safe_json_encode($return);
}
// EOF