]> git.mxchange.org Git - friendica.git/commitdiff
Standards and a new function to fetch content
authorMichael <heluecht@pirati.ca>
Thu, 21 Jun 2018 15:14:01 +0000 (15:14 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 21 Jun 2018 15:14:01 +0000 (15:14 +0000)
include/api.php
include/conversation.php
mod/tagger.php
src/Model/Item.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/OStatus.php
src/Worker/Delivery.php
src/Worker/Notifier.php

index 8b0d0c0d915569b08f3775801912ebd4bc51e05d..a5088756ae20625d8e71b0edd96af539467e5ee0 100644 (file)
@@ -1547,7 +1547,7 @@ function api_search($type)
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
        $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
-       $data['status'] = api_format_items(dba::inArray($statuses), $user_info);
+       $data['status'] = api_format_items(Item::inArray($statuses), $user_info);
 
        return api_format_data("statuses", $type, $data);
 }
@@ -1614,7 +1614,7 @@ function api_statuses_home_timeline($type)
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
        $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
-       $items = dba::inArray($statuses);
+       $items = Item::inArray($statuses);
 
        $ret = api_format_items($items, $user_info, false, $type);
 
@@ -1691,7 +1691,7 @@ function api_statuses_public_timeline($type)
                $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
                $statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
 
-               $r = dba::inArray($statuses);
+               $r = Item::inArray($statuses);
        } else {
                $condition = ["`verb` = ? AND `id` > ? AND NOT `private` AND `wall` AND NOT `user`.`hidewall` AND `item`.`origin`",
                        ACTIVITY_POST, $since_id];
@@ -1708,7 +1708,7 @@ function api_statuses_public_timeline($type)
                $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
                $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
-               $r = dba::inArray($statuses);
+               $r = Item::inArray($statuses);
        }
 
        $ret = api_format_items($r, $user_info, false, $type);
@@ -1767,7 +1767,7 @@ function api_statuses_networkpublic_timeline($type)
        $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
        $statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
 
-       $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
+       $ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
 
        $data = ['status' => $ret];
        switch ($type) {
@@ -1843,7 +1843,7 @@ function api_statuses_show($type)
                throw new BadRequestException("There is no status with this id.");
        }
 
-       $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
+       $ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
 
        if ($conversation) {
                $data = ['status' => $ret];
@@ -1923,7 +1923,7 @@ function api_conversation_show($type)
                throw new BadRequestException("There is no status with id $id.");
        }
 
-       $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
+       $ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
 
        $data = ['status' => $ret];
        return api_format_data("statuses", $type, $data);
@@ -2089,7 +2089,7 @@ function api_statuses_mentions($type)
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
        $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
