OXID eShop CE  4.9.7
 All Classes 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  parent::save();
84 
85  // saving config params
86  $this->saveConfVars();
87 
88  $oShop = oxNew('oxshop');
89  if ($oShop->loadInLang($this->_iEditLang, $this->getEditObjectId())) {
90 
91  //assigning values
92  $oShop->setLanguage(0);
93  $oShop->assign(oxRegistry::getConfig()->getRequestParameter('editval'));
94  $oShop->setLanguage($this->_iEditLang);
95  $oShop->save();
96 
97  // saving static url changes
98  if (is_array($aStaticUrl = oxRegistry::getConfig()->getRequestParameter('aStaticUrl'))) {
99  $this->_sActSeoObject = oxRegistry::get("oxSeoEncoder")->encodeStaticUrls($this->_processUrls($aStaticUrl), $oShop->getId(), $this->_iEditLang);
100  }
101  }
102  }
103 
111  protected function _processUrls($aUrls)
112  {
113  if (isset($aUrls['oxseo__oxstdurl']) && $aUrls['oxseo__oxstdurl']) {
114  $aUrls['oxseo__oxstdurl'] = $this->_cleanupUrl($aUrls['oxseo__oxstdurl']);
115  }
116 
117  if (isset($aUrls['oxseo__oxseourl']) && is_array($aUrls['oxseo__oxseourl'])) {
118  foreach ($aUrls['oxseo__oxseourl'] as $iPos => $sUrl) {
119  $aUrls['oxseo__oxseourl'][$iPos] = $this->_cleanupUrl($sUrl);
120  }
121  }
122 
123  return $aUrls;
124  }
125 
133  protected function _cleanupUrl($sUrl)
134  {
135  // replacing &amp; to & or removing double &&
136  while ((stripos($sUrl, '&amp;') !== false) || (stripos($sUrl, '&&') !== false)) {
137  $sUrl = str_replace('&amp;', '&', $sUrl);
138  $sUrl = str_replace('&&', '&', $sUrl);
139  }
140 
141  // converting & to &amp;
142  return str_replace('&', '&amp;', $sUrl);
143  }
144 
148  public function dropSeoIds()
149  {
150  $this->resetSeoData($this->getConfig()->getShopId());
151  }
152 
156  public function deleteStaticUrl()
157  {
158  if (is_array($aStaticUrl = oxRegistry::getConfig()->getRequestParameter('aStaticUrl'))) {
159  if (($sObjectid = $aStaticUrl['oxseo__oxobjectid']) && $sObjectid != '-1') {
160  // active shop id
161  $soxId = $this->getEditObjectId();
162  $oDb = oxDb::getDb();
163  $oDb->execute("delete from oxseo where oxtype='static' and oxobjectid = " . $oDb->quote($sObjectid) . " and oxshopid = " . $oDb->quote($soxId));
164  }
165  }
166  }
167 }