search.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Search extends oxUBase
00008 {
00009 
00015     protected $_iAllArtCnt = 0;
00016 
00022     protected $_iCntPages = null;
00023 
00029     protected $_sThisTemplate = 'page/search/search.tpl';
00030 
00036     protected $_sListType = 'search';
00037 
00043     protected $_blShowSorting = true;
00044 
00050     protected $_blEmptySearch = null;
00051 
00057     protected $_oRecommList = null;
00058 
00064     protected $_sSearchParamForHtml = null;
00065 
00071     protected $_sSearchParam = null;
00072 
00078     protected $_sSearchCatId = null;
00079 
00085     protected $_sSearchVendor = null;
00086 
00092     protected $_sSearchManufacturer = null;
00093 
00099     protected $_blSearchClass = null;
00100 
00106     protected $_oPageNavigation = null;
00107 
00113     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00114 
00120     protected $_aSimilarRecommListIds = null;
00121 
00122 
00131     public function init()
00132     {
00133         parent::init();
00134 
00135         $myConfig = $this->getConfig();
00136 
00137         // #1184M - special char search
00138         $oConfig = oxRegistry::getConfig();
00139         $sSearchParamForQuery = trim($oConfig->getRequestParameter('searchparam', true));
00140 
00141         // searching in category ?
00142         $sInitialSearchCat = $this->_sSearchCatId = rawurldecode($oConfig->getRequestParameter('searchcnid'));
00143 
00144         // searching in vendor #671
00145         $sInitialSearchVendor = rawurldecode($oConfig->getRequestParameter('searchvendor'));
00146 
00147         // searching in Manufacturer #671
00148         $sManufacturerParameter = $oConfig->getRequestParameter('searchmanufacturer');
00149         $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode($sManufacturerParameter);
00150 
00151         $this->_blEmptySearch = false;
00152         if (!$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer) {
00153             //no search string
00154             $this->_aArticleList = null;
00155             $this->_blEmptySearch = true;
00156 
00157             return false;
00158         }
00159 
00160         // config allows to search in Manufacturers ?
00161         if (!$myConfig->getConfigParam('bl_perfLoadManufacturerTree')) {
00162             $sInitialSearchManufacturer = null;
00163         }
00164 
00165         // searching ..
00167         $oSearchHandler = oxNew('oxsearch');
00168         $oSearchList = $oSearchHandler->getSearchArticles(
00169             $sSearchParamForQuery,
00170             $sInitialSearchCat,
00171             $sInitialSearchVendor,
00172             $sInitialSearchManufacturer,
00173             $this->getSortingSql($this->getSortIdent())
00174         );
00175 
00176         // list of found articles
00177         $this->_aArticleList = $oSearchList;
00178         $this->_iAllArtCnt = 0;
00179 
00180         // skip count calculation if no articles in list found
00181         if ($oSearchList->count()) {
00182             $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount(
00183                 $sSearchParamForQuery,
00184                 $sInitialSearchCat,
00185                 $sInitialSearchVendor,
00186                 $sInitialSearchManufacturer
00187             );
00188         }
00189 
00190         $iNrofCatArticles = (int) $myConfig->getConfigParam('iNrofCatArticles');
00191         $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
00192         $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
00193     }
00194 
00201     public function render()
00202     {
00203         parent::render();
00204 
00205         $oConfig = $this->getConfig();
00206         if ($oConfig->getConfigParam('bl_rssSearch')) {
00207             $oRss = oxNew('oxrssfeed');
00208             $sSearch = $oConfig->getRequestParameter('searchparam', true);
00209             $sCnid = $oConfig->getRequestParameter('searchcnid', true);
00210             $sVendor = $oConfig->getRequestParameter('searchvendor', true);
00211             $sManufacturer = $oConfig->getRequestParameter('searchmanufacturer', true);
00212             $sSearchArticlesTitle = $oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor, $sManufacturer);
00213             $sSearchArticlesUrl = $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor, $sManufacturer);
00214             $this->addRssFeed($sSearchArticlesTitle, $sSearchArticlesUrl, 'searchArticles');
00215         }
00216 
00217         // processing list articles
00218         $this->_processListArticles();
00219 
00220         return $this->_sThisTemplate;
00221     }
00222 
00227     protected function _processListArticles()
00228     {
00229         $sAddDynParams = $this->getAddUrlParams();
00230         if ($sAddDynParams && ($aArtList = $this->getArticleList())) {
00231             $blSeo = oxRegistry::getUtils()->seoIsActive();
00232             foreach ($aArtList as $oArticle) {
00233                 // appending std and dynamic urls
00234                 if (!$blSeo) {
00235                     // only if seo is off..
00236                     $oArticle->appendStdLink($sAddDynParams);
00237                 }
00238                 $oArticle->appendLink($sAddDynParams);
00239             }
00240         }
00241     }
00242 
00248     public function getAddUrlParams()
00249     {
00250         $sAddParams = parent::getAddUrlParams();
00251         $sAddParams .= ($sAddParams ? '&amp;' : '') . "listtype={$this->_sListType}";
00252         $oConfig = $this->getConfig();
00253 
00254         if ($sParam = $oConfig->getRequestParameter('searchparam', true)) {
00255             $sAddParams .= "&amp;searchparam=" . rawurlencode($sParam);
00256         }
00257 
00258         if ($sParam = $oConfig->getRequestParameter('searchcnid')) {
00259             $sAddParams .= "&amp;searchcnid=$sParam";
00260         }
00261 
00262         if ($sParam = rawurldecode($oConfig->getRequestParameter('searchvendor'))) {
00263             $sAddParams .= "&amp;searchvendor=$sParam";
00264         }
00265 
00266         if ($sParam = rawurldecode($oConfig->getRequestParameter('searchmanufacturer'))) {
00267             $sAddParams .= "&amp;searchmanufacturer=$sParam";
00268         }
00269 
00270         return $sAddParams;
00271     }
00272 
00278     protected function _isSearchClass()
00279     {
00280         if ($this->_blSearchClass === null) {
00281             $this->_blSearchClass = false;
00282             if (strtolower($this->getConfig()->getRequestParameter('cl')) == 'search') {
00283                 $this->_blSearchClass = true;
00284             }
00285         }
00286 
00287         return $this->_blSearchClass;
00288     }
00289 
00295     public function isEmptySearch()
00296     {
00297         return $this->_blEmptySearch;
00298     }
00299 
00305     public function getArticleList()
00306     {
00307         return $this->_aArticleList;
00308     }
00309 
00315     public function getSimilarRecommListIds()
00316     {
00317         if ($this->_aSimilarRecommListIds === null) {
00318             $this->_aSimilarRecommListIds = false;
00319 
00320             $aList = $this->getArticleList();
00321             if ($aList && $aList->count() > 0) {
00322                 $this->_aSimilarRecommListIds = $aList->arrayKeys();
00323             }
00324         }
00325 
00326         return $this->_aSimilarRecommListIds;
00327     }
00328 
00334     public function getSearchParamForHtml()
00335     {
00336         if ($this->_sSearchParamForHtml === null) {
00337             $this->_sSearchParamForHtml = false;
00338             if ($this->_isSearchClass()) {
00339                 $this->_sSearchParamForHtml = $this->getConfig()->getRequestParameter('searchparam');
00340             }
00341         }
00342 
00343         return $this->_sSearchParamForHtml;
00344     }
00345 
00351     public function getSearchParam()
00352     {
00353         if ($this->_sSearchParam === null) {
00354             $this->_sSearchParam = false;
00355             if ($this->_isSearchClass()) {
00356                 $this->_sSearchParam = rawurlencode($this->getConfig()->getRequestParameter('searchparam', true));
00357             }
00358         }
00359 
00360         return $this->_sSearchParam;
00361     }
00362 
00368     public function getSearchCatId()
00369     {
00370         if ($this->_sSearchCatId === null) {
00371             $this->_sSearchCatId = false;
00372             if ($this->_isSearchClass()) {
00373                 $this->_sSearchCatId = rawurldecode($this->getConfig()->getRequestParameter('searchcnid'));
00374             }
00375         }
00376 
00377         return $this->_sSearchCatId;
00378     }
00379 
00385     public function getSearchVendor()
00386     {
00387         if ($this->_sSearchVendor === null) {
00388             $this->_sSearchVendor = false;
00389             if ($this->_isSearchClass()) {
00390                 // searching in vendor #671
00391                 $this->_sSearchVendor = rawurldecode($this->getConfig()->getRequestParameter('searchvendor'));
00392             }
00393         }
00394 
00395         return $this->_sSearchVendor;
00396     }
00397 
00403     public function getSearchManufacturer()
00404     {
00405         if ($this->_sSearchManufacturer === null) {
00406             $this->_sSearchManufacturer = false;
00407             if ($this->_isSearchClass()) {
00408                 // searching in Manufacturer #671
00409                 $sManufacturerParameter = $this->getConfig()->getRequestParameter('searchmanufacturer');
00410                 $this->_sSearchManufacturer = rawurldecode($sManufacturerParameter);
00411             }
00412         }
00413 
00414         return $this->_sSearchManufacturer;
00415     }
00416 
00422     public function getPageNavigation()
00423     {
00424         if ($this->_oPageNavigation === null) {
00425             $this->_oPageNavigation = false;
00426             $this->_oPageNavigation = $this->generatePageNavigation();
00427         }
00428 
00429         return $this->_oPageNavigation;
00430     }
00431 
00432 
00438     public function getActiveCategory()
00439     {
00440         return $this->getActSearch();
00441     }
00442 
00448     public function getBreadCrumb()
00449     {
00450         $aPaths = array();
00451         $aPath = array();
00452 
00453         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00454         $aPath['title'] = oxRegistry::getLang()->translateString('SEARCH', $iBaseLanguage, false);
00455         $aPath['link'] = $this->getLink();
00456         $aPaths[] = $aPath;
00457 
00458         return $aPaths;
00459     }
00460 
00466     public function canSelectDisplayType()
00467     {
00468         return $this->getConfig()->getConfigParam('blShowListDisplayType');
00469     }
00470 
00476     protected function _canRedirect()
00477     {
00478         return false;
00479     }
00480 
00486     public function getArticleCount()
00487     {
00488         return $this->_iAllArtCnt;
00489     }
00490 
00496     public function getTitle()
00497     {
00498         $sTitle = '';
00499         $sTitle .= $this->getArticleCount();
00500         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00501         $sTitle .= ' ' . oxRegistry::getLang()->translateString('HITS_FOR', $iBaseLanguage, false);
00502         $sTitle .= ' "' . $this->getSearchParamForHtml() . '"';
00503 
00504         return $sTitle;
00505     }
00506 }