[geeklog-cvs] geeklog-1.3/system/classes search.class.php,1.29,1.30

dhaun at iowaoutdoors.org dhaun at iowaoutdoors.org
Wed Jan 5 08:01:28 EST 2005


Update of /var/cvs/geeklog-1.3/system/classes
In directory www:/tmp/cvs-serv3298

Modified Files:
	search.class.php 
Log Message:
A few optimizations and support for $_CONF['show_fullname']


Index: search.class.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/system/classes/search.class.php,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** search.class.php	1 Jan 2005 15:44:19 -0000	1.29
--- search.class.php	5 Jan 2005 13:01:25 -0000	1.30
***************
*** 9,13 ****
  // | Geeklog search class.                                                     |
  // +---------------------------------------------------------------------------+
! // | Copyright (C) 2000-2004 by the following authors:                         |
  // |                                                                           |
  // | Authors: Tony Bibbs       - tony AT geeklog DOT net                       |
--- 9,13 ----
  // | Geeklog search class.                                                     |
  // +---------------------------------------------------------------------------+
! // | Copyright (C) 2000-2005 by the following authors:                         |
  // |                                                                           |
  // | Authors: Tony Bibbs       - tony AT geeklog DOT net                       |
***************
*** 33,37 ****
  // $Id$
  
! if (eregi ('search.class.php', $HTTP_SERVER_VARS['PHP_SELF'])) {
      die ('This file can not be used on its own.');
  }
--- 33,37 ----
  // $Id$
  
! if (eregi ('search.class.php', $_SERVER['PHP_SELF'])) {
      die ('This file can not be used on its own.');
  }
***************
*** 52,56 ****
      */
      var $_query = '';
!     
      /**
      * @access private
--- 52,56 ----
      */
      var $_query = '';
! 
      /**
      * @access private
***************
*** 58,62 ****
      */
      var $_topic = '';
!     
      /**
      * @access private
--- 58,62 ----
      */
      var $_topic = '';
! 
      /**
      * @access private
***************
*** 64,68 ****
      */
      var $_dateStart = null;
!     
      /**
      * @access private
--- 64,68 ----
      */
      var $_dateStart = null;
! 
      /**
      * @access private
***************
*** 70,74 ****
      */
      var $_dateEnd = null;
!     
      /**
      * @access private
--- 70,74 ----
      */
      var $_dateEnd = null;
! 
      /**
      * @access private
***************
*** 76,80 ****
      */
      var $_author = null;
!     
      /**
      * @access private
--- 76,80 ----
      */
      var $_author = null;
! 
      /**
      * @access private
***************
*** 82,86 ****
      */
      var $_type = '';
!     
      /**
      * @access private
--- 82,86 ----
      */
      var $_type = '';
! 
      /**
      * @access private
***************
*** 88,92 ****
      */
      var $_keyType = '';
!     
      /**
      * @access private
--- 88,92 ----
      */
      var $_keyType = '';
! 
      /**
      * @access private
***************
*** 94,98 ****
      */
      var $_page = null;
!     
      /**
      * Constructor
--- 94,98 ----
      */
      var $_page = null;
! 
      /**
      * Constructor
***************
*** 106,139 ****
      function Search()
      {
-         global $HTTP_POST_VARS, $HTTP_GET_VARS;
-         
-         // This page is register_globals friendly.  Because I
-         // can't guarantee a version of PHP > 4.1 I can't simply
-         // reference $_REQUEST so $input_vars simulates this.
-         $input_vars = array();
-         if (count($HTTP_POST_VARS) == 0) {
-             $input_vars = $HTTP_GET_VARS;
-         } else {
-             $input_vars = $HTTP_POST_VARS;
-         }
-         
          // Set search criteria
!         $this->_query = strip_tags (COM_stripslashes ($input_vars['query']));
!         $this->_topic = COM_applyFilter ($input_vars['topic']);
!         $this->_dateStart = COM_applyFilter ($input_vars['datestart']);
!         $this->_dateEnd = COM_applyFilter ($input_vars['dateend']);
!         $this->_author = COM_applyFilter ($input_vars['author']);
!         $this->_type = COM_applyFilter ($input_vars['type']);
          if (empty ($this->_type)) {
              $this->_type = 'all';
          }
!         $this->_keyType = COM_applyFilter ($input_vars['keyType']);
!         $this->_page = COM_applyFilter ($input_vars['page']);
!         
          // In case we got a username instead of uid, convert it.  This should
          // make custom themes for search page easier.
          $this->_convertAuthor();
      }
!     
      /**
      * Converts a username to a uid
--- 106,127 ----
      function Search()
      {
          // Set search criteria
!         $this->_query = strip_tags (COM_stripslashes ($_REQUEST['query']));
!         $this->_topic = COM_applyFilter ($_REQUEST['topic']);
!         $this->_dateStart = COM_applyFilter ($_REQUEST['datestart']);
!         $this->_dateEnd = COM_applyFilter ($_REQUEST['dateend']);
!         $this->_author = COM_applyFilter ($_REQUEST['author']);
!         $this->_type = COM_applyFilter ($_REQUEST['type']);
          if (empty ($this->_type)) {
              $this->_type = 'all';
          }
!         $this->_keyType = COM_applyFilter ($_REQUEST['keyType']);
!         $this->_page = COM_applyFilter ($_REQUEST['page']);
! 
          // In case we got a username instead of uid, convert it.  This should
          // make custom themes for search page easier.
          $this->_convertAuthor();
      }
! 
      /**
      * Converts a username to a uid
***************
*** 159,189 ****
  
      /**
!     * Create SQL to check the topic permissions of the current user.
      *
!     * @author Dirk Haun <dirk AT haun-online DOT de>
      * @access private
      *
      */
