$searchTerm = trim(rawurldecode($_REQUEST['q']));
$data = [];
+ $data['status'] = [];
$count = 15;
$exclude_replies = !empty($_REQUEST['exclude_replies']);
if (!empty($_REQUEST['rpp'])) {
}
$terms = DBA::select('term', ['oid'], $condition, []);
$itemIds = [];
- while($term = DBA::fetch($terms)){ $itemIds[] = $term['oid']; }
+ 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).')' ;
+ if (empty($itemIds)) {
+ return api_format_data("statuses", $type, $data);
+ }
+
+ $tmpAr = ['`id` IN ('.implode(", ", $itemIds).')'];
+ if ($exclude_replies) {
+ $tmpAr[] = "`id` = `parent`";
+ }
+
+ $condition = [ implode(" AND ", $tmpAr) ];
} else {
$condition = ["`id` > ?
- ". ($exclude_replies ? " AND `id` = `parent` " : ' ')."
+ " . ( $exclude_replies ? " AND `id` = `parent` " : ' ' ) . "
AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))
AND `body` LIKE CONCAT('%',?,'%')",
$since_id, api_user(), $_REQUEST['q']];
$condition[0] .= " AND `id` <= ?";
$condition[] = $max_id;
}
-
}
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
*
* @return void
*/
-function bindComments(&$data){
- if(count($data) == 0) return;
+function bindComments(&$data)
+{
+ if (count($data) == 0) {
+ return;
+ }
$ids = [];
$comments = [];
- foreach($data as $item){ $ids[] = $item['id']; }
+ 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);
+ $idStr = DBA::escape(implode(", ", $ids));
+ $sql = "SELECT `parent`, COUNT(*) as comments FROM `item` WHERE `parent` IN ($idStr) AND `deleted` = ? AND `gravity`= ? GROUP BY `parent`";
+ $items = DBA::p($sql, 0, GRAVITY_COMMENT);
+ $itemsData = DBA::toArray($items);
- foreach($result as $records) {
- $comments[$records['parent']] = $records['comments'];
+ foreach ($itemsData as $item) {
+ $comments[$item['parent']] = $item['comments'];
}
- foreach($data as $idx => $item){
+ foreach ($data as $idx => $item) {
$id = $item['id'];
$data[$idx]['friendica_comments'] = isset($comments[$id]) ? $comments[$id] : 0;
}