Use predefined field lists

This commit is contained in:
Michael 2018-06-17 06:27:52 +00:00
parent 1aec8f620d
commit 0280a46ab4
9 changed files with 54 additions and 40 deletions

View file

@ -1626,7 +1626,7 @@ function api_search($type)
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$data['status'] = api_format_items(dba::inArray($statuses), $user_info); $data['status'] = api_format_items(dba::inArray($statuses), $user_info);
@ -1693,7 +1693,7 @@ function api_statuses_home_timeline($type)
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$items = dba::inArray($statuses); $items = dba::inArray($statuses);
@ -1770,7 +1770,7 @@ function api_statuses_public_timeline($type)
} }
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]]; $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
$statuses = Item::selectThread(api_user(), [], $condition, $params); $statuses = Item::selectThread(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$r = dba::inArray($statuses); $r = dba::inArray($statuses);
} else { } else {
@ -1787,7 +1787,7 @@ function api_statuses_public_timeline($type)
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$r = dba::inArray($statuses); $r = dba::inArray($statuses);
} }
@ -1846,7 +1846,7 @@ function api_statuses_networkpublic_timeline($type)
} }
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]]; $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
$statuses = Item::selectThread(api_user(), [], $condition, $params); $statuses = Item::selectThread(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type); $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@ -1917,7 +1917,7 @@ function api_statuses_show($type)
$params = []; $params = [];
} }
$statuses = Item::select(api_user(), [], $condition, $params); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
/// @TODO How about copying this to above methods which don't check $r ? /// @TODO How about copying this to above methods which don't check $r ?
if (!DBM::is_result($statuses)) { if (!DBM::is_result($statuses)) {
@ -1998,7 +1998,7 @@ function api_conversation_show($type)
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
if (!DBM::is_result($statuses)) { if (!DBM::is_result($statuses)) {
throw new BadRequestException("There is no status with id $id."); throw new BadRequestException("There is no status with id $id.");
@ -2168,7 +2168,7 @@ function api_statuses_mentions($type)
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type); $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@ -2248,7 +2248,7 @@ function api_statuses_user_timeline($type)
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$ret = api_format_items(dba::inArray($statuses), $user_info, true, $type); $ret = api_format_items(dba::inArray($statuses), $user_info, true, $type);
@ -2300,7 +2300,7 @@ function api_favorites_create_destroy($type)
$itemid = intval($_REQUEST['id']); $itemid = intval($_REQUEST['id']);
} }
$item = Item::selectFirst(api_user(), [], ['id' => $itemid, 'uid' => api_user()]); $item = Item::selectFirst(api_user(), Item::DISPLAY_FIELDLIST, ['id' => $itemid, 'uid' => api_user()]);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {
throw new BadRequestException("Invalid item."); throw new BadRequestException("Invalid item.");
@ -2390,7 +2390,7 @@ function api_favorites($type)
$condition[] = $max_id; $condition[] = $max_id;
} }
$statuses = Item::select(api_user(), [], $condition, $params); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type); $ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
} }
@ -3198,7 +3198,7 @@ function api_lists_statuses($type)
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$items = api_format_items(dba::inArray($statuses), $user_info, false, $type); $items = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@ -4723,7 +4723,7 @@ function prepare_photo_data($type, $scale, $photo_id)
$condition = ["`parent` = ? AND `uid` = ? AND (`verb` = ? OR `type`='photo')", $condition = ["`parent` = ? AND `uid` = ? AND (`verb` = ? OR `type`='photo')",
$item[0]['parent'], api_user(), ACTIVITY_POST]; $item[0]['parent'], api_user(), ACTIVITY_POST];
$statuses = Item::select(api_user(), [], $condition); $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $condition);
// prepare output of comments // prepare output of comments
$commentData = api_format_items(dba::inArray($statuses), $user_info, false, $type); $commentData = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@ -5716,7 +5716,7 @@ function api_friendica_notification_seen($type)
$nm->setSeen($note); $nm->setSeen($note);
if ($note['otype']=='item') { if ($note['otype']=='item') {
// would be really better with an ItemsManager and $im->getByID() :-P // would be really better with an ItemsManager and $im->getByID() :-P
$item = Item::selectFirst(api_user(), [], ['id' => $note['iid'], 'uid' => api_user()]); $item = Item::selectFirst(api_user(), Item::DISPLAY_FIELDLIST, ['id' => $note['iid'], 'uid' => api_user()]);
if (DBM::is_result($$item)) { if (DBM::is_result($$item)) {
// we found the item, return it to the user // we found the item, return it to the user
$ret = api_format_items([$item], $user_info, false, $type); $ret = api_format_items([$item], $user_info, false, $type);

View file

@ -788,7 +788,7 @@ function conversation_add_children($parents, $block_authors, $order, $uid) {
if ($block_authors) { if ($block_authors) {
$condition[0] .= "AND NOT `author`.`hidden`"; $condition[0] .= "AND NOT `author`.`hidden`";
} }
$thread_items = Item::select(local_user(), [], $condition, $params); $thread_items = Item::select(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$comments = dba::inArray($thread_items); $comments = dba::inArray($thread_items);

View file

@ -349,7 +349,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
$condition = ["`item`.`parent-uri` = (SELECT `parent-uri` FROM `item` WHERE `id` = ?) $condition = ["`item`.`parent-uri` = (SELECT `parent-uri` FROM `item` WHERE `id` = ?)
AND `item`.`uid` IN (0, ?) " . $sql_extra, $item_id, local_user()]; AND `item`.`uid` IN (0, ?) " . $sql_extra, $item_id, local_user()];
$params = ['order' => ['uid', 'parent' => true, 'gravity', 'id']]; $params = ['order' => ['uid', 'parent' => true, 'gravity', 'id']];
$r = Item::select(local_user(), [], $condition, $params); $r = Item::select(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
if (!DBM::is_result($r)) { if (!DBM::is_result($r)) {
notice(L10n::t('Item not found.') . EOL); notice(L10n::t('Item not found.') . EOL);

View file

@ -455,7 +455,7 @@ function networkFlatView(App $a, $update = 0)
} }
$params = ['order' => ['id' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]]; $params = ['order' => ['id' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
$result = Item::select(local_user(), [], $condition, $params); $result = Item::select(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$items = dba::inArray($result); $items = dba::inArray($result);
$condition = ['unseen' => true, 'uid' => local_user()]; $condition = ['unseen' => true, 'uid' => local_user()];

View file

@ -79,7 +79,7 @@ function notes_content(App $a, $update = false)
dba::close($r); dba::close($r);
$condition = ['uid' => local_user(), 'parent' => $parents_arr]; $condition = ['uid' => local_user(), 'parent' => $parents_arr];
$result = Item::select(local_user(), [], $condition); $result = Item::select(local_user(), Item::DISPLAY_FIELDLIST, $condition);
if (DBM::is_result($result)) { if (DBM::is_result($result)) {
$items = conv_sort(dba::inArray($result), 'commented'); $items = conv_sort(dba::inArray($result), 'commented');
$o .= conversation($a, $items, 'notes', $update); $o .= conversation($a, $items, 'notes', $update);

View file

@ -338,7 +338,7 @@ function profile_content(App $a, $update = 0)
} }
$condition = ['uid' => $a->profile['profile_uid'], 'parent' => $parents_arr]; $condition = ['uid' => $a->profile['profile_uid'], 'parent' => $parents_arr];
$result = Item::select($a->profile['profile_uid'], [], $condition); $result = Item::select($a->profile['profile_uid'], Item::DISPLAY_FIELDLIST, $condition);
$items = conv_sort(dba::inArray($result), 'created'); $items = conv_sort(dba::inArray($result), 'created');
} else { } else {
$items = []; $items = [];

View file

@ -211,7 +211,7 @@ function search_content(App $a) {
} }
dba::close($terms); dba::close($terms);
$items = Item::select(local_user(), [], ['id' => array_reverse($itemids)]); $items = Item::select(local_user(), Item::DISPLAY_FIELDLIST, ['id' => array_reverse($itemids)]);
$r = dba::inArray($items); $r = dba::inArray($items);
} else { } else {
logger("Start fulltext search for '".$search."'", LOGGER_DEBUG); logger("Start fulltext search for '".$search."'", LOGGER_DEBUG);
@ -221,7 +221,7 @@ function search_content(App $a) {
local_user(), $search]; local_user(), $search];
$params = ['order' => ['id' => true], $params = ['order' => ['id' => true],
'limit' => [$a->pager['start'], $a->pager['itemspage']]]; 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
$items = Item::select(local_user(), [], $condition, $params); $items = Item::select(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$r = dba::inArray($items); $r = dba::inArray($items);
} }

View file

@ -1068,7 +1068,7 @@ class Contact extends BaseObject
$author_id, ACTIVITY_POST, local_user()]; $author_id, ACTIVITY_POST, local_user()];
$params = ['order' => ['created' => true], $params = ['order' => ['created' => true],
'limit' => [$a->pager['start'], $a->pager['itemspage']]]; 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
$r = Item::select(local_user(), [], $condition, $params); $r = Item::select(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$items = dba::inArray($r); $items = dba::inArray($r);

View file

@ -33,6 +33,29 @@ require_once 'include/text.php';
class Item extends BaseObject class Item extends BaseObject
{ {
// Field list that is used to display the items
const DISPLAY_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid',
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'attach',
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'item_id', 'item_network',
'author-id', 'author-link', 'author-name', 'author-avatar',
'owner-id', 'owner-link', 'owner-name', 'owner-avatar',
'contact-id', 'contact-link', 'contact-name', 'contact-avatar',
'network', 'url', 'name', 'writable', 'self', 'cid', 'alias',
'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
'event-summary', 'event-desc', 'event-location', 'event-type',
'event-nofinish', 'event-adjust', 'event-ignore', 'event-id'];
// Field list that is used to deliver items via the protocols
const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid',
'created', 'edited', 'verb', 'object-type', 'object', 'target',
'private', 'title', 'body', 'location', 'coord', 'app',
'attach', 'tag', 'bookmark', 'deleted', 'extid',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'author-id', 'author-link', 'owner-link', 'contact-uid',
'signed_text', 'signature', 'signer'];
/** /**
* Retrieve a single record from the item table and returns it in an associative array * Retrieve a single record from the item table and returns it in an associative array
* *
@ -170,22 +193,15 @@ class Item extends BaseObject
'guid', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'event-id', 'guid', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'event-id',
'location', 'coord', 'app', 'attach', 'rendered-hash', 'rendered-html', 'object', 'location', 'coord', 'app', 'attach', 'rendered-hash', 'rendered-html', 'object',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'id' => 'item_id', 'network' => 'item_network']; 'id' => 'item_id', 'network' => 'item_network',
'type', 'extid', 'changed', 'moderated', 'target-type', 'target',
// The additional fields aren't needed to be selected by default.
// We need them to select the correct tables. To see the difference we split the arrays
if (!empty($selected)) {
$additional_item_fields = ['type', 'extid', 'changed', 'moderated', 'target-type', 'target',
'resource-id', 'tag', 'inform', 'pubmail', 'visible', 'bookmark', 'unseen', 'deleted', 'resource-id', 'tag', 'inform', 'pubmail', 'visible', 'bookmark', 'unseen', 'deleted',
'forum_mode', 'mention', 'global', 'shadow']; 'forum_mode', 'mention', 'global', 'shadow'];
$item_fields = array_merge($item_fields, $additional_item_fields);
}
$author_fields = ['url' => 'author-link', 'name' => 'author-name', 'thumb' => 'author-avatar']; $author_fields = ['url' => 'author-link', 'name' => 'author-name', 'thumb' => 'author-avatar'];
$owner_fields = ['url' => 'owner-link', 'name' => 'owner-name', 'thumb' => 'owner-avatar']; $owner_fields = ['url' => 'owner-link', 'name' => 'owner-name', 'thumb' => 'owner-avatar'];
$contact_fields = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar', $contact_fields = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar',
'network', 'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias', 'network', 'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias', 'uid' => 'contact-uid',
'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id']; 'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id'];
$event_fields = ['created' => 'event-created', 'edited' => 'event-edited', $event_fields = ['created' => 'event-created', 'edited' => 'event-edited',
@ -198,11 +214,9 @@ class Item extends BaseObject
$fields = ['item' => $item_fields, 'author' => $author_fields, 'owner' => $owner_fields, $fields = ['item' => $item_fields, 'author' => $author_fields, 'owner' => $owner_fields,
'contact' => $contact_fields, 'event' => $event_fields]; 'contact' => $contact_fields, 'event' => $event_fields];
if (!empty($selected)) {
$fields['parent-item'] = ['guid' => 'parent-guid']; $fields['parent-item'] = ['guid' => 'parent-guid'];
$fields['parent-item-author'] = ['url' => 'parent-author-link', 'name' => 'parent-author-name']; $fields['parent-item-author'] = ['url' => 'parent-author-link', 'name' => 'parent-author-name'];
$fields['sign'] = ['signed_text', 'signature', 'signer']; $fields['sign'] = ['signed_text', 'signature', 'signer'];
}
return $fields; return $fields;
} }