]> git.mxchange.org Git - friendica.git/blobdiff - mod/msearch.php
Merge pull request #11641 from tobiasd/20220613-lng
[friendica.git] / mod / msearch.php
index 1e858f1db473504d7ba0ba86f26a40dad46fbe03..00a72ea9f72171f75470ae3042fd7c7109192057 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -20,6 +20,7 @@
  */
 
 use Friendica\App;
+use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\User;
@@ -37,39 +38,15 @@ function msearch_post(App $a)
 
        if (!strlen($search)) {
                $output = ['total' => 0, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
-               echo json_encode($output);
-               exit();
+               System::jsonExit($output);
        }
 
        $total = 0;
 
-       $count_stmt = DBA::p(
-               "SELECT COUNT(*) AS `total`
-                       FROM `profile`
-                       JOIN `user` ON `user`.`uid` = `profile`.`uid`
-                       WHERE `profile`.`net-publish`
-                       AND MATCH(`pub_keywords`) AGAINST (?)",
-               $search
-       );
-       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 `profile`.`net-publish`
-                       AND MATCH(`pub_keywords`) AGAINST (?)
-                       LIMIT ?, ?",
-               $search,
-               $startrec,
-               $perpage
-       );
+       $condition = ["`net-publish` AND MATCH(`pub_keywords`) AGAINST (?)", $search];
+       $total = DBA::count('owner-view', $condition);
 
+       $search_stmt = DBA::select('owner-view', ['pub_keywords', 'name', 'nickname', 'uid'], $condition, ['limit' => [$startrec, $perpage]]);
        while ($search_result = DBA::fetch($search_stmt)) {
                $results[] = [
                        'name'  => $search_result['name'],
@@ -83,7 +60,5 @@ function msearch_post(App $a)
 
        $output = ['total' => $total, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
 
-       echo json_encode($output);
-
-       exit();
+       System::jsonExit($output);
 }