]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
AP: Debug option to deliver via AP first
[friendica.git] / src / Model / Item.php
index 6c071bfc7fb7e1adec24c92a2f893dda94e0bea0..b460d5f79fdf886364acfe50a0c7ddf99a4580e6 100644 (file)
@@ -20,15 +20,6 @@ use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
-use Friendica\Model\Contact;
-use Friendica\Model\Event;
-use Friendica\Model\FileTag;
-use Friendica\Model\PermissionSet;
-use Friendica\Model\Term;
-use Friendica\Model\ItemURI;
-use Friendica\Model\Photo;
-use Friendica\Model\Attach;
-use Friendica\Object\Image;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Util\DateTimeFormat;
@@ -568,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',
@@ -1245,18 +1236,24 @@ class Item extends BaseObject
        // This function will finally cover most of the preparation functionality in mod/item.php
        public static function prepare(&$item)
        {
+               /*
+                * @TODO: Unused code triggering inspection errors
+                *
                $data = BBCode::getAttachmentData($item['body']);
                if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $item['body'], $match, PREG_SET_ORDER) || isset($data["type"]))
                        && ($posttype != Item::PT_PERSONAL_NOTE)) {
                        $posttype = Item::PT_PAGE;
                        $objecttype = ACTIVITY_OBJ_BOOKMARK;
                }
+                */
        }
 
        public static function insert($item, $force_parent = false, $notify = false, $dontcache = false)
        {
                $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;
@@ -1266,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));
@@ -1795,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) {
@@ -1855,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;
@@ -2024,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;
                }
@@ -2391,7 +2386,6 @@ class Item extends BaseObject
 
        public static function setHashtags(&$item)
        {
-
                $tags = BBCode::getTags($item["body"]);
 
                // No hashtags?
@@ -2399,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);
@@ -2435,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"]);
@@ -2455,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)
@@ -2481,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?
@@ -2531,8 +2545,8 @@ class Item extends BaseObject
                        return;
                }
 
-               $community_page = (($user['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
-               $prvgroup = (($user['page-flags'] == Contact::PAGE_PRVGROUP) ? true : false);
+               $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
+               $prvgroup = (($user['page-flags'] == User::PAGE_FLAGS_PRVGROUP) ? true : false);
 
                $item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $item_id]);
                if (!DBA::isResult($item)) {
@@ -3049,7 +3063,6 @@ class Item extends BaseObject
                // Contact-id is the uid-dependant author contact
                if (local_user() == $uid) {
                        $item_contact_id = $owner_self_contact['id'];
-                       $item_contact = $owner_self_contact;
                } else {
                        $item_contact_id = Contact::getIdForURL($author_contact['url'], $uid, true);
                        $item_contact = DBA::selectFirst('contact', [], ['id' => $item_contact_id]);
@@ -3176,8 +3189,6 @@ class Item extends BaseObject
                        $item["mention"] = 1;
                }
 
-               $sql = "";
-
                $fields = [];
 
                foreach ($item as $field => $data) {