shop_seo.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Shop_Seo extends Shop_Config
00009 {
00010 
00014     protected $_sActSeoObject = null;
00015 
00022     public function render()
00023     {
00024         parent::render();
00025 
00026         $this->_aViewData['subjlang'] = $this->_iEditLang;
00027 
00028         // loading shop
00029         $oShop = oxNew('oxshop');
00030         $oShop->loadInLang($this->_iEditLang, $this->_aViewData['edit']->getId());
00031         $this->_aViewData['edit'] = $oShop;
00032 
00033         // loading static seo urls
00034         $sQ = "select oxstdurl, oxobjectid from oxseo where oxtype='static' and oxshopid=" . oxDb::getDb()->quote($oShop->getId()) . " group by oxobjectid order by oxstdurl";
00035 
00036         $oList = oxNew('oxlist');
00037         $oList->init('oxbase', 'oxseo');
00038         $oList->selectString($sQ);
00039 
00040         $this->_aViewData['aStaticUrls'] = $oList;
00041 
00042         // loading active url info
00043         $this->_loadActiveUrl($oShop->getId());
00044 
00045         return "shop_seo.tpl";
00046     }
00047 
00053     protected function _loadActiveUrl($iShopId)
00054     {
00055         $sActObject = null;
00056         if ($this->_sActSeoObject) {
00057             $sActObject = $this->_sActSeoObject;
00058         } elseif (is_array($aStatUrl = oxRegistry::getConfig()->getRequestParameter('aStaticUrl'))) {
00059             $sActObject = $aStatUrl['oxseo__oxobjectid'];
00060         }
00061 
00062         if ($sActObject && $sActObject != '-1') {
00063             $this->_aViewData['sActSeoObject'] = $sActObject;
00064 
00065             $oDb = oxDb::getDb(oxDB::FETCH_MODE_ASSOC);
00066             $sQ = "select oxseourl, oxlang from oxseo where oxobjectid = " . $oDb->quote($sActObject) . " and oxshopid = " . $oDb->quote($iShopId);
00067             $oRs = $oDb->execute($sQ);
00068             if ($oRs != false && $oRs->recordCount() > 0) {
00069                 while (!$oRs->EOF) {
00070                     $aSeoUrls[$oRs->fields['oxlang']] = array($sActObject, $oRs->fields['oxseourl']);
00071                     $oRs->moveNext();
00072                 }
00073                 $this->_aViewData['aSeoUrls'] = $aSeoUrls;
00074             }
00075         }
00076     }
00077 
00081     public function save()
00082     {
00083         parent::save();
00084 
00085         // saving config params
00086         $this->saveConfVars();
00087 
00088         $oShop = oxNew('oxshop');
00089         if ($oShop->loadInLang($this->_iEditLang, $this->getEditObjectId())) {
00090 
00091             //assigning values
00092             $oShop->setLanguage(0);
00093             $oShop->assign(oxRegistry::getConfig()->getRequestParameter('editval'));
00094             $oShop->setLanguage($this->_iEditLang);
00095             $oShop->save();
00096 
00097             // saving static url changes
00098             if (is_array($aStaticUrl = oxRegistry::getConfig()->getRequestParameter('aStaticUrl'))) {
00099                 $this->_sActSeoObject = oxRegistry::get("oxSeoEncoder")->encodeStaticUrls($this->_processUrls($aStaticUrl), $oShop->getId(), $this->_iEditLang);
00100             }
00101         }
00102     }
00103 
00111     protected function _processUrls($aUrls)
00112     {
00113         if (isset($aUrls['oxseo__oxstdurl']) && $aUrls['oxseo__oxstdurl']) {
00114             $aUrls['oxseo__oxstdurl'] = $this->_cleanupUrl($aUrls['oxseo__oxstdurl']);
00115         }
00116 
00117         if (isset($aUrls['oxseo__oxseourl']) && is_array($aUrls['oxseo__oxseourl'])) {
00118             foreach ($aUrls['oxseo__oxseourl'] as $iPos => $sUrl) {
00119                 $aUrls['oxseo__oxseourl'][$iPos] = $this->_cleanupUrl($sUrl);
00120             }
00121         }
00122 
00123         return $aUrls;
00124     }
00125 
00133     protected function _cleanupUrl($sUrl)
00134     {
00135         // replacing &amp; to & or removing double &&
00136         while ((stripos($sUrl, '&amp;') !== false) || (stripos($sUrl, '&&') !== false)) {
00137             $sUrl = str_replace('&amp;', '&', $sUrl);
00138             $sUrl = str_replace('&&', '&', $sUrl);
00139         }
00140 
00141         // converting & to &amp;
00142         return str_replace('&', '&amp;', $sUrl);
00143     }
00144 
00148     public function dropSeoIds()
00149     {
00150         $this->resetSeoData($this->getConfig()->getShopId());
00151     }
00152 
00156     public function deleteStaticUrl()
00157     {
00158         if (is_array($aStaticUrl = oxRegistry::getConfig()->getRequestParameter('aStaticUrl'))) {
00159             if (($sObjectid = $aStaticUrl['oxseo__oxobjectid']) && $sObjectid != '-1') {
00160                 // active shop id
00161                 $soxId = $this->getEditObjectId();
00162                 $oDb = oxDb::getDb();
00163                 $oDb->execute("delete from oxseo where oxtype='static' and oxobjectid = " . $oDb->quote($sObjectid) . " and oxshopid = " . $oDb->quote($soxId));
00164             }
00165         }
00166     }
00167 }