2 require_once("include/bbcode.php");
3 require_once('include/security.php');
4 require_once('include/conversation.php');
5 require_once('mod/dirfind.php');
7 function search_saved_searches() {
11 if(! feature_enabled(local_user(),'savedsearch'))
14 $r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d",
23 'term' => $rr['term'],
24 'encodedterm' => urlencode($rr['term']),
25 'delete' => t('Remove term'),
26 'selected' => ($search==$rr['term']),
31 $tpl = get_markup_template("saved_searches_aside.tpl");
33 $o .= replace_macros($tpl, array(
34 '$title' => t('Saved Searches'),
46 function search_init(&$a) {
48 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
51 if(x($_GET,'save') && $search) {
52 $r = q("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1",
57 q("INSERT INTO `search` (`uid`,`term`) VALUES ( %d, '%s')",
63 if(x($_GET,'remove') && $search) {
64 q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
70 $a->page['aside'] .= search_saved_searches();
74 unset($_SESSION['theme']);
75 unset($_SESSION['mobile-theme']);
84 function search_post(&$a) {
85 if(x($_POST,'search'))
86 $a->data['search'] = $_POST['search'];
90 function search_content(&$a) {
92 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
93 notice( t('Public access denied.') . EOL);
97 if(get_config('system','local_search') AND !local_user()) {
98 notice(t('Public access denied.').EOL);
100 //http_status_exit(403);
104 nav_set_selected('search');
107 $o = '<h3>' . t('Search') . '</h3>';
109 if(x($a->data,'search'))
110 $search = notags(trim($a->data['search']));
112 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
117 $search = ((x($_GET,'tag')) ? notags(trim(rawurldecode($_GET['tag']))) : '');
121 $o .= search($search,'search-box','/search',((local_user()) ? true : false), false);
123 if(strpos($search,'#') === 0) {
125 $search = substr($search,1);
127 if(strpos($search,'@') === 0) {
128 return dirfind_content($a);
130 if(strpos($search,'!') === 0) {
131 return dirfind_content($a);
134 if(x($_GET,'search-option'))
135 switch($_GET['search-option']) {
142 return dirfind_content($a, "@");
145 return dirfind_content($a, "!");
152 if (get_config('system','only_tag_search'))
155 // Here is the way permissions work in the search module...
156 // Only public posts can be shown
157 // OR your own posts if you are a logged in member
158 // No items will be shown if the member has a blocked profile wall.
161 logger("Start tag search for '".$search."'", LOGGER_DEBUG);
163 $r = q("SELECT STRAIGHT_JOIN `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
164 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
165 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
166 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
168 INNER JOIN `item` ON `item`.`id`=`term`.`oid`
169 INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
170 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
171 AND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s'
172 ORDER BY term.created DESC LIMIT %d , %d ",
173 intval(local_user()), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)),
174 intval($a->pager['start']), intval($a->pager['itemspage']));
176 logger("Start fulltext search for '".$search."'", LOGGER_DEBUG);
178 if (get_config('system','use_fulltext_engine')) {
179 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
181 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
184 $r = q("SELECT STRAIGHT_JOIN `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
185 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
186 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
187 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
189 INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
190 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
191 AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND (`item`.`private` OR NOT `item`.`network` IN ('%s', '%s', '%s'))))
193 GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d ",
194 intval(local_user()), dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
195 intval($a->pager['start']), intval($a->pager['itemspage']));
199 info( t('No results.') . EOL);
205 $title = sprintf( t('Items tagged with: %s'), $search);
207 $title = sprintf( t('Search results for: %s'), $search);
209 $o .= replace_macros(get_markup_template("section_title.tpl"),array(
213 logger("Start Conversation for '".$search."'", LOGGER_DEBUG);
214 $o .= conversation($a,$r,'search',false);
216 $o .= alt_pager($a,count($r));
218 logger("Done '".$search."'", LOGGER_DEBUG);