00001 <?php
00002
00006 class Object_Seo extends oxAdminDetails
00007 {
00015 public function render()
00016 {
00017 parent::render();
00018
00019 if ( ( $oObject= $this->_getObject( oxConfig::getParameter( 'oxid' ) ) ) ) {
00020
00021 $iShopId = $this->getConfig()->getShopId();
00022 $oOtherLang = $oObject->getAvailableInLangs();
00023 if (!isset($oOtherLang[$this->_iEditLang])) {
00024
00025 $oObject->loadInLang( key( $oOtherLang ), oxConfig::getParameter( 'oxid' ) );
00026 }
00027 $this->_aViewData['edit'] = $oObject;
00028
00029 $aLangs = oxLang::getInstance()->getLanguageNames();
00030 foreach ( $aLangs as $id => $language) {
00031 $oLang= new oxStdClass();
00032 $oLang->sLangDesc = $language;
00033 $oLang->selected = ($id == $this->_iEditLang);
00034 $this->_aViewData['otherlang'][$id] = clone $oLang;
00035 }
00036
00037
00038 $sQ = $this->_getSeoDataSql( $oObject, $iShopId, $this->_iEditLang );
00039 $aSeoData = oxDb::getDb(true)->getArray( $sQ );
00040 $aSeoData = ( is_array( $aSeoData ) && isset( $aSeoData[0] ) )?$aSeoData[0]:array();
00041
00042
00043 if ( !isset( $aSeoData['OXSEOURL'] ) || !$aSeoData['OXSEOURL'] ||
00044 ( isset( $aSeoData['OXEXPIRED'] ) && $aSeoData['OXEXPIRED'] ) ) {
00045 $aSeoData['OXSEOURL'] = $this->_getSeoUrl( $oObject );
00046 }
00047
00048
00049 $this->_aViewData['aSeoData'] = $aSeoData;
00050 }
00051
00052 return 'object_seo.tpl';
00053 }
00054
00064 protected function _getSeoDataSql( $oObject, $iShopId, $iLang )
00065 {
00066 return "select * from oxseo where oxobjectid = '".$oObject->getId()."' and
00067 oxshopid = '{$iShopId}' and oxlang = {$iLang} ";
00068 }
00069
00077 protected function _getSeoUrl( $oObject )
00078 {
00079 $iShopId = $this->getConfig()->getShopId();
00080 return oxDb::getDb()->getOne( $this->_getSeoUrlQuery( $oObject, $iShopId ) );
00081 }
00082
00090 protected function _getSeoUrlQuery( $oObject, $iShopId )
00091 {
00092 return "select oxseourl from oxseo where oxobjectid = '".$oObject->getId()."' and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang} ";
00093 }
00094
00099 protected function _getObject( $sOxid )
00100 {
00101 if ( $this->_oObject === null ) {
00102
00103 $this->_oObject = oxNew( $this->_getType() );
00104 if ( !$this->_oObject->loadInLang( $this->_iEditLang, $sOxid ) ) {
00105 $this->_oObject = false;
00106 }
00107 }
00108 return $this->_oObject;
00109 }
00110
00115 protected function _getType() {}
00116
00121 protected function _getStdUrl( $sOxid )
00122 {
00123 return $this->_getObject( $sOxid )->getLink();
00124 }
00125
00131 public function save()
00132 {
00133
00134 if ( ( $sOxid = $this->getSeoEntryId() ) ) {
00135 $aSeoData = oxConfig::getParameter( 'aSeoData' );
00136 $iShopId = $this->getConfig()->getShopId();
00137
00138
00139 if ( !isset( $aSeoData['oxfixed'] ) ) {
00140 $aSeoData['oxfixed'] = 0;
00141 }
00142
00143 $oEncoder = oxSeoEncoder::getInstance();
00144
00145
00146 $oEncoder->markAsExpired( $sOxid, $this->getconfig()->getShopId(), 1, $this->getEditLang() );
00147
00148
00149 $oEncoder->addSeoEntry( $sOxid, $iShopId, $this->getEditLang(), $this->_getStdUrl( oxConfig::getParameter( 'oxid' ) ),
00150 $aSeoData['oxseourl'], $this->_getSeoEntryType(), $aSeoData['oxfixed'],
00151 trim( $aSeoData['oxkeywords'] ), trim( $aSeoData['oxdescription'] ), $this->processParam( $aSeoData['oxparams'] ), true );
00152 }
00153 }
00154
00160 public function getEditLang()
00161 {
00162 return $this->_iEditLang;
00163 }
00164
00170 protected function getSeoEntryId()
00171 {
00172 return oxConfig::getParameter( 'oxid' );
00173 }
00174
00180 protected function _getSeoEntryType()
00181 {
00182 return $this->_getType();
00183 }
00184
00192 public function processParam( $sParam )
00193 {
00194 return $sParam;
00195 }
00196 }