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']);
62 function search_post(&$a) {
63 if(x($_POST,'search'))
64 $a->data['search'] = $_POST['search'];
68 function search_content(&$a) {
70 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
71 notice( t('Public access denied.') . EOL);
75 nav_set_selected('search');
77 require_once("include/bbcode.php");
78 require_once('include/security.php');
79 require_once('include/conversation.php');
81 $o = '<div id="live-search"></div>' . "\r\n";
83 $o .= '<h3>' . t('Search This Site') . '</h3>';
85 if(x($a->data,'search'))
86 $search = notags(trim($a->data['search']));
88 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
90 $o .= search($search,'search-box','/search',((local_user()) ? true : false));
95 // Here is the way permissions work in the search module...
96 // Only public posts can be shown
97 // OR your own posts if you are a logged in member
98 // No items will be shown if the member has a blocked profile wall.
100 $r = q("SELECT COUNT(*) AS `total`
101 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
102 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
103 AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0)
104 OR `item`.`uid` = %d )
105 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
106 AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' )",
107 intval(local_user()),
108 dbesc(preg_quote($search)),
109 dbesc('\\]' . preg_quote($search) . '\\[')
113 $a->set_pager_total($r[0]['total']);
115 if(! $r[0]['total']) {
116 info( t('No results.') . EOL);
120 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
121 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
122 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
123 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
125 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
126 LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
127 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
128 AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0 )
129 OR `item`.`uid` = %d )
130 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
131 AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' )
132 ORDER BY `received` DESC LIMIT %d , %d ",
133 intval(local_user()),
134 dbesc(preg_quote($search)),
135 dbesc('\\]' . preg_quote($search) . '\\['),
136 intval($a->pager['start']),
137 intval($a->pager['itemspage'])
141 $o .= '<h2>Search results for: ' . $search . '</h2>';
143 $o .= conversation($a,$r,'search',false);