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 
00028     public static function getInstance()
00029     {
00030         return oxRegistry::get("oxSeoEncoderTag");
00031     }
00032 
00042     public function getTagUri( $sTag, $iLang = null, $sOxid = null )
00043     {
00044         return $this->_getDynamicTagUri( $sTag, $this->getStdTagUri( $sTag ), "tag/{$sTag}/", $iLang, $sOxid );
00045     }
00046 
00058     protected function _getDynamicTagUri( $sTag, $sStdUrl, $sSeoUrl, $iLang, $sOxid = null )
00059     {
00060         $iShopId = $this->getConfig()->getShopId();
00061 
00062         $sStdUrl   = $this->_trimUrl( $sStdUrl );
00063         $sObjectId = $this->getDynamicObjectId( $iShopId, $sStdUrl );
00064         $sSeoUrl   = $this->_prepareUri( $this->addLanguageParam( $sSeoUrl, $iLang ), $iLang );
00065 
00066         //load details link from DB
00067         $sOldSeoUrl = $this->_loadFromDb( 'dynamic', $sObjectId, $iLang );
00068         if ( $sOldSeoUrl === $sSeoUrl ) {
00069             $sSeoUrl = $sOldSeoUrl;
00070         } else {
00071             if ( $sOldSeoUrl ) {
00072                 // old must be transferred to history
00073                 $this->_copyToHistory( $sObjectId, $iShopId, $iLang, 'dynamic' );
00074             }
00075             // creating unique
00076             $sSeoUrl = $this->_processSeoUrl( $sSeoUrl, $sObjectId, $iLang );
00077 
00078             // inserting
00079             $this->_saveToDb( 'dynamic', $sObjectId, $sStdUrl, $sSeoUrl, $iLang, $iShopId );
00080         }
00081 
00082         return $sSeoUrl;
00083     }
00084 
00092     protected function _prepareTag( $sTag )
00093     {
00094         if ( $this->_oTagPrepareUtil == null ) {
00095            $this->_oTagPrepareUtil = oxNew('oxtagcloud');
00096         }
00097 
00098         return $sTag = $this->_oTagPrepareUtil->prepareTags($sTag);
00099     }
00100 
00109     public function getStdTagUri( $sTag, $blIncludeIndex = true )
00110     {
00111         // while tags are just strings, standard ulrs formatted stays here
00112         $sUri = "cl=tag&amp;searchtag=" . rawurlencode( $sTag );
00113         if ( $blIncludeIndex ) {
00114             $sUri = "index.php?" . $sUri;
00115         }
00116         return $sUri;
00117     }
00118 
00127     public function getTagUrl( $sTag, $iLang = null)
00128     {
00129         if (!isset($iLang)) {
00130             $iLang = oxRegistry::getLang()->getBaseLanguage();
00131         }
00132         return $this->_getFullUrl( $this->getTagUri( $sTag, $iLang ), $iLang );
00133     }
00134 
00145     public function getTagPageUrl( $sTag, $iPage, $iLang = null, $blFixed = false )
00146     {
00147         if (!isset($iLang)) {
00148             $iLang = oxRegistry::getLang()->getBaseLanguage();
00149         }
00150         $sStdUrl = $this->getStdTagUri( $sTag ) . '&amp;pgNr=' . $iPage;
00151         $sParams = (int) ($iPage + 1);
00152 
00153         $sStdUrl = $this->_trimUrl( $sStdUrl, $iLang );
00154         $sSeoUrl = $this->getTagUri( $sTag, $iLang ) . $sParams . "/";
00155 
00156         return $this->_getFullUrl( $this->_getDynamicTagUri( $sTag, $sStdUrl, $sSeoUrl, $iLang ), $iLang );
00157     }
00158 }