shop_seo.php

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         // loading shop
00028         $oShop = oxNew( 'oxshop' );
00029         $oShop->loadInLang( $this->_iEditLang, $this->_aViewData['edit']->getId() );
00030         $this->_aViewData['edit'] = $oShop;
00031 
00032         // loading static seo urls
00033         $sQ = "select oxstdurl, oxobjectid from oxseo where oxtype='static' and oxshopid='".$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         // loading active url info
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             $sQ = "select oxseourl, oxlang from oxseo where oxobjectid = '$sActObject' and oxshopid = '{$iShopId}'";
00067             $oRs = oxDb::getDb(true)->execute( $sQ );
00068             if ( $oRs != false && $oRs->recordCount() > 0 ) {
00069                 while ( !$oRs->EOF ) {
00070                     $aSeoUrls[$oRs->fields['oxlang']] = array( $oRs->fields['oxobjectid'], $oRs->fields['oxseourl'] );
00071                     $oRs->moveNext();
00072                 }
00073                 $this->_aViewData['aSeoUrls'] = $aSeoUrls;
00074             }
00075         }
00076     }
00077 
00083     public function save()
00084     {
00085 
00086         // saving config params
00087         $this->saveConfVars();
00088 
00089         $soxId = oxConfig::getParameter( 'oxid' );
00090         $aParams = oxConfig::getParameter( 'editval' );
00091         $aConfParams = oxConfig::getParameter( 'confstrs' );
00092 
00093         $oEncoder = oxSeoEncoder::getInstance();
00094 
00095         $oShop = oxNew( 'oxshop' );
00096         $oShop->load( $soxId );
00097 
00098         //assigning values
00099         $oShop->assign( $aParams );
00100         $oShop->setLanguage( $this->_iEditLang );
00101         $oShop->save();
00102 
00103         oxUtils::getInstance()->rebuildCache();
00104 
00105         // saving static url changes
00106         if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00107             $this->_sActSeoObject = $oEncoder->encodeStaticUrls( $this->_processUrls( $aStaticUrl ), $oShop->getId(), $this->_iEditLang );
00108         }
00109     }
00110 
00118     protected function _processUrls( $aUrls )
00119     {
00120         if ( isset( $aUrls['oxseo__oxstdurl'] ) && $aUrls['oxseo__oxstdurl'] ) {
00121             $aUrls['oxseo__oxstdurl'] = $this->_cleanupUrl( $aUrls['oxseo__oxstdurl'] );
00122         }
00123 
00124         if ( isset( $aUrls['oxseo__oxseourl'] ) && is_array( $aUrls['oxseo__oxseourl'] ) ) {
00125             foreach ( $aUrls['oxseo__oxseourl'] as $iPos => $sUrl) {
00126                 $aUrls['oxseo__oxseourl'][$iPos] = $this->_cleanupUrl( $sUrl );
00127             }
00128         }
00129 
00130         return $aUrls;
00131     }
00132 
00140     protected function _cleanupUrl( $sUrl )
00141     {
00142         // replacing &amp; to & or removing double &&
00143         while ( ( stripos( $sUrl, '&amp;' ) !== false ) || ( stripos( $sUrl, '&&' ) !== false ) ) {
00144             $sUrl = str_replace( '&amp;', '&', $sUrl );
00145             $sUrl = str_replace( '&&', '&', $sUrl );
00146         }
00147 
00148         // converting & to &amp;
00149         return str_replace( '&', '&amp;', $sUrl );
00150     }
00151 
00157     public function dropSeoIds()
00158     {
00159         $sQ = 'delete from oxseo where oxshopid = "'.$this->getConfig()->getShopId().'" and oxtype != "static" and oxfixed != 1';
00160         oxDB::getDb()->execute( $sQ );
00161     }
00162 
00168     public function deleteStaticUrl()
00169     {
00170         if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00171             if ( ( $sObjectid = $aStaticUrl['oxseo__oxobjectid'] ) && $sObjectid != '-1' ) {
00172                 // active shop id
00173                 $soxId = oxConfig::getParameter( 'oxid' );
00174                 oxDb::getDb()->execute( "delete from oxseo where oxobjectid = '{$sObjectid}' and oxshopid = '{$soxId}'" );
00175             }
00176         }
00177     }
00178 }

Generated on Tue Apr 21 15:45:44 2009 for OXID eShop CE by  doxygen 1.5.5