3 function search_saved_searches() {
7 if(! feature_enabled(local_user(),'savedsearch'))
10 $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
19 'term' => $rr['term'],
20 'encodedterm' => urlencode($rr['term']),
21 'delete' => t('Remove term'),
22 'selected' => ($search==$rr['term']),
27 $tpl = get_markup_template("saved_searches_aside.tpl");
29 $o .= replace_macros($tpl, array(
30 '$title' => t('Saved Searches'),
42 function search_init(&$a) {
44 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
47 if(x($_GET,'save') && $search) {
48 $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
53 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
59 if(x($_GET,'remove') && $search) {
60 q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
66 $a->page['aside'] .= search_saved_searches();
70 unset($_SESSION['theme']);
71 unset($_SESSION['mobile-theme']);
80 function search_post(&$a) {
81 if(x($_POST,'search'))
82 $a->data['search'] = $_POST['search'];
86 function search_content(&$a) {
88 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
89 notice( t('Public access denied.') . EOL);
93 nav_set_selected('search');
95 require_once("include/bbcode.php");
96 require_once('include/security.php');
97 require_once('include/conversation.php');
99 $o = '<h3>' . t('Search') . '</h3>';
101 if(x($a->data,'search'))
102 $search = notags(trim($a->data['search']));
104 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
109 $search = ((x($_GET,'tag')) ? notags(trim(rawurldecode($_GET['tag']))) : '');
113 $o .= search($search,'search-box','/search',((local_user()) ? true : false));
115 if(strpos($search,'#') === 0) {
117 $search = substr($search,1);
119 if(strpos($search,'@') === 0) {
120 require_once('mod/dirfind.php');
121 return dirfind_content($a);
127 if (get_config('system','only_tag_search'))
133 $sql_table = sprintf("`item` INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d) AS `term` ON `item`.`id` = `term`.`oid` ",
134 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
136 $sql_order = "`item`.`id`";
138 if (get_config('system','use_fulltext_engine')) {
139 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
141 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
143 $sql_table = "`item`";
144 $sql_order = "`item`.`id`";
145 //$sql_order = "`item`.`received`";
148 // Here is the way permissions work in the search module...
149 // Only public posts can be shown
150 // OR your own posts if you are a logged in member
151 // No items will be shown if the member has a blocked profile wall.
153 if( (! get_config('alt_pager', 'global')) && (! get_pconfig(local_user(),'system','alt_pager')) ) {
154 $r = q("SELECT distinct(`item`.`uri`) as `total`
155 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
156 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
157 INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
158 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
159 AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0)
160 OR ( `item`.`uid` = %d ))
164 // $sql_extra group by `item`.`uri` ",
167 $a->set_pager_total(count($r));
170 info( t('No results.') . EOL);
175 $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
176 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
177 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
178 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
179 `user`.`nickname`, `user`.`uid`, `user`.`hidewall`
180 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
181 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
182 INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
183 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
184 AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0 )
185 OR ( `item`.`uid` = %d ))
186 $sql_extra GROUP BY `item`.`uri`
187 ORDER BY $sql_order DESC LIMIT %d , %d ",
188 intval(local_user()),
189 intval($a->pager['start']),
190 intval($a->pager['itemspage'])
193 // group by `item`.`uri`
196 info( t('No results.') . EOL);
202 $o .= '<h2>Items tagged with: ' . $search . '</h2>';
204 $o .= '<h2>Search results for: ' . $search . '</h2>';
206 $o .= conversation($a,$r,'search',false);
208 if( get_config('alt_pager', 'global') || get_pconfig(local_user(),'system','alt_pager') ) {
209 $o .= alt_pager($a,count($r));