]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Merge pull request #5776 from annando/fix-contact
[friendica.git] / src / Model / Item.php
index b9c88bca8650111f6703a8c6762ea70ac9270aaf..d10a211a59511d98b579583d748c2ff004471a4f 100644 (file)
@@ -111,7 +111,7 @@ class Item extends BaseObject
         * @param string $activity activity string
         * @return integer Activity index
         */
-       private static function activityToIndex($activity)
+       public static function activityToIndex($activity)
        {
                $index = array_search($activity, self::ACTIVITIES);
 
@@ -584,7 +584,13 @@ class Item extends BaseObject
                } else {
                        $master_table = "`item`";
                }
-               return "$master_table.`visible` AND NOT $master_table.`deleted` AND NOT $master_table.`moderated` AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) ";
+               return sprintf("$master_table.`visible` AND NOT $master_table.`deleted` AND NOT $master_table.`moderated`
+                       AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
+                       AND (`user-author`.`blocked` IS NULL OR NOT `user-author`.`blocked`)
+                       AND (`user-author`.`ignored` IS NULL OR NOT `user-author`.`ignored` OR `item`.`gravity` != %d)
+                       AND (`user-owner`.`blocked` IS NULL OR NOT `user-owner`.`blocked`)
+                       AND (`user-owner`.`ignored` IS NULL OR NOT `user-owner`.`ignored` OR `item`.`gravity` != %d) ",
+                       GRAVITY_PARENT, GRAVITY_PARENT);
        }
 
        /**
@@ -615,8 +621,10 @@ class Item extends BaseObject
                                OR `contact`.`self` OR `item`.`gravity` != %d OR `contact`.`uid` = 0)
                                STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = $master_table.`author-id` AND NOT `author`.`blocked`
                                STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = $master_table.`owner-id` AND NOT `owner`.`blocked`
-                               LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d",
-                               Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid));
+                               LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d
+                               LEFT JOIN `user-contact` AS `user-author` ON `user-author`.`cid` = $master_table.`author-id` AND `user-author`.`uid` = %d
+                               LEFT JOIN `user-contact` AS `user-owner` ON `user-owner`.`cid` = $master_table.`owner-id` AND `user-owner`.`uid` = %d",
+                               Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid), intval($uid), intval($uid));
                } else {
                        if (strpos($sql_commands, "`contact`.") !== false) {
                                $joins .= "LEFT JOIN `contact` ON `contact`.`id` = $master_table.`contact-id`";
@@ -1454,15 +1462,6 @@ class Item extends BaseObject
                        return 0;
                }
 
-               // These fields aren't stored anymore in the item table, they are fetched upon request
-               unset($item['author-link']);
-               unset($item['author-name']);
-               unset($item['author-avatar']);
-
-               unset($item['owner-link']);
-               unset($item['owner-name']);
-               unset($item['owner-avatar']);
-
                if ($item['network'] == Protocol::PHANTOM) {
                        logger('Missing network. Called by: '.System::callstack(), LOGGER_DEBUG);
 
@@ -1700,6 +1699,15 @@ class Item extends BaseObject
                unset($item['postopts']);
                unset($item['inform']);
 
+               // These fields aren't stored anymore in the item table, they are fetched upon request
+               unset($item['author-link']);
+               unset($item['author-name']);
+               unset($item['author-avatar']);
+
+               unset($item['owner-link']);
+               unset($item['owner-name']);
+               unset($item['owner-avatar']);
+
                DBA::transaction();
                $ret = DBA::insert('item', $item);
 
@@ -2456,6 +2464,12 @@ class Item extends BaseObject
                }
        }
 
+       /**
+        * 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
+        */
        public static function getIdAndNickByGuid($guid, $uid = 0)
        {
                $nick = "";
@@ -2467,28 +2481,28 @@ class Item extends BaseObject
 
                // Does the given user have this item?
                if ($uid) {
-                       /// @todo This query has to be abstracted for the "uri-id" changes
-                       $item = DBA::fetchFirst("SELECT `item`.`id`, `user`.`nickname` FROM `item`
-                               INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
-                               WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
-                                       AND `item`.`guid` = ? AND `item`.`uid` = ?", $guid, $uid);
+                       $item = self::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
                        if (DBA::isResult($item)) {
-                               $id = $item["id"];
-                               $nick = $item["nickname"];
+                               $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 == "") {
-                       /// @todo This query has to be abstracted for the "uri-id" changes
-                       $item = DBA::fetchFirst("SELECT `item`.`id`, `user`.`nickname` FROM `item`
-                               INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
-                               WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
-                                       AND NOT `item`.`private` AND `item`.`wall`
-                                       AND `item`.`guid` = ?", $guid);
+                       $condition = ["`guid` = ? AND `uid` != 0", $guid];
+                       $item = self::selectFirst(['id', 'uid'], $condition);
                        if (DBA::isResult($item)) {
-                               $id = $item["id"];
-                               $nick = $item["nickname"];
+                               $user = DBA::selectFirst('user', ['nickname'], ['uid' => $item['uid']]);
+                               if (!DBA::isResult($user)) {
+                                       return;
+                               }
+                               $id = $item['id'];
+                               $nick = $user['nickname'];
                        }
                }
                return ["nick" => $nick, "id" => $id];
@@ -3177,8 +3191,7 @@ class Item extends BaseObject
                        return;
                }
 
-               // Using dba::delete at this time could delete the associated item entries
-               $result = DBA::e("DELETE FROM `thread` WHERE `iid` = ?", $itemid);
+               $result = DBA::delete('thread', ['iid' => $itemid], ['cascade' => false]);
 
                logger("deleteThread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG);