More item calls have been replaced with the new functions
This commit is contained in:
parent
41d1f0173a
commit
bb79b8f4ac
|
@ -391,98 +391,6 @@ function visible_activity($item) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SQL query for items
|
|
||||||
*
|
|
||||||
* @param int $uid user id
|
|
||||||
*/
|
|
||||||
function item_query($uid = 0) {
|
|
||||||
return "SELECT " . item_fieldlists() . " FROM `item` " .
|
|
||||||
item_joins($uid) . " WHERE " . item_condition();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief List of all data fields that are needed for displaying items
|
|
||||||
*/
|
|
||||||
function item_fieldlists() {
|
|
||||||
|
|
||||||
/*
|
|
||||||
These Fields are not added below (yet). They are here to for bug search.
|
|
||||||
`item`.`type`,
|
|
||||||
`item`.`extid`,
|
|
||||||
`item`.`changed`,
|
|
||||||
`item`.`moderated`,
|
|
||||||
`item`.`target-type`,
|
|
||||||
`item`.`target`,
|
|
||||||
`item`.`resource-id`,
|
|
||||||
`item`.`tag`,
|
|
||||||
`item`.`inform`,
|
|
||||||
`item`.`pubmail`,
|
|
||||||
`item`.`visible`,
|
|
||||||
`item`.`bookmark`,
|
|
||||||
`item`.`unseen`,
|
|
||||||
`item`.`deleted`,
|
|
||||||
`item`.`forum_mode`,
|
|
||||||
`item`.`mention`,
|
|
||||||
`item`.`global`,
|
|
||||||
`item`.`shadow`,
|
|
||||||
`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
|
|
||||||
`item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
|
|
||||||
*/
|
|
||||||
|
|
||||||
return "`item`.`author-id`,
|
|
||||||
`item`.`owner-id`,
|
|
||||||
`item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
|
|
||||||
`item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`content-warning`,
|
|
||||||
`item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
|
|
||||||
`item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
|
|
||||||
`item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, `item`.`origin`,
|
|
||||||
`item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
|
|
||||||
`item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`,
|
|
||||||
`item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`,
|
|
||||||
`item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
|
|
||||||
`item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
|
|
||||||
|
|
||||||
`author`.`url` AS `author-link`, `author`.`name` AS `author-name`, `author`.`thumb` AS `author-avatar`,
|
|
||||||
`owner`.`url` AS `owner-link`, `owner`.`name` AS `owner-name`, `owner`.`thumb` AS `owner-avatar`,
|
|
||||||
`contact`.`url` AS `contact-link`, `contact`.`name` AS `contact-name`, `contact`.`thumb` AS `contact-avatar`,
|
|
||||||
|
|
||||||
`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
|
|
||||||
`contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`,
|
|
||||||
|
|
||||||
`event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`,
|
|
||||||
`event`.`start` AS `event-start`,`event`.`finish` AS `event-finish`,
|
|
||||||
`event`.`summary` AS `event-summary`,`event`.`desc` AS `event-desc`,
|
|
||||||
`event`.`location` AS `event-location`, `event`.`type` AS `event-type`,
|
|
||||||
`event`.`nofinish` AS `event-nofinish`,`event`.`adjust` AS `event-adjust`,
|
|
||||||
`event`.`ignore` AS `event-ignore`, `event`.`id` AS `event-id`";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SQL join for contacts that are needed for displaying items
|
|
||||||
*
|
|
||||||
* @param int $uid user id
|
|
||||||
*/
|
|
||||||
function item_joins($uid = 0) {
|
|
||||||
return sprintf("STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
|
||||||
AND NOT `contact`.`blocked`
|
|
||||||
AND ((NOT `contact`.`readonly` AND NOT `contact`.`pending` AND (`contact`.`rel` IN (%s, %s)))
|
|
||||||
OR `contact`.`self` OR (`item`.`id` != `item`.`parent`) OR `contact`.`uid` = 0)
|
|
||||||
STRAIGHT_JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` AND NOT `author`.`blocked`
|
|
||||||
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id` AND NOT `owner`.`blocked`
|
|
||||||
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
|
|
||||||
LEFT JOIN `event` ON `event-id` = `event`.`id`",
|
|
||||||
CONTACT_IS_SHARING, CONTACT_IS_FRIEND, intval($uid)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SQL condition for items that are needed for displaying items
|
|
||||||
*/
|
|
||||||
function item_condition() {
|
|
||||||
return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) ";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Render" a conversation or list of items for HTML display.
|
* "Render" a conversation or list of items for HTML display.
|
||||||
* There are two major forms of display:
|
* There are two major forms of display:
|
||||||
|
@ -931,8 +839,6 @@ function item_photo_menu($item) {
|
||||||
$status_link = $profile_link . '?url=status';
|
$status_link = $profile_link . '?url=status';
|
||||||
$photos_link = $profile_link . '?url=photos';
|
$photos_link = $profile_link . '?url=photos';
|
||||||
$profile_link = $profile_link . '?url=profile';
|
$profile_link = $profile_link . '?url=profile';
|
||||||
} else {
|
|
||||||
$profile_link = Contact::magicLink($profile_link);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cid && !$item['self']) {
|
if ($cid && !$item['self']) {
|
||||||
|
|
|
@ -738,14 +738,18 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
|
||||||
// Only act if it is a "real" post
|
// Only act if it is a "real" post
|
||||||
// We need the additional check for the "local_profile" because of mixed situations on connector networks
|
// We need the additional check for the "local_profile" because of mixed situations on connector networks
|
||||||
$item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-id`, `guid`,
|
$item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-id`, `guid`,
|
||||||
`parent-uri`, `uri`, `contact-id`
|
`parent-uri`, `uri`, `contact-id`, `network`
|
||||||
FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
|
FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
|
||||||
NOT (`author-link` IN ($profile_list)) LIMIT 1",
|
NOT (`author-link` IN ($profile_list)) LIMIT 1",
|
||||||
intval($itemid), dbesc(ACTIVITY_POST));
|
intval($itemid), dbesc(ACTIVITY_POST));
|
||||||
if (!$item)
|
if (!$item)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if ($item[0]['network'] != NETWORK_FEED) {
|
||||||
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['author-id']]);
|
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['author-id']]);
|
||||||
|
} else {
|
||||||
|
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['contact-id']]);
|
||||||
|
}
|
||||||
|
|
||||||
// Generate the notification array
|
// Generate the notification array
|
||||||
$params = [];
|
$params = [];
|
||||||
|
|
|
@ -435,28 +435,33 @@ function networkFlatView(App $a, $update = 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($file)) {
|
|
||||||
$sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
|
|
||||||
dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
|
|
||||||
} else {
|
|
||||||
$sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
|
|
||||||
}
|
|
||||||
|
|
||||||
$pager_sql = networkPager($a, $update);
|
$pager_sql = networkPager($a, $update);
|
||||||
|
|
||||||
// show all items unthreaded in reverse created date order
|
if (strlen($file)) {
|
||||||
$items = q("SELECT %s FROM `item` $sql_post_table %s
|
$condition = ["`term` = ? AND `otype` = ? AND `type` = ? AND `uid` = ?",
|
||||||
WHERE %s AND `item`.`uid` = %d
|
$file, TERM_OBJ_POST, TERM_FILE, local_user()];
|
||||||
ORDER BY `item`.`id` DESC $pager_sql ",
|
$params = ['order' => ['tid' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
|
||||||
item_fieldlists(), item_joins(local_user()), item_condition(),
|
$result = dba::select('term', ['oid'], $condition);
|
||||||
intval(local_user())
|
|
||||||
);
|
$posts = [];
|
||||||
|
while ($term = dba::fetch($result)) {
|
||||||
|
$posts[] = $term['oid'];
|
||||||
|
}
|
||||||
|
dba::close($terms);
|
||||||
|
|
||||||
|
$condition = ['uid' => local_user(), 'id' => $posts];
|
||||||
|
} else {
|
||||||
|
$condition = ['uid' => local_user()];
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = ['order' => ['id' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
|
||||||
|
$result = Item::select(local_user(), [], $condition, $params);
|
||||||
|
$items = dba::inArray($result);
|
||||||
|
|
||||||
$condition = ['unseen' => true, 'uid' => local_user()];
|
$condition = ['unseen' => true, 'uid' => local_user()];
|
||||||
networkSetSeen($condition);
|
networkSetSeen($condition);
|
||||||
|
|
||||||
$mode = 'network-new';
|
$o .= networkConversation($a, $items, 'network-new', $update);
|
||||||
$o .= networkConversation($a, $items, $mode, $update);
|
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
}
|
}
|
||||||
|
|
21
mod/ping.php
21
mod/ping.php
|
@ -15,6 +15,7 @@ use Friendica\Core\System;
|
||||||
use Friendica\Database\DBM;
|
use Friendica\Database\DBM;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Group;
|
use Friendica\Model\Group;
|
||||||
|
use Friendica\Model\Item;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Temporal;
|
use Friendica\Util\Temporal;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
@ -127,20 +128,14 @@ function ping_init(App $a)
|
||||||
|
|
||||||
$notifs = ping_get_notifications(local_user());
|
$notifs = ping_get_notifications(local_user());
|
||||||
|
|
||||||
$items_unseen = q(
|
$condition = ["`unseen` AND `uid` = ? AND `contact-id` != ?", local_user(), local_user()];
|
||||||
"SELECT `item`.`id`, `item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`,
|
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||||
`item`.`contact-id`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`,
|
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||||
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`
|
$params = ['order' => ['created' => true]];
|
||||||
FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id` = `item`.`parent`
|
$items = Item::select(local_user(), $fields, $condition, $params);
|
||||||
WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
|
|
||||||
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `pitem`.`parent` != 0
|
|
||||||
AND `item`.`contact-id` != %d
|
|
||||||
ORDER BY `item`.`created` DESC",
|
|
||||||
intval(local_user()),
|
|
||||||
intval(local_user())
|
|
||||||
);
|
|
||||||
|
|
||||||
if (DBM::is_result($items_unseen)) {
|
if (DBM::is_result($items)) {
|
||||||
|
$items_unseen = dba::inArray($items);
|
||||||
$arr = ['items' => $items_unseen];
|
$arr = ['items' => $items_unseen];
|
||||||
Addon::callHooks('network_ping', $arr);
|
Addon::callHooks('network_ping', $arr);
|
||||||
|
|
||||||
|
|
|
@ -238,6 +238,11 @@ class NotificationsManager extends BaseObject
|
||||||
$it['seen'] = ($it['unseen'] > 0 ? false : true);
|
$it['seen'] = ($it['unseen'] > 0 ? false : true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For feed items we use the user's contact, since the avatar is mostly self choosen.
|
||||||
|
if (!empty($it['network']) && $it['network'] == NETWORK_FEED) {
|
||||||
|
$it['author-avatar'] = $it['contact-avatar'];
|
||||||
|
}
|
||||||
|
|
||||||
// Depending on the identifier of the notification we need to use different defaults
|
// Depending on the identifier of the notification we need to use different defaults
|
||||||
switch ($ident) {
|
switch ($ident) {
|
||||||
case 'system':
|
case 'system':
|
||||||
|
@ -399,8 +404,8 @@ class NotificationsManager extends BaseObject
|
||||||
$condition['unseen'] = true;
|
$condition['unseen'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'created',
|
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||||
'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||||
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
|
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
|
||||||
$items = Item::select(local_user(), $fields, $condition, $params);
|
$items = Item::select(local_user(), $fields, $condition, $params);
|
||||||
|
|
||||||
|
@ -484,8 +489,8 @@ class NotificationsManager extends BaseObject
|
||||||
$condition[0] .= " AND `unseen`";
|
$condition[0] .= " AND `unseen`";
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'created',
|
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||||
'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||||
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
|
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
|
||||||
$items = Item::select(local_user(), $fields, $condition, $params);
|
$items = Item::select(local_user(), $fields, $condition, $params);
|
||||||
|
|
||||||
|
@ -524,8 +529,8 @@ class NotificationsManager extends BaseObject
|
||||||
$condition['unseen'] = true;
|
$condition['unseen'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'created',
|
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||||
'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||||
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
|
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
|
||||||
$items = Item::select(local_user(), $fields, $condition, $params);
|
$items = Item::select(local_user(), $fields, $condition, $params);
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ class Item extends BaseObject
|
||||||
$table = "`item` " . self::constructJoins($uid, $select_fields . $condition_string . $param_string, false);
|
$table = "`item` " . self::constructJoins($uid, $select_fields . $condition_string . $param_string, false);
|
||||||
|
|
||||||
$sql = "SELECT " . $select_fields . " FROM " . $table . $condition_string . $param_string;
|
$sql = "SELECT " . $select_fields . " FROM " . $table . $condition_string . $param_string;
|
||||||
//echo $sql;
|
|
||||||
return dba::p($sql, $condition);
|
return dba::p($sql, $condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +160,13 @@ class Item extends BaseObject
|
||||||
*/
|
*/
|
||||||
private static function fieldlist($selected)
|
private static function fieldlist($selected)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
These Fields are not added below. They are here to for bug search.
|
||||||
|
'type', 'extid', 'changed', 'moderated', 'target-type', 'target', 'resource-id',
|
||||||
|
'tag', 'inform', 'pubmail', 'visible', 'bookmark', 'unseen', 'deleted',
|
||||||
|
'forum_mode', 'mention', 'global', 'shadow',
|
||||||
|
*/
|
||||||
|
|
||||||
$item_fields = ['author-id', 'owner-id', 'contact-id', 'uid', 'id', 'parent',
|
$item_fields = ['author-id', 'owner-id', 'contact-id', 'uid', 'id', 'parent',
|
||||||
'uri', 'thr-parent', 'parent-uri', 'content-warning',
|
'uri', 'thr-parent', 'parent-uri', 'content-warning',
|
||||||
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
|
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
|
||||||
|
|
Loading…
Reference in a new issue