- $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']];
-
- if ($max_id > 0) {
- $condition[0] .= " AND `item`.`id` <= ?";
- $condition[] = $max_id;
+ if (!empty($_REQUEST['q'])) {
+ $condition = [
+ "`id` > ?
+ 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;
+ }
+ } elseif (!empty($_REQUEST['friendica_tag'])) {
+ $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,
+ Strings::escapeTags(trim(rawurldecode($_REQUEST['friendica_tag'])))
+ ];
+ 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 = ['id' => empty($itemIds) ? [0] : $itemIds ];