Standards and a new function to fetch content

This commit is contained in:
Michael 2018-06-21 15:14:01 +00:00
parent 5743bb0dae
commit d643e00d33
9 changed files with 59 additions and 25 deletions

View 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;

View 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);

View 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;
}

View 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();
}

View 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"]]);

View 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;

View 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;
}

View 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']) {