search.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Search extends oxUBase
00008 {
00013     protected $_iAllArtCnt     = 0;
00014 
00019     protected $_iCntPages = null;
00020 
00025     protected $_sThisTemplate = 'page/search/search.tpl';
00026 
00031     protected $_sListType = 'search';
00032 
00037     protected $_blShowSorting = true;
00038 
00043     protected $_blEmptySearch = null;
00044 
00049     protected $_oRecommList = null;
00050 
00055     protected $_sSearchParamForHtml = null;
00056 
00061     protected $_sSearchParam = null;
00062 
00067     protected $_sSearchCatId = null;
00068 
00073     protected $_sSearchVendor = null;
00074 
00079     protected $_sSearchManufacturer = null;
00080 
00085     protected $_blSearchClass = null;
00086 
00091     protected $_oPageNavigation = null;
00092 
00098     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00099 
00105     protected $_aSimilarRecommListIds = null;
00106 
00107 
00116     public function init()
00117     {
00118         parent::init();
00119 
00120         $myConfig = $this->getConfig();
00121 
00122         // #1184M - specialchar search
00123         $sSearchParamForQuery = oxConfig::getParameter( 'searchparam', true );
00124 
00125         // searching in category ?
00126         $sInitialSearchCat = $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00127 
00128         // searching in vendor #671
00129         $sInitialSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00130 
00131         // searching in Manufacturer #671
00132         $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00133 
00134         $this->_blEmptySearch = false;
00135         if ( !$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer ) {
00136             //no search string
00137             $this->_aArticleList = null;
00138             $this->_blEmptySearch = true;
00139             return false;
00140         }
00141 
00142         // config allows to search in Manufacturers ?
00143         if ( !$myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00144             $sInitialSearchManufacturer = null;
00145         }
00146 
00147         // searching ..
00148         $oSearchHandler = oxNew( 'oxsearch' );
00149         $oSearchList = $oSearchHandler->getSearchArticles( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer, $this->getSortingSql( $this->getSortIdent() ) );
00150 
00151         // list of found articles
00152         $this->_aArticleList = $oSearchList;
00153         $this->_iAllArtCnt    = 0;
00154 
00155         // skip count calculation if no articles in list found
00156         if ( $oSearchList->count() ) {
00157             $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer );
00158         }
00159 
00160         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00161         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00162         $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00163     }
00164 
00171     public function render()
00172     {
00173         parent::render();
00174 
00175         $myConfig = $this->getConfig();
00176         if ( $myConfig->getConfigParam( 'bl_rssSearch' ) ) {
00177             $oRss = oxNew('oxrssfeed');
00178             $sSearch = oxConfig::getParameter( 'searchparam', true );
00179             $sCnid = oxConfig::getParameter( 'searchcnid', true );
00180             $sVendor = oxConfig::getParameter( 'searchvendor', true );
00181             $sManufacturer = oxConfig::getParameter( 'searchmanufacturer', true );
00182             $this->addRssFeed($oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor, $sManufacturer), $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor, $sManufacturer), 'searchArticles');
00183         }
00184 
00185         // processing list articles
00186         $this->_processListArticles();
00187 
00188         return $this->_sThisTemplate;
00189     }
00190 
00197     protected function _processListArticles()
00198     {
00199         $sAddDynParams = $this->getAddUrlParams();
00200         if ( $sAddDynParams && ( $aArtList = $this->getArticleList() ) ) {
00201             $blSeo = oxRegistry::getUtils()->seoIsActive();
00202             foreach ( $aArtList as $oArticle ) {
00203                 // appending std and dynamic urls
00204                 if ( !$blSeo ) {
00205                     // only if seo is off..
00206                     $oArticle->appendStdLink( $sAddDynParams );
00207                 }
00208                 $oArticle->appendLink( $sAddDynParams );
00209             }
00210         }
00211     }
00212 
00218     public function getAddUrlParams()
00219     {
00220         $sAddParams  = parent::getAddUrlParams();
00221         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00222 
00223         if ( $sParam = oxConfig::getParameter( 'searchparam', true ) ) {
00224             $sAddParams .= "&amp;searchparam=".rawurlencode($sParam);
00225         }
00226 
00227         if ( $sParam = oxConfig::getParameter( 'searchcnid' ) ) {
00228             $sAddParams .= "&amp;searchcnid=$sParam";
00229         }
00230 
00231         if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchvendor' ) ) ) {
00232             $sAddParams .= "&amp;searchvendor=$sParam";
00233         }
00234 
00235         if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
00236             $sAddParams .= "&amp;searchmanufacturer=$sParam";
00237         }
00238         return $sAddParams;
00239     }
00240 
00252     public function setItemSorting( $sCnid, $sSortBy, $sSortOrder  = null )
00253     {
00254         parent::setItemSorting( $sCnid, $sSortBy, $sSortOrder );
00255     }
00256 
00266     public function getSorting( $sCnid )
00267     {
00268         return parent::getSorting( $sCnid );
00269     }
00270 
00276     protected function _isSearchClass()
00277     {
00278         if ( $this->_blSearchClass === null ) {
00279             $this->_blSearchClass = false;
00280             if ( strtolower(oxConfig::getParameter( 'cl' )) == 'search' ) {
00281                 $this->_blSearchClass = true;
00282             }
00283         }
00284         return $this->_blSearchClass;
00285     }
00291     public function isEmptySearch()
00292     {
00293         return $this->_blEmptySearch;
00294     }
00295 
00301     public function getArticleList()
00302     {
00303         return $this->_aArticleList;
00304     }
00305 
00311     public function getSimilarRecommListIds()
00312     {
00313         if ( $this->_aSimilarRecommListIds === null ) {
00314             $this->_aSimilarRecommListIds = false;
00315 
00316             $aList = $this->getArticleList();
00317             if ( $aList && $aList->count() > 0 ) {
00318                 $this->_aSimilarRecommListIds = $aList->arrayKeys();
00319             }
00320         }
00321 
00322         return $this->_aSimilarRecommListIds;
00323     }
00324 
00330     public function getSearchParamForHtml()
00331     {
00332         if ( $this->_sSearchParamForHtml === null ) {
00333             $this->_sSearchParamForHtml = false;
00334             if ( $this->_isSearchClass() ) {
00335                 $this->_sSearchParamForHtml = oxConfig::getParameter( 'searchparam' );
00336             }
00337         }
00338         return $this->_sSearchParamForHtml;
00339     }
00340 
00346     public function getSearchParam()
00347     {
00348         if ( $this->_sSearchParam === null ) {
00349             $this->_sSearchParam = false;
00350             if ( $this->_isSearchClass() ) {
00351                 $this->_sSearchParam = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00352             }
00353         }
00354         return $this->_sSearchParam;
00355     }
00356 
00362     public function getSearchCatId()
00363     {
00364         if ( $this->_sSearchCatId === null ) {
00365             $this->_sSearchCatId = false;
00366             if ( $this->_isSearchClass() ) {
00367                 $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00368             }
00369         }
00370         return $this->_sSearchCatId;
00371     }
00372 
00378     public function getSearchVendor()
00379     {
00380         if ( $this->_sSearchVendor === null ) {
00381             $this->_sSearchVendor = false;
00382             if ( $this->_isSearchClass() ) {
00383                 // searching in vendor #671
00384                 $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00385             }
00386         }
00387         return $this->_sSearchVendor;
00388     }
00389 
00395     public function getSearchManufacturer()
00396     {
00397         if ( $this->_sSearchManufacturer === null ) {
00398             $this->_sSearchManufacturer = false;
00399             if ( $this->_isSearchClass() ) {
00400                 // searching in Manufacturer #671
00401                 $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00402             }
00403         }
00404         return $this->_sSearchManufacturer;
00405     }
00406 
00412     public function getPageNavigation()
00413     {
00414         if ( $this->_oPageNavigation === null ) {
00415             $this->_oPageNavigation = false;
00416             $this->_oPageNavigation = $this->generatePageNavigation();
00417         }
00418         return $this->_oPageNavigation;
00419     }
00420 
00421 
00427     public function getActiveCategory()
00428     {
00429         return $this->getActSearch();
00430     }
00431 
00437     public function getBreadCrumb()
00438     {
00439         $aPaths = array();
00440         $aPath = array();
00441 
00442         $aPath['title'] = oxRegistry::getLang()->translateString( 'SEARCH_TITLE', oxRegistry::getLang()->getBaseLanguage(), false );
00443         $aPath['link']  = $this->getLink();
00444         $aPaths[] = $aPath;
00445 
00446         return $aPaths;
00447     }
00448 
00454     public function canSelectDisplayType()
00455     {
00456         return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00457     }
00458 
00464     protected function _canRedirect()
00465     {
00466         return false;
00467     }
00468 
00474     public function getArticleCount()
00475     {
00476         return $this->_iAllArtCnt;
00477     }
00478 }