]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Merge pull request #8344 from MrPetovan/bug/8339-remote-follow-local-profile
[friendica.git] / src / Model / Item.php
index 88208564dc4913ae9bf75a40229facc532bbdb99..9d2acdce04dd59610d0b3f969b59cc5a49818822 100644 (file)
@@ -1,14 +1,28 @@
 <?php
-
 /**
- * @file src/Model/Item.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
 
 namespace Friendica\Model;
 
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
-use Friendica\Core\Config;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
@@ -104,7 +118,7 @@ class Item
        public static function isLegacyMode()
        {
                if (is_null(self::$legacy_mode)) {
-                       self::$legacy_mode = (Config::get("system", "post_update_version") < 1279);
+                       self::$legacy_mode = (DI::config()->get("system", "post_update_version") < 1279);
                }
 
                return self::$legacy_mode;
@@ -1451,7 +1465,7 @@ class Item
                $uid = intval($item['uid']);
 
                // check for create date and expire time
-               $expire_interval = Config::get('system', 'dbclean-expire-days', 0);
+               $expire_interval = DI::config()->get('system', 'dbclean-expire-days', 0);
 
                $user = DBA::selectFirst('user', ['expire'], ['uid' => $uid]);
                if (DBA::isResult($user) && ($user['expire'] > 0) && (($user['expire'] < $expire_interval) || ($expire_interval == 0))) {
@@ -1857,7 +1871,18 @@ class Item
                }
 
                // Creates or assigns the permission set
-               $item['psid'] = PermissionSet::fetchIDForPost($item);
+               $item['psid'] = PermissionSet::getIdFromACL(
+                       $item['uid'],
+                       $item['allow_cid'],
+                       $item['allow_gid'],
+                       $item['deny_cid'],
+                       $item['deny_gid']
+               );
+
+               $item['allow_cid'] = null;
+               $item['allow_gid'] = null;
+               $item['deny_cid'] = null;
+               $item['deny_gid'] = null;
 
                // We are doing this outside of the transaction to avoid timing problems
                if (!self::insertActivity($item)) {
@@ -1879,7 +1904,7 @@ class Item
                unset($item['owner-name']);
                unset($item['owner-avatar']);
 
-               $like_no_comment = Config::get('system', 'like_no_comment');
+               $like_no_comment = DI::config()->get('system', 'like_no_comment');
 
                DBA::transaction();
                $ret = DBA::insert('item', $item);
@@ -2585,7 +2610,7 @@ class Item
                $URLSearchString = "^\[\]";
 
                // All hashtags should point to the home server if "local_tags" is activated
-               if (Config::get('system', 'local_tags')) {
+               if (DI::config()->get('system', 'local_tags')) {
                        $item["body"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
                                        "#[url=".DI::baseUrl()."/search?tag=$2]$2[/url]", $item["body"]);
 
@@ -2730,7 +2755,13 @@ class Item
 
                $private = ($user['allow_cid'] || $user['allow_gid'] || $user['deny_cid'] || $user['deny_gid']) ? 1 : 0;
 
-               $psid = PermissionSet::fetchIDForPost($user);
+               $psid = PermissionSet::getIdFromACL(
+                       $user['uid'],
+                       $user['allow_cid'],
+                       $user['allow_gid'],
+                       $user['deny_cid'],
+                       $user['deny_gid']
+               );
 
                $forum_mode = ($prvgroup ? 2 : 1);
 
@@ -2842,7 +2873,7 @@ class Item
         */
        public static function fixPrivatePhotos($s, $uid, $item = null, $cid = 0)
        {
-               if (Config::get('system', 'disable_embedded')) {
+               if (DI::config()->get('system', 'disable_embedded')) {
                        return $s;
                }
 
@@ -3420,7 +3451,7 @@ class Item
                if ($rendered_hash == ''
                        || $rendered_html == ""
                        || $rendered_hash != hash("md5", $item["body"])
-                       || Config::get("system", "ignore_cache")
+                       || DI::config()->get("system", "ignore_cache")
                ) {
                        self::addRedirToImageTags($item);
 
@@ -3439,7 +3470,7 @@ class Item
                        }
 
                        // Only compare the HTML when we forcefully ignore the cache
-                       if (Config::get("system", "ignore_cache") && ($rendered_html != $item["rendered-html"])) {
+                       if (DI::config()->get("system", "ignore_cache") && ($rendered_html != $item["rendered-html"])) {
                                $update = true;
                        }
 
@@ -3599,7 +3630,7 @@ class Item
                        $title .= ' ' . $mtch[2] . ' ' . DI::l10n()->t('bytes');
 
                        $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
-                       $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
+                       $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" rel="noopener noreferrer" >' . $icon . '</a>';
                }
 
                if ($as != '') {
@@ -3728,6 +3759,36 @@ class Item
                return 0;
        }
 
+       /**
+        * Return the URI for a link to the post 
+        * 
+        * @param string $uri URI or link to post
+        *
+        * @return string URI
+        */
+       public static function getURIByLink(string $uri)
+       {
+               $ssl_uri = str_replace('http://', 'https://', $uri);
+               $uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
+
+               $item = DBA::selectFirst('item', ['uri'], ['uri' => $uris]);
+               if (DBA::isResult($item)) {
+                       return $item['uri'];
+               }
+
+               $itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]);
+               if (!DBA::isResult($itemcontent)) {
+                       return '';
+               }
+
+               $itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
+               if (DBA::isResult($itemuri)) {
+                       return $itemuri['uri'];
+               }
+
+               return '';
+       }
+
        /**
         * Fetches item for given URI or plink
         *
@@ -3743,8 +3804,8 @@ class Item
                        return $item_id;
                }
 
-               if (ActivityPub\Processor::fetchMissingActivity($uri)) {
-                       $item_id = self::searchByLink($uri, $uid);
+               if ($fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri)) {
+                       $item_id = self::searchByLink($fetched_uri, $uid);
                } else {
                        $item_id = Diaspora::fetchByURL($uri);
                }