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 protected function _getProductLinkType()
00232 {
00233 $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00234 if ( ( $oCat = $this->getActCategory() ) && $oCat->isPriceCategory() ) {
00235 $iCatType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00236 }
00237 return $iCatType;
00238 }
00239
00248 public function executefilter()
00249 {
00250
00251 $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00252 $sActCat = oxConfig::getParameter( 'cnid' );
00253 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00254 $aSessionFilter[$sActCat] = $aFilter;
00255 oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00256 }
00257
00265 protected function _loadArticles( $oCategory )
00266 {
00267 $myConfig = $this->getConfig();
00268
00269 $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00270 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00271
00272
00273 $oArtList = oxNew( 'oxarticlelist' );
00274 $oArtList->setSqlLimit( $iNrofCatArticles * $this->getActPage(), $iNrofCatArticles );
00275 $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00276
00277 if ( $oCategory->isPriceCategory() ) {
00278 $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00279 $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
00280
00281 $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00282 } else {
00283 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00284
00285 $sActCat = oxConfig::getParameter( 'cnid' );
00286 $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00287 }
00288
00289 $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00290
00291 return $oArtList;
00292 }
00293
00299 protected function _getSeoObjectId()
00300 {
00301 if ( ( $oCategory = $this->getActCategory() ) ) {
00302 return $oCategory->getId();
00303 }
00304 }
00305
00311 protected function _getCatPathString()
00312 {
00313 if ( $this->_sCatPathString === null ) {
00314
00315
00316 $this->_sCatPathString = false;
00317
00318
00319 if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00320
00321 $oStr = getStr();
00322 $this->_sCatPathString = '';
00323 foreach ( $aPath as $oCat ) {
00324 if ( $this->_sCatPathString ) {
00325 $this->_sCatPathString .= ', ';
00326 }
00327 $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00328 }
00329 }
00330 }
00331 return $this->_sCatPathString;
00332 }
00333
00343 protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00344 {
00345
00346 $sDescription = oxLang::getInstance()->translateString( 'INC_HEADER_YOUAREHERE' );
00347
00348
00349 if ( $oCategory = $this->_getCategory() ) {
00350 if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00351 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00352 }
00353
00354
00355 $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00356 }
00357
00358
00359 if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00360 $sDescription .= " {$sSuffix}";
00361 }
00362
00363
00364 $sDescription = getStr()->cleanStr($sDescription);
00365 return trim( strip_tags( getStr()->html_entity_decode( $sDescription ) ) );
00366 }
00367
00373 public function getMetaDescription()
00374 {
00375 $sMeta = parent::getMetaDescription();
00376
00377 if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00378 if ( $sMeta ) {
00379 $sMeta .= ", ";
00380 }
00381 $sMeta .= $sTitlePageSuffix;
00382 }
00383
00384 return $sMeta;
00385 }
00386
00399 protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00400 {
00401
00402 $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->oxcategories__oxlongdesc->value ):'';
00403 $aArticleList = $this->getArticleList();
00404 if ( !$sAddText && count($aArticleList)) {
00405 foreach ( $aArticleList as $oArticle ) {
00406 if ( $sAddText ) {
00407 $sAddText .= ', ';
00408 }
00409 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00410 }
00411 }
00412
00413 if ( !$sMeta ) {
00414 $sMeta = trim( $this->_getCatPathString() );
00415 }
00416
00417 if ( $sMeta ) {
00418 $sMeta = "{$sMeta} - {$sAddText}";
00419 } else {
00420 $sMeta = $sAddText;
00421 }
00422
00423 return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00424 }
00425
00434 protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00435 {
00436 $sKeywords = '';
00437 if ( ( $oCategory = $this->getActCategory() ) ) {
00438 $aKeywords = array();
00439
00440 if ( $oCatTree = $this->getCategoryTree() ) {
00441 foreach ( $oCatTree->getPath() as $oCat ) {
00442 $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00443 }
00444 }
00445
00446 if ( count( $aKeywords ) > 0 ) {
00447 $sKeywords = implode( ", ", $aKeywords );
00448 }
00449
00450 $aSubCats = $oCategory->getSubCats();
00451 if ( is_array( $aSubCats ) ) {
00452 foreach ( $aSubCats as $oSubCat ) {
00453 $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00454 }
00455 }
00456 }
00457
00458 $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00459
00460 return trim( $sKeywords );
00461 }
00462
00471 protected function _collectMetaKeyword( $sKeywords )
00472 {
00473 $iMaxTextLength = 60;
00474 $sText = '';
00475
00476 if ( count( $aArticleList = $this->getArticleList() ) ) {
00477 $oStr = getStr();
00478 foreach ( $aArticleList as $oProduct ) {
00479 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00480
00481
00482 $sDesc = preg_replace( "/\./", " ", $sDesc );
00483
00484 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00485 $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00486 $sDesc = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00487 }
00488 if ( $sText ) {
00489 $sText .= ', ';
00490 }
00491 $sText .= $sDesc;
00492 }
00493 }
00494
00495 if ( !$sKeywords ) {
00496 $sKeywords = $this->_getCatPathString();
00497 }
00498
00499 if ( $sKeywords ) {
00500 $sText = "{$sKeywords}, {$sText}";
00501 }
00502
00503 return parent::_prepareMetaKeyword( $sText );
00504 }
00505
00513 public function getTemplateName()
00514 {
00515
00516 if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00517 $this->_sThisTemplate = $sTplName;
00518 } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00519 $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00520 }
00521
00522 return $this->_sThisTemplate;
00523 }
00524
00534 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00535 {
00536 if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00537 if ( $iPage ) {
00538 $sUrl = oxSeoEncoderCategory::getInstance()->getCategoryPageUrl( $oCategory, $iPage, $iLang, $this->_isFixedUrl( $oCategory ) );
00539 }
00540 } else {
00541 $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00542 }
00543 return $sUrl;
00544 }
00545
00553 protected function _isFixedUrl( $oCategory )
00554 {
00555 if ( $this->_blFixedUrl == null ) {
00556 $oDb = oxDb::getDb();
00557 $sIdQuoted = $oDb->quote( $oCategory->getId() );
00558 $iLang = $oCategory->getLanguage();
00559 $sShopId = $this->getConfig()->getShopId();
00560 $this->_blFixedUrl = $oDb->getOne( "select oxfixed from oxseo where oxobjectid = {$sIdQuoted} and oxshopid = '{$sShopId}' and oxlang = '{$iLang}' and oxparams = '' " );
00561 }
00562 return $this->_blFixedUrl;
00563 }
00564
00570 protected function _isActCategory()
00571 {
00572 return $this->_blIsCat;
00573 }
00574
00582 protected function _getCategory()
00583 {
00584 return $this->getActCategory();
00585 }
00586
00592 public function generatePageNavigationUrl( )
00593 {
00594 if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00595 return $oCategory->getLink();
00596 } else {
00597 return parent::generatePageNavigationUrl( );
00598 }
00599 }
00600
00608 public function getSorting( $sCnid )
00609 {
00610
00611 $aSorting = parent::getSorting( $sCnid );
00612 $oActCat = $this->getActCategory();
00613 if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00614 $sSortBy = getViewName( 'oxarticles' ).".{$oActCat->oxcategories__oxdefsort->value}";
00615 $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? " desc " : null;
00616
00617 $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00618 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00619 }
00620 return $aSorting;
00621 }
00622
00628 public function getTitleSuffix()
00629 {
00630 if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00631 return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00632 }
00633 }
00634
00640 public function getTitlePageSuffix()
00641 {
00642 if ( ( $iPage = $this->getActPage() ) ) {
00643 return oxLang::getInstance()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00644 }
00645 }
00646
00655 protected function _getSubject( $iLang )
00656 {
00657 return $this->getActCategory();
00658 }
00659
00666 public function getAttributes()
00667 {
00668
00669 $this->_aAttributes = false;
00670 if ( ( $oCategory = $this->getActCategory() ) ) {
00671 $aAttributes = $oCategory->getAttributes();
00672 if ( count( $aAttributes ) ) {
00673 $this->_aAttributes = $aAttributes;
00674 }
00675 }
00676 return $this->_aAttributes;
00677 }
00678
00684 public function getArticleList()
00685 {
00686 if ( $this->_aArticleList === null ) {
00687 if ( $this->_isActCategory() && ( $oCategory = $this->getActCategory() ) ) {
00688 $aArticleList = $this->_loadArticles( $oCategory );
00689 if ( count( $aArticleList ) ) {
00690 $this->_aArticleList = $aArticleList;
00691 }
00692 }
00693 }
00694 return $this->_aArticleList;
00695 }
00696
00702 public function getSimilarRecommLists()
00703 {
00704 if ( $this->_oRecommList === null ) {
00705 $this->_oRecommList = false;
00706 if ( $aCatArtList = $this->getArticleList() ) {
00707 $oRecommList = oxNew('oxrecommlist');
00708 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00709 }
00710 }
00711 return $this->_oRecommList;
00712 }
00713
00719 public function getCatTreePath()
00720 {
00721 if ( $this->_sCatTreePath === null ) {
00722 $this->_sCatTreePath = false;
00723
00724 if ( $oCatTree = $this->getCategoryTree() ) {
00725 $this->_sCatTreePath = $oCatTree->getPath();
00726 }
00727 }
00728 return $this->_sCatTreePath;
00729 }
00730
00738 public function getTemplateLocation()
00739 {
00740 if ( $this->_sCatTreeHtmlPath === null ) {
00741 $this->_sCatTreeHtmlPath = false;
00742
00743 if ( $oCatTree = $this->getCategoryTree() ) {
00744 $this->_sCatTreeHtmlPath = $oCatTree->getHtmlPath();
00745 }
00746 }
00747 return $this->_sCatTreeHtmlPath;
00748 }
00749
00755 public function getTreePath()
00756 {
00757 if ( $oCatTree = $this->getCategoryTree() ) {
00758 return $oCatTree->getPath();
00759 }
00760 }
00761
00768 public function hasVisibleSubCats()
00769 {
00770 if ( $this->_blHasVisibleSubCats === null ) {
00771 $this->_blHasVisibleSubCats = false;
00772 if ( $oClickCat = $this->getActCategory() ) {
00773 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00774 }
00775 }
00776 return $this->_blHasVisibleSubCats;
00777 }
00778
00784 public function getSubCatList()
00785 {
00786 if ( $this->_aSubCatList === null ) {
00787 $this->_aSubCatList = array();
00788 if ( $oClickCat = $this->getActCategory() ) {
00789 $this->_aSubCatList = $oClickCat->getSubCats();
00790 }
00791 }
00792 return $this->_aSubCatList;
00793 }
00794
00800 public function getPageNavigation()
00801 {
00802 if ( $this->_oPageNavigation === null ) {
00803 $this->_oPageNavigation = $this->generatePageNavigation();
00804 }
00805 return $this->_oPageNavigation;
00806 }
00807
00813 public function getTitle()
00814 {
00815 if ( $this->_sCatTitle === null ) {
00816 $this->_sCatTitle = false;
00817 if ( ( $oCategory = $this->getActCategory() ) ) {
00818 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00819 }
00820 }
00821 return $this->_sCatTitle;
00822 }
00823
00829 public function getTop5ArticleList()
00830 {
00831 if ( $this->_aTop5ArticleList === null ) {
00832 $this->_aTop5ArticleList = false;
00833 $myConfig = $this->getConfig();
00834 if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00835
00836 $oArtList = oxNew( 'oxarticlelist' );
00837 $oArtList->loadTop5Articles();
00838 if ( $oArtList->count() ) {
00839 $this->_aTop5ArticleList = $oArtList;
00840 }
00841 }
00842 }
00843 return $this->_aTop5ArticleList;
00844 }
00845
00851 public function getBargainArticleList()
00852 {
00853 if ( $this->_aBargainArticleList === null ) {
00854 $this->_aBargainArticleList = array();
00855 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00856 $oArtList = oxNew( 'oxarticlelist' );
00857 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00858 if ( $oArtList->count() ) {
00859 $this->_aBargainArticleList = $oArtList;
00860 }
00861 }
00862 }
00863 return $this->_aBargainArticleList;
00864 }
00865
00871 public function getActiveCategory()
00872 {
00873 return $this->getActCategory();
00874 }
00875
00881 public function getCanonicalUrl()
00882 {
00883 if ( ( $iPage = $this->getActPage() ) ) {
00884 return $this->_addPageNrParam( $this->generatePageNavigationUrl(), $iPage );
00885 } elseif ( ( $oCategory = $this->getActiveCategory() ) ) {
00886 return $oCategory->getLink();
00887 }
00888 }
00889 }