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             oxUtils::getInstance()->rebuildCache();
00101 
00102             // saving static url changes
00103             if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00104                 $this->_sActSeoObject = oxSeoEncoder::getInstance()->encodeStaticUrls( $this->_processUrls( $aStaticUrl ), $oShop->getId(), $this->_iEditLang );
00105             }
00106         }
00107     }
00108 
00116     protected function _processUrls( $aUrls )
00117     {
00118         if ( isset( $aUrls['oxseo__oxstdurl'] ) && $aUrls['oxseo__oxstdurl'] ) {
00119             $aUrls['oxseo__oxstdurl'] = $this->_cleanupUrl( $aUrls['oxseo__oxstdurl'] );
00120         }
00121 
00122         if ( isset( $aUrls['oxseo__oxseourl'] ) && is_array( $aUrls['oxseo__oxseourl'] ) ) {
00123             foreach ( $aUrls['oxseo__oxseourl'] as $iPos => $sUrl) {
00124                 $aUrls['oxseo__oxseourl'][$iPos] = $this->_cleanupUrl( $sUrl );
00125             }
00126         }
00127 
00128         return $aUrls;
00129     }
00130 
00138     protected function _cleanupUrl( $sUrl )
00139     {
00140         // replacing &amp; to & or removing double &&
00141         while ( ( stripos( $sUrl, '&amp;' ) !== false ) || ( stripos( $sUrl, '&&' ) !== false ) ) {
00142             $sUrl = str_replace( '&amp;', '&', $sUrl );
00143             $sUrl = str_replace( '&&', '&', $sUrl );
00144         }
00145 
00146         // converting & to &amp;
00147         return str_replace( '&', '&amp;', $sUrl );
00148     }
00149 
00155     public function dropSeoIds()
00156     {
00157         $this->resetSeoData( $this->getConfig()->getShopId() );
00158     }
00159 
00165     public function deleteStaticUrl()
00166     {
00167         if ( is_array( $aStaticUrl = oxConfig::getParameter( 'aStaticUrl' ) ) ) {
00168             if ( ( $sObjectid = $aStaticUrl['oxseo__oxobjectid'] ) && $sObjectid != '-1' ) {
00169                 // active shop id
00170                 $soxId = $this->getEditObjectId();
00171                 $oDb = oxDb::getDb();
00172                 $oDb->execute( "delete from oxseo where oxtype='static' and oxobjectid = ".$oDb->quote( $sObjectid ) ." and oxshopid = ".$oDb->quote( $soxId ) );
00173             }
00174         }
00175     }
00176 }