alist.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class aList extends oxUBase
00010 {
00011 
00017     protected $_iAllArtCnt = 0;
00018 
00024     protected $_iCntPages = 0;
00025 
00031     protected $_sThisTemplate = 'page/list/list.tpl';
00032 
00038     protected $_sThisMoreTemplate = 'page/list/morecategories.tpl';
00039 
00045     protected $_sCatPathString = null;
00046 
00052     protected $_blShowSorting = true;
00053 
00059     protected $_aAttributes = null;
00060 
00066     protected $_aCatArtList = null;
00067 
00073     protected $_blHasVisibleSubCats = null;
00074 
00080     protected $_aSubCatList = null;
00081 
00087     protected $_oPageNavigation = null;
00088 
00094     protected $_blIsCat = null;
00095 
00101     protected $_oRecommList = null;
00102 
00108     protected $_sCatTitle = null;
00109 
00115     protected $_blShowTagCloud = true;
00116 
00122     protected $_blBargainAction = false;
00123 
00129     protected $_aSimilarRecommListIds = null;
00130 
00131 
00138     public function getViewId()
00139     {
00140         if (!isset($this->_sViewId)) {
00141             $sCatId = oxRegistry::getConfig()->getRequestParameter('cnid');
00142             $iActPage = $this->getActPage();
00143             $iArtPerPage = oxRegistry::getSession()->getVariable('_artperpage');
00144             $sListDisplayType = $this->_getListDisplayType();
00145             $sParentViewId = parent::getViewId();
00146 
00147             // shorten it
00148             $this->_sViewId = md5(
00149                 $sParentViewId . '|' . $sCatId . '|' . $iActPage . '|' . $iArtPerPage . '|' . $sListDisplayType
00150             );
00151 
00152         }
00153 
00154         return $this->_sViewId;
00155     }
00156 
00169     public function render()
00170     {
00171         $myConfig = $this->getConfig();
00172 
00173         $oCategory = null;
00174         $blContinue = true;
00175         $this->_blIsCat = false;
00176 
00177         // A. checking for fake "more" category
00178         if ('oxmore' == $myConfig->getRequestParameter('cnid')) {
00179             // overriding some standard value and parameters
00180             $this->_sThisTemplate = $this->_sThisMoreTemplate;
00181             $oCategory = oxNew('oxcategory');
00182             $oCategory->oxcategories__oxactive = new oxField(1, oxField::T_RAW);
00183             $this->setActiveCategory($oCategory);
00184 
00185             $this->_blShowTagCloud = true;
00186 
00187         } elseif (($oCategory = $this->getActiveCategory())) {
00188             $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
00189             $this->_blIsCat = true;
00190             $this->_blBargainAction = true;
00191         }
00192 
00193 
00194         // category is inactive ?
00195         if (!$blContinue || !$oCategory) {
00196             oxRegistry::getUtils()->redirect($myConfig->getShopURL() . 'index.php', true, 302);
00197         }
00198 
00199         $oCat = $this->getActiveCategory();
00200         if ($oCat && $myConfig->getConfigParam('bl_rssCategories')) {
00201             $oRss = oxNew('oxrssfeed');
00202             $this->addRssFeed(
00203                 $oRss->getCategoryArticlesTitle($oCat),
00204                 $oRss->getCategoryArticlesUrl($oCat),
00205                 'activeCategory'
00206             );
00207         }
00208 
00209         //checking if actual pages count does not exceed real articles page count
00210         $this->getArticleList();
00211 
00212         if ($this->_blIsCat) {
00213             $this->_checkRequestedPage();
00214         }
00215 
00216         parent::render();
00217 
00218         // processing list articles
00219         $this->_processListArticles();
00220 
00221         return $this->getTemplateName();
00222     }
00223 
00230     protected function _checkRequestedPage()
00231     {
00232         $iPageCnt = $this->getPageCount();
00233         // redirecting to first page in case requested page does not exist
00234         if ($iPageCnt && (($iPageCnt - 1) < $this->getActPage())) {
00235             oxRegistry::getUtils()->redirect($this->getActiveCategory()->getLink(), false);
00236         }
00237     }
00238 
00243     protected function _processListArticles()
00244     {
00245         if ($aArtList = $this->getArticleList()) {
00246             $iLinkType = $this->_getProductLinkType();
00247             $sAddDynParams = $this->getAddUrlParams();
00248             $sAddSeoParams = $this->getAddSeoUrlParams();
00249 
00250             foreach ($aArtList as $oArticle) {
00251                 $oArticle->setLinkType($iLinkType);
00252 
00253                 // appending dynamic urls
00254                 if ($sAddDynParams) {
00255                     $oArticle->appendStdLink($sAddDynParams);
00256                 }
00257 
00258                 // appending seo urls
00259                 if ($sAddSeoParams) {
00260                     $oArticle->appendLink($sAddSeoParams);
00261                 }
00262             }
00263         }
00264     }
00265 
00266 
00272     public function getAddUrlParams()
00273     {
00274         $sParams = parent::getAddUrlParams();
00275         if (!oxRegistry::getUtils()->seoIsActive()) {
00276             $iPgNr = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
00277             if ($iPgNr > 0) {
00278                 $sParams .= ($sParams ? '&amp;' : '') . "pgNr={$iPgNr}";
00279             }
00280         }
00281 
00282         return $sParams;
00283     }
00284 
00288     public function getAddSeoUrlParams()
00289     {
00290     }
00291 
00299     protected function _getProductLinkType()
00300     {
00301         $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
00302         if (($oCat = $this->getActiveCategory()) && $oCat->isPriceCategory()) {
00303             $iCatType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00304         }
00305 
00306         return $iCatType;
00307     }
00308 
00315     public function executefilter()
00316     {
00317         $iLang = oxRegistry::getLang()->getBaseLanguage();
00318         // store this into session
00319         $aFilter = oxRegistry::getConfig()->getRequestParameter('attrfilter', true);
00320         $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
00321 
00322         if (!empty($aFilter)) {
00323             $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
00324             //fix for #2904 - if language will be changed attributes of this category will be deleted from session
00325             //and new filters for active language set.
00326             $aSessionFilter[$sActCat] = null;
00327             $aSessionFilter[$sActCat][$iLang] = $aFilter;
00328             oxRegistry::getSession()->setVariable('session_attrfilter', $aSessionFilter);
00329         }
00330     }
00331 
00339     protected function _loadArticles($oCategory)
00340     {
00341         $myConfig = $this->getConfig();
00342 
00343         $iNrofCatArticles = (int) $myConfig->getConfigParam('iNrofCatArticles');
00344         $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
00345 
00346         // load only articles which we show on screen
00347         $oArtList = oxNew('oxarticlelist');
00348         $oArtList->setSqlLimit($iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles);
00349         $oArtList->setCustomSorting($this->getSortingSql($this->getSortIdent()));
00350 
00351         if ($oCategory->isPriceCategory()) {
00352             $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
00353             $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
00354 
00355             $this->_iAllArtCnt = $oArtList->loadPriceArticles($dPriceFrom, $dPriceTo, $oCategory);
00356         } else {
00357             $aSessionFilter = oxRegistry::getSession()->getVariable('session_attrfilter');
00358 
00359             $sActCat = oxRegistry::getConfig()->getRequestParameter('cnid');
00360             $this->_iAllArtCnt = $oArtList->loadCategoryArticles($sActCat, $aSessionFilter);
00361         }
00362 
00363         $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
00364 
00365         return $oArtList;
00366     }
00367 
00373     public function getActPage()
00374     {
00375         return $this->_getRequestPageNr();
00376     }
00377 
00386     protected function _getRequestPageNr()
00387     {
00388         return parent::getActPage();
00389     }
00390 
00396     protected function _getListDisplayType()
00397     {
00398         $sListDisplayType = oxRegistry::getSession()->getVariable('ldtype');
00399 
00400         if (is_null($sListDisplayType)) {
00401             $sListDisplayType = oxRegistry::getConfig()->getConfigParam('sDefaultListDisplayType');
00402         }
00403 
00404         return $sListDisplayType;
00405     }
00406 
00412     protected function _getSeoObjectId()
00413     {
00414         if (($oCategory = $this->getActiveCategory())) {
00415             return $oCategory->getId();
00416         }
00417     }
00418 
00424     protected function _getCatPathString()
00425     {
00426         if ($this->_sCatPathString === null) {
00427 
00428             // marking as already set
00429             $this->_sCatPathString = false;
00430 
00431             //fetching category path
00432             if (is_array($aPath = $this->getCatTreePath())) {
00433 
00434                 $oStr = getStr();
00435                 $this->_sCatPathString = '';
00436                 foreach ($aPath as $oCat) {
00437                     if ($this->_sCatPathString) {
00438                         $this->_sCatPathString .= ', ';
00439                     }
00440                     $this->_sCatPathString .= $oStr->strtolower($oCat->oxcategories__oxtitle->value);
00441                 }
00442             }
00443         }
00444 
00445         return $this->_sCatPathString;
00446     }
00447 
00457     protected function _prepareMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
00458     {
00459         $sDescription = '';
00460         // appending parent title
00461         if ($oCategory = $this->getActiveCategory()) {
00462             if (($oParent = $oCategory->getParentCategory())) {
00463                 $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
00464             }
00465 
00466             // adding category title
00467             $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
00468         }
00469 
00470         // and final component ..
00471         //changed for #2776
00472         if (($sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value)) {
00473             $sDescription .= " {$sSuffix}";
00474         }
00475 
00476         // making safe for output
00477         $sDescription = getStr()->html_entity_decode($sDescription);
00478         $sDescription = getStr()->strip_tags($sDescription);
00479         $sDescription = getStr()->cleanStr($sDescription);
00480         $sDescription = getStr()->htmlspecialchars($sDescription);
00481 
00482         return trim($sDescription);
00483     }
00484 
00490     public function getMetaDescription()
00491     {
00492         $sMeta = parent::getMetaDescription();
00493 
00494         if ($sTitlePageSuffix = $this->getTitlePageSuffix()) {
00495             if ($sMeta) {
00496                 $sMeta .= ", ";
00497             }
00498             $sMeta .= $sTitlePageSuffix;
00499         }
00500 
00501         return $sMeta;
00502     }
00503 
00516     protected function _collectMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
00517     {
00518         //formatting description tag
00519         $oCategory = $this->getActiveCategory();
00520 
00521         $sAddText = (($oCategory instanceof oxCategory)) ? trim($oCategory->getLongDesc()) : '';
00522 
00523         $aArticleList = $this->getArticleList();
00524         if (!$sAddText && count($aArticleList)) {
00525             foreach ($aArticleList as $oArticle) {
00526                 if ($sAddText) {
00527                     $sAddText .= ', ';
00528                 }
00529                 $sAddText .= $oArticle->oxarticles__oxtitle->value;
00530             }
00531         }
00532 
00533         if (!$sMeta) {
00534             $sMeta = trim($this->_getCatPathString());
00535         }
00536 
00537         if ($sMeta) {
00538             $sMeta = "{$sMeta} - {$sAddText}";
00539         } else {
00540             $sMeta = $sAddText;
00541         }
00542 
00543         return parent::_prepareMetaDescription($sMeta, $iLength, $blDescTag);
00544     }
00545 
00554     protected function _prepareMetaKeyword($sKeywords, $blRemoveDuplicatedWords = true)
00555     {
00556         $sKeywords = '';
00557         if (($oCategory = $this->getActiveCategory())) {
00558             $aKeywords = array();
00559 
00560             if ($oCatTree = $this->getCategoryTree()) {
00561                 foreach ($oCatTree->getPath() as $oCat) {
00562                     $aKeywords[] = trim($oCat->oxcategories__oxtitle->value);
00563                 }
00564             }
00565 
00566             if (count($aKeywords) > 0) {
00567                 $sKeywords = implode(", ", $aKeywords);
00568             }
00569 
00570             $aSubCats = $oCategory->getSubCats();
00571             if (is_array($aSubCats)) {
00572                 foreach ($aSubCats as $oSubCat) {
00573                     $sKeywords .= ', ' . $oSubCat->oxcategories__oxtitle->value;
00574                 }
00575             }
00576         }
00577 
00578         $sKeywords = parent::_prepareMetaDescription($sKeywords, -1, $blRemoveDuplicatedWords);
00579 
00580         return trim($sKeywords);
00581     }
00582 
00591     protected function _collectMetaKeyword($sKeywords)
00592     {
00593         $iMaxTextLength = 60;
00594         $sText = '';
00595 
00596         if (count($aArticleList = $this->getArticleList())) {
00597             $oStr = getStr();
00598             foreach ($aArticleList as $oProduct) {
00599                 $sDesc = $oStr->strip_tags(trim($oStr->strtolower($oProduct->getLongDescription()->value)));
00600 
00601                 //removing dots from string (they are not cleaned up during general string cleanup)
00602                 $sDesc = $oStr->preg_replace("/\./", " ", $sDesc);
00603 
00604                 if ($oStr->strlen($sDesc) > $iMaxTextLength) {
00605                     $sMidText = $oStr->substr($sDesc, 0, $iMaxTextLength);
00606                     $sDesc = $oStr->substr(
00607                         $sMidText,
00608                         0,
00609                         ($oStr->strlen($sMidText) - $oStr->strpos(strrev($sMidText), ' '))
00610                     );
00611                 }
00612                 if ($sText) {
00613                     $sText .= ', ';
00614                 }
00615                 $sText .= $sDesc;
00616             }
00617         }
00618 
00619         if (!$sKeywords) {
00620             $sKeywords = $this->_getCatPathString();
00621         }
00622 
00623         if ($sKeywords) {
00624             $sText = "{$sKeywords}, {$sText}";
00625         }
00626 
00627         return parent::_prepareMetaKeyword($sText);
00628     }
00629 
00637     public function getTemplateName()
00638     {
00639         // assign template name
00640         if (($sTplName = basename(oxRegistry::getConfig()->getRequestParameter('tpl')))) {
00641             $this->_sThisTemplate = 'custom/' . $sTplName;
00642         } elseif (($oCategory = $this->getActiveCategory()) && $oCategory->oxcategories__oxtemplate->value) {
00643             $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
00644         }
00645 
00646         return $this->_sThisTemplate;
00647     }
00648 
00658     protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
00659     {
00660         if (oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory())) {
00661             if ($iPage) {
00662                 // only if page number > 0
00663                 $sUrl = $oCategory->getBaseSeoLink($iLang, $iPage);
00664             }
00665         } else {
00666             $sUrl = parent::_addPageNrParam($sUrl, $iPage, $iLang);
00667         }
00668 
00669         return $sUrl;
00670     }
00671 
00677     protected function _isActCategory()
00678     {
00679         return $this->_blIsCat;
00680     }
00681 
00687     public function generatePageNavigationUrl()
00688     {
00689         if ((oxRegistry::getUtils()->seoIsActive() && ($oCategory = $this->getActiveCategory()))) {
00690             return $oCategory->getLink();
00691         }
00692 
00693         return parent::generatePageNavigationUrl();
00694     }
00695 
00701     public function getDefaultSorting()
00702     {
00703         $aSorting = parent::getDefaultSorting();
00704 
00705         $oCategory = $this->getActiveCategory();
00706         if ($oCategory && $oCategory instanceof oxCategory) {
00707             if ($sDefaultSorting = $oCategory->getDefaultSorting()) {
00708                 $sArticleTable = getViewName('oxarticles');
00709                 $sSortBy = $sArticleTable . '.' . $sDefaultSorting;
00710                 $sSortDir = ($oCategory->getDefaultSortingMode()) ? "desc" : "asc";
00711                 $aSorting = array('sortby' => $sSortBy, 'sortdir' => $sSortDir);
00712             }
00713         }
00714 
00715         return $aSorting;
00716     }
00717 
00718 
00724     public function getTitleSuffix()
00725     {
00726         if ($this->getActiveCategory()->oxcategories__oxshowsuffix->value) {
00727             return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
00728         }
00729     }
00730 
00736     public function getTitlePageSuffix()
00737     {
00738         if (($iPage = $this->getActPage())) {
00739             return oxRegistry::getLang()->translateString('PAGE') . " " . ($iPage + 1);
00740         }
00741     }
00742 
00751     protected function _getSubject($iLang)
00752     {
00753         return $this->getActiveCategory();
00754     }
00755 
00762     public function getAttributes()
00763     {
00764         $this->_aAttributes = false;
00765 
00766         if (($oCategory = $this->getActiveCategory())) {
00767             $aAttributes = $oCategory->getAttributes();
00768             if (count($aAttributes)) {
00769                 $this->_aAttributes = $aAttributes;
00770             }
00771         }
00772 
00773         return $this->_aAttributes;
00774     }
00775 
00781     public function getArticleList()
00782     {
00783         if ($this->_aArticleList === null) {
00784             if ($oCategory = $this->getActiveCategory()) {
00785                 $aArticleList = $this->_loadArticles($oCategory);
00786                 if (count($aArticleList)) {
00787                     $this->_aArticleList = $aArticleList;
00788                 }
00789             }
00790         }
00791 
00792         return $this->_aArticleList;
00793     }
00794 
00800     public function getArticleCount()
00801     {
00802         return $this->_iAllArtCnt;
00803     }
00804 
00810     public function getSimilarRecommListIds()
00811     {
00812         if ($this->_aSimilarRecommListIds === null) {
00813             $this->_aSimilarRecommListIds = false;
00814 
00815             if ($aCatArtList = $this->getArticleList()) {
00816                 $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
00817             }
00818         }
00819 
00820         return $this->_aSimilarRecommListIds;
00821     }
00822 
00828     public function getCatTreePath()
00829     {
00830         if ($this->_sCatTreePath === null) {
00831             $this->_sCatTreePath = false;
00832             // category path
00833             if ($oCatTree = $this->getCategoryTree()) {
00834                 $this->_sCatTreePath = $oCatTree->getPath();
00835             }
00836         }
00837 
00838         return $this->_sCatTreePath;
00839     }
00840 
00846     public function getTreePath()
00847     {
00848         if ($oCatTree = $this->getCategoryTree()) {
00849             return $oCatTree->getPath();
00850         }
00851     }
00852 
00858     public function getBreadCrumb()
00859     {
00860         $aPaths = array();
00861 
00862         if ('oxmore' == oxRegistry::getConfig()->getRequestParameter('cnid')) {
00863             $aPath = array();
00864             $aPath['title'] = oxRegistry::getLang()->translateString(
00865                 'CATEGORY_OVERVIEW',
00866                 oxRegistry::getLang()->getBaseLanguage(),
00867                 false
00868             );
00869             $aPath['link'] = $this->getLink();
00870 
00871             $aPaths[] = $aPath;
00872 
00873             return $aPaths;
00874         }
00875 
00876         if (($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath())) {
00877             foreach ($oCatPath as $oCat) {
00878                 $aCatPath = array();
00879 
00880                 $aCatPath['link'] = $oCat->getLink();
00881                 $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
00882 
00883                 $aPaths[] = $aCatPath;
00884             }
00885         }
00886 
00887         return $aPaths;
00888     }
00889 
00896     public function hasVisibleSubCats()
00897     {
00898         if ($this->_blHasVisibleSubCats === null) {
00899             $this->_blHasVisibleSubCats = false;
00900             if ($oClickCat = $this->getActiveCategory()) {
00901                 $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
00902             }
00903         }
00904 
00905         return $this->_blHasVisibleSubCats;
00906     }
00907 
00913     public function getSubCatList()
00914     {
00915         if ($this->_aSubCatList === null) {
00916             $this->_aSubCatList = array();
00917             if ($oClickCat = $this->getActiveCategory()) {
00918                 $this->_aSubCatList = $oClickCat->getSubCats();
00919             }
00920         }
00921 
00922         return $this->_aSubCatList;
00923     }
00924 
00930     public function getPageNavigation()
00931     {
00932         if ($this->_oPageNavigation === null) {
00933             $this->_oPageNavigation = $this->generatePageNavigation();
00934         }
00935 
00936         return $this->_oPageNavigation;
00937     }
00938 
00944     public function getTitle()
00945     {
00946         if ($this->_sCatTitle === null) {
00947             $this->_sCatTitle = false;
00948             if ($this->getCategoryId() == 'oxmore') {
00949                 $oLang = oxRegistry::getLang();
00950                 $iBaseLanguage = $oLang->getBaseLanguage();
00951 
00952                 $this->_sCatTitle = $oLang->translateString('CATEGORY_OVERVIEW', $iBaseLanguage, false);
00953             } elseif (($oCategory = $this->getActiveCategory())) {
00954                 $sTitleField = 'oxcategories__oxtitle';
00955                 $this->_sCatTitle = $oCategory->$sTitleField->value;
00956             }
00957         }
00958 
00959         return $this->_sCatTitle;
00960     }
00961 
00967     public function getBargainArticleList()
00968     {
00969         if ($this->_aBargainArticleList === null) {
00970             $this->_aBargainArticleList = array();
00971             if ($this->getConfig()->getConfigParam('bl_perfLoadAktion') && $this->_isActCategory()) {
00972                 $oArtList = oxNew('oxarticlelist');
00973                 $oArtList->loadActionArticles('OXBARGAIN');
00974                 if ($oArtList->count()) {
00975                     $this->_aBargainArticleList = $oArtList;
00976                 }
00977             }
00978         }
00979 
00980         return $this->_aBargainArticleList;
00981     }
00982 
00988     public function getActiveCategory()
00989     {
00990         if ($this->_oActCategory === null) {
00991             $this->_oActCategory = false;
00992             $oCategory = oxNew('oxCategory');
00993             if ($oCategory->load($this->getCategoryId())) {
00994                 $this->_oActCategory = $oCategory;
00995             }
00996         }
00997 
00998         return $this->_oActCategory;
00999     }
01000 
01006     public function getCanonicalUrl()
01007     {
01008         if (($oCategory = $this->getActiveCategory())) {
01009             $oUtils = oxRegistry::get("oxUtilsUrl");
01010             if (oxRegistry::getUtils()->seoIsActive()) {
01011                 $sUrl = $oUtils->prepareCanonicalUrl(
01012                     $oCategory->getBaseSeoLink($oCategory->getLanguage(), $this->getActPage())
01013                 );
01014             } else {
01015                 $sUrl = $oUtils->prepareCanonicalUrl(
01016                     $oCategory->getBaseStdLink($oCategory->getLanguage(), $this->getActPage())
01017                 );
01018             }
01019 
01020             return $sUrl;
01021         }
01022     }
01023 
01029     public function canSelectDisplayType()
01030     {
01031         return $this->getConfig()->getConfigParam('blShowListDisplayType');
01032     }
01033 
01039     public function getPageCount()
01040     {
01041         return $this->_iCntPages;
01042     }
01043 }