]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Thread.php
Merge pull request #9577 from annando/updateprofile
[friendica.git] / src / Object / Thread.php
index cd055ee5ebfa4e17eb4cf963219afaca2bfabdd2..6b31ad7049bb2165a629879d3dd05c03ef9e988d 100644 (file)
@@ -1,23 +1,40 @@
 <?php
 /**
- * @file src/Object/Thread.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\Object;
 
-use Friendica\BaseObject;
+use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
-use Friendica\Object\Post;
-
-require_once 'boot.php';
-require_once 'include/text.php';
+use Friendica\DI;
+use Friendica\Protocol\Activity;
+use Friendica\Security\Security;
 
 /**
  * A list of threads
  *
  * We should think about making this a SPL Iterator
  */
-class Thread extends BaseObject
+class Thread
 {
+       /** @var Post[] */
        private $parents = [];
        private $mode = null;
        private $writable = false;
@@ -27,9 +44,10 @@ class Thread extends BaseObject
        /**
         * Constructor
         *
-        * @param string  $mode    The mode
-        * @param boolean $preview Are we in the preview mode?
+        * @param string  $mode     The mode
+        * @param boolean $preview  Are we in the preview mode?
         * @param boolean $writable Override the writable check
+        * @throws \Exception
         */
        public function __construct($mode, $preview, $writable = false)
        {
@@ -40,10 +58,11 @@ class Thread extends BaseObject
        /**
         * Set the mode we'll be displayed on
         *
-        * @param string $mode The mode to set
+        * @param string  $mode     The mode to set
         * @param boolean $writable Override the writable check
         *
         * @return void
+        * @throws \Exception
         */
        private function setMode($mode, $writable)
        {
@@ -51,7 +70,7 @@ class Thread extends BaseObject
                        return;
                }
 
-               $a = self::getApp();
+               $a = DI::app();
 
                switch ($mode) {
                        case 'network':
@@ -60,12 +79,12 @@ class Thread extends BaseObject
                                $this->writable = true;
                                break;
                        case 'profile':
-                               $this->profile_owner = $a->profile['profile_uid'];
-                               $this->writable = can_write_wall($this->profile_owner);
+                               $this->profile_owner = $a->profile['uid'];
+                               $this->writable = Security::canWriteToUserWall($this->profile_owner);
                                break;
                        case 'display':
                                $this->profile_owner = $a->profile['uid'];
-                               $this->writable = can_write_wall($this->profile_owner) || $writable;
+                               $this->writable = Security::canWriteToUserWall($this->profile_owner) || $writable;
                                break;
                        case 'community':
                                $this->profile_owner = 0;
@@ -76,7 +95,7 @@ class Thread extends BaseObject
                                $this->writable = $writable;
                                break;
                        default:
-                               logger('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
+                               Logger::log('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').', Logger::DEBUG);
                                return false;
                                break;
                }
@@ -126,22 +145,23 @@ class Thread extends BaseObject
        /**
         * Add a thread to the conversation
         *
-        * @param object $item The item to insert
+        * @param Post $item The item to insert
         *
         * @return mixed The inserted item on success
         *               false on failure
+        * @throws \Exception
         */
        public function addParent(Post $item)
        {
                $item_id = $item->getId();
 
                if (!$item_id) {
-                       logger('[ERROR] Conversation::addThread : Item has no ID!!', LOGGER_DEBUG);
+                       Logger::log('[ERROR] Conversation::addThread : Item has no ID!!', Logger::DEBUG);
                        return false;
                }
 
                if ($this->getParent($item->getId())) {
-                       logger('[WARN] Conversation::addThread : Thread already exists ('. $item->getId() .').', LOGGER_DEBUG);
+                       Logger::log('[WARN] Conversation::addThread : Thread already exists ('. $item->getId() .').', Logger::DEBUG);
                        return false;
                }
 
@@ -149,12 +169,12 @@ class Thread extends BaseObject
                 * Only add will be displayed
                 */
                if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
-                       logger('[WARN] Conversation::addThread : Thread is a mail ('. $item->getId() .').', LOGGER_DEBUG);
+                       Logger::log('[WARN] Conversation::addThread : Thread is a mail ('. $item->getId() .').', Logger::DEBUG);
                        return false;
                }
 
-               if ($item->getDataValue('verb') === ACTIVITY_LIKE || $item->getDataValue('verb') === ACTIVITY_DISLIKE) {
-                       logger('[WARN] Conversation::addThread : Thread is a (dis)like ('. $item->getId() .').', LOGGER_DEBUG);
+               if ($item->getDataValue('verb') === Activity::LIKE || $item->getDataValue('verb') === Activity::DISLIKE) {
+                       Logger::log('[WARN] Conversation::addThread : Thread is a (dis)like ('. $item->getId() .').', Logger::DEBUG);
                        return false;
                }
 
@@ -169,16 +189,15 @@ class Thread extends BaseObject
         *
         * We should find a way to avoid using those arguments (at least most of them)
         *
-        * @param object $conv_responses data
+        * @param array $conv_responses data
         *
         * @return mixed The data requested on success
         *               false on failure
+        * @throws \Exception
         */
        public function getTemplateData($conv_responses)
        {
-               $a = self::getApp();
                $result = [];
-               $i = 0;
 
                foreach ($this->parents as $item) {
                        if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
@@ -188,7 +207,7 @@ class Thread extends BaseObject
                        $item_data = $item->getTemplateData($conv_responses);
 
                        if (!$item_data) {
-                               logger('[ERROR] Conversation::getTemplateData : Failed to get item template data ('. $item->getId() .').', LOGGER_DEBUG);
+                               Logger::log('[ERROR] Conversation::getTemplateData : Failed to get item template data ('. $item->getId() .').', Logger::DEBUG);
                                return false;
                        }
                        $result[] = $item_data;