X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItem.php;h=b460d5f79fdf886364acfe50a0c7ddf99a4580e6;hb=fc0acd7b1f4723b9e45badcaae53e466e1a29b85;hp=cffa25397c850df81bd3a1e57d091cdec3edefe8;hpb=ad9c67663d8206315c649be3b27bf5418fb91ad3;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index cffa25397c..b460d5f79f 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -559,10 +559,10 @@ class Item extends BaseObject $fields['permissionset'] = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']; - $fields['author'] = ['url' => 'author-link', 'name' => 'author-name', + $fields['author'] = ['url' => 'author-link', 'name' => 'author-name', 'addr' => 'author-addr', 'thumb' => 'author-avatar', 'nick' => 'author-nick', 'network' => 'author-network']; - $fields['owner'] = ['url' => 'owner-link', 'name' => 'owner-name', + $fields['owner'] = ['url' => 'owner-link', 'name' => 'owner-name', 'addr' => 'owner-addr', 'thumb' => 'owner-avatar', 'nick' => 'owner-nick', 'network' => 'owner-network']; $fields['contact'] = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar', @@ -1252,6 +1252,8 @@ class Item extends BaseObject { $orig_item = $item; + $priority = PRIORITY_HIGH; + // If it is a posting where users should get notifications, then define it as wall posting if ($notify) { $item['wall'] = 1; @@ -1261,8 +1263,6 @@ class Item extends BaseObject if (is_int($notify)) { $priority = $notify; - } else { - $priority = PRIORITY_HIGH; } } else { $item['network'] = trim(defaults($item, 'network', Protocol::PHANTOM)); @@ -1790,13 +1790,13 @@ class Item extends BaseObject DBA::insert('diaspora-interaction', ['uri-id' => $item['uri-id'], 'interaction' => $diaspora_signed_text], true); } - $deleted = self::tagDeliver($item['uid'], $current_post); + self::tagDeliver($item['uid'], $current_post); /* * current post can be deleted if is for a community page and no mention are * in it. */ - if (!$deleted && !$dontcache) { + if (!$dontcache) { $posted_item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $current_post]); if (DBA::isResult($posted_item)) { if ($notify) { @@ -1850,7 +1850,7 @@ class Item extends BaseObject $cmd = 'wall-new'; } - Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', $cmd, $current_post); + Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $cmd, $current_post); } return $current_post; @@ -2019,7 +2019,7 @@ class Item extends BaseObject $condition = ['id' => $itemid, 'uid' => 0, 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""], 'visible' => true, 'deleted' => false, 'moderated' => false, 'private' => false]; - $item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]); + $item = self::selectFirst(self::ITEM_FIELDLIST, $condition); if (!DBA::isResult($item)) { return; } @@ -2386,7 +2386,6 @@ class Item extends BaseObject public static function setHashtags(&$item) { - $tags = BBCode::getTags($item["body"]); // No hashtags? @@ -2394,6 +2393,17 @@ class Item extends BaseObject return false; } + // What happens in [code], stays in [code]! + // escape the # and the [ + // hint: we will also get in trouble with #tags, when we want markdown in posts -> ### Headline 3 + $item["body"] = preg_replace_callback("/\[code(.*?)\](.*?)\[\/code\]/ism", + function ($match) { + // we truly ESCape all # and [ to prevent gettin weird tags in [code] blocks + $find = ['#', '[']; + $replace = [chr(27).'sharp', chr(27).'leftsquarebracket']; + return ("[code" . $match[1] . "]" . str_replace($find, $replace, $match[2]) . "[/code]"); + }, $item["body"]); + // This sorting is important when there are hashtags that are part of other hashtags // Otherwise there could be problems with hashtags like #test and #test2 rsort($tags); @@ -2430,12 +2440,11 @@ class Item extends BaseObject "#$2", $item["body"]); foreach ($tags as $tag) { - if ((strpos($tag, '#') !== 0) || strpos($tag, '[url=')) { + if ((strpos($tag, '#') !== 0) || strpos($tag, '[url=') || $tag[1] == '#') { continue; } $basetag = str_replace('_',' ',substr($tag,1)); - $newtag = '#[url=' . System::baseUrl() . '/search?tag=' . $basetag . ']' . $basetag . '[/url]'; $item["body"] = str_replace($tag, $newtag, $item["body"]); @@ -2450,6 +2459,16 @@ class Item extends BaseObject // Convert back the masked hashtags $item["body"] = str_replace("#", "#", $item["body"]); + + // Remember! What happens in [code], stays in [code] + // roleback the # and [ + $item["body"] = preg_replace_callback("/\[code(.*?)\](.*?)\[\/code\]/ism", + function ($match) { + // we truly unESCape all sharp and leftsquarebracket + $find = [chr(27).'sharp', chr(27).'leftsquarebracket']; + $replace = ['#', '[']; + return ("[code" . $match[1] . "]" . str_replace($find, $replace, $match[2]) . "[/code]"); + }, $item["body"]); } public static function getGuidById($id) @@ -2476,7 +2495,7 @@ class Item extends BaseObject $id = 0; if ($uid == 0) { - $uid == local_user(); + $uid = local_user(); } // Does the given user have this item?