]> 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 d150b2e..fe09b67
@@ -4,17 +4,18 @@ function search_saved_searches() {
 
        $o = '';
 
-       $r = q("select `term` from `search` WHERE `uid` = %d",
+       $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 .= '<div id="saved-search-list"><ul id="saved-search-ul">' . "\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 .= '<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>' . "\r\n";
+               $o .= '</ul><div class="clear"></div></div>' . "\r\n";
        }               
 
        return $o;
@@ -49,6 +50,9 @@ function search_init(&$a) {
                $a->page['aside'] .= search_saved_searches();
 
        }
+       else
+               unset($_SESSION['theme']);
+
 
 
 }
@@ -67,17 +71,16 @@ function search_content(&$a) {
                notice( t('Public access denied.') . EOL);
                return;
        }
+       
+       nav_set_selected('search');
 
        require_once("include/bbcode.php");
        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']));
@@ -93,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))
@@ -127,20 +126,19 @@ 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);