00001 <?php
00002
00009 class Shop_Seo extends Shop_Config
00010 {
00014 protected $_sActSeoObject = null;
00015
00022 public function render()
00023 {
00024 parent::render();
00025
00026
00027 $oShop = $this->_aViewData["edit"];
00028
00029 $oShop->loadInLang( $this->_iEditLang, $oShop->oxshops__oxid->value );
00030
00031
00032 $oOtherLang = $oShop->getAvailableInLangs();
00033 if (!isset($oOtherLang[$this->_iEditLang])) {
00034
00035 $oShop->loadInLang( key($oOtherLang), $oShop->oxshops__oxid->value );
00036 }
00037
00038 $aLang = array_diff ( oxLang::getInstance()->getLanguageNames(), $oOtherLang);
00039 if ( count( $aLang))
00040 $this->_aViewData["posslang"] = $aLang;
00041
00042 foreach ( $oOtherLang as $id => $language) {
00043 $oLang = new oxStdClass();
00044 $oLang->sLangDesc = $language;
00045 $oLang->selected = ($id == $this->_iEditLang);
00046 $this->_aViewData["otherlang"][$id] = clone $oLang;
00047 }
00048
00049
00050 $sQ = "select oxstdurl, oxobjectid from oxseo where oxtype='static' and oxshopid='".$oShop->getId()."' group by oxobjectid order by oxstdurl";
00051
00052 $oList = oxNew( 'oxlist' );
00053 $oList->init( 'oxbase', 'oxseo' );
00054 $oList->selectString( $sQ );
00055
00056 $this->_aViewData['aStaticUrls'] = $oList;
00057
00058
00059 $this->_loadActiveUrl( $oShop->getId() );
00060
00061 return "shop_seo.tpl";
00062 }
00063
00071 protected function _loadActiveUrl( $iShopId )
00072 {
00073 $sActObject = null;
00074 if ( $this->_sActSeoObject ) {
00075 $sActObject = $this->_sActSeoObject;
00076 } elseif ( is_array( $aStatUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00077 $sActObject = $aStatUrl['oxseo__oxobjectid'];
00078 }
00079
00080 if ( $sActObject && $sActObject != '-1' ) {
00081 $this->_aViewData['sActSeoObject'] = $sActObject;
00082
00083 $sQ = "select oxseourl, oxlang from oxseo where oxobjectid = '$sActObject' and oxshopid = '{$iShopId}'";
00084 $oRs = oxDb::getDb(true)->execute( $sQ );
00085 if ( $oRs != false && $oRs->recordCount() > 0 ) {
00086 while ( !$oRs->EOF ) {
00087 $aSeoUrls[$oRs->fields['oxlang']] = array( $oRs->fields['oxobjectid'], $oRs->fields['oxseourl'] );
00088 $oRs->moveNext();
00089 }
00090 $this->_aViewData['aSeoUrls'] = $aSeoUrls;
00091 }
00092 }
00093 }
00094
00100 public function save()
00101 {
00102
00103
00104 $this->saveConfVars();
00105
00106 $soxId = oxConfig::getParameter( 'oxid' );
00107 $aParams = oxConfig::getParameter( 'editval' );
00108 $aConfParams = oxConfig::getParameter( 'confstrs' );
00109
00110 $oEncoder = oxSeoEncoder::getInstance();
00111
00112
00113 $iDefLang = $this->getConfig()->getConfigParam( 'iDefSeoLang' );
00114 $iUserLang = (int) ( ( isset( $aConfParams['iDefSeoLang'] ) )? $aConfParams['iDefSeoLang'] : 0 );
00115 if ( $iDefLang != $iUserLang ) {
00116 $this->resetSeoData( $soxId );
00117 }
00118
00119 $oShop = oxNew( 'oxshop' );
00120 $oShop->load( $soxId );
00121
00122
00123 $oShop->assign( $aParams );
00124 $oShop->setLanguage( $this->_iEditLang );
00125 $oShop->save();
00126
00127 oxUtils::getInstance()->rebuildCache();
00128
00129
00130 if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00131 $this->_sActSeoObject = $oEncoder->encodeStaticUrls( $this->_processUrls( $aStaticUrl ), $oShop->getId(), $this->_iEditLang );
00132 }
00133
00134 return $this->autosave();
00135 }
00136
00144 protected function _processUrls( $aUrls )
00145 {
00146 if ( isset( $aUrls['oxseo__oxstdurl'] ) && $aUrls['oxseo__oxstdurl'] ) {
00147 $aUrls['oxseo__oxstdurl'] = $this->_cleanupUrl( $aUrls['oxseo__oxstdurl'] );
00148 }
00149
00150 if ( isset( $aUrls['oxseo__oxseourl'] ) && is_array( $aUrls['oxseo__oxseourl'] ) ) {
00151 foreach ( $aUrls['oxseo__oxseourl'] as $iPos => $sUrl) {
00152 $aUrls['oxseo__oxseourl'][$iPos] = $this->_cleanupUrl( $sUrl );
00153 }
00154 }
00155
00156 return $aUrls;
00157 }
00158
00166 protected function _cleanupUrl( $sUrl )
00167 {
00168
00169 while ( ( stripos( $sUrl, '&' ) !== false ) || ( stripos( $sUrl, '&&' ) !== false ) ) {
00170 $sUrl = str_replace( '&', '&', $sUrl );
00171 $sUrl = str_replace( '&&', '&', $sUrl );
00172 }
00173
00174
00175 return str_replace( '&', '&', $sUrl );
00176 }
00177
00183 public function dropSeoIds()
00184 {
00185 $sQ = 'delete from oxseo where oxshopid = "'.oxConfig::getInstance()->getShopId().'" and oxtype != "static" and oxfixed != 1';
00186 oxDB::getDb()->execute( $sQ );
00187 }
00188
00194 public function deleteStaticUrl()
00195 {
00196 if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00197 if ( ( $sObjectid = $aStaticUrl['oxseo__oxobjectid'] ) && $sObjectid != '-1' ) {
00198
00199 $soxId = oxConfig::getParameter( 'oxid' );
00200 oxDb::getDb()->execute( "delete from oxseo where oxobjectid = '{$sObjectid}' and oxshopid = '{$soxId}'" );
00201 }
00202 }
00203 }
00204 }