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 $oDb = oxDb::getDb();
00555 $sIdQuoted = $oDb->quote( $oCategory->getId() );
00556 $iLang = $oCategory->getLanguage();
00557 $sShopId = $this->getConfig()->getShopId();
00558 $this->_blFixedUrl = $oDb->getOne( "select oxfixed from oxseo where oxobjectid = {$sIdQuoted} and oxshopid = '{$sShopId}' and oxlang = '{$iLang}' and oxparams = '' " );
00559 }
00560 return $this->_blFixedUrl;
00561 }
00562
00568 protected function _isActCategory()
00569 {
00570 return $this->_blIsCat;
00571 }
00572
00580 protected function _getCategory()
00581 {
00582 return $this->getActCategory();
00583 }
00584
00590 public function generatePageNavigationUrl( )
00591 {
00592 if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00593 return $oCategory->getLink();
00594 } else {
00595 return parent::generatePageNavigationUrl( );
00596 }
00597 }
00598
00606 public function getSorting( $sCnid )
00607 {
00608
00609 $aSorting = parent::getSorting( $sCnid );
00610 $oActCat = $this->getActCategory();
00611 if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00612 $sSortBy = getViewName( 'oxarticles' ).".{$oActCat->oxcategories__oxdefsort->value}";
00613 $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? " desc " : null;
00614
00615 $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00616 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00617 }
00618 return $aSorting;
00619 }
00620
00626 public function getTitleSuffix()
00627 {
00628 if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00629 return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00630 }
00631 }
00632
00641 protected function _getSubject( $iLang )
00642 {
00643 return $this->getActCategory();
00644 }
00645
00652 public function getAttributes()
00653 {
00654
00655 $this->_aAttributes = false;
00656 if ( ( $oCategory = $this->getActCategory() ) ) {
00657 $aAttributes = $oCategory->getAttributes();
00658 if ( count( $aAttributes ) ) {
00659 $this->_aAttributes = $aAttributes;
00660 }
00661 }
00662 return $this->_aAttributes;
00663 }
00664
00670 public function getArticleList()
00671 {
00672 if ( $this->_aArticleList === null ) {
00673 if ( $this->_isActCategory() && ( $oCategory = $this->getActCategory() ) ) {
00674 $aArticleList = $this->_loadArticles( $oCategory );
00675 if ( count( $aArticleList ) ) {
00676 $this->_aArticleList = $aArticleList;
00677 }
00678 }
00679 }
00680 return $this->_aArticleList;
00681 }
00682
00688 public function getSimilarRecommLists()
00689 {
00690 if ( $this->_oRecommList === null ) {
00691 $this->_oRecommList = false;
00692 if ( $aCatArtList = $this->getArticleList() ) {
00693 $oRecommList = oxNew('oxrecommlist');
00694 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00695 }
00696 }
00697 return $this->_oRecommList;
00698 }
00699
00705 public function getCatTreePath()
00706 {
00707 if ( $this->_sCatTreePath === null ) {
00708 $this->_sCatTreePath = false;
00709
00710 if ( $oCatTree = $this->getCategoryTree() ) {
00711 $this->_sCatTreePath = $oCatTree->getPath();
00712 }
00713 }
00714 return $this->_sCatTreePath;
00715 }
00716
00722 public function getTemplateLocation()
00723 {
00724 if ( $this->_sCatTreeHtmlPath === null ) {
00725 $this->_sCatTreeHtmlPath = false;
00726
00727 if ( $oCatTree = $this->getCategoryTree() ) {
00728 $this->_sCatTreeHtmlPath = $oCatTree->getHtmlPath();
00729 }
00730 }
00731 return $this->_sCatTreeHtmlPath;
00732 }
00733
00740 public function hasVisibleSubCats()
00741 {
00742 if ( $this->_blHasVisibleSubCats === null ) {
00743 $this->_blHasVisibleSubCats = false;
00744 if ( $oClickCat = $this->getActCategory() ) {
00745 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00746 }
00747 }
00748 return $this->_blHasVisibleSubCats;
00749 }
00750
00756 public function getSubCatList()
00757 {
00758 if ( $this->_aSubCatList === null ) {
00759 $this->_aSubCatList = array();
00760 if ( $oClickCat = $this->getActCategory() ) {
00761 $this->_aSubCatList = $oClickCat->getSubCats();
00762 }
00763 }
00764 return $this->_aSubCatList;
00765 }
00766
00772 public function getPageNavigation()
00773 {
00774 if ( $this->_oPageNavigation === null ) {
00775 $this->_oPageNavigation = $this->generatePageNavigation();
00776 }
00777 return $this->_oPageNavigation;
00778 }
00779
00785 public function getTitle()
00786 {
00787 if ( $this->_sCatTitle === null ) {
00788 $this->_sCatTitle = false;
00789 if ( ( $oCategory = $this->getActCategory() ) ) {
00790 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00791 }
00792 }
00793 return $this->_sCatTitle;
00794 }
00795
00801 public function getTop5ArticleList()
00802 {
00803 if ( $this->_aTop5ArticleList === null ) {
00804 $this->_aTop5ArticleList = false;
00805 $myConfig = $this->getConfig();
00806 if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00807
00808 $oArtList = oxNew( 'oxarticlelist' );
00809 $oArtList->loadTop5Articles();
00810 if ( $oArtList->count() ) {
00811 $this->_aTop5ArticleList = $oArtList;
00812 }
00813 }
00814 }
00815 return $this->_aTop5ArticleList;
00816 }
00817
00823 public function getBargainArticleList()
00824 {
00825 if ( $this->_aBargainArticleList === null ) {
00826 $this->_aBargainArticleList = array();
00827 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00828 $oArtList = oxNew( 'oxarticlelist' );
00829 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00830 if ( $oArtList->count() ) {
00831 $this->_aBargainArticleList = $oArtList;
00832 }
00833 }
00834 }
00835 return $this->_aBargainArticleList;
00836 }
00837
00843 public function getActiveCategory()
00844 {
00845 return $this->getActCategory();
00846 }
00847
00848 }