-       $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
+       $ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
 
        $data = ['status' => $ret];
        switch ($type) {
@@ -2169,7 +2169,7 @@ function api_statuses_user_timeline($type)
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
        $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
-       $ret = api_format_items(dba::inArray($statuses), $user_info, true, $type);
+       $ret = api_format_items(Item::inArray($statuses), $user_info, true, $type);
 
        $data = ['status' => $ret];
        switch ($type) {
@@ -2311,7 +2311,7 @@ function api_favorites($type)
 
                $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
-               $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
+               $ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
        }
 
        $data = ['status' => $ret];
@@ -2728,7 +2728,7 @@ function api_format_items_activities(&$item, $type = "json")
        $condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri']];
        $ret = Item::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
 
-       while ($item = dba::fetch($ret)) {
+       while ($item = Item::fetch($ret)) {
                // not used as result should be structured like other user data
                //builtin_activity_puller($i, $activities);
 
@@ -3117,7 +3117,7 @@ function api_lists_statuses($type)
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
        $statuses = Item::selectForUser(api_user(), [], $condition, $params);
 
-       $items = api_format_items(dba::inArray($statuses), $user_info, false, $type);
+       $items = api_format_items(Item::inArray($statuses), $user_info, false, $type);
 
        $data = ['status' => $items];
        switch ($type) {
@@ -4636,7 +4636,7 @@ function prepare_photo_data($type, $scale, $photo_id)
        $statuses = Item::selectForUser(api_user(), [], $condition);
 
        // prepare output of comments
-       $commentData = api_format_items(dba::inArray($statuses), $user_info, false, $type);
+       $commentData = api_format_items(Item::inArray($statuses), $user_info, false, $type);
        $comments = [];
        if ($type == "xml") {
                $k = 0;
index 5d013014b776c5eaaf0fe80ae788b02c3052ffe8..08220d4bb2c1c9fc541b122d43f29e6000831d9b 100644 (file)
@@ -779,7 +779,7 @@ function conversation_add_children($parents, $block_authors, $order, $uid) {
                }
                $thread_items = Item::selectForUser(local_user(), [], $condition, $params);
 
-               $comments = dba::inArray($thread_items);
+               $comments = Item::inArray($thread_items);
 
                if (count($comments) != 0) {
                        $items = array_merge($items, $comments);
index 6267552636207d8773e50797a4237ab14cdb40a1..717c0947769d47b9fb30bd6101332e4a90c22e47 100644 (file)
@@ -175,7 +175,7 @@ EOT;
        }
 
        // if the original post is on this site, update it.
-       $original_item = Item::selectFirst(['tag','id','uid'], ['origin' => true, 'uri' => $item['uri']]);
+       $original_item = Item::selectFirst(['tag', 'id', 'uid'], ['origin' => true, 'uri' => $item['uri']]);
        if (DBM::is_result($original_item)) {
                $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
                        intval($original_item['uid'])
index f448c6ba7fabcd5428c1460705f4e3108da74bef..d4c5e81704aaf08f5b0e9fae328f5b77380e4e6c 100644 (file)
@@ -56,6 +56,40 @@ class Item extends BaseObject
                        'author-id', 'author-link', 'owner-link', 'contact-uid',
                        'signed_text', 'signature', 'signer'];
 
+       /**
+        * @brief Fetch a single item row
+        *
+        * @param mixed $stmt statement object
+        * @return array current row
+        */
+       public static function fetch($stmt)
+       {
+               $row = dba::fetch($stmt);
+
+               return $row;
+       }
+
+       /**
+        * @brief Fills an array with data from an item query
+        *
+        * @param object $stmt statement object
+        * @return array Data array
+        */
+       public static function inArray($stmt, $do_close = true) {
+               if (is_bool($stmt)) {
+                       return $stmt;
+               }
+
+               $data = [];
+               while ($row = self::fetch($stmt)) {
+                       $data[] = $row;
+               }
+               if ($do_close) {
+                       dba::close($stmt);
+               }
+               return $data;
+       }
+
        /**
         * Retrieve a single record from the item table for a given user and returns it in an associative array
         *
@@ -118,7 +152,7 @@ class Item extends BaseObject
                if (is_bool($result)) {
                        return $result;
                } else {
-                       $row = dba::fetch($result);
+                       $row = self::fetch($result);
                        dba::close($result);
                        return $row;
                }
@@ -225,7 +259,7 @@ class Item extends BaseObject
                if (is_bool($result)) {
                        return $result;
                } else {
-                       $row = dba::fetch($result);
+                       $row = self::fetch($result);
                        dba::close($result);
                        return $row;
                }
index 208eb112c665bebc6f1bfe5b481594eab3a471ff..1047ffdfe282a9584ad0f1fccf18280cd3123af5 100644 (file)
@@ -246,7 +246,7 @@ class DFRN
 
                if (!empty($ids)) {
                        $ret = Item::select(Item::DELIVER_FIELDLIST, ['id' => $ids]);
-                       $items = dba::inArray($ret);
+                       $items = Item::inArray($ret);
                } else {
                        $items = [];
                }
@@ -330,7 +330,7 @@ class DFRN
                }
 
                $ret = Item::select(Item::DELIVER_FIELDLIST, $condition);
-               $items = dba::inArray($ret);
+               $items = Item::inArray($ret);
                if (!DBM::is_result($items)) {
                        killme();
                }
@@ -938,7 +938,7 @@ class DFRN
 
                if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
                        $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
-                       $parent = Item::selectFirst(['guid','plink'], ['uri' => $parent_item, 'uid' => $item['uid']]);
+                       $parent = Item::selectFirst(['guid', 'plink'], ['uri' => $parent_item, 'uid' => $item['uid']]);
                        $attributes = ["ref" => $parent_item, "type" => "text/html",
                                                "href" => $parent['plink'],
                                                "dfrn:diaspora_guid" => $parent['guid']];
index c42e8c24841f78f6e41da81a85cf3100a2023126..29fb42a8089f2ddeb2d30f296f145825d84324d2 100644 (file)
@@ -2218,7 +2218,7 @@ class Diaspora
 
                // Send all existing comments and likes to the requesting server
                $comments = Item::select(['id', 'verb', 'self'], ['parent' => $item['id']]);
-               while ($comment = dba::fetch($comments)) {
+               while ($comment = Item::fetch($comments)) {
                        if ($comment['id'] == $comment['parent']) {
                                continue;
                        }
@@ -2771,7 +2771,7 @@ class Diaspora
                        return false;
                }
 
-               while ($item = dba::fetch($r)) {
+               while ($item = Item::fetch($r)) {
                        // Fetch the parent item
                        $parent = Item::selectFirst(['author-link'], ['id' => $item["parent"]]);
 
index 957f60a2ce5c2ac9d8396f483246def361e42bc6..2c826221e7ad69b8922984ec2baee2f28f7f5417 100644 (file)
@@ -2152,7 +2152,7 @@ class OStatus
                        $ret = Item::select([], $condition, $params);
                }
 
-               $items = dba::inArray($ret);
+               $items = Item::inArray($ret);
 
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
index 15273762ab3808ec7f446be413998cad84ee05bd..e505f4bd705f2da1d84c1f701303f8ae7b6ac289 100644 (file)
@@ -64,7 +64,7 @@ class Delivery extends BaseObject
                        $itemdata = Item::select([], $condition, $params);
 
                        $items = [];
-                       while ($item = dba::fetch($itemdata)) {
+                       while ($item = Item::fetch($itemdata)) {
                                if ($item['id'] == $parent_id) {
                                        $parent = $item;
                                }
index 61b296a26543a2b3c7d40c41f33255a3db876505..fcf36bd55ab41a589a6b49fdddfb0b30e88c92e3 100644 (file)
@@ -124,7 +124,7 @@ class Notifier {
                                return;
                        }
 
-                       $items = dba::inArray($ret);
+                       $items = Item::inArray($ret);
 
                        // avoid race condition with deleting entries
                        if ($items[0]['deleted']) {