From 1b8bd16f4728672273afda5530315836d6c59561 Mon Sep 17 00:00:00 2001 From: nobody Date: Thu, 21 Jan 2021 18:36:44 -0800 Subject: [PATCH] bugs --- Zotlabs/Lib/Activity.php | 20 +++++++++++-- Zotlabs/Module/Profiles.php | 3 +- include/bbcode.php | 58 ++++++++++++++++++++----------------- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 6ba76fc72..63e3cef74 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -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) { diff --git a/Zotlabs/Module/Profiles.php b/Zotlabs/Module/Profiles.php index 4aea1f3db..6e13f7811 100644 --- a/Zotlabs/Module/Profiles.php +++ b/Zotlabs/Module/Profiles.php @@ -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'); diff --git a/include/bbcode.php b/include/bbcode.php index 8c5881fb1..b1b95d86f 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -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('#(?$2',$Text); - $Text = preg_replace('#(?$2',$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('#(^| )(?$3',$Text); - $Text = preg_replace('#(?$1', $Text); - $Text = preg_replace('#<\/code><\/pre>\n
| .*?>)#','
',$Text); + $Text = preg_replace_callback("/\[code(.*?)\](.*?)\[\/code\]/ism", 'bb_code_preprotect', $Text); - // blockquotes - $Text = preg_replace('#^(>)+ +(.*?)$#m','
$2
',$Text); - $Text = preg_replace('#\n
#',"\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:)?([^\)]+)\)(?!`)#','$1',$Text); + $Text = preg_replace('#(?$2',$Text); + $Text = preg_replace('#(?$2',$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('#(^| )(?$3
',$Text); + $Text = preg_replace('#(?$1', $Text); + $Text = preg_replace('#<\/code><\/pre>\n
| .*?>)#','
',$Text); - // unordered lists - $Text = preg_replace('#^ *[*\-+] +(.*?)$#m','
  • $1
',$Text); - // order lists - $Text = preg_replace('#^\d+[\.] +(.*?)$#m','
  1. $1
',$Text); + // blockquotes + $Text = preg_replace('#^(>)+ +(.*?)$#m','
$2
',$Text); + $Text = preg_replace('#\n
#',"\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:)?([^\)]+)\)(?!`)#','$1',$Text); + + // unordered lists + $Text = preg_replace('#^ *[*\-+] +(.*?)$#m','
  • $1
',$Text); + // order lists + $Text = preg_replace('#^\d+[\.] +(.*?)$#m','
  1. $1
',$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
tags