OXID eShop CE  4.9.9
 All Classes 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  $aLangs = $oProduct->getAvailableInLangs();
119  foreach ($aLangs as $iLang => $sLangTitle) {
120  if ($oTagList = $this->_getTagList($oProduct, $iLang)) {
121  $this->_aSelectionList["oxtag"][$iLang] = $oTagList;
122  }
123  }
124  }
125 
126  return $this->_aSelectionList;
127  }
128 
136  protected function _getCategoryList($oArticle)
137  {
138  $sMainCatId = false;
139  if ($oMainCat = $oArticle->getCategory()) {
140  $sMainCatId = $oMainCat->getId();
141  }
142 
143  $aCatList = array();
144  $iLang = $this->getEditLang();
145 
146  // adding categories
147  $sView = getViewName('oxobject2category');
148  $oDb = oxDb::getDb(oxDB::FETCH_MODE_ASSOC);
149  $sSqlForPriceCategories = $oArticle->getSqlForPriceCategories('oxid');
150  $sQuotesArticleId = $oDb->quote($oArticle->getId());
151  $sQ = "select oxobject2category.oxcatnid as oxid from {$sView} as oxobject2category " .
152  "where oxobject2category.oxobjectid=" . $sQuotesArticleId . " union " . $sSqlForPriceCategories;
153 
154  $oRs = $oDb->execute($sQ);
155  if ($oRs != false && $oRs->recordCount() > 0) {
156  while (!$oRs->EOF) {
157  $oCat = oxNew('oxcategory');
158  if ($oCat->loadInLang($iLang, current($oRs->fields))) {
159  if ($sMainCatId == $oCat->getId()) {
160  $sSuffix = oxRegistry::getLang()->translateString('(main category)', $this->getEditLang());
161  $sTitleField = 'oxcategories__oxtitle';
162  $sTitle = $oCat->$sTitleField->getRawValue() . " " . $sSuffix;
163  $oCat->$sTitleField = new oxField($sTitle, oxField::T_RAW);
164  }
165  $aCatList[] = $oCat;
166  }
167  $oRs->moveNext();
168  }
169  }
170 
171  return $aCatList;
172  }
173 
181  protected function _getVendorList($oArticle)
182  {
183  if ($oArticle->oxarticles__oxvendorid->value) {
184  $oVendor = oxNew('oxvendor');
185  if ($oVendor->loadInLang($this->getEditLang(), $oArticle->oxarticles__oxvendorid->value)) {
186  return array($oVendor);
187  }
188  }
189  }
190 
198  protected function _getManufacturerList($oArticle)
199  {
200  if ($oArticle->oxarticles__oxmanufacturerid->value) {
201  $oManufacturer = oxNew('oxmanufacturer');
202  if ($oManufacturer->loadInLang($this->getEditLang(), $oArticle->oxarticles__oxmanufacturerid->value)) {
203  return array($oManufacturer);
204  }
205  }
206  }
207 
216  protected function _getTagList($oArticle, $iLang)
217  {
218  $oArticleTagList = oxNew("oxarticletaglist");
219  $oArticleTagList->setLanguage($iLang);
220  $oArticleTagList->load($oArticle->getId());
221  $aTagsList = array();
222  if (count($aTags = $oArticleTagList->getArray())) {
223  $sShopId = $this->getConfig()->getShopId();
224  $iProdId = $oArticle->getId();
225  foreach ($aTags as $sTitle => $oTagObject) {
226  // A. we do not have oxTag object yet, so reusing manufacturers for general interface
227  $oTag = oxNew("oxManufacturer");
228  $oTag->setLanguage($iLang);
229  $oTag->setId(md5(strtolower($sShopId . $this->_getStdUrl($iProdId, "oxtag", "tag", $iLang, $sTitle))));
230  $oTag->oxmanufacturers__oxtitle = new oxField($sTitle);
231  $aTagsList[] = $oTag;
232  }
233  }
234 
235  return $aTagsList;
236  }
237 
243  public function getActCategory()
244  {
245  $oCat = oxNew('oxcategory');
246 
247  return ($oCat->load($this->getActCatId())) ? $oCat : null;
248  }
249 
255  public function getTag()
256  {
257  if ($this->getActCatType() == 'oxtag') {
258 
259  $iLang = $this->getActCatLang();
260  $sTagId = $this->getActCatId();
261 
262  $oProduct = oxNew('oxarticle');
263  $oProduct->loadInLang($iLang, $this->getEditObjectId());
264 
265  $aList = $this->_getTagList($oProduct, $iLang);
266  foreach ($aList as $oTag) {
267  if ($oTag->getId() == $sTagId) {
268  return $oTag->getTitle();
269  }
270  }
271  }
272  }
273 
279  public function getActVendor()
280  {
281  $oVendor = oxNew('oxvendor');
282 
283  return ($this->getActCatType() == 'oxvendor' && $oVendor->load($this->getActCatId())) ? $oVendor : null;
284  }
285 
291  public function getActManufacturer()
292  {
293  $oManufacturer = oxNew('oxmanufacturer');
294  $blLoaded = $this->getActCatType() == 'oxmanufacturer' && $oManufacturer->load($this->getActCatId());
295 
296  return ($blLoaded) ? $oManufacturer : null;
297  }
298 
304  public function getListType()
305  {
306  switch ($this->getActCatType()) {
307  case 'oxvendor':
308  return 'vendor';
309  case 'oxmanufacturer':
310  return 'manufacturer';
311  case 'oxtag':
312  return 'tag';
313  }
314  }
315 
321  public function getEditLang()
322  {
323  return $this->getActCatLang();
324  }
325 
331  protected function _getAltSeoEntryId()
332  {
333  return $this->getEditObjectId();
334  }
335 
341  protected function _getSeoEntryType()
342  {
343  if ($this->getTag()) {
344  return 'dynamic';
345  } else {
346  return $this->_getType();
347  }
348  }
349 
355  protected function _getType()
356  {
357  return 'oxarticle';
358  }
359 
367  public function processParam($sParam)
368  {
369  if ($this->getTag()) {
370  return '';
371  } else {
372  return $this->getActCatId();
373  }
374  }
375 
381  protected function _getEncoder()
382  {
383  return oxRegistry::get("oxSeoEncoderArticle");
384  }
385 
391  public function getEntryUri()
392  {
393  $oProduct = oxNew('oxarticle');
394  if ($oProduct->load($this->getEditObjectId())) {
395  $oEncoder = $this->_getEncoder();
396  switch ($this->getActCatType()) {
397  case 'oxvendor':
398  return $oEncoder->getArticleVendorUri($oProduct, $this->getEditLang());
399  case 'oxmanufacturer':
400  return $oEncoder->getArticleManufacturerUri($oProduct, $this->getEditLang());
401  case 'oxtag':
402  return $oEncoder->getArticleTagUri($oProduct, $this->getActCatLang());
403  default:
404  if ($this->getActCatId()) {
405  return $oEncoder->getArticleUri($oProduct, $this->getEditLang());
406  } else {
407  return $oEncoder->getArticleMainUri($oProduct, $this->getEditLang());
408  }
409  }
410  }
411  }
412 
424  protected function _getStdUrl($sOxid, $sCatType = null, $sListType = null, $iLang = null, $sTag = null)
425  {
426  $iLang = $iLang !== null ? $iLang : $this->getEditLang();
427  $sCatType = $sCatType !== null ? $sCatType : $this->getActCatType();
428  $sListType = $sListType !== null ? $sListType : $this->getListType();
429 
430  $aParams = array();
431  if ($sListType) {
432  $aParams["listtype"] = $sListType;
433  }
434 
435  $oProduct = oxNew('oxarticle');
436  $oProduct->loadInLang($iLang, $sOxid);
437 
438  // adding vendor or manufacturer id
439  switch ($sCatType) {
440  case 'oxvendor':
441  $aParams["cnid"] = "v_" . $this->getActCatId();
442  break;
443  case 'oxmanufacturer':
444  $aParams["mnid"] = $this->getActCatId();
445  break;
446  case 'oxtag':
447  $aParams["searchtag"] = $sTag !== null ? $sTag : $this->getTag();
448  break;
449  default:
450  $aParams["cnid"] = $this->getActCatId();
451  break;
452  }
453 
454  $oUtilsUrl = oxRegistry::get("oxUtilsUrl");
455 
456  return trim($oUtilsUrl->appendUrl($oProduct->getBaseStdLink($iLang, true, false), $aParams), '&amp;');
457  }
458 
464  public function showCatSelect()
465  {
466  return true;
467  }
468 
474  protected function _getSaveObjectId()
475  {
476  $sId = $this->getEditObjectId();
477  if ($this->getActCatType() == 'oxtag') {
478  $sId = $this->_getEncoder()->getDynamicObjectId($this->getConfig()->getShopId(), $this->_getStdUrl($sId));
479  }
480 
481  return $sId;
482  }
483 
489  public function isEntryFixed()
490  {
491  $oDb = oxDb::getDb();
492 
493  $sId = $this->_getSaveObjectId();
494  $iLang = (int) $this->getEditLang();
495  $iShopId = $this->getConfig()->getShopId();
496  $sParam = $this->processParam($this->getActCatId());
497 
498  $sQ = "select oxfixed from oxseo where
499  oxseo.oxobjectid = " . $oDb->quote($sId) . " and
500  oxseo.oxshopid = '{$iShopId}' and oxseo.oxlang = {$iLang} and oxparams = " . $oDb->quote($sParam);
501 
502  return (bool) oxDb::getDb()->getOne($sQ, false, false);
503  }
504 }