!     function _checkTopicPermissions ()
      {
!         global $_TABLES;
  
!         $topicsql = '';
  
!         $tresult = DB_query ("SELECT tid FROM {$_TABLES['topics']}"
!                              . COM_getPermSQL ());
!         $trows = DB_numRows ($tresult);
!         if ($trows > 0) {
!             $tids = array ();
!             for ($i = 0; $i < $trows; $i++) {
!                 $T = DB_fetchArray ($tresult);
!                 $tids[] = $T['tid'];
!             }
!             if (sizeof ($tids) > 0) {
!                 $topicsql = "AND (tid IN ('" . implode ("','", $tids) . "')) ";
!             }
          }
  
!         return $topicsql;
      }
  
--- 147,169 ----
  
      /**
!     * Return the user's username or full name for display, depending
!     * on the $_CONF['show_fullname'] config.php setting
      *
!     * @author Dirk Haun <dirk AT haun-online DOT de
      * @access private
      *
      */
!     function _displayName ($username, $fullname)
      {
!         global $_CONF;
  
!         $retval = $username;
  
!         if (isset ($_CONF['show_fullname']) && ($_CONF['show_fullname'] == 1)
!                 && !empty ($fullname)) {
!             $retval = $fullname;
          }
  
!         return $retval;
      }
  
***************
*** 208,225 ****
          $resultPage = 1;
  
!         if($this->_page > 1) {
              $resultPage = $this->_page;
          }
  
-         $groupList = '';
-         if (!empty ($_USER['uid'])) {
-             foreach ($_GROUPS AS $grp) {
-                 $groupList .= $grp . ',';
-             }
-             $groupList = substr($groupList, 0, -1);
-         }
- 
          if ($this->_type == 'all' OR $this->_type == 'stories') {
!             $sql = "SELECT sid,title,introtext,bodytext,hits,uid,group_id,owner_id,perm_owner,perm_group,perm_members,perm_anon,UNIX_TIMESTAMP(date) as day,'story' as type FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW()) " . $this->_checkTopicPermissions ();
              if (!empty ($this->_query)) {
                  if($this->_keyType == 'phrase') {
--- 188,197 ----
          $resultPage = 1;
  
!         if ($this->_page > 1) {
              $resultPage = $this->_page;
          }
  
          if ($this->_type == 'all' OR $this->_type == 'stories') {
!             $sql = "SELECT u.username,u.fullname,s.uid,sid,title,introtext,bodytext,hits,UNIX_TIMESTAMP(date) AS day,'story' AS type FROM {$_TABLES['stories']} AS s,{$_TABLES['users']} AS u WHERE (draft_flag = 0) AND (date <= NOW()) AND (u.uid = s.uid) ";
              if (!empty ($this->_query)) {
                  if($this->_keyType == 'phrase') {
***************
*** 227,233 ****
                      $mywords[] = $this->_query;
                      $mysearchterm = addslashes ($this->_query);
!                     $sql .= "AND (introtext like '%$mysearchterm%'  ";
!                     $sql .= "OR bodytext like '%$mysearchterm%' ";
!                     $sql .= "OR title like '%$mysearchterm%')  ";
                  } elseif($this->_keyType == 'all') {
                      // must contain ALL of the keywords
--- 199,205 ----
                      $mywords[] = $this->_query;
                      $mysearchterm = addslashes ($this->_query);
!                     $sql .= "AND (introtext LIKE '%$mysearchterm%'  ";
!                     $sql .= "OR bodytext LIKE '%$mysearchterm%' ";
!                     $sql .= "OR title LIKE '%$mysearchterm%')  ";
                  } elseif($this->_keyType == 'all') {
                      // must contain ALL of the keywords
***************
*** 237,243 ****
                      foreach ($mywords AS $mysearchterm) {
                          $mysearchterm = addslashes (trim ($mysearchterm));
!                         $tmp .= "(introtext like '%$mysearchterm%' OR ";
!                         $tmp .= "bodytext like '%$mysearchterm%' OR ";
!                         $tmp .= "title like '%$mysearchterm%') AND ";
                      }
                      $tmp = substr($tmp, 0, strlen($tmp) - 4);
--- 209,215 ----
                      foreach ($mywords AS $mysearchterm) {
                          $mysearchterm = addslashes (trim ($mysearchterm));
!                         $tmp .= "(introtext LIKE '%$mysearchterm%' OR ";
!                         $tmp .= "bodytext LIKE '%$mysearchterm%' OR ";
!                         $tmp .= "title LIKE '%$mysearchterm%') AND ";
                      }
                      $tmp = substr($tmp, 0, strlen($tmp) - 4);
***************
*** 251,257 ****
                      foreach ($mywords AS $mysearchterm) {
                          $mysearchterm = addslashes (trim ($mysearchterm));
!                         $tmp .= "(introtext like '%$mysearchterm%' OR ";
!                         $tmp .= "bodytext like '%$mysearchterm%' OR ";
!                         $tmp .= "title like '%$mysearchterm%') OR ";
                      }
                      $tmp = substr($tmp, 0, strlen($tmp) - 3);
--- 223,229 ----
                      foreach ($mywords AS $mysearchterm) {
                          $mysearchterm = addslashes (trim ($mysearchterm));
!                         $tmp .= "(introtext LIKE '%$mysearchterm%' OR ";
!                         $tmp .= "bodytext LIKE '%$mysearchterm%' OR ";
!                         $tmp .= "title LIKE '%$mysearchterm%') OR ";
                      }
                      $tmp = substr($tmp, 0, strlen($tmp) - 3);
***************
*** 260,266 ****
                      $mywords[] = $this->_query;
                      $mysearchterm = addslashes ($this->_query);
!                     $sql .= "AND (introtext like '%$mysearchterm%'  ";
!                     $sql .= "OR bodytext like '%$mysearchterm%' ";
!                     $sql .= "OR title like '%$mysearchterm%')  ";
                  }
              }
--- 232,238 ----
                      $mywords[] = $this->_query;
                      $mysearchterm = addslashes ($this->_query);
!                     $sql .= "AND (introtext LIKE '%$mysearchterm%'  ";
!                     $sql .= "OR bodytext LIKE '%$mysearchterm%' ";
!                     $sql .= "OR title LIKE '%$mysearchterm%')  ";
                  }
              }
***************
*** 279,286 ****
                  $sql .= "AND (uid = '$this->_author') ";
              }
!             $permsql = COM_getPermSQL ('AND');
              $sql .= $permsql;
              $sql .= "ORDER BY date desc";
!     
              $result_stories = DB_query($sql);
              $nrows_stories = DB_numRows($result_stories);
--- 251,258 ----
                  $sql .= "AND (uid = '$this->_author') ";
              }
