OXID eShop CE  4.10.6
 All Classes Namespaces Files Functions Variables Pages
shop_seo.php
Go to the documentation of this file.
1 <?php
2 
8 class Shop_Seo extends Shop_Config
9 {
10 
14  protected $_sActSeoObject = null;
15 
22  public function render()
23  {
25 
26  $this->_aViewData['subjlang'] = $this->_iEditLang;
27 
28  // loading shop
29  $oShop = oxNew('oxshop');
30  $oShop->loadInLang($this->_iEditLang, $this->_aViewData['edit']->getId());
31  $this->_aViewData['edit'] = $oShop;
32 
33  // loading static seo urls
34  $sQ = "select oxstdurl, oxobjectid from oxseo where oxtype='static' and oxshopid=" . oxDb::getDb()->quote($oShop->getId()) . " group by oxobjectid order by oxstdurl";
35 
36  $oList = oxNew('oxlist');
37  $oList->init('oxbase', 'oxseo');
38  $oList->selectString($sQ);
39 
40  $this->_aViewData['aStaticUrls'] = $oList;
41 
42  // loading active url info
43  $this->_loadActiveUrl($oShop->getId());
44 
45  return "shop_seo.tpl";
46  }
47 
53  protected function _loadActiveUrl($iShopId)
54  {
55  $sActObject = null;
56  if ($this->_sActSeoObject) {
57  $sActObject = $this->_sActSeoObject;
58  } elseif (is_array($aStatUrl = oxRegistry::getConfig()->getRequestParameter('aStaticUrl'))) {
59  $sActObject = $aStatUrl['oxseo__oxobjectid'];
60  }
61 
62  if ($sActObject && $sActObject != '-1') {
63  $this->_aViewData['sActSeoObject'] = $sActObject;
64 
65  $oDb = oxDb::getDb(oxDB::FETCH_MODE_ASSOC);
66  $sQ = "select oxseourl, oxlang from oxseo where oxobjectid = " . $oDb->quote($sActObject) . " and oxshopid = " . $oDb->quote($iShopId);
67  $oRs = $oDb->execute($sQ);
68  if ($oRs != false && $oRs->recordCount() > 0) {
69  while (!$oRs->EOF) {
70  $aSeoUrls[$oRs->fields['oxlang']] = array($sActObject, $oRs->fields['oxseourl']);
71  $oRs->moveNext();
72  }
73  $this->_aViewData['aSeoUrls'] = $aSeoUrls;
74  }
75  }
76  }
77 
81  public function save()
82  {
83  // saving config params
84  $this->saveConfVars();
85 
86  $oShop = oxNew('oxshop');
87  if ($oShop->loadInLang($this->_iEditLang, $this->getEditObjectId())) {
88 
89  //assigning values
90  $oShop->setLanguage(0);
91  $oShop->assign(oxRegistry::getConfig()->getRequestParameter('editval'));
92  $oShop->setLanguage($this->_iEditLang);
93  $oShop->save();
94 
95  // saving static url changes
96  if (is_array($aStaticUrl = oxRegistry::getConfig()->getRequestParameter('aStaticUrl'))) {
97  $this->_sActSeoObject = oxRegistry::get("oxSeoEncoder")->encodeStaticUrls($this->_processUrls($aStaticUrl), $oShop->getId(), $this->_iEditLang);
98  }
99  }
100  }
101 
109  protected function _processUrls($aUrls)
110  {
111  if (isset($aUrls['oxseo__oxstdurl']) && $aUrls['oxseo__oxstdurl']) {
112  $aUrls['oxseo__oxstdurl'] = $this->_cleanupUrl($aUrls['oxseo__oxstdurl']);
113  }
114 
115  if (isset($aUrls['oxseo__oxseourl']) && is_array($aUrls['oxseo__oxseourl'])) {
116  foreach ($aUrls['oxseo__oxseourl'] as $iPos => $sUrl) {
117  $aUrls['oxseo__oxseourl'][$iPos] = $this->_cleanupUrl($sUrl);
118  }
119  }
120 
121  return $aUrls;
122  }
123 
131  protected function _cleanupUrl($sUrl)
132  {
133  // replacing &amp; to & or removing double &&
134  while ((stripos($sUrl, '&amp;') !== false) || (stripos($sUrl, '&&') !== false)) {
135  $sUrl = str_replace('&amp;', '&', $sUrl);
136  $sUrl = str_replace('&&', '&', $sUrl);
137  }
138 
139  // converting & to &amp;
140  return str_replace('&', '&amp;', $sUrl);
141  }
142 
146  public function dropSeoIds()
147  {
148  $this->resetSeoData($this->getConfig()->getShopId());
149  }
150 
154  public function deleteStaticUrl()
155  {
156  if (is_array($aStaticUrl = oxRegistry::getConfig()->getRequestParameter('aStaticUrl'))) {
157  if (($sObjectid = $aStaticUrl['oxseo__oxobjectid']) && $sObjectid != '-1') {
158  // active shop id
159  $soxId = $this->getEditObjectId();
160  $oDb = oxDb::getDb();
161  $oDb->execute("delete from oxseo where oxtype='static' and oxobjectid = " . $oDb->quote($sObjectid) . " and oxshopid = " . $oDb->quote($soxId));
162  }
163  }
164  }
165 }