Fixed bug #9994: ereg* is deprecated in PHP 5.3 alpha3
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / pi / class.tx_indexedsearch.php
index ccc19b5..18a0f4e 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2001-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 2001-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -154,7 +154,20 @@ class tx_indexedsearch extends tslib_pibase {
        var $resultSections = array();          // Page tree sections for search result.
        var $external_parsers = array();        // External parser objects
        var $iconFileNameCache = array();       // Storage of icons....
-       var $lexerObj;                          // Lexer object
+
+       /**
+        * Lexer object
+        *
+        * @var tx_indexedsearch_lexer
+        */
+       var $lexerObj;
+
+       /**
+        * Indexer object
+        *
+        * @var tx_indexedsearch_indexer
+        */
+       var $indexerObj;
        var $templateCode;                      // Will hold the content of $conf['templateFile']
        var $hiddenFieldList = 'ext, type, defOp, media, order, group, lang, desc, results';
 
@@ -304,6 +317,10 @@ class tx_indexedsearch extends tslib_pibase {
                        }
                }
 
+                       // Should we use join_pages instead of long lists of uids?
+               if ($this->conf['search.']['skipExtendToSubpagesChecking'])     {
+                       $this->join_pages = 1;
+               }
 
                        // Add media to search in:
                if (strlen(trim($this->conf['search.']['mediaList'])))  {
@@ -332,12 +349,14 @@ class tx_indexedsearch extends tslib_pibase {
                if ($this->conf['show.']['L1sections']) {
                        $firstLevelMenu = $this->getMenu($this->wholeSiteIdList);
                        while(list($kk,$mR) = each($firstLevelMenu))    {
-                               if ($mR['doktype']!=5)  {
+                                       // @TODO: RFC #7370: doktype 2&5 are deprecated since TYPO3 4.2-beta1
+                               if ($mR['doktype']!=5 && !$mR['nav_hide']) {
                                        $this->optValues['sections']['rl1_'.$mR['uid']] = trim($this->pi_getLL('opt_RL1').' '.$mR['title']);
                                        if ($this->conf['show.']['L2sections']) {
                                                $secondLevelMenu = $this->getMenu($mR['uid']);
                                                while(list($kk2,$mR2) = each($secondLevelMenu)) {
-                                                       if ($mR['doktype']!=5)  {
+                                                               // @TODO: RFC #7370: doktype 2&5 are deprecated since TYPO3 4.2-beta1
+                                                       if ($mR2['doktype']!=5 && !$mR2['nav_hide']) {
                                                                $this->optValues['sections']['rl2_'.$mR2['uid']] = trim($this->pi_getLL('opt_RL2').' '.$mR2['title']);
                                                        } else unset($secondLevelMenu[$kk2]);
                                                }
@@ -564,8 +583,10 @@ class tx_indexedsearch extends tslib_pibase {
                        $c = 0; // Result pointer: Counts up the position in the current search-result
                        $grouping_phashes = array();    // Used to filter out duplicates.
                        $grouping_chashes = array();    // Used to filter out duplicates BASED ON cHash.
-                       $firstRow = Array();    // Will hold the first row in result - used to calculate relative hit-ratings.
-                       $resultRows = Array();  // Will hold the results rows for display.
+                       $firstRow = array();    // Will hold the first row in result - used to calculate relative hit-ratings.
+                       $resultRows = array();  // Will hold the results rows for display.
+
+                       $exactCount = $this->conf['search.']['exactCount'];     // Continue counting and checking of results even if we are sure they are not displayed in this request. This will slow down your page rendering, but it allows precise search result counters.
 
                                // Now, traverse result and put the rows to be displayed into an array
                                // Each row should contain the fields from 'ISEC.*, IP.*' combined + artificial fields "show_resume" (boolean) and "result_number" (counter)
@@ -590,11 +611,11 @@ class tx_indexedsearch extends tslib_pibase {
                                                $c++;   // Increase the result pointer
 
                                                        // All rows for display is put into resultRows[]
-                                               if ($c > $pointer * $this->piVars['results'])   {
+                                               if ($c > $pointer * $this->piVars['results'] && $c <= ($pointer * $this->piVars['results'] + $this->piVars['results'])) {
                                                        $row['result_number'] = $c;
                                                        $resultRows[] = $row;
-                                                               // This may lead to a problem: If the result check is not stopped here, the search will take longer. However the result counter will not filter out grouped cHashes/pHashes that were not processed yet.
-                                                       if (($c+1) > ($pointer+1)*$this->piVars['results'])     break;
+                                                               // This may lead to a problem: If the result check is not stopped here, the search will take longer. However the result counter will not filter out grouped cHashes/pHashes that were not processed yet. You can change this behavior using the "search.exactCount" property (see above).
+                                                       if (!$exactCount && (($c+1) > ($pointer+1)*$this->piVars['results']))   { break; }
                                                }
                                        } else {
                                                $count--;       // Skip this row if the user cannot view it (missing permission)
@@ -682,7 +703,7 @@ class tx_indexedsearch extends tslib_pibase {
                        // Print a message telling which words we searched for, and in which sections etc.
                $what = $this->tellUsWhatIsSeachedFor($sWArr).
                                (substr($this->piVars['sections'],0,2)=='rl'?' '.$this->pi_getLL('inSection','',1).' "'.substr($this->getPathFromPageId(substr($this->piVars['sections'],4)),1).'"':'');
-               $what = '<div'.$this->pi_classParam('whatis').'><p>'.$what.'</p></div>';
+               $what = '<div'.$this->pi_classParam('whatis').'>'.$this->cObj->stdWrap($what, $this->conf['whatis_stdWrap.']).'</div>';
                $content = $what.$content;
 
                        // Return content:
@@ -820,23 +841,23 @@ class tx_indexedsearch extends tslib_pibase {
 
                                // Perform search for word:
                        switch($theType)        {
-                               case '1':
+                               case '1':       // Part of word
                                        $wSel = "IW.baseword LIKE '%".$GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_words')."%'";
                                        $res = $this->execPHashListQuery($wSel,' AND is_stopword=0');
                                break;
-                               case '2':
+                               case '2':       // First part of word
                                        $wSel = "IW.baseword LIKE '".$GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_words')."%'";
                                        $res = $this->execPHashListQuery($wSel,' AND is_stopword=0');
                                break;
-                               case '3':
+                               case '3':       // Last part of word
                                        $wSel = "IW.baseword LIKE '%".$GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_words')."'";
                                        $res = $this->execPHashListQuery($wSel,' AND is_stopword=0');
                                break;
-                               case '10':
+                               case '10':      // Sounds like
                                        $wSel = 'IW.metaphone = '.$this->indexerObj->metaphone($sWord);
                                        $res = $this->execPHashListQuery($wSel,' AND is_stopword=0');
                                break;
-                               case '20':
+                               case '20':      // Sentence
                                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                                                'ISEC.phash',
                                                                'index_section ISEC, index_fulltext IFT',
@@ -849,7 +870,7 @@ class tx_indexedsearch extends tslib_pibase {
 
                                        if ($this->piVars['type']==20)  $this->piVars['order'] = 'mtime';               // If there is a fulltext search for a sentence there is a likeliness that sorting cannot be done by the rankings from the rel-table (because no relations will exist for the sentence in the word-table). So therefore mtime is used instaed. It is not required, but otherwise some hits may be left out.
                                break;
-                               default:
+                               default:        // Distinct word
                                        $wSel = 'IW.wid = '.$hash = $this->indexerObj->md5inthash($sWord);
                                        $res = $this->execPHashListQuery($wSel,' AND is_stopword=0');
                                break;
@@ -1307,7 +1328,7 @@ class tx_indexedsearch extends tslib_pibase {
                        // Multilangual text
                $substituteArray = array('searchFor', 'extResume', 'atATime', 'orderBy', 'fromSection', 'searchIn', 'match', 'style', 'freeIndexUid');
                foreach ($substituteArray as $marker)   {
-                       $markerArray['###FORM_'.strtoupper($marker).'###'] = $this->pi_getLL('form_'.$marker,'',1);
+                       $markerArray['###FORM_'.t3lib_div::strtoupper($marker).'###'] = $this->pi_getLL('form_'.$marker,'',1);
                }
 
                $markerArray['###FORM_SUBMIT###'] = $this->pi_getLL('submit_button_label','',1);
@@ -1324,7 +1345,7 @@ class tx_indexedsearch extends tslib_pibase {
                        $html = $this->cObj->substituteSubpart($html, '###ADDITONAL_KEYWORD###', '');
                }
 
-               $markerArray['###ACTION_URL###'] = $this->pi_getPageLink($GLOBALS['TSFE']->id, $GLOBALS['TSFE']->sPre);
+               $markerArray['###ACTION_URL###'] = htmlspecialchars($this->pi_getPageLink($GLOBALS['TSFE']->id, $GLOBALS['TSFE']->sPre));
 
                $hiddenFieldCode = $this->cObj->getSubpart($this->templateCode, '###HIDDEN_FIELDS###');
                $hiddenFieldCode = preg_replace('/^\n\t(.+)/ms', '$1', $hiddenFieldCode);               // Remove first newline and tab (cosmetical issue)
@@ -1575,7 +1596,7 @@ class tx_indexedsearch extends tslib_pibase {
 
                        if (is_array($tmplContent))     {
                                foreach ($tmplContent AS $k => $v)      {
-                                       $markerArray['###'.strtoupper($k).'###'] = $v;
+                                       $markerArray['###'.t3lib_div::strtoupper($k).'###'] = $v;
                                }
                        }
 
@@ -2003,17 +2024,17 @@ class tx_indexedsearch extends tslib_pibase {
                                        // Possibly shorten string:
                                if (!$k)        {       // First entry at all (only cropped on the frontside)
                                        if ($strLen > $postPreLgd)      {
-                                               $output[$k] = $divider.ereg_replace('^[^[:space:]]+[[:space:]]','',$GLOBALS['TSFE']->csConvObj->crop('utf-8',$parts[$k],-($postPreLgd-$postPreLgd_offset)));
+                                               $output[$k] = $divider.preg_replace('/^[^[:space:]]+[[:space:]]/','',$GLOBALS['TSFE']->csConvObj->crop('utf-8',$parts[$k],-($postPreLgd-$postPreLgd_offset)));
                                        }
                                } elseif ($summaryLgd > $summaryMax || !isset($parts[$k+1])) {  // In case summary length is exceed OR if there are no more entries at all:
                                        if ($strLen > $postPreLgd)      {
-                                               $output[$k] = ereg_replace('[[:space:]][^[:space:]]+$','',$GLOBALS['TSFE']->csConvObj->crop('utf-8',$parts[$k],$postPreLgd-$postPreLgd_offset)).$divider;
+                                               $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/','',$GLOBALS['TSFE']->csConvObj->crop('utf-8',$parts[$k],$postPreLgd-$postPreLgd_offset)).$divider;
                                        }
                                } else {        // In-between search words:
                                        if ($strLen > $postPreLgd*2)    {
-                                               $output[$k] = ereg_replace('[[:space:]][^[:space:]]+$','',$GLOBALS['TSFE']->csConvObj->crop('utf-8',$parts[$k],$postPreLgd-$postPreLgd_offset)).
+                                               $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/','',$GLOBALS['TSFE']->csConvObj->crop('utf-8',$parts[$k],$postPreLgd-$postPreLgd_offset)).
                                                                                $divider.
-                                                                               ereg_replace('^[^[:space:]]+[[:space:]]','',$GLOBALS['TSFE']->csConvObj->crop('utf-8',$parts[$k],-($postPreLgd-$postPreLgd_offset)));
+                                                                               preg_replace('/^[^[:space:]]+[[:space:]]/','',$GLOBALS['TSFE']->csConvObj->crop('utf-8',$parts[$k],-($postPreLgd-$postPreLgd_offset)));
                                        }
                                }
                                $summaryLgd+= $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $output[$k]);;
@@ -2066,9 +2087,12 @@ class tx_indexedsearch extends tslib_pibase {
         * @return      array           Modified template array
         */
        function makeInfo($row,$tmplArray)      {
+               $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
+               $timeFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
+
                $tmplArray['size'] = t3lib_div::formatSize($row['item_size']);
-               $tmplArray['created'] = date('d-m-y',$row['item_crdate']);
-               $tmplArray['modified'] = date('d-m-y H:i',$row['item_mtime']);
+               $tmplArray['created'] = date($dateFormat, $row['item_crdate']);
+               $tmplArray['modified'] = date($dateFormat.' '.$timeFormat, $row['item_mtime']);
 
                $pathId = $row['data_page_id']?$row['data_page_id']:$row['page_id'];
                $pathMP = $row['data_page_id']?$row['data_page_mp']:'';
@@ -2241,7 +2265,7 @@ class tx_indexedsearch extends tslib_pibase {
        function getFirstSysDomainRecordForPage($id)    {
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('domainName', 'sys_domain', 'pid='.intval($id).$this->cObj->enableFields('sys_domain'), '', 'sorting');
                $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
-               return ereg_replace('\/$','',$row['domainName']);
+               return rtrim($row['domainName'], '/');
        }
 
        /**
@@ -2310,6 +2334,7 @@ class tx_indexedsearch extends tslib_pibase {
                        while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
                                $output[$row['uid']] = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        return $output;
                } else {
                        return $GLOBALS['TSFE']->sys_page->getMenu($id);
@@ -2360,4 +2385,5 @@ class tx_indexedsearch extends tslib_pibase {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/indexed_search/pi/class.tx_indexedsearch.php'])       {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/indexed_search/pi/class.tx_indexedsearch.php']);
 }
+
 ?>