]> git.mxchange.org Git - friendica.git/blob - mod/search.php
multi-user, do not cache open mbox
[friendica.git] / mod / search.php
1 <?php
2
3
4 function search_post(&$a) {
5         if(x($_POST,'search'))
6                 $a->data['search'] = $_POST['search'];
7 }
8
9
10 function search_content(&$a) {
11
12         require_once("include/bbcode.php");
13         require_once('include/security.php');
14         require_once('include/conversation.php');
15
16         if(x($_SESSION,'theme'))
17                 unset($_SESSION['theme']);
18
19         $o = '<div id="live-search"></div>' . "\r\n";
20
21         $o .= '<h3>' . t('Search') . '</h3>';
22
23         if(x($a->data,'search'))
24                 $search = notags(trim($a->data['search']));
25         else
26                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
27
28         $o .= search($search);
29
30         if(! $search)
31                 return $o;
32
33
34         $sql_extra = "
35                 AND `item`.`allow_cid` = '' 
36                 AND `item`.`allow_gid` = '' 
37                 AND `item`.`deny_cid`  = '' 
38                 AND `item`.`deny_gid`  = '' 
39         ";
40
41         $s_bool  = "AND MATCH (`item`.`body`) AGAINST ( '%s' IN BOOLEAN MODE )";
42         $s_regx  = "AND `item`.`body` REGEXP '%s' ";
43
44         if(mb_strlen($search) >= 3)
45                 $search_alg = $s_bool;
46         else
47                 $search_alg = $s_regx;
48
49         $r = q("SELECT COUNT(*) AS `total`
50                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
51                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
52                 AND ( `wall` = 1 OR `contact`.`uid` = %d )
53                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
54                 $search_alg
55                 $sql_extra ",
56                 intval(local_user()),
57                 dbesc($search)
58         );
59
60         if(count($r))
61                 $a->set_pager_total($r[0]['total']);
62
63         if(! $r[0]['total']) {
64                 notice( t('No results.') . EOL);
65                 return $o;
66         }
67
68         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
69                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
70                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
71                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
72                 `user`.`nickname`
73                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
74                 LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` 
75                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
76                 AND ( `wall` = 1 OR `contact`.`uid` = %d )
77                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
78                 $search_alg
79                 $sql_extra
80                 ORDER BY `parent` DESC ",
81                 intval(local_user()),
82                 dbesc($search)
83         );
84
85
86
87         $o .= conversation($a,$r,'search',false);
88
89         $o .= paginate($a);
90
91         return $o;
92 }
93