OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
oxtag.php
Go to the documentation of this file.
1 <?php
2 
3 // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
4 if (!defined('OXTAGCLOUD_MINTAGLENGTH')) {
5  define('OXTAGCLOUD_MINTAGLENGTH', 4);
6 }
7 // END deprecated
8 
14 class oxTag extends oxSuperCfg
15 {
16 
22  protected $_sTag = '';
23 
27  protected $_aForbiddenTags = array(
28  'admin', 'application', 'core', 'export', 'modules', 'out', 'setup', 'tmp'
29  );
30 
36  protected $_sTagLink = null;
37 
44  protected $_iTagMaxLength = 60;
45 
51  protected $_iHitCount = 1;
52 
59  protected $_aMetaChars = array('+', '-', '>', '<', '(', ')', '~', '*', '"', '\'', '\\', '[', ']', '{', '}', ';', ':', '.', '/', '|', '!', '@', '#', '$', '%', '^', '&', '?', '=', '`');
60 
66  public function __construct($sTag = null)
67  {
69  if ($sTag !== null) {
70  $this->set($sTag);
71  }
72  }
73 
79  public function setMaxLength($iTagMaxLength)
80  {
81  $this->_iTagMaxLength = $iTagMaxLength;
82  }
83 
89  public function getMaxLength()
90  {
91  return $this->_iTagMaxLength;
92  }
93 
100  public function set($sTag, $blPrepare = true)
101  {
102  $this->_sTag = $blPrepare ? $this->prepare($sTag) : $sTag;
103  $this->setLink();
104  }
105 
111  public function get()
112  {
113  return $this->_sTag;
114  }
115 
121  public function setHitCount($iHitCount)
122  {
123  $this->_iHitCount = $iHitCount;
124  }
125 
131  public function getHitCount()
132  {
133  return $this->_iHitCount;
134  }
135 
139  public function increaseHitCount()
140  {
141  $this->_iHitCount++;
142  }
143 
149  public function isValid()
150  {
151  $blValid = strlen($this->_sTag) > 0 ? true : false;
152  if ($blValid && in_array($this->_sTag, $this->_aForbiddenTags)) {
153  $blValid = false;
154  }
155 
156  return $blValid;
157  }
158 
164  public function getLink()
165  {
166  if (is_null($this->_sTagLink)) {
167  $this->_sTagLink = $this->formLink($this->get());
168  }
169 
170  return $this->_sTagLink;
171  }
172 
178  public function setLink($sTagLink = null)
179  {
180  $this->_sTagLink = $sTagLink;
181  }
182 
188  public function getTitle()
189  {
190  return getStr()->htmlentities($this->get());
191  }
192 
198  public function __toString()
199  {
200  return $this->get();
201  }
202 
211  public function prepare($sTag)
212  {
213  $sTag = $this->stripMetaChars($sTag);
214  $oStr = getStr();
215  $iLen = $oStr->strlen($sTag);
216  if ($iLen > $this->getMaxLength()) {
217  $sTag = trim($oStr->substr($sTag, 0, $this->getMaxLength()));
218  }
219 
220  return $oStr->strtolower($sTag);
221  }
222 
230  public function stripMetaChars($sText)
231  {
232  $oStr = getStr();
233 
234  // Remove meta chars
235  $sText = str_replace($this->_aMetaChars, ' ', $sText);
236 
237  // Replace multiple spaces with single space
238  $sText = $oStr->preg_replace("/\s+/", " ", trim($sText));
239 
240  return $sText;
241  }
242 
250  public function formLink($sTag)
251  {
252  $oSeoEncoderTag = oxRegistry::get("oxSeoEncoderTag");
253 
254  $iLang = oxRegistry::getLang()->getBaseLanguage();
255 
256  $sUrl = false;
257  if (oxRegistry::getUtils()->seoIsActive()) {
258  $sUrl = $oSeoEncoderTag->getTagUrl($sTag, $iLang);
259  }
260 
261  return $sUrl ? $sUrl : $this->getConfig()->getShopUrl() . $oSeoEncoderTag->getStdTagUri($sTag) . "&amp;lang=" . $iLang;
262  }
263 
267  public function addUnderscores()
268  {
269  $oStr = getStr();
270  $aTagParts = explode(' ', $this->get());
271  foreach ($aTagParts as &$sTagPart) {
272  if ($oStr->strlen($sTagPart) < OXTAGCLOUD_MINTAGLENGTH) {
273  $sTagPart .= str_repeat("_", OXTAGCLOUD_MINTAGLENGTH - $oStr->strlen($sTagPart));
274  }
275  }
276  unset($sTagPart);
277  $this->set(implode(' ', $aTagParts), false);
278  }
279 
280 
284  public function removeUnderscores()
285  {
286  $oStr = getStr();
287  $sRes = '';
288  if ($oStr->preg_match_all("/([\s\-]?)([^\s\-]+)([\s\-]?)/", $this->get(), $aMatches)) {
289  foreach ($aMatches[2] as $iKey => $sMatch) {
290  if ($oStr->strlen($sMatch) <= OXTAGCLOUD_MINTAGLENGTH) {
291  $sMatch = rtrim($sMatch, "_");
292  }
293  $sRes .= $aMatches[1][$iKey] . $sMatch . $aMatches[3][$iKey];
294  }
295  }
296  $this->set($sRes, false);
297  }
298 }