]> git.mxchange.org Git - friendica.git/blob - mod/search.php
fix minor placement issues on old themes from testbubble theme changes
[friendica.git] / mod / search.php
1 <?php
2
3 function search_saved_searches() {
4
5         $o = '';
6
7         $r = q("select `term` from `search` WHERE `uid` = %d",
8                 intval(local_user())
9         );
10
11         if(count($r)) {
12                 $o .= '<div id="saved-search-list" class="widget">';
13                 $o .= '<h3>' . t('Saved Searches') . '</h3>' . "\r\n";
14                 $o .= '<ul id="saved-search-ul">' . "\r\n";
15                 foreach($r as $rr) {
16                         $o .= '<li class="saved-search-li clear"><a href="search/?f=&remove=1&search=' . $rr['term'] . '" class="icon drophide savedsearchdrop" title="' . t('Remove term') . '" onclick="return confirmDelete();" onmouseover="imgbright(this);" onmouseout="imgdull(this);" ></a> <a href="search/?f&search=' . $rr['term'] . '" class="savedsearchterm" >' . $rr['term'] . '</a></li>' . "\r\n";
17                 }
18                 $o .= '</ul></div>' . "\r\n";
19         }               
20
21         return $o;
22
23 }
24
25
26 function search_init(&$a) {
27
28         $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
29
30         if(local_user()) {
31                 if(x($_GET,'save') && $search) {
32                         $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
33                                 intval(local_user()),
34                                 dbesc($search)
35                         );
36                         if(! count($r)) {
37                                 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
38                                         intval(local_user()),
39                                         dbesc($search)
40                                 );
41                         }
42                 }
43                 if(x($_GET,'remove') && $search) {
44                         q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
45                                 intval(local_user()),
46                                 dbesc($search)
47                         );
48                 }
49
50                 $a->page['aside'] .= search_saved_searches();
51
52         }
53
54
55 }
56
57
58
59 function search_post(&$a) {
60         if(x($_POST,'search'))
61                 $a->data['search'] = $_POST['search'];
62 }
63
64
65 function search_content(&$a) {
66
67         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
68                 notice( t('Public access denied.') . EOL);
69                 return;
70         }
71
72         require_once("include/bbcode.php");
73         require_once('include/security.php');
74         require_once('include/conversation.php');
75
76         if(x($_SESSION,'theme'))
77                 unset($_SESSION['theme']);
78
79         $o = '<div id="live-search"></div>' . "\r\n";
80
81         $o .= '<h3>' . t('Search') . '</h3>';
82
83         if(x($a->data,'search'))
84                 $search = notags(trim($a->data['search']));
85         else
86                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
87
88         $o .= search($search,'search-box','/search',((local_user()) ? true : false));
89
90         if(! $search)
91                 return $o;
92
93         // Here is the way permissions work in the search module...
94         // Only public wall posts can be shown
95         // OR your own posts if you are a logged in member
96
97         $s_bool  = "AND MATCH (`item`.`body`) AGAINST ( '%s' IN BOOLEAN MODE )";
98         $s_regx  = "AND `item`.`body` REGEXP '%s' ";
99
100         if(mb_strlen($search) >= 3)
101                 $search_alg = $s_bool;
102         else
103                 $search_alg = $s_regx;
104
105         $r = q("SELECT COUNT(*) AS `total`
106                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
107                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
108                 AND (( `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0) 
109                         OR `item`.`uid` = %d )
110                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
111                 $search_alg ",
112                 intval(local_user()),
113                 dbesc($search)
114         );
115
116         if(count($r))
117                 $a->set_pager_total($r[0]['total']);
118
119         if(! $r[0]['total']) {
120                 info( t('No results.') . EOL);
121                 return $o;
122         }
123
124         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
125                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
126                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
127                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
128                 `user`.`nickname`
129                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
130                 LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
131                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
132                 AND (( `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0 ) 
133                         OR `item`.`uid` = %d )
134                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
135                 $search_alg
136                 ORDER BY `received` DESC LIMIT %d , %d ",
137                 intval(local_user()),
138                 dbesc($search),
139                 intval($a->pager['start']),
140                 intval($a->pager['itemspage'])
141
142         );
143
144         $o .= '<h2>Search results for: ' . $search . '</h2>';
145
146         $o .= conversation($a,$r,'search',false);
147
148         $o .= paginate($a);
149
150         return $o;
151 }
152