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 
00117     protected $_aSimilarRecommListIds = null;
00118 
00119 
00126     public function getViewId()
00127     {
00128         if ( !isset( $this->_sViewId ) ) {
00129             $sCatId   = oxConfig::getParameter( 'cnid' );
00130             $iActPage = $this->getActPage();
00131             $iArtPerPage = oxSession::getVar( '_artperpage' );
00132             $sListDisplayType = oxSession::getVar( 'ldtype' );
00133             $sParentViewId = parent::getViewId();
00134 
00135             // shorten it
00136                 $this->_sViewId = md5( $sParentViewId.'|'.$sCatId.'|'.$iActPage.'|'.$iArtPerPage.'|'.$sListDisplayType );
00137 
00138         }
00139 
00140         return $this->_sViewId;
00141     }
00142 
00155     public function render()
00156     {
00157         $myConfig = $this->getConfig();
00158 
00159         $oCategory  = null;
00160         $blContinue = true;
00161         $this->_blIsCat = false;
00162 
00163         // A. checking for fake "more" category
00164         if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00165             // overriding some standard value and parameters
00166             $this->_sThisTemplate = $this->_sThisMoreTemplate;
00167             $oCategory = oxNew( 'oxcategory' );
00168             $oCategory->oxcategories__oxactive = new oxField( 1, oxField::T_RAW );
00169             $this->setActCategory( $oCategory );
00170 
00171             $this->_blShowTagCloud = true;
00172 
00173         } elseif ( ( $oCategory = $this->getActCategory() ) ) {
00174             $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
00175             $this->_blIsCat = true;
00176             $this->_blBargainAction = true;
00177         }
00178 
00179 
00180         // category is inactive ?
00181         if ( !$blContinue || !$oCategory ) {
00182             oxRegistry::getUtils()->redirect( $myConfig->getShopURL().'index.php', true, 302 );
00183         }
00184 
00185         $oCat = $this->getActCategory();
00186         if ($oCat && $myConfig->getConfigParam( 'bl_rssCategories' )) {
00187             $oRss = oxNew('oxrssfeed');
00188             $this->addRssFeed($oRss->getCategoryArticlesTitle($oCat), $oRss->getCategoryArticlesUrl($oCat), 'activeCategory');
00189         }
00190 
00191         //checking if actual pages count does not exceed real articles page count
00192         $this->getArticleList();
00193 
00194         if ( $this->_blIsCat ) {
00195             $this->_checkRequestedPage();
00196         }
00197 
00198         parent::render();
00199 
00200         // processing list articles
00201         $this->_processListArticles();
00202 
00203         return $this->getTemplateName();
00204     }
00205 
00214     protected function _checkRequestedPage()
00215     {
00216         $iPageCnt = $this->getPageCount();
00217         // redirecting to first page in case requested page does not exist
00218         if ( $iPageCnt && ( ( $iPageCnt - 1 ) < $this->getActPage() ) ) {
00219             oxRegistry::getUtils()->redirect( $this->getActiveCategory()->getLink(), false );
00220         }
00221     }
00222 
00229     protected function _processListArticles()
00230     {
00231         if ( $aArtList = $this->getArticleList() ) {
00232             $iLinkType = $this->_getProductLinkType();
00233             $sAddDynParams = $this->getAddUrlParams();
00234             $sAddSeoParams = $this->getAddSeoUrlParams();
00235 
00236             foreach ( $aArtList as $oArticle ) {
00237                 $oArticle->setLinkType( $iLinkType );
00238 
00239                 // appending dynamic urls
00240                 if ( $sAddDynParams ) {
00241                     $oArticle->appendStdLink( $sAddDynParams );
00242                 }
00243 
00244                 // appending seo urls
00245                 if ( $sAddSeoParams ) {
00246                     $oArticle->appendLink( $sAddSeoParams );
00247                 }
00248             }
00249         }
00250     }
00251 
00252 
00258     public function getAddUrlParams()
00259     {
00260         $sParams = parent::getAddUrlParams();
00261         if ( !oxRegistry::getUtils()->seoIsActive() ) {
00262             $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
00263             if ( $iPgNr > 0 ) {
00264                 $sParams .= ($sParams?'&amp;':'') . "pgNr={$iPgNr}";
00265             }
00266         }
00267 
00268         return $sParams;
00269     }
00270 
00276     public function getAddSeoUrlParams()
00277     {
00278     }
00279 
00287     protected function _getProductLinkType()
00288     {
00289         $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00290         if ( ( $oCat = $this->getActCategory() ) && $oCat->isPriceCategory() ) {
00291             $iCatType =  OXARTICLE_LINKTYPE_PRICECATEGORY;
00292         }
00293         return $iCatType;
00294     }
00295 
00304     public function executefilter()
00305     {
00306         $iLang = oxRegistry::getLang()->getBaseLanguage();
00307         // store this into session
00308         $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00309         $sActCat = oxConfig::getParameter( 'cnid' );
00310 
00311         if ( !empty( $aFilter ) ) {
00312             $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00313             //fix for #2904 - if language will be changed attributes of this category will be deleted from session
00314             //and new filters for active language set.
00315             $aSessionFilter[$sActCat] = null;
00316             $aSessionFilter[$sActCat][$iLang] = $aFilter;
00317             oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00318         }
00319     }
00320 
00328     protected function _loadArticles( $oCategory )
00329     {
00330         $myConfig = $this->getConfig();
00331 
00332         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00333         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00334 
00335         // load only articles which we show on screen
00336         $oArtList = oxNew( 'oxarticlelist' );
00337         $oArtList->setSqlLimit( $iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles );
00338         $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00339 
00340         if ( $oCategory->isPriceCategory() ) {
00341             $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00342             $dPriceTo   = $oCategory->oxcategories__oxpriceto->value;
00343 
00344             $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00345         } else {
00346             $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00347 
00348             $sActCat = oxConfig::getParameter( 'cnid' );
00349             $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00350         }
00351 
00352         $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00353 
00354         return $oArtList;
00355     }
00356 
00362     public function getActPage()
00363     {
00364         return $this->_getRequestPageNr();
00365     }
00366 
00375     protected function _getRequestPageNr()
00376     {
00377         return parent::getActPage();
00378     }
00379 
00385     protected function _getSeoObjectId()
00386     {
00387         if ( ( $oCategory = $this->getActCategory() ) ) {
00388             return $oCategory->getId();
00389         }
00390     }
00391 
00397     protected function _getCatPathString()
00398     {
00399         if ( $this->_sCatPathString === null ) {
00400 
00401             // marking as allready set
00402             $this->_sCatPathString = false;
00403 
00404             //fetching category path
00405             if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00406 
00407                 $oStr = getStr();
00408                 $this->_sCatPathString = '';
00409                 foreach ( $aPath as $oCat ) {
00410                     if ( $this->_sCatPathString ) {
00411                         $this->_sCatPathString .= ', ';
00412                     }
00413                     $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00414                 }
00415             }
00416         }
00417         return $this->_sCatPathString;
00418     }
00419 
00429     protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00430     {
00431         // appending parent title
00432         if ( $oCategory = $this->getActCategory() ) {
00433             if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00434                 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00435             }
00436 
00437             // adding cateogry title
00438             $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00439         }
00440 
00441         // and final component ..
00442         //changed for #2776
00443         if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value ) ) {
00444             $sDescription .= " {$sSuffix}";
00445         }
00446 
00447         // making safe for output
00448         $sDescription = getStr()->cleanStr($sDescription);
00449         $sDescription = strip_tags( getStr()->html_entity_decode( $sDescription ) );
00450         $sDescription = getStr()->htmlspecialchars( $sDescription );
00451         return trim( $sDescription );
00452     }
00453 
00459     public function getMetaDescription()
00460     {
00461         $sMeta = parent::getMetaDescription();
00462 
00463         if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00464             if ( $sMeta ) {
00465                 $sMeta .= ", ";
00466             }
00467             $sMeta .= $sTitlePageSuffix;
00468         }
00469 
00470         return $sMeta;
00471     }
00472 
00485     protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00486     {
00487         //formatting description tag
00488         $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->getLongDesc() ):'';
00489         $aArticleList = $this->getArticleList();
00490         if ( !$sAddText && count($aArticleList)) {
00491             foreach ( $aArticleList as $oArticle ) {
00492                 if ( $sAddText ) {
00493                     $sAddText .= ', ';
00494                 }
00495                 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00496             }
00497         }
00498 
00499         if ( !$sMeta ) {
00500             $sMeta = trim( $this->_getCatPathString() );
00501         }
00502 
00503         if ( $sMeta ) {
00504             $sMeta = "{$sMeta} - {$sAddText}";
00505         } else {
00506             $sMeta = $sAddText;
00507         }
00508 
00509         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00510     }
00511 
00520     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00521     {
00522         $sKeywords = '';
00523         if ( ( $oCategory = $this->getActCategory() ) ) {
00524             $aKeywords = array();
00525 
00526             if ( $oCatTree = $this->getCategoryTree() ) {
00527                 foreach ( $oCatTree->getPath() as $oCat ) {
00528                     $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00529                 }
00530             }
00531 
00532             if ( count( $aKeywords ) > 0 ) {
00533                 $sKeywords = implode( ", ", $aKeywords );
00534             }
00535 
00536             $aSubCats  = $oCategory->getSubCats();
00537             if ( is_array( $aSubCats ) ) {
00538                 foreach ( $aSubCats as $oSubCat ) {
00539                     $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00540                 }
00541             }
00542         }
00543 
00544         $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00545 
00546         return trim( $sKeywords );
00547     }
00548 
00557     protected function _collectMetaKeyword( $sKeywords )
00558     {
00559         $iMaxTextLength = 60;
00560         $sText = '';
00561 
00562         if ( count( $aArticleList = $this->getArticleList() ) ) {
00563             $oStr = getStr();
00564             foreach ( $aArticleList as $oProduct ) {
00565                 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getLongDescription()->value ) ) );
00566 
00567                 //removing dots from string (they are not cleaned up during general string cleanup)
00568                 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00569 
00570                 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00571                     $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00572                     $sDesc    = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00573                 }
00574                 if ( $sText ) {
00575                     $sText .= ', ';
00576                 }
00577                 $sText .= $sDesc;
00578             }
00579         }
00580 
00581         if ( !$sKeywords ) {
00582             $sKeywords = $this->_getCatPathString();
00583         }
00584 
00585         if ( $sKeywords ) {
00586             $sText = "{$sKeywords}, {$sText}";
00587         }
00588 
00589         return parent::_prepareMetaKeyword( $sText );
00590     }
00591 
00599     public function getTemplateName()
00600     {
00601         // assign template name
00602         if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00603             $this->_sThisTemplate = 'custom/'.$sTplName;
00604         } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00605             $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00606         }
00607 
00608         return $this->_sThisTemplate;
00609     }
00610 
00620     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00621     {
00622         if ( oxRegistry::getUtils()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00623             if ( $iPage ) {
00624                 // only if page number > 0
00625                 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00626             }
00627         } else {
00628             $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00629         }
00630         return $sUrl;
00631     }
00632 
00638     protected function _isActCategory()
00639     {
00640         return $this->_blIsCat;
00641     }
00642 
00648     public function generatePageNavigationUrl( )
00649     {
00650         if ( ( oxRegistry::getUtils()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00651             return $oCategory->getLink();
00652         }
00653         return parent::generatePageNavigationUrl( );
00654     }
00655 
00663     public function getSorting( $sCnid )
00664     {
00665         // category has own sorting
00666         $aSorting = parent::getSorting( $sCnid );
00667         $oActCat = $this->getActCategory();
00668         if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00669             $sSortBy  = $oActCat->oxcategories__oxdefsort->value;
00670             $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : null;
00671 
00672             $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00673             $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00674         }
00675         return $aSorting;
00676     }
00677 
00683     public function getTitleSuffix()
00684     {
00685         if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00686             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00687         }
00688     }
00689 
00695     public function getTitlePageSuffix()
00696     {
00697         if ( ( $iPage = $this->getActPage() ) ) {
00698             return oxRegistry::getLang()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00699         }
00700     }
00701 
00710     protected function _getSubject( $iLang )
00711     {
00712         return $this->getActCategory();
00713     }
00714 
00721     public function getAttributes()
00722     {
00723         $this->_aAttributes = false;
00724         if ( ( $oCategory = $this->getActCategory() ) ) {
00725             $aAttributes = $oCategory->getAttributes();
00726             if ( count( $aAttributes ) ) {
00727                 $this->_aAttributes = $aAttributes;
00728             }
00729         }
00730 
00731         return $this->_aAttributes;
00732     }
00733 
00739     public function getArticleList()
00740     {
00741         if ( $this->_aArticleList === null ) {
00742             if ( /*$this->_isActCategory() &&*/ ( $oCategory = $this->getActCategory() ) ) {
00743                 $aArticleList = $this->_loadArticles( $oCategory );
00744                 if ( count( $aArticleList ) ) {
00745                     $this->_aArticleList = $aArticleList;
00746                 }
00747             }
00748         }
00749 
00750         return $this->_aArticleList;
00751     }
00752 
00758     public function getArticleCount()
00759     {
00760         return $this->_iAllArtCnt;
00761     }
00762 
00768     public function getSimilarRecommListIds()
00769     {
00770         if ( $this->_aSimilarRecommListIds === null ) {
00771             $this->_aSimilarRecommListIds = false;
00772 
00773             if ( $aCatArtList = $this->getArticleList() ) {
00774                 $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
00775             }
00776         }
00777         return $this->_aSimilarRecommListIds;
00778     }
00779 
00785     public function getCatTreePath()
00786     {
00787         if ( $this->_sCatTreePath === null ) {
00788              $this->_sCatTreePath = false;
00789             // category path
00790             if ( $oCatTree = $this->getCategoryTree() ) {
00791                 $this->_sCatTreePath = $oCatTree->getPath();
00792             }
00793         }
00794         return $this->_sCatTreePath;
00795     }
00796 
00802     public function getTreePath()
00803     {
00804         if ( $oCatTree = $this->getCategoryTree() ) {
00805             return $oCatTree->getPath();
00806         }
00807     }
00808 
00814     public function getBreadCrumb()
00815     {
00816         $aPaths = array();
00817 
00818         if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00819             $aPath = array();
00820             $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxRegistry::getLang()->getBaseLanguage(), false );
00821             $aPath['link']  = $this->getLink();
00822 
00823             $aPaths[] = $aPath;
00824 
00825             return $aPaths;
00826         }
00827 
00828         if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00829             foreach ( $oCatPath as $oCat ) {
00830                 $aCatPath = array();
00831 
00832                 $aCatPath['link'] = $oCat->getLink();
00833                 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00834 
00835                 $aPaths[] = $aCatPath;
00836             }
00837         }
00838 
00839         return $aPaths;
00840     }
00841 
00848     public function hasVisibleSubCats()
00849     {
00850         if ( $this->_blHasVisibleSubCats === null ) {
00851             $this->_blHasVisibleSubCats = false;
00852             if ( $oClickCat = $this->getActCategory() ) {
00853                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00854             }
00855         }
00856         return $this->_blHasVisibleSubCats;
00857     }
00858 
00864     public function getSubCatList()
00865     {
00866         if ( $this->_aSubCatList === null ) {
00867             $this->_aSubCatList = array();
00868             if ( $oClickCat = $this->getActCategory() ) {
00869                 $this->_aSubCatList = $oClickCat->getSubCats();
00870             }
00871         }
00872 
00873         return $this->_aSubCatList;
00874     }
00875 
00881     public function getPageNavigation()
00882     {
00883         if ( $this->_oPageNavigation === null ) {
00884             $this->_oPageNavigation = $this->generatePageNavigation();
00885         }
00886         return $this->_oPageNavigation;
00887     }
00888 
00894     public function getTitle()
00895     {
00896         if ( $this->_sCatTitle === null ) {
00897             $this->_sCatTitle = false;
00898             if ( ( $oCategory = $this->getActCategory() ) ) {
00899                 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00900             }
00901         }
00902         return $this->_sCatTitle;
00903     }
00904 
00910     public function getTop5ArticleList()
00911     {
00912         if ( $this->_aTop5ArticleList === null ) {
00913             $this->_aTop5ArticleList = false;
00914             $myConfig = $this->getConfig();
00915             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00916                 // top 5 articles
00917                 $oArtList = oxNew( 'oxarticlelist' );
00918                 $oArtList->loadTop5Articles();
00919                 if ( $oArtList->count() ) {
00920                     $this->_aTop5ArticleList = $oArtList;
00921                 }
00922             }
00923         }
00924         return $this->_aTop5ArticleList;
00925     }
00926 
00932     public function getBargainArticleList()
00933     {
00934         if ( $this->_aBargainArticleList === null ) {
00935             $this->_aBargainArticleList = array();
00936             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00937                 $oArtList = oxNew( 'oxarticlelist' );
00938                 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00939                 if ( $oArtList->count() ) {
00940                     $this->_aBargainArticleList = $oArtList;
00941                 }
00942             }
00943         }
00944         return $this->_aBargainArticleList;
00945     }
00946 
00952     public function getActiveCategory()
00953     {
00954         return $this->getActCategory();
00955     }
00956 
00962     public function getCanonicalUrl()
00963     {
00964         if ( ( $oCategory = $this->getActiveCategory() ) ) {
00965             $oUtils = oxRegistry::get("oxUtilsUrl");
00966             if ( oxRegistry::getUtils()->seoIsActive() ) {
00967                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00968             } else {
00969                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00970             }
00971             return $sUrl;
00972         }
00973     }
00974 
00980     public function canSelectDisplayType()
00981     {
00982         return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00983     }
00984 
00990     public function getPageCount()
00991     {
00992         return $this->_iCntPages;
00993     }
00994 
01000     public function isMoreTagsVisible()
01001     {
01002         return true;
01003     }
01004 }