]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Merge pull request #7095 from annando/ap-connect
[friendica.git] / src / Model / Item.php
index 16a3b07b53097e98ab3d52dccd693a1b9ce4f888..387014d4b93e55883b1c90e0a081d4bc961be060 100644 (file)
@@ -27,6 +27,7 @@ use Friendica\Util\Map;
 use Friendica\Util\XML;
 use Friendica\Util\Security;
 use Friendica\Util\Strings;
+use Friendica\Util\Network;
 use Text_LanguageDetect;
 
 class Item extends BaseObject
@@ -44,14 +45,14 @@ class Item extends BaseObject
 
        // Field list that is used to display the items
        const DISPLAY_FIELDLIST = [
-               'uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network',
+               'uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network', 'gravity',
                'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
                'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'attach', 'language',
                'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
                'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'item_id',
                'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
                'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network',
-               'contact-id', 'contact-link', 'contact-name', 'contact-avatar',
+               'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar',
                'writable', 'self', 'cid', 'alias',
                'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
                'event-summary', 'event-desc', 'event-location', 'event-type',
@@ -91,7 +92,7 @@ class Item extends BaseObject
 
        // Never reorder or remove entries from this list. Just add new ones at the end, if needed.
        // The item-activity table only stores the index and needs this array to know the matching activity.
-       const ACTIVITIES = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE];
+       const ACTIVITIES = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE, ACTIVITY_FOLLOW, ACTIVITY2_ANNOUNCE];
 
        private static $legacy_mode = null;
 
@@ -1439,20 +1440,30 @@ class Item extends BaseObject
                $default = ['url' => $item['author-link'], 'name' => $item['author-name'],
                        'photo' => $item['author-avatar'], 'network' => $item['network']];
 
-               $item['author-id'] = defaults($item, 'author-id', Contact::getIdForURL($item["author-link"], 0, false, $default));
+               $item['author-id'] = defaults($item, 'author-id', Contact::getIdForURL($item['author-link'], 0, false, $default));
 
-               if (Contact::isBlocked($item["author-id"])) {
-                       Logger::notice('Author is blocked node-wide', ['author-link' => $item["author-link"], 'item-uri' => $item["uri"]]);
+               if (Contact::isBlocked($item['author-id'])) {
+                       Logger::notice('Author is blocked node-wide', ['author-link' => $item['author-link'], 'item-uri' => $item['uri']]);
+                       return 0;
+               }
+
+               if (!empty($item['author-link']) && Network::isUrlBlocked($item['author-link'])) {
+                       Logger::notice('Author server is blocked', ['author-link' => $item['author-link'], 'item-uri' => $item['uri']]);
                        return 0;
                }
 
                $default = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
                        'photo' => $item['owner-avatar'], 'network' => $item['network']];
 
-               $item['owner-id'] = defaults($item, 'owner-id', Contact::getIdForURL($item["owner-link"], 0, false, $default));
+               $item['owner-id'] = defaults($item, 'owner-id', Contact::getIdForURL($item['owner-link'], 0, false, $default));
+
+               if (Contact::isBlocked($item['owner-id'])) {
+                       Logger::notice('Owner is blocked node-wide', ['owner-link' => $item['owner-link'], 'item-uri' => $item['uri']]);
+                       return 0;
+               }
 
-               if (Contact::isBlocked($item["owner-id"])) {
-                       Logger::notice('Owner is blocked node-wide', ['owner-link' => $item["owner-link"], 'item-uri' => $item["uri"]]);
+               if (!empty($item['owner-link']) && Network::isUrlBlocked($item['owner-link'])) {
+                       Logger::notice('Owner server is blocked', ['owner-link' => $item['owner-link'], 'item-uri' => $item['uri']]);
                        return 0;
                }
 
@@ -2497,62 +2508,6 @@ class Item extends BaseObject
                        }, $item["body"]);
        }
 
-       public static function getGuidById($id)
-       {
-               $item = self::selectFirst(['guid'], ['id' => $id]);
-               if (DBA::isResult($item)) {
-                       return $item['guid'];
-               } else {
-                       return '';
-               }
-       }
-
-       /**
-        * This function is only used for the old Friendica app on Android that doesn't like paths with guid
-        *
-        * @param string $guid item guid
-        * @param int    $uid  user id
-        * @return array with id and nick of the item with the given guid
-        * @throws \Exception
-        */
-       public static function getIdAndNickByGuid($guid, $uid = 0)
-       {
-               $nick = "";
-               $id = 0;
-
-               if ($uid == 0) {
-                       $uid = local_user();
-               }
-
-               // Does the given user have this item?
-               if ($uid) {
-                       $item = self::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
-                       if (DBA::isResult($item)) {
-                               $user = DBA::selectFirst('user', ['nickname'], ['uid' => $uid]);
-                               if (!DBA::isResult($user)) {
-                                       return;
-                               }
-                               $id = $item['id'];
-                               $nick = $user['nickname'];
-                       }
-               }
-
-               // Or is it anywhere on the server?
-               if ($nick == "") {
-                       $condition = ["`guid` = ? AND `uid` != 0", $guid];
-                       $item = self::selectFirst(['id', 'uid'], $condition);
-                       if (DBA::isResult($item)) {
-                               $user = DBA::selectFirst('user', ['nickname'], ['uid' => $item['uid']]);
-                               if (!DBA::isResult($user)) {
-                                       return;
-                               }
-                               $id = $item['id'];
-                               $nick = $user['nickname'];
-                       }
-               }
-               return ["nick" => $nick, "id" => $id];
-       }
-
        /**
         * look for mention tags and setup a second delivery chain for forum/community posts if appropriate
         *
@@ -3455,9 +3410,7 @@ class Item extends BaseObject
                        if (strpos($mime, 'video') !== false) {
                                if (!$vhead) {
                                        $vhead = true;
-                                       $a->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('videos_head.tpl'), [
-                                               '$baseurl' => System::baseUrl(),
-                                       ]);
+                                       $a->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('videos_head.tpl'));
                                }
 
                                $url_parts = explode('/', $the_url);
@@ -3581,4 +3534,31 @@ class Item extends BaseObject
 
                return $ret;
        }
+
+       /**
+        * Is the given item array a post that is sent as starting post to a forum?
+        *
+        * @param array $item
+        * @param array $owner
+        *
+        * @return boolean "true" when it is a forum post
+        */
+       public static function isForumPost(array $item, array $owner = [])
+       {
+               if (empty($owner)) {
+                       $owner = User::getOwnerDataById($item['uid']);
+                       if (empty($owner)) {
+                               return false;
+                       }
+               }
+
+               if (($item['author-id'] == $item['owner-id']) ||
+                       ($owner['id'] == $item['contact-id']) ||
+                       ($item['uri'] != $item['parent-uri']) ||
+                       $item['origin']) {
+                       return false;
+               }
+
+               return Contact::isForum($item['contact-id']);
+       }
 }