OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
alist.php
Go to the documentation of this file.
1 <?php
2 
9 class aList extends oxUBase
10 {
15  protected $_iAllArtCnt = 0;
16 
21  protected $_iCntPages = 0;
22 
27  protected $_sThisTemplate = 'page/list/list.tpl';
28 
33  protected $_sThisMoreTemplate = 'page/list/morecategories.tpl';
34 
39  protected $_sCatPathString = null;
40 
45  protected $_blShowSorting = true;
46 
51  protected $_aAttributes = null;
52 
57  protected $_aCatArtList = null;
58 
63  protected $_blHasVisibleSubCats = null;
64 
69  protected $_aSubCatList = null;
70 
75  protected $_oPageNavigation = null;
76 
81  protected $_blIsCat = null;
82 
87  protected $_oRecommList = null;
88 
93  protected $_sCatTitle = null;
94 
99  protected $_blShowTagCloud = true;
100 
105  protected $_blBargainAction = false;
106 
112  protected $_aSimilarRecommListIds = null;
113 
114 
121  public function getViewId()
122  {
123  if ( !isset( $this->_sViewId ) ) {
124  $sCatId = oxConfig::getParameter( 'cnid' );
125  $iActPage = $this->getActPage();
126  $iArtPerPage = oxSession::getVar( '_artperpage' );
127  $sListDisplayType = oxSession::getVar( 'ldtype' );
128  $sParentViewId = parent::getViewId();
129 
130  // shorten it
131  $this->_sViewId = md5( $sParentViewId.'|'.$sCatId.'|'.$iActPage.'|'.$iArtPerPage.'|'.$sListDisplayType );
132 
133  }
134 
135  return $this->_sViewId;
136  }
137 
150  public function render()
151  {
152  $myConfig = $this->getConfig();
153 
154  $oCategory = null;
155  $blContinue = true;
156  $this->_blIsCat = false;
157 
158  // A. checking for fake "more" category
159  if ( 'oxmore' == $myConfig->getRequestParameter( 'cnid' ) ) {
160  // overriding some standard value and parameters
161  $this->_sThisTemplate = $this->_sThisMoreTemplate;
162  $oCategory = oxNew( 'oxcategory' );
163  $oCategory->oxcategories__oxactive = new oxField( 1, oxField::T_RAW );
164  $this->setActiveCategory( $oCategory );
165 
166  $this->_blShowTagCloud = true;
167 
168  } elseif ( ( $oCategory = $this->getActiveCategory() ) ) {
169  $blContinue = ( bool ) $oCategory->oxcategories__oxactive->value;
170  $this->_blIsCat = true;
171  $this->_blBargainAction = true;
172  }
173 
174 
175  // category is inactive ?
176  if ( !$blContinue || !$oCategory ) {
177  oxRegistry::getUtils()->redirect( $myConfig->getShopURL().'index.php', true, 302 );
178  }
179 
180  $oCat = $this->getActiveCategory();
181  if ($oCat && $myConfig->getConfigParam( 'bl_rssCategories' )) {
182  $oRss = oxNew('oxrssfeed');
183  $this->addRssFeed($oRss->getCategoryArticlesTitle($oCat), $oRss->getCategoryArticlesUrl($oCat), 'activeCategory');
184  }
185 
186  //checking if actual pages count does not exceed real articles page count
187  $this->getArticleList();
188 
189  if ( $this->_blIsCat ) {
190  $this->_checkRequestedPage();
191  }
192 
193  parent::render();
194 
195  // processing list articles
196  $this->_processListArticles();
197 
198  return $this->getTemplateName();
199  }
200 
209  protected function _checkRequestedPage()
210  {
211  $iPageCnt = $this->getPageCount();
212  // redirecting to first page in case requested page does not exist
213  if ( $iPageCnt && ( ( $iPageCnt - 1 ) < $this->getActPage() ) ) {
214  oxRegistry::getUtils()->redirect( $this->getActiveCategory()->getLink(), false );
215  }
216  }
217 
224  protected function _processListArticles()
225  {
226  if ( $aArtList = $this->getArticleList() ) {
227  $iLinkType = $this->_getProductLinkType();
228  $sAddDynParams = $this->getAddUrlParams();
229  $sAddSeoParams = $this->getAddSeoUrlParams();
230 
231  foreach ( $aArtList as $oArticle ) {
232  $oArticle->setLinkType( $iLinkType );
233 
234  // appending dynamic urls
235  if ( $sAddDynParams ) {
236  $oArticle->appendStdLink( $sAddDynParams );
237  }
238 
239  // appending seo urls
240  if ( $sAddSeoParams ) {
241  $oArticle->appendLink( $sAddSeoParams );
242  }
243  }
244  }
245  }
246 
247 
253  public function getAddUrlParams()
254  {
255  $sParams = parent::getAddUrlParams();
256  if ( !oxRegistry::getUtils()->seoIsActive() ) {
257  $iPgNr = (int) oxConfig::getParameter( 'pgNr' );
258  if ( $iPgNr > 0 ) {
259  $sParams .= ($sParams?'&amp;':'') . "pgNr={$iPgNr}";
260  }
261  }
262 
263  return $sParams;
264  }
265 
271  public function getAddSeoUrlParams()
272  {
273  }
274 
282  protected function _getProductLinkType()
283  {
284  $iCatType = OXARTICLE_LINKTYPE_CATEGORY;
285  if ( ( $oCat = $this->getActiveCategory() ) && $oCat->isPriceCategory() ) {
287  }
288  return $iCatType;
289  }
290 
299  public function executefilter()
300  {
301  $iLang = oxRegistry::getLang()->getBaseLanguage();
302  // store this into session
303  $aFilter = oxRegistry::getConfig()->getRequestParameter( 'attrfilter', true );
304  $sActCat = oxRegistry::getConfig()->getRequestParameter( 'cnid' );
305 
306  if ( !empty( $aFilter ) ) {
307  $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
308  //fix for #2904 - if language will be changed attributes of this category will be deleted from session
309  //and new filters for active language set.
310  $aSessionFilter[$sActCat] = null;
311  $aSessionFilter[$sActCat][$iLang] = $aFilter;
312  oxSession::setVar( 'session_attrfilter', $aSessionFilter );
313  }
314  }
315 
323  protected function _loadArticles( $oCategory )
324  {
325  $myConfig = $this->getConfig();
326 
327  $iNrofCatArticles = (int) $myConfig->getConfigParam( 'iNrofCatArticles' );
328  $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
329 
330  // load only articles which we show on screen
331  $oArtList = oxNew( 'oxarticlelist' );
332  $oArtList->setSqlLimit( $iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles );
333  $oArtList->setCustomSorting( $this->getSortingSql( $this->getSortIdent() ) );
334 
335  if ( $oCategory->isPriceCategory() ) {
336  $dPriceFrom = $oCategory->oxcategories__oxpricefrom->value;
337  $dPriceTo = $oCategory->oxcategories__oxpriceto->value;
338 
339  $this->_iAllArtCnt = $oArtList->loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory );
340  } else {
341  $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
342 
343  $sActCat = oxConfig::getParameter( 'cnid' );
344  $this->_iAllArtCnt = $oArtList->loadCategoryArticles( $sActCat, $aSessionFilter );
345  }
346 
347  $this->_iCntPages = round( $this->_iAllArtCnt/$iNrofCatArticles + 0.49 );
348 
349  return $oArtList;
350  }
351 
357  public function getActPage()
358  {
359  return $this->_getRequestPageNr();
360  }
361 
370  protected function _getRequestPageNr()
371  {
372  return parent::getActPage();
373  }
374 
380  protected function _getSeoObjectId()
381  {
382  if ( ( $oCategory = $this->getActiveCategory() ) ) {
383  return $oCategory->getId();
384  }
385  }
386 
392  protected function _getCatPathString()
393  {
394  if ( $this->_sCatPathString === null ) {
395 
396  // marking as already set
397  $this->_sCatPathString = false;
398 
399  //fetching category path
400  if ( is_array( $aPath = $this->getCatTreePath() ) ) {
401 
402  $oStr = getStr();
403  $this->_sCatPathString = '';
404  foreach ( $aPath as $oCat ) {
405  if ( $this->_sCatPathString ) {
406  $this->_sCatPathString .= ', ';
407  }
408  $this->_sCatPathString .= $oStr->strtolower( $oCat->oxcategories__oxtitle->value );
409  }
410  }
411  }
412  return $this->_sCatPathString;
413  }
414 
424  protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
425  {
426  $sDescription = '';
427  // appending parent title
428  if ( $oCategory = $this->getActiveCategory() ) {
429  if ( ( $oParent = $oCategory->getParentCategory() ) ) {
430  $sDescription .= " {$oParent->oxcategories__oxtitle->value} -";
431  }
432 
433  // adding category title
434  $sDescription .= " {$oCategory->oxcategories__oxtitle->value}.";
435  }
436 
437  // and final component ..
438  //changed for #2776
439  if ( ( $sSuffix = $this->getConfig()->getActiveShop()->oxshops__oxtitleprefix->value ) ) {
440  $sDescription .= " {$sSuffix}";
441  }
442 
443  // making safe for output
444  $sDescription = getStr()->html_entity_decode( $sDescription );
445  $sDescription = getStr()->strip_tags( $sDescription );
446  $sDescription = getStr()->cleanStr( $sDescription );
447  $sDescription = getStr()->htmlspecialchars( $sDescription );
448  return trim( $sDescription );
449  }
450 
456  public function getMetaDescription()
457  {
458  $sMeta = parent::getMetaDescription();
459 
460  if ( $sTitlePageSuffix = $this->getTitlePageSuffix() ) {
461  if ( $sMeta ) {
462  $sMeta .= ", ";
463  }
464  $sMeta .= $sTitlePageSuffix;
465  }
466 
467  return $sMeta;
468  }
469 
482  protected function _collectMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
483  {
484  //formatting description tag
485  $oCategory = $this->getActiveCategory();
486 
487  $sAddText = ( ( $oCategory instanceof oxCategory ) ) ? trim( $oCategory->getLongDesc() ) : '';
488 
489  $aArticleList = $this->getArticleList();
490  if ( !$sAddText && count($aArticleList)) {
491  foreach ( $aArticleList as $oArticle ) {
492  if ( $sAddText ) {
493  $sAddText .= ', ';
494  }
495  $sAddText .= $oArticle->oxarticles__oxtitle->value;
496  }
497  }
498 
499  if ( !$sMeta ) {
500  $sMeta = trim( $this->_getCatPathString() );
501  }
502 
503  if ( $sMeta ) {
504  $sMeta = "{$sMeta} - {$sAddText}";
505  } else {
506  $sMeta = $sAddText;
507  }
508 
509  return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
510  }
511 
520  protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
521  {
522  $sKeywords = '';
523  if ( ( $oCategory = $this->getActiveCategory() ) ) {
524  $aKeywords = array();
525 
526  if ( $oCatTree = $this->getCategoryTree() ) {
527  foreach ( $oCatTree->getPath() as $oCat ) {
528  $aKeywords[] = trim( $oCat->oxcategories__oxtitle->value );
529  }
530  }
531 
532  if ( count( $aKeywords ) > 0 ) {
533  $sKeywords = implode( ", ", $aKeywords );
534  }
535 
536  $aSubCats = $oCategory->getSubCats();
537  if ( is_array( $aSubCats ) ) {
538  foreach ( $aSubCats as $oSubCat ) {
539  $sKeywords .= ', '.$oSubCat->oxcategories__oxtitle->value;
540  }
541  }
542  }
543 
544  $sKeywords = parent::_prepareMetaDescription( $sKeywords, -1, $blRemoveDuplicatedWords );
545 
546  return trim( $sKeywords );
547  }
548 
557  protected function _collectMetaKeyword( $sKeywords )
558  {
559  $iMaxTextLength = 60;
560  $sText = '';
561 
562  if ( count( $aArticleList = $this->getArticleList() ) ) {
563  $oStr = getStr();
564  foreach ( $aArticleList as $oProduct ) {
565  $sDesc = $oStr->strip_tags( trim( $oStr->strtolower( $oProduct->getLongDescription()->value ) ) );
566 
567  //removing dots from string (they are not cleaned up during general string cleanup)
568  $sDesc = $oStr->preg_replace( "/\./", " ", $sDesc );
569 
570  if ( $oStr->strlen( $sDesc ) > $iMaxTextLength ) {
571  $sMidText = $oStr->substr( $sDesc, 0, $iMaxTextLength );
572  $sDesc = $oStr->substr( $sMidText, 0, ( $oStr->strlen( $sMidText ) - $oStr->strpos( strrev( $sMidText ), ' ' ) ) );
573  }
574  if ( $sText ) {
575  $sText .= ', ';
576  }
577  $sText .= $sDesc;
578  }
579  }
580 
581  if ( !$sKeywords ) {
582  $sKeywords = $this->_getCatPathString();
583  }
584 
585  if ( $sKeywords ) {
586  $sText = "{$sKeywords}, {$sText}";
587  }
588 
589  return parent::_prepareMetaKeyword( $sText );
590  }
591 
599  public function getTemplateName()
600  {
601  // assign template name
602  if ( ( $sTplName = basename( oxConfig::getParameter( 'tpl' ) ) ) ) {
603  $this->_sThisTemplate = 'custom/'.$sTplName;
604  } elseif ( ( $oCategory = $this->getActiveCategory() ) && $oCategory->oxcategories__oxtemplate->value ) {
605  $this->_sThisTemplate = $oCategory->oxcategories__oxtemplate->value;
606  }
607 
608  return $this->_sThisTemplate;
609  }
610 
620  protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
621  {
622  if ( oxRegistry::getUtils()->seoIsActive() && ( $oCategory = $this->getActiveCategory() ) ) {
623  if ( $iPage ) {
624  // only if page number > 0
625  $sUrl = $oCategory->getBaseSeoLink( $iLang, $iPage );
626  }
627  } else {
628  $sUrl = parent::_addPageNrParam( $sUrl, $iPage, $iLang );
629  }
630  return $sUrl;
631  }
632 
638  protected function _isActCategory()
639  {
640  return $this->_blIsCat;
641  }
642 
648  public function generatePageNavigationUrl( )
649  {
650  if ( ( oxRegistry::getUtils()->seoIsActive() && ( $oCategory = $this->getActiveCategory() ) ) ) {
651  return $oCategory->getLink();
652  }
654  }
655 
665  public function getSorting( $sCnid )
666  {
667  $aSorting = parent::getSorting( $sCnid );
668  return $aSorting;
669  }
670 
676  public function getDefaultSorting()
677  {
678  $aSorting = parent::getDefaultSorting();
679 
680  $oCategory = $this->getActiveCategory();
681  if ( $oCategory && $oCategory instanceof oxCategory ) {
682  if ( $sDefaultSorting = $oCategory->getDefaultSorting() ) {
683  $sArticleTable = getViewName( 'oxarticles' );
684  $sSortBy = $sArticleTable.'.'.$sDefaultSorting;
685  $sSortDir = ( $oCategory->getDefaultSortingMode() ) ? "desc" : "asc";
686  $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
687  }
688  }
689 
690  return $aSorting;
691  }
692 
693 
699  public function getTitleSuffix()
700  {
701  if ( $this->getActiveCategory()->oxcategories__oxshowsuffix->value ) {
702  return $this->getConfig()->getActiveShop()->oxshops__oxtitlesuffix->value;
703  }
704  }
705 
711  public function getTitlePageSuffix()
712  {
713  if ( ( $iPage = $this->getActPage() ) ) {
714  return oxRegistry::getLang()->translateString( 'PAGE' )." ". ( $iPage + 1 );
715  }
716  }
717 
726  protected function _getSubject( $iLang )
727  {
728  return $this->getActiveCategory();
729  }
730 
737  public function getAttributes()
738  {
739  $this->_aAttributes = false;
740 
741  if ( ( $oCategory = $this->getActiveCategory() ) ) {
742  $aAttributes = $oCategory->getAttributes();
743  if ( count( $aAttributes ) ) {
744  $this->_aAttributes = $aAttributes;
745  }
746  }
747 
748  return $this->_aAttributes;
749  }
750 
756  public function getArticleList()
757  {
758  if ( $this->_aArticleList === null ) {
759  if ( /*$this->_isActCategory() &&*/ ( $oCategory = $this->getActiveCategory() ) ) {
760  $aArticleList = $this->_loadArticles( $oCategory );
761  if ( count( $aArticleList ) ) {
762  $this->_aArticleList = $aArticleList;
763  }
764  }
765  }
766 
767  return $this->_aArticleList;
768  }
769 
775  public function getArticleCount()
776  {
777  return $this->_iAllArtCnt;
778  }
779 
785  public function getSimilarRecommListIds()
786  {
787  if ( $this->_aSimilarRecommListIds === null ) {
788  $this->_aSimilarRecommListIds = false;
789 
790  if ( $aCatArtList = $this->getArticleList() ) {
791  $this->_aSimilarRecommListIds = $aCatArtList->arrayKeys();
792  }
793  }
795  }
796 
802  public function getCatTreePath()
803  {
804  if ( $this->_sCatTreePath === null ) {
805  $this->_sCatTreePath = false;
806  // category path
807  if ( $oCatTree = $this->getCategoryTree() ) {
808  $this->_sCatTreePath = $oCatTree->getPath();
809  }
810  }
811  return $this->_sCatTreePath;
812  }
813 
819  public function getTreePath()
820  {
821  if ( $oCatTree = $this->getCategoryTree() ) {
822  return $oCatTree->getPath();
823  }
824  }
825 
831  public function getBreadCrumb()
832  {
833  $aPaths = array();
834 
835  if ( 'oxmore' == oxConfig::getParameter( 'cnid' ) ) {
836  $aPath = array();
837  $aPath['title'] = oxRegistry::getLang()->translateString( 'CATEGORY_OVERVIEW', oxRegistry::getLang()->getBaseLanguage(), false );
838  $aPath['link'] = $this->getLink();
839 
840  $aPaths[] = $aPath;
841 
842  return $aPaths;
843  }
844 
845  if ( ($oCatTree = $this->getCategoryTree()) && ($oCatPath = $oCatTree->getPath()) ) {
846  foreach ( $oCatPath as $oCat ) {
847  $aCatPath = array();
848 
849  $aCatPath['link'] = $oCat->getLink();
850  $aCatPath['title'] = $oCat->oxcategories__oxtitle->value;
851 
852  $aPaths[] = $aCatPath;
853  }
854  }
855 
856  return $aPaths;
857  }
858 
865  public function hasVisibleSubCats()
866  {
867  if ( $this->_blHasVisibleSubCats === null ) {
868  $this->_blHasVisibleSubCats = false;
869  if ( $oClickCat = $this->getActiveCategory() ) {
870  $this->_blHasVisibleSubCats = $oClickCat->getHasVisibleSubCats();
871  }
872  }
874  }
875 
881  public function getSubCatList()
882  {
883  if ( $this->_aSubCatList === null ) {
884  $this->_aSubCatList = array();
885  if ( $oClickCat = $this->getActiveCategory() ) {
886  $this->_aSubCatList = $oClickCat->getSubCats();
887  }
888  }
889 
890  return $this->_aSubCatList;
891  }
892 
898  public function getPageNavigation()
899  {
900  if ( $this->_oPageNavigation === null ) {
901  $this->_oPageNavigation = $this->generatePageNavigation();
902  }
904  }
905 
911  public function getTitle()
912  {
913  if ( $this->_sCatTitle === null ) {
914  $this->_sCatTitle = false;
915  if ( ( $oCategory = $this->getActiveCategory() ) ) {
916  $this->_sCatTitle = $oCategory->oxcategories__oxtitle->value;
917  }
918  }
919  return $this->_sCatTitle;
920  }
921 
927  public function getBargainArticleList()
928  {
929  if ( $this->_aBargainArticleList === null ) {
930  $this->_aBargainArticleList = array();
931  if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) && $this->_isActCategory() ) {
932  $oArtList = oxNew( 'oxarticlelist' );
933  $oArtList->loadActionArticles( 'OXBARGAIN' );
934  if ( $oArtList->count() ) {
935  $this->_aBargainArticleList = $oArtList;
936  }
937  }
938  }
940  }
941 
947  public function getActiveCategory()
948  {
949  if ( $this->_oActCategory === null ) {
950  $this->_oActCategory = false;
951  $oCategory = oxNew( 'oxCategory' );
952  if ( $oCategory->load( $this->getCategoryId() ) ) {
953  $this->_oActCategory = $oCategory;
954  }
955  }
956  return $this->_oActCategory;
957  }
958 
964  public function getCanonicalUrl()
965  {
966  if ( ( $oCategory = $this->getActiveCategory() ) ) {
967  $oUtils = oxRegistry::get("oxUtilsUrl");
968  if ( oxRegistry::getUtils()->seoIsActive() ) {
969  $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseSeoLink( $oCategory->getLanguage(), $this->getActPage() ) );
970  } else {
971  $sUrl = $oUtils->prepareCanonicalUrl( $oCategory->getBaseStdLink( $oCategory->getLanguage(), $this->getActPage() ) );
972  }
973  return $sUrl;
974  }
975  }
976 
982  public function canSelectDisplayType()
983  {
984  return $this->getConfig()->getConfigParam( 'blShowListDisplayType' );
985  }
986 
992  public function getPageCount()
993  {
994  return $this->_iCntPages;
995  }
996 }