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;
// If the icon is already an HTML tag, return it as is
if (str_contains_array($icon, ['<', '>'])) {
return $icon;
}
$icon = trim(strtolower($icon));
// Use the defined icon if available, else check for an empty icon and return an empty string
$icon = isset($config['icon'][$icon]) ? $config['icon'][$icon] : ($icon ?: '');
// Handle emoji styled icons
if (preg_match('/^:[\w\-_]+:$/', $icon) || is_intnum($icon)) {
return '
' . get_icon_emoji($icon) . '';
}
// Append glyphicon main class if these icons are used
if (str_starts($icon, 'glyphicon-')) {
$icon = 'glyphicon ' . $icon;
}
// Initialize the 'class' key in $attribs if not already set and merge additional classes
$attribs['class'] = array_merge([$icon], (array)$class, isset($attribs['class']) ? $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"));
if (is_intnum($emoji)) {
// convert int number string to emoji number
$return = '';
foreach (str_split($emoji) as $num) {
switch ($num) {
case '0':
$return .= get_icon_emoji(':zero:', $type, $attribs);
break;
case '1':
$return .= get_icon_emoji(':one:', $type, $attribs);
break;
case '2':
$return .= get_icon_emoji(':two:', $type, $attribs);
break;
case '3':
$return .= get_icon_emoji(':three:', $type, $attribs);
break;
case '4':
$return .= get_icon_emoji(':four:', $type, $attribs);
break;
case '5':
$return .= get_icon_emoji(':five:', $type, $attribs);
break;
case '6':
$return .= get_icon_emoji(':six:', $type, $attribs);
break;
case '7':
$return .= get_icon_emoji(':seven:', $type, $attribs);
break;
case '8':
$return .= get_icon_emoji(':eight:', $type, $attribs);
break;
case '9':
$return .= get_icon_emoji(':nine:', $type, $attribs);
break;
}
}
return $return;
}
// 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