From: Michael Date: Thu, 21 Jun 2018 15:14:01 +0000 (+0000) Subject: Standards and a new function to fetch content X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d643e00d33883584ff599d92a8929351c6e48503;p=friendica.git Standards and a new function to fetch content --- diff --git a/include/api.php b/include/api.php index 8b0d0c0d91..a5088756ae 100644 --- a/include/api.php +++ b/include/api.php @@ -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; diff --git a/include/conversation.php b/include/conversation.php index 5d013014b7..08220d4bb2 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -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); diff --git a/mod/tagger.php b/mod/tagger.php index 6267552636..717c094776 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -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']) diff --git a/src/Model/Item.php b/src/Model/Item.php index f448c6ba7f..d4c5e81704 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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; } diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 208eb112c6..1047ffdfe2 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -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']]; diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index c42e8c2484..29fb42a808 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -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"]]); diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 957f60a2ce..2c826221e7 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -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; diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 15273762ab..e505f4bd70 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -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; } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 61b296a265..fcf36bd55a 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -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']) {