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( oxDB::FETCH_MODE_ASSOC );
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( $sActObject, $oRs->fields['oxseourl'] );
00072                     $oRs->moveNext();
00073                 }
00074                 $this->_aViewData['aSeoUrls'] = $aSeoUrls;
00075             }
00076         }
00077     }
00078 
00084     public function save()
00085     {
00086         parent::save();
00087 
00088         // saving config params
00089         $this->saveConfVars();
00090 
00091         $oShop = oxNew( 'oxshop' );
00092         if ( $oShop->loadInLang( $this->_iEditLang, $this->getEditObjectId() ) ) {
00093 
00094             //assigning values
00095             $oShop->setLanguage( 0 );
00096             $oShop->assign( oxConfig::getParameter( 'editval' ) );
00097             $oShop->setLanguage( $this->_iEditLang );
00098             $oShop->save();
00099 
00100             // saving static url changes
00101             if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00102                 $this->_sActSeoObject = oxRegistry::get("oxSeoEncoder")->encodeStaticUrls( $this->_processUrls( $aStaticUrl ), $oShop->getId(), $this->_iEditLang );
00103             }
00104         }
00105     }
00106 
00114     protected function _processUrls( $aUrls )
00115     {
00116         if ( isset( $aUrls['oxseo__oxstdurl'] ) && $aUrls['oxseo__oxstdurl'] ) {
00117             $aUrls['oxseo__oxstdurl'] = $this->_cleanupUrl( $aUrls['oxseo__oxstdurl'] );
00118         }
00119 
00120         if ( isset( $aUrls['oxseo__oxseourl'] ) && is_array( $aUrls['oxseo__oxseourl'] ) ) {
00121             foreach ( $aUrls['oxseo__oxseourl'] as $iPos => $sUrl) {
00122                 $aUrls['oxseo__oxseourl'][$iPos] = $this->_cleanupUrl( $sUrl );
00123             }
00124         }
00125 
00126         return $aUrls;
00127     }
00128 
00136     protected function _cleanupUrl( $sUrl )
00137     {
00138         // replacing &amp; to & or removing double &&
00139         while ( ( stripos( $sUrl, '&amp;' ) !== false ) || ( stripos( $sUrl, '&&' ) !== false ) ) {
00140             $sUrl = str_replace( '&amp;', '&', $sUrl );
00141             $sUrl = str_replace( '&&', '&', $sUrl );
00142         }
00143 
00144         // converting & to &amp;
00145         return str_replace( '&', '&amp;', $sUrl );
00146     }
00147 
00153     public function dropSeoIds()
00154     {
00155         $this->resetSeoData( $this->getConfig()->getShopId() );
00156     }
00157 
00163     public function deleteStaticUrl()
00164     {
00165         if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00166             if ( ( $sObjectid = $aStaticUrl['oxseo__oxobjectid'] ) && $sObjectid != '-1' ) {
00167                 // active shop id
00168                 $soxId = $this->getEditObjectId();
00169                 $oDb = oxDb::getDb();
00170                 $oDb->execute( "delete from oxseo where oxtype='static' and oxobjectid = ".$oDb->quote( $sObjectid ) ." and oxshopid = ".$oDb->quote( $soxId ) );
00171             }
00172         }
00173     }
00174 }