]> git.mxchange.org Git - friendica.git/blob - mod/msearch.php
Update "storage" console command
[friendica.git] / mod / msearch.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5 use Friendica\Database\DBA;
6
7 function msearch_post(App $a)
8 {
9         $search = defaults($_POST, 's', '');
10         $perpage  = intval(defaults($_POST, 'n', 80));
11         $page     = intval(defaults($_POST, 'p', 1));
12         $startrec = ($page - 1) * $perpage;
13
14         $total = 0;
15         $results = [];
16
17         if (!strlen($search)) {
18                 $output = ['total' => 0, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
19                 echo json_encode($output);
20                 exit();
21         }
22
23         $count_stmt = DBA::p(
24                 "SELECT COUNT(*) AS `total`
25                         FROM `profile`
26                         JOIN `user` ON `user`.`uid` = `profile`.`uid`
27                         WHERE `is-default` = 1
28                         AND `user`.`hidewall` = 0
29                         AND MATCH(`pub_keywords`) AGAINST (?)",
30                 $search
31         );
32
33         if (DBA::isResult($count_stmt)) {
34                 $row = DBA::fetch($count_stmt);
35                 $total = $row['total'];
36         }
37
38         DBA::close($count_stmt);
39
40         $search_stmt = DBA::p(
41                 "SELECT `pub_keywords`, `username`, `nickname`, `user`.`uid`
42                         FROM `user`
43                         JOIN `profile` ON `user`.`uid` = `profile`.`uid`
44                         WHERE `is-default` = 1
45                         AND `user`.`hidewall` = 0
46                         AND MATCH(`pub_keywords`) AGAINST (?)
47                         LIMIT ?, ?",
48                 $search,
49                 $startrec,
50                 $perpage
51         );
52
53         while($search_result = DBA::fetch($search_stmt)) {
54                 $results[] = [
55                         'name'  => $search_result['name'],
56                         'url'   => System::baseUrl() . '/profile/' . $search_result['nickname'],
57                         'photo' => System::baseUrl() . '/photo/avatar/' . $search_result['uid'] . '.jpg',
58                         'tags'  => str_replace([',', '  '], [' ', ' '], $search_result['pub_keywords'])
59                 ];
60         }
61
62         $output = ['total' => $total, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
63
64         echo json_encode($output);
65
66         exit();
67 }