OXID eShop CE  4.8.12
 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 {
13  protected $_sActSeoObject = null;
14 
21  public function render()
22  {
24 
25  $this->_aViewData['subjlang'] = $this->_iEditLang;
26 
27  // loading shop
28  $oShop = oxNew( 'oxshop' );
29  $oShop->loadInLang( $this->_iEditLang, $this->_aViewData['edit']->getId() );
30  $this->_aViewData['edit'] = $oShop;
31 
32  // loading static seo urls
33  $sQ = "select oxstdurl, oxobjectid from oxseo where oxtype='static' and oxshopid=".oxDb::getDb()->quote( $oShop->getId() )." group by oxobjectid order by oxstdurl";
34 
35  $oList = oxNew( 'oxlist' );
36  $oList->init( 'oxbase', 'oxseo' );
37  $oList->selectString( $sQ );
38 
39  $this->_aViewData['aStaticUrls'] = $oList;
40 
41  // loading active url info
42  $this->_loadActiveUrl( $oShop->getId() );
43 
44  return "shop_seo.tpl";
45  }
46 
54  protected function _loadActiveUrl( $iShopId )
55  {
56  $sActObject = null;
57  if ( $this->_sActSeoObject ) {
58  $sActObject = $this->_sActSeoObject;
59  } elseif ( is_array( $aStatUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
60  $sActObject = $aStatUrl['oxseo__oxobjectid'];
61  }
62 
63  if ( $sActObject && $sActObject != '-1' ) {
64  $this->_aViewData['sActSeoObject'] = $sActObject;
65 
66  $oDb = oxDb::getDb( oxDB::FETCH_MODE_ASSOC );
67  $sQ = "select oxseourl, oxlang from oxseo where oxobjectid = ".$oDb->quote( $sActObject )." and oxshopid = ".$oDb->quote( $iShopId );
68  $oRs = $oDb->execute( $sQ );
69  if ( $oRs != false && $oRs->recordCount() > 0 ) {
70  while ( !$oRs->EOF ) {
71  $aSeoUrls[$oRs->fields['oxlang']] = array( $sActObject, $oRs->fields['oxseourl'] );
72  $oRs->moveNext();
73  }
74  $this->_aViewData['aSeoUrls'] = $aSeoUrls;
75  }
76  }
77  }
78 
84  public function save()
85  {
86  parent::save();
87 
88  // saving config params
89  $this->saveConfVars();
90 
91  $oShop = oxNew( 'oxshop' );
92  if ( $oShop->loadInLang( $this->_iEditLang, $this->getEditObjectId() ) ) {
93 
94  //assigning values
95  $oShop->setLanguage( 0 );
96  $oShop->assign( oxConfig::getParameter( 'editval' ) );
97  $oShop->setLanguage( $this->_iEditLang );
98  $oShop->save();
99 
100  // saving static url changes
101  if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
102  $this->_sActSeoObject = oxRegistry::get("oxSeoEncoder")->encodeStaticUrls( $this->_processUrls( $aStaticUrl ), $oShop->getId(), $this->_iEditLang );
103  }
104  }
105  }
106 
114  protected function _processUrls( $aUrls )
115  {
116  if ( isset( $aUrls['oxseo__oxstdurl'] ) && $aUrls['oxseo__oxstdurl'] ) {
117  $aUrls['oxseo__oxstdurl'] = $this->_cleanupUrl( $aUrls['oxseo__oxstdurl'] );
118  }
119 
120  if ( isset( $aUrls['oxseo__oxseourl'] ) && is_array( $aUrls['oxseo__oxseourl'] ) ) {
121  foreach ( $aUrls['oxseo__oxseourl'] as $iPos => $sUrl) {
122  $aUrls['oxseo__oxseourl'][$iPos] = $this->_cleanupUrl( $sUrl );
123  }
124  }
125 
126  return $aUrls;
127  }
128 
136  protected function _cleanupUrl( $sUrl )
137  {
138  // replacing &amp; to & or removing double &&
139  while ( ( stripos( $sUrl, '&amp;' ) !== false ) || ( stripos( $sUrl, '&&' ) !== false ) ) {
140  $sUrl = str_replace( '&amp;', '&', $sUrl );
141  $sUrl = str_replace( '&&', '&', $sUrl );
142  }
143 
144  // converting & to &amp;
145  return str_replace( '&', '&amp;', $sUrl );
146  }
147 
153  public function dropSeoIds()
154  {
155  $this->resetSeoData( $this->getConfig()->getShopId() );
156  }
157 
163  public function deleteStaticUrl()
164  {
165  if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
166  if ( ( $sObjectid = $aStaticUrl['oxseo__oxobjectid'] ) && $sObjectid != '-1' ) {
167  // active shop id
168  $soxId = $this->getEditObjectId();
169  $oDb = oxDb::getDb();
170  $oDb->execute( "delete from oxseo where oxtype='static' and oxobjectid = ".$oDb->quote( $sObjectid ) ." and oxshopid = ".$oDb->quote( $soxId ) );
171  }
172  }
173  }
174 }