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         // appending parent title
00424         if ( $oCategory = $this->getActCategory() ) {
00425             if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00426                 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00427             }
00428 
00429             // adding cateogry title
00430             $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00431         }
00432 
00433         // and final component ..
00434         //changed for #2776
00435         if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value ) ) {
00436             $sDescription .= " {$sSuffix}";
00437         }
00438 
00439         // making safe for output
00440         $sDescription = getStr()->html_entity_decode( $sDescription );
00441         $sDescription = getStr()->strip_tags( $sDescription );
00442         $sDescription = getStr()->cleanStr( $sDescription );
00443         $sDescription = getStr()->htmlspecialchars( $sDescription );
00444         return trim( $sDescription );
00445     }
00446 
00452     public function getMetaDescription()
00453     {
00454         $sMeta = parent::getMetaDescription();
00455 
00456         if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00457             if ( $sMeta ) {
00458                 $sMeta .= ", ";
00459             }
00460             $sMeta .= $sTitlePageSuffix;
00461         }
00462 
00463         return $sMeta;
00464     }
00465 
00478     protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00479     {
00480         //formatting description tag
00481         $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->getLongDesc() ):'';
00482         $aArticleList = $this->getArticleList();
00483         if ( !$sAddText && count($aArticleList)) {
00484             foreach ( $aArticleList as $oArticle ) {
00485                 if ( $sAddText ) {
00486                     $sAddText .= ', ';
00487                 }
00488                 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00489             }
00490         }
00491 
00492         if ( !$sMeta ) {
00493             $sMeta = trim( $this->_getCatPathString() );
00494         }
00495 
00496         if ( $sMeta ) {
00497             $sMeta = "{$sMeta} - {$sAddText}";
00498         } else {
00499             $sMeta = $sAddText;
00500         }
00501 
00502         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00503     }
00504 
00513     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00514     {
00515         $sKeywords = '';
00516         if ( ( $oCategory = $this->getActCategory() ) ) {
00517             $aKeywords = array();
00518 
00519             if ( $oCatTree = $this->getCategoryTree() ) {
00520                 foreach ( $oCatTree->getPath() as $oCat ) {
00521                     $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00522                 }
00523             }
00524 
00525             if ( count( $aKeywords ) > 0 ) {
00526                 $sKeywords = implode( ", ", $aKeywords );
00527             }
00528 
00529             $aSubCats  = $oCategory->getSubCats();
00530             if ( is_array( $aSubCats ) ) {
00531                 foreach ( $aSubCats as $oSubCat ) {
00532                     $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00533                 }
00534             }
00535         }
00536 
00537         $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00538 
00539         return trim( $sKeywords );
00540     }
00541 
00550     protected function _collectMetaKeyword( $sKeywords )
00551     {
00552         $iMaxTextLength = 60;
00553         $sText = '';
00554 
00555         if ( count( $aArticleList = $this->getArticleList() ) ) {
00556             $oStr = getStr();
00557             foreach ( $aArticleList as $oProduct ) {
00558                 $sDesc = $oStr->strip_tags( trim( $oStr->strtolower( $oProduct->getLongDescription()->value ) ) );
00559 
00560                 //removing dots from string (they are not cleaned up during general string cleanup)
00561                 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00562 
00563                 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00564                     $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00565                     $sDesc    = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00566                 }
00567                 if ( $sText ) {
00568                     $sText .= ', ';
00569                 }
00570                 $sText .= $sDesc;
00571             }
00572         }
00573 
00574         if ( !$sKeywords ) {
00575             $sKeywords = $this->_getCatPathString();
00576         }
00577 
00578         if ( $sKeywords ) {
00579             $sText = "{$sKeywords}, {$sText}";
00580         }
00581 
00582         return parent::_prepareMetaKeyword( $sText );
00583     }
00584 
00592     public function getTemplateName()
00593     {
00594         // assign template name
00595         if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00596             $this->_sThisTemplate = 'custom/'.$sTplName;
00597         } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00598             $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00599         }
00600 
00601         return $this->_sThisTemplate;
00602     }
00603 
00613     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00614     {
00615         if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00616             if ( $iPage ) {
00617                 // only if page number > 0
00618                 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00619             }
00620         } else {
00621             $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00622         }
00623         return $sUrl;
00624     }
00625 
00631     protected function _isActCategory()
00632     {
00633         return $this->_blIsCat;
00634     }
00635 
00641     public function generatePageNavigationUrl( )
00642     {
00643         if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00644             return $oCategory->getLink();
00645         }
00646         return parent::generatePageNavigationUrl( );
00647     }
00648 
00656     public function getSorting( $sCnid )
00657     {
00658         // category has own sorting
00659         $aSorting = parent::getSorting( $sCnid );
00660         $oActCat = $this->getActCategory();
00661         if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00662             $sSortBy  = $oActCat->oxcategories__oxdefsort->value;
00663             $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : "asc";
00664 
00665             $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00666             $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00667         }
00668         return $aSorting;
00669     }
00670 
00676     public function getTitleSuffix()
00677     {
00678         if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00679             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00680         }
00681     }
00682 
00688     public function getTitlePageSuffix()
00689     {
00690         if ( ( $iPage = $this->getActPage() ) ) {
00691             return oxLang::getInstance()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00692         }
00693     }
00694 
00703     protected function _getSubject( $iLang )
00704     {
00705         return $this->getActCategory();
00706     }
00707 
00714     public function getAttributes()
00715     {
00716         $this->_aAttributes = false;
00717         if ( ( $oCategory = $this->getActCategory() ) ) {
00718             $aAttributes = $oCategory->getAttributes();
00719             if ( count( $aAttributes ) ) {
00720                 $this->_aAttributes = $aAttributes;
00721             }
00722         }
00723 
00724         return $this->_aAttributes;
00725     }
00726 
00732     public function getArticleList()
00733     {
00734         if ( $this->_aArticleList === null ) {
00735             if ( /*$this->_isActCategory() &&*/ ( $oCategory = $this->getActCategory() ) ) {
00736                 $aArticleList = $this->_loadArticles( $oCategory );
00737                 if ( count( $aArticleList ) ) {
00738                     $this->_aArticleList = $aArticleList;
00739                 }
00740             }
00741         }
00742 
00743         return $this->_aArticleList;
00744     }
00745 
00751     public function getArticleCount()
00752     {
00753         return $this->_iAllArtCnt;
00754     }
00755 
00761     public function getSimilarRecommLists()
00762     {
00763         if (!$this->getViewConfig()->getShowListmania()) {
00764             return false;
00765         }
00766 
00767         if ( $this->_oRecommList === null ) {
00768             $this->_oRecommList = false;
00769             if ( $aCatArtList = $this->getArticleList() ) {
00770                 $oRecommList = oxNew('oxrecommlist');
00771                 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00772             }
00773         }
00774         return $this->_oRecommList;
00775     }
00776 
00782     public function getCatTreePath()
00783     {
00784         if ( $this->_sCatTreePath === null ) {
00785              $this->_sCatTreePath = false;
00786             // category path
00787             if ( $oCatTree = $this->getCategoryTree() ) {
00788                 $this->_sCatTreePath = $oCatTree->getPath();
00789             }
00790         }
00791         return $this->_sCatTreePath;
00792     }
00793 
00799     public function getTreePath()
00800     {
00801         if ( $oCatTree = $this->getCategoryTree() ) {
00802             return $oCatTree->getPath();
00803         }
00804     }
00805 
00811     public function getBreadCrumb()
00812     {
00813         $aPaths = array();
00814 
00815         if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00816             $aPath = array();
00817             $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxLang::getInstance()->getBaseLanguage(), false );
00818             $aPath['link']  = $this->getLink();
00819 
00820             $aPaths[] = $aPath;
00821 
00822             return $aPaths;
00823         }
00824 
00825         if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00826             foreach ( $oCatPath as $oCat ) {
00827                 $aCatPath = array();
00828 
00829                 $aCatPath['link'] = $oCat->getLink();
00830                 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00831 
00832                 $aPaths[] = $aCatPath;
00833             }
00834         }
00835 
00836         return $aPaths;
00837     }
00838 
00845     public function hasVisibleSubCats()
00846     {
00847         if ( $this->_blHasVisibleSubCats === null ) {
00848             $this->_blHasVisibleSubCats = false;
00849             if ( $oClickCat = $this->getActCategory() ) {
00850                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00851             }
00852         }
00853         return $this->_blHasVisibleSubCats;
00854     }
00855 
00861     public function getSubCatList()
00862     {
00863         if ( $this->_aSubCatList === null ) {
00864             $this->_aSubCatList = array();
00865             if ( $oClickCat = $this->getActCategory() ) {
00866                 $this->_aSubCatList = $oClickCat->getSubCats();
00867             }
00868         }
00869 
00870         return $this->_aSubCatList;
00871     }
00872 
00878     public function getPageNavigation()
00879     {
00880         if ( $this->_oPageNavigation === null ) {
00881             $this->_oPageNavigation = $this->generatePageNavigation();
00882         }
00883         return $this->_oPageNavigation;
00884     }
00885 
00891     public function getTitle()
00892     {
00893         if ( $this->_sCatTitle === null ) {
00894             $this->_sCatTitle = false;
00895             if ( ( $oCategory = $this->getActCategory() ) ) {
00896                 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00897             }
00898         }
00899         return $this->_sCatTitle;
00900     }
00901 
00907     public function getTop5ArticleList()
00908     {
00909         if ( $this->_aTop5ArticleList === null ) {
00910             $this->_aTop5ArticleList = false;
00911             $myConfig = $this->getConfig();
00912             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00913                 // top 5 articles
00914                 $oArtList = oxNew( 'oxarticlelist' );
00915                 $oArtList->loadTop5Articles();
00916                 if ( $oArtList->count() ) {
00917                     $this->_aTop5ArticleList = $oArtList;
00918                 }
00919             }
00920         }
00921         return $this->_aTop5ArticleList;
00922     }
00923 
00929     public function getBargainArticleList()
00930     {
00931         if ( $this->_aBargainArticleList === null ) {
00932             $this->_aBargainArticleList = array();
00933             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00934                 $oArtList = oxNew( 'oxarticlelist' );
00935                 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00936                 if ( $oArtList->count() ) {
00937                     $this->_aBargainArticleList = $oArtList;
00938                 }
00939             }
00940         }
00941         return $this->_aBargainArticleList;
00942     }
00943 
00949     public function getActiveCategory()
00950     {
00951         return $this->getActCategory();
00952     }
00953 
00959     public function getCanonicalUrl()
00960     {
00961         if ( ( $oCategory = $this->getActiveCategory() ) ) {
00962             $oUtils = oxUtilsUrl::getInstance();
00963             if ( oxUtils::getInstance()->seoIsActive() ) {
00964                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00965             } else {
00966                 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00967             }
00968             return $sUrl;
00969         }
00970     }
00971 
00977     public function canSelectDisplayType()
00978     {
00979         return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00980     }
00981 
00987     public function getPageCount()
00988     {
00989         return $this->_iCntPages;
00990     }
00991 
00997     public function isMoreTagsVisible()
00998     {
00999         return true;
01000     }
01001 }