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()->html_entity_decode( $sDescription );
00449         $sDescription = getStr()->strip_tags( $sDescription );
00450         $sDescription = getStr()->cleanStr( $sDescription );
00451         $sDescription = getStr()->htmlspecialchars( $sDescription );
00452         return trim( $sDescription );
00453     }
00454 
00460     public function getMetaDescription()
00461     {
00462         $sMeta = parent::getMetaDescription();
00463 
00464         if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00465             if ( $sMeta ) {
00466                 $sMeta .= ", ";
00467             }
00468             $sMeta .= $sTitlePageSuffix;
00469         }
00470 
00471         return $sMeta;
00472     }
00473 
00486     protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00487     {
00488         //formatting description tag
00489         $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->getLongDesc() ):'';
00490         $aArticleList = $this->getArticleList();
00491         if ( !$sAddText && count($aArticleList)) {
00492             foreach ( $aArticleList as $oArticle ) {
00493                 if ( $sAddText ) {
00494                     $sAddText .= ', ';
00495                 }
00496                 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00497             }
00498         }
00499 
00500         if ( !$sMeta ) {
00501             $sMeta = trim( $this->_getCatPathString() );
00502         }
00503 
00504         if ( $sMeta ) {
00505             $sMeta = "{$sMeta} - {$sAddText}";
00506         } else {
00507             $sMeta = $sAddText;
00508         }
00509 
00510         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00511     }
00512 
00521     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00522     {
00523         $sKeywords = '';
00524         if ( ( $oCategory = $this->getActCategory() ) ) {
00525             $aKeywords = array();
00526 
00527             if ( $oCatTree = $this->getCategoryTree() ) {
00528                 foreach ( $oCatTree->getPath() as $oCat ) {
00529                     $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00530                 }
00531             }
00532 
00533             if ( count( $aKeywords ) > 0 ) {
00534                 $sKeywords = implode( ", ", $aKeywords );
00535             }
00536 
00537             $aSubCats  = $oCategory->getSubCats();
00538             if ( is_array( $aSubCats ) ) {
00539                 foreach ( $aSubCats as $oSubCat ) {
00540                     $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00541                 }
00542             }
00543         }
00544 
00545         $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00546 
00547         return trim( $sKeywords );
00548     }
00549 
00558     protected function _collectMetaKeyword( $sKeywords )
00559     {
00560         $iMaxTextLength = 60;
00561         $sText = '';
00562 
00563         if ( count( $aArticleList = $this->getArticleList() ) ) {
00564             $oStr = getStr();
00565             foreach ( $aArticleList as $oProduct ) {
00566                 $sDesc = $oStr->strip_tags( trim( $oStr->strtolower( $oProduct->getLongDescription()->value ) ) );
00567 
00568                 //removing dots from string (they are not cleaned up during general string cleanup)
00569                 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00570 
00571                 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00572                     $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00573                     $sDesc    = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00574                 }
00575                 if ( $sText ) {
00576                     $sText .= ', ';
00577                 }
00578                 $sText .= $sDesc;
00579             }
00580         }
00581 
00582         if ( !$sKeywords ) {
00583             $sKeywords = $this->_getCatPathString();
00584         }
00585 
00586         if ( $sKeywords ) {
00587             $sText = "{$sKeywords}, {$sText}";
00588         }
00589 
00590         return parent::_prepareMetaKeyword( $sText );
00591     }
00592 
00600     public function getTemplateName()
00601     {
00602         // assign template name
00603         if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00604             $this->_sThisTemplate = 'custom/'.$sTplName;
00605         } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00606             $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00607         }
00608 
00609         return $this->_sThisTemplate;
00610     }
00611 
00621     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00622     {
00623         if ( oxRegistry::getUtils()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00624             if ( $iPage ) {
00625                 // only if page number > 0
00626                 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00627             }
00628         } else {
00629             $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00630         }
00631         return $sUrl;
00632     }
00633 
00639     protected function _isActCategory()
00640     {
00641         return $this->_blIsCat;
00642     }
00643 
00649     public function generatePageNavigationUrl( )
00650     {
00651         if ( ( oxRegistry::getUtils()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00652             return $oCategory->getLink();
00653         }
00654         return parent::generatePageNavigationUrl( );
00655     }
00656 
00664     public function getSorting( $sCnid )
00665     {
00666         // category has own sorting
00667         $aSorting = parent::getSorting( $sCnid );
00668         $oActCat = $this->getActCategory();
00669         if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00670             $sSortBy  = $oActCat->oxcategories__oxdefsort->value;
00671             $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : "asc";
00672 
00673             $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00674             $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00675         }
00676         return $aSorting;
00677     }
00678 
00684     public function getTitleSuffix()
00685     {
00686         if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00687             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00688         }
00689     }
00690 
00696     public function getTitlePageSuffix()
00697     {
00698         if ( ( $iPage = $this->getActPage() ) ) {
00699             return oxRegistry::getLang()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00700         }
00701     }
00702 
00711     protected function _getSubject( $iLang )
00712     {
00713         return $this->getActCategory();
00714     }
00715 
00722     public function getAttributes()
00723     {
00724         $this->_aAttributes = false;
00725         if ( ( $oCategory = $this->getActCategory() ) ) {
00726             $aAttributes = $oCategory->getAttributes();
00727             if ( count( $aAttributes ) ) {
00728                 $this->_aAttributes = $aAttributes;
00729             }
00730         }
00731 
00732         return $this->_aAttributes;
00733     }
00734 
00740     public function getArticleList()
00741     {
00742         if ( $this->_aArticleList === null ) {
00743             if ( /*$this->_isActCategory() &&*/ ( $oCategory = $this->getActCategory() ) ) {
00744                 $aArticleList = $this->_loadArticles( $oCategory );
00745                 if ( count( $aArticleList ) ) {
00746                     $this->_aArticleList = $aArticleList;
00747                 }
00748             }
00749         }
00750 
00751         return $this->_aArticleList;
00752     }
00753 
00759     public function getArticleCount()
00760     {
00761         return $this->_iAllArtCnt;
00762     }
00763 
00769     public function getSimilarRecommListIds()
00770     {
00771         if ( $this->_aSimilarRecommListIds === null ) {
00772             $this->_aSimilarRecommListIds = false;
00773 
00774             if ( $aCatArtList = $this->getArticleList() ) {
00775                 $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
00776             }
00777         }
00778         return $this->_aSimilarRecommListIds;
00779     }
00780 
00786     public function getCatTreePath()
00787     {
00788         if ( $this->_sCatTreePath === null ) {
00789              $this->_sCatTreePath = false;
00790             // category path
00791             if ( $oCatTree = $this->getCategoryTree() ) {
00792                 $this->_sCatTreePath = $oCatTree->getPath();
00793             }
00794         }
00795         return $this->_sCatTreePath;
00796     }
00797 
00803     public function getTreePath()
00804     {
00805         if ( $oCatTree = $this->getCategoryTree() ) {
00806             return $oCatTree->getPath();
00807         }
00808     }
00809 
00815     public function getBreadCrumb()
00816     {
00817         $aPaths = array();
00818 
00819         if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00820             $aPath = array();
00821             $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxRegistry::getLang()->getBaseLanguage(), false );
00822             $aPath['link']  = $this->getLink();
00823 
00824             $aPaths[] = $aPath;
00825 
00826             return $aPaths;
00827         }
00828 
00829         if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00830             foreach ( $oCatPath as $oCat ) {
00831                 $aCatPath = array();
00832 
00833                 $aCatPath['link'] = $oCat->getLink();
00834                 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00835 
00836                 $aPaths[] = $aCatPath;
00837             }
00838         }
00839 
00840         return $aPaths;
00841     }
00842 
00849     public function hasVisibleSubCats()
00850     {
00851         if ( $this->_blHasVisibleSubCats === null ) {
00852             $this->_blHasVisibleSubCats = false;
00853             if ( $oClickCat = $this->getActCategory() ) {
00854                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00855             }
00856         }
00857         return $this->_blHasVisibleSubCats;
00858     }
00859 
00865     public function getSubCatList()
00866     {
00867         if ( $this->_aSubCatList === null ) {
00868             $this->_aSubCatList = array();
00869             if ( $oClickCat = $this->getActCategory() ) {
00870                 $this->_aSubCatList = $oClickCat->getSubCats();
00871             }
00872         }
00873 
00874         return $this->_aSubCatList;
00875     }
00876 
00882     public function getPageNavigation()
00883     {
00884         if ( $this->_oPageNavigation === null ) {
00885             $this->_oPageNavigation = $this->generatePageNavigation();
00886         }
00887         return $this->_oPageNavigation;
00888     }
00889 
00895     public function getTitle()
00896     {
00897         if ( $this->_sCatTitle === null ) {
00898             $this->_sCatTitle = false;
00899             if ( ( $oCategory = $this->getActCategory() ) ) {
00900                 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00901             }
00902         }
00903         return $this->_sCatTitle;
00904     }
00905 
00911     public function getTop5ArticleList()
00912     {
00913         if ( $this->_aTop5ArticleList === null ) {
00914             $this->_aTop5ArticleList = false;
00915             $myConfig = $this->getConfig();
00916             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00917                 // top 5 articles
00918                 $oArtList = oxNew( 'oxarticlelist' );
00919                 $oArtList->loadTop5Articles();
00920                 if ( $oArtList->count() ) {
00921                     $this->_aTop5ArticleList = $oArtList;
00922                 }
00923             }
00924         }
00925         return $this->_aTop5ArticleList;
00926     }
00927 
00933     public function getBargainArticleList()
00934     {
00935         if ( $this->_aBargainArticleList === null ) {
00936             $this->_aBargainArticleList = array();
00937             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00938                 $oArtList = oxNew( 'oxarticlelist' );
00939                 $oArtList->loadActionArticles( 'OXBARGAIN' );
00940                 if ( $oArtList->count() ) {
00941                     $this->_aBargainArticleList = $oArtList;
00942                 }
00943             }
00944         }
00945         return $this->_aBargainArticleList;
00946     }
00947 
00953     public function getActiveCategory()
00954     {
00955         return $this->getActCategory();
00956     }
00957 
00963     public function getCanonicalUrl()
00964     {
00965         if ( ( $oCategory = $this->getActiveCategory() ) ) {
00966             $oUtils = oxRegistry::get("oxUtilsUrl");
00967             if ( oxRegistry::getUtils()->seoIsActive() ) {
00968                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00969             } else {
00970                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00971             }
00972             return $sUrl;
00973         }
00974     }
00975 
00981     public function canSelectDisplayType()
00982     {
00983         return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00984     }
00985 
00991     public function getPageCount()
00992     {
00993         return $this->_iCntPages;
00994     }
00995 }