OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
oxseoencodertag.php
Go to the documentation of this file.
1 <?php
2 
8 {
12  protected static $_instance = null;
13 
19  protected $_oTagPrepareUtil = null;
20 
28  public static function getInstance()
29  {
30  return oxRegistry::get("oxSeoEncoderTag");
31  }
32 
42  public function getTagUri( $sTag, $iLang = null, $sOxid = null )
43  {
44  return $this->_getDynamicTagUri( $sTag, $this->getStdTagUri( $sTag ), "tag/{$sTag}/", $iLang, $sOxid );
45  }
46 
58  protected function _getDynamicTagUri( $sTag, $sStdUrl, $sSeoUrl, $iLang, $sOxid = null )
59  {
60  $iShopId = $this->getConfig()->getShopId();
61 
62  $sStdUrl = $this->_trimUrl( $sStdUrl );
63  $sObjectId = $this->getDynamicObjectId( $iShopId, $sStdUrl );
64  $sSeoUrl = $this->_prepareUri( $this->addLanguageParam( $sSeoUrl, $iLang ), $iLang );
65 
66  //load details link from DB
67  $sOldSeoUrl = $this->_loadFromDb( 'dynamic', $sObjectId, $iLang );
68  if ( $sOldSeoUrl === $sSeoUrl ) {
69  $sSeoUrl = $sOldSeoUrl;
70  } else {
71  if ( $sOldSeoUrl ) {
72  // old must be transferred to history
73  $this->_copyToHistory( $sObjectId, $iShopId, $iLang, 'dynamic' );
74  }
75  // creating unique
76  $sSeoUrl = $this->_processSeoUrl( $sSeoUrl, $sObjectId, $iLang );
77 
78  // inserting
79  $this->_saveToDb( 'dynamic', $sObjectId, $sStdUrl, $sSeoUrl, $iLang, $iShopId );
80  }
81 
82  return $sSeoUrl;
83  }
84 
92  protected function _prepareTag( $sTag )
93  {
94  if ( $this->_oTagPrepareUtil == null ) {
95  $this->_oTagPrepareUtil = oxNew('oxtagcloud');
96  }
97 
98  return $sTag = $this->_oTagPrepareUtil->prepareTags($sTag);
99  }
100 
109  public function getStdTagUri( $sTag, $blIncludeIndex = true )
110  {
111  // while tags are just strings, standard ulrs formatted stays here
112  $sUri = "cl=tag&amp;searchtag=" . rawurlencode( $sTag );
113  if ( $blIncludeIndex ) {
114  $sUri = "index.php?" . $sUri;
115  }
116  return $sUri;
117  }
118 
127  public function getTagUrl( $sTag, $iLang = null)
128  {
129  if (!isset($iLang)) {
130  $iLang = oxRegistry::getLang()->getBaseLanguage();
131  }
132  return $this->_getFullUrl( $this->getTagUri( $sTag, $iLang ), $iLang );
133  }
134 
145  public function getTagPageUrl( $sTag, $iPage, $iLang = null, $blFixed = false )
146  {
147  if (!isset($iLang)) {
148  $iLang = oxRegistry::getLang()->getBaseLanguage();
149  }
150  $sStdUrl = $this->getStdTagUri( $sTag ) . '&amp;pgNr=' . $iPage;
151  $sParams = (int) ($iPage + 1);
152 
153  $sStdUrl = $this->_trimUrl( $sStdUrl, $iLang );
154  $sSeoUrl = $this->getTagUri( $sTag, $iLang ) . $sParams . "/";
155 
156  return $this->_getFullUrl( $this->_getDynamicTagUri( $sTag, $sStdUrl, $sSeoUrl, $iLang ), $iLang );
157  }
158 }