]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Merge pull request #8230 from AlfredSK/AlfredSK-statistics-query
[friendica.git] / src / Model / Item.php
index 62d6620bc1be7fc7effe8b6ed9dfa3d86c4fd333..b960ba38f3dfa5fbb91d3a719b9416ef45632f3f 100644 (file)
@@ -1,16 +1,29 @@
 <?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\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
@@ -105,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;
@@ -1452,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))) {
@@ -1858,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)) {
@@ -1880,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);
@@ -2586,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"]);
 
@@ -2731,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);
 
@@ -2843,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;
                }
 
@@ -3388,16 +3418,16 @@ class Item
        public static function postType($item)
        {
                if (!empty($item['event-id'])) {
-                       return L10n::t('event');
+                       return DI::l10n()->t('event');
                } elseif (!empty($item['resource-id'])) {
-                       return L10n::t('photo');
+                       return DI::l10n()->t('photo');
                } elseif (!empty($item['verb']) && $item['verb'] !== Activity::POST) {
-                       return L10n::t('activity');
+                       return DI::l10n()->t('activity');
                } elseif ($item['id'] != $item['parent']) {
-                       return L10n::t('comment');
+                       return DI::l10n()->t('comment');
                }
 
-               return L10n::t('post');
+               return DI::l10n()->t('post');
        }
 
        /**
@@ -3421,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);
 
@@ -3440,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;
                        }
 
@@ -3520,7 +3550,7 @@ class Item
                $filter_reasons = [];
                if (!$is_preview && public_contact() != $item['author-id']) {
                        if (!empty($item['content-warning']) && (!local_user() || !DI::pConfig()->get(local_user(), 'system', 'disable_cw', false))) {
-                               $filter_reasons[] = L10n::t('Content warning: %s', $item['content-warning']);
+                               $filter_reasons[] = DI::l10n()->t('Content warning: %s', $item['content-warning']);
                        }
 
                        $hook_data = [
@@ -3580,7 +3610,7 @@ class Item
                                $as .= Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
                                        '$video' => [
                                                'id'     => $id,
-                                               'title'  => L10n::t('View Video'),
+                                               'title'  => DI::l10n()->t('View Video'),
                                                'src'    => $the_url,
                                                'mime'   => $mime,
                                        ],
@@ -3597,7 +3627,7 @@ class Item
                        }
 
                        $title = Strings::escapeHtml(trim(($mtch[4] ?? '') ?: $mtch[1]));
-                       $title .= ' ' . $mtch[2] . ' ' . L10n::t('bytes');
+                       $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>';
@@ -3644,20 +3674,20 @@ class Item
                        $ret = [
                                'href' => "display/" . $item['guid'],
                                'orig' => "display/" . $item['guid'],
-                               'title' => L10n::t('View on separate page'),
-                               'orig_title' => L10n::t('view on separate page'),
+                               'title' => DI::l10n()->t('View on separate page'),
+                               'orig_title' => DI::l10n()->t('view on separate page'),
                        ];
 
                        if (!empty($item['plink'])) {
                                $ret["href"] = DI::baseUrl()->remove($item['plink']);
-                               $ret["title"] = L10n::t('link to source');
+                               $ret["title"] = DI::l10n()->t('link to source');
                        }
 
                } elseif (!empty($item['plink']) && ($item['private'] != 1)) {
                        $ret = [
                                'href' => $item['plink'],
                                'orig' => $item['plink'],
-                               'title' => L10n::t('link to source'),
+                               'title' => DI::l10n()->t('link to source'),
                        ];
                } else {
                        $ret = [];
@@ -3729,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
         *
@@ -3744,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);
                }