00001 <?php
00002
00009 class aList extends oxUBase
00010 {
00015 protected $_iAllArtCnt = 0;
00016
00021 protected $_iCntPages = null;
00022
00027 protected $_sThisTemplate = 'list.tpl';
00028
00033 protected $_sThisMoreTemplate = 'list_more.tpl';
00034
00039 protected $_sCatPathString = null;
00040
00045 protected $_blShowSorting = true;
00046
00051 protected $_aAttributes = null;
00052
00057 protected $_aCatArtList = null;
00058
00063 protected $_sCatTreeHtmlPath = null;
00064
00069 protected $_blHasVisibleSubCats = null;
00070
00075 protected $_aSubCatList = null;
00076
00081 protected $_oPageNavigation = null;
00082
00087 protected $_blIsCat = null;
00088
00093 protected $_oRecommList = null;
00094
00099 protected $_sCatTitle = null;
00100
00105 protected $_blFixedUrl = null;
00106
00113 public function getViewId()
00114 {
00115 if ( !isset( $this->_sViewId ) ) {
00116 $sCatId = oxConfig::getParameter( 'cnid' );
00117 $iActPage = $this->getActPage();
00118 $iArtPerPage = oxConfig::getParameter( '_artperpage' );
00119 $sParentViewId = parent::getViewId();
00120
00121
00122 $this->_sViewId = md5( $sParentViewId.'|'.$sCatId.'|'.$iActPage.'|'.$iArtPerPage );
00123
00124 }
00125
00126 return $this->_sViewId;
00127 }
00128
00144 public function render()
00145 {
00146 $myConfig = $this->getConfig();
00147
00148 $oCategory = null;
00149 $blContinue = true;
00150 $this->_blIsCat = false;
00151
00152
00153 if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) && $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00154
00155
00156 $this->_sThisTemplate = $this->_sThisMoreTemplate;
00157 $oCategory = oxNew( 'oxcategory' );
00158 $oCategory->oxcategories__oxactive = new oxField( 1, oxField::T_RAW );
00159 $this->setActCategory( $oCategory );
00160 } elseif ( ( $oCategory = $this->getActCategory() ) ) {
00161 $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
00162 $this->_blIsCat = true;
00163 }
00164
00165
00166
00167 if ( !$blContinue || !$oCategory ) {
00168 oxUtils::getInstance()->redirect( $myConfig->getShopURL().'index.php' );
00169 }
00170
00171 $this->_aViewData['filterattributes'] = $this->getAttributes();
00172
00173 $this->_aViewData['articlelist'] = $this->getArticleList();
00174 $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00175
00176
00177 $this->_aViewData['articlebargainlist'] = $this->getBargainArticleList();
00178 $this->_aViewData['aTop5Articles'] = $this->getTop5ArticleList();
00179
00180 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00181
00182 $this->_aViewData['actCatpath'] = $this->getCatTreePath();
00183 $this->_aViewData['template_location'] = $this->getTemplateLocation();
00184
00185
00186 $this->_aViewData['actCategory'] = $this->getActCategory();
00187
00188 $oCat = $this->getActCategory();
00189 if ($oCat && is_array($myConfig->getConfigParam( 'aRssSelected' )) && in_array('oxrss_categories', $myConfig->getConfigParam( 'aRssSelected' ))) {
00190 $oRss = oxNew('oxrssfeed');
00191 $this->addRssFeed($oRss->getCategoryArticlesTitle($oCat), $oRss->getCategoryArticlesUrl($oCat), 'activeCategory');
00192 }
00193
00194
00195 $this->_aViewData['hasVisibleSubCats'] = $this->hasVisibleSubCats();
00196 $this->_aViewData['subcatlist'] = $this->getSubCatList();
00197
00198 $this->_aViewData['title'] = $this->getTitle();
00199
00200 parent::render();
00201
00202
00203 $this->_processListArticles();
00204
00205 return $this->getTemplateName();
00206 }
00207
00214 protected function _processListArticles()
00215 {
00216 if ( $aArtList = $this->getArticleList() ) {
00217 $iLinkType = $this->_getProductLinkType();
00218 foreach ( $aArtList as $oArticle ) {
00219 $oArticle->setLinkType( $iLinkType );
00220 }
00221 }
00222 }
00223
00231 public function noIndex()
00232 {
00233
00234 if ( $this->_getProductLinkType() == OXARTICLE_LINKTYPE_PRICECATEGORY ) {
00235 return $this->_iViewIndexState = VIEW_INDEXSTATE_NOINDEXFOLLOW;
00236 }
00237
00238 return parent::noIndex();
00239 }
00240
00248 protected function _getProductLinkType()
00249 {
00250 $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00251 if ( ( $oCat = $this->getActCategory() ) && $oCat->isPriceCategory() ) {
00252 $iCatType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00253 }
00254 return $iCatType;
00255 }
00256
00265 public function executefilter()
00266 {
00267
00268 $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00269 $sActCat = oxConfig::getParameter( 'cnid' );
00270 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00271 $aSessionFilter[$sActCat] = $aFilter;
00272 oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00273 }
00274
00282 protected function _loadArticles( $oCategory )
00283 {
00284 $myConfig = $this->getConfig();
00285
00286 $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00287 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00288
00289
00290 $oArtList = oxNew( 'oxarticlelist' );
00291 $oArtList->setSqlLimit( $iNrofCatArticles * $this->getActPage(), $iNrofCatArticles );
00292 $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00293
00294 if ( $oCategory->isPriceCategory() ) {
00295 $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00296 $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
00297
00298 $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00299 } else {
00300 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00301
00302 $sActCat = oxConfig::getParameter( 'cnid' );
00303 $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00304 }
00305
00306 $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00307
00308 return $oArtList;
00309 }
00310
00316 protected function _getSeoObjectId()
00317 {
00318 if ( ( $oCategory = $this->getActCategory() ) ) {
00319 return $oCategory->getId();
00320 }
00321 }
00322
00328 protected function _getCatPathString()
00329 {
00330 if ( $this->_sCatPathString === null ) {
00331
00332
00333 $this->_sCatPathString = false;
00334
00335
00336 if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00337
00338 $oStr = getStr();
00339 $this->_sCatPathString = '';
00340 foreach ( $aPath as $oCat ) {
00341 if ( $this->_sCatPathString ) {
00342 $this->_sCatPathString .= ', ';
00343 }
00344 $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00345 }
00346 }
00347 }
00348 return $this->_sCatPathString;
00349 }
00350
00360 protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00361 {
00362
00363 $sDescription = oxLang::getInstance()->translateString( 'INC_HEADER_YOUAREHERE' );
00364
00365
00366 if ( $oCategory = $this->_getCategory() ) {
00367 if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00368 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00369 }
00370
00371
00372 $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00373 }
00374
00375
00376 if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00377 $sDescription .= " {$sSuffix}";
00378 }
00379
00380
00381 $sDescription = getStr()->cleanStr($sDescription);
00382 return trim( strip_tags( getStr()->html_entity_decode( $sDescription ) ) );
00383 }
00384
00397 protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00398 {
00399
00400 $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->oxcategories__oxlongdesc->value ):'';
00401 $aArticleList = $this->getArticleList();
00402 if ( !$sAddText && count($aArticleList)) {
00403 foreach ( $aArticleList as $oArticle ) {
00404 if ( $sAddText ) {
00405 $sAddText .= ', ';
00406 }
00407 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00408 }
00409 }
00410
00411 if ( !$sMeta ) {
00412 $sMeta = trim( $this->_getCatPathString() );
00413 }
00414
00415 if ( $sMeta ) {
00416 $sMeta = "{$sMeta} - {$sAddText}";
00417 } else {
00418 $sMeta = $sAddText;
00419 }
00420
00421 return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00422 }
00423
00432 protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00433 {
00434 $sKeywords = '';
00435 if ( ( $oCategory = $this->getActCategory() ) ) {
00436 $aKeywords = array();
00437
00438 if ( $oCatTree = $this->getCategoryTree() ) {
00439 foreach ( $oCatTree->getPath() as $oCat ) {
00440 $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00441 }
00442 }
00443
00444 if ( count( $aKeywords ) > 0 ) {
00445 $sKeywords = implode( ", ", $aKeywords );
00446 }
00447
00448 $aSubCats = $oCategory->getSubCats();
00449 if ( is_array( $aSubCats ) ) {
00450 foreach ( $aSubCats as $oSubCat ) {
00451 $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00452 }
00453 }
00454 }
00455
00456 $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00457
00458 return trim( $sKeywords );
00459 }
00460
00469 protected function _collectMetaKeyword( $sKeywords )
00470 {
00471 $iMaxTextLenght = 60;
00472 $sText = '';
00473
00474 if ( count( $aArticleList = $this->getArticleList() ) ) {
00475 $oStr = getStr();
00476 foreach ( $aArticleList as $oProduct ) {
00477 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00478
00479
00480 $sDesc = preg_replace( "/\./", " ", $sDesc );
00481
00482 if ( $oStr->strlen( $sDesc ) > $iMaxTextLenght ) {
00483 $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLenght );
00484 $sDesc .= $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00485 }
00486 if ( $sText ) {
00487 $sText .= ', ';
00488 }
00489 $sText .= $sDesc;
00490 }
00491 }
00492
00493 if ( !$sKeywords ) {
00494 $sKeywords = $this->_getCatPathString();
00495 }
00496
00497 if ( $sKeywords ) {
00498 $sText = "{$sKeywords}, {$sText}";
00499 }
00500
00501 return parent::_prepareMetaKeyword( $sText );
00502 }
00503
00511 public function getTemplateName()
00512 {
00513
00514 if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00515 $this->_sThisTemplate = $sTplName;
00516 } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00517 $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00518 }
00519
00520 return $this->_sThisTemplate;
00521 }
00522
00532 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00533 {
00534 if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00535 if ( $iPage ) {
00536 $sUrl = oxSeoEncoderCategory::getInstance()->getCategoryPageUrl( $oCategory, $iPage, $iLang, $this->_isFixedUrl( $oCategory ) );
00537 }
00538 } else {
00539 $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00540 }
00541 return $sUrl;
00542 }
00543
00551 protected function _isFixedUrl( $oCategory )
00552 {
00553 if ( $this->_blFixedUrl == null ) {
00554 $sId = $oCategory->getId();
00555 $iLang = $oCategory->getLanguage();
00556 $sShopId = $this->getConfig()->getShopId();
00557 $this->_blFixedUrl = oxDb::getDb()->getOne( "select oxfixed from oxseo where oxobjectid = '{$sId}' and oxshopid = '{$sShopId}' and oxlang = '{$iLang}' and oxparams = '' " );
00558 }
00559 return $this->_blFixedUrl;
00560 }
00561
00567 protected function _isActCategory()
00568 {
00569 return $this->_blIsCat;
00570 }
00571
00579 protected function _getCategory()
00580 {
00581 return $this->getActCategory();
00582 }
00583
00589 public function generatePageNavigationUrl( )
00590 {
00591 if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00592 return $oCategory->getLink();
00593 } else {
00594 return parent::generatePageNavigationUrl( );
00595 }
00596 }
00597
00605 public function getSorting( $sCnid )
00606 {
00607
00608 $aSorting = parent::getSorting( $sCnid );
00609 $oActCat = $this->getActCategory();
00610 if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00611 $sSortBy = getViewName( 'oxarticles' ).".{$oActCat->oxcategories__oxdefsort->value}";
00612 $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? " desc " : null;
00613
00614 $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00615 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00616 }
00617 return $aSorting;
00618 }
00619
00625 public function getTitleSuffix()
00626 {
00627 if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00628 return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00629 }
00630 }
00631
00640 protected function _getSubject( $iLang )
00641 {
00642 return $this->getActCategory();
00643 }
00644
00651 public function getAttributes()
00652 {
00653
00654 $this->_aAttributes = false;
00655 if ( ( $oCategory = $this->getActCategory() ) ) {
00656 $aAttributes = $oCategory->getAttributes();
00657 if ( count( $aAttributes ) ) {
00658 $this->_aAttributes = $aAttributes;
00659 }
00660 }
00661 return $this->_aAttributes;
00662 }
00663
00669 public function getArticleList()
00670 {
00671 if ( $this->_aArticleList === null ) {
00672 if ( $this->_isActCategory() && ( $oCategory = $this->getActCategory() ) ) {
00673 $aArticleList = $this->_loadArticles( $oCategory );
00674 if ( count( $aArticleList ) ) {
00675 $this->_aArticleList = $aArticleList;
00676 }
00677 }
00678 }
00679 return $this->_aArticleList;
00680 }
00681
00687 public function getSimilarRecommLists()
00688 {
00689 if ( $this->_oRecommList === null ) {
00690 $this->_oRecommList = false;
00691 if ( $aCatArtList = $this->getArticleList() ) {
00692 $oRecommList = oxNew('oxrecommlist');
00693 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00694 }
00695 }
00696 return $this->_oRecommList;
00697 }
00698
00704 public function getCatTreePath()
00705 {
00706 if ( $this->_sCatTreePath === null ) {
00707 $this->_sCatTreePath = false;
00708
00709 if ( $oCatTree = $this->getCategoryTree() ) {
00710 $this->_sCatTreePath = $oCatTree->getPath();
00711 }
00712 }
00713 return $this->_sCatTreePath;
00714 }
00715
00721 public function getTemplateLocation()
00722 {
00723 if ( $this->_sCatTreeHtmlPath === null ) {
00724 $this->_sCatTreeHtmlPath = false;
00725
00726 if ( $oCatTree = $this->getCategoryTree() ) {
00727 $this->_sCatTreeHtmlPath = $oCatTree->getHtmlPath();
00728 }
00729 }
00730 return $this->_sCatTreeHtmlPath;
00731 }
00732
00739 public function hasVisibleSubCats()
00740 {
00741 if ( $this->_blHasVisibleSubCats === null ) {
00742 $this->_blHasVisibleSubCats = false;
00743 if ( $oClickCat = $this->getActCategory() ) {
00744 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00745 }
00746 }
00747 return $this->_blHasVisibleSubCats;
00748 }
00749
00755 public function getSubCatList()
00756 {
00757 if ( $this->_aSubCatList === null ) {
00758 $this->_aSubCatList = array();
00759 if ( $oClickCat = $this->getActCategory() ) {
00760 $this->_aSubCatList = $oClickCat->getSubCats();
00761 }
00762 }
00763 return $this->_aSubCatList;
00764 }
00765
00771 public function getPageNavigation()
00772 {
00773 if ( $this->_oPageNavigation === null ) {
00774 $this->_oPageNavigation = $this->generatePageNavigation();
00775 }
00776 return $this->_oPageNavigation;
00777 }
00778
00784 public function getTitle()
00785 {
00786 if ( $this->_sCatTitle === null ) {
00787 $this->_sCatTitle = false;
00788 if ( ( $oCategory = $this->getActCategory() ) ) {
00789 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00790 }
00791 }
00792 return $this->_sCatTitle;
00793 }
00794
00800 public function getTop5ArticleList()
00801 {
00802 if ( $this->_aTop5ArticleList === null ) {
00803 $this->_aTop5ArticleList = false;
00804 $myConfig = $this->getConfig();
00805 if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00806
00807 $oArtList = oxNew( 'oxarticlelist' );
00808 $oArtList->loadTop5Articles();
00809 if ( $oArtList->count() ) {
00810 $this->_aTop5ArticleList = $oArtList;
00811 }
00812 }
00813 }
00814 return $this->_aTop5ArticleList;
00815 }
00816
00822 public function getBargainArticleList()
00823 {
00824 if ( $this->_aBargainArticleList === null ) {
00825 $this->_aBargainArticleList = array();
00826 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00827 $oArtList = oxNew( 'oxarticlelist' );
00828 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00829 if ( $oArtList->count() ) {
00830 $this->_aBargainArticleList = $oArtList;
00831 }
00832 }
00833 }
00834 return $this->_aBargainArticleList;
00835 }
00836
00842 public function getActiveCategory()
00843 {
00844 return $this->getActCategory();
00845 }
00846
00847 }