alist.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class aList extends oxUBase
00010 {
00015     protected $_iAllArtCnt = 0;
00016 
00021     protected $_iCntPages = 0;
00022 
00027     protected $_sThisTemplate = 'page/list/list.tpl';
00028 
00033     protected $_sThisMoreTemplate = 'page/list/morecategories.tpl';
00034 
00039     protected $_sCatPathString = null;
00040 
00045     protected $_blShowSorting = true;
00046 
00051     protected $_aAttributes = null;
00052 
00057     protected $_aCatArtList = null;
00058 
00063     protected $_blHasVisibleSubCats = null;
00064 
00069     protected $_aSubCatList = null;
00070 
00075     protected $_oPageNavigation = null;
00076 
00081     protected $_blIsCat = null;
00082 
00087     protected $_oRecommList = null;
00088 
00093     protected $_sCatTitle = null;
00094 
00099     protected $_blTop5Action = true;
00104     protected $_blShowTagCloud = true;
00105 
00110     protected $_blBargainAction = false;
00111 
00118     public function getViewId()
00119     {
00120         if ( !isset( $this->_sViewId ) ) {
00121             $sCatId   = oxConfig::getParameter( 'cnid' );
00122             $iActPage = $this->getActPage();
00123             $iArtPerPage = oxSession::getVar( '_artperpage' );
00124             $sListDisplayType = oxSession::getVar( 'ldtype' );
00125             $sParentViewId = parent::getViewId();
00126 
00127             // shorten it
00128                 $this->_sViewId = md5( $sParentViewId.'|'.$sCatId.'|'.$iActPage.'|'.$iArtPerPage.'|'.$sListDisplayType );
00129 
00130         }
00131 
00132         return $this->_sViewId;
00133     }
00134 
00147     public function render()
00148     {
00149         $myConfig = $this->getConfig();
00150 
00151         $oCategory  = null;
00152         $blContinue = true;
00153         $this->_blIsCat = false;
00154 
00155         // A. checking for fake "more" category
00156         if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00157             // overriding some standard value and parameters
00158             $this->_sThisTemplate = $this->_sThisMoreTemplate;
00159             $oCategory = oxNew( 'oxcategory' );
00160             $oCategory->oxcategories__oxactive = new oxField( 1, oxField::T_RAW );
00161             $this->setActCategory( $oCategory );
00162 
00163             $this->_blShowTagCloud = true;
00164 
00165         } elseif ( ( $oCategory = $this->getActCategory() ) ) {
00166             $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
00167             $this->_blIsCat = true;
00168             $this->_blBargainAction = true;
00169         }
00170 
00171 
00172         // category is inactive ?
00173         if ( !$blContinue || !$oCategory ) {
00174             oxUtils::getInstance()->redirect( $myConfig->getShopURL().'index.php' );
00175         }
00176 
00177         $oCat = $this->getActCategory();
00178         if ($oCat && $myConfig->getConfigParam( 'bl_rssCategories' )) {
00179             $oRss = oxNew('oxrssfeed');
00180             $this->addRssFeed($oRss->getCategoryArticlesTitle($oCat), $oRss->getCategoryArticlesUrl($oCat), 'activeCategory');
00181         }
00182 
00183         //checking if actual pages count does not exceed real articles page count
00184         $this->getArticleList();
00185 
00186         if ( $this->getPageCount() < $this->getActPage() ) {
00187             error_404_handler();
00188         }
00189 
00190         parent::render();
00191 
00192         // processing list articles
00193         $this->_processListArticles();
00194 
00195         return $this->getTemplateName();
00196     }
00197 
00204     protected function _processListArticles()
00205     {
00206         if ( $aArtList = $this->getArticleList() ) {
00207             $iLinkType = $this->_getProductLinkType();
00208             $sAddDynParams = $this->getAddUrlParams();
00209             $sAddSeoParams = $this->getAddSeoUrlParams();
00210 
00211             foreach ( $aArtList as $oArticle ) {
00212                 $oArticle->setLinkType( $iLinkType );
00213 
00214                 // appending dynamic urls
00215                 if ( $sAddDynParams ) {
00216                     $oArticle->appendStdLink( $sAddDynParams );
00217                 }
00218 
00219                 // appending seo urls
00220                 if ( $sAddSeoParams ) {
00221                     $oArticle->appendLink( $sAddSeoParams );
00222                 }
00223             }
00224         }
00225     }
00226 
00227 
00233     public function getAddUrlParams()
00234     {
00235         $sParams = parent::getAddUrlParams();
00236         if ( !oxUtils::getInstance()->seoIsActive() ) {
00237             $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
00238             if ( $iPgNr > 0 ) {
00239                 $sParams .= ($sParams?'&amp;':'') . "pgNr={$iPgNr}";
00240             }
00241         }
00242 
00243         return $sParams;
00244     }
00245 
00251     public function getAddSeoUrlParams()
00252     {
00253     }
00254 
00262     protected function _getProductLinkType()
00263     {
00264         $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00265         if ( ( $oCat = $this->getActCategory() ) && $oCat->isPriceCategory() ) {
00266             $iCatType =  OXARTICLE_LINKTYPE_PRICECATEGORY;
00267         }
00268         return $iCatType;
00269     }
00270 
00279     public function executefilter()
00280     {
00281         $iLang = oxLang::getInstance()->getBaseLanguage();
00282         // store this into session
00283         $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00284         $sActCat = oxConfig::getParameter( 'cnid' );
00285 
00286         if ( !empty( $aFilter ) ) {
00287             $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00288             //fix for #2904 - if language will be changed attributes of this category will be deleted from session
00289             //and new filters for active language set.
00290             $aSessionFilter[$sActCat] = null;
00291             $aSessionFilter[$sActCat][$iLang] = $aFilter;
00292             oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00293         }
00294     }
00295 
00303     protected function _loadArticles( $oCategory )
00304     {
00305         $myConfig = $this->getConfig();
00306 
00307         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00308         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00309 
00310         // load only articles which we show on screen
00311         $oArtList = oxNew( 'oxarticlelist' );
00312         $oArtList->setSqlLimit( $iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles );
00313         $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00314 
00315         if ( $oCategory->isPriceCategory() ) {
00316             $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00317             $dPriceTo   = $oCategory->oxcategories__oxpriceto->value;
00318 
00319             $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00320         } else {
00321             $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00322 
00323             $sActCat = oxConfig::getParameter( 'cnid' );
00324             $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00325         }
00326 
00327         $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00328 
00329         return $oArtList;
00330     }
00331 
00337     public function getActPage()
00338     {
00339         return $this->_getRequestPageNr();
00340     }
00341 
00350     protected function _getRequestPageNr()
00351     {
00352         return parent::getActPage();
00353     }
00354 
00360     protected function _getSeoObjectId()
00361     {
00362         if ( ( $oCategory = $this->getActCategory() ) ) {
00363             return $oCategory->getId();
00364         }
00365     }
00366 
00372     protected function _getCatPathString()
00373     {
00374         if ( $this->_sCatPathString === null ) {
00375 
00376             // marking as allready set
00377             $this->_sCatPathString = false;
00378 
00379             //fetching category path
00380             if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00381 
00382                 $oStr = getStr();
00383                 $this->_sCatPathString = '';
00384                 foreach ( $aPath as $oCat ) {
00385                     if ( $this->_sCatPathString ) {
00386                         $this->_sCatPathString .= ', ';
00387                     }
00388                     $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00389                 }
00390             }
00391         }
00392         return $this->_sCatPathString;
00393     }
00394 
00404     protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00405     {
00406         // using language constant ..
00407         $sDescription = oxLang::getInstance()->translateString( 'ALIST_META_DESCRIPTION_PREFIX' );
00408 
00409         // appending parent title
00410         if ( $oCategory = $this->getActCategory() ) {
00411             if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00412                 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00413             }
00414 
00415             // adding cateogry title
00416             $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00417         }
00418 
00419         // and final component ..
00420         if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00421             $sDescription .= " {$sSuffix}";
00422         }
00423 
00424         // making safe for output
00425         $sDescription = getStr()->cleanStr($sDescription);
00426         return trim( strip_tags( getStr()->html_entity_decode( $sDescription ) ) );
00427     }
00428 
00434     public function getMetaDescription()
00435     {
00436         $sMeta = parent::getMetaDescription();
00437 
00438         if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00439             if ( $sMeta ) {
00440                 $sMeta .= ", ";
00441             }
00442             $sMeta .= $sTitlePageSuffix;
00443         }
00444 
00445         return $sMeta;
00446     }
00447 
00460     protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00461     {
00462         //formatting description tag
00463         $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->getLongDesc() ):'';
00464         $aArticleList = $this->getArticleList();
00465         if ( !$sAddText && count($aArticleList)) {
00466             foreach ( $aArticleList as $oArticle ) {
00467                 if ( $sAddText ) {
00468                     $sAddText .= ', ';
00469                 }
00470                 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00471             }
00472         }
00473 
00474         if ( !$sMeta ) {
00475             $sMeta = trim( $this->_getCatPathString() );
00476         }
00477 
00478         if ( $sMeta ) {
00479             $sMeta = "{$sMeta} - {$sAddText}";
00480         } else {
00481             $sMeta = $sAddText;
00482         }
00483 
00484         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00485     }
00486 
00495     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00496     {
00497         $sKeywords = '';
00498         if ( ( $oCategory = $this->getActCategory() ) ) {
00499             $aKeywords = array();
00500 
00501             if ( $oCatTree = $this->getCategoryTree() ) {
00502                 foreach ( $oCatTree->getPath() as $oCat ) {
00503                     $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00504                 }
00505             }
00506 
00507             if ( count( $aKeywords ) > 0 ) {
00508                 $sKeywords = implode( ", ", $aKeywords );
00509             }
00510 
00511             $aSubCats  = $oCategory->getSubCats();
00512             if ( is_array( $aSubCats ) ) {
00513                 foreach ( $aSubCats as $oSubCat ) {
00514                     $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00515                 }
00516             }
00517         }
00518 
00519         $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00520 
00521         return trim( $sKeywords );
00522     }
00523 
00532     protected function _collectMetaKeyword( $sKeywords )
00533     {
00534         $iMaxTextLength = 60;
00535         $sText = '';
00536 
00537         if ( count( $aArticleList = $this->getArticleList() ) ) {
00538             $oStr = getStr();
00539             foreach ( $aArticleList as $oProduct ) {
00540                 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00541 
00542                 //removing dots from string (they are not cleaned up during general string cleanup)
00543                 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00544 
00545                 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00546                     $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00547                     $sDesc    = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00548                 }
00549                 if ( $sText ) {
00550                     $sText .= ', ';
00551                 }
00552                 $sText .= $sDesc;
00553             }
00554         }
00555 
00556         if ( !$sKeywords ) {
00557             $sKeywords = $this->_getCatPathString();
00558         }
00559 
00560         if ( $sKeywords ) {
00561             $sText = "{$sKeywords}, {$sText}";
00562         }
00563 
00564         return parent::_prepareMetaKeyword( $sText );
00565     }
00566 
00574     public function getTemplateName()
00575     {
00576         // assign template name
00577         if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00578             $this->_sThisTemplate = $sTplName;
00579         } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00580             $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00581         }
00582 
00583         return $this->_sThisTemplate;
00584     }
00585 
00595     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00596     {
00597         if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00598             if ( $iPage ) {
00599                 // only if page number > 0
00600                 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00601             }
00602         } else {
00603             $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00604         }
00605         return $sUrl;
00606     }
00607 
00613     protected function _isActCategory()
00614     {
00615         return $this->_blIsCat;
00616     }
00617 
00623     public function generatePageNavigationUrl( )
00624     {
00625         if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00626             return $oCategory->getLink();
00627         }
00628         return parent::generatePageNavigationUrl( );
00629     }
00630 
00638     public function getSorting( $sCnid )
00639     {
00640         // category has own sorting
00641         $aSorting = parent::getSorting( $sCnid );
00642         $oActCat = $this->getActCategory();
00643         if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00644             $sSortBy  = $oActCat->oxcategories__oxdefsort->value;
00645             $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : null;
00646 
00647             $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00648             $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00649         }
00650         return $aSorting;
00651     }
00652 
00658     public function getTitleSuffix()
00659     {
00660         if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00661             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00662         }
00663     }
00664 
00670     public function getTitlePageSuffix()
00671     {
00672         if ( ( $iPage = $this->getActPage() ) ) {
00673             return oxLang::getInstance()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00674         }
00675     }
00676 
00685     protected function _getSubject( $iLang )
00686     {
00687         return $this->getActCategory();
00688     }
00689 
00696     public function getAttributes()
00697     {
00698         $this->_aAttributes = false;
00699         if ( ( $oCategory = $this->getActCategory() ) ) {
00700             $aAttributes = $oCategory->getAttributes();
00701             if ( count( $aAttributes ) ) {
00702                 $this->_aAttributes = $aAttributes;
00703             }
00704         }
00705 
00706         return $this->_aAttributes;
00707     }
00708 
00714     public function getArticleList()
00715     {
00716         if ( $this->_aArticleList === null ) {
00717             if ( /*$this->_isActCategory() &&*/ ( $oCategory = $this->getActCategory() ) ) {
00718                 $aArticleList = $this->_loadArticles( $oCategory );
00719                 if ( count( $aArticleList ) ) {
00720                     $this->_aArticleList = $aArticleList;
00721                 }
00722             }
00723         }
00724 
00725         return $this->_aArticleList;
00726     }
00727 
00733     public function getSimilarRecommLists()
00734     {
00735         if (!$this->getViewConfig()->getShowListmania()) {
00736             return false;
00737         }
00738 
00739         if ( $this->_oRecommList === null ) {
00740             $this->_oRecommList = false;
00741             if ( $aCatArtList = $this->getArticleList() ) {
00742                 $oRecommList = oxNew('oxrecommlist');
00743                 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00744             }
00745         }
00746         return $this->_oRecommList;
00747     }
00748 
00754     public function getCatTreePath()
00755     {
00756         if ( $this->_sCatTreePath === null ) {
00757              $this->_sCatTreePath = false;
00758             // category path
00759             if ( $oCatTree = $this->getCategoryTree() ) {
00760                 $this->_sCatTreePath = $oCatTree->getPath();
00761             }
00762         }
00763         return $this->_sCatTreePath;
00764     }
00765 
00771     public function getTreePath()
00772     {
00773         if ( $oCatTree = $this->getCategoryTree() ) {
00774             return $oCatTree->getPath();
00775         }
00776     }
00777 
00783     public function getBreadCrumb()
00784     {
00785         $aPaths = array();
00786 
00787         if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00788             $aPath = array();
00789             $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxLang::getInstance()->getBaseLanguage(), false );
00790             $aPath['link']  = $this->getLink();
00791 
00792             $aPaths[] = $aPath;
00793 
00794             return $aPaths;
00795         }
00796 
00797         if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00798             foreach ( $oCatPath as $oCat ) {
00799                 $aCatPath = array();
00800 
00801                 $aCatPath['link'] = $oCat->getLink();
00802                 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00803 
00804                 $aPaths[] = $aCatPath;
00805             }
00806         }
00807 
00808         return $aPaths;
00809     }
00810 
00817     public function hasVisibleSubCats()
00818     {
00819         if ( $this->_blHasVisibleSubCats === null ) {
00820             $this->_blHasVisibleSubCats = false;
00821             if ( $oClickCat = $this->getActCategory() ) {
00822                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00823             }
00824         }
00825         return $this->_blHasVisibleSubCats;
00826     }
00827 
00833     public function getSubCatList()
00834     {
00835         if ( $this->_aSubCatList === null ) {
00836             $this->_aSubCatList = array();
00837             if ( $oClickCat = $this->getActCategory() ) {
00838                 $this->_aSubCatList = $oClickCat->getSubCats();
00839             }
00840         }
00841 
00842         return $this->_aSubCatList;
00843     }
00844 
00850     public function getPageNavigation()
00851     {
00852         if ( $this->_oPageNavigation === null ) {
00853             $this->_oPageNavigation = $this->generatePageNavigation();
00854         }
00855         return $this->_oPageNavigation;
00856     }
00857 
00863     public function getTitle()
00864     {
00865         if ( $this->_sCatTitle === null ) {
00866             $this->_sCatTitle = false;
00867             if ( ( $oCategory = $this->getActCategory() ) ) {
00868                 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00869             }
00870         }
00871         return $this->_sCatTitle;
00872     }
00873 
00879     public function getTop5ArticleList()
00880     {
00881         if ( $this->_aTop5ArticleList === null ) {
00882             $this->_aTop5ArticleList = false;
00883             $myConfig = $this->getConfig();
00884             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00885                 // top 5 articles
00886                 $oArtList = oxNew( 'oxarticlelist' );
00887                 $oArtList->loadTop5Articles();
00888                 if ( $oArtList->count() ) {
00889                     $this->_aTop5ArticleList = $oArtList;
00890                 }
00891             }
00892         }
00893         return $this->_aTop5ArticleList;
00894     }
00895 
00901     public function getBargainArticleList()
00902     {
00903         if ( $this->_aBargainArticleList === null ) {
00904             $this->_aBargainArticleList = array();
00905             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00906                 $oArtList = oxNew( 'oxarticlelist' );
00907                 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00908                 if ( $oArtList->count() ) {
00909                     $this->_aBargainArticleList = $oArtList;
00910                 }
00911             }
00912         }
00913         return $this->_aBargainArticleList;
00914     }
00915 
00921     public function getActiveCategory()
00922     {
00923         return $this->getActCategory();
00924     }
00925 
00931     public function getCanonicalUrl()
00932     {
00933         if ( ( $oCategory = $this->getActiveCategory() ) ) {
00934             $oUtils = oxUtilsUrl::getInstance();
00935             if ( oxUtils::getInstance()->seoIsActive() ) {
00936                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00937             } else {
00938                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00939             }
00940             return $sUrl;
00941         }
00942     }
00943 
00949     public function canSelectDisplayType()
00950     {
00951         return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00952     }
00953 
00959     public function getPageCount()
00960     {
00961         return $this->_iCntPages;
00962     }
00963 
00969     public function isMoreTagsVisible()
00970     {
00971         return true;
00972     }
00973 }