!             $permsql = COM_getPermSQL ('AND') . COM_getTopicSQL ('AND');
              $sql .= $permsql;
              $sql .= "ORDER BY date desc";
! 
              $result_stories = DB_query($sql);
              $nrows_stories = DB_numRows($result_stories);
***************
*** 300,324 ****
              // order as your headings above!
              while ($A = DB_fetchArray($result_stories)) {
!                 if (SEC_hasAccess($A['owner_id'],$A['group_id'],$A['perm_owner'],$A['perm_group'],$A['perm_members'],$A['perm_anon']) > 0) {
!                     // get rows    
!                     $A['title'] = str_replace('$','$',$A['title']);
!                     $thetime = COM_getUserDateTimeFormat($A['day']);
!                     if (empty ($urlQuery)) {
!                         $articleUrl = COM_buildUrl ($_CONF['site_url']
!                                         . '/article.php?story=' . $A['sid']);
!                     } else {
!                         $articleUrl = $_CONF['site_url'] . '/article.php?story='
!                             . $A['sid'] . '&query=' . urlencode ($urlQuery);
!                     }
!                     $row = array ('<a href="' . $articleUrl . '">'
!                             . stripslashes ($A['title']) . '</a>', $thetime[0],
!                             DB_getItem ($_TABLES['users'], 'username',
!                             "uid = '{$A['uid']}'"), $A['hits']);
!                     $story_results->addSearchResult($row);
!                     $story_results->num_searchresults++;
                  } else {
!                     // user is not allowed to see this item so don't count it either
!                     $story_results->num_itemssearched--;
                  }
              }
          } else {
--- 272,298 ----
              // order as your headings above!
              while ($A = DB_fetchArray($result_stories)) {
!                 // get rows    
!                 $A['title'] = str_replace ('$', '$', $A['title']);
!                 $thetime = COM_getUserDateTimeFormat ($A['day']);
!                 if (empty ($urlQuery)) {
!                     $articleUrl = COM_buildUrl ($_CONF['site_url']
!                                     . '/article.php?story=' . $A['sid']);
                  } else {
!                     $articleUrl = $_CONF['site_url'] . '/article.php?story='
!                         . $A['sid'] . '&query=' . urlencode ($urlQuery);
                  }
+                 $author = $this->_displayName ($A['username'], $A['fullname']);
+                 if ($A['uid'] == 1) {
+                     $profile = $author;
+                 } else {
+                     $profile = '<a href="' . $_CONF['site_url']
+                              . '/users.php?mode=profile&uid=' . $A['uid']
+                              . '">' . $author . '</a>';
+                 }
+                 $row = array ('<a href="' . $articleUrl . '">'
+                               . stripslashes ($A['title']) . '</a>',
+                               $thetime[0], $profile, $A['hits']);
+                 $story_results->addSearchResult ($row);
+                 $story_results->num_searchresults++;
              }
          } else {
***************
*** 329,333 ****
          return $story_results;
      }
