]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Merge remote-tracking branch 'upstream/develop' into more-abstraction
[friendica.git] / include / api.php
index 00c2173c38b1b8f4c4297047928e1b8396447f42..1fbdd8f7fc458fbaf7e26f0e51bfed5089d434b0 100644 (file)
@@ -688,59 +688,8 @@ function api_get_user(App $a, $contact_id = null)
 
                $usr = dba::selectFirst('user', ['default-location'], ['uid' => api_user()]);
                $profile = dba::selectFirst('profile', ['about'], ['uid' => api_user(), 'is-default' => true]);
-
-               /// @TODO old-lost code? (twice)
-               // Counting is deactivated by now, due to performance issues
-               // count public wall messages
-               //$r = q("SELECT COUNT(*) as `count` FROM `item` WHERE `uid` = %d AND `wall`",
-               //              intval($uinfo[0]['uid'])
-               //);
-               //$countitms = $r[0]['count'];
-               $countitms = 0;
-       } else {
-               // Counting is deactivated by now, due to performance issues
-               //$r = q("SELECT count(*) as `count` FROM `item`
-               //              WHERE  `contact-id` = %d",
-               //              intval($uinfo[0]['id'])
-               //);
-               //$countitms = $r[0]['count'];
-               $countitms = 0;
-       }
-
-               /// @TODO old-lost code? (twice)
-               /*
-               // Counting is deactivated by now, due to performance issues
-               // count friends
-               $r = q("SELECT count(*) as `count` FROM `contact`
-                               WHERE  `uid` = %d AND `rel` IN ( %d, %d )
-                               AND `self`=0 AND NOT `blocked` AND NOT `pending` AND `hidden`=0",
-                               intval($uinfo[0]['uid']),
-                               intval(CONTACT_IS_SHARING),
-                               intval(CONTACT_IS_FRIEND)
-               );
-               $countfriends = $r[0]['count'];
-
-               $r = q("SELECT count(*) as `count` FROM `contact`
-                               WHERE  `uid` = %d AND `rel` IN ( %d, %d )
-                               AND `self`=0 AND NOT `blocked` AND NOT `pending` AND `hidden`=0",
-                               intval($uinfo[0]['uid']),
-                               intval(CONTACT_IS_FOLLOWER),
-                               intval(CONTACT_IS_FRIEND)
-               );
-               $countfollowers = $r[0]['count'];
-
-               $r = q("SELECT count(*) as `count` FROM item where starred = 1 and uid = %d and deleted = 0",
-                       intval($uinfo[0]['uid'])
-               );
-               $starred = $r[0]['count'];
-
-
-               if (! $uinfo[0]['self']) {
-                       $countfriends = 0;
-                       $countfollowers = 0;
-                       $starred = 0;
-               }
-               */
+       }
+       $countitms = 0;
        $countfriends = 0;
        $countfollowers = 0;
        $starred = 0;
@@ -1626,7 +1575,7 @@ function api_search($type)
        }
 
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
-       $statuses = Item::select(api_user(), [], $condition, $params);
+       $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
        $data['status'] = api_format_items(dba::inArray($statuses), $user_info);
 
@@ -1693,7 +1642,7 @@ function api_statuses_home_timeline($type)
        }
 
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
-       $statuses = Item::select(api_user(), [], $condition, $params);
+       $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
        $items = dba::inArray($statuses);
 
@@ -1770,7 +1719,7 @@ function api_statuses_public_timeline($type)
                }
 
                $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
-               $statuses = Item::selectThread(api_user(), [], $condition, $params);
+               $statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
 
                $r = dba::inArray($statuses);
        } else {
@@ -1787,7 +1736,7 @@ function api_statuses_public_timeline($type)
                }
 
                $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
-               $statuses = Item::select(api_user(), [], $condition, $params);
+               $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
                $r = dba::inArray($statuses);
        }
@@ -1846,7 +1795,7 @@ function api_statuses_networkpublic_timeline($type)
        }
 
        $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
-       $statuses = Item::selectThread(api_user(), [], $condition, $params);
+       $statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
 
        $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
 
@@ -1917,7 +1866,7 @@ function api_statuses_show($type)
                $params = [];
        }
 
-       $statuses = Item::select(api_user(), [], $condition, $params);
+       $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
        /// @TODO How about copying this to above methods which don't check $r ?
        if (!DBM::is_result($statuses)) {
@@ -1998,7 +1947,7 @@ function api_conversation_show($type)
        }
 
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
-       $statuses = Item::select(api_user(), [], $condition, $params);
+       $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
        if (!DBM::is_result($statuses)) {
                throw new BadRequestException("There is no status with id $id.");
@@ -2048,7 +1997,7 @@ function api_statuses_repeat($type)
        logger('API: api_statuses_repeat: '.$id);
 
        $fields = ['body', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
-       $item = Item::selectFirst(api_user(), $fields, ['id' => $id, 'private' => false]);
+       $item = Item::selectFirst($fields, ['id' => $id, 'private' => false]);
 
        if (DBM::is_result($item) && $item['body'] != "") {
                if (strpos($item['body'], "[/share]") !== false) {
@@ -2168,7 +2117,7 @@ function api_statuses_mentions($type)
        }
 
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
-       $statuses = Item::select(api_user(), [], $condition, $params);
+       $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
        $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
 
@@ -2248,7 +2197,7 @@ function api_statuses_user_timeline($type)
        }
 
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
-       $statuses = Item::select(api_user(), [], $condition, $params);
+       $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
        $ret = api_format_items(dba::inArray($statuses), $user_info, true, $type);
 
@@ -2300,7 +2249,7 @@ function api_favorites_create_destroy($type)
                $itemid = intval($_REQUEST['id']);
        }
 
-       $item = Item::selectFirst(api_user(), [], ['id' => $itemid, 'uid' => api_user()]);
+       $item = Item::selectFirstForUser(api_user(), [], ['id' => $itemid, 'uid' => api_user()]);
 
        if (!DBM::is_result($item)) {
                throw new BadRequestException("Invalid item.");
@@ -2390,7 +2339,7 @@ function api_favorites($type)
                        $condition[] = $max_id;
                }
 
-               $statuses = Item::select(api_user(), [], $condition, $params);
+               $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
                $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
        }
@@ -3198,7 +3147,7 @@ function api_lists_statuses($type)
        }
 
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
-       $statuses = Item::select(api_user(), [], $condition, $params);
+       $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
        $items = api_format_items(dba::inArray($statuses), $user_info, false, $type);
 
@@ -4599,7 +4548,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
 function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility = false)
 {
        // get data about the api authenticated user
-       $uri = item_new_uri(get_app()->get_hostname(), intval(api_user()));
+       $uri = Item::newURI(intval(api_user()));
        $owner_record = q("SELECT * FROM `contact` WHERE `uid`= %d AND `self` LIMIT 1", intval(api_user()));
 
        $arr = [];
@@ -4723,7 +4672,7 @@ function prepare_photo_data($type, $scale, $photo_id)
        $condition = ["`parent` = ? AND `uid` = ? AND (`verb` = ? OR `type`='photo')",
                $item[0]['parent'], api_user(), ACTIVITY_POST];
 
-       $statuses = Item::select(api_user(), [], $condition);
+       $statuses = Item::selectForUser(api_user(), [], $condition);
 
        // prepare output of comments
        $commentData = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@@ -5716,7 +5665,7 @@ function api_friendica_notification_seen($type)
        $nm->setSeen($note);
        if ($note['otype']=='item') {
                // would be really better with an ItemsManager and $im->getByID() :-P
-               $item = Item::selectFirst(api_user(), [], ['id' => $note['iid'], 'uid' => api_user()]);
+               $item = Item::selectFirstForUser(api_user(), [], ['id' => $note['iid'], 'uid' => api_user()]);
                if (DBM::is_result($$item)) {
                        // we found the item, return it to the user
                        $ret = api_format_items([$item], $user_info, false, $type);