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

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5