]> git.mxchange.org Git - friendica.git/commitdiff
Move DI dependency for Content\Item class
authorPhilipp <admin@philipp.info>
Thu, 20 Oct 2022 19:36:38 +0000 (21:36 +0200)
committerPhilipp <admin@philipp.info>
Fri, 21 Oct 2022 17:35:32 +0000 (19:35 +0200)
src/Content/Item.php

index 469c7764c7047277d7745a0f5a9ad6e5fb60194e..6ef59432f10000eec57a85baf946cee3271e7e5b 100644 (file)
@@ -27,9 +27,9 @@ use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
-use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Item as ItemModel;
@@ -53,12 +53,15 @@ class Item
        private $l10n;
        /** @var Profiler */
        private $profiler;
+       /** @var IHandleUserSessions */
+       private $userSession;
 
-       public function __construct(Profiler $profiler, Activity $activity, L10n $l10n)
+       public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession)
        {
-               $this->profiler = $profiler;
-               $this->activity = $activity;
-               $this->l10n   = $l10n;
+               $this->profiler    = $profiler;
+               $this->activity    = $activity;
+               $this->l10n        = $l10n;
+               $this->userSession = $userSession;
        }
 
        /**
@@ -110,7 +113,7 @@ class Item
                        $categories[] = [
                                'name' => $savedFolderName,
                                'url' => $url,
-                               'removeurl' => DI::userSession()->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : '',
+                               'removeurl' => $this->userSession->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : '',
                                'first' => $first,
                                'last' => false
                        ];
@@ -121,12 +124,12 @@ class Item
                        $categories[count($categories) - 1]['last'] = true;
                }
 
-               if (DI::userSession()->getLocalUserId() == $uid) {
+               if ($this->userSession->getLocalUserId() == $uid) {
                        foreach (Post\Category::getArrayByURIId($item['uri-id'], $uid, Post\Category::FILE) as $savedFolderName) {
                                $folders[] = [
                                        'name' => $savedFolderName,
                                        'url' => "#",
-                                       'removeurl' => DI::userSession()->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : '',
+                                       'removeurl' => $this->userSession->getLocalUserId() == $uid ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : '',
                                        'first' => $first,
                                        'last' => false
                                ];
@@ -332,7 +335,7 @@ class Item
                $sub_link = $contact_url = $pm_url = $status_link = '';
                $photos_link = $posts_link = $block_link = $ignore_link = '';
 
-               if (DI::userSession()->getLocalUserId() && DI::userSession()->getLocalUserId() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
+               if ($this->userSession->getLocalUserId() && $this->userSession->getLocalUserId() == $item['uid'] && $item['gravity'] == ItemModel::GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
                        $sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
                }
 
@@ -349,7 +352,7 @@ class Item
                $pcid = $item['author-id'];
                $network = '';
                $rel = 0;
-               $condition = ['uid' => DI::userSession()->getLocalUserId(), 'uri-id' => $item['author-uri-id']];
+               $condition = ['uid' => $this->userSession->getLocalUserId(), 'uri-id' => $item['author-uri-id']];
                $contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition);
                if (DBA::isResult($contact)) {
                        $cid = $contact['id'];
@@ -379,7 +382,7 @@ class Item
                        }
                }
 
-               if (DI::userSession()->getLocalUserId()) {
+               if ($this->userSession->getLocalUserId()) {
                        $menu = [
                                $this->l10n->t('Follow Thread') => $sub_link,
                                $this->l10n->t('View Status') => $status_link,
@@ -440,7 +443,7 @@ class Item
                return (!($this->activity->match($item['verb'], Activity::FOLLOW) &&
                        $item['object-type'] === Activity\ObjectType::NOTE &&
                        empty($item['self']) &&
-                       $item['uid'] == DI::userSession()->getLocalUserId())
+                       $item['uid'] == $this->userSession->getLocalUserId())
                );
        }