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 
00108     public function init()
00109     {
00110         parent::init();
00111 
00112         $myConfig = $this->getConfig();
00113 
00114         // #1184M - specialchar search
00115         $sSearchParamForQuery = oxConfig::getParameter( 'searchparam', true );
00116 
00117         // searching in category ?
00118         $sInitialSearchCat = $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00119 
00120         // searching in vendor #671
00121         $sInitialSearchVendor = $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00122 
00123         // searching in Manufacturer #671
00124         $sInitialSearchManufacturer = $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00125 
00126         $this->_blEmptySearch = false;
00127         if ( !$sSearchParamForQuery && !$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer ) {
00128             //no search string
00129             $this->_aArticleList = null;
00130             $this->_blEmptySearch = true;
00131             return false;
00132         }
00133 
00134         // config allows to search in vendors ?
00135         if ( !$myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00136             $sInitialSearchVendor = null;
00137         }
00138 
00139         // config allows to search in Manufacturers ?
00140         if ( !$myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00141             $sInitialSearchManufacturer = null;
00142         }
00143 
00144         // searching ..
00145         $oSearchHandler = oxNew( 'oxsearch' );
00146         $oSearchList = $oSearchHandler->getSearchArticles( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer, $this->getSortingSql( 'oxsearch' ) );
00147 
00148         // list of found articles
00149         $this->_aArticleList = $oSearchList;
00150         $this->_iAllArtCnt    = 0;
00151 
00152         // skip count calculation if no articles in list found
00153         if ( $oSearchList->count() ) {
00154             $this->_iAllArtCnt = $oSearchHandler->getSearchArticleCount( $sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer );
00155         }
00156 
00157         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00158         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00159         $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00160     }
00161 
00168     public function render()
00169     {
00170         parent::render();
00171 
00172         $myConfig = $this->getConfig();
00173         if ( $myConfig->getConfigParam( 'bl_rssSearch' ) ) {
00174             $oRss = oxNew('oxrssfeed');
00175             $sSearch = oxConfig::getParameter( 'searchparam', true );
00176             $sCnid = oxConfig::getParameter( 'searchcnid', true );
00177             $sVendor = oxConfig::getParameter( 'searchvendor', true );
00178             $sManufacturer = oxConfig::getParameter( 'searchmanufacturer', true );
00179             $this->addRssFeed($oRss->getSearchArticlesTitle($sSearch, $sCnid, $sVendor, $sManufacturer), $oRss->getSearchArticlesUrl($sSearch, $sCnid, $sVendor, $sManufacturer), 'searchArticles');
00180         }
00181 
00182         // processing list articles
00183         $this->_processListArticles();
00184 
00185         return $this->_sThisTemplate;
00186     }
00187 
00194     protected function _processListArticles()
00195     {
00196         $sAddDynParams = $this->getAddUrlParams();
00197         if ( $sAddDynParams && ( $aArtList = $this->getArticleList() ) ) {
00198             $blSeo = oxUtils::getInstance()->seoIsActive();
00199             foreach ( $aArtList as $oArticle ) {
00200                 // appending std and dynamic urls
00201                 if ( !$blSeo ) {
00202                     // only if seo is off..
00203                     $oArticle->appendStdLink( $sAddDynParams );
00204                 }
00205                 $oArticle->appendLink( $sAddDynParams );
00206             }
00207         }
00208     }
00209 
00215     public function getAddUrlParams()
00216     {
00217         $sAddParams  = parent::getAddUrlParams();
00218         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00219 
00220         if ( $sParam = oxConfig::getParameter( 'searchparam', true ) ) {
00221             $sAddParams .= "&amp;searchparam=".rawurlencode($sParam);
00222         }
00223 
00224         if ( $sParam = oxConfig::getParameter( 'searchcnid' ) ) {
00225             $sAddParams .= "&amp;searchcnid=$sParam";
00226         }
00227 
00228         if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchvendor' ) ) ) {
00229             $sAddParams .= "&amp;searchvendor=$sParam";
00230         }
00231 
00232         if ( $sParam = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
00233             $sAddParams .= "&amp;searchmanufacturer=$sParam";
00234         }
00235         return $sAddParams;
00236     }
00237 
00247     public function setItemSorting( $sCnid, $sSortBy, $sSortOrder  = null )
00248     {
00249         parent::setItemSorting( "oxsearch", $sSortBy, $sSortOrder );
00250     }
00251 
00259     public function getSorting( $sCnid )
00260     {
00261         return parent::getSorting( "oxsearch" );
00262     }
00263 
00269     protected function _isSearchClass()
00270     {
00271         if ( $this->_blSearchClass === null ) {
00272             $this->_blSearchClass = false;
00273             if ( strtolower(oxConfig::getParameter( 'cl' )) == 'search' ) {
00274                 $this->_blSearchClass = true;
00275             }
00276         }
00277         return $this->_blSearchClass;
00278     }
00284     public function isEmptySearch()
00285     {
00286         return $this->_blEmptySearch;
00287     }
00288 
00294     public function getArticleList()
00295     {
00296         return $this->_aArticleList;
00297     }
00298 
00304     public function getSimilarRecommLists()
00305     {
00306         if (!$this->getViewConfig()->getShowListmania()) {
00307             return false;
00308         }
00309 
00310         if ( $this->_oRecommList === null ) {
00311             $this->_oRecommList = false;
00312             $aList = $this->getArticleList();
00313             if ( $aList && $aList->count() > 0 ) {
00314                 // loading recommlists
00315                 $oRecommList = oxNew('oxrecommlist');
00316                 $this->_oRecommList  = $oRecommList->getRecommListsByIds( $aList->arrayKeys());
00317             }
00318         }
00319         return $this->_oRecommList;
00320     }
00321 
00327     public function getSearchParamForHtml()
00328     {
00329         if ( $this->_sSearchParamForHtml === null ) {
00330             $this->_sSearchParamForHtml = false;
00331             if ( $this->_isSearchClass() ) {
00332                 $this->_sSearchParamForHtml = oxConfig::getParameter( 'searchparam' );
00333             }
00334         }
00335         return $this->_sSearchParamForHtml;
00336     }
00337 
00343     public function getSearchParam()
00344     {
00345         if ( $this->_sSearchParam === null ) {
00346             $this->_sSearchParam = false;
00347             if ( $this->_isSearchClass() ) {
00348                 $this->_sSearchParam = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00349             }
00350         }
00351         return $this->_sSearchParam;
00352     }
00353 
00359     public function getSearchCatId()
00360     {
00361         if ( $this->_sSearchCatId === null ) {
00362             $this->_sSearchCatId = false;
00363             if ( $this->_isSearchClass() ) {
00364                 $this->_sSearchCatId = rawurldecode( oxConfig::getParameter( 'searchcnid' ) );
00365             }
00366         }
00367         return $this->_sSearchCatId;
00368     }
00369 
00375     public function getSearchVendor()
00376     {
00377         if ( $this->_sSearchVendor === null ) {
00378             $this->_sSearchVendor = false;
00379             if ( $this->_isSearchClass() ) {
00380                 // searching in vendor #671
00381                 $this->_sSearchVendor = rawurldecode( oxConfig::getParameter( 'searchvendor' ) );
00382             }
00383         }
00384         return $this->_sSearchVendor;
00385     }
00386 
00392     public function getSearchManufacturer()
00393     {
00394         if ( $this->_sSearchManufacturer === null ) {
00395             $this->_sSearchManufacturer = false;
00396             if ( $this->_isSearchClass() ) {
00397                 // searching in Manufacturer #671
00398                 $this->_sSearchManufacturer = rawurldecode( oxConfig::getParameter( 'searchmanufacturer' ) );
00399             }
00400         }
00401         return $this->_sSearchManufacturer;
00402     }
00403 
00409     public function getPageNavigation()
00410     {
00411         if ( $this->_oPageNavigation === null ) {
00412             $this->_oPageNavigation = false;
00413             $this->_oPageNavigation = $this->generatePageNavigation();
00414         }
00415         return $this->_oPageNavigation;
00416     }
00417 
00418 
00424     public function getActiveCategory()
00425     {
00426         return $this->getActSearch();
00427     }
00428 
00434     public function getBreadCrumb()
00435     {
00436         $aPaths = array();
00437         $aPath = array();
00438 
00439         $aPath['title'] = oxLang::getInstance()->translateString( 'SEARCH_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
00440         $aPath['link']  = $this->getLink();
00441         $aPaths[] = $aPath;
00442 
00443         return $aPaths;
00444     }
00445 
00451     public function canSelectDisplayType()
00452     {
00453         return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00454     }
00455 
00461     protected function _canRedirect()
00462     {
00463         return false;
00464     }
00465 
00466 }