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
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
00156 if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00157
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
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
00184 $this->getArticleList();
00185
00186 if ( $this->_blIsCat ) {
00187 $this->_checkRequestedPage();
00188 }
00189
00190 parent::render();
00191
00192
00193 $this->_processListArticles();
00194
00195 return $this->getTemplateName();
00196 }
00197
00206 protected function _checkRequestedPage()
00207 {
00208 $iPageCnt = $this->getPageCount();
00209
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
00232 if ( $sAddDynParams ) {
00233 $oArticle->appendStdLink( $sAddDynParams );
00234 }
00235
00236
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?'&':'') . "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
00300 $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00301 $sActCat = oxConfig::getParameter( 'cnid' );
00302
00303 if ( !empty( $aFilter ) ) {
00304 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00305
00306
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
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
00394 $this->_sCatPathString = false;
00395
00396
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
00424 if ( $oCategory = $this->getActCategory() ) {
00425 if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00426 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00427 }
00428
00429
00430 $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00431 }
00432
00433
00434
00435 if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value ) ) {
00436 $sDescription .= " {$sSuffix}";
00437 }
00438
00439
00440 $sDescription = getStr()->cleanStr($sDescription);
00441 return trim( strip_tags( getStr()->html_entity_decode( $sDescription ) ) );
00442 }
00443
00449 public function getMetaDescription()
00450 {
00451 $sMeta = parent::getMetaDescription();
00452
00453 if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00454 if ( $sMeta ) {
00455 $sMeta .= ", ";
00456 }
00457 $sMeta .= $sTitlePageSuffix;
00458 }
00459
00460 return $sMeta;
00461 }
00462
00475 protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00476 {
00477
00478 $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->getLongDesc() ):'';
00479 $aArticleList = $this->getArticleList();
00480 if ( !$sAddText && count($aArticleList)) {
00481 foreach ( $aArticleList as $oArticle ) {
00482 if ( $sAddText ) {
00483 $sAddText .= ', ';
00484 }
00485 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00486 }
00487 }
00488
00489 if ( !$sMeta ) {
00490 $sMeta = trim( $this->_getCatPathString() );
00491 }
00492
00493 if ( $sMeta ) {
00494 $sMeta = "{$sMeta} - {$sAddText}";
00495 } else {
00496 $sMeta = $sAddText;
00497 }
00498
00499 return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00500 }
00501
00510 protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00511 {
00512 $sKeywords = '';
00513 if ( ( $oCategory = $this->getActCategory() ) ) {
00514 $aKeywords = array();
00515
00516 if ( $oCatTree = $this->getCategoryTree() ) {
00517 foreach ( $oCatTree->getPath() as $oCat ) {
00518 $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00519 }
00520 }
00521
00522 if ( count( $aKeywords ) > 0 ) {
00523 $sKeywords = implode( ", ", $aKeywords );
00524 }
00525
00526 $aSubCats = $oCategory->getSubCats();
00527 if ( is_array( $aSubCats ) ) {
00528 foreach ( $aSubCats as $oSubCat ) {
00529 $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00530 }
00531 }
00532 }
00533
00534 $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00535
00536 return trim( $sKeywords );
00537 }
00538
00547 protected function _collectMetaKeyword( $sKeywords )
00548 {
00549 $iMaxTextLength = 60;
00550 $sText = '';
00551
00552 if ( count( $aArticleList = $this->getArticleList() ) ) {
00553 $oStr = getStr();
00554 foreach ( $aArticleList as $oProduct ) {
00555 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getLongDescription()->value ) ) );
00556
00557
00558 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00559
00560 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00561 $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00562 $sDesc = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00563 }
00564 if ( $sText ) {
00565 $sText .= ', ';
00566 }
00567 $sText .= $sDesc;
00568 }
00569 }
00570
00571 if ( !$sKeywords ) {
00572 $sKeywords = $this->_getCatPathString();
00573 }
00574
00575 if ( $sKeywords ) {
00576 $sText = "{$sKeywords}, {$sText}";
00577 }
00578
00579 return parent::_prepareMetaKeyword( $sText );
00580 }
00581
00589 public function getTemplateName()
00590 {
00591
00592 if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00593 $this->_sThisTemplate = 'custom/'.$sTplName;
00594 } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00595 $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00596 }
00597
00598 return $this->_sThisTemplate;
00599 }
00600
00610 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00611 {
00612 if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00613 if ( $iPage ) {
00614
00615 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00616 }
00617 } else {
00618 $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00619 }
00620 return $sUrl;
00621 }
00622
00628 protected function _isActCategory()
00629 {
00630 return $this->_blIsCat;
00631 }
00632
00638 public function generatePageNavigationUrl( )
00639 {
00640 if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00641 return $oCategory->getLink();
00642 }
00643 return parent::generatePageNavigationUrl( );
00644 }
00645
00653 public function getSorting( $sCnid )
00654 {
00655
00656 $aSorting = parent::getSorting( $sCnid );
00657 $oActCat = $this->getActCategory();
00658 if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00659 $sSortBy = $oActCat->oxcategories__oxdefsort->value;
00660 $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : null;
00661
00662 $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00663 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00664 }
00665 return $aSorting;
00666 }
00667
00673 public function getTitleSuffix()
00674 {
00675 if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00676 return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00677 }
00678 }
00679
00685 public function getTitlePageSuffix()
00686 {
00687 if ( ( $iPage = $this->getActPage() ) ) {
00688 return oxLang::getInstance()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00689 }
00690 }
00691
00700 protected function _getSubject( $iLang )
00701 {
00702 return $this->getActCategory();
00703 }
00704
00711 public function getAttributes()
00712 {
00713 $this->_aAttributes = false;
00714 if ( ( $oCategory = $this->getActCategory() ) ) {
00715 $aAttributes = $oCategory->getAttributes();
00716 if ( count( $aAttributes ) ) {
00717 $this->_aAttributes = $aAttributes;
00718 }
00719 }
00720
00721 return $this->_aAttributes;
00722 }
00723
00729 public function getArticleList()
00730 {
00731 if ( $this->_aArticleList === null ) {
00732 if ( ( $oCategory = $this->getActCategory() ) ) {
00733 $aArticleList = $this->_loadArticles( $oCategory );
00734 if ( count( $aArticleList ) ) {
00735 $this->_aArticleList = $aArticleList;
00736 }
00737 }
00738 }
00739
00740 return $this->_aArticleList;
00741 }
00742
00748 public function getArticleCount()
00749 {
00750 return $this->_iAllArtCnt;
00751 }
00752
00758 public function getSimilarRecommLists()
00759 {
00760 if (!$this->getViewConfig()->getShowListmania()) {
00761 return false;
00762 }
00763
00764 if ( $this->_oRecommList === null ) {
00765 $this->_oRecommList = false;
00766 if ( $aCatArtList = $this->getArticleList() ) {
00767 $oRecommList = oxNew('oxrecommlist');
00768 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00769 }
00770 }
00771 return $this->_oRecommList;
00772 }
00773
00779 public function getCatTreePath()
00780 {
00781 if ( $this->_sCatTreePath === null ) {
00782 $this->_sCatTreePath = false;
00783
00784 if ( $oCatTree = $this->getCategoryTree() ) {
00785 $this->_sCatTreePath = $oCatTree->getPath();
00786 }
00787 }
00788 return $this->_sCatTreePath;
00789 }
00790
00796 public function getTreePath()
00797 {
00798 if ( $oCatTree = $this->getCategoryTree() ) {
00799 return $oCatTree->getPath();
00800 }
00801 }
00802
00808 public function getBreadCrumb()
00809 {
00810 $aPaths = array();
00811
00812 if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00813 $aPath = array();
00814 $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxLang::getInstance()->getBaseLanguage(), false );
00815 $aPath['link'] = $this->getLink();
00816
00817 $aPaths[] = $aPath;
00818
00819 return $aPaths;
00820 }
00821
00822 if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00823 foreach ( $oCatPath as $oCat ) {
00824 $aCatPath = array();
00825
00826 $aCatPath['link'] = $oCat->getLink();
00827 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00828
00829 $aPaths[] = $aCatPath;
00830 }
00831 }
00832
00833 return $aPaths;
00834 }
00835
00842 public function hasVisibleSubCats()
00843 {
00844 if ( $this->_blHasVisibleSubCats === null ) {
00845 $this->_blHasVisibleSubCats = false;
00846 if ( $oClickCat = $this->getActCategory() ) {
00847 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00848 }
00849 }
00850 return $this->_blHasVisibleSubCats;
00851 }
00852
00858 public function getSubCatList()
00859 {
00860 if ( $this->_aSubCatList === null ) {
00861 $this->_aSubCatList = array();
00862 if ( $oClickCat = $this->getActCategory() ) {
00863 $this->_aSubCatList = $oClickCat->getSubCats();
00864 }
00865 }
00866
00867 return $this->_aSubCatList;
00868 }
00869
00875 public function getPageNavigation()
00876 {
00877 if ( $this->_oPageNavigation === null ) {
00878 $this->_oPageNavigation = $this->generatePageNavigation();
00879 }
00880 return $this->_oPageNavigation;
00881 }
00882
00888 public function getTitle()
00889 {
00890 if ( $this->_sCatTitle === null ) {
00891 $this->_sCatTitle = false;
00892 if ( ( $oCategory = $this->getActCategory() ) ) {
00893 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00894 }
00895 }
00896 return $this->_sCatTitle;
00897 }
00898
00904 public function getTop5ArticleList()
00905 {
00906 if ( $this->_aTop5ArticleList === null ) {
00907 $this->_aTop5ArticleList = false;
00908 $myConfig = $this->getConfig();
00909 if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00910
00911 $oArtList = oxNew( 'oxarticlelist' );
00912 $oArtList->loadTop5Articles();
00913 if ( $oArtList->count() ) {
00914 $this->_aTop5ArticleList = $oArtList;
00915 }
00916 }
00917 }
00918 return $this->_aTop5ArticleList;
00919 }
00920
00926 public function getBargainArticleList()
00927 {
00928 if ( $this->_aBargainArticleList === null ) {
00929 $this->_aBargainArticleList = array();
00930 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00931 $oArtList = oxNew( 'oxarticlelist' );
00932 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00933 if ( $oArtList->count() ) {
00934 $this->_aBargainArticleList = $oArtList;
00935 }
00936 }
00937 }
00938 return $this->_aBargainArticleList;
00939 }
00940
00946 public function getActiveCategory()
00947 {
00948 return $this->getActCategory();
00949 }
00950
00956 public function getCanonicalUrl()
00957 {
00958 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00959 $oUtils = oxUtilsUrl::getInstance();
00960 if ( oxUtils::getInstance()->seoIsActive() ) {
00961 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00962 } else {
00963 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00964 }
00965 return $sUrl;
00966 }
00967 }
00968
00974 public function canSelectDisplayType()
00975 {
00976 return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00977 }
00978
00984 public function getPageCount()
00985 {
00986 return $this->_iCntPages;
00987 }
00988
00994 public function isMoreTagsVisible()
00995 {
00996 return true;
00997 }
00998 }