3 function search_saved_searches() {
7 $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
16 'term' => $rr['term'],
17 'encodedterm' => urlencode($rr['term']),
18 'delete' => t('Remove term'),
19 'selected' => ($search==$rr['term']),
24 $tpl = get_markup_template("saved_searches_aside.tpl");
26 $o .= replace_macros($tpl, array(
27 '$title' => t('Saved Searches'),
39 function search_init(&$a) {
41 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
44 if(x($_GET,'save') && $search) {
45 $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
50 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
56 if(x($_GET,'remove') && $search) {
57 q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
63 $a->page['aside'] .= search_saved_searches();
67 unset($_SESSION['theme']);
68 unset($_SESSION['mobile-theme']);
77 function search_post(&$a) {
78 if(x($_POST,'search'))
79 $a->data['search'] = $_POST['search'];
83 function search_content(&$a) {
85 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
86 notice( t('Public access denied.') . EOL);
90 nav_set_selected('search');
92 require_once("include/bbcode.php");
93 require_once('include/security.php');
94 require_once('include/conversation.php');
96 $o = '<div id="live-search"></div>' . "\r\n";
98 $o .= '<h3>' . t('Search') . '</h3>';
100 if(x($a->data,'search'))
101 $search = notags(trim($a->data['search']));
103 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
108 $search = ((x($_GET,'tag')) ? notags(trim(rawurldecode($_GET['tag']))) : '');
112 $o .= search($search,'search-box','/search',((local_user()) ? true : false));
114 if(strpos($search,'#') === 0) {
116 $search = substr($search,1);
118 if(strpos($search,'@') === 0) {
119 require_once('mod/dirfind.php');
120 return dirfind_content($a);
126 if (get_config('system','use_fulltext_engine')) {
128 $sql_extra = sprintf(" AND MATCH (`item`.`tag`) AGAINST ('".'"%s"'."' in boolean mode) ", '#'.dbesc(protect_sprintf($search)));
130 $sql_extra = sprintf(" AND MATCH (`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) ", dbesc(protect_sprintf($search)));
133 $sql_extra = sprintf(" AND `item`.`tag` REGEXP '%s' ", dbesc('\\]' . protect_sprintf(preg_quote($search)) . '\\['));
135 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
141 // Here is the way permissions work in the search module...
142 // Only public posts can be shown
143 // OR your own posts if you are a logged in member
144 // No items will be shown if the member has a blocked profile wall.
146 if(! get_pconfig(local_user(),'system','alt_pager')) {
147 $r = q("SELECT distinct(`item`.`uri`) as `total`
148 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
149 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
150 AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0)
151 OR `item`.`uid` = %d )
152 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
153 $sql_extra group by `item`.`uri` ",
158 $a->set_pager_total(count($r));
161 info( t('No results.') . EOL);
166 $r = q("SELECT distinct(`item`.`uri`), `item`.*, `item`.`id` AS `item_id`,
167 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
168 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
169 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
171 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
172 LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
173 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
174 AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0 )
175 OR `item`.`uid` = %d )
176 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
178 group by `item`.`uri`
179 ORDER BY `received` DESC LIMIT %d , %d ",
180 intval(local_user()),
181 intval($a->pager['start']),
182 intval($a->pager['itemspage'])
187 info( t('No results.') . EOL);
193 $o .= '<h2>Items tagged with: ' . $search . '</h2>';
195 $o .= '<h2>Search results for: ' . $search . '</h2>';
197 $o .= conversation($a,$r,'search',false);
199 if(! get_pconfig(local_user(),'system','alt_pager')) {
203 $o .= alt_pager($a,count($r));