X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fmsearch.php;h=64c6ce3cf8a0c2f5a2ad9dfebbb8463b321c2aac;hb=5e1ceb57de62e4f2b6af957fa7952eed09c1aedb;hp=89de5b70576f354653ad4daf8645d5aa5b843876;hpb=8ec424325375aa923c7d2d78ac8ddcc352f09cff;p=friendica.git diff --git a/mod/msearch.php b/mod/msearch.php index 89de5b7057..64c6ce3cf8 100644 --- a/mod/msearch.php +++ b/mod/msearch.php @@ -1,42 +1,67 @@ 0, 'items_page' => $perpage, 'page' => $page, 'results' => $results]; + echo json_encode($output); + exit(); + } + + $count_stmt = DBA::p( + "SELECT COUNT(*) AS `total` + FROM `profile` + JOIN `user` ON `user`.`uid` = `profile`.`uid` + WHERE `is-default` = 1 + AND `user`.`hidewall` = 0 + AND MATCH(`pub_keywords`) AGAINST (?)", + $search ); - if(count($r)) - $total = $r[0]['total']; - $r = q("SELECT `pub_keywords`, `username`, `nickname`, `user`.`uid` FROM `user` LEFT JOIN `profile` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') LIMIT %d , %d ", - dbesc($search), - intval($startrec), - intval($perpage) + if (DBA::isResult($count_stmt)) { + $row = DBA::fetch($count_stmt); + $total = $row['total']; + } + + DBA::close($count_stmt); + + $search_stmt = DBA::p( + "SELECT `pub_keywords`, `username`, `nickname`, `user`.`uid` + FROM `user` + JOIN `profile` ON `user`.`uid` = `profile`.`uid` + WHERE `is-default` = 1 + AND `user`.`hidewall` = 0 + AND MATCH(`pub_keywords`) AGAINST (?) + LIMIT ?, ?", + $search, + $startrec, + $perpage ); - $results = array(); - if(count($r)) { - foreach($r as $rr) - $results[] = array( - 'name' => $rr['name'], - 'url' => $a->get_baseurl() . '/profile/' . $rr['nickname'], - 'photo' => $a->get_baseurl() . '/photo/avatar/' . $rr['uid'] . '.jpg', - 'tags' => str_replace(array(',',' '),array(' ',' '),$rr['pub_keywords']) - ); + while($search_result = DBA::fetch($search_stmt)) { + $results[] = [ + 'name' => $search_result['name'], + 'url' => System::baseUrl() . '/profile/' . $search_result['nickname'], + 'photo' => System::baseUrl() . '/photo/avatar/' . $search_result['uid'] . '.jpg', + 'tags' => str_replace([',', ' '], [' ', ' '], $search_result['pub_keywords']) + ]; } - $output = array('total' => $total, 'items_page' => $perpage, 'page' => $page + 1, 'results' => $results); + $output = ['total' => $total, 'items_page' => $perpage, 'page' => $page, 'results' => $results]; echo json_encode($output); - killme(); - -} \ No newline at end of file + exit(); +}