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', true, 302 );
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->_blIsCat ) {
00187             $this->_checkRequestedPage();
00188         }
00189 
00190         parent::render();
00191 
00192         // processing list articles
00193         $this->_processListArticles();
00194 
00195         return $this->getTemplateName();
00196     }
00197 
00206     protected function _checkRequestedPage()
00207     {
00208         $iPageCnt = $this->getPageCount();
00209         // redirecting to first page in case requested page does not exist
00210         if ( $iPageCnt && ( ( $iPageCnt - 1 ) < $this->getActPage() ) ) {
00211             oxUtils::getInstance()->redirect( $this->getActiveCategory()->getLink(), false );
00212         }
00213     }
00214 
00221     protected function _processListArticles()
00222     {
00223         if ( $aArtList = $this->getArticleList() ) {
00224             $iLinkType = $this->_getProductLinkType();
00225             $sAddDynParams = $this->getAddUrlParams();
00226             $sAddSeoParams = $this->getAddSeoUrlParams();
00227 
00228             foreach ( $aArtList as $oArticle ) {
00229                 $oArticle->setLinkType( $iLinkType );
00230 
00231                 // appending dynamic urls
00232                 if ( $sAddDynParams ) {
00233                     $oArticle->appendStdLink( $sAddDynParams );
00234                 }
00235 
00236                 // appending seo urls
00237                 if ( $sAddSeoParams ) {
00238                     $oArticle->appendLink( $sAddSeoParams );
00239                 }
00240             }
00241         }
00242     }
00243 
00244 
00250     public function getAddUrlParams()
00251     {
00252         $sParams = parent::getAddUrlParams();
00253         if ( !oxUtils::getInstance()->seoIsActive() ) {
00254             $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
00255             if ( $iPgNr > 0 ) {
00256                 $sParams .= ($sParams?'&amp;':'') . "pgNr={$iPgNr}";
00257             }
00258         }
00259 
00260         return $sParams;
00261     }
00262 
00268     public function getAddSeoUrlParams()
00269     {
00270     }
00271 
00279     protected function _getProductLinkType()
00280     {
00281         $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00282         if ( ( $oCat = $this->getActCategory() ) && $oCat->isPriceCategory() ) {
00283             $iCatType =  OXARTICLE_LINKTYPE_PRICECATEGORY;
00284         }
00285         return $iCatType;
00286     }
00287 
00296     public function executefilter()
00297     {
00298         $iLang = oxLang::getInstance()->getBaseLanguage();
00299         // store this into session
00300         $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00301         $sActCat = oxConfig::getParameter( 'cnid' );
00302 
00303         if ( !empty( $aFilter ) ) {
00304             $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00305             //fix for #2904 - if language will be changed attributes of this category will be deleted from session
00306             //and new filters for active language set.
00307             $aSessionFilter[$sActCat] = null;
00308             $aSessionFilter[$sActCat][$iLang] = $aFilter;
00309             oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00310         }
00311     }
00312 
00320     protected function _loadArticles( $oCategory )
00321     {
00322         $myConfig = $this->getConfig();
00323 
00324         $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00325         $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00326 
00327         // load only articles which we show on screen
00328         $oArtList = oxNew( 'oxarticlelist' );
00329         $oArtList->setSqlLimit( $iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles );
00330         $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00331 
00332         if ( $oCategory->isPriceCategory() ) {
00333             $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00334             $dPriceTo   = $oCategory->oxcategories__oxpriceto->value;
00335 
00336             $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00337         } else {
00338             $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00339 
00340             $sActCat = oxConfig::getParameter( 'cnid' );
00341             $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00342         }
00343 
00344         $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00345 
00346         return $oArtList;
00347     }
00348 
00354     public function getActPage()
00355     {
00356         return $this->_getRequestPageNr();
00357     }
00358 
00367     protected function _getRequestPageNr()
00368     {
00369         return parent::getActPage();
00370     }
00371 
00377     protected function _getSeoObjectId()
00378     {
00379         if ( ( $oCategory = $this->getActCategory() ) ) {
00380             return $oCategory->getId();
00381         }
00382     }
00383 
00389     protected function _getCatPathString()
00390     {
00391         if ( $this->_sCatPathString === null ) {
00392 
00393             // marking as allready set
00394             $this->_sCatPathString = false;
00395 
00396             //fetching category path
00397             if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00398 
00399                 $oStr = getStr();
00400                 $this->_sCatPathString = '';
00401                 foreach ( $aPath as $oCat ) {
00402                     if ( $this->_sCatPathString ) {
00403                         $this->_sCatPathString .= ', ';
00404                     }
00405                     $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00406                 }
00407             }
00408         }
00409         return $this->_sCatPathString;
00410     }
00411 
00421     protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00422     {
00423         // using language constant ..
00424         $sDescription = oxLang::getInstance()->translateString( 'ALIST_META_DESCRIPTION_PREFIX' );
00425 
00426         // appending parent title
00427         if ( $oCategory = $this->getActCategory() ) {
00428             if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00429                 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00430             }
00431 
00432             // adding cateogry title
00433             $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00434         }
00435 
00436         // and final component ..
00437         if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00438             $sDescription .= " {$sSuffix}";
00439         }
00440 
00441         // making safe for output
00442         $sDescription = getStr()->cleanStr($sDescription);
00443         return trim( strip_tags( getStr()->html_entity_decode( $sDescription ) ) );
00444     }
00445 
00451     public function getMetaDescription()
00452     {
00453         $sMeta = parent::getMetaDescription();
00454 
00455         if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00456             if ( $sMeta ) {
00457                 $sMeta .= ", ";
00458             }
00459             $sMeta .= $sTitlePageSuffix;
00460         }
00461 
00462         return $sMeta;
00463     }
00464 
00477     protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00478     {
00479         //formatting description tag
00480         $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->getLongDesc() ):'';
00481         $aArticleList = $this->getArticleList();
00482         if ( !$sAddText && count($aArticleList)) {
00483             foreach ( $aArticleList as $oArticle ) {
00484                 if ( $sAddText ) {
00485                     $sAddText .= ', ';
00486                 }
00487                 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00488             }
00489         }
00490 
00491         if ( !$sMeta ) {
00492             $sMeta = trim( $this->_getCatPathString() );
00493         }
00494 
00495         if ( $sMeta ) {
00496             $sMeta = "{$sMeta} - {$sAddText}";
00497         } else {
00498             $sMeta = $sAddText;
00499         }
00500 
00501         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00502     }
00503 
00512     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00513     {
00514         $sKeywords = '';
00515         if ( ( $oCategory = $this->getActCategory() ) ) {
00516             $aKeywords = array();
00517 
00518             if ( $oCatTree = $this->getCategoryTree() ) {
00519                 foreach ( $oCatTree->getPath() as $oCat ) {
00520                     $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00521                 }
00522             }
00523 
00524             if ( count( $aKeywords ) > 0 ) {
00525                 $sKeywords = implode( ", ", $aKeywords );
00526             }
00527 
00528             $aSubCats  = $oCategory->getSubCats();
00529             if ( is_array( $aSubCats ) ) {
00530                 foreach ( $aSubCats as $oSubCat ) {
00531                     $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00532                 }
00533             }
00534         }
00535 
00536         $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00537 
00538         return trim( $sKeywords );
00539     }
00540 
00549     protected function _collectMetaKeyword( $sKeywords )
00550     {
00551         $iMaxTextLength = 60;
00552         $sText = '';
00553 
00554         if ( count( $aArticleList = $this->getArticleList() ) ) {
00555             $oStr = getStr();
00556             foreach ( $aArticleList as $oProduct ) {
00557                 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00558 
00559                 //removing dots from string (they are not cleaned up during general string cleanup)
00560                 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00561 
00562                 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00563                     $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00564                     $sDesc    = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00565                 }
00566                 if ( $sText ) {
00567                     $sText .= ', ';
00568                 }
00569                 $sText .= $sDesc;
00570             }
00571         }
00572 
00573         if ( !$sKeywords ) {
00574             $sKeywords = $this->_getCatPathString();
00575         }
00576 
00577         if ( $sKeywords ) {
00578             $sText = "{$sKeywords}, {$sText}";
00579         }
00580 
00581         return parent::_prepareMetaKeyword( $sText );
00582     }
00583 
00591     public function getTemplateName()
00592     {
00593         // assign template name
00594         if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00595             $this->_sThisTemplate = $sTplName;
00596         } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00597             $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00598         }
00599 
00600         return $this->_sThisTemplate;
00601     }
00602 
00612     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00613     {
00614         if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00615             if ( $iPage ) {
00616                 // only if page number > 0
00617                 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00618             }
00619         } else {
00620             $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00621         }
00622         return $sUrl;
00623     }
00624 
00630     protected function _isActCategory()
00631     {
00632         return $this->_blIsCat;
00633     }
00634 
00640     public function generatePageNavigationUrl( )
00641     {
00642         if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00643             return $oCategory->getLink();
00644         }
00645         return parent::generatePageNavigationUrl( );
00646     }
00647 
00655     public function getSorting( $sCnid )
00656     {
00657         // category has own sorting
00658         $aSorting = parent::getSorting( $sCnid );
00659         $oActCat = $this->getActCategory();
00660         if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00661             $sSortBy  = $oActCat->oxcategories__oxdefsort->value;
00662             $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : null;
00663 
00664             $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00665             $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00666         }
00667         return $aSorting;
00668     }
00669 
00675     public function getTitleSuffix()
00676     {
00677         if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00678             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00679         }
00680     }
00681 
00687     public function getTitlePageSuffix()
00688     {
00689         if ( ( $iPage = $this->getActPage() ) ) {
00690             return oxLang::getInstance()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00691         }
00692     }
00693 
00702     protected function _getSubject( $iLang )
00703     {
00704         return $this->getActCategory();
00705     }
00706 
00713     public function getAttributes()
00714     {
00715         $this->_aAttributes = false;
00716         if ( ( $oCategory = $this->getActCategory() ) ) {
00717             $aAttributes = $oCategory->getAttributes();
00718             if ( count( $aAttributes ) ) {
00719                 $this->_aAttributes = $aAttributes;
00720             }
00721         }
00722 
00723         return $this->_aAttributes;
00724     }
00725 
00731     public function getArticleList()
00732     {
00733         if ( $this->_aArticleList === null ) {
00734             if ( /*$this->_isActCategory() &&*/ ( $oCategory = $this->getActCategory() ) ) {
00735                 $aArticleList = $this->_loadArticles( $oCategory );
00736                 if ( count( $aArticleList ) ) {
00737                     $this->_aArticleList = $aArticleList;
00738                 }
00739             }
00740         }
00741 
00742         return $this->_aArticleList;
00743     }
00744 
00750     public function getSimilarRecommLists()
00751     {
00752         if (!$this->getViewConfig()->getShowListmania()) {
00753             return false;
00754         }
00755 
00756         if ( $this->_oRecommList === null ) {
00757             $this->_oRecommList = false;
00758             if ( $aCatArtList = $this->getArticleList() ) {
00759                 $oRecommList = oxNew('oxrecommlist');
00760                 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00761             }
00762         }
00763         return $this->_oRecommList;
00764     }
00765 
00771     public function getCatTreePath()
00772     {
00773         if ( $this->_sCatTreePath === null ) {
00774              $this->_sCatTreePath = false;
00775             // category path
00776             if ( $oCatTree = $this->getCategoryTree() ) {
00777                 $this->_sCatTreePath = $oCatTree->getPath();
00778             }
00779         }
00780         return $this->_sCatTreePath;
00781     }
00782 
00788     public function getTreePath()
00789     {
00790         if ( $oCatTree = $this->getCategoryTree() ) {
00791             return $oCatTree->getPath();
00792         }
00793     }
00794 
00800     public function getBreadCrumb()
00801     {
00802         $aPaths = array();
00803 
00804         if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00805             $aPath = array();
00806             $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxLang::getInstance()->getBaseLanguage(), false );
00807             $aPath['link']  = $this->getLink();
00808 
00809             $aPaths[] = $aPath;
00810 
00811             return $aPaths;
00812         }
00813 
00814         if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00815             foreach ( $oCatPath as $oCat ) {
00816                 $aCatPath = array();
00817 
00818                 $aCatPath['link'] = $oCat->getLink();
00819                 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00820 
00821                 $aPaths[] = $aCatPath;
00822             }
00823         }
00824 
00825         return $aPaths;
00826     }
00827 
00834     public function hasVisibleSubCats()
00835     {
00836         if ( $this->_blHasVisibleSubCats === null ) {
00837             $this->_blHasVisibleSubCats = false;
00838             if ( $oClickCat = $this->getActCategory() ) {
00839                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00840             }
00841         }
00842         return $this->_blHasVisibleSubCats;
00843     }
00844 
00850     public function getSubCatList()
00851     {
00852         if ( $this->_aSubCatList === null ) {
00853             $this->_aSubCatList = array();
00854             if ( $oClickCat = $this->getActCategory() ) {
00855                 $this->_aSubCatList = $oClickCat->getSubCats();
00856             }
00857         }
00858 
00859         return $this->_aSubCatList;
00860     }
00861 
00867     public function getPageNavigation()
00868     {
00869         if ( $this->_oPageNavigation === null ) {
00870             $this->_oPageNavigation = $this->generatePageNavigation();
00871         }
00872         return $this->_oPageNavigation;
00873     }
00874 
00880     public function getTitle()
00881     {
00882         if ( $this->_sCatTitle === null ) {
00883             $this->_sCatTitle = false;
00884             if ( ( $oCategory = $this->getActCategory() ) ) {
00885                 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00886             }
00887         }
00888         return $this->_sCatTitle;
00889     }
00890 
00896     public function getTop5ArticleList()
00897     {
00898         if ( $this->_aTop5ArticleList === null ) {
00899             $this->_aTop5ArticleList = false;
00900             $myConfig = $this->getConfig();
00901             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00902                 // top 5 articles
00903                 $oArtList = oxNew( 'oxarticlelist' );
00904                 $oArtList->loadTop5Articles();
00905                 if ( $oArtList->count() ) {
00906                     $this->_aTop5ArticleList = $oArtList;
00907                 }
00908             }
00909         }
00910         return $this->_aTop5ArticleList;
00911     }
00912 
00918     public function getBargainArticleList()
00919     {
00920         if ( $this->_aBargainArticleList === null ) {
00921             $this->_aBargainArticleList = array();
00922             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00923                 $oArtList = oxNew( 'oxarticlelist' );
00924                 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00925                 if ( $oArtList->count() ) {
00926                     $this->_aBargainArticleList = $oArtList;
00927                 }
00928             }
00929         }
00930         return $this->_aBargainArticleList;
00931     }
00932 
00938     public function getActiveCategory()
00939     {
00940         return $this->getActCategory();
00941     }
00942 
00948     public function getCanonicalUrl()
00949     {
00950         if ( ( $oCategory = $this->getActiveCategory() ) ) {
00951             $oUtils = oxUtilsUrl::getInstance();
00952             if ( oxUtils::getInstance()->seoIsActive() ) {
00953                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00954             } else {
00955                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00956             }
00957             return $sUrl;
00958         }
00959     }
00960 
00966     public function canSelectDisplayType()
00967     {
00968         return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00969     }
00970 
00976     public function getPageCount()
00977     {
00978         return $this->_iCntPages;
00979     }
00980 
00986     public function isMoreTagsVisible()
00987     {
00988         return true;
00989     }
00990 }