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 $oEncoder->markAsExpired( null, $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( $aStaticUrl, $oShop->getId(), $this->_iEditLang );
00132 }
00133
00134 return $this->autosave();
00135 }
00136
00142 public function dropSeoIds()
00143 {
00144 $sQ = 'delete from oxseo where oxshopid = "'.oxConfig::getInstance()->getShopId().'" and oxtype != "static" and oxfixed != 1';
00145 oxDB::getDb()->execute( $sQ );
00146 }
00147
00153 public function deleteStaticUrl()
00154 {
00155 if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00156 if ( ( $sObjectid = $aStaticUrl['oxseo__oxobjectid'] ) && $sObjectid != '-1' ) {
00157
00158 $soxId = oxConfig::getParameter( 'oxid' );
00159 oxDb::getDb()->execute( "delete from oxseo where oxobjectid = '{$sObjectid}' and oxshopid = '{$soxId}'" );
00160 }
00161 }
00162 }
00163 }