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 $_oCategory = null;
00088
00093 protected $_blIsCat = null;
00094
00099 protected $_oRecommList = null;
00100
00105 protected $_sCatTitle = null;
00106
00111 protected $_blFixedUrl = null;
00112
00119 public function getViewId()
00120 {
00121 if ( isset( $this->_sViewId ) ) {
00122 return $this->_sViewId;
00123 }
00124
00125 $iActPage = $this->getActPage();
00126
00127
00128 $_sViewId = md5( parent::getViewId().'|'.oxConfig::getParameter( 'cnid' ).'|'.$iActPage.'|'.oxConfig::getParameter( '_artperpage' ) );
00129
00130
00131 return $this->_sViewId = $_sViewId;
00132 }
00133
00149 public function render()
00150 {
00151 $myConfig = $this->getConfig();
00152
00153 $this->_oCategory = null;
00154 $blContinue = true;
00155 $this->_blIsCat = false;
00156
00157
00158 if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) && $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00159
00160
00161 $this->_sThisTemplate = $this->_sThisMoreTemplate;
00162 $this->_oCategory = oxNew( 'oxcategory' );
00163 $this->_oCategory->oxcategories__oxactive = new oxField(1, oxField::T_RAW);
00164 } else {
00165 if( ( $this->_oActCategory = $this->getActCategory() ) ) {
00166 $this->_oCategory = $this->_oActCategory;
00167 $blContinue = $this->_oCategory->oxcategories__oxactive->value;
00168 $this->_blIsCat = true;
00169 }
00170 }
00171
00172
00173
00174 if ( !$blContinue || !$this->_oCategory ) {
00175 oxUtils::getInstance()->redirect( $myConfig->getShopURL().'index.php' );
00176 }
00177
00178 $this->_aViewData['filterattributes'] = $this->getAttributes();
00179
00180 $this->_aViewData['articlelist'] = $this->getArticleList();
00181 $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00182
00183
00184 $this->_aViewData['articlebargainlist'] = $this->getBargainArticleList();
00185 $this->_aViewData['aTop5Articles'] = $this->getTop5ArticleList();
00186
00187 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00188
00189 $this->_aViewData['actCatpath'] = $this->getCatTreePath();
00190 $this->_aViewData['template_location'] = $this->getTemplateLocation();
00191
00192
00193 $this->setMetaDescription( null );
00194 $this->setMetaKeywords( null );
00195
00196
00197 $this->_aViewData['actCategory'] = $this->getActiveCategory();
00198
00199 $oCat = $this->getActCategory();
00200 if ($oCat && is_array($myConfig->getConfigParam( 'aRssSelected' )) && in_array('oxrss_categories', $myConfig->getConfigParam( 'aRssSelected' ))) {
00201 $oRss = oxNew('oxrssfeed');
00202 $this->addRssFeed($oRss->getCategoryArticlesTitle($oCat), $oRss->getCategoryArticlesUrl($oCat), 'activeCategory');
00203 }
00204
00205
00206 $this->_aViewData['hasVisibleSubCats'] = $this->hasVisibleSubCats();
00207 $this->_aViewData['subcatlist'] = $this->getSubCatList();
00208
00209 $this->_aViewData['title'] = $this->getTitle();
00210
00211 parent::render();
00212
00213 return $this->getTemplateName();
00214 }
00215
00224 public function executefilter()
00225 {
00226
00227 $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00228 $sActCat = oxConfig::getParameter( 'cnid' );
00229 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00230 $aSessionFilter[$sActCat] = $aFilter;
00231 oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00232 }
00233
00241 protected function _loadArticles( $oCategory )
00242 {
00243 $myConfig = $this->getConfig();
00244
00245 $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00246 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00247
00248
00249 $oArtList = oxNew( 'oxarticlelist' );
00250 $oArtList->setSqlLimit( $iNrofCatArticles * $this->getActPage(), $iNrofCatArticles );
00251
00252 if ( $this->_oActCategory ) {
00253 $oArtList->setCustomSorting( $this->getSortingSql( $this->_oActCategory->getId() ) );
00254 }
00255
00256 if ( $oCategory->oxcategories__oxpricefrom->value || $oCategory->oxcategories__oxpriceto->value ) {
00257 $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00258 $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
00259
00260 $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00261 } else {
00262
00263 $aSessionFilter = null;
00264 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00265
00266 $sActCat = oxConfig::getParameter( 'cnid' );
00267 $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00268 }
00269
00270 $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00271
00272 return $oArtList;
00273 }
00274
00280 protected function _getSeoObjectId()
00281 {
00282 if ( ( $oCategory = $this->getActCategory() ) ) {
00283 return $oCategory->getId();
00284 }
00285 }
00286
00292 protected function _getCatPathString()
00293 {
00294 if ( $this->_sCatPathString === null ) {
00295
00296
00297 $this->_sCatPathString = false;
00298
00299
00300 if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00301
00302 $this->_sCatPathString = '';
00303 foreach ( $aPath as $oCat ) {
00304 if ( $this->_sCatPathString ) {
00305 $this->_sCatPathString .= ', ';
00306 }
00307 $this->_sCatPathString .= strtolower( $oCat->oxcategories__oxtitle->value );
00308 }
00309 }
00310 }
00311 return $this->_sCatPathString;
00312 }
00313
00325 protected function _prepareMetaDescription( $aCatPath, $iLength = 1024, $blDescTag = false )
00326 {
00327
00328 $sDescription = oxLang::getInstance()->translateString( 'INC_HEADER_YOUAREHERE' );
00329
00330
00331 if ( ( $oParent = $this->_oCategory->getParentCategory() ) ) {
00332 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00333 }
00334
00335
00336 $sDescription .= " {$this->_oCategory->oxcategories__oxtitle->value}.";
00337
00338
00339 if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00340 $sDescription .= " {$sSuffix}";
00341 }
00342
00343
00344 $aRemoveChars = array( "\"", "'", "\n", "\r", "\t", "\x95", "\xA0" );
00345 $sDescription = str_replace( $aRemoveChars, ' ', $sDescription );
00346
00347 return strip_tags( html_entity_decode( $sDescription ) );
00348 }
00349
00362 protected function _collectMetaDescription( $aCatPath, $iLength = 1024, $blDescTag = false )
00363 {
00364
00365 $sAddText = $this->_oActCategory?trim( $this->_oActCategory->oxcategories__oxlongdesc->value ):'';
00366 if ( !$sAddText && count($this->_aArticleList)) {
00367 foreach ( $this->_aArticleList as $oArticle ) {
00368 if ( $sAddText ) {
00369 $sAddText .= ', ';
00370 }
00371 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00372 }
00373 }
00374
00375 return parent::_prepareMetaDescription( $this->_getCatPathString().' - '.$sAddText, $iLength, $blDescTag );
00376 }
00377
00385 protected function _prepareMetaKeyword( $aCatPath )
00386 {
00387 $sKeywords = '';
00388 if ( ( $oParent = $this->_oCategory->getParentCategory() ) ) {
00389 $sKeywords = $oParent->oxcategories__oxtitle->value;
00390 }
00391
00392 $sKeywords = ( $sKeywords ? $sKeywords . ', ' : '' ) . $this->_oCategory->oxcategories__oxtitle->value;
00393 $aSubCats = $this->_oCategory->getSubCats();
00394 if ( is_array( $aSubCats ) ) {
00395 foreach ( $aSubCats as $oSubCat ) {
00396 $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00397 }
00398 }
00399
00400 $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, true );
00401 $sKeywords = $this->_removeDuplicatedWords( $sKeywords );
00402
00403
00404 $aSkipTags = $this->getConfig()->getConfigParam( 'aSkipTags' );
00405 if ( is_array( $aSkipTags ) && $sKeywords ) {
00406 foreach ( $aSkipTags as $sSkip ) {
00407 $aPattern = array( '/\W'.$sSkip.'\W/i', '/^'.$sSkip.'\W/i', '/\"'.$sSkip.'$/i' );
00408 $sKeywords = preg_replace( $aPattern, '', $sKeywords );
00409 }
00410 }
00411
00412 return $sKeywords;
00413 }
00414
00423 protected function _collectMetaKeyword( $aCatPath )
00424 {
00425 $iMaxTextLenght = 60;
00426 $sText = '';
00427
00428 if (count($this->_aArticleList)) {
00429 foreach ( $this->_aArticleList as $oProduct ) {
00430 $sDesc = strip_tags( trim( strtolower( $oProduct->oxarticles__oxlongdesc->value ) ) );
00431 if ( strlen( $sDesc ) > $iMaxTextLenght ) {
00432 $sMidText = substr( $sDesc, 0, $iMaxTextLenght );
00433 $sText .= substr( $sMidText, 0, ( strlen( $sMidText ) - strpos( strrev( $sMidText ), ' ' ) ) );
00434 }
00435 }
00436 }
00437 return parent::_prepareMetaKeyword( $this->_getCatPathString() . ', ' . $sText );
00438 }
00439
00447 public function getTemplateName()
00448 {
00449
00450 if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00451 $this->_sThisTemplate = $sTplName;
00452 } elseif ( $this->_oActCategory && $this->_oActCategory->oxcategories__oxtemplate->value ) {
00453 $this->_sThisTemplate = $this->_oActCategory->oxcategories__oxtemplate->value;
00454 }
00455
00456 return $this->_sThisTemplate;
00457 }
00458
00468 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00469 {
00470 if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00471 if ( $iPage ) {
00472 $sUrl = oxSeoEncoderCategory::getInstance()->getCategoryPageUrl( $oCategory, $iPage, $iLang, $this->_isFixedUrl( $oCategory ) );
00473 }
00474 } else {
00475 $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00476 }
00477 return $sUrl;
00478 }
00479
00485 protected function _isFixedUrl( $oCategory )
00486 {
00487 if ( $this->_blFixedUrl == null ) {
00488 $sId = $oCategory->getId();
00489 $iLang = $oCategory->getLanguage();
00490 $sShopId = oxConfig::getInstance()->getShopId();
00491 $this->_blFixedUrl = oxDb::getDb()->getOne( "select oxfixed from oxseo where oxobjectid = '{$sId}' and oxshopid = '{$sShopId}' and oxlang = '{$iLang}' and oxparams = '' " );
00492 }
00493 return $this->_blFixedUrl;
00494 }
00495
00501 public function _isActCategory()
00502 {
00503 return $this->_blIsCat;
00504 }
00505
00511 protected function _getCategory()
00512 {
00513 return $this->_oCategory;
00514 }
00515
00521 public function generatePageNavigationUrl( )
00522 {
00523 if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00524 return $oCategory->getLink();
00525 } else {
00526 return parent::generatePageNavigationUrl( );
00527 }
00528 }
00529
00537 public function getSorting( $sCnid )
00538 {
00539
00540 $aSorting = parent::getSorting( $sCnid );
00541 if ( !$aSorting && $this->_oActCategory && $this->_oActCategory->oxcategories__oxdefsort->value ) {
00542 $sSortBy = getViewName( 'oxarticles' ).'.'.$this->_oActCategory->oxcategories__oxdefsort->value;
00543 if ( $sSortBy) {
00544 $sSortDir = $this->_oActCategory->oxcategories__oxdefsortmode->value ? " desc " : null;
00545 }
00546 $sSortDir = $sSortDir?$sSortDir:null;
00547
00548 $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00549 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00550 }
00551 return $aSorting;
00552 }
00553
00559 public function getTitleSuffix()
00560 {
00561 if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00562 return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00563 }
00564 }
00565
00572 protected function getSubject()
00573 {
00574 return $this->getActCategory();
00575 }
00576
00583 public function getAttributes()
00584 {
00585
00586 $this->_aAttributes = false;
00587 if ( $this->_getCategory() ) {
00588 $aAttributes = $this->_getCategory()->getAttributes();
00589 if ( count( $aAttributes ) ) {
00590 $this->_aAttributes = $aAttributes;
00591 }
00592 }
00593 return $this->_aAttributes;
00594 }
00595
00601 public function getArticleList()
00602 {
00603 if ( $this->_aArticleList === null ) {
00604 if ( ( $oCategory = $this->_getCategory() ) && $this->_isActCategory() ) {
00605 $aArticleList = $this->_loadArticles( $oCategory );
00606 if ( count( $aArticleList ) ) {
00607 $this->_aArticleList = $aArticleList;
00608 }
00609 }
00610 }
00611 return $this->_aArticleList;
00612 }
00613
00619 public function getSimilarRecommLists()
00620 {
00621 if ( $this->_oRecommList === null ) {
00622 $this->_oRecommList = false;
00623 if ( $aCatArtList = $this->getArticleList() ) {
00624 $oRecommList = oxNew('oxrecommlist');
00625 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00626 }
00627 }
00628 return $this->_oRecommList;
00629 }
00630
00636 public function getCatTreePath()
00637 {
00638 if ( $this->_sCatTreePath === null ) {
00639 $this->_sCatTreePath = false;
00640
00641 if ( $oCatTree = $this->getCategoryTree() ) {
00642 $this->_sCatTreePath = $oCatTree->getPath();
00643 }
00644 }
00645 return $this->_sCatTreePath;
00646 }
00647
00653 public function getTemplateLocation()
00654 {
00655 if ( $this->_sCatTreeHtmlPath === null ) {
00656 $this->_sCatTreeHtmlPath = false;
00657
00658 if ( $oCatTree = $this->getCategoryTree() ) {
00659 $this->_sCatTreeHtmlPath = $oCatTree->getHtmlPath();
00660 }
00661 }
00662 return $this->_sCatTreeHtmlPath;
00663 }
00664
00671 public function hasVisibleSubCats()
00672 {
00673 if ( $this->_blHasVisibleSubCats === null ) {
00674 $this->_blHasVisibleSubCats = false;
00675 if ( $oClickCat = $this->getActCategory() ) {
00676 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00677 }
00678 }
00679 return $this->_blHasVisibleSubCats;
00680 }
00681
00687 public function getSubCatList()
00688 {
00689 if ( $this->_aSubCatList === null ) {
00690 $this->_aSubCatList = array();
00691 if ( $oClickCat = $this->getActCategory() ) {
00692 $this->_aSubCatList = $oClickCat->getSubCats();
00693 }
00694 }
00695 return $this->_aSubCatList;
00696 }
00697
00703 public function getPageNavigation()
00704 {
00705 if ( $this->_oPageNavigation === null ) {
00706 $this->_oPageNavigation = false;
00707 $this->_oPageNavigation = $this->generatePageNavigation();
00708 }
00709 return $this->_oPageNavigation;
00710 }
00711
00717 public function getTitle()
00718 {
00719 if ( $this->_sCatTitle === null ) {
00720 $this->_sCatTitle = false;
00721 if ( $oCategory = $this->_getCategory() ) {
00722 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00723 }
00724 }
00725 return $this->_sCatTitle;
00726 }
00727
00733 public function getTop5ArticleList()
00734 {
00735 if ( $this->_aTop5ArticleList === null ) {
00736 $this->_aTop5ArticleList = false;
00737 $myConfig = $this->getConfig();
00738 if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00739
00740 $oArtList = oxNew( 'oxarticlelist' );
00741 $oArtList->loadTop5Articles();
00742 if ( $oArtList->count() ) {
00743 $this->_aTop5ArticleList = $oArtList;
00744 }
00745 }
00746 }
00747 return $this->_aTop5ArticleList;
00748 }
00749
00755 public function getBargainArticleList()
00756 {
00757 if ( $this->_aBargainArticleList === null ) {
00758 $this->_aBargainArticleList = array();
00759 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00760 $oArtList = oxNew( 'oxarticlelist' );
00761 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00762 if ( $oArtList->count() ) {
00763 $this->_aBargainArticleList = $oArtList;
00764 }
00765 }
00766 }
00767 return $this->_aBargainArticleList;
00768 }
00769
00775 public function getActiveCategory()
00776 {
00777 return $this->getActCategory();
00778 }
00779
00780 }