$ret = $data;
break;
}
-
return $ret;
}
$returndata["image"] = ["w" => $media["width"],
"h" => $media["height"],
"image_type" => $media["type"],
- "preview" => $media["preview"]];
+ "friendica_preview_url" => $media["preview"]];
Logger::log("Media uploaded: " . print_r($returndata, true), Logger::DEBUG);
$a = \get_app();
$user_info = api_get_user($a);
- if (api_user() === false || $user_info === false) {
- throw new ForbiddenException();
- }
-
- $data = [];
+ if (api_user() === false || $user_info === false) { throw new ForbiddenException(); }
- if (empty($_REQUEST['q'])) {
- throw new BadRequestException("q parameter is required.");
- }
+ if (empty($_REQUEST['q'])) { throw new BadRequestException("q parameter is required."); }
+
+ $searchTerm = trim(rawurldecode($_REQUEST['q']));
+ $data = [];
+ $count = 15;
+ $exclude_replies = !empty($_REQUEST['exclude_replies']);
if (!empty($_REQUEST['rpp'])) {
$count = $_REQUEST['rpp'];
} elseif (!empty($_REQUEST['count'])) {
$count = $_REQUEST['count'];
- } else {
- $count = 15;
}
-
+
$since_id = defaults($_REQUEST, 'since_id', 0);
$max_id = defaults($_REQUEST, 'max_id', 0);
$page = (!empty($_REQUEST['page']) ? $_REQUEST['page'] - 1 : 0);
-
$start = $page * $count;
+ $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ if (preg_match('/^#(\w+)$/', $searchTerm, $matches) === 1 && isset($matches[1])) {
+ $searchTerm = $matches[1];
+ $condition = ["`oid` > ?
+ AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))
+ AND `otype` = ? AND `type` = ? AND `term` = ?",
+ $since_id, local_user(), TERM_OBJ_POST, TERM_HASHTAG, $searchTerm];
+ if ($max_id > 0) {
+ $condition[0] .= " AND `oid` <= ?";
+ $condition[] = $max_id;
+ }
+ $terms = DBA::select('term', ['oid'], $condition, []);
+ $itemIds = [];
+ while($term = DBA::fetch($terms)){ $itemIds[] = $term['oid']; }
+ DBA::close($terms);
+ $condition = [$exclude_replies ? "`id` = `parent` AND " : ''];
+ $condition[0] .= empty($itemIds) ? '' : ' `id` IN ('.implode(", ", $itemIds).')' ;
- $condition = ["`gravity` IN (?, ?) AND `item`.`id` > ?
- AND (`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))
- AND `item`.`body` LIKE CONCAT('%',?,'%')",
- GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, api_user(), $_REQUEST['q']];
+ } else {
+ $condition = ["`id` > ?
+ ". ($exclude_replies ? " AND `id` = `parent` " : ' ')."
+ AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))
+ AND `body` LIKE CONCAT('%',?,'%')",
+ $since_id, api_user(), $_REQUEST['q']];
+ if ($max_id > 0) {
+ $condition[0] .= " AND `id` <= ?";
+ $condition[] = $max_id;
+ }
- if ($max_id > 0) {
- $condition[0] .= " AND `item`.`id` <= ?";
- $condition[] = $max_id;
}
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
$data['status'] = api_format_items(Item::inArray($statuses), $user_info);
+ bindComments($data['status']);
+
return api_format_data("statuses", $type, $data);
}
Item::update(['unseen' => false], ['unseen' => true, 'id' => $idarray]);
}
}
+
+ bindComments($ret);
$data = ['status' => $ret];
switch ($type) {
return api_format_data("statuses", $type, $data);
}
+
/// @TODO move to top of file or somewhere better
api_register_func('api/statuses/home_timeline', 'api_statuses_home_timeline', true);
api_register_func('api/statuses/friends_timeline', 'api_statuses_home_timeline', true);
$ret = api_format_items($r, $user_info, false, $type);
+ bindComments($ret);
+
$data = ['status' => $ret];
switch ($type) {
case "atom":
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
+ bindComments($ret);
+
$data = ['status' => $ret];
switch ($type) {
case "atom":
$ret = api_format_items(Item::inArray($statuses), $user_info, true, $type);
+ bindComments($ret);
+
$data = ['status' => $ret];
switch ($type) {
case "atom":
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
}
+ bindComments($ret);
+
$data = ['status' => $ret];
switch ($type) {
case "atom":
$ret = [];
- foreach ($r as $item) {
+ foreach ((array)$r as $item) {
localize_item($item);
list($status_user, $owner_user) = api_item_get_user($a, $item);
$notes = $xmlnotes;
}
-
return api_format_data("notes", $type, ['note' => $notes]);
}
/// @TODO move to top of file or somewhere better
api_register_func('api/saved_searches/list', 'api_saved_searches_list', true);
+/*
+ * Bind comment numbers(friendica_comments: Int) on each statuses page of *_timeline / favorites / search
+ *
+ * @brief Number of comments
+ *
+ * @param object $data [Status, Status]
+ *
+ * @return void
+ */
+function bindComments(&$data){
+ if(count($data) == 0) return;
+
+ $ids = [];
+ $comments = [];
+ foreach($data as $item){ $ids[] = $item['id']; }
+
+ $sql = "SELECT `parent`,COUNT(*) as comments FROM `item`
+ WHERE `parent` IN ( %s ) AND `deleted` = %d AND `gravity`= %d GROUP BY `parent`";
+ $result = q($sql, implode(",", $ids), 0, GRAVITY_COMMENT);
+
+ foreach($result as $records) {
+ $comments[$records['parent']] = $records['comments'];
+ }
+
+ foreach($data as $idx => $item){
+ $id = $item['id'];
+ $data[$idx]['friendica_comments'] = isset($comments[$id]) ? $comments[$id] : 0;
+ }
+}
+
/*
@TODO Maybe open to implement?
To.Do: