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 return $this->getTemplateName();
00203 }
00204
00213 public function executefilter()
00214 {
00215
00216 $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00217 $sActCat = oxConfig::getParameter( 'cnid' );
00218 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00219 $aSessionFilter[$sActCat] = $aFilter;
00220 oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00221 }
00222
00230 protected function _loadArticles( $oCategory )
00231 {
00232 $myConfig = $this->getConfig();
00233
00234 $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00235 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00236
00237
00238 $oArtList = oxNew( 'oxarticlelist' );
00239 $oArtList->setSqlLimit( $iNrofCatArticles * $this->getActPage(), $iNrofCatArticles );
00240 $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00241
00242 if ( $oCategory->oxcategories__oxpricefrom->value || $oCategory->oxcategories__oxpriceto->value ) {
00243 $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00244 $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
00245
00246 $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00247 } else {
00248 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00249
00250 $sActCat = oxConfig::getParameter( 'cnid' );
00251 $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00252 }
00253
00254 $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00255
00256 return $oArtList;
00257 }
00258
00264 protected function _getSeoObjectId()
00265 {
00266 if ( ( $oCategory = $this->getActCategory() ) ) {
00267 return $oCategory->getId();
00268 }
00269 }
00270
00276 protected function _getCatPathString()
00277 {
00278 if ( $this->_sCatPathString === null ) {
00279
00280
00281 $this->_sCatPathString = false;
00282
00283
00284 if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00285
00286 $oStr = getStr();
00287 $this->_sCatPathString = '';
00288 foreach ( $aPath as $oCat ) {
00289 if ( $this->_sCatPathString ) {
00290 $this->_sCatPathString .= ', ';
00291 }
00292 $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00293 }
00294 }
00295 }
00296 return $this->_sCatPathString;
00297 }
00298
00308 protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00309 {
00310
00311 $sDescription = oxLang::getInstance()->translateString( 'INC_HEADER_YOUAREHERE' );
00312
00313
00314 if ( $oCategory = $this->_getCategory() ) {
00315 if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00316 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00317 }
00318
00319
00320 $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00321 }
00322
00323
00324 if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00325 $sDescription .= " {$sSuffix}";
00326 }
00327
00328
00329 $sDescription = getStr()->cleanStr($sDescription);
00330 return trim( strip_tags( getStr()->html_entity_decode( $sDescription ) ) );
00331 }
00332
00345 protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00346 {
00347
00348 $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->oxcategories__oxlongdesc->value ):'';
00349 $aArticleList = $this->getArticleList();
00350 if ( !$sAddText && count($aArticleList)) {
00351 foreach ( $aArticleList as $oArticle ) {
00352 if ( $sAddText ) {
00353 $sAddText .= ', ';
00354 }
00355 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00356 }
00357 }
00358
00359 if ( !$sMeta ) {
00360 $sMeta = trim( $this->_getCatPathString() );
00361 }
00362
00363 if ( $sMeta ) {
00364 $sMeta = "{$sMeta} - {$sAddText}";
00365 } else {
00366 $sMeta = $sAddText;
00367 }
00368
00369 return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00370 }
00371
00379 protected function _prepareMetaKeyword( $sKeywords )
00380 {
00381 $sKeywords = '';
00382 if ( ( $oCategory = $this->getActCategory() ) ) {
00383 if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00384 $sKeywords = $oParent->oxcategories__oxtitle->value;
00385 }
00386
00387 $sKeywords = ( $sKeywords ? $sKeywords . ', ' : '' ) . $oCategory->oxcategories__oxtitle->value;
00388 $aSubCats = $oCategory->getSubCats();
00389 if ( is_array( $aSubCats ) ) {
00390 foreach ( $aSubCats as $oSubCat ) {
00391 $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00392 }
00393 }
00394 }
00395
00396 $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, true );
00397 $sKeywords = $this->_removeDuplicatedWords( $sKeywords );
00398
00399
00400 $aSkipTags = $this->getConfig()->getConfigParam( 'aSkipTags' );
00401 if ( is_array( $aSkipTags ) && $sKeywords ) {
00402 foreach ( $aSkipTags as $sSkip ) {
00403 $aPattern = array( '/\W'.$sSkip.'\W/i', '/^'.$sSkip.'\W/i', '/\"'.$sSkip.'$/i' );
00404 $sKeywords = preg_replace( $aPattern, '', $sKeywords );
00405 }
00406 }
00407
00408 return trim( $sKeywords );
00409 }
00410
00419 protected function _collectMetaKeyword( $sKeywords )
00420 {
00421 $iMaxTextLenght = 60;
00422 $sText = '';
00423
00424 if ( count( $aArticleList = $this->getArticleList() ) ) {
00425 $oStr = getStr();
00426 foreach ( $aArticleList as $oProduct ) {
00427 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00428 if ( $oStr->strlen( $sDesc ) > $iMaxTextLenght ) {
00429 $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLenght );
00430 $sDesc .= $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00431 }
00432 if ( $sText ) {
00433 $sText .= ', ';
00434 }
00435 $sText .= $sDesc;
00436 }
00437 }
00438
00439 if ( !$sKeywords ) {
00440 $sKeywords = $this->_getCatPathString();
00441 }
00442
00443 if ( $sKeywords ) {
00444 $sText = "{$sKeywords}, {$sText}";
00445 }
00446
00447 return parent::_prepareMetaKeyword( $sText );
00448 }
00449
00457 public function getTemplateName()
00458 {
00459
00460 if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00461 $this->_sThisTemplate = $sTplName;
00462 } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00463 $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00464 }
00465
00466 return $this->_sThisTemplate;
00467 }
00468
00478 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00479 {
00480 if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00481 if ( $iPage ) {
00482 $sUrl = oxSeoEncoderCategory::getInstance()->getCategoryPageUrl( $oCategory, $iPage, $iLang, $this->_isFixedUrl( $oCategory ) );
00483 }
00484 } else {
00485 $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00486 }
00487 return $sUrl;
00488 }
00489
00495 protected function _isFixedUrl( $oCategory )
00496 {
00497 if ( $this->_blFixedUrl == null ) {
00498 $sId = $oCategory->getId();
00499 $iLang = $oCategory->getLanguage();
00500 $sShopId = $this->getConfig()->getShopId();
00501 $this->_blFixedUrl = oxDb::getDb()->getOne( "select oxfixed from oxseo where oxobjectid = '{$sId}' and oxshopid = '{$sShopId}' and oxlang = '{$iLang}' and oxparams = '' " );
00502 }
00503 return $this->_blFixedUrl;
00504 }
00505
00511 public function _isActCategory()
00512 {
00513 return $this->_blIsCat;
00514 }
00515
00523 protected function _getCategory()
00524 {
00525 return $this->getActCategory();
00526 }
00527
00533 public function generatePageNavigationUrl( )
00534 {
00535 if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00536 return $oCategory->getLink();
00537 } else {
00538 return parent::generatePageNavigationUrl( );
00539 }
00540 }
00541
00549 public function getSorting( $sCnid )
00550 {
00551
00552 $aSorting = parent::getSorting( $sCnid );
00553 $oActCat = $this->getActCategory();
00554 if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00555 $sSortBy = getViewName( 'oxarticles' ).".{$oActCat->oxcategories__oxdefsort->value}";
00556 $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? " desc " : null;
00557
00558 $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00559 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00560 }
00561 return $aSorting;
00562 }
00563
00569 public function getTitleSuffix()
00570 {
00571 if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00572 return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00573 }
00574 }
00575
00582 protected function _getSubject()
00583 {
00584 return $this->getActCategory();
00585 }
00586
00593 public function getAttributes()
00594 {
00595
00596 $this->_aAttributes = false;
00597 if ( ( $oCategory = $this->getActCategory() ) ) {
00598 $aAttributes = $oCategory->getAttributes();
00599 if ( count( $aAttributes ) ) {
00600 $this->_aAttributes = $aAttributes;
00601 }
00602 }
00603 return $this->_aAttributes;
00604 }
00605
00611 public function getArticleList()
00612 {
00613 if ( $this->_aArticleList === null ) {
00614 if ( $this->_isActCategory() && ( $oCategory = $this->getActCategory() ) ) {
00615 $aArticleList = $this->_loadArticles( $oCategory );
00616 if ( count( $aArticleList ) ) {
00617 $this->_aArticleList = $aArticleList;
00618 }
00619 }
00620 }
00621 return $this->_aArticleList;
00622 }
00623
00629 public function getSimilarRecommLists()
00630 {
00631 if ( $this->_oRecommList === null ) {
00632 $this->_oRecommList = false;
00633 if ( $aCatArtList = $this->getArticleList() ) {
00634 $oRecommList = oxNew('oxrecommlist');
00635 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00636 }
00637 }
00638 return $this->_oRecommList;
00639 }
00640
00646 public function getCatTreePath()
00647 {
00648 if ( $this->_sCatTreePath === null ) {
00649 $this->_sCatTreePath = false;
00650
00651 if ( $oCatTree = $this->getCategoryTree() ) {
00652 $this->_sCatTreePath = $oCatTree->getPath();
00653 }
00654 }
00655 return $this->_sCatTreePath;
00656 }
00657
00663 public function getTemplateLocation()
00664 {
00665 if ( $this->_sCatTreeHtmlPath === null ) {
00666 $this->_sCatTreeHtmlPath = false;
00667
00668 if ( $oCatTree = $this->getCategoryTree() ) {
00669 $this->_sCatTreeHtmlPath = $oCatTree->getHtmlPath();
00670 }
00671 }
00672 return $this->_sCatTreeHtmlPath;
00673 }
00674
00681 public function hasVisibleSubCats()
00682 {
00683 if ( $this->_blHasVisibleSubCats === null ) {
00684 $this->_blHasVisibleSubCats = false;
00685 if ( $oClickCat = $this->getActCategory() ) {
00686 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00687 }
00688 }
00689 return $this->_blHasVisibleSubCats;
00690 }
00691
00697 public function getSubCatList()
00698 {
00699 if ( $this->_aSubCatList === null ) {
00700 $this->_aSubCatList = array();
00701 if ( $oClickCat = $this->getActCategory() ) {
00702 $this->_aSubCatList = $oClickCat->getSubCats();
00703 }
00704 }
00705 return $this->_aSubCatList;
00706 }
00707
00713 public function getPageNavigation()
00714 {
00715 if ( $this->_oPageNavigation === null ) {
00716 $this->_oPageNavigation = false;
00717 $this->_oPageNavigation = $this->generatePageNavigation();
00718 }
00719 return $this->_oPageNavigation;
00720 }
00721
00727 public function getTitle()
00728 {
00729 if ( $this->_sCatTitle === null ) {
00730 $this->_sCatTitle = false;
00731 if ( ( $oCategory = $this->getActCategory() ) ) {
00732 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00733 }
00734 }
00735 return $this->_sCatTitle;
00736 }
00737
00743 public function getTop5ArticleList()
00744 {
00745 if ( $this->_aTop5ArticleList === null ) {
00746 $this->_aTop5ArticleList = false;
00747 $myConfig = $this->getConfig();
00748 if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00749
00750 $oArtList = oxNew( 'oxarticlelist' );
00751 $oArtList->loadTop5Articles();
00752 if ( $oArtList->count() ) {
00753 $this->_aTop5ArticleList = $oArtList;
00754 }
00755 }
00756 }
00757 return $this->_aTop5ArticleList;
00758 }
00759
00765 public function getBargainArticleList()
00766 {
00767 if ( $this->_aBargainArticleList === null ) {
00768 $this->_aBargainArticleList = array();
00769 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00770 $oArtList = oxNew( 'oxarticlelist' );
00771 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00772 if ( $oArtList->count() ) {
00773 $this->_aBargainArticleList = $oArtList;
00774 }
00775 }
00776 }
00777 return $this->_aBargainArticleList;
00778 }
00779
00785 public function getActiveCategory()
00786 {
00787 return $this->getActCategory();
00788 }
00789
00790 }