OXID eShop CE  4.10.0
 All Classes Namespaces Files Functions Variables Pages
tag.php
Go to the documentation of this file.
1 <?php
2 
8 class Tag extends aList
9 {
10 
16  protected $_sListType = 'tag';
17 
23  protected $_blShowSorting = true;
24 
30  protected $_sTag;
31 
37  protected $_sTagTitle;
38 
44  protected $_oPageNavigation = null;
45 
52 
59 
65  public function render()
66  {
68 
69  $oArticleList = $this->getArticleList();
70 
71  // if tags are off or no articles - showing 404 header (#2139)
72  if (!$this->showTags() || !$oArticleList) {
73  error_404_handler();
74  }
75 
76  // processing list articles
77  $this->_processListArticles();
78 
79  return $this->_sThisTemplate;
80  }
81 
87  protected function _getProductLinkType()
88  {
90  }
91 
97  public function getAddUrlParams()
98  {
99  $sAddParams = parent::getAddUrlParams();
100  $sAddParams .= ($sAddParams ? '&amp;' : '') . "listtype={$this->_sListType}";
101  if ($sParam = oxRegistry::getConfig()->getRequestParameter('searchtag', true)) {
102  $sAddParams .= "&amp;searchtag=" . rawurlencode($sParam);
103  }
104 
105  return $sAddParams;
106  }
107 
115  protected function _loadArticles($oCategory)
116  {
117  // load only articles which we show on screen
118  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
119  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
120  $oArtList = oxNew('oxarticlelist');
121  $oArtList->setSqlLimit($iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles);
122  $oArtList->setCustomSorting($this->getSortingSql($this->getSortIdent()));
123  // load the articles
124  $this->_iAllArtCnt = $oArtList->loadTagArticles($this->getTag(), oxRegistry::getLang()->getBaseLanguage());
125  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
126 
127  return $oArtList;
128  }
129 
135  protected function _getCatPathString()
136  {
137  return $this->getTag();
138  }
139 
145  protected function _getSeoObjectId()
146  {
147  return md5("tag" . $this->getTag());
148  }
149 
155  public function generatePageNavigationUrl()
156  {
157  if ((oxRegistry::getUtils()->seoIsActive() && ($sTag = $this->getTag()))) {
158  $sLink = oxRegistry::get("oxSeoEncoderTag")->getTagUrl($sTag, oxRegistry::getLang()->getBaseLanguage());
159  }
160 
161  return $sLink ? $sLink : oxUBase::generatePageNavigationUrl();
162  }
163 
173  protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
174  {
175  $sSeoUrl = $blSeo = oxRegistry::getUtils()->seoIsActive();
176  if ($blSeo && ($sTag = $this->getTag())) {
177  if ($iPage && ($sSeoUrl = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl($sTag, $iPage, $iLang))) {
178  // only if page number > 0
179  $sUrl = $sSeoUrl;
180  }
181  }
182 
183  return (!$blSeo || !$sSeoUrl) ? oxUBase::_addPageNrParam($sUrl, $iPage, $iLang) : $sUrl;
184  }
185 
191  public function getArticleList()
192  {
193  if ($this->_aArticleList === null) {
194  if (($this->getTag())) {
195  $this->_aArticleList = $this->_loadArticles(null);
196  }
197  }
198 
199  return $this->_aArticleList;
200  }
201 
207  public function getTag()
208  {
209  if ($this->_sTag === null) {
210  $this->_sTag = oxRegistry::getConfig()->getRequestParameter("searchtag", false);
211  }
212 
213  return $this->_sTag;
214  }
215 
221  public function getTitle()
222  {
223  if ($this->_sTagTitle === null) {
224  $this->_sTagTitle = false;
225  if (($sTag = $this->getTag())) {
226  $oStr = getStr();
227  $sTitle = $oStr->ucfirst($sTag);
228  $this->_sTagTitle = $oStr->htmlspecialchars($sTitle);
229  }
230  }
231 
232  return $this->_sTagTitle;
233  }
234 
240  public function getTreePath()
241  {
242  if (($sTag = $this->getTag())) {
243  $oStr = getStr();
244 
245  $aPath[0] = oxNew("oxcategory");
246  $aPath[0]->setLink(false);
247  $aPath[0]->oxcategories__oxtitle = new oxField(oxRegistry::getLang()->translateString('TAGS'));
248 
249  $aPath[1] = oxNew("oxcategory");
250  $aPath[1]->setLink(false);
251  $aPath[1]->oxcategories__oxtitle = new oxField($oStr->ucfirst($sTag));
252 
253  return $aPath;
254  }
255  }
256 
266  protected function _prepareMetaKeyword($sKeywords, $blRemoveDuplicatedWords = true)
267  {
268  return parent::_collectMetaKeyword($sKeywords);
269  }
270 
281  protected function _prepareMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
282  {
283  return parent::_collectMetaDescription($sMeta, $iLength, $blDescTag);
284  }
285 
291  public function getCanonicalUrl()
292  {
293  if (($iPage = $this->getActPage())) {
294  return $this->_addPageNrParam($this->generatePageNavigationUrl(), $iPage);
295  } elseif (($sTag = $this->getTag())) {
296  return oxRegistry::get("oxSeoEncoderTag")->getTagUrl($sTag);
297  }
298  }
299 
305  public function getBreadCrumb()
306  {
307  $aPaths = array();
308  $aCatPath = array();
309 
310  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
311  $sSelfLink = $this->getViewConfig()->getSelfLink();
312 
313  $aCatPath['title'] = oxRegistry::getLang()->translateString('TAGS', $iBaseLanguage, false);
314  $aCatPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl($sSelfLink . 'cl=tags');
315  $aPaths[] = $aCatPath;
316 
317  $aCatPath['title'] = $this->getTitle();
318  $aCatPath['link'] = $this->getCanonicalUrl();
319  $aPaths[] = $aCatPath;
320 
321  return $aPaths;
322  }
323 }