This commit is contained in:
nobody 2021-01-21 18:36:44 -08:00
parent f857aba50e
commit 1b8bd16f47
3 changed files with 49 additions and 32 deletions

View file

@ -2361,7 +2361,7 @@ class Activity {
$s['body'] = $content['content'];
}
else {
$s['body'] = ((self::bb_content($content,'bbcode') && (! $response_activity)) ? self::bb_content($content,'bbcode') : self::bb_content($content,'content'));
$s['body'] = ((self::bb_content($content,'bbcode') && (! $response_activity)) ? self::bb_content($content,'bbcode') : self::bb_content($content,'content'));
}
@ -2696,7 +2696,21 @@ class Activity {
if ($cacheable) {
if ((! array_key_exists('mimetype',$s)) || ($s['mimetype'] === 'text/bbcode')) {
$s['html'] = bbcode($s['body']);
// preserve the original purified HTML content *unless* we've modified $s['body']
// within this function (to add attachments or reaction descriptions or mention rewrites).
// This avoids/bypasses some markdown rendering issues which can occur when
// converting to our markdown-enhanced bbcode and then back to HTML again.
// Also if we do need bbcode, use the 'bbonly' flag to ignore markdown and only
// interpret bbcode; which is much less susceptible to false positives in the
// conversion regexes.
if ($s['body'] === self::bb_content($content,'content')) {
$s['html'] = $content['content'];
}
else {
$s['html'] = bbcode($s['body'], [ 'bbonly' => true ]);
}
}
}
@ -3000,7 +3014,7 @@ class Activity {
}
else {
$fetch = false;
if (perm_is_allowed($channel['channel_id'],$observer_hash,'send_stream') && (PConfig::Get($channel['channel_id'],'system','hyperdrive',true) || $act->type === 'Announce')) {
if (intval($channel['channel_system']) || (perm_is_allowed($channel['channel_id'],$observer_hash,'send_stream') && (PConfig::Get($channel['channel_id'],'system','hyperdrive',true) || $act->type === 'Announce'))) {
$fetch = (($fetch_parents) ? self::fetch_and_store_parents($channel,$observer_hash,$act,$item) : false);
}
if ($fetch) {

View file

@ -27,9 +27,8 @@ class Profiles extends Controller {
if(! $r) {
notice( t('Profile not found.') . EOL);
goaway(z_root() . '/profiles');
return; // NOTREACHED
}
$profile_guid = $r['profile_guid'];
$profile_guid = $r[0]['profile_guid'];
check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');

View file

@ -1238,6 +1238,7 @@ function bbcode($Text, $options = []) {
$activitypub = ((array_key_exists('activitypub',$options)) ? $options['activitypub'] : false);
$censored = ((array_key_exists('censored',$options)) ? $options['censored'] : false);
$plain = ((array_key_exists('plain',$options)) ? $options['plain'] : false);
$bbonly = ((array_key_exists('bbonly',$options)) ? $options['bbonly'] : false);
if ($activitypub) {
$export = true;
@ -1248,8 +1249,6 @@ function bbcode($Text, $options = []) {
call_hooks('bbcode_filter', $Text);
// Hide all [noparse] contained bbtags by spacefying them
if (strpos($Text,'[noparse]') !== false) {
$Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text);
@ -1341,39 +1340,44 @@ function bbcode($Text, $options = []) {
$Text = str_replace("\r\n", "\n", $Text);
// save code blocks from being interpreted as markdown
$Text = preg_replace_callback("/\[code(.*?)\](.*?)\[\/code\]/ism", 'bb_code_preprotect', $Text);
if (! $bbonly) {
// Perform some markdown conversions before translating linefeeds so as to keep the regexes manageable
// save code blocks from being interpreted as markdown
$Text = preg_replace('#(?<!\\\)([*_]{3})([^\n]+?)\1#','<strong><em>$2</em></strong>',$Text);
$Text = preg_replace('#(?<!\\\)([*_]{2})([^\n]+?)\1#','<strong>$2</strong>',$Text);
// The character check is so we don't mistake underscore in the middle of a code variable as an italic trigger.
$Text = preg_replace_callback('#(^| )(?<!\\\)([*_])([^\n|`]+?)\2#m','md_italic',$Text);
$Text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx','md_topheader', $Text);
$Text = preg_replace_callback('#^(\#{1,6})\s+([^\#]+?)\s*\#*$#m','md_header', $Text);
$Text = preg_replace_callback('#(^|\n)([`~]{3,})(?: *\.?([a-zA-Z0-9\-.]+))?\n+([\s\S]+?)\n+\2(\n|$)#','md_codeblock',$Text);
$Text = preg_replace('#^(?:\0(.*?)\0\n)?( {4}|\t)(.*?)$#m','<pre><code>$3</code></pre>',$Text);
$Text = preg_replace('#(?<!\\\)`([^\n]+?)`#','<pre><code>$1</code></pre>', $Text);
$Text = preg_replace('#<\/code><\/pre>\n<pre><code(>| .*?>)#','<br>',$Text);
$Text = preg_replace_callback("/\[code(.*?)\](.*?)\[\/code\]/ism", 'bb_code_preprotect', $Text);
// blockquotes
$Text = preg_replace('#^(&gt;)+ +(.*?)$#m','<blockquote>$2</blockquote>',$Text);
$Text = preg_replace('#</blockquote>\n<blockquote>#',"\n", $Text);
// Perform some markdown conversions before translating linefeeds so as to keep the regexes manageable
// links
$Text = preg_replace_callback('#!\[[^\]]*\]\((.*?)(?=\"|\))(\".*\")?\)(?!`)#','md_image',$Text);
$Text = preg_replace('#\[([^\[]+)\]\((?:javascript:)?([^\)]+)\)(?!`)#','<a href="$2">$1</a>',$Text);
$Text = preg_replace('#(?<!\\\)([*_]{3})([^\n]+?)\1#','<strong><em>$2</em></strong>',$Text);
$Text = preg_replace('#(?<!\\\)([*_]{2})([^\n]+?)\1#','<strong>$2</strong>',$Text);
// The character check is so we don't mistake underscore in the middle of a code variable as an italic trigger.
$Text = preg_replace_callback('#(^| )(?<!\\\)([*_])([^\n|`]+?)\2#m','md_italic',$Text);
$Text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx','md_topheader', $Text);
$Text = preg_replace_callback('#^(\#{1,6})\s+([^\#]+?)\s*\#*$#m','md_header', $Text);
$Text = preg_replace_callback('#(^|\n)([`~]{3,})(?: *\.?([a-zA-Z0-9\-.]+))?\n+([\s\S]+?)\n+\2(\n|$)#','md_codeblock',$Text);
$Text = preg_replace('#^(?:\0(.*?)\0\n)?( {4}|\t)(.*?)$#m','<pre><code>$3</code></pre>',$Text);
$Text = preg_replace('#(?<!\\\)`([^\n]+?)`#','<pre><code>$1</code></pre>', $Text);
$Text = preg_replace('#<\/code><\/pre>\n<pre><code(>| .*?>)#','<br>',$Text);
// unordered lists
$Text = preg_replace('#^ *[*\-+] +(.*?)$#m','<ul><li>$1</li></ul>',$Text);
// order lists
$Text = preg_replace('#^\d+[\.] +(.*?)$#m','<ol><li>$1</li></ol>',$Text);
// blockquotes
$Text = preg_replace('#^(&gt;)+ +(.*?)$#m','<blockquote>$2</blockquote>',$Text);
$Text = preg_replace('#</blockquote>\n<blockquote>#',"\n", $Text);
$Text = preg_replace('/\s*<\/(ol|ul)>\n+<\1>\s*/',"\n",$Text);
// links
$Text = preg_replace_callback('#!\[[^\]]*\]\((.*?)(?=\"|\))(\".*\")?\)(?!`)#','md_image',$Text);
$Text = preg_replace('#\[([^\[]+)\]\((?:javascript:)?([^\)]+)\)(?!`)#','<a href="$2">$1</a>',$Text);
// unordered lists
$Text = preg_replace('#^ *[*\-+] +(.*?)$#m','<ul><li>$1</li></ul>',$Text);
// order lists
$Text = preg_replace('#^\d+[\.] +(.*?)$#m','<ol><li>$1</li></ol>',$Text);
$Text = preg_replace('/\s*<\/(ol|ul)>\n+<\1>\s*/',"\n",$Text);
$Text = bb_code_preunprotect($Text);
}
$Text = bb_code_preunprotect($Text);
// Convert new line chars to html <br> tags