3 function search_saved_searches() {
7 $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
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";
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";
18 $o .= '</ul><div class="clear"></div></div>' . "\r\n";
26 function search_init(&$a) {
28 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
31 if(x($_GET,'save') && $search) {
32 $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
37 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
43 if(x($_GET,'remove') && $search) {
44 q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
50 $a->page['aside'] .= search_saved_searches();
54 unset($_SESSION['theme']);
55 unset($_SESSION['mobile-theme']);
64 function search_post(&$a) {
65 if(x($_POST,'search'))
66 $a->data['search'] = $_POST['search'];
70 function search_content(&$a) {
72 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
73 notice( t('Public access denied.') . EOL);
77 nav_set_selected('search');
79 require_once("include/bbcode.php");
80 require_once('include/security.php');
81 require_once('include/conversation.php');
83 $o = '<div id="live-search"></div>' . "\r\n";
85 $o .= '<h3>' . t('Search') . '</h3>';
87 if(x($a->data,'search'))
88 $search = notags(trim($a->data['search']));
90 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
95 $search = ((x($_GET,'tag')) ? notags(trim(rawurldecode($_GET['tag']))) : '');
99 $o .= search($search,'search-box','/search',((local_user()) ? true : false));
101 if(strpos($search,'#') === 0) {
103 $search = substr($search,1);
105 if(strpos($search,'@') === 0) {
106 require_once('mod/dirfind.php');
107 return dirfind_content($a);
113 if (get_config('system','use_fulltext_engine')) {
115 $sql_extra = sprintf(" AND MATCH (`item`.`tag`) AGAINST ('".'"%s"'."' in boolean mode) ", '#'.dbesc(protect_sprintf($search)));
117 $sql_extra = sprintf(" AND MATCH (`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) ", dbesc(protect_sprintf($search)));
120 $sql_extra = sprintf(" AND `item`.`tag` REGEXP '%s' ", dbesc('\\]' . protect_sprintf(preg_quote($search)) . '\\['));
122 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
128 // Here is the way permissions work in the search module...
129 // Only public posts can be shown
130 // OR your own posts if you are a logged in member
131 // No items will be shown if the member has a blocked profile wall.
133 if(! get_pconfig(local_user(),'system','alt_pager')) {
134 $r = q("SELECT distinct(`item`.`uri`) as `total`
135 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
136 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
137 AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0)
138 OR `item`.`uid` = %d )
139 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
140 $sql_extra group by `item`.`uri` ",
145 $a->set_pager_total(count($r));
148 info( t('No results.') . EOL);
153 $r = q("SELECT distinct(`item`.`uri`), `item`.*, `item`.`id` AS `item_id`,
154 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
155 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
156 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
158 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
159 LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
160 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
161 AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0 )
162 OR `item`.`uid` = %d )
163 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
165 group by `item`.`uri`
166 ORDER BY `received` DESC LIMIT %d , %d ",
167 intval(local_user()),
168 intval($a->pager['start']),
169 intval($a->pager['itemspage'])
174 info( t('No results.') . EOL);
180 $o .= '<h2>Items tagged with: ' . $search . '</h2>';
182 $o .= '<h2>Search results for: ' . $search . '</h2>';
184 $o .= conversation($a,$r,'search',false);
186 if(! get_pconfig(local_user(),'system','alt_pager')) {
190 $o .= alt_pager($a,count($r));