object_seo.php

Go to the documentation of this file.
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                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
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             // loading SEO part
00038             $this->_getSeoUrl( $oObject );
00039             $sQ = $this->_getSeoDataSql( $oObject, $iShopId, $this->_iEditLang );
00040             $aSeoData = oxDb::getDb(true)->getArray( $sQ );
00041             $aSeoData = ( is_array( $aSeoData ) && isset( $aSeoData[0] ) )?$aSeoData[0]:array();
00042 
00043             // passing to view
00044             $this->_aViewData['aSeoData'] = $aSeoData;
00045         }
00046 
00047         return 'object_seo.tpl';
00048     }
00049 
00059     protected function _getSeoDataSql( $oObject, $iShopId, $iLang )
00060     {
00061         return "select * from oxseo
00062                left join oxobject2seodata on
00063                    oxobject2seodata.oxobjectid = oxseo.oxobjectid and
00064                    oxobject2seodata.oxshopid = oxseo.oxshopid and
00065                    oxobject2seodata.oxlang = oxseo.oxlang
00066                where
00067                    oxseo.oxobjectid = ".oxDb::getDb()->quote( $oObject->getId() )." and
00068                    oxseo.oxshopid = '{$iShopId}' and oxseo.oxlang = {$iLang} ";
00069     }
00070 
00078     protected function _getSeoUrl( $oObject )
00079     {
00080         return oxDb::getDb()->getOne( $this->_getSeoUrlQuery( $oObject, $this->getConfig()->getShopId() ) );
00081     }
00082 
00091      protected function _getSeoUrlQuery( $oObject, $iShopId )
00092      {
00093         return "select oxseourl from oxseo where oxobjectid = '".$oObject->getId()."' and oxshopid = '{$iShopId}' and oxlang = {$this->_iEditLang} ";
00094      }
00095 
00103     protected function _getObject( $sOxid )
00104     {
00105         if ( $this->_oObject === null && ( $sType = $this->_getType() ) ) {
00106             $this->_oObject = false;
00107 
00108             // load object
00109             $oObject = oxNew( $sType );
00110             if ( $oObject->loadInLang( $this->_iEditLang, $sOxid ) ) {
00111                 $this->_oObject = $oObject;
00112             }
00113         }
00114         return $this->_oObject;
00115     }
00116 
00122     protected function _getType()
00123     {
00124     }
00125 
00133     protected function _getStdUrl( $sOxid )
00134     {
00135         return $this->_getObject( $sOxid )->getBaseStdLink( $this->_iEditLang, true, false );
00136     }
00137 
00143     public function save()
00144     {
00145         // saving/updating seo params
00146         if ( ( $sOxid = $this->_getSeoEntryId() ) ) {
00147             $aSeoData = oxConfig::getParameter( 'aSeoData' );
00148             $iShopId  = $this->getConfig()->getShopId();
00149 
00150             // checkbox handling
00151             if ( !isset( $aSeoData['oxfixed'] ) ) {
00152                 $aSeoData['oxfixed'] = 0;
00153             }
00154 
00155             $oEncoder = $this->_getEncoder();
00156 
00157             // marking self and page links as expired
00158             $oEncoder->markAsExpired( $sOxid, $iShopId, 1, $this->getEditLang() );
00159 
00160             // saving
00161             $oEncoder->addSeoEntry( $sOxid, $iShopId, $this->getEditLang(), $this->_getStdUrl( $sOxid ),
00162                                     $aSeoData['oxseourl'], $this->_getSeoEntryType(), $aSeoData['oxfixed'],
00163                                     trim( $aSeoData['oxkeywords'] ), trim( $aSeoData['oxdescription'] ), $this->processParam( $aSeoData['oxparams'] ), true, $this->_getAltSeoEntryId() );
00164         }
00165     }
00166 
00172     public function getEditLang()
00173     {
00174         return $this->_iEditLang;
00175     }
00176 
00184     protected function getSeoEntryId()
00185     {
00186         return $this->_getSeoEntryId();
00187     }
00188 
00194     protected function _getAltSeoEntryId()
00195     {
00196     }
00197 
00203     protected function _getSeoEntryId()
00204     {
00205         return oxConfig::getParameter( 'oxid' );
00206     }
00207 
00213     protected function _getSeoEntryType()
00214     {
00215         return $this->_getType();
00216     }
00217 
00225     public function processParam( $sParam )
00226     {
00227         return $sParam;
00228     }
00229 
00235     protected function _getEncoder()
00236     {
00237         return oxSeoEncoder::getInstance();
00238     }
00239 }