OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
tag.php
Go to the documentation of this file.
1 <?php
2 
6 class Tag extends aList
7 {
8 
14  protected $_sListType = 'tag';
15 
21  protected $_blShowSorting = true;
22 
28  protected $_sTag;
29 
35  protected $_sTagTitle;
36 
42  protected $_oPageNavigation = null;
43 
50 
57 
63  public function render()
64  {
66 
67  $oArticleList = $this->getArticleList();
68 
69  // if tags are off or no articles - showing 404 header (#2139)
70  if (!$this->showTags() || !$oArticleList) {
71  error_404_handler();
72  }
73 
74  // processing list articles
75  $this->_processListArticles();
76 
77  return $this->_sThisTemplate;
78  }
79 
85  protected function _getProductLinkType()
86  {
88  }
89 
95  public function getAddUrlParams()
96  {
97  $sAddParams = parent::getAddUrlParams();
98  $sAddParams .= ($sAddParams ? '&amp;' : '') . "listtype={$this->_sListType}";
99  if ($sParam = oxRegistry::getConfig()->getRequestParameter('searchtag', true)) {
100  $sAddParams .= "&amp;searchtag=" . rawurlencode($sParam);
101  }
102 
103  return $sAddParams;
104  }
105 
113  protected function _loadArticles($oCategory)
114  {
115  // load only articles which we show on screen
116  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
117  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
118  $oArtList = oxNew('oxarticlelist');
119  $oArtList->setSqlLimit($iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles);
120  $oArtList->setCustomSorting($this->getSortingSql($this->getSortIdent()));
121  // load the articles
122  $this->_iAllArtCnt = $oArtList->loadTagArticles($this->getTag(), oxRegistry::getLang()->getBaseLanguage());
123  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
124 
125  return $oArtList;
126  }
127 
133  protected function _getCatPathString()
134  {
135  return $this->getTag();
136  }
137 
143  protected function _getSeoObjectId()
144  {
145  return md5("tag" . $this->getTag());
146  }
147 
153  public function generatePageNavigationUrl()
154  {
155  if ((oxRegistry::getUtils()->seoIsActive() && ($sTag = $this->getTag()))) {
156  $sLink = oxRegistry::get("oxSeoEncoderTag")->getTagUrl($sTag, oxRegistry::getLang()->getBaseLanguage());
157  }
158 
159  return $sLink ? $sLink : oxUBase::generatePageNavigationUrl();
160  }
161 
171  protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
172  {
173  $sSeoUrl = $blSeo = oxRegistry::getUtils()->seoIsActive();
174  if ($blSeo && ($sTag = $this->getTag())) {
175  if ($iPage && ($sSeoUrl = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl($sTag, $iPage, $iLang))) {
176  // only if page number > 0
177  $sUrl = $sSeoUrl;
178  }
179  }
180 
181  return (!$blSeo || !$sSeoUrl) ? oxUBase::_addPageNrParam($sUrl, $iPage, $iLang) : $sUrl;
182  }
183 
189  public function getArticleList()
190  {
191  if ($this->_aArticleList === null) {
192  if (($this->getTag())) {
193  $this->_aArticleList = $this->_loadArticles(null);
194  }
195  }
196 
197  return $this->_aArticleList;
198  }
199 
205  public function getTag()
206  {
207  if ($this->_sTag === null) {
208  $this->_sTag = oxRegistry::getConfig()->getRequestParameter("searchtag", false);
209  }
210 
211  return $this->_sTag;
212  }
213 
219  public function getTitle()
220  {
221  if ($this->_sTagTitle === null) {
222  $this->_sTagTitle = false;
223  if (($sTag = $this->getTag())) {
224  $oStr = getStr();
225  $sTitle = $oStr->ucfirst($sTag);
226  $this->_sTagTitle = $oStr->htmlspecialchars($sTitle);
227  }
228  }
229 
230  return $this->_sTagTitle;
231  }
232 
238  public function getTreePath()
239  {
240  if (($sTag = $this->getTag())) {
241  $oStr = getStr();
242 
243  $aPath[0] = oxNew("oxcategory");
244  $aPath[0]->setLink(false);
245  $aPath[0]->oxcategories__oxtitle = new oxField(oxRegistry::getLang()->translateString('TAGS'));
246 
247  $aPath[1] = oxNew("oxcategory");
248  $aPath[1]->setLink(false);
249  $aPath[1]->oxcategories__oxtitle = new oxField($oStr->ucfirst($sTag));
250 
251  return $aPath;
252  }
253  }
254 
264  protected function _prepareMetaKeyword($sKeywords, $blRemoveDuplicatedWords = true)
265  {
266  return parent::_collectMetaKeyword($sKeywords);
267  }
268 
279  protected function _prepareMetaDescription($sMeta, $iLength = 1024, $blDescTag = false)
280  {
281  return parent::_collectMetaDescription($sMeta, $iLength, $blDescTag);
282  }
283 
289  public function getCanonicalUrl()
290  {
291  if (($iPage = $this->getActPage())) {
292  return $this->_addPageNrParam($this->generatePageNavigationUrl(), $iPage);
293  } elseif (($sTag = $this->getTag())) {
294  return oxRegistry::get("oxSeoEncoderTag")->getTagUrl($sTag);
295  }
296  }
297 
303  public function getBreadCrumb()
304  {
305  $aPaths = array();
306  $aCatPath = array();
307 
308  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
309  $sSelfLink = $this->getViewConfig()->getSelfLink();
310 
311  $aCatPath['title'] = oxRegistry::getLang()->translateString('TAGS', $iBaseLanguage, false);
312  $aCatPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl($sSelfLink . 'cl=tags');
313  $aPaths[] = $aCatPath;
314 
315  $aCatPath['title'] = $this->getTitle();
316  $aCatPath['link'] = $this->getCanonicalUrl();
317  $aPaths[] = $aCatPath;
318 
319  return $aPaths;
320  }
321 }