* @param string $activity activity string
* @return integer Activity index
*/
- private static function activityToIndex($activity)
+ public static function activityToIndex($activity)
{
$index = array_search($activity, self::ACTIVITIES);
} else {
$master_table = "`item`";
}
- return "$master_table.`visible` AND NOT $master_table.`deleted` AND NOT $master_table.`moderated` AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) ";
+ return sprintf("$master_table.`visible` AND NOT $master_table.`deleted` AND NOT $master_table.`moderated`
+ AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
+ AND (`user-author`.`blocked` IS NULL OR NOT `user-author`.`blocked`)
+ AND (`user-author`.`ignored` IS NULL OR NOT `user-author`.`ignored` OR `item`.`gravity` != %d)
+ AND (`user-owner`.`blocked` IS NULL OR NOT `user-owner`.`blocked`)
+ AND (`user-owner`.`ignored` IS NULL OR NOT `user-owner`.`ignored` OR `item`.`gravity` != %d) ",
+ GRAVITY_PARENT, GRAVITY_PARENT);
}
/**
OR `contact`.`self` OR `item`.`gravity` != %d OR `contact`.`uid` = 0)
STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = $master_table.`author-id` AND NOT `author`.`blocked`
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = $master_table.`owner-id` AND NOT `owner`.`blocked`
- LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d",
- Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid));
+ LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d
+ LEFT JOIN `user-contact` AS `user-author` ON `user-author`.`cid` = $master_table.`author-id` AND `user-author`.`uid` = %d
+ LEFT JOIN `user-contact` AS `user-owner` ON `user-owner`.`cid` = $master_table.`owner-id` AND `user-owner`.`uid` = %d",
+ Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid), intval($uid), intval($uid));
} else {
if (strpos($sql_commands, "`contact`.") !== false) {
$joins .= "LEFT JOIN `contact` ON `contact`.`id` = $master_table.`contact-id`";
return 0;
}
- // These fields aren't stored anymore in the item table, they are fetched upon request
- unset($item['author-link']);
- unset($item['author-name']);
- unset($item['author-avatar']);
-
- unset($item['owner-link']);
- unset($item['owner-name']);
- unset($item['owner-avatar']);
-
if ($item['network'] == Protocol::PHANTOM) {
logger('Missing network. Called by: '.System::callstack(), LOGGER_DEBUG);
unset($item['postopts']);
unset($item['inform']);
+ // These fields aren't stored anymore in the item table, they are fetched upon request
+ unset($item['author-link']);
+ unset($item['author-name']);
+ unset($item['author-avatar']);
+
+ unset($item['owner-link']);
+ unset($item['owner-name']);
+ unset($item['owner-avatar']);
+
DBA::transaction();
$ret = DBA::insert('item', $item);
}
}
+ /**
+ * This function is only used for the old Friendica app on Android that doesn't like paths with guid
+ * @param string $guid item guid
+ * @param int $uid user id
+ * @return array with id and nick of the item with the given guid
+ */
public static function getIdAndNickByGuid($guid, $uid = 0)
{
$nick = "";
// Does the given user have this item?
if ($uid) {
- /// @todo This query has to be abstracted for the "uri-id" changes
- $item = DBA::fetchFirst("SELECT `item`.`id`, `user`.`nickname` FROM `item`
- INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
- WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
- AND `item`.`guid` = ? AND `item`.`uid` = ?", $guid, $uid);
+ $item = self::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
if (DBA::isResult($item)) {
- $id = $item["id"];
- $nick = $item["nickname"];
+ $user = DBA::selectFirst('user', ['nickname'], ['uid' => $uid]);
+ if (!DBA::isResult($user)) {
+ return;
+ }
+ $id = $item['id'];
+ $nick = $user['nickname'];
}
}
// Or is it anywhere on the server?
if ($nick == "") {
- /// @todo This query has to be abstracted for the "uri-id" changes
- $item = DBA::fetchFirst("SELECT `item`.`id`, `user`.`nickname` FROM `item`
- INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
- WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
- AND NOT `item`.`private` AND `item`.`wall`
- AND `item`.`guid` = ?", $guid);
+ $condition = ["`guid` = ? AND `uid` != 0", $guid];
+ $item = self::selectFirst(['id', 'uid'], $condition);
if (DBA::isResult($item)) {
- $id = $item["id"];
- $nick = $item["nickname"];
+ $user = DBA::selectFirst('user', ['nickname'], ['uid' => $item['uid']]);
+ if (!DBA::isResult($user)) {
+ return;
+ }
+ $id = $item['id'];
+ $nick = $user['nickname'];
}
}
return ["nick" => $nick, "id" => $id];
return;
}
- // Using dba::delete at this time could delete the associated item entries
- $result = DBA::e("DELETE FROM `thread` WHERE `iid` = ?", $itemid);
+ $result = DBA::delete('thread', ['iid' => $itemid], ['cascade' => false]);
logger("deleteThread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG);