oxseoencodercategory.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxSeoEncoderCategory extends oxSeoEncoder
00009 {
00013     protected static $_instance = null;
00014 
00021     protected $_aCatCache = array();
00022 
00028     public static function getInstance()
00029     {
00030         if (!self::$_instance) {
00031             self::$_instance = oxNew("oxSeoEncoderCategory");
00032         }
00033         return self::$_instance;
00034     }
00035 
00047     protected function _categoryUrlLoader( $oCat, $iLang )
00048     {
00049         $sSeoUrl = false;
00050 
00051         $sCacheId = $this->_getCategoryCacheId( $oCat, $iLang );
00052         if ( isset( $this->_aCatCache[$sCacheId] ) ) {
00053             $sSeoUrl = $this->_aCatCache[ $sCacheId ];
00054         } elseif ( ( $sSeoUrl = $this->_loadFromDb( 'oxcategory', $oCat->getId(), $iLang ) ) ) {
00055             // caching
00056             $this->_aCatCache[ $sCacheId ] = $sSeoUrl;
00057         }
00058 
00059         return $sSeoUrl;
00060     }
00061 
00072     private function _getCategoryCacheId( $oCat, $iLang )
00073     {
00074         return $oCat->getId() . '_' . ( (int) $iLang );
00075     }
00076 
00085     public function getCategoryUri( $oCat, $iLang = null )
00086     {
00087         startProfile(__FUNCTION__);
00088         $sCatId = $oCat->getId();
00089 
00090         // skipping external category URLs
00091         if ( $oCat->oxcategories__oxextlink->value ) {
00092             $sSeoUrl = null;
00093         } else {
00094             // not found in cache, process it from the top
00095             if (!isset($iLang)) {
00096                 $iLang = $oCat->getLanguage();
00097             }
00098 
00099             $aCacheMap = array();
00100             $aStdLinks = array();
00101 
00102             while ( $oCat && !($sSeoUrl = $this->_categoryUrlLoader( $oCat, $iLang ) )) {
00103 
00104                 if ($iLang != $oCat->getLanguage()) {
00105                     $sId = $oCat->getId();
00106                     $oCat = oxNew('oxcategory');
00107                     $oCat->loadInLang($iLang, $sId);
00108                 }
00109 
00110                 // prepare oCat title part
00111                 $sTitle = $this->_prepareTitle( $oCat->oxcategories__oxtitle->value );
00112 
00113                 foreach ( array_keys( $aCacheMap ) as $id ) {
00114                     $aCacheMap[$id] = $sTitle . '/' . $aCacheMap[$id];
00115                 }
00116 
00117                 $aCacheMap[$oCat->getId()] = $sTitle;
00118                 $aStdLinks[$oCat->getId()] = $oCat->getStdLink();
00119 
00120                 // load parent
00121                 $oCat = $oCat->getParentCategory();
00122             }
00123 
00124             foreach ( $aCacheMap as $sId => $sUri ) {
00125                 $this->_aCatCache[$sId.'_'.$iLang] = $this->_getUniqueSeoUrl( $sSeoUrl.$sUri.'/', '/', $sId );
00126                 $this->_saveToDb( 'oxcategory', $sId, $aStdLinks[$sId], $this->_aCatCache[$sId.'_'.$iLang], $iLang );
00127             }
00128 
00129             $sSeoUrl = $this->_aCatCache[$sCatId.'_'.$iLang];
00130         }
00131 
00132         stopProfile(__FUNCTION__);
00133 
00134         return $sSeoUrl;
00135     }
00136 
00137 
00148     public function getCategoryPageUrl( $oCategory, $iPage, $iLang = null, $blFixed = false )
00149     {
00150         if (!isset($iLang)) {
00151             $iLang = $oCategory->getLanguage();
00152         }
00153         $sStdUrl = $oCategory->getStdLink() . '&amp;pgNr=' . $iPage;
00154         $sParams = sprintf( "%0" . ceil( $this->_iCntPages / 10 + 1 ) . "d", $iPage + 1 );
00155 
00156         $sStdUrl = $this->_trimUrl( $sStdUrl, $iLang );
00157         $sSeoUrl = $this->getCategoryUri( $oCategory, $iLang ) . $sParams . "/";
00158 
00159         return $this->_getFullUrl( $this->_getPageUri( $oCategory, 'oxcategory', $sStdUrl, $sSeoUrl, $sParams, $iLang, $blFixed ), $iLang );
00160     }
00161 
00173     public function getCategoryUrl( $oCategory, $iLang = null )
00174     {
00175         if (!isset($iLang)) {
00176             $iLang = $oCategory->getLanguage();
00177         }
00178         // category may have specified url
00179         if ( ( $sSeoUrl = $this->getCategoryUri( $oCategory, $iLang ) ) ) {
00180             return $this->_getFullUrl( $sSeoUrl, $iLang );
00181         }
00182         return '';
00183     }
00184 
00192     public function markRelatedAsExpired( $oCategory )
00193     {
00194         $oDb = oxDb::getDb();
00195         // select it from table instead of using object carrying value
00196         // this is because this method is usually called inside update,
00197         // where object may already be carrying changed id
00198         $aCatInfo = $oDb->getAll("select oxrootid, oxleft, oxright from oxcategories where oxid = '".$oCategory->getId()."' limit 1");
00199         $sCatRootId = $aCatInfo[0][0];
00200         // update article for root of this cat
00201         $sQ = "update oxseo as seo1, (select oxobjectid from oxseo where oxtype = 'oxarticle' and oxparams = '{$sCatRootId}') as seo2 set seo1.oxexpired = '1' where seo1.oxtype = 'oxarticle' and seo1.oxobjectid = seo2.oxobjectid";
00202         $oDb->execute( $sQ );
00203 
00204         // update sub cats
00205         $sQ = "update oxseo as seo1, (select oxid from oxcategories where oxrootid='$sCatRootId' and oxleft > {$aCatInfo[0][1]} and oxright < {$aCatInfo[0][2]}) as seo2 set seo1.oxexpired = '1' where seo1.oxtype = 'oxcategory' and seo1.oxobjectid = seo2.oxid";
00206         $oDb->execute( $sQ );
00207     }
00208 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5