00001 <?php
00002
00009 class aList extends oxUBase
00010 {
00015 protected $_iAllArtCnt = 0;
00016
00021 protected $_iCntPages = 0;
00022
00027 protected $_sThisTemplate = 'page/list/list.tpl';
00028
00033 protected $_sThisMoreTemplate = 'page/list/morecategories.tpl';
00034
00039 protected $_sCatPathString = null;
00040
00045 protected $_blShowSorting = true;
00046
00051 protected $_aAttributes = null;
00052
00057 protected $_aCatArtList = null;
00058
00063 protected $_blHasVisibleSubCats = null;
00064
00069 protected $_aSubCatList = null;
00070
00075 protected $_oPageNavigation = null;
00076
00081 protected $_blIsCat = null;
00082
00087 protected $_oRecommList = null;
00088
00093 protected $_sCatTitle = null;
00094
00099 protected $_blTop5Action = true;
00104 protected $_blShowTagCloud = false;
00105
00110 protected $_blBargainAction = false;
00111
00118 public function getViewId()
00119 {
00120 if ( !isset( $this->_sViewId ) ) {
00121 $sCatId = oxConfig::getParameter( 'cnid' );
00122 $iActPage = $this->getActPage();
00123 $iArtPerPage = oxSession::getVar( '_artperpage' );
00124 $sListDisplayType = oxSession::getVar( 'ldtype' );
00125 $sParentViewId = parent::getViewId();
00126
00127
00128 $this->_sViewId = md5( $sParentViewId.'|'.$sCatId.'|'.$iActPage.'|'.$iArtPerPage.'|'.$sListDisplayType );
00129
00130 }
00131
00132 return $this->_sViewId;
00133 }
00134
00147 public function render()
00148 {
00149 $myConfig = $this->getConfig();
00150
00151 $oCategory = null;
00152 $blContinue = true;
00153 $this->_blIsCat = false;
00154
00155
00156 if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00157
00158 $this->_sThisTemplate = $this->_sThisMoreTemplate;
00159 $oCategory = oxNew( 'oxcategory' );
00160 $oCategory->oxcategories__oxactive = new oxField( 1, oxField::T_RAW );
00161 $this->setActCategory( $oCategory );
00162
00163 $this->_blShowTagCloud = true;
00164
00165 } elseif ( ( $oCategory = $this->getActCategory() ) ) {
00166 $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
00167 $this->_blIsCat = true;
00168 $this->_blBargainAction = true;
00169 }
00170
00171
00172
00173 if ( !$blContinue || !$oCategory ) {
00174 oxUtils::getInstance()->redirect( $myConfig->getShopURL().'index.php' );
00175 }
00176
00177 $oCat = $this->getActCategory();
00178 if ($oCat && $myConfig->getConfigParam( 'bl_rssCategories' )) {
00179 $oRss = oxNew('oxrssfeed');
00180 $this->addRssFeed($oRss->getCategoryArticlesTitle($oCat), $oRss->getCategoryArticlesUrl($oCat), 'activeCategory');
00181 }
00182
00183
00184 $this->getArticleList();
00185
00186 if ( $this->getPageCount() < $this->getActPage() ) {
00187 error_404_handler();
00188 }
00189
00190 parent::render();
00191
00192
00193 $this->_processListArticles();
00194
00195 return $this->getTemplateName();
00196 }
00197
00204 protected function _processListArticles()
00205 {
00206 if ( $aArtList = $this->getArticleList() ) {
00207 $iLinkType = $this->_getProductLinkType();
00208 $sAddDynParams = $this->getAddUrlParams();
00209 $sAddSeoParams = $this->getAddSeoUrlParams();
00210
00211 foreach ( $aArtList as $oArticle ) {
00212 $oArticle->setLinkType( $iLinkType );
00213
00214
00215 if ( $sAddDynParams ) {
00216 $oArticle->appendStdLink( $sAddDynParams );
00217 }
00218
00219
00220 if ( $sAddSeoParams ) {
00221 $oArticle->appendLink( $sAddSeoParams );
00222 }
00223 }
00224 }
00225 }
00226
00227
00233 public function getAddUrlParams()
00234 {
00235 $sParams = parent::getAddUrlParams();
00236 if ( !oxUtils::getInstance()->seoIsActive() ) {
00237 $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
00238 if ( $iPgNr > 0 ) {
00239 $sParams .= ($sParams?'&':'') . "pgNr={$iPgNr}";
00240 }
00241 }
00242
00243 return $sParams;
00244 }
00245
00251 public function getAddSeoUrlParams()
00252 {
00253 }
00254
00262 protected function _getProductLinkType()
00263 {
00264 $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00265 if ( ( $oCat = $this->getActCategory() ) && $oCat->isPriceCategory() ) {
00266 $iCatType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00267 }
00268 return $iCatType;
00269 }
00270
00279 public function executefilter()
00280 {
00281
00282 $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00283 $sActCat = oxConfig::getParameter( 'cnid' );
00284
00285 if ( !empty( $aFilter ) ) {
00286 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00287 $aSessionFilter[$sActCat] = $aFilter;
00288 oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00289 }
00290 }
00291
00299 protected function _loadArticles( $oCategory )
00300 {
00301 $myConfig = $this->getConfig();
00302
00303 $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00304 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00305
00306
00307 $oArtList = oxNew( 'oxarticlelist' );
00308 $oArtList->setSqlLimit( $iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles );
00309 $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00310
00311 if ( $oCategory->isPriceCategory() ) {
00312 $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00313 $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
00314
00315 $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00316 } else {
00317 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00318
00319 $sActCat = oxConfig::getParameter( 'cnid' );
00320 $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00321 }
00322
00323 $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00324
00325 return $oArtList;
00326 }
00327
00333 public function getActPage()
00334 {
00335 return $this->_getRequestPageNr();
00336 }
00337
00346 protected function _getRequestPageNr()
00347 {
00348 return parent::getActPage();
00349 }
00350
00356 protected function _getSeoObjectId()
00357 {
00358 if ( ( $oCategory = $this->getActCategory() ) ) {
00359 return $oCategory->getId();
00360 }
00361 }
00362
00368 protected function _getCatPathString()
00369 {
00370 if ( $this->_sCatPathString === null ) {
00371
00372
00373 $this->_sCatPathString = false;
00374
00375
00376 if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00377
00378 $oStr = getStr();
00379 $this->_sCatPathString = '';
00380 foreach ( $aPath as $oCat ) {
00381 if ( $this->_sCatPathString ) {
00382 $this->_sCatPathString .= ', ';
00383 }
00384 $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00385 }
00386 }
00387 }
00388 return $this->_sCatPathString;
00389 }
00390
00400 protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00401 {
00402
00403 $sDescription = oxLang::getInstance()->translateString( 'ALIST_META_DESCRIPTION_PREFIX' );
00404
00405
00406 if ( $oCategory = $this->getActCategory() ) {
00407 if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00408 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00409 }
00410
00411
00412 $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00413 }
00414
00415
00416 if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00417 $sDescription .= " {$sSuffix}";
00418 }
00419
00420
00421 $sDescription = getStr()->cleanStr($sDescription);
00422 return trim( strip_tags( getStr()->html_entity_decode( $sDescription ) ) );
00423 }
00424
00430 public function getMetaDescription()
00431 {
00432 $sMeta = parent::getMetaDescription();
00433
00434 if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00435 if ( $sMeta ) {
00436 $sMeta .= ", ";
00437 }
00438 $sMeta .= $sTitlePageSuffix;
00439 }
00440
00441 return $sMeta;
00442 }
00443
00456 protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00457 {
00458
00459 $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->getLongDesc() ):'';
00460 $aArticleList = $this->getArticleList();
00461 if ( !$sAddText && count($aArticleList)) {
00462 foreach ( $aArticleList as $oArticle ) {
00463 if ( $sAddText ) {
00464 $sAddText .= ', ';
00465 }
00466 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00467 }
00468 }
00469
00470 if ( !$sMeta ) {
00471 $sMeta = trim( $this->_getCatPathString() );
00472 }
00473
00474 if ( $sMeta ) {
00475 $sMeta = "{$sMeta} - {$sAddText}";
00476 } else {
00477 $sMeta = $sAddText;
00478 }
00479
00480 return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00481 }
00482
00491 protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00492 {
00493 $sKeywords = '';
00494 if ( ( $oCategory = $this->getActCategory() ) ) {
00495 $aKeywords = array();
00496
00497 if ( $oCatTree = $this->getCategoryTree() ) {
00498 foreach ( $oCatTree->getPath() as $oCat ) {
00499 $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00500 }
00501 }
00502
00503 if ( count( $aKeywords ) > 0 ) {
00504 $sKeywords = implode( ", ", $aKeywords );
00505 }
00506
00507 $aSubCats = $oCategory->getSubCats();
00508 if ( is_array( $aSubCats ) ) {
00509 foreach ( $aSubCats as $oSubCat ) {
00510 $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00511 }
00512 }
00513 }
00514
00515 $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00516
00517 return trim( $sKeywords );
00518 }
00519
00528 protected function _collectMetaKeyword( $sKeywords )
00529 {
00530 $iMaxTextLength = 60;
00531 $sText = '';
00532
00533 if ( count( $aArticleList = $this->getArticleList() ) ) {
00534 $oStr = getStr();
00535 foreach ( $aArticleList as $oProduct ) {
00536 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00537
00538
00539 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00540
00541 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00542 $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00543 $sDesc = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00544 }
00545 if ( $sText ) {
00546 $sText .= ', ';
00547 }
00548 $sText .= $sDesc;
00549 }
00550 }
00551
00552 if ( !$sKeywords ) {
00553 $sKeywords = $this->_getCatPathString();
00554 }
00555
00556 if ( $sKeywords ) {
00557 $sText = "{$sKeywords}, {$sText}";
00558 }
00559
00560 return parent::_prepareMetaKeyword( $sText );
00561 }
00562
00570 public function getTemplateName()
00571 {
00572
00573 if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00574 $this->_sThisTemplate = $sTplName;
00575 } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00576 $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00577 }
00578
00579 return $this->_sThisTemplate;
00580 }
00581
00591 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00592 {
00593 if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00594 if ( $iPage ) {
00595
00596 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00597 }
00598 } else {
00599 $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00600 }
00601 return $sUrl;
00602 }
00603
00609 protected function _isActCategory()
00610 {
00611 return $this->_blIsCat;
00612 }
00613
00619 public function generatePageNavigationUrl( )
00620 {
00621 if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00622 return $oCategory->getLink();
00623 }
00624 return parent::generatePageNavigationUrl( );
00625 }
00626
00634 public function getSorting( $sCnid )
00635 {
00636
00637 $aSorting = parent::getSorting( $sCnid );
00638 $oActCat = $this->getActCategory();
00639 if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00640 $sSortBy = getViewName( 'oxarticles' ).".{$oActCat->oxcategories__oxdefsort->value}";
00641 $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : null;
00642
00643 $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00644 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00645 }
00646 return $aSorting;
00647 }
00648
00654 public function getTitleSuffix()
00655 {
00656 if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00657 return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00658 }
00659 }
00660
00666 public function getTitlePageSuffix()
00667 {
00668 if ( ( $iPage = $this->getActPage() ) ) {
00669 return oxLang::getInstance()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00670 }
00671 }
00672
00681 protected function _getSubject( $iLang )
00682 {
00683 return $this->getActCategory();
00684 }
00685
00692 public function getAttributes()
00693 {
00694 $this->_aAttributes = false;
00695 if ( ( $oCategory = $this->getActCategory() ) ) {
00696 $aAttributes = $oCategory->getAttributes();
00697 if ( count( $aAttributes ) ) {
00698 $this->_aAttributes = $aAttributes;
00699 }
00700 }
00701
00702 return $this->_aAttributes;
00703 }
00704
00710 public function getArticleList()
00711 {
00712 if ( $this->_aArticleList === null ) {
00713 if ( ( $oCategory = $this->getActCategory() ) ) {
00714 $aArticleList = $this->_loadArticles( $oCategory );
00715 if ( count( $aArticleList ) ) {
00716 $this->_aArticleList = $aArticleList;
00717 }
00718 }
00719 }
00720
00721 return $this->_aArticleList;
00722 }
00723
00729 public function getSimilarRecommLists()
00730 {
00731 if (!$this->getViewConfig()->getShowListmania()) {
00732 return false;
00733 }
00734
00735 if ( $this->_oRecommList === null ) {
00736 $this->_oRecommList = false;
00737 if ( $aCatArtList = $this->getArticleList() ) {
00738 $oRecommList = oxNew('oxrecommlist');
00739 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00740 }
00741 }
00742 return $this->_oRecommList;
00743 }
00744
00750 public function getCatTreePath()
00751 {
00752 if ( $this->_sCatTreePath === null ) {
00753 $this->_sCatTreePath = false;
00754
00755 if ( $oCatTree = $this->getCategoryTree() ) {
00756 $this->_sCatTreePath = $oCatTree->getPath();
00757 }
00758 }
00759 return $this->_sCatTreePath;
00760 }
00761
00767 public function getTreePath()
00768 {
00769 if ( $oCatTree = $this->getCategoryTree() ) {
00770 return $oCatTree->getPath();
00771 }
00772 }
00773
00779 public function getBreadCrumb()
00780 {
00781 $aPaths = array();
00782
00783 if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00784
00785 $aPaths[]['title'] = oxLang::getInstance()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxLang::getInstance()->getBaseLanguage(), false );
00786
00787 return $aPaths;
00788 }
00789
00790 if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00791 foreach ( $oCatPath as $oCat ) {
00792 $aCatPath = array();
00793
00794 $aCatPath['link'] = $oCat->getLink();
00795 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00796
00797 $aPaths[] = $aCatPath;
00798 }
00799 }
00800
00801 return $aPaths;
00802 }
00803
00810 public function hasVisibleSubCats()
00811 {
00812 if ( $this->_blHasVisibleSubCats === null ) {
00813 $this->_blHasVisibleSubCats = false;
00814 if ( $oClickCat = $this->getActCategory() ) {
00815 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00816 }
00817 }
00818 return $this->_blHasVisibleSubCats;
00819 }
00820
00826 public function getSubCatList()
00827 {
00828 if ( $this->_aSubCatList === null ) {
00829 $this->_aSubCatList = array();
00830 if ( $oClickCat = $this->getActCategory() ) {
00831 $this->_aSubCatList = $oClickCat->getSubCats();
00832 }
00833 }
00834
00835 return $this->_aSubCatList;
00836 }
00837
00843 public function getPageNavigation()
00844 {
00845 if ( $this->_oPageNavigation === null ) {
00846 $this->_oPageNavigation = $this->generatePageNavigation();
00847 }
00848 return $this->_oPageNavigation;
00849 }
00850
00856 public function getTitle()
00857 {
00858 if ( $this->_sCatTitle === null ) {
00859 $this->_sCatTitle = false;
00860 if ( ( $oCategory = $this->getActCategory() ) ) {
00861 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00862 }
00863 }
00864 return $this->_sCatTitle;
00865 }
00866
00872 public function getTop5ArticleList()
00873 {
00874 if ( $this->_aTop5ArticleList === null ) {
00875 $this->_aTop5ArticleList = false;
00876 $myConfig = $this->getConfig();
00877 if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00878
00879 $oArtList = oxNew( 'oxarticlelist' );
00880 $oArtList->loadTop5Articles();
00881 if ( $oArtList->count() ) {
00882 $this->_aTop5ArticleList = $oArtList;
00883 }
00884 }
00885 }
00886 return $this->_aTop5ArticleList;
00887 }
00888
00894 public function getBargainArticleList()
00895 {
00896 if ( $this->_aBargainArticleList === null ) {
00897 $this->_aBargainArticleList = array();
00898 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00899 $oArtList = oxNew( 'oxarticlelist' );
00900 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00901 if ( $oArtList->count() ) {
00902 $this->_aBargainArticleList = $oArtList;
00903 }
00904 }
00905 }
00906 return $this->_aBargainArticleList;
00907 }
00908
00914 public function getActiveCategory()
00915 {
00916 return $this->getActCategory();
00917 }
00918
00924 public function getCanonicalUrl()
00925 {
00926 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00927 $oUtils = oxUtilsUrl::getInstance();
00928 if ( oxUtils::getInstance()->seoIsActive() ) {
00929 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00930 } else {
00931 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00932 }
00933 return $sUrl;
00934 }
00935 }
00936
00942 public function canSelectDisplayType()
00943 {
00944 return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00945 }
00946
00952 public function getPageCount()
00953 {
00954 return $this->_iCntPages;
00955 }
00956 }