OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
tag.php
Go to the documentation of this file.
1 <?php
2 
6 class Tag extends aList
7 {
12  protected $_sListType = 'tag';
13 
18  protected $_blShowSorting = true;
19 
25  protected $_sTag;
26 
32  protected $_sTagTitle;
33 
38  protected $_oPageNavigation = null;
39 
46 
53 
59  public function render()
60  {
62 
63  $oArticleList = $this->getArticleList();
64 
65  // if tags are off or no articles - showing 404 header (#2139)
66  if ( !$this->showTags() || !$oArticleList) {
67  error_404_handler();
68  }
69 
70  // processing list articles
71  $this->_processListArticles();
72 
73  return $this->_sThisTemplate;
74  }
75 
81  protected function _getProductLinkType()
82  {
84  }
85 
91  public function getAddUrlParams()
92  {
93  $sAddParams = parent::getAddUrlParams();
94  $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
95  if ( $sParam = oxRegistry::getConfig()->getRequestParameter( 'searchtag', true ) ) {
96  $sAddParams .= "&amp;searchtag=" . rawurlencode( $sParam );
97  }
98  return $sAddParams;
99  }
100 
108  protected function _loadArticles( $oCategory )
109  {
110  // load only articles which we show on screen
111  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
112  $iNrofCatArticles = $iNrofCatArticles?$iNrofCatArticles:1;
113  $oArtList = oxNew( 'oxarticlelist' );
114  $oArtList->setSqlLimit( $iNrofCatArticles * $this->_getRequestPageNr(), $iNrofCatArticles );
115  $oArtList->setCustomSorting( $this->getSortingSql( $this->getSortIdent() ) );
116  // load the articles
117  $this->_iAllArtCnt = $oArtList->loadTagArticles( $this->getTag(), oxRegistry::getLang()->getBaseLanguage());
118  $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
119 
120  return $oArtList;
121  }
122 
128  protected function _getCatPathString()
129  {
130  return $this->getTag();
131  }
132 
138  protected function _getSeoObjectId()
139  {
140  return md5("tag" . $this->getTag() );
141  }
142 
152  public function getSorting( $sCnid )
153  {
154  return parent::getSorting( $sCnid );
155  }
156 
168  public function setItemSorting( $sCnid, $sSortBy, $sSortOrder = null )
169  {
170  parent::setItemSorting( $sCnid, $sSortBy, $sSortOrder );
171  }
172 
178  public function generatePageNavigationUrl()
179  {
180  if ( ( oxRegistry::getUtils()->seoIsActive() && ( $sTag = $this->getTag() ) ) ) {
181  $sLink = oxRegistry::get("oxSeoEncoderTag")->getTagUrl( $sTag, oxRegistry::getLang()->getBaseLanguage() );
182  }
183  return $sLink ? $sLink : oxUBase::generatePageNavigationUrl();
184  }
185 
195  protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
196  {
197  $sSeoUrl = $blSeo = oxRegistry::getUtils()->seoIsActive();
198  if ( $blSeo && ( $sTag = $this->getTag() ) ) {
199  if ( $iPage && ( $sSeoUrl = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl( $sTag, $iPage, $iLang ) ) ) {
200  // only if page number > 0
201  $sUrl = $sSeoUrl;
202  }
203  }
204 
205  return ( !$blSeo || !$sSeoUrl ) ? oxUBase::_addPageNrParam( $sUrl, $iPage, $iLang ) : $sUrl;
206  }
207 
213  public function getArticleList()
214  {
215  if ( $this->_aArticleList === null ) {
216  if ( ( $this->getTag() ) ) {
217  $this->_aArticleList = $this->_loadArticles( null );
218  }
219  }
220 
221  return $this->_aArticleList;
222  }
223 
229  public function getTag()
230  {
231  if ( $this->_sTag === null ) {
232  $this->_sTag = oxRegistry::getConfig()->getRequestParameter("searchtag", false);
233  }
234  return $this->_sTag;
235  }
236 
242  public function getTitle()
243  {
244  if ( $this->_sTagTitle === null ) {
245  $this->_sTagTitle = false;
246  if ( ( $sTag = $this->getTag() ) ) {
247  $oStr = getStr();
248  $sTitle = $oStr->ucfirst( $sTag );
249  $this->_sTagTitle = $oStr->htmlspecialchars( $sTitle );
250  }
251  }
252  return $this->_sTagTitle;
253  }
254 
260  public function getTreePath()
261  {
262  if ( ( $sTag = $this->getTag() ) ) {
263  $oStr = getStr();
264 
265  $aPath[0] = oxNew( "oxcategory" );
266  $aPath[0]->setLink( false );
267  $aPath[0]->oxcategories__oxtitle = new oxField( oxRegistry::getLang()->translateString('TAGS') );
268 
269  $aPath[1] = oxNew( "oxcategory" );
270  $aPath[1]->setLink( false );
271  $aPath[1]->oxcategories__oxtitle = new oxField( $oStr->ucfirst( $sTag ) );
272  return $aPath;
273  }
274  }
275 
285  protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
286  {
287  return parent::_collectMetaKeyword( $sKeywords );
288  }
289 
300  protected function _prepareMetaDescription( $sMeta, $iLength = 1024, $blDescTag = false )
301  {
302  return parent::_collectMetaDescription( $sMeta, $iLength, $blDescTag );
303  }
304 
310  public function getCanonicalUrl()
311  {
312  if ( ( $iPage = $this->getActPage() ) ) {
313  return $this->_addPageNrParam( $this->generatePageNavigationUrl(), $iPage );
314  } elseif ( ( $sTag = $this->getTag() ) ) {
315  return oxRegistry::get("oxSeoEncoderTag")->getTagUrl( $sTag );
316  }
317  }
318 
324  public function getBreadCrumb()
325  {
326  $aPaths = array();
327  $aCatPath = array();
328 
329  $aCatPath['title'] = oxRegistry::getLang()->translateString( 'TAGS', oxRegistry::getLang()->getBaseLanguage(), false );
330  $aCatPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=tags' );
331  $aPaths[] = $aCatPath;
332 
333  $aCatPath['title'] = $this->getTitle();
334  $aCatPath['link'] = $this->getCanonicalUrl();
335  $aPaths[] = $aCatPath;
336 
337  return $aPaths;
338  }
339 
340 }