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 $_blShowTagCloud = true;
00100
00105 protected $_blBargainAction = false;
00106
00112 protected $_aSimilarRecommListIds = null;
00113
00114
00121 public function getViewId()
00122 {
00123 if ( !isset( $this->_sViewId ) ) {
00124 $sCatId = oxConfig::getParameter( 'cnid' );
00125 $iActPage = $this->getActPage();
00126 $iArtPerPage = oxSession::getVar( '_artperpage' );
00127 $sListDisplayType = oxSession::getVar( 'ldtype' );
00128 $sParentViewId = parent::getViewId();
00129
00130
00131 $this->_sViewId = md5( $sParentViewId.'|'.$sCatId.'|'.$iActPage.'|'.$iArtPerPage.'|'.$sListDisplayType );
00132
00133 }
00134
00135 return $this->_sViewId;
00136 }
00137
00150 public function render()
00151 {
00152 $myConfig = $this->getConfig();
00153
00154 $oCategory = null;
00155 $blContinue = true;
00156 $this->_blIsCat = false;
00157
00158
00159 if ( 'oxmore' == $myConfig->getRequestParameter( 'cnid' ) ) {
00160
00161 $this->_sThisTemplate = $this->_sThisMoreTemplate;
00162 $oCategory = oxNew( 'oxcategory' );
00163 $oCategory->oxcategories__oxactive = new oxField( 1, oxField::T_RAW );
00164 $this->setActiveCategory( $oCategory );
00165
00166 $this->_blShowTagCloud = true;
00167
00168 } elseif ( ( $oCategory = $this->getActiveCategory() ) ) {
00169 $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
00170 $this->_blIsCat = true;
00171 $this->_blBargainAction = true;
00172 }
00173
00174
00175
00176 if ( !$blContinue || !$oCategory ) {
00177 oxRegistry::getUtils()->redirect( $myConfig->getShopURL().'index.php', true, 302 );
00178 }
00179
00180 $oCat = $this->getActiveCategory();
00181 if ($oCat && $myConfig->getConfigParam( 'bl_rssCategories' )) {
00182 $oRss = oxNew('oxrssfeed');
00183 $this->addRssFeed($oRss->getCategoryArticlesTitle($oCat), $oRss->getCategoryArticlesUrl($oCat), 'activeCategory');
00184 }
00185
00186
00187 $this->getArticleList();
00188
00189 if ( $this->_blIsCat ) {
00190 $this->_checkRequestedPage();
00191 }
00192
00193 parent::render();
00194
00195
00196 $this->_processListArticles();
00197
00198 return $this->getTemplateName();
00199 }
00200
00209 protected function _checkRequestedPage()
00210 {
00211 $iPageCnt = $this->getPageCount();
00212
00213 if ( $iPageCnt && ( ( $iPageCnt - 1 ) < $this->getActPage() ) ) {
00214 oxRegistry::getUtils()->redirect( $this->getActiveCategory()->getLink(), false );
00215 }
00216 }
00217
00224 protected function _processListArticles()
00225 {
00226 if ( $aArtList = $this->getArticleList() ) {
00227 $iLinkType = $this->_getProductLinkType();
00228 $sAddDynParams = $this->getAddUrlParams();
00229 $sAddSeoParams = $this->getAddSeoUrlParams();
00230
00231 foreach ( $aArtList as $oArticle ) {
00232 $oArticle->setLinkType( $iLinkType );
00233
00234
00235 if ( $sAddDynParams ) {
00236 $oArticle->appendStdLink( $sAddDynParams );
00237 }
00238
00239
00240 if ( $sAddSeoParams ) {
00241 $oArticle->appendLink( $sAddSeoParams );
00242 }
00243 }
00244 }
00245 }
00246
00247
00253 public function getAddUrlParams()
00254 {
00255 $sParams = parent::getAddUrlParams();
00256 if ( !oxRegistry::getUtils()->seoIsActive() ) {
00257 $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
00258 if ( $iPgNr > 0 ) {
00259 $sParams .= ($sParams?'&':'') . "pgNr={$iPgNr}";
00260 }
00261 }
00262
00263 return $sParams;
00264 }
00265
00271 public function getAddSeoUrlParams()
00272 {
00273 }
00274
00282 protected function _getProductLinkType()
00283 {
00284 $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00285 if ( ( $oCat = $this->getActiveCategory() ) && $oCat->isPriceCategory() ) {
00286 $iCatType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00287 }
00288 return $iCatType;
00289 }
00290
00299 public function executefilter()
00300 {
00301 $iLang = oxRegistry::getLang()->getBaseLanguage();
00302
00303 $aFilter = oxRegistry::getConfig()->getRequestParameter( 'attrfilter', true );
00304 $sActCat = oxRegistry::getConfig()->getRequestParameter( 'cnid' );
00305
00306 if ( !empty( $aFilter ) ) {
00307 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00308
00309
00310 $aSessionFilter[$sActCat] = null;
00311 $aSessionFilter[$sActCat][$iLang] = $aFilter;
00312 oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00313 }
00314 }
00315
00323 protected function _loadArticles( $oCategory )
00324 {
00325 $myConfig = $this->getConfig();
00326
00327 $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00328 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00329
00330
00331 $oArtList = oxNew( 'oxarticlelist' );
00332 $oArtList->setSqlLimit( $iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles );
00333 $oArtList->setCustomSorting( $this->getSortingSql( $this->getSortIdent() ) );
00334
00335 if ( $oCategory->isPriceCategory() ) {
00336 $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00337 $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
00338
00339 $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00340 } else {
00341 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00342
00343 $sActCat = oxConfig::getParameter( 'cnid' );
00344 $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00345 }
00346
00347 $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00348
00349 return $oArtList;
00350 }
00351
00357 public function getActPage()
00358 {
00359 return $this->_getRequestPageNr();
00360 }
00361
00370 protected function _getRequestPageNr()
00371 {
00372 return parent::getActPage();
00373 }
00374
00380 protected function _getSeoObjectId()
00381 {
00382 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00383 return $oCategory->getId();
00384 }
00385 }
00386
00392 protected function _getCatPathString()
00393 {
00394 if ( $this->_sCatPathString === null ) {
00395
00396
00397 $this->_sCatPathString = false;
00398
00399
00400 if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00401
00402 $oStr = getStr();
00403 $this->_sCatPathString = '';
00404 foreach ( $aPath as $oCat ) {
00405 if ( $this->_sCatPathString ) {
00406 $this->_sCatPathString .= ', ';
00407 }
00408 $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00409 }
00410 }
00411 }
00412 return $this->_sCatPathString;
00413 }
00414
00424 protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00425 {
00426 $sDescription = '';
00427
00428 if ( $oCategory = $this->getActiveCategory() ) {
00429 if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00430 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00431 }
00432
00433
00434 $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00435 }
00436
00437
00438
00439 if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value ) ) {
00440 $sDescription .= " {$sSuffix}";
00441 }
00442
00443
00444 $sDescription = getStr()->html_entity_decode( $sDescription );
00445 $sDescription = getStr()->strip_tags( $sDescription );
00446 $sDescription = getStr()->cleanStr( $sDescription );
00447 $sDescription = getStr()->htmlspecialchars( $sDescription );
00448 return trim( $sDescription );
00449 }
00450
00456 public function getMetaDescription()
00457 {
00458 $sMeta = parent::getMetaDescription();
00459
00460 if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00461 if ( $sMeta ) {
00462 $sMeta .= ", ";
00463 }
00464 $sMeta .= $sTitlePageSuffix;
00465 }
00466
00467 return $sMeta;
00468 }
00469
00482 protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00483 {
00484
00485 $oCategory = $this->getActiveCategory();
00486
00487 $sAddText = ( ( $oCategory instanceof oxCategory ) ) ? trim( $oCategory->getLongDesc() ) : '';
00488
00489 $aArticleList = $this->getArticleList();
00490 if ( !$sAddText && count($aArticleList)) {
00491 foreach ( $aArticleList as $oArticle ) {
00492 if ( $sAddText ) {
00493 $sAddText .= ', ';
00494 }
00495 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00496 }
00497 }
00498
00499 if ( !$sMeta ) {
00500 $sMeta = trim( $this->_getCatPathString() );
00501 }
00502
00503 if ( $sMeta ) {
00504 $sMeta = "{$sMeta} - {$sAddText}";
00505 } else {
00506 $sMeta = $sAddText;
00507 }
00508
00509 return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00510 }
00511
00520 protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00521 {
00522 $sKeywords = '';
00523 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00524 $aKeywords = array();
00525
00526 if ( $oCatTree = $this->getCategoryTree() ) {
00527 foreach ( $oCatTree->getPath() as $oCat ) {
00528 $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00529 }
00530 }
00531
00532 if ( count( $aKeywords ) > 0 ) {
00533 $sKeywords = implode( ", ", $aKeywords );
00534 }
00535
00536 $aSubCats = $oCategory->getSubCats();
00537 if ( is_array( $aSubCats ) ) {
00538 foreach ( $aSubCats as $oSubCat ) {
00539 $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00540 }
00541 }
00542 }
00543
00544 $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00545
00546 return trim( $sKeywords );
00547 }
00548
00557 protected function _collectMetaKeyword( $sKeywords )
00558 {
00559 $iMaxTextLength = 60;
00560 $sText = '';
00561
00562 if ( count( $aArticleList = $this->getArticleList() ) ) {
00563 $oStr = getStr();
00564 foreach ( $aArticleList as $oProduct ) {
00565 $sDesc = $oStr->strip_tags( trim( $oStr->strtolower( $oProduct->getLongDescription()->value ) ) );
00566
00567
00568 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00569
00570 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00571 $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00572 $sDesc = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00573 }
00574 if ( $sText ) {
00575 $sText .= ', ';
00576 }
00577 $sText .= $sDesc;
00578 }
00579 }
00580
00581 if ( !$sKeywords ) {
00582 $sKeywords = $this->_getCatPathString();
00583 }
00584
00585 if ( $sKeywords ) {
00586 $sText = "{$sKeywords}, {$sText}";
00587 }
00588
00589 return parent::_prepareMetaKeyword( $sText );
00590 }
00591
00599 public function getTemplateName()
00600 {
00601
00602 if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00603 $this->_sThisTemplate = 'custom/'.$sTplName;
00604 } elseif ( ( $oCategory = $this->getActiveCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00605 $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00606 }
00607
00608 return $this->_sThisTemplate;
00609 }
00610
00620 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00621 {
00622 if ( oxRegistry::getUtils()->seoIsActive() && ( $oCategory = $this->getActiveCategory() ) ) {
00623 if ( $iPage ) {
00624
00625 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00626 }
00627 } else {
00628 $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00629 }
00630 return $sUrl;
00631 }
00632
00638 protected function _isActCategory()
00639 {
00640 return $this->_blIsCat;
00641 }
00642
00648 public function generatePageNavigationUrl( )
00649 {
00650 if ( ( oxRegistry::getUtils()->seoIsActive() && ( $oCategory = $this->getActiveCategory() ) ) ) {
00651 return $oCategory->getLink();
00652 }
00653 return parent::generatePageNavigationUrl( );
00654 }
00655
00665 public function getSorting( $sCnid )
00666 {
00667 $aSorting = parent::getSorting( $sCnid );
00668 return $aSorting;
00669 }
00670
00676 public function getDefaultSorting()
00677 {
00678 $aSorting = parent::getDefaultSorting();
00679
00680 $oCategory = $this->getActiveCategory();
00681 if ( $oCategory && $oCategory instanceof oxCategory ) {
00682 if ( $sDefaultSorting = $oCategory->getDefaultSorting() ) {
00683 $sArticleTable = getViewName( 'oxarticles' );
00684 $sSortBy = $sArticleTable.'.'.$sDefaultSorting;
00685 $sSortDir = ( $oCategory->getDefaultSortingMode() ) ? "desc" : "asc";
00686 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00687 }
00688 }
00689
00690 return $aSorting;
00691 }
00692
00693
00699 public function getTitleSuffix()
00700 {
00701 if ( $this->getActiveCategory()->oxcategories__oxshowsuffix->value ) {
00702 return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00703 }
00704 }
00705
00711 public function getTitlePageSuffix()
00712 {
00713 if ( ( $iPage = $this->getActPage() ) ) {
00714 return oxRegistry::getLang()->translateString( 'PAGE' )." ". ( $iPage + 1 );
00715 }
00716 }
00717
00726 protected function _getSubject( $iLang )
00727 {
00728 return $this->getActiveCategory();
00729 }
00730
00737 public function getAttributes()
00738 {
00739 $this->_aAttributes = false;
00740
00741 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00742 $aAttributes = $oCategory->getAttributes();
00743 if ( count( $aAttributes ) ) {
00744 $this->_aAttributes = $aAttributes;
00745 }
00746 }
00747
00748 return $this->_aAttributes;
00749 }
00750
00756 public function getArticleList()
00757 {
00758 if ( $this->_aArticleList === null ) {
00759 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00760 $aArticleList = $this->_loadArticles( $oCategory );
00761 if ( count( $aArticleList ) ) {
00762 $this->_aArticleList = $aArticleList;
00763 }
00764 }
00765 }
00766
00767 return $this->_aArticleList;
00768 }
00769
00775 public function getArticleCount()
00776 {
00777 return $this->_iAllArtCnt;
00778 }
00779
00785 public function getSimilarRecommListIds()
00786 {
00787 if ( $this->_aSimilarRecommListIds === null ) {
00788 $this->_aSimilarRecommListIds = false;
00789
00790 if ( $aCatArtList = $this->getArticleList() ) {
00791 $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
00792 }
00793 }
00794 return $this->_aSimilarRecommListIds;
00795 }
00796
00802 public function getCatTreePath()
00803 {
00804 if ( $this->_sCatTreePath === null ) {
00805 $this->_sCatTreePath = false;
00806
00807 if ( $oCatTree = $this->getCategoryTree() ) {
00808 $this->_sCatTreePath = $oCatTree->getPath();
00809 }
00810 }
00811 return $this->_sCatTreePath;
00812 }
00813
00819 public function getTreePath()
00820 {
00821 if ( $oCatTree = $this->getCategoryTree() ) {
00822 return $oCatTree->getPath();
00823 }
00824 }
00825
00831 public function getBreadCrumb()
00832 {
00833 $aPaths = array();
00834
00835 if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00836 $aPath = array();
00837 $aPath['title'] = oxRegistry::getLang()->translateString( 'CATEGORY_OVERVIEW', oxRegistry::getLang()->getBaseLanguage(), false );
00838 $aPath['link'] = $this->getLink();
00839
00840 $aPaths[] = $aPath;
00841
00842 return $aPaths;
00843 }
00844
00845 if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00846 foreach ( $oCatPath as $oCat ) {
00847 $aCatPath = array();
00848
00849 $aCatPath['link'] = $oCat->getLink();
00850 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00851
00852 $aPaths[] = $aCatPath;
00853 }
00854 }
00855
00856 return $aPaths;
00857 }
00858
00865 public function hasVisibleSubCats()
00866 {
00867 if ( $this->_blHasVisibleSubCats === null ) {
00868 $this->_blHasVisibleSubCats = false;
00869 if ( $oClickCat = $this->getActiveCategory() ) {
00870 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00871 }
00872 }
00873 return $this->_blHasVisibleSubCats;
00874 }
00875
00881 public function getSubCatList()
00882 {
00883 if ( $this->_aSubCatList === null ) {
00884 $this->_aSubCatList = array();
00885 if ( $oClickCat = $this->getActiveCategory() ) {
00886 $this->_aSubCatList = $oClickCat->getSubCats();
00887 }
00888 }
00889
00890 return $this->_aSubCatList;
00891 }
00892
00898 public function getPageNavigation()
00899 {
00900 if ( $this->_oPageNavigation === null ) {
00901 $this->_oPageNavigation = $this->generatePageNavigation();
00902 }
00903 return $this->_oPageNavigation;
00904 }
00905
00911 public function getTitle()
00912 {
00913 if ( $this->_sCatTitle === null ) {
00914 $this->_sCatTitle = false;
00915 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00916 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00917 }
00918 }
00919 return $this->_sCatTitle;
00920 }
00921
00927 public function getBargainArticleList()
00928 {
00929 if ( $this->_aBargainArticleList === null ) {
00930 $this->_aBargainArticleList = array();
00931 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00932 $oArtList = oxNew( 'oxarticlelist' );
00933 $oArtList->loadActionArticles( 'OXBARGAIN' );
00934 if ( $oArtList->count() ) {
00935 $this->_aBargainArticleList = $oArtList;
00936 }
00937 }
00938 }
00939 return $this->_aBargainArticleList;
00940 }
00941
00947 public function getActiveCategory()
00948 {
00949 if ( $this->_oActCategory === null ) {
00950 $this->_oActCategory = false;
00951 $oCategory = oxNew( 'oxCategory' );
00952 if ( $oCategory->load( $this->getCategoryId() ) ) {
00953 $this->_oActCategory = $oCategory;
00954 }
00955 }
00956 return $this->_oActCategory;
00957 }
00958
00964 public function getCanonicalUrl()
00965 {
00966 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00967 $oUtils = oxRegistry::get("oxUtilsUrl");
00968 if ( oxRegistry::getUtils()->seoIsActive() ) {
00969 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00970 } else {
00971 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00972 }
00973 return $sUrl;
00974 }
00975 }
00976
00982 public function canSelectDisplayType()
00983 {
00984 return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00985 }
00986
00992 public function getPageCount()
00993 {
00994 return $this->_iCntPages;
00995 }
00996 }