Go to the documentation of this file.00001 <?php
00002
00008 class Shop_Seo extends Shop_Config
00009 {
00013 protected $_sActSeoObject = null;
00014
00021 public function render()
00022 {
00023 parent::render();
00024
00025 $this->_aViewData['subjlang'] = $this->_iEditLang;
00026
00027
00028 $oShop = oxNew( 'oxshop' );
00029 $oShop->loadInLang( $this->_iEditLang, $this->_aViewData['edit']->getId() );
00030 $this->_aViewData['edit'] = $oShop;
00031
00032
00033 $sQ = "select oxstdurl, oxobjectid from oxseo where oxtype='static' and oxshopid=".oxDb::getDb()->quote( $oShop->getId() )." group by oxobjectid order by oxstdurl";
00034
00035 $oList = oxNew( 'oxlist' );
00036 $oList->init( 'oxbase', 'oxseo' );
00037 $oList->selectString( $sQ );
00038
00039 $this->_aViewData['aStaticUrls'] = $oList;
00040
00041
00042 $this->_loadActiveUrl( $oShop->getId() );
00043
00044 return "shop_seo.tpl";
00045 }
00046
00054 protected function _loadActiveUrl( $iShopId )
00055 {
00056 $sActObject = null;
00057 if ( $this->_sActSeoObject ) {
00058 $sActObject = $this->_sActSeoObject;
00059 } elseif ( is_array( $aStatUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00060 $sActObject = $aStatUrl['oxseo__oxobjectid'];
00061 }
00062
00063 if ( $sActObject && $sActObject != '-1' ) {
00064 $this->_aViewData['sActSeoObject'] = $sActObject;
00065
00066 $oDb = oxDb::getDb(true);
00067 $sQ = "select oxseourl, oxlang from oxseo where oxobjectid = ".$oDb->quote( $sActObject )." and oxshopid = ".$oDb->quote( $iShopId );
00068 $oRs = $oDb->execute( $sQ );
00069 if ( $oRs != false && $oRs->recordCount() > 0 ) {
00070 while ( !$oRs->EOF ) {
00071 $aSeoUrls[$oRs->fields['oxlang']] = array( $sActObject, $oRs->fields['oxseourl'] );
00072 $oRs->moveNext();
00073 }
00074 $this->_aViewData['aSeoUrls'] = $aSeoUrls;
00075 }
00076 }
00077 }
00078
00084 public function save()
00085 {
00086
00087
00088 $this->saveConfVars();
00089
00090 $oShop = oxNew( 'oxshop' );
00091 if ( $oShop->loadInLang( $this->_iEditLang, oxConfig::getParameter( 'oxid' ) ) ) {
00092
00093
00094 $oShop->setLanguage( 0 );
00095 $oShop->assign( oxConfig::getParameter( 'editval' ) );
00096 $oShop->setLanguage( $this->_iEditLang );
00097 $oShop->save();
00098
00099 oxUtils::getInstance()->rebuildCache();
00100
00101
00102 if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00103 $this->_sActSeoObject = oxSeoEncoder::getInstance()->encodeStaticUrls( $this->_processUrls( $aStaticUrl ), $oShop->getId(), $this->_iEditLang );
00104 }
00105 }
00106 }
00107
00115 protected function _processUrls( $aUrls )
00116 {
00117 if ( isset( $aUrls['oxseo__oxstdurl'] ) && $aUrls['oxseo__oxstdurl'] ) {
00118 $aUrls['oxseo__oxstdurl'] = $this->_cleanupUrl( $aUrls['oxseo__oxstdurl'] );
00119 }
00120
00121 if ( isset( $aUrls['oxseo__oxseourl'] ) && is_array( $aUrls['oxseo__oxseourl'] ) ) {
00122 foreach ( $aUrls['oxseo__oxseourl'] as $iPos => $sUrl) {
00123 $aUrls['oxseo__oxseourl'][$iPos] = $this->_cleanupUrl( $sUrl );
00124 }
00125 }
00126
00127 return $aUrls;
00128 }
00129
00137 protected function _cleanupUrl( $sUrl )
00138 {
00139
00140 while ( ( stripos( $sUrl, '&' ) !== false ) || ( stripos( $sUrl, '&&' ) !== false ) ) {
00141 $sUrl = str_replace( '&', '&', $sUrl );
00142 $sUrl = str_replace( '&&', '&', $sUrl );
00143 }
00144
00145
00146 return str_replace( '&', '&', $sUrl );
00147 }
00148
00154 public function dropSeoIds()
00155 {
00156 $this->resetSeoData( $this->getConfig()->getShopId() );
00157 }
00158
00164 public function deleteStaticUrl()
00165 {
00166 if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00167 if ( ( $sObjectid = $aStaticUrl['oxseo__oxobjectid'] ) && $sObjectid != '-1' ) {
00168
00169 $soxId = oxConfig::getParameter( 'oxid' );
00170 $oDb = oxDb::getDb();
00171 $oDb->execute( "delete from oxseo where oxtype='static' and oxobjectid = ".$oDb->quote( $sObjectid ) ." and oxshopid = ".$oDb->quote( $soxId ) );
00172 }
00173 }
00174 }
00175 }