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 $sDescription = strip_tags( getStr()->html_entity_decode( $sDescription ) );
00442 $sDescription = getStr()->htmlspecialchars( $sDescription );
00443 return trim( $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
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->getLongDescription()->value ) ) );
00558
00559
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
00594 if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00595 $this->_sThisTemplate = 'custom/'.$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
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
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 ( ( $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 getArticleCount()
00751 {
00752 return $this->_iAllArtCnt;
00753 }
00754
00760 public function getSimilarRecommLists()
00761 {
00762 if (!$this->getViewConfig()->getShowListmania()) {
00763 return false;
00764 }
00765
00766 if ( $this->_oRecommList === null ) {
00767 $this->_oRecommList = false;
00768 if ( $aCatArtList = $this->getArticleList() ) {
00769 $oRecommList = oxNew('oxrecommlist');
00770 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00771 }
00772 }
00773 return $this->_oRecommList;
00774 }
00775
00781 public function getCatTreePath()
00782 {
00783 if ( $this->_sCatTreePath === null ) {
00784 $this->_sCatTreePath = false;
00785
00786 if ( $oCatTree = $this->getCategoryTree() ) {
00787 $this->_sCatTreePath = $oCatTree->getPath();
00788 }
00789 }
00790 return $this->_sCatTreePath;
00791 }
00792
00798 public function getTreePath()
00799 {
00800 if ( $oCatTree = $this->getCategoryTree() ) {
00801 return $oCatTree->getPath();
00802 }
00803 }
00804
00810 public function getBreadCrumb()
00811 {
00812 $aPaths = array();
00813
00814 if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00815 $aPath = array();
00816 $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxLang::getInstance()->getBaseLanguage(), false );
00817 $aPath['link'] = $this->getLink();
00818
00819 $aPaths[] = $aPath;
00820
00821 return $aPaths;
00822 }
00823
00824 if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00825 foreach ( $oCatPath as $oCat ) {
00826 $aCatPath = array();
00827
00828 $aCatPath['link'] = $oCat->getLink();
00829 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00830
00831 $aPaths[] = $aCatPath;
00832 }
00833 }
00834
00835 return $aPaths;
00836 }
00837
00844 public function hasVisibleSubCats()
00845 {
00846 if ( $this->_blHasVisibleSubCats === null ) {
00847 $this->_blHasVisibleSubCats = false;
00848 if ( $oClickCat = $this->getActCategory() ) {
00849 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00850 }
00851 }
00852 return $this->_blHasVisibleSubCats;
00853 }
00854
00860 public function getSubCatList()
00861 {
00862 if ( $this->_aSubCatList === null ) {
00863 $this->_aSubCatList = array();
00864 if ( $oClickCat = $this->getActCategory() ) {
00865 $this->_aSubCatList = $oClickCat->getSubCats();
00866 }
00867 }
00868
00869 return $this->_aSubCatList;
00870 }
00871
00877 public function getPageNavigation()
00878 {
00879 if ( $this->_oPageNavigation === null ) {
00880 $this->_oPageNavigation = $this->generatePageNavigation();
00881 }
00882 return $this->_oPageNavigation;
00883 }
00884
00890 public function getTitle()
00891 {
00892 if ( $this->_sCatTitle === null ) {
00893 $this->_sCatTitle = false;
00894 if ( ( $oCategory = $this->getActCategory() ) ) {
00895 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00896 }
00897 }
00898 return $this->_sCatTitle;
00899 }
00900
00906 public function getTop5ArticleList()
00907 {
00908 if ( $this->_aTop5ArticleList === null ) {
00909 $this->_aTop5ArticleList = false;
00910 $myConfig = $this->getConfig();
00911 if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00912
00913 $oArtList = oxNew( 'oxarticlelist' );
00914 $oArtList->loadTop5Articles();
00915 if ( $oArtList->count() ) {
00916 $this->_aTop5ArticleList = $oArtList;
00917 }
00918 }
00919 }
00920 return $this->_aTop5ArticleList;
00921 }
00922
00928 public function getBargainArticleList()
00929 {
00930 if ( $this->_aBargainArticleList === null ) {
00931 $this->_aBargainArticleList = array();
00932 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00933 $oArtList = oxNew( 'oxarticlelist' );
00934 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00935 if ( $oArtList->count() ) {
00936 $this->_aBargainArticleList = $oArtList;
00937 }
00938 }
00939 }
00940 return $this->_aBargainArticleList;
00941 }
00942
00948 public function getActiveCategory()
00949 {
00950 return $this->getActCategory();
00951 }
00952
00958 public function getCanonicalUrl()
00959 {
00960 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00961 $oUtils = oxUtilsUrl::getInstance();
00962 if ( oxUtils::getInstance()->seoIsActive() ) {
00963 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00964 } else {
00965 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00966 }
00967 return $sUrl;
00968 }
00969 }
00970
00976 public function canSelectDisplayType()
00977 {
00978 return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00979 }
00980
00986 public function getPageCount()
00987 {
00988 return $this->_iCntPages;
00989 }
00990
00996 public function isMoreTagsVisible()
00997 {
00998 return true;
00999 }
01000 }