oxseoencodertag.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxSeoEncoderTag extends oxSeoEncoder
00008 {
00012     protected static $_instance = null;
00013 
00019     protected $_oTagPrepareUtil = null;
00020 
00026     public static function getInstance()
00027     {
00028         // disable caching for test modules
00029         if ( defined( 'OXID_PHP_UNIT' ) ) {
00030             self::$_instance = modInstances::getMod( __CLASS__ );
00031         }
00032 
00033         if ( !self::$_instance instanceof oxSeoEncoderTag ) {
00034             self::$_instance = oxNew( 'oxSeoEncoderTag' );
00035             if ( defined( 'OXID_PHP_UNIT' ) ) {
00036                 modInstances::addMod( __CLASS__, self::$_instance);
00037             }
00038         }
00039 
00040         if ( defined( 'OXID_PHP_UNIT' ) ) {
00041             // resetting cache
00042             self::$_instance->_aSeoCache = array();
00043         }
00044 
00045         return self::$_instance;
00046     }
00047 
00057     public function getTagUri( $sTag, $iLang = null, $sOxid = null )
00058     {
00059         return $this->_getDynamicTagUri( $sTag, $this->getStdTagUri( $sTag ), "tag/{$sTag}/", $iLang, $sOxid );
00060     }
00061 
00073     protected function _getDynamicTagUri( $sTag, $sStdUrl, $sSeoUrl, $iLang, $sOxid = null )
00074     {
00075         $iShopId = $this->getConfig()->getShopId();
00076 
00077         $sStdUrl   = $this->_trimUrl( $sStdUrl );
00078         $sObjectId = $this->getDynamicObjectId( $iShopId, $sStdUrl );
00079         $sSeoUrl   = $this->_prepareUri( $this->addLanguageParam( $sSeoUrl, $iLang ), $iLang );
00080 
00081         //load details link from DB
00082         $sOldSeoUrl = $this->_loadFromDb( 'dynamic', $sObjectId, $iLang );
00083         if ( $sOldSeoUrl === $sSeoUrl ) {
00084             $sSeoUrl = $sOldSeoUrl;
00085         } else {
00086 
00087             if ( $sOldSeoUrl ) {
00088                 // old must be transferred to history
00089                 $this->_copyToHistory( $sObjectId, $iShopId, $iLang, 'dynamic' );
00090             }
00091 
00092             // disabling check if there are any tags used, as it should always generate seo url.
00093             /*$oTagCloud = oxNew('oxtagcloud');
00094             $oDb = oxDb::getDb();
00095             $sTag = $oTagCloud->prepareTags($sTag);
00096             $sViewName = getViewName( 'oxartextends', $iLang );
00097             $sQ = "select 1 from {$sViewName} where {$sViewName}.oxtags LIKE ".$oDb->quote( "%$sTag%" )."";
00098 
00099             if ( $sOxid ) {
00100                 $sQ .= " and oxid = " . $oDb->quote( $sOxid );
00101             }*/
00102 
00103             //if ( $oDb->getOne( $sQ ) ) {
00104                 // creating unique
00105                 $sSeoUrl = $this->_processSeoUrl( $sSeoUrl, $sObjectId, $iLang );
00106 
00107                 // inserting
00108                 $this->_saveToDb( 'dynamic', $sObjectId, $sStdUrl, $sSeoUrl, $iLang, $iShopId );
00109             /*} else {
00110                 $sSeoUrl = false;
00111             }*/
00112         }
00113 
00114         return $sSeoUrl;
00115     }
00116 
00124     protected function _prepareTag( $sTag )
00125     {
00126         if ( $this->_oTagPrepareUtil == null ) {
00127            $this->_oTagPrepareUtil = oxNew('oxtagcloud');
00128         }
00129 
00130         return $sTag = $this->_oTagPrepareUtil->prepareTags($sTag);
00131     }
00132 
00141     public function getStdTagUri( $sTag, $blIncludeIndex = true )
00142     {
00143         // while tags are just strings, standard ulrs formatted stays here
00144         $sUri = "cl=tag&amp;searchtag=" . rawurlencode( $sTag );
00145         if ( $blIncludeIndex ) {
00146             $sUri = "index.php?" . $sUri;
00147         }
00148         return $sUri;
00149     }
00150 
00159     public function getTagUrl( $sTag, $iLang = null)
00160     {
00161         if (!isset($iLang)) {
00162             $iLang = oxLang::getInstance()->getBaseLanguage();
00163         }
00164         return $this->_getFullUrl( $this->getTagUri( $sTag, $iLang ), $iLang );
00165     }
00166 
00177     public function getTagPageUrl( $sTag, $iPage, $iLang = null, $blFixed = false )
00178     {
00179         if (!isset($iLang)) {
00180             $iLang = oxLang::getInstance()->getBaseLanguage();
00181         }
00182         $sStdUrl = $this->getStdTagUri( $sTag ) . '&amp;pgNr=' . $iPage;
00183         $sParams = (int) ($iPage + 1);
00184 
00185         $sStdUrl = $this->_trimUrl( $sStdUrl, $iLang );
00186         $sSeoUrl = $this->getTagUri( $sTag, $iLang ) . $sParams . "/";
00187 
00188         return $this->_getFullUrl( $this->_getDynamicTagUri( $sTag, $sStdUrl, $sSeoUrl, $iLang ), $iLang );
00189     }
00190 }