]> git.mxchange.org Git - friendica.git/blob - mod/search.php
f7ce75905a80b23c6616baf39da485d2da594423
[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         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
13                 notice( t('Public access denied.') . EOL);
14                 return;
15         }
16         
17         nav_set_selected('search');
18
19         require_once("include/bbcode.php");
20         require_once('include/security.php');
21         require_once('include/conversation.php');
22
23         if(x($_SESSION,'theme'))
24                 unset($_SESSION['theme']);
25
26         $o = '<div id="live-search"></div>' . "\r\n";
27
28         $o .= '<h3>' . t('Search') . '</h3>';
29
30         if(x($a->data,'search'))
31                 $search = notags(trim($a->data['search']));
32         else
33                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
34
35         $o .= search($search);
36
37         if(! $search)
38                 return $o;
39
40         // Here is the way permissions work in the search module...
41         // Only public wall posts can be shown
42         // OR your own posts if you are a logged in member
43
44         $s_bool  = "AND MATCH (`item`.`body`) AGAINST ( '%s' IN BOOLEAN MODE )";
45         $s_regx  = "AND `item`.`body` REGEXP '%s' ";
46
47         if(mb_strlen($search) >= 3)
48                 $search_alg = $s_bool;
49         else
50                 $search_alg = $s_regx;
51
52         $r = q("SELECT COUNT(*) AS `total`
53                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
54                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
55                 AND (( `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0) 
56                         OR `item`.`uid` = %d )
57                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
58                 $search_alg ",
59                 intval(local_user()),
60                 dbesc($search)
61         );
62
63         if(count($r))
64                 $a->set_pager_total($r[0]['total']);
65
66         if(! $r[0]['total']) {
67                 info( t('No results.') . EOL);
68                 return $o;
69         }
70
71         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
72                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
73                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
74                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
75                 `user`.`nickname`
76                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
77                 LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
78                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
79                 AND (( `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0 ) 
80                         OR `item`.`uid` = %d )
81                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
82                 $search_alg
83                 ORDER BY `received` DESC LIMIT %d , %d ",
84                 intval(local_user()),
85                 dbesc($search),
86                 intval($a->pager['start']),
87                 intval($a->pager['itemspage'])
88
89         );
90
91
92
93         $o .= conversation($a,$r,'search',false);
94
95         $o .= paginate($a);
96         $o .= cc_license();
97
98         return $o;
99 }
100