!     
      /**
      * Performs search on all comments
--- 303,307 ----
          return $story_results;
      }
! 
      /**
      * Performs search on all comments
***************
*** 345,375 ****
  
              $stsql = COM_getPermSQL ('AND', 0, 2, $_TABLES['stories']);
!             $stsql .= $this->_checkTopicPermissions ();
  
              $stwhere = '';
  
!             $groupList = '';
!             if (!empty ($_USER['uid'])) {
!                 foreach ($_GROUPS as $grp) {
!                     $groupList .= $grp . ',';
!                 }
!                 $groupList = substr($groupList, 0, -1);
!             }
!             if (!empty ($_USER['uid'])) {
                  $stwhere .= "({$_TABLES['stories']}.owner_id IS NOT NULL AND {$_TABLES['stories']}.perm_owner IS NOT NULL) OR ";
                  $stwhere .= "({$_TABLES['stories']}.group_id IS NOT NULL AND {$_TABLES['stories']}.perm_group IS NOT NULL) OR ";
                  $stwhere .= "({$_TABLES['stories']}.perm_members IS NOT NULL) OR ";
              }
!             $stwhere .= "({$_TABLES['stories']}.perm_anon IS NOT NULL)";
!     
              $posql = COM_getPermSQL ('AND', 0, 2, $_TABLES['pollquestions']);
              $powhere = '';
!             if (!empty ($_USER['uid'])) {
                  $powhere .= "({$_TABLES['pollquestions']}.owner_id IS NOT NULL AND {$_TABLES['pollquestions']}.perm_owner IS NOT NULL) OR ";
                  $powhere .= "({$_TABLES['pollquestions']}.group_id IS NOT NULL AND {$_TABLES['pollquestions']}.perm_group IS NOT NULL) OR ";
                  $powhere .= "({$_TABLES['pollquestions']}.perm_members IS NOT NULL) OR ";
              }
!             $powhere .= "({$_TABLES['pollquestions']}.perm_anon IS NOT NULL)";
!     
              $mysearchterm = addslashes ($this->_query);
              $sql = "SELECT {$_TABLES['stories']}.sid,{$_TABLES['comments']}.title,comment,pid,cid,{$_TABLES['comments']}.uid,{$_TABLES['comments']}.sid AS qid,type as comment_type,UNIX_TIMESTAMP({$_TABLES['comments']}.date) as day,'comment' as type FROM {$_TABLES['comments']} ";
--- 319,344 ----
  
              $stsql = COM_getPermSQL ('AND', 0, 2, $_TABLES['stories']);
!             $stsql .= COM_getTopicSQL ('AND');
  
              $stwhere = '';
  
!             if (empty ($_USER['uid']) || ($_USER['uid'] == 1)) {
!                 $stwhere .= "({$_TABLES['stories']}.perm_anon IS NOT NULL)";
!             } else {
                  $stwhere .= "({$_TABLES['stories']}.owner_id IS NOT NULL AND {$_TABLES['stories']}.perm_owner IS NOT NULL) OR ";
                  $stwhere .= "({$_TABLES['stories']}.group_id IS NOT NULL AND {$_TABLES['stories']}.perm_group IS NOT NULL) OR ";
                  $stwhere .= "({$_TABLES['stories']}.perm_members IS NOT NULL) OR ";
              }
! 
              $posql = COM_getPermSQL ('AND', 0, 2, $_TABLES['pollquestions']);
              $powhere = '';
!             if (empty ($_USER['uid']) || ($_USER['uid'] == 1)) {
!                 $powhere .= "({$_TABLES['pollquestions']}.perm_anon IS NOT NULL)";
!             } else {
                  $powhere .= "({$_TABLES['pollquestions']}.owner_id IS NOT NULL AND {$_TABLES['pollquestions']}.perm_owner IS NOT NULL) OR ";
                  $powhere .= "({$_TABLES['pollquestions']}.group_id IS NOT NULL AND {$_TABLES['pollquestions']}.perm_group IS NOT NULL) OR ";
                  $powhere .= "({$_TABLES['pollquestions']}.perm_members IS NOT NULL) OR ";
              }
! 
              $mysearchterm = addslashes ($this->_query);
              $sql = "SELECT {$_TABLES['stories']}.sid,{$_TABLES['comments']}.title,comment,pid,cid,{$_TABLES['comments']}.uid,{$_TABLES['comments']}.sid AS qid,type as comment_type,UNIX_TIMESTAMP({$_TABLES['comments']}.date) as day,'comment' as type FROM {$_TABLES['comments']} ";
***************
*** 404,424 ****
              $comment_results->num_searchresults = 0;
              $comment_results->num_itemssearched = $B[0];
!     
              // NOTE if any of your data items need to be links then add them here! 
              // make sure data elements are in an array and in the same order as
              // your headings above!
              while ($A = DB_fetchArray($result_comments)) {
                  $A['title'] = str_replace('$','$',$A['title']);
-                 if (!empty ($this->_query)) {
-                     $querystring = '&query=' . $this->_query;
-                 } else {
-                     $querystring = '';
-                 }
                  $A['title'] = '<a href="' . $_CONF['site_url']
                              . '/comment.php?mode=view&cid=' . $A['cid']
!                             . '">' . stripslashes ($A['title']) . '</a>';
! 
                  $thetime = COM_getUserDateTimeFormat ($A['day']);
!                 $row = array ($A['title'], $thetime[0], DB_getItem ($_TABLES['users'], 'username', "uid = '{$A['uid']}'"));
                  $comment_results->addSearchResult($row);
                  $comment_results->num_searchresults++;
--- 373,406 ----
              $comment_results->num_searchresults = 0;
              $comment_results->num_itemssearched = $B[0];
! 
!             if (!empty ($this->_query)) {
!                 $querystring = '&query=' . $this->_query;
!             } else {
!                 $querystring = '';
!             }
! 
              // NOTE if any of your data items need to be links then add them here! 
              // make sure data elements are in an array and in the same order as
              // your headings above!
+             $names = array ();
              while ($A = DB_fetchArray($result_comments)) {
                  $A['title'] = str_replace('$','$',$A['title']);
                  $A['title'] = '<a href="' . $_CONF['site_url']
                              . '/comment.php?mode=view&cid=' . $A['cid']
!                             . $querystring . '">' . stripslashes ($A['title'])
!                             . '</a>';
                  $thetime = COM_getUserDateTimeFormat ($A['day']);
!                 if (empty ($names[$A['uid']])) {
!                     $names[$A['uid']] = COM_getDisplayName ($A['uid']);
!                 }
!                 $author = $names[$A['uid']];
!                 if ($A['uid'] == 1) {
!                     $profile = $author;
!                 } else {
!                     $profile = '<a href="' . $_CONF['site_url']
!                              . '/users.php?mode=profile&uid=' . $A['uid']
!                              . '">' . $author . '</a>';
!                 }
!                 $row = array ($A['title'], $thetime[0], $profile);
                  $comment_results->addSearchResult($row);
                  $comment_results->num_searchresults++;
***************
*** 429,432 ****
--- 411,415 ----
              $comment_results->num_itemssearched = 0;
          }
+ 
          return $comment_results;        
      }
***************
*** 446,450 ****
          // Build SQL
          if ( $this->_query != "" AND (($this->_type == 'links') OR ($this->_type == 'all')) ) {
!             $sql = "SELECT lid,title,description,url,hits,group_id,owner_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['links']} WHERE ";
      
              if ($this->_keyType == 'phrase') {
--- 429,433 ----
          // Build SQL
          if ( $this->_query != "" AND (($this->_type == 'links') OR ($this->_type == 'all')) ) {
!             $sql = "SELECT lid,title,description,url,hits FROM {$_TABLES['links']} WHERE ";
      
              if ($this->_keyType == 'phrase') {
***************
*** 452,458 ****
                  $mywords[] = $this->_query;
                  $mysearchterm = addslashes ($this->_query);
!                 $sql .= "(description like '%$mysearchterm%' ";
!                 $sql .= "OR title like '%$mysearchterm%')  ";
!             } else if ($this->_keyType == 'all')  { 
                  // must contain ALL of the keywords
                  $mywords = explode(' ', $this->_query);
--- 435,441 ----
                  $mywords[] = $this->_query;
                  $mysearchterm = addslashes ($this->_query);
!                 $sql .= "(description LIKE '%$mysearchterm%' ";
!                 $sql .= "OR title LIKE '%$mysearchterm%')  ";
!             } else if ($this->_keyType == 'all') {
                  // must contain ALL of the keywords
                  $mywords = explode(' ', $this->_query);
***************
*** 460,465 ****
                  foreach ($mywords AS $mysearchterm) {
                      $mysearchterm = addslashes (trim ($mysearchterm));
!                     $tmp .= "(description like '%$mysearchterm%' OR ";
!                     $tmp .= "title like '%$mysearchterm%') AND ";
                  }
                  $tmp = substr($tmp, 0, strlen($tmp) - 4);
--- 443,448 ----
                  foreach ($mywords AS $mysearchterm) {
                      $mysearchterm = addslashes (trim ($mysearchterm));
!                     $tmp .= "(description LIKE '%$mysearchterm%' OR ";
!                     $tmp .= "title LIKE '%$mysearchterm%') AND ";
                  }
                  $tmp = substr($tmp, 0, strlen($tmp) - 4);
***************
*** 471,476 ****
                  foreach ($mywords AS $mysearchterm) {
                      $mysearchterm = addslashes (trim ($mysearchterm));
!                     $tmp .= "(description like '%$mysearchterm%' OR ";
!                     $tmp .= "title like '%$mysearchterm%') OR ";
                  }
                  $tmp = substr($tmp,0,strlen($tmp)-3);
--- 454,459 ----
                  foreach ($mywords AS $mysearchterm) {
                      $mysearchterm = addslashes (trim ($mysearchterm));
!                     $tmp .= "(description LIKE '%$mysearchterm%' OR ";
!                     $tmp .= "title LIKE '%$mysearchterm%') OR ";
                  }
                  $tmp = substr($tmp,0,strlen($tmp)-3);
***************
*** 479,484 ****
                  $mywords[] = $this->_query;
                  $mysearchterm = addslashes ($this->_query);
!                 $sql .= "(description like '%$mysearchterm%' ";
!                 $sql .= "OR title like '%$mysearchterm%')  ";
              }
      
--- 462,467 ----
                  $mywords[] = $this->_query;
                  $mysearchterm = addslashes ($this->_query);
!                 $sql .= "(description LIKE '%$mysearchterm%' ";
!                 $sql .= "OR title LIKE '%$mysearchterm%') ";
              }
      
***************
*** 491,495 ****
                  $sql .= "AND (UNIX_TIMESTAMP(date) BETWEEN '$startdate' AND '$enddate') ";
              }
!             $sql .= "ORDER BY title ASC";
              $result_links = DB_query($sql);
              $nrows_links = DB_numRows($result_links);
--- 474,479 ----
                  $sql .= "AND (UNIX_TIMESTAMP(date) BETWEEN '$startdate' AND '$enddate') ";
              }
!             $sql .= COM_getPermSQL ('AND');
!             $sql .= " ORDER BY title ASC";
              $result_links = DB_query($sql);
              $nrows_links = DB_numRows($result_links);
***************
*** 506,522 ****
              // your headings above!
              while ($A = DB_fetchArray($result_links)) {
!                 if (SEC_hasAccess($A['owner_id'],$A['group_id'],$A['perm_owner'],$A['perm_group'],$A['perm_members'],$A['perm_anon']) > 0) {
!                     $thetime = COM_getUserDateTimeFormat($A['day']);
!                     $row = array (stripslashes ($A['title']),
!                                   '<a href="' . COM_buildUrl ($_CONF['site_url']
!                                   . '/portal.php?what=link&item='
!                                   . $A['lid']) . '">' . $A['url'] . '</a>',
!                                   $A['hits']);
!                     $link_results->addSearchResult($row);
!                     $link_results->num_searchresults++;
!                 } else {
!                     // user is not allowed to see this item so don't count it either
!                     $link_results->num_itemssearched--;
!                 }
              }
          } else {
--- 490,500 ----
              // your headings above!
              while ($A = DB_fetchArray($result_links)) {
!                 $thetime = COM_getUserDateTimeFormat($A['day']);
!                 $row = array (stripslashes ($A['title']),
!                               '<a href="' . COM_buildUrl ($_CONF['site_url']
!                               . '/portal.php?what=link&item=' . $A['lid'])
!                               . '">' . $A['url'] . '</a>', $A['hits']);
!                 $link_results->addSearchResult($row);
!                 $link_results->num_searchresults++;
              }
          } else {
***************
*** 539,554 ****
      {
          global $_CONF, $_TABLES, $LANG09, $LANG12;
!     
          if (($this->_type == 'events') OR
              (($this->_type == 'all') AND empty($this->_author))) {
!             $sql = "SELECT eid,title,description,location,datestart,dateend,timestart,timeend,group_id,owner_id,perm_owner,perm_group,perm_members,perm_anon,UNIX_TIMESTAMP(datestart) as day FROM {$_TABLES['events']} WHERE ";
!     
              if($this->_keyType == 'phrase') {
                  // do an exact phrase search (default)
                  $mywords[] = $this->_query;
                  $mysearchterm = addslashes ($this->_query);
!                 $sql .= "(location like '%$mysearchterm%'  ";
!                 $sql .= "OR description like '%$mysearchterm%' ";
!                 $sql .= "OR title like '%$mysearchterm%') ";
              } 
              elseif($this->_keyType == 'all') {
--- 517,532 ----
      {
          global $_CONF, $_TABLES, $LANG09, $LANG12;
! 
          if (($this->_type == 'events') OR
              (($this->_type == 'all') AND empty($this->_author))) {
!             $sql = "SELECT eid,title,description,location,datestart,dateend,timestart,timeend,UNIX_TIMESTAMP(datestart) AS day FROM {$_TABLES['events']} WHERE ";
! 
              if($this->_keyType == 'phrase') {
                  // do an exact phrase search (default)
                  $mywords[] = $this->_query;
                  $mysearchterm = addslashes ($this->_query);
!                 $sql .= "(location LIKE '%$mysearchterm%'  ";
!                 $sql .= "OR description LIKE '%$mysearchterm%' ";
!                 $sql .= "OR title LIKE '%$mysearchterm%') ";
              } 
              elseif($this->_keyType == 'all') {
***************
*** 558,564 ****
                  foreach ($mywords AS $mysearchterm) {
                      $mysearchterm = addslashes (trim ($mysearchterm));
!                     $tmp .= "(location like '%$mysearchterm%' OR ";
!                     $tmp .= "description like '%$mysearchterm%' OR ";
!                     $tmp .= "title like '%$mysearchterm%') AND ";
                  }
                  $tmp = substr($tmp, 0, strlen($tmp) - 4);
--- 536,542 ----
                  foreach ($mywords AS $mysearchterm) {
                      $mysearchterm = addslashes (trim ($mysearchterm));
!                     $tmp .= "(location LIKE '%$mysearchterm%' OR ";
!                     $tmp .= "description LIKE '%$mysearchterm%' OR ";
!                     $tmp .= "title LIKE '%$mysearchterm%') AND ";
                  }
                  $tmp = substr($tmp, 0, strlen($tmp) - 4);
***************
*** 570,576 ****
                  foreach ($mywords AS $mysearchterm) {
                      $mysearchterm = addslashes (trim ($mysearchterm));
!                     $tmp .= "(location like '%$mysearchterm%' OR ";
!                     $tmp .= "description like '%$mysearchterm%' OR ";
!                     $tmp .= "title like '%$mysearchterm%') OR ";
                  }
                  $tmp = substr($tmp, 0, strlen($tmp) - 3);
--- 548,554 ----
                  foreach ($mywords AS $mysearchterm) {
                      $mysearchterm = addslashes (trim ($mysearchterm));
!                     $tmp .= "(location LIKE '%$mysearchterm%' OR ";
!                     $tmp .= "description LIKE '%$mysearchterm%' OR ";
!                     $tmp .= "title LIKE '%$mysearchterm%') OR ";
                  }
                  $tmp = substr($tmp, 0, strlen($tmp) - 3);
***************
*** 581,587 ****
                  $mywords[] = $this->_query;
                  $mysearchterm = addslashes ($this->_query);
!                 $sql .= "(location like '%$mysearchterm%'  ";
!                 $sql .= "OR description like '%$mysearchterm%' ";
!                 $sql .= "OR title like '%$mysearchterm%')  ";
              }
  
--- 559,565 ----
                  $mywords[] = $this->_query;
                  $mysearchterm = addslashes ($this->_query);
!                 $sql .= "(location LIKE '%$mysearchterm%'  ";
!                 $sql .= "OR description LIKE '%$mysearchterm%' ";
!                 $sql .= "OR title LIKE '%$mysearchterm%')  ";
              }
  
***************
*** 594,597 ****
--- 572,576 ----
                  $sql .= "AND (UNIX_TIMESTAMP(datestart) BETWEEN '$startdate' AND '$enddate') ";
              }
+             $sql .= COM_getPermSQL ('AND');
              $sql .= "ORDER BY datestart desc";
              $result_events = DB_query($sql);
***************
*** 611,635 ****
              // headings above!
              while ($A = DB_fetchArray($result_events)) {
!                 if (SEC_hasAccess($A['owner_id'],$A['group_id'],$A['perm_owner'],$A['perm_group'],$A['perm_members'],$A['perm_anon']) > 0) {
!                     if ($A['allday'] == 0) {
!                         $fulldate = $A['datestart'] . ' ' . $A['timestart'] . ' - ' . $A['dateend'] . ' ' . $A['timeend'];
                      } else {
!                         if ($A['datestart'] <> $A['dateend']) {
!                             $fulldate = $A['datestart'] . ' - ' . $A['dateend'] . ' ' . $LANG09[35];
!                         } else {
!                             $fulldate = $A['datestart'] . ' ' . $LANG09[35];
!                         }
                      }
-                     $thetime = COM_getUserDateTimeFormat($A['day']);
-                     $A['title'] = str_replace('$','$',$A['title']);
-                     $row = array('<a href="' . $_CONF['site_url'] . '/calendar_event.php?eid=' . $A['eid'] . '">' . $A['title'] . '</a>',
-                                 $fulldate,
-                                 $A['location'],$A['description']);
-                     $event_results->addSearchResult($row);
-                     $event_results->num_searchresults++;
-                 } else {
-                     // user is not allowed to see this item so don't count it either
-                     $event_results->num_itemssearched--;
                  }
              }
          } else {
--- 590,612 ----
              // headings above!
              while ($A = DB_fetchArray($result_events)) {
!                 if ($A['allday'] == 0) {
!                     $fulldate = $A['datestart'] . ' ' . $A['timestart'] . ' - '
!                               . $A['dateend'] . ' ' . $A['timeend'];
!                 } else {
!                     if ($A['datestart'] <> $A['dateend']) {
!                         $fulldate = $A['datestart'] . ' - ' . $A['dateend']
!                                   . ' ' . $LANG09[35];
                      } else {
!                         $fulldate = $A['datestart'] . ' ' . $LANG09[35];
                      }
                  }
+                 $thetime = COM_getUserDateTimeFormat ($A['day']);
+                 $A['title'] = str_replace ('$', '$', $A['title']);
+                 $row = array ('<a href="' . $_CONF['site_url']
+                               . '/calendar_event.php?eid=' . $A['eid'] . '">'
+                               . $A['title'] . '</a>',
+                               $fulldate, $A['location'], $A['description']);
+                 $event_results->addSearchResult($row);
+                 $event_results->num_searchresults++;
              }
          } else {
***************
*** 1023,1030 ****
              
              if (!empty ($inlist)) {
!                 $result = DB_query("SELECT uid,username FROM {$_TABLES['users']} WHERE uid in ($inlist) ORDER by username");
                  $useroptions = '';
                  while ($A = DB_fetchArray($result)) {
!                     $useroptions .= '<option value="' . $A['uid'] . '">' . $A['username'] . '</option>';
                  }
                  $searchform->set_var('author_option_list', $useroptions);
--- 1000,1020 ----
              
              if (!empty ($inlist)) {
!                 $sql = "SELECT uid,username,fullname FROM {$_TABLES['users']} WHERE uid IN ($inlist)";
!                 if (isset ($_CONF['show_fullname']) &&
!                         ($_CONF['show_fullname'] == 1)) {
!                     /* Caveat: This will group all users with an emtpy fullname
!                      *         together, so it's not exactly sorted by their
!                      *         full name ...
!                      */
!                     $sql .= ' ORDER BY fullname,username';
!                 } else {
!                     $sql .= ' ORDER BY username';
!                 }
!                 $result = DB_query ($sql);
                  $useroptions = '';
                  while ($A = DB_fetchArray($result)) {
!                     $useroptions .= '<option value="' . $A['uid'] . '">'
!                         . $this->_displayName ($A['username'], $A['fullname'])
!                         . '</option>';
                  }
                  $searchform->set_var('author_option_list', $useroptions);
***************
*** 1044,1048 ****
          return $retval;
      }
!     
      /**
      * Kicks off the appropriate search(es)
--- 1034,1038 ----
          return $retval;
      }
! 
      /**
      * Kicks off the appropriate search(es)
***************
*** 1072,1076 ****
          // Have plugins do their searches
          list($nrows_plugins, $total_plugins, $result_plugins) = PLG_doSearch($this->_query, $this->_dateStart, $this->_dateEnd, $this->_topic, $this->_type, $this->_author, $this->_keyType);
!         
          // Add the core GL object search results to plugin results
          $nrows_plugins = $nrows_plugins + $this->story_results->num_searchresults;
--- 1062,1066 ----
          // Have plugins do their searches
          list($nrows_plugins, $total_plugins, $result_plugins) = PLG_doSearch($this->_query, $this->_dateStart, $this->_dateEnd, $this->_topic, $this->_type, $this->_author, $this->_keyType);
! 
          // Add the core GL object search results to plugin results
          $nrows_plugins = $nrows_plugins + $this->story_results->num_searchresults;
***************
*** 1078,1099 ****
          $nrows_plugins = $nrows_plugins + $this->link_results->num_searchresults;
          $nrows_plugins = $nrows_plugins + $this->event_results->num_searchresults;
!         
          $total_plugins = $total_plugins + $this->story_results->num_itemssearched;
          $total_plugins = $total_plugins + $this->comment_results->num_itemssearched;
          $total_plugins = $total_plugins + $this->link_results->num_itemssearched;
          $total_plugins = $total_plugins + $this->event_results->num_itemssearched;
!         
          // Move GL core objects to front of array
          array_unshift($result_plugins, $this->story_results, $this->comment_results, $this->link_results, $this->event_results);
!         
          // Searches are done, stop timer
          $searchtime = $searchtimer->stopTimer();
!       
          // Format results
          $retval = $this->_formatResults($nrows_plugins, $total_plugins, $result_plugins, $searchtime);
!         
          return $retval;
      }
!     
  }
  
--- 1068,1089 ----
          $nrows_plugins = $nrows_plugins + $this->link_results->num_searchresults;
          $nrows_plugins = $nrows_plugins + $this->event_results->num_searchresults;
! 
          $total_plugins = $total_plugins + $this->story_results->num_itemssearched;
          $total_plugins = $total_plugins + $this->comment_results->num_itemssearched;
          $total_plugins = $total_plugins + $this->link_results->num_itemssearched;
          $total_plugins = $total_plugins + $this->event_results->num_itemssearched;
! 
          // Move GL core objects to front of array
          array_unshift($result_plugins, $this->story_results, $this->comment_results, $this->link_results, $this->event_results);
! 
          // Searches are done, stop timer
          $searchtime = $searchtimer->stopTimer();
! 
          // Format results
          $retval = $this->_formatResults($nrows_plugins, $total_plugins, $result_plugins, $searchtime);
! 
          return $retval;
      }
! 
  }
  




More information about the geeklog-cvs mailing list