]> git.mxchange.org Git - friendica.git/blobdiff - mod/search.php
Merge pull request #67 from tomtom84/master
[friendica.git] / mod / search.php
old mode 100644 (file)
new mode 100755 (executable)
index f7ce759..fe09b67
@@ -1,5 +1,63 @@
 <?php
 
+function search_saved_searches() {
+
+       $o = '';
+
+       $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
+               intval(local_user())
+       );
+
+       if(count($r)) {
+               $o .= '<div id="saved-search-list" class="widget">';
+               $o .= '<h3>' . t('Saved Searches') . '</h3>' . "\r\n";
+               $o .= '<ul id="saved-search-ul">' . "\r\n";
+               foreach($r as $rr) {
+                       $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";
+               }
+               $o .= '</ul><div class="clear"></div></div>' . "\r\n";
+       }               
+
+       return $o;
+
+}
+
+
+function search_init(&$a) {
+
+       $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
+
+       if(local_user()) {
+               if(x($_GET,'save') && $search) {
+                       $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
+                               intval(local_user()),
+                               dbesc($search)
+                       );
+                       if(! count($r)) {
+                               q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
+                                       intval(local_user()),
+                                       dbesc($search)
+                               );
+                       }
+               }
+               if(x($_GET,'remove') && $search) {
+                       q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
+                               intval(local_user()),
+                               dbesc($search)
+                       );
+               }
+
+               $a->page['aside'] .= search_saved_searches();
+
+       }
+       else
+               unset($_SESSION['theme']);
+
+
+
+}
+
+
 
 function search_post(&$a) {
        if(x($_POST,'search'))
@@ -20,19 +78,16 @@ function search_content(&$a) {
        require_once('include/security.php');
        require_once('include/conversation.php');
 
-       if(x($_SESSION,'theme'))
-               unset($_SESSION['theme']);
-
        $o = '<div id="live-search"></div>' . "\r\n";
 
-       $o .= '<h3>' . t('Search') . '</h3>';
+       $o .= '<h3>' . t('Search This Site') . '</h3>';
 
        if(x($a->data,'search'))
                $search = notags(trim($a->data['search']));
        else
                $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
 
-       $o .= search($search);
+       $o .= search($search,'search-box','/search',((local_user()) ? true : false));
 
        if(! $search)
                return $o;
@@ -41,23 +96,19 @@ function search_content(&$a) {
        // Only public wall posts can be shown
        // OR your own posts if you are a logged in member
 
-       $s_bool  = "AND MATCH (`item`.`body`) AGAINST ( '%s' IN BOOLEAN MODE )";
-       $s_regx  = "AND `item`.`body` REGEXP '%s' ";
+       $s_regx  = sprintf("AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' )", 
+               dbesc(preg_quote($search)), dbesc('\\]' . preg_quote($search) . '\\['));
 
-       if(mb_strlen($search) >= 3)
-               $search_alg = $s_bool;
-       else
-               $search_alg = $s_regx;
+       $search_alg = $s_regx;
 
        $r = q("SELECT COUNT(*) AS `total`
                FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
-               WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
+               WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
                AND (( `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0) 
                        OR `item`.`uid` = %d )
                AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                $search_alg ",
-               intval(local_user()),
-               dbesc($search)
+               intval(local_user())
        );
 
        if(count($r))
@@ -75,25 +126,23 @@ function search_content(&$a) {
                `user`.`nickname`
                FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
-               WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
+               WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
                AND (( `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0 ) 
                        OR `item`.`uid` = %d )
                AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                $search_alg
                ORDER BY `received` DESC LIMIT %d , %d ",
                intval(local_user()),
-               dbesc($search),
                intval($a->pager['start']),
                intval($a->pager['itemspage'])
 
        );
 
-
+       $o .= '<h2>Search results for: ' . $search . '</h2>';
 
        $o .= conversation($a,$r,'search',false);
 
        $o .= paginate($a);
-       $o .= cc_license();
 
        return $o;
 }