OXID eShop CE  4.10.8
 All Classes Namespaces Files Functions Variables Pages
article_seo.php
Go to the documentation of this file.
1 <?php
2 
6 class Article_Seo extends Object_Seo
7 {
8 
14  protected $_sActCatId = null;
15 
21  protected $_aSelectionList = null;
22 
28  public function getActCatType()
29  {
30  $sType = false;
31  $aData = oxRegistry::getConfig()->getRequestParameter("aSeoData");
32  if ($aData && isset($aData["oxparams"])) {
33  $oStr = getStr();
34  $iEndPos = $oStr->strpos($aData["oxparams"], "#");
35  $sType = $oStr->substr($aData["oxparams"], 0, $iEndPos);
36  } elseif ($aList = $this->getSelectionList()) {
37  reset($aList);
38  $sType = key($aList);
39  }
40 
41  return $sType;
42  }
43 
49  public function getActCatLang()
50  {
51  if (oxRegistry::getConfig()->getRequestParameter("editlanguage") !== null) {
52  return $this->_iEditLang;
53  }
54 
55  $iLang = false;
56  $aData = oxRegistry::getConfig()->getRequestParameter("aSeoData");
57  if ($aData && isset($aData["oxparams"])) {
58  $oStr = getStr();
59  $iStartPos = $oStr->strpos($aData["oxparams"], "#");
60  $iEndPos = $oStr->strpos($aData["oxparams"], "#", $iStartPos + 1);
61  $iLang = $oStr->substr($aData["oxparams"], $iEndPos + 1);
62  } elseif ($aList = $this->getSelectionList()) {
63  $aList = reset($aList);
64  $iLang = key($aList);
65  }
66 
67  return (int) $iLang;
68  }
69 
75  public function getActCatId()
76  {
77  $sId = false;
78  $aData = oxRegistry::getConfig()->getRequestParameter("aSeoData");
79  if ($aData && isset($aData["oxparams"])) {
80  $oStr = getStr();
81  $iStartPos = $oStr->strpos($aData["oxparams"], "#");
82  $iEndPos = $oStr->strpos($aData["oxparams"], "#", $iStartPos + 1);
83  $iLen = $oStr->strlen($aData["oxparams"]);
84  $sId = $oStr->substr($aData["oxparams"], $iStartPos + 1, $iEndPos - $iLen);
85  } elseif ($aList = $this->getSelectionList()) {
86  $oItem = reset($aList[$this->getActCatType()][$this->getActCatLang()]);
87  $sId = $oItem->getId();
88  }
89 
90  return $sId;
91  }
92 
98  public function getSelectionList()
99  {
100  if ($this->_aSelectionList === null) {
101  $this->_aSelectionList = array();
102 
103  $oProduct = oxNew('oxarticle');
104  $oProduct->load($this->getEditObjectId());
105 
106  if ($oCatList = $this->_getCategoryList($oProduct)) {
107  $this->_aSelectionList["oxcategory"][$this->_iEditLang] = $oCatList;
108  }
109 
110  if ($oVndList = $this->_getVendorList($oProduct)) {
111  $this->_aSelectionList["oxvendor"][$this->_iEditLang] = $oVndList;
112  }
113 
114  if ($oManList = $this->_getManufacturerList($oProduct)) {
115  $this->_aSelectionList["oxmanufacturer"][$this->_iEditLang] = $oManList;
116  }
117 
118  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
119  $aLangs = $oProduct->getAvailableInLangs();
120  foreach ($aLangs as $iLang => $sLangTitle) {
121  if ($oTagList = $this->_getTagList($oProduct, $iLang)) {
122  $this->_aSelectionList["oxtag"][$iLang] = $oTagList;
123  }
124  }
125  // END deprecated
126  }
127 
128  return $this->_aSelectionList;
129  }
130 
138  protected function _getCategoryList($oArticle)
139  {
140  $sMainCatId = false;
141  if ($oMainCat = $oArticle->getCategory()) {
142  $sMainCatId = $oMainCat->getId();
143  }
144 
145  $aCatList = array();
146  $iLang = $this->getEditLang();
147 
148  // adding categories
149  $sView = getViewName('oxobject2category');
150  $oDb = oxDb::getDb(oxDB::FETCH_MODE_ASSOC);
151  $sSqlForPriceCategories = $oArticle->getSqlForPriceCategories('oxid');
152  $sQuotesArticleId = $oDb->quote($oArticle->getId());
153  $sQ = "select oxobject2category.oxcatnid as oxid from {$sView} as oxobject2category " .
154  "where oxobject2category.oxobjectid=" . $sQuotesArticleId . " union " . $sSqlForPriceCategories;
155 
156  $oRs = $oDb->execute($sQ);
157  if ($oRs != false && $oRs->recordCount() > 0) {
158  while (!$oRs->EOF) {
159  $oCat = oxNew('oxcategory');
160  if ($oCat->loadInLang($iLang, current($oRs->fields))) {
161  if ($sMainCatId == $oCat->getId()) {
162  $sSuffix = oxRegistry::getLang()->translateString('(main category)', $this->getEditLang());
163  $sTitleField = 'oxcategories__oxtitle';
164  $sTitle = $oCat->$sTitleField->getRawValue() . " " . $sSuffix;
165  $oCat->$sTitleField = new oxField($sTitle, oxField::T_RAW);
166  }
167  $aCatList[] = $oCat;
168  }
169  $oRs->moveNext();
170  }
171  }
172 
173  return $aCatList;
174  }
175 
183  protected function _getVendorList($oArticle)
184  {
185  if ($oArticle->oxarticles__oxvendorid->value) {
186  $oVendor = oxNew('oxvendor');
187  if ($oVendor->loadInLang($this->getEditLang(), $oArticle->oxarticles__oxvendorid->value)) {
188  return array($oVendor);
189  }
190  }
191  }
192 
200  protected function _getManufacturerList($oArticle)
201  {
202  if ($oArticle->oxarticles__oxmanufacturerid->value) {
203  $oManufacturer = oxNew('oxmanufacturer');
204  if ($oManufacturer->loadInLang($this->getEditLang(), $oArticle->oxarticles__oxmanufacturerid->value)) {
205  return array($oManufacturer);
206  }
207  }
208  }
209 
220  protected function _getTagList($oArticle, $iLang)
221  {
222  $oArticleTagList = oxNew("oxarticletaglist");
223  $oArticleTagList->setLanguage($iLang);
224  $oArticleTagList->load($oArticle->getId());
225  $aTagsList = array();
226  if (count($aTags = $oArticleTagList->getArray())) {
227  $sShopId = $this->getConfig()->getShopId();
228  $iProdId = $oArticle->getId();
229  foreach ($aTags as $sTitle => $oTagObject) {
230  // A. we do not have oxTag object yet, so reusing manufacturers for general interface
231  $oTag = oxNew("oxManufacturer");
232  $oTag->setLanguage($iLang);
233  $oTag->setId(md5(strtolower($sShopId . $this->_getStdUrl($iProdId, "oxtag", "tag", $iLang, $sTitle))));
234  $oTag->oxmanufacturers__oxtitle = new oxField($sTitle);
235  $aTagsList[] = $oTag;
236  }
237  }
238 
239  return $aTagsList;
240  }
241 
247  public function getActCategory()
248  {
249  $oCat = oxNew('oxcategory');
250 
251  return ($oCat->load($this->getActCatId())) ? $oCat : null;
252  }
253 
261  public function getTag()
262  {
263  if ($this->getActCatType() == 'oxtag') {
264 
265  $iLang = $this->getActCatLang();
266  $sTagId = $this->getActCatId();
267 
268  $oProduct = oxNew('oxarticle');
269  $oProduct->loadInLang($iLang, $this->getEditObjectId());
270 
271  $aList = $this->_getTagList($oProduct, $iLang);
272  foreach ($aList as $oTag) {
273  if ($oTag->getId() == $sTagId) {
274  return $oTag->getTitle();
275  }
276  }
277  }
278  }
279 
285  public function getActVendor()
286  {
287  $oVendor = oxNew('oxvendor');
288 
289  return ($this->getActCatType() == 'oxvendor' && $oVendor->load($this->getActCatId())) ? $oVendor : null;
290  }
291 
297  public function getActManufacturer()
298  {
299  $oManufacturer = oxNew('oxmanufacturer');
300  $blLoaded = $this->getActCatType() == 'oxmanufacturer' && $oManufacturer->load($this->getActCatId());
301 
302  return ($blLoaded) ? $oManufacturer : null;
303  }
304 
310  public function getListType()
311  {
312  switch ($this->getActCatType()) {
313  case 'oxvendor':
314  return 'vendor';
315  case 'oxmanufacturer':
316  return 'manufacturer';
317  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
318  case 'oxtag':
319  return 'tag';
320  // END deprecated
321  }
322  }
323 
329  public function getEditLang()
330  {
331  return $this->getActCatLang();
332  }
333 
339  protected function _getAltSeoEntryId()
340  {
341  return $this->getEditObjectId();
342  }
343 
349  protected function _getSeoEntryType()
350  {
351  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
352  if ($this->getTag()) {
353  return 'dynamic';
354  } else {
355  return $this->_getType();
356  }
357  // END deprecated
358  }
359 
365  protected function _getType()
366  {
367  return 'oxarticle';
368  }
369 
377  public function processParam($sParam)
378  {
379  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
380  if ($this->getTag()) {
381  return '';
382  } else {
383  return $this->getActCatId();
384  }
385  // END deprecated
386  }
387 
393  protected function _getEncoder()
394  {
395  return oxRegistry::get("oxSeoEncoderArticle");
396  }
397 
403  public function getEntryUri()
404  {
405  $oProduct = oxNew('oxarticle');
406  if ($oProduct->load($this->getEditObjectId())) {
407  $oEncoder = $this->_getEncoder();
408  switch ($this->getActCatType()) {
409  case 'oxvendor':
410  return $oEncoder->getArticleVendorUri($oProduct, $this->getEditLang());
411  case 'oxmanufacturer':
412  return $oEncoder->getArticleManufacturerUri($oProduct, $this->getEditLang());
413  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
414  case 'oxtag':
415  return $oEncoder->getArticleTagUri($oProduct, $this->getActCatLang());
416  // END deprecated
417  default:
418  if ($this->getActCatId()) {
419  return $oEncoder->getArticleUri($oProduct, $this->getEditLang());
420  } else {
421  return $oEncoder->getArticleMainUri($oProduct, $this->getEditLang());
422  }
423  }
424  }
425  }
426 
440  protected function _getStdUrl($sOxid, $sCatType = null, $sListType = null, $iLang = null, $sTag = null)
441  {
442  $iLang = $iLang !== null ? $iLang : $this->getEditLang();
443  $sCatType = $sCatType !== null ? $sCatType : $this->getActCatType();
444  $sListType = $sListType !== null ? $sListType : $this->getListType();
445 
446  $aParams = array();
447  if ($sListType) {
448  $aParams["listtype"] = $sListType;
449  }
450 
451  $oProduct = oxNew('oxarticle');
452  $oProduct->loadInLang($iLang, $sOxid);
453 
454  // adding vendor or manufacturer id
455  switch ($sCatType) {
456  case 'oxvendor':
457  $aParams["cnid"] = "v_" . $this->getActCatId();
458  break;
459  case 'oxmanufacturer':
460  $aParams["mnid"] = $this->getActCatId();
461  break;
462  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
463  case 'oxtag':
464  $aParams["searchtag"] = $sTag !== null ? $sTag : $this->getTag();
465  break;
466  // END deprecated
467  default:
468  $aParams["cnid"] = $this->getActCatId();
469  break;
470  }
471 
472  $oUtilsUrl = oxRegistry::get("oxUtilsUrl");
473 
474  return trim($oUtilsUrl->appendUrl($oProduct->getBaseStdLink($iLang, true, false), $aParams), '&amp;');
475  }
476 
482  public function showCatSelect()
483  {
484  return true;
485  }
486 
492  protected function _getSaveObjectId()
493  {
494  $sId = $this->getEditObjectId();
495  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
496  if ($this->getActCatType() == 'oxtag') {
497  $sId = $this->_getEncoder()->getDynamicObjectId($this->getConfig()->getShopId(), $this->_getStdUrl($sId));
498  }
499  // END deprecated
500 
501  return $sId;
502  }
503 
509  public function isEntryFixed()
510  {
511  $oDb = oxDb::getDb();
512 
513  $sId = $this->_getSaveObjectId();
514  $iLang = (int) $this->getEditLang();
515  $iShopId = $this->getConfig()->getShopId();
516  $sParam = $this->processParam($this->getActCatId());
517 
518  $sQ = "select oxfixed from oxseo where
519  oxseo.oxobjectid = " . $oDb->quote($sId) . " and
520  oxseo.oxshopid = '{$iShopId}' and oxseo.oxlang = {$iLang} and oxparams = " . $oDb->quote($sParam);
521 
522  return (bool) oxDb::getDb()->getOne($sQ, false, false);
523  }
524 }