diff --git a/include/api.php b/include/api.php
index c89a5b164..8b0d0c0d9 100644
--- a/include/api.php
+++ b/include/api.php
@@ -688,59 +688,8 @@ function api_get_user(App $a, $contact_id = null)
$usr = dba::selectFirst('user', ['default-location'], ['uid' => api_user()]);
$profile = dba::selectFirst('profile', ['about'], ['uid' => api_user(), 'is-default' => true]);
-
- /// @TODO old-lost code? (twice)
- // Counting is deactivated by now, due to performance issues
- // count public wall messages
- //$r = q("SELECT COUNT(*) as `count` FROM `item` WHERE `uid` = %d AND `wall`",
- // intval($uinfo[0]['uid'])
- //);
- //$countitms = $r[0]['count'];
- $countitms = 0;
- } else {
- // Counting is deactivated by now, due to performance issues
- //$r = q("SELECT count(*) as `count` FROM `item`
- // WHERE `contact-id` = %d",
- // intval($uinfo[0]['id'])
- //);
- //$countitms = $r[0]['count'];
- $countitms = 0;
}
-
- /// @TODO old-lost code? (twice)
- /*
- // Counting is deactivated by now, due to performance issues
- // count friends
- $r = q("SELECT count(*) as `count` FROM `contact`
- WHERE `uid` = %d AND `rel` IN ( %d, %d )
- AND `self`=0 AND NOT `blocked` AND NOT `pending` AND `hidden`=0",
- intval($uinfo[0]['uid']),
- intval(CONTACT_IS_SHARING),
- intval(CONTACT_IS_FRIEND)
- );
- $countfriends = $r[0]['count'];
-
- $r = q("SELECT count(*) as `count` FROM `contact`
- WHERE `uid` = %d AND `rel` IN ( %d, %d )
- AND `self`=0 AND NOT `blocked` AND NOT `pending` AND `hidden`=0",
- intval($uinfo[0]['uid']),
- intval(CONTACT_IS_FOLLOWER),
- intval(CONTACT_IS_FRIEND)
- );
- $countfollowers = $r[0]['count'];
-
- $r = q("SELECT count(*) as `count` FROM item where starred = 1 and uid = %d and deleted = 0",
- intval($uinfo[0]['uid'])
- );
- $starred = $r[0]['count'];
-
-
- if (! $uinfo[0]['self']) {
- $countfriends = 0;
- $countfollowers = 0;
- $starred = 0;
- }
- */
+ $countitems = 0;
$countfriends = 0;
$countfollowers = 0;
$starred = 0;
@@ -790,7 +739,7 @@ function api_get_user(App $a, $contact_id = null)
'time_zone' => 'UTC',
'geo_enabled' => false,
'verified' => true,
- 'statuses_count' => intval($countitms),
+ 'statuses_count' => intval($countitems),
'lang' => '',
'contributors_enabled' => false,
'is_translator' => false,
@@ -1173,18 +1122,8 @@ function api_statuses_update($type)
if ($throttle_day > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
- $r = q(
- "SELECT COUNT(*) AS `posts_day` FROM `item` WHERE `uid`=%d AND `wall`
- AND `created` > '%s' AND `id` = `parent`",
- intval(api_user()),
- dbesc($datefrom)
- );
-
- if (DBM::is_result($r)) {
- $posts_day = $r[0]["posts_day"];
- } else {
- $posts_day = 0;
- }
+ $condition = ["`uid` = ? AND `wall` AND `created` > ? AND `id` = `parent`", api_user(), $datefrom];
+ $posts_day = dba::count('item', $condition);
if ($posts_day > $throttle_day) {
logger('Daily posting limit reached for user '.api_user(), LOGGER_DEBUG);
@@ -1197,18 +1136,8 @@ function api_statuses_update($type)
if ($throttle_week > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
- $r = q(
- "SELECT COUNT(*) AS `posts_week` FROM `item` WHERE `uid`=%d AND `wall`
- AND `created` > '%s' AND `id` = `parent`",
- intval(api_user()),
- dbesc($datefrom)
- );
-
- if (DBM::is_result($r)) {
- $posts_week = $r[0]["posts_week"];
- } else {
- $posts_week = 0;
- }
+ $condition = ["`uid` = ? AND `wall` AND `created` > ? AND `id` = `parent`", api_user(), $datefrom];
+ $posts_week = dba::count('item', $condition);
if ($posts_week > $throttle_week) {
logger('Weekly posting limit reached for user '.api_user(), LOGGER_DEBUG);
@@ -1221,18 +1150,8 @@ function api_statuses_update($type)
if ($throttle_month > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
- $r = q(
- "SELECT COUNT(*) AS `posts_month` FROM `item` WHERE `uid`=%d AND `wall`
- AND `created` > '%s' AND `id` = `parent`",
- intval(api_user()),
- dbesc($datefrom)
- );
-
- if (DBM::is_result($r)) {
- $posts_month = $r[0]["posts_month"];
- } else {
- $posts_month = 0;
- }
+ $condition = ["`uid` = ? AND `wall` AND `created` > ? AND `id` = `parent`", api_user(), $datefrom];
+ $posts_month = dba::count('item', $condition);
if ($posts_month > $throttle_month) {
logger('Monthly posting limit reached for user '.api_user(), LOGGER_DEBUG);
@@ -2806,20 +2725,16 @@ function api_format_items_activities(&$item, $type = "json")
'attendmaybe' => [],
];
- $items = q(
- 'SELECT * FROM `item`
- WHERE `uid` = %d AND `thr-parent` = "%s" AND `visible` AND NOT `deleted`',
- intval($item['uid']),
- dbesc($item['uri'])
- );
+ $condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri']];
+ $ret = Item::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
- foreach ($items as $i) {
+ while ($item = dba::fetch($ret)) {
// not used as result should be structured like other user data
//builtin_activity_puller($i, $activities);
// get user data and add it to the array of the activity
- $user = api_get_user($a, $i['author-id']);
- switch ($i['verb']) {
+ $user = api_get_user($a, $item['author-id']);
+ switch ($item['verb']) {
case ACTIVITY_LIKE:
$activities['like'][] = $user;
break;
@@ -2840,6 +2755,8 @@ function api_format_items_activities(&$item, $type = "json")
}
}
+ dba::close($ret);
+
if ($type == "xml") {
$xml_activities = [];
foreach ($activities as $k => $v) {
@@ -3924,16 +3841,13 @@ function api_fr_photoalbum_delete($type)
// function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
// to the user and the contacts of the users (drop_items() performs the federation of the deletion to other networks
foreach ($r as $rr) {
- $photo_item = q(
- "SELECT `id` FROM `item` WHERE `uid` = %d AND `resource-id` = '%s' AND `type` = 'photo'",
- intval(local_user()),
- dbesc($rr['resource-id'])
- );
+ $condition = ['uid' => local_user(), 'resource-id' => $rr['resource-id'], 'type' => 'photo'];
+ $photo_item = Item::selectFirstForUser(local_user(), ['id'], $condition);
if (!DBM::is_result($photo_item)) {
throw new InternalServerErrorException("problem with deleting items occured");
}
- Item::deleteForUser(['id' => $photo_item[0]['id']], api_user());
+ Item::deleteForUser(['id' => $photo_item['id']], api_user());
}
// now let's delete all photos from the album
@@ -4214,18 +4128,15 @@ function api_fr_photo_delete($type)
// return success of deletion or error message
if ($result) {
// retrieve the id of the parent element (the photo element)
- $photo_item = q(
- "SELECT `id` FROM `item` WHERE `uid` = %d AND `resource-id` = '%s' AND `type` = 'photo'",
- intval(local_user()),
- dbesc($photo_id)
- );
+ $condition = ['uid' => local_user(), 'resource-id' => $photo_id, 'type' => 'photo'];
+ $photo_item = Item::selectFirstForUser(local_user(), ['id'], $condition);
if (!DBM::is_result($photo_item)) {
throw new InternalServerErrorException("problem with deleting items occured");
}
// function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
// to the user and the contacts of the users (drop_items() do all the necessary magic to avoid orphans in database and federate deletion)
- Item::deleteForUser(['id' => $photo_item[0]['id']], api_user());
+ Item::deleteForUser(['id' => $photo_item['id']], api_user());
$answer = ['result' => 'deleted', 'message' => 'photo with id `' . $photo_id . '` has been deleted from server.'];
return api_format_data("photo_delete", $type, ['$result' => $answer]);
@@ -4713,12 +4624,10 @@ function prepare_photo_data($type, $scale, $photo_id)
}
// retrieve item element for getting activities (like, dislike etc.) related to photo
- $item = q(
- "SELECT * FROM `item` WHERE `uid` = %d AND `resource-id` = '%s' AND `type` = 'photo'",
- intval(local_user()),
- dbesc($photo_id)
- );
- $data['photo']['friendica_activities'] = api_format_items_activities($item[0], $type);
+ $condition = ['uid' => local_user(), 'resource-id' => $photo_id, 'type' => 'photo'];
+ $item = Item::selectFirstForUser(local_user(), ['id'], $condition);
+
+ $data['photo']['friendica_activities'] = api_format_items_activities($item, $type);
// retrieve comments on photo
$condition = ["`parent` = ? AND `uid` = ? AND (`verb` = ? OR `type`='photo')",
@@ -5013,35 +4922,26 @@ function api_in_reply_to($item)
$in_reply_to['screen_name'] = null;
if (($item['thr-parent'] != $item['uri']) && (intval($item['parent']) != intval($item['id']))) {
- $r = q(
- "SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
- intval($item['uid']),
- dbesc($item['thr-parent'])
- );
-
- if (DBM::is_result($r)) {
- $in_reply_to['status_id'] = intval($r[0]['id']);
+ $parent = Item::selectFirst(['id'], ['uid' => $item['uid'], 'uri' => $item['thr-parent']]);
+ if (DBM::is_result($parent)) {
+ $in_reply_to['status_id'] = intval($parent['id']);
} else {
$in_reply_to['status_id'] = intval($item['parent']);
}
$in_reply_to['status_id_str'] = (string) intval($in_reply_to['status_id']);
- $r = q(
- "SELECT `contact`.`nick`, `contact`.`name`, `contact`.`id`, `contact`.`url` FROM `item`
- STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`author-id`
- WHERE `item`.`id` = %d LIMIT 1",
- intval($in_reply_to['status_id'])
- );
+ $fields = ['author-nick', 'author-name', 'author-id', 'author-link'];
+ $parent = Item::selectFirst($fields, ['id' => $in_reply_to['status_id']]);
- if (DBM::is_result($r)) {
- if ($r[0]['nick'] == "") {
- $r[0]['nick'] = api_get_nick($r[0]["url"]);
+ if (DBM::is_result($parent)) {
+ if ($parent['author-nick'] == "") {
+ $parent['author-nick'] = api_get_nick($parent['author-link']);
}
- $in_reply_to['screen_name'] = (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']);
- $in_reply_to['user_id'] = intval($r[0]['id']);
- $in_reply_to['user_id_str'] = (string) intval($r[0]['id']);
+ $in_reply_to['screen_name'] = (($parent['author-nick']) ? $parent['author-nick'] : $parent['author-name']);
+ $in_reply_to['user_id'] = intval($parent['author-id']);
+ $in_reply_to['user_id_str'] = (string) intval($parent['author-id']);
}
// There seems to be situation, where both fields are identical:
diff --git a/include/conversation.php b/include/conversation.php
index 97be7e9aa..6ef2e73aa 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -633,16 +633,12 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
$location_e = $location;
$owner_name_e = $owner_name;
- if ($item['item_network'] == "") {
- $item['item_network'] = $item['network'];
- }
-
$tmp_item = [
'template' => $tpl,
'id' => (($preview) ? 'P0' : $item['item_id']),
'guid' => (($preview) ? 'Q0' : $item['guid']),
- 'network' => $item['item_network'],
- 'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link),
+ 'network' => $item['network'],
+ 'network_name' => ContactSelector::networkToName($item['network'], $profile_link),
'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
'profile_url' => $profile_link,
'item_photo_menu' => item_photo_menu($item),
@@ -688,7 +684,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
Addon::callHooks('display_item', $arr);
$threads[$threadsid]['id'] = $item['item_id'];
- $threads[$threadsid]['network'] = $item['item_network'];
+ $threads[$threadsid]['network'] = $item['network'];
$threads[$threadsid]['items'] = [$arr['output']];
}
diff --git a/include/items.php b/include/items.php
index c54869c3e..ee514c8fc 100644
--- a/include/items.php
+++ b/include/items.php
@@ -335,17 +335,14 @@ function drop_item($id) {
// locate item to be deleted
- $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
- intval($id)
- );
+ $fields = ['id', 'uid', 'contact-id', 'deleted'];
+ $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $id]);
- if (!DBM::is_result($r)) {
+ if (!DBM::is_result($item)) {
notice(L10n::t('Item not found.') . EOL);
goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
}
- $item = $r[0];
-
if ($item['deleted']) {
return 0;
}
@@ -364,7 +361,6 @@ function drop_item($id) {
}
if ((local_user() == $item['uid']) || $contact_id) {
-
// Check if we should do HTML-based delete confirmation
if ($_REQUEST['confirm']) {
//
';
return $o;
-
}
diff --git a/mod/viewsrc.php b/mod/viewsrc.php
index d2f0d01a0..087b9f3d2 100644
--- a/mod/viewsrc.php
+++ b/mod/viewsrc.php
@@ -5,38 +5,33 @@
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Database\DBM;
+use Friendica\Model\Item;
-function viewsrc_content(App $a) {
-
- if (! local_user()) {
+function viewsrc_content(App $a)
+{
+ if (!local_user()) {
notice(L10n::t('Access denied.') . EOL);
return;
}
- $o = '';
+ $o = '';
$item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
- if(! $item_id) {
+ if (!$item_id) {
$a->error = 404;
notice(L10n::t('Item not found.') . EOL);
return;
}
- $r = q("SELECT `item`.`body` FROM `item`
- WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
- and `item`.`moderated` = 0
- AND `item`.`id` = '%s' LIMIT 1",
- intval(local_user()),
- dbesc($item_id)
- );
+ $item = Item::selectFirst(['body'], ['uid' => local_user(), 'id' => $item_id]);
- if (DBM::is_result($r))
- if(is_ajax()) {
- echo str_replace("\n",'
',$r[0]['body']);
+ if (DBM::is_result($item)) {
+ if (is_ajax()) {
+ echo str_replace("\n", '
', $item['body']);
killme();
} else {
- $o .= str_replace("\n",'
',$r[0]['body']);
+ $o .= str_replace("\n", '
', $item['body']);
}
+ }
return $o;
}
-
diff --git a/src/Model/Item.php b/src/Model/Item.php
index dcf944cc4..c3b759f65 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -38,8 +38,8 @@ class Item extends BaseObject
'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',
+ 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'item_id',
+ 'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
'owner-id', 'owner-link', 'owner-name', 'owner-avatar',
'contact-id', 'contact-link', 'contact-name', 'contact-avatar',
'network', 'url', 'name', 'writable', 'self', 'cid', 'alias',
@@ -164,21 +164,63 @@ class Item extends BaseObject
return dba::p($sql, $condition);
}
+ /**
+ * @brief Select rows from the starting post in the item table
+ *
+ * @param integer $uid User ID
+ * @param array $fields Array of selected fields, empty for all
+ * @param array $condition Array of fields for condition
+ * @param array $params Array of several parameters
+ *
+ * @return boolean|object
+ */
+ public static function selectThreadForUser($uid, array $selected = [], array $condition = [], $params = [])
+ {
+ $params['uid'] = $uid;
+
+ if (empty($selected)) {
+ $selected = Item::DISPLAY_FIELDLIST;
+ }
+
+ return self::selectThread($selected, $condition, $params);
+ }
+
/**
* Retrieve a single record from the starting post in the item table and returns it in an associative array
*
* @brief Retrieve a single record from a table
* @param integer $uid User ID
+ * @param array $selected
+ * @param array $condition
+ * @param array $params
+ * @return bool|array
+ * @see dba::select
+ */
+ public static function selectFirstThreadForUser($uid, array $selected = [], array $condition = [], $params = [])
+ {
+ $params['uid'] = $uid;
+
+ if (empty($selected)) {
+ $selected = Item::DISPLAY_FIELDLIST;
+ }
+
+ return self::selectFirstThread($selected, $condition, $params);
+ }
+
+ /**
+ * Retrieve a single record from the starting post in the item table and returns it in an associative array
+ *
+ * @brief Retrieve a single record from a table
* @param array $fields
* @param array $condition
* @param array $params
* @return bool|array
* @see dba::select
*/
- public static function selectFirstThreadForUser($uid, array $fields = [], array $condition = [], $params = [])
+ public static function selectFirstThread(array $fields = [], array $condition = [], $params = [])
{
$params['limit'] = 1;
- $result = self::selectThreadForUser($uid, $fields, $condition, $params);
+ $result = self::selectThread($fields, $condition, $params);
if (is_bool($result)) {
return $result;
@@ -192,17 +234,20 @@ class Item extends BaseObject
/**
* @brief Select rows from the starting post in the item table
*
- * @param integer $uid User ID
- * @param array $fields Array of selected fields, empty for all
+ * @param array $selected Array of selected fields, empty for all
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters
*
* @return boolean|object
*/
- public static function selectThreadForUser($uid, array $selected = [], array $condition = [], $params = [])
+ public static function selectThread(array $selected = [], array $condition = [], $params = [])
{
- if (empty($selected)) {
- $selected = Item::DISPLAY_FIELDLIST;
+ $uid = 0;
+ $usermode = false;
+
+ if (isset($params['uid'])) {
+ $uid = $params['uid'];
+ $usermode = true;
}
$fields = self::fieldlist($selected);
@@ -219,7 +264,9 @@ class Item extends BaseObject
$condition_string = self::addTablesToFields($condition_string, $threadfields);
$condition_string = self::addTablesToFields($condition_string, $fields);
- $condition_string = $condition_string . ' AND ' . self::condition(true);
+ if ($usermode) {
+ $condition_string = $condition_string . ' AND ' . self::condition(true);
+ }
$param_string = dba::buildParameter($params);
$param_string = self::addTablesToFields($param_string, $threadfields);
@@ -250,17 +297,19 @@ class Item extends BaseObject
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention',
'rendered-hash', 'rendered-html', 'global', 'shadow', 'content-warning',
- 'id' => 'item_id', 'network' => 'item_network'];
+ 'id' => 'item_id', 'network'];
- $fields['author'] = ['url' => 'author-link', 'name' => 'author-name', 'thumb' => 'author-avatar'];
+ $fields['author'] = ['url' => 'author-link', 'name' => 'author-name',
+ 'thumb' => 'author-avatar', 'nick' => 'author-nick', 'network' => 'author-network'];
- $fields['owner'] = ['url' => 'owner-link', 'name' => 'owner-name', 'thumb' => 'owner-avatar'];
+ $fields['owner'] = ['url' => 'owner-link', 'name' => 'owner-name',
+ 'thumb' => 'owner-avatar', 'nick' => 'owner-nick', 'network' => 'owner-network'];
$fields['contact'] = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar',
'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', 'network' => 'contact-network'];
- $fields['parent-item'] = ['guid' => 'parent-guid'];
+ $fields['parent-item'] = ['guid' => 'parent-guid', 'network' => 'parent-network'];
$fields['parent-item-author'] = ['url' => 'parent-author-link', 'name' => 'parent-author-name'];
diff --git a/src/Model/Term.php b/src/Model/Term.php
index fd44603f9..0de2eddf4 100644
--- a/src/Model/Term.php
+++ b/src/Model/Term.php
@@ -6,6 +6,7 @@ namespace Friendica\Model;
use Friendica\Core\System;
use Friendica\Database\DBM;
+use Friendica\Model\Item;
use dba;
require_once 'boot.php';
@@ -114,7 +115,7 @@ class Term
$users = q("SELECT `uid` FROM `contact` WHERE self AND (`url` = '%s' OR `nurl` = '%s')", $link, $link);
foreach ($users AS $user) {
if ($user['uid'] == $message['uid']) {
- dba::update('item', ['mention' => true], ['id' => $itemid]);
+ Item::update(['mention' => true], ['id' => $itemid]);
dba::update('thread', ['mention' => true], ['iid' => $message['parent']]);
}
}
diff --git a/src/Model/User.php b/src/Model/User.php
index 39c544c3a..76769e14c 100644
--- a/src/Model/User.php
+++ b/src/Model/User.php
@@ -65,6 +65,21 @@ class User
return $r;
}
+ /**
+ * @brief Get owner data by nick name
+ *
+ * @param int $nick
+ * @return boolean|array
+ */
+ public static function getOwnerDataByNick($nick)
+ {
+ $user = dba::selectFirst('user', ['uid'], ['nickname' => $nick]);
+ if (!DBM::is_result($user)) {
+ return false;
+ }
+ return self::getOwnerDataById($user['uid']);
+ }
+
/**
* @brief Returns the default group for a given user and network
*
diff --git a/src/Object/Post.php b/src/Object/Post.php
index a66e48a38..bceee3844 100644
--- a/src/Object/Post.php
+++ b/src/Object/Post.php
@@ -326,17 +326,17 @@ class Post extends BaseObject
$owner_name_e = $this->getOwnerName();
// Disable features that aren't available in several networks
- if (!in_array($item["item_network"], [NETWORK_DFRN, NETWORK_DIASPORA]) && isset($buttons["dislike"])) {
+ if (!in_array($item["network"], [NETWORK_DFRN, NETWORK_DIASPORA]) && isset($buttons["dislike"])) {
unset($buttons["dislike"]);
$isevent = false;
$tagger = '';
}
- if (($item["item_network"] == NETWORK_FEED) && isset($buttons["like"])) {
+ if (($item["network"] == NETWORK_FEED) && isset($buttons["like"])) {
unset($buttons["like"]);
}
- if (($item["item_network"] == NETWORK_MAIL) && isset($buttons["like"])) {
+ if (($item["network"] == NETWORK_MAIL) && isset($buttons["like"])) {
unset($buttons["like"]);
}
@@ -401,8 +401,8 @@ class Post extends BaseObject
'wait' => L10n::t('Please wait'),
'thread_level' => $thread_level,
'edited' => $edited,
- 'network' => $item["item_network"],
- 'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link),
+ 'network' => $item["network"],
+ 'network_name' => ContactSelector::networkToName($item['network'], $profile_link),
'received' => $item['received'],
'commented' => $item['commented'],
'created_date' => $item['created'],
diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php
index ce9e6642e..e84dddcea 100644
--- a/src/Protocol/OStatus.php
+++ b/src/Protocol/OStatus.php
@@ -15,6 +15,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\GContact;
use Friendica\Model\Item;
+use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Object\Image;
use Friendica\Util\DateTimeFormat;
@@ -1619,22 +1620,14 @@ class OStatus
$title = self::entryHeader($doc, $entry, $owner, $item, $toplevel);
- $r = q(
- "SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' AND NOT `private` AND `network` IN ('%s', '%s', '%s') LIMIT 1",
- intval($owner["uid"]),
- dbesc($repeated_guid),
- dbesc(NETWORK_DFRN),
- dbesc(NETWORK_DIASPORA),
- dbesc(NETWORK_OSTATUS)
- );
- if (DBM::is_result($r)) {
- $repeated_item = $r[0];
- } else {
+ $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => false,
+ 'network' => [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS]];
+ $repeated_item = Item::selectFirst([], $condition);
+ if (!DBM::is_result($repeated_item)) {
return false;
}
- $contact = self::contactEntry($repeated_item['author-link'], $owner);
- $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
+ $contact = self::contactEntry($repeated_item['author-link'], $owner);
$title = $owner["nick"]." repeated a notice by ".$contact["nick"];
@@ -1695,16 +1688,11 @@ class OStatus
$as_object = $doc->createElement("activity:object");
- $parent = q(
- "SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
- dbesc($item["thr-parent"]),
- intval($item["uid"])
- );
- $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
+ $parent = Item::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
- XML::addElement($doc, $as_object, "activity:object-type", self::constructObjecttype($parent[0]));
+ XML::addElement($doc, $as_object, "activity:object-type", self::constructObjecttype($parent));
- self::entryContent($doc, $as_object, $parent[0], $owner, "New entry");
+ self::entryContent($doc, $as_object, $parent, $owner, "New entry");
$entry->appendChild($as_object);
@@ -1952,22 +1940,19 @@ class OStatus
$mentioned = [];
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
- $parent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `id` = %d", intval($item["parent"]));
+ $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item["parent"]]);
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
- $thrparent = q(
- "SELECT `guid`, `author-link`, `owner-link`, `plink` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
- intval($owner["uid"]),
- dbesc($parent_item)
- );
- if ($thrparent) {
- $mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"];
- $mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"];
- $parent_plink = $thrparent[0]["plink"];
+ $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $parent_item]);
+
+ if (DBM::is_result($thrparent)) {
+ $mentioned[$thrparent["author-link"]] = $thrparent["author-link"];
+ $mentioned[$thrparent["owner-link"]] = $thrparent["owner-link"];
+ $parent_plink = $thrparent["plink"];
} else {
- $mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"];
- $mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"];
- $parent_plink = System::baseUrl()."/display/".$parent[0]["guid"];
+ $mentioned[$parent["author-link"]] = $parent["author-link"];
+ $mentioned[$parent["owner-link"]] = $parent["owner-link"];
+ $parent_plink = System::baseUrl()."/display/".$parent["guid"];
}
$attributes = [
@@ -2119,25 +2104,23 @@ class OStatus
{
$stamp = microtime(true);
+ $owner = User::getOwnerDataByNick($owner_nick);
+ if (!$owner) {
+ return;
+ }
+
$cachekey = "ostatus:feed:" . $owner_nick . ":" . $filter . ":" . $last_update;
$previous_created = $last_update;
- $result = Cache::get($cachekey);
- if (!$nocache && !is_null($result)) {
- logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
- $last_update = $result['last_update'];
- return $result['feed'];
- }
-
- $owner = dba::fetch_first(
- "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
- FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
- WHERE `contact`.`self` AND `user`.`nickname` = ? LIMIT 1",
- $owner_nick
- );
- if (!DBM::is_result($owner)) {
- return;
+ // Don't cache when the last item was posted less then 15 minutes ago (Cache duration)
+ if ((time() - strtotime($owner['last-item'])) < 15*60) {
+ $result = Cache::get($cachekey);
+ if (!$nocache && !is_null($result)) {
+ logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
+ $last_update = $result['last_update'];
+ return $result['feed'];
+ }
}
if (!strlen($last_update)) {
@@ -2147,37 +2130,30 @@ class OStatus
$check_date = DateTimeFormat::utc($last_update);
$authorid = Contact::getIdForURL($owner["url"], 0, true);
- $sql_extra = '';
- if ($filter === 'posts') {
- $sql_extra .= ' AND `item`.`id` = `item`.`parent` ';
- }
+ $condition = ["`uid` = ? AND `created` > ? AND NOT `deleted`
+ AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
+ $owner["uid"], $check_date, NETWORK_OSTATUS, NETWORK_DFRN];
if ($filter === 'comments') {
- $sql_extra .= sprintf(" AND `item`.`object-type` = '%s' ", dbesc(ACTIVITY_OBJ_COMMENT));
+ $condition[0] .= " AND `object-type` = ? ";
+ $condition[] = ACTIVITY_OBJ_COMMENT;
}
if ($owner['account-type'] != ACCOUNT_TYPE_COMMUNITY) {
- $sql_extra .= sprintf(" AND `item`.`contact-id` = %d AND `item`.`author-id` = %d ", intval($owner["id"]), intval($authorid));
+ $condition[0] .= " AND `contact-id` = ? AND `author-id` = ?";
+ $condition[] = $owner["id"];
+ $condition[] = $authorid;
}
- $items = q(
- "SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` USE INDEX (`uid_contactid_created`)
- STRAIGHT_JOIN `thread` ON `thread`.`iid` = `item`.`parent`
- WHERE `item`.`uid` = %d
- AND `item`.`created` > '%s'
- AND NOT `item`.`deleted`
- AND NOT `item`.`private`
- AND `item`.`visible`
- AND `item`.`wall`
- AND `thread`.`network` IN ('%s', '%s')
- $sql_extra
- ORDER BY `item`.`created` DESC LIMIT %d",
- intval($owner["uid"]),
- dbesc($check_date),
- dbesc(NETWORK_OSTATUS),
- dbesc(NETWORK_DFRN),
- intval($max_items)
- );
+ $params = ['order' => ['created' => true], 'limit' => $max_items];
+
+ if ($filter === 'posts') {
+ $ret = Item::selectThread([], $condition, $params);
+ } else {
+ $ret = Item::select([], $condition, $params);
+ }
+
+ $items = dba::inArray($ret);
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;