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 = true;
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', true, 302 );
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->_blIsCat ) {
00187 $this->_checkRequestedPage();
00188 }
00189
00190 parent::render();
00191
00192
00193 $this->_processListArticles();
00194
00195 return $this->getTemplateName();
00196 }
00197
00206 protected function _checkRequestedPage()
00207 {
00208 $iPageCnt = $this->getPageCount();
00209
00210 if ( $iPageCnt && ( ( $iPageCnt - 1 ) < $this->getActPage() ) ) {
00211 oxUtils::getInstance()->redirect( $this->getActiveCategory()->getLink(), false );
00212 }
00213 }
00214
00221 protected function _processListArticles()
00222 {
00223 if ( $aArtList = $this->getArticleList() ) {
00224 $iLinkType = $this->_getProductLinkType();
00225 $sAddDynParams = $this->getAddUrlParams();
00226 $sAddSeoParams = $this->getAddSeoUrlParams();
00227
00228 foreach ( $aArtList as $oArticle ) {
00229 $oArticle->setLinkType( $iLinkType );
00230
00231
00232 if ( $sAddDynParams ) {
00233 $oArticle->appendStdLink( $sAddDynParams );
00234 }
00235
00236
00237 if ( $sAddSeoParams ) {
00238 $oArticle->appendLink( $sAddSeoParams );
00239 }
00240 }
00241 }
00242 }
00243
00244
00250 public function getAddUrlParams()
00251 {
00252 $sParams = parent::getAddUrlParams();
00253 if ( !oxUtils::getInstance()->seoIsActive() ) {
00254 $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
00255 if ( $iPgNr > 0 ) {
00256 $sParams .= ($sParams?'&':'') . "pgNr={$iPgNr}";
00257 }
00258 }
00259
00260 return $sParams;
00261 }
00262
00268 public function getAddSeoUrlParams()
00269 {
00270 }
00271
00279 protected function _getProductLinkType()
00280 {
00281 $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00282 if ( ( $oCat = $this->getActCategory() ) && $oCat->isPriceCategory() ) {
00283 $iCatType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00284 }
00285 return $iCatType;
00286 }
00287
00296 public function executefilter()
00297 {
00298 $iLang = oxLang::getInstance()->getBaseLanguage();
00299
00300 $aFilter = oxConfig::getParameter( 'attrfilter', 1 );
00301 $sActCat = oxConfig::getParameter( 'cnid' );
00302
00303 if ( !empty( $aFilter ) ) {
00304 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00305
00306
00307 $aSessionFilter[$sActCat] = null;
00308 $aSessionFilter[$sActCat][$iLang] = $aFilter;
00309 oxSession::setVar( 'session_attrfilter', $aSessionFilter );
00310 }
00311 }
00312
00320 protected function _loadArticles( $oCategory )
00321 {
00322 $myConfig = $this->getConfig();
00323
00324 $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
00325 $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
00326
00327
00328 $oArtList = oxNew( 'oxarticlelist' );
00329 $oArtList->setSqlLimit( $iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles );
00330 $oArtList->setCustomSorting( $this->getSortingSql( $oCategory->getId() ) );
00331
00332 if ( $oCategory->isPriceCategory() ) {
00333 $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00334 $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
00335
00336 $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
00337 } else {
00338 $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00339
00340 $sActCat = oxConfig::getParameter( 'cnid' );
00341 $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
00342 }
00343
00344 $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
00345
00346 return $oArtList;
00347 }
00348
00354 public function getActPage()
00355 {
00356 return $this->_getRequestPageNr();
00357 }
00358
00367 protected function _getRequestPageNr()
00368 {
00369 return parent::getActPage();
00370 }
00371
00377 protected function _getSeoObjectId()
00378 {
00379 if ( ( $oCategory = $this->getActCategory() ) ) {
00380 return $oCategory->getId();
00381 }
00382 }
00383
00389 protected function _getCatPathString()
00390 {
00391 if ( $this->_sCatPathString === null ) {
00392
00393
00394 $this->_sCatPathString = false;
00395
00396
00397 if ( is_array( $aPath = $this->getCatTreePath() ) ) {
00398
00399 $oStr = getStr();
00400 $this->_sCatPathString = '';
00401 foreach ( $aPath as $oCat ) {
00402 if ( $this->_sCatPathString ) {
00403 $this->_sCatPathString .= ', ';
00404 }
00405 $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
00406 }
00407 }
00408 }
00409 return $this->_sCatPathString;
00410 }
00411
00421 protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00422 {
00423
00424 $sDescription = oxLang::getInstance()->translateString( 'ALIST_META_DESCRIPTION_PREFIX' );
00425
00426
00427 if ( $oCategory = $this->getActCategory() ) {
00428 if ( ( $oParent = $oCategory->getParentCategory() ) ) {
00429 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00430 }
00431
00432
00433 $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00434 }
00435
00436
00437 if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxstarttitle->value ) ) {
00438 $sDescription .= " {$sSuffix}";
00439 }
00440
00441
00442 $sDescription = getStr()->cleanStr($sDescription);
00443 $sDescription = strip_tags( getStr()->html_entity_decode( $sDescription ) );
00444 $sDescription = getStr()->htmlspecialchars( $sDescription );
00445 return trim( $sDescription );
00446 }
00447
00453 public function getMetaDescription()
00454 {
00455 $sMeta = parent::getMetaDescription();
00456
00457 if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
00458 if ( $sMeta ) {
00459 $sMeta .= ", ";
00460 }
00461 $sMeta .= $sTitlePageSuffix;
00462 }
00463
00464 return $sMeta;
00465 }
00466
00479 protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
00480 {
00481
00482 $sAddText = ( $oCategory = $this->getActCategory() ) ? trim( $oCategory->getLongDesc() ):'';
00483 $aArticleList = $this->getArticleList();
00484 if ( !$sAddText && count($aArticleList)) {
00485 foreach ( $aArticleList as $oArticle ) {
00486 if ( $sAddText ) {
00487 $sAddText .= ', ';
00488 }
00489 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00490 }
00491 }
00492
00493 if ( !$sMeta ) {
00494 $sMeta = trim( $this->_getCatPathString() );
00495 }
00496
00497 if ( $sMeta ) {
00498 $sMeta = "{$sMeta} - {$sAddText}";
00499 } else {
00500 $sMeta = $sAddText;
00501 }
00502
00503 return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00504 }
00505
00514 protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00515 {
00516 $sKeywords = '';
00517 if ( ( $oCategory = $this->getActCategory() ) ) {
00518 $aKeywords = array();
00519
00520 if ( $oCatTree = $this->getCategoryTree() ) {
00521 foreach ( $oCatTree->getPath() as $oCat ) {
00522 $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
00523 }
00524 }
00525
00526 if ( count( $aKeywords ) > 0 ) {
00527 $sKeywords = implode( ", ", $aKeywords );
00528 }
00529
00530 $aSubCats = $oCategory->getSubCats();
00531 if ( is_array( $aSubCats ) ) {
00532 foreach ( $aSubCats as $oSubCat ) {
00533 $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
00534 }
00535 }
00536 }
00537
00538 $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
00539
00540 return trim( $sKeywords );
00541 }
00542
00551 protected function _collectMetaKeyword( $sKeywords )
00552 {
00553 $iMaxTextLength = 60;
00554 $sText = '';
00555
00556 if ( count( $aArticleList = $this->getArticleList() ) ) {
00557 $oStr = getStr();
00558 foreach ( $aArticleList as $oProduct ) {
00559 $sDesc = strip_tags( trim( $oStr->strtolower( $oProduct->getArticleLongDesc()->value ) ) );
00560
00561
00562 $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
00563
00564 if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
00565 $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
00566 $sDesc = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
00567 }
00568 if ( $sText ) {
00569 $sText .= ', ';
00570 }
00571 $sText .= $sDesc;
00572 }
00573 }
00574
00575 if ( !$sKeywords ) {
00576 $sKeywords = $this->_getCatPathString();
00577 }
00578
00579 if ( $sKeywords ) {
00580 $sText = "{$sKeywords}, {$sText}";
00581 }
00582
00583 return parent::_prepareMetaKeyword( $sText );
00584 }
00585
00593 public function getTemplateName()
00594 {
00595
00596 if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
00597 $this->_sThisTemplate = $sTplName;
00598 } elseif ( ( $oCategory = $this->getActCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
00599 $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00600 }
00601
00602 return $this->_sThisTemplate;
00603 }
00604
00614 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00615 {
00616 if ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) {
00617 if ( $iPage ) {
00618
00619 $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
00620 }
00621 } else {
00622 $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
00623 }
00624 return $sUrl;
00625 }
00626
00632 protected function _isActCategory()
00633 {
00634 return $this->_blIsCat;
00635 }
00636
00642 public function generatePageNavigationUrl( )
00643 {
00644 if ( ( oxUtils::getInstance()->seoIsActive() && ( $oCategory = $this->getActCategory() ) ) ) {
00645 return $oCategory->getLink();
00646 }
00647 return parent::generatePageNavigationUrl( );
00648 }
00649
00657 public function getSorting( $sCnid )
00658 {
00659
00660 $aSorting = parent::getSorting( $sCnid );
00661 $oActCat = $this->getActCategory();
00662 if ( !$aSorting && $oActCat && $oActCat->oxcategories__oxdefsort->value ) {
00663 $sSortBy = $oActCat->oxcategories__oxdefsort->value;
00664 $sSortDir = ( $oActCat->oxcategories__oxdefsortmode->value ) ? "desc" : null;
00665
00666 $this->setItemSorting( $sCnid, $sSortBy, $sSortDir );
00667 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
00668 }
00669 return $aSorting;
00670 }
00671
00677 public function getTitleSuffix()
00678 {
00679 if ( $this->getActCategory()->oxcategories__oxshowsuffix->value ) {
00680 return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00681 }
00682 }
00683
00689 public function getTitlePageSuffix()
00690 {
00691 if ( ( $iPage = $this->getActPage() ) ) {
00692 return oxLang::getInstance()->translateString( 'INC_HEADER_TITLEPAGE' ). ( $iPage + 1 );
00693 }
00694 }
00695
00704 protected function _getSubject( $iLang )
00705 {
00706 return $this->getActCategory();
00707 }
00708
00715 public function getAttributes()
00716 {
00717 $this->_aAttributes = false;
00718 if ( ( $oCategory = $this->getActCategory() ) ) {
00719 $aAttributes = $oCategory->getAttributes();
00720 if ( count( $aAttributes ) ) {
00721 $this->_aAttributes = $aAttributes;
00722 }
00723 }
00724
00725 return $this->_aAttributes;
00726 }
00727
00733 public function getArticleList()
00734 {
00735 if ( $this->_aArticleList === null ) {
00736 if ( ( $oCategory = $this->getActCategory() ) ) {
00737 $aArticleList = $this->_loadArticles( $oCategory );
00738 if ( count( $aArticleList ) ) {
00739 $this->_aArticleList = $aArticleList;
00740 }
00741 }
00742 }
00743
00744 return $this->_aArticleList;
00745 }
00746
00752 public function getArticleCount()
00753 {
00754 return $this->_iAllArtCnt;
00755 }
00756
00762 public function getSimilarRecommLists()
00763 {
00764 if (!$this->getViewConfig()->getShowListmania()) {
00765 return false;
00766 }
00767
00768 if ( $this->_oRecommList === null ) {
00769 $this->_oRecommList = false;
00770 if ( $aCatArtList = $this->getArticleList() ) {
00771 $oRecommList = oxNew('oxrecommlist');
00772 $this->_oRecommList = $oRecommList->getRecommListsByIds( $aCatArtList->arrayKeys());
00773 }
00774 }
00775 return $this->_oRecommList;
00776 }
00777
00783 public function getCatTreePath()
00784 {
00785 if ( $this->_sCatTreePath === null ) {
00786 $this->_sCatTreePath = false;
00787
00788 if ( $oCatTree = $this->getCategoryTree() ) {
00789 $this->_sCatTreePath = $oCatTree->getPath();
00790 }
00791 }
00792 return $this->_sCatTreePath;
00793 }
00794
00800 public function getTreePath()
00801 {
00802 if ( $oCatTree = $this->getCategoryTree() ) {
00803 return $oCatTree->getPath();
00804 }
00805 }
00806
00812 public function getBreadCrumb()
00813 {
00814 $aPaths = array();
00815
00816 if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
00817 $aPath = array();
00818 $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_PRODUCT_MORECATEGORIES', oxLang::getInstance()->getBaseLanguage(), false );
00819 $aPath['link'] = $this->getLink();
00820
00821 $aPaths[] = $aPath;
00822
00823 return $aPaths;
00824 }
00825
00826 if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
00827 foreach ( $oCatPath as $oCat ) {
00828 $aCatPath = array();
00829
00830 $aCatPath['link'] = $oCat->getLink();
00831 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00832
00833 $aPaths[] = $aCatPath;
00834 }
00835 }
00836
00837 return $aPaths;
00838 }
00839
00846 public function hasVisibleSubCats()
00847 {
00848 if ( $this->_blHasVisibleSubCats === null ) {
00849 $this->_blHasVisibleSubCats = false;
00850 if ( $oClickCat = $this->getActCategory() ) {
00851 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00852 }
00853 }
00854 return $this->_blHasVisibleSubCats;
00855 }
00856
00862 public function getSubCatList()
00863 {
00864 if ( $this->_aSubCatList === null ) {
00865 $this->_aSubCatList = array();
00866 if ( $oClickCat = $this->getActCategory() ) {
00867 $this->_aSubCatList = $oClickCat->getSubCats();
00868 }
00869 }
00870
00871 return $this->_aSubCatList;
00872 }
00873
00879 public function getPageNavigation()
00880 {
00881 if ( $this->_oPageNavigation === null ) {
00882 $this->_oPageNavigation = $this->generatePageNavigation();
00883 }
00884 return $this->_oPageNavigation;
00885 }
00886
00892 public function getTitle()
00893 {
00894 if ( $this->_sCatTitle === null ) {
00895 $this->_sCatTitle = false;
00896 if ( ( $oCategory = $this->getActCategory() ) ) {
00897 $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
00898 }
00899 }
00900 return $this->_sCatTitle;
00901 }
00902
00908 public function getTop5ArticleList()
00909 {
00910 if ( $this->_aTop5ArticleList === null ) {
00911 $this->_aTop5ArticleList = false;
00912 $myConfig = $this->getConfig();
00913 if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00914
00915 $oArtList = oxNew( 'oxarticlelist' );
00916 $oArtList->loadTop5Articles();
00917 if ( $oArtList->count() ) {
00918 $this->_aTop5ArticleList = $oArtList;
00919 }
00920 }
00921 }
00922 return $this->_aTop5ArticleList;
00923 }
00924
00930 public function getBargainArticleList()
00931 {
00932 if ( $this->_aBargainArticleList === null ) {
00933 $this->_aBargainArticleList = array();
00934 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
00935 $oArtList = oxNew( 'oxarticlelist' );
00936 $oArtList->loadAktionArticles( 'OXBARGAIN' );
00937 if ( $oArtList->count() ) {
00938 $this->_aBargainArticleList = $oArtList;
00939 }
00940 }
00941 }
00942 return $this->_aBargainArticleList;
00943 }
00944
00950 public function getActiveCategory()
00951 {
00952 return $this->getActCategory();
00953 }
00954
00960 public function getCanonicalUrl()
00961 {
00962 if ( ( $oCategory = $this->getActiveCategory() ) ) {
00963 $oUtils = oxUtilsUrl::getInstance();
00964 if ( oxUtils::getInstance()->seoIsActive() ) {
00965 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
00966 } else {
00967 $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
00968 }
00969 return $sUrl;
00970 }
00971 }
00972
00978 public function canSelectDisplayType()
00979 {
00980 return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
00981 }
00982
00988 public function getPageCount()
00989 {
00990 return $this->_iCntPages;
00991 }
00992
00998 public function isMoreTagsVisible()
00999 {
01000 return true;
01001 }
01002 }