';
if ($avatar != "")
$headline .= '';
if(strpos($link,'/cards/'))
$type = t('card');
elseif(strpos($link,'/articles/'))
$type = t('article');
else
$type = t('post');
// Bob Smith wrote the following post 2 hours ago
$fmt = sprintf( t('%1$s wrote the following %2$s %3$s'),
'' . $author . '',
'' . $type . '',
$reldate
);
$headline .= '' . $fmt . '
';
$text = $headline . '
' . trim($match[2]) . '
';
return $text;
}
function bb_location($match) {
// not yet implemented
}
/**
* @brief Returns an iframe from $match[1].
*
* @param array $match
* @return string HTML iframe with content of $match[1]
*/
function bb_iframe($match) {
$sandbox = ((strpos($match[1], App::get_hostname())) ? ' sandbox="allow-scripts" ' : '');
return '';
}
function bb_ShareAttributesSimple($match) {
$matches = array();
$attributes = $match[1];
$author = "";
preg_match("/author='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
$author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
preg_match('/author="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
$author = $matches[1];
$profile = "";
preg_match("/profile='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
$profile = $matches[1];
preg_match('/profile="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
$profile = $matches[1];
$text = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . ' ' . $author . ':
' . $match[2] . '
';
return($text);
}
function rpost_callback($match) {
if ($match[2]) {
return str_replace($match[0], Libzot::get_rpost_path(App::get_observer()) . '&title=' . urlencode($match[2]) . '&body=' . urlencode($match[3]), $match[0]);
} else {
return str_replace($match[0], Libzot::get_rpost_path(App::get_observer()) . '&body=' . urlencode($match[3]), $match[0]);
}
}
function bb_map_coords($match) {
// the extra space in the following line is intentional
return str_replace($match[0],'
';
}
function bb_definitionList($match) {
// $match[1] is the markup styles for the "terms" in the definition list.
// $match[2] is the content between the [dl]...[/dl] tags
$classes = '';
if (stripos($match[1], "b") !== false) $classes .= 'dl-terms-bold ';
if (stripos($match[1], "i") !== false) $classes .= 'dl-terms-italic ';
if (stripos($match[1], "u") !== false) $classes .= 'dl-terms-underline ';
if (stripos($match[1], "l") !== false) $classes .= 'dl-terms-large ';
if (stripos($match[1], "m") !== false) $classes .= 'dl-terms-monospace ';
if (stripos($match[1], "h") !== false) $classes .= 'dl-horizontal '; // dl-horizontal is already provided by bootstrap
if (strlen($classes) === 0) $classes = "dl-terms-plain";
// The bbcode transformation will be:
// [*=term-text] description-text =>
term-text
description-text
// then after all replacements have been made, the extra
at the start of the
// first line can be removed. HTML5 allows the tag to be missing from the end of the last line.
// Using '(?\n";
$eatLeadingSpaces = '(?: |[ \t])*'; // prevent spaces infront of [*= from adding another line to the previous element
$listElements = preg_replace('/^(\n| )/', '', $match[2]); // ltrim the first newline
$listElements = preg_replace(
'/' . $eatLeadingSpaces . '\[\*=([[:print:]]*?)(?$1
',
$listElements
);
// Unescape any \] inside the
tags
$listElements = preg_replace_callback('/
(.*?)<\/dt>/ism', 'bb_definitionList_unescapeBraces', $listElements);
// Remove the extra at the start of the string, if there is one.
$firstOpenTag = strpos($listElements, '
', $text);
// [dl] tags have an optional [dl terms="bi"] form where bold/italic/underline/mono/large
// etc. style may be specified for the "terms" in the definition list. The quotation marks
// are also optional. The regex looks intimidating, but breaks down as:
// "[dl" "]" "[/dl]"
// where optional-termStyles are: "terms="
$text = preg_replace_callback('/\[dl[[:space:]]*(?:terms=(?:"|")?([a-zA-Z]+)(?:"|")?)?\](.*?)\[\/dl\]/ism', 'bb_definitionList', $text);
}
if (strpos($text,'[checklist]') !== false) {
$text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism",'bb_fix_lf', $text);
$text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism", 'bb_checklist', $text);
}
if (strpos($text,'[/table]') !== false) {
$text = str_replace(["[/table]\r", "[/table]\n"], '[/table]', $text);
$text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fix_lf',$text);
$text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '
', $text);
}
$text = str_replace('[hr]', '', $text);
// This is actually executed in prepare_body()
$text = str_replace('[nosmile]', '', $text);
// Check for font change text
if (strpos($text,'[/font]') !== false) {
$text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm", "$2", $text);
}
// Check for [spoiler] text
$endlessloop = 0;
while ((strpos($text, "[/spoiler]")!== false) and (strpos($text, "[spoiler]") !== false) and (++$endlessloop < 20)) {
$text = preg_replace_callback("/\[spoiler\](.*?)\[\/spoiler\]/ism", 'bb_spoilertag', $text);
}
// Check for [spoiler=Author] text
$endlessloop = 0;
while ((strpos($text, "[/spoiler]")!== false) and (strpos($text, "[spoiler=") !== false) and (++$endlessloop < 20)) {
$text = preg_replace_callback("/\[spoiler=(.*?)\](.*?)\[\/spoiler\]/ism", 'bb_spoilertag', $text);
}
// Check for [open] text
$endlessloop = 0;
while ((strpos($text, "[/open]")!== false) and (strpos($text, "[open]") !== false) and (++$endlessloop < 20)) {
$text = preg_replace_callback("/\[open\](.*?)\[\/open\]/ism", 'bb_opentag', $text);
}
// Check for [open=Title] text
$endlessloop = 0;
while ((strpos($text, "[/open]")!== false) and (strpos($text, "[open=") !== false) and (++$endlessloop < 20)) {
$text = preg_replace_callback("/\[open=(.*?)\](.*?)\[\/open\]/ism", 'bb_opentag', $text);
}
// Declare the format for [quote] layout
$QuoteLayout = '
$1
';
// Check for [quote] text
// handle nested quotes
$endlessloop = 0;
while ((strpos($text, "[/quote]") !== false) and (strpos($text, "[quote]") !== false) and (++$endlessloop < 20))
$text = preg_replace("/\[quote\](.*?)\[\/quote\]/ism", "$QuoteLayout", $text);
// Check for [quote=Author] text
$t_wrote = t('$1 wrote:');
// handle nested quotes
$endlessloop = 0;
while ((strpos($text, "[/quote]")!== false) and (strpos($text, "[quote=") !== false) and (++$endlessloop < 20))
$text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism",
"" . $t_wrote . "
$2
",
$text);
// Images
if (strpos($text,'[/img]') !== false) {
$text = preg_replace_callback('/\[\$b64img(.*?)\[\/(img)\]/ism','\red_unescape_codeblock',$text);
}
if (strpos($text,'[/zmg]') !== false) {
$text = preg_replace_callback('/\[\$b64zmg(.*?)\[\/(zmg)\]/ism','\red_unescape_codeblock',$text);
}
// [img]pathtoimage[/img]
if (strpos($text,'[/img]') !== false) {
$text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '', $text);
}
// [img=pathtoimage]image description[/img]
if (strpos($text,'[/img]') !== false) {
$text = preg_replace("/\[img=http(.*?)\](.*?)\[\/img\]/ism", '', $text);
}
// [zmg]pathtoimage[/zmg]
if (strpos($text,'[/zmg]') !== false) {
$text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '', $text);
}
// [zmg=pathtoimage]image description[/zmg]
if (strpos($text,'[/zmg]') !== false) {
$text = preg_replace("/\[zmg=http(.*?)\](.*?)\[\/zmg\]/ism", '', $text);
}
$text = preg_replace_callback("/\[([zi])mg([ \=])(.*?)\](.*?)\[\/[zi]mg\]/ism",'bb_imgoptions',$text);
// style (sanitized)
if (strpos($text,'[/style]') !== false) {
$text = preg_replace_callback("(\[style=(.*?)\](.*?)\[\/style\])ism", "bb_sanitize_style", $text);
}
// crypt
if (strpos($text,'[/crypt]') !== false) {
$text = preg_replace_callback("/\[crypt\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $text);
$text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $text);
}
if(strpos($text,'[/app]') !== false) {
$text = preg_replace_callback("/\[app\](.*?)\[\/app\]/ism",'bb_parse_app', $text);
}
if(strpos($text,'[/element]') !== false) {
$text = preg_replace_callback("/\[element\](.*?)\[\/element\]/ism",'bb_parse_element', $text);
}
// html5 video and audio
if (strpos($text,'[/video]') !== false) {
$text = preg_replace_callback("/\[video (.*?)\](.*?)\[\/video\]/ism", 'videowithopts', $text);
$text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryzrlvideo', $text);
}
if (strpos($text,'[/audio]') !== false) {
$text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryzrlaudio', $text);
}
if (strpos($text,'[/zvideo]') !== false) {
$text = preg_replace_callback("/\[zvideo (.*?)\](.*?)\[\/zvideo\]/ism", 'videowithopts', $text);
$text = preg_replace_callback("/\[zvideo\](.*?)\[\/zvideo\]/ism", 'tryzrlvideo', $text);
}
if (strpos($text,'[/zaudio]') !== false) {
$text = preg_replace_callback("/\[zaudio\](.*?)\[\/zaudio\]/ism", 'tryzrlaudio', $text);
}
// SVG stuff
$text = preg_replace_callback("/\[svg(.*?)\](.*?)\[\/svg\]/ism", 'bb_svg', $text);
// Try to Oembed
if ($tryoembed) {
if (strpos($text,'[/video]') !== false) {
$text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $text);
}
if (strpos($text,'[/audio]') !== false) {
$text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $text);
}
if (strpos($text,'[/zvideo]') !== false) {
$text = preg_replace_callback("/\[zvideo\](.*?)\[\/zvideo\]/ism", 'tryoembed', $text);
}
if (strpos($text,'[/zaudio]') !== false) {
$text = preg_replace_callback("/\[zaudio\](.*?)\[\/zaudio\]/ism", 'tryoembed', $text);
}
}
// if video couldn't be embedded, link to it instead.
if (strpos($text,'[/video]') !== false) {
$text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $text);
}
if (strpos($text,'[/audio]') !== false) {
$text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $text);
}
if (strpos($text,'[/zvideo]') !== false) {
$text = preg_replace("/\[zvideo\](.*?)\[\/zvideo\]/", '$1', $text);
}
if (strpos($text,'[/zaudio]') !== false) {
$text = preg_replace("/\[zaudio\](.*?)\[\/zaudio\]/", '$1', $text);
}
// oembed tag
if (strpos($text,'[/embed]') !== false) {
$text = oembed_bbcode2html($text);
// Avoid triple linefeeds through oembed
$text = str_replace("
", " ", $text);
}
// If we found an event earlier, strip out all the event code and replace with a reformatted version.
// Replace the event-start section with the entire formatted event. The other bbcode is stripped.
// Summary (e.g. title) is required, earlier revisions only required description (in addition to
// start which is always required). Allow desc with a missing summary for compatibility.
if ((x($ev,'desc') || x($ev,'summary')) && x($ev,'dtstart')) {
$sub = format_event_html($ev);
$sub = str_replace('$',"\0",$sub);
$text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/ism",$sub,$text);
$text = preg_replace("/\[event\](.*?)\[\/event\]/ism",'',$text);
$text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$text);
$text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism",'',$text);
$text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism",'',$text);
$text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism",'',$text);
$text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism",'',$text);
$text = preg_replace("/\[event\-timezone\](.*?)\[\/event\-timezone\]/ism",'',$text);
$text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$text);
$text = str_replace("\0",'$',$text);
}
if (strpos($text,'[summary]') !== false) {
$text = preg_replace_callback("/\[summary\](.*?)\[\/summary\]/ism", 'bb_unspacefy',$text);
}
if(strpos($text,'[/summary]') !== false) {
$text = preg_replace_callback("/^(.*?)\[summary\](.*?)\[\/summary\](.*?)$/is", 'bb_summary', $text);
}
// Unhide all [noparse] contained bbtags unspacefying them
// and triming the [noparse] tag.
if (strpos($text,'[noparse]') !== false) {
$text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_unspacefy_and_trim', $text);
}
if (strpos($text,'[nobb]') !== false) {
$text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_unspacefy_and_trim', $text);
}
if (strpos($text,'[pre]') !== false) {
$text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim', $text);
}
// replace escaped links in code= blocks
$text = str_replace('%eY9-!','http', $text);
$text = bb_code_unprotect($text);
$text = preg_replace('/\[\&\;([#a-z0-9]+)\;\]/', '&$1;', $text);
// fix any escaped ampersands that may have been converted into links
if(strpos($text,'&') !== false)
$text = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism", '<$1$2=$3&$4>', $text);
// This is subtle - it's an XSS filter. It only accepts links with a protocol scheme and where
// the scheme begins with z (zhttp), h (http(s)), f (ftp(s)), m (mailto), t (tel) and named anchors.
$text = preg_replace("/\<(.*?)(src|href)=\"[^zhfmt#](.*?)\>/ism", '<$1$2="">', $text);
$text = bb_replace_images($text, $saved_images);
// Convert new line chars to html tags
// nlbr seems to be hopelessly messed up
// $text = nl2br($text);
// We'll emulate it.
$text = str_replace("\r\n", "\n", $text);
$text = str_replace(["\r", "\n"], ' ', $text);
/**
* @hooks bbcode
* * _string_ **html** - The resulting HTML after converting from bbcode.
*/
call_hooks('bbcode', $text);
return $text;
}