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( $this->getSortIdent() ) );
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 
00666     public function getSorting( $sCnid )
00667     {
00668         $aSorting = parent::getSorting( $sCnid );
00669         return $aSorting;
00670     }
00671 
00677     public function getDefaultSorting()
00678     {
00679         $oActCat = $this->getActCategory();
00680 
00681         if ( $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00682             $sSortBy  = $oActCat->oxcategories__oxdefsort->value;
00683             $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : "asc";
00684             $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00685         } else {
00686             $aSorting = parent::getDefaultSorting();
00687         }
00688         return $aSorting;
00689     }
00690 
00691 
00697     public function getTitleSuffix()
00698     {
00699         if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00700             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00701         }
00702     }
00703 
00709     public function getTitlePageSuffix()
00710     {
00711         if ( ( $iPage = $this->getActPage() ) ) {
00712             return oxRegistry::getLang()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00713         }
00714     }
00715 
00724     protected function _getSubject( $iLang )
00725     {
00726         return $this->getActCategory();
00727     }
00728 
00735     public function getAttributes()
00736     {
00737         $this->_aAttributes = false;
00738         if ( ( $oCategory = $this->getActCategory() ) ) {
00739             $aAttributes = $oCategory->getAttributes();
00740             if ( count( $aAttributes ) ) {
00741                 $this->_aAttributes = $aAttributes;
00742             }
00743         }
00744 
00745         return $this->_aAttributes;
00746     }
00747 
00753     public function getArticleList()
00754     {
00755         if ( $this->_aArticleList === null ) {
00756             if ( /*$this->_isActCategory() &&*/ ( $oCategory = $this->getActCategory() ) ) {
00757                 $aArticleList = $this->_loadArticles( $oCategory );
00758                 if ( count( $aArticleList ) ) {
00759                     $this->_aArticleList = $aArticleList;
00760                 }
00761             }
00762         }
00763 
00764         return $this->_aArticleList;
00765     }
00766 
00772     public function getArticleCount()
00773     {
00774         return $this->_iAllArtCnt;
00775     }
00776 
00782     public function getSimilarRecommListIds()
00783     {
00784         if ( $this->_aSimilarRecommListIds === null ) {
00785             $this->_aSimilarRecommListIds = false;
00786 
00787             if ( $aCatArtList = $this->getArticleList() ) {
00788                 $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
00789             }
00790         }
00791         return $this->_aSimilarRecommListIds;
00792     }
00793 
00799     public function getCatTreePath()
00800     {
00801         if ( $this->_sCatTreePath === null ) {
00802              $this->_sCatTreePath = false;
00803             // category path
00804             if ( $oCatTree = $this->getCategoryTree() ) {
00805                 $this->_sCatTreePath = $oCatTree->getPath();
00806             }
00807         }
00808         return $this->_sCatTreePath;
00809     }
00810 
00816     public function getTreePath()
00817     {
00818         if ( $oCatTree = $this->getCategoryTree() ) {
00819             return $oCatTree->getPath();
00820         }
00821     }
00822 
00828     public function getBreadCrumb()
00829     {
00830         $aPaths = array();
00831 
00832         if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00833             $aPath = array();
00834             $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxRegistry::getLang()->getBaseLanguage(), false );
00835             $aPath['link']  = $this->getLink();
00836 
00837             $aPaths[] = $aPath;
00838 
00839             return $aPaths;
00840         }
00841 
00842         if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00843             foreach ( $oCatPath as $oCat ) {
00844                 $aCatPath = array();
00845 
00846                 $aCatPath['link'] = $oCat->getLink();
00847                 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00848 
00849                 $aPaths[] = $aCatPath;
00850             }
00851         }
00852 
00853         return $aPaths;
00854     }
00855 
00862     public function hasVisibleSubCats()
00863     {
00864         if ( $this->_blHasVisibleSubCats === null ) {
00865             $this->_blHasVisibleSubCats = false;
00866             if ( $oClickCat = $this->getActCategory() ) {
00867                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00868             }
00869         }
00870         return $this->_blHasVisibleSubCats;
00871     }
00872 
00878     public function getSubCatList()
00879     {
00880         if ( $this->_aSubCatList === null ) {
00881             $this->_aSubCatList = array();
00882             if ( $oClickCat = $this->getActCategory() ) {
00883                 $this->_aSubCatList = $oClickCat->getSubCats();
00884             }
00885         }
00886 
00887         return $this->_aSubCatList;
00888     }
00889 
00895     public function getPageNavigation()
00896     {
00897         if ( $this->_oPageNavigation === null ) {
00898             $this->_oPageNavigation = $this->generatePageNavigation();
00899         }
00900         return $this->_oPageNavigation;
00901     }
00902 
00908     public function getTitle()
00909     {
00910         if ( $this->_sCatTitle === null ) {
00911             $this->_sCatTitle = false;
00912             if ( ( $oCategory = $this->getActCategory() ) ) {
00913                 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00914             }
00915         }
00916         return $this->_sCatTitle;
00917     }
00918 
00924     public function getTop5ArticleList()
00925     {
00926         if ( $this->_aTop5ArticleList === null ) {
00927             $this->_aTop5ArticleList = false;
00928             $myConfig = $this->getConfig();
00929             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00930                 // top 5 articles
00931                 $oArtList = oxNew( 'oxarticlelist' );
00932                 $oArtList->loadTop5Articles();
00933                 if ( $oArtList->count() ) {
00934                     $this->_aTop5ArticleList = $oArtList;
00935                 }
00936             }
00937         }
00938         return $this->_aTop5ArticleList;
00939     }
00940 
00946     public function getBargainArticleList()
00947     {
00948         if ( $this->_aBargainArticleList === null ) {
00949             $this->_aBargainArticleList = array();
00950             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00951                 $oArtList = oxNew( 'oxarticlelist' );
00952                 $oArtList->loadActionArticles( 'OXBARGAIN' );
00953                 if ( $oArtList->count() ) {
00954                     $this->_aBargainArticleList = $oArtList;
00955                 }
00956             }
00957         }
00958         return $this->_aBargainArticleList;
00959     }
00960 
00966     public function getActiveCategory()
00967     {
00968         return $this->getActCategory();
00969     }
00970 
00976     public function getCanonicalUrl()
00977     {
00978         if ( ( $oCategory = $this->getActiveCategory() ) ) {
00979             $oUtils = oxRegistry::get("oxUtilsUrl");
00980             if ( oxRegistry::getUtils()->seoIsActive() ) {
00981                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00982             } else {
00983                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00984             }
00985             return $sUrl;
00986         }
00987     }
00988 
00994     public function canSelectDisplayType()
00995     {
00996         return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00997     }
00998 
01004     public function getPageCount()
01005     {
01006         return $this->_iCntPages;
01007     }
01008 }