oxutilsurl.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsUrl extends oxSuperCfg
00007 {
00013     private static $_instance = null;
00014 
00020     protected $_aAddUrlParams = null;
00021 
00027     public static function getInstance()
00028     {
00029         // disable caching for test modules
00030         if ( defined( 'OXID_PHP_UNIT' ) ) {
00031             self::$_instance = modInstances::getMod( __CLASS__ );
00032         }
00033 
00034         if ( !(self::$_instance instanceof oxUtilsUrl ) ) {
00035             self::$_instance = oxNew( 'oxUtilsUrl' );
00036             if ( defined( 'OXID_PHP_UNIT' ) ) {
00037                 modInstances::addMod( __CLASS__, self::$_instance);
00038             }
00039         }
00040         return self::$_instance;
00041     }
00042 
00048     public function getBaseAddUrlParams()
00049     {
00050         $aAddUrlParams = array();
00051 
00052         return $aAddUrlParams;
00053     }
00054 
00060     public function getAddUrlParams()
00061     {
00062         if ( $this->_aAddUrlParams === null ) {
00063             $this->_aAddUrlParams = $this->getBaseAddUrlParams();
00064 
00065             // appending currency
00066             if ( ( $iCur = oxConfig::getParameter( 'currency' ) ) ) {
00067                 $this->_aAddUrlParams['cur'] = $iCur;
00068             }
00069         }
00070         return $this->_aAddUrlParams;
00071     }
00072 
00082     public function prepareUrlForNoSession( $sUrl )
00083     {
00084         if ( oxUtils::getInstance()->seoIsActive() ) {
00085             return $sUrl;
00086         }
00087 
00088         $oStr = getStr();
00089         $sUrl = $oStr->preg_replace('/(force_)?(admin_)?sid=[a-z0-9\._]*&?(amp;)?/i', '', $sUrl);
00090 
00091         if ($qpos = $oStr->strpos($sUrl, '?')) {
00092             if ($qpos == $oStr->strlen($sUrl)-1) {
00093                 $sSep = '';
00094             } else {
00095                 $sSep = '&amp;';
00096             }
00097         } else {
00098             $sSep = '?';
00099         }
00100 
00101         if ( !$oStr->preg_match('/[&?](amp;)?lang=[0-9]+/i', $sUrl)) {
00102             $sUrl .= "{$sSep}lang=".oxLang::getInstance()->getBaseLanguage();
00103             $sSep = '&amp;';
00104         }
00105 
00106         if ( !$oStr->preg_match('/[&?](amp;)?cur=[0-9]+/i', $sUrl)) {
00107             $iCur = (int) oxConfig::getParameter('currency');
00108             if ( $iCur ) {
00109                 $sUrl .= "{$sSep}cur=".$iCur;
00110                 $sSep = '&amp;';
00111             }
00112         }
00113 
00114         return $sUrl;
00115     }
00116 
00125     protected function _appendUrl( $sUrl, $aAddParams )
00126     {
00127         $oStr = getStr();
00128         $sSep = '&amp;';
00129         if ( $oStr->strpos( $sUrl, '?' ) === false ) {
00130             $sSep = '?';
00131         }
00132 
00133         if ( count( $aAddParams ) ) {
00134             foreach ( $aAddParams as $sName => $sValue ) {
00135                 if ( isset( $sValue ) && !$oStr->preg_match("/\?(.*&(amp;)?)?".preg_quote( $sName )."=/", $sUrl ) ) {
00136                     $sUrl .= $sSep . $sName . "=" . $sValue;
00137                     $sSep = '&amp;';
00138                 }
00139             }
00140         }
00141         return $sUrl ? $sUrl.$sSep : '';
00142     }
00143 
00152     public function cleanUrl( $sUrl, $aParams = null )
00153     {
00154         $oStr = getStr();
00155         if ( is_array( $aParams ) ) {
00156             foreach ( $aParams as $sParam ) {
00157                 $sUrl = $oStr->preg_replace( '/(\?|&(amp;)?)'.preg_quote( $sParam ).'=[a-z0-9\.]+&?(amp;)?/i', '\1', $sUrl );
00158             }
00159         } else {
00160             $sUrl = $oStr->preg_replace( '/(\?|&(amp;)?).+/i', '\1', $sUrl );
00161         }
00162 
00163         return trim( $sUrl, "?" );
00164     }
00165 
00176     public function processUrl( $sUrl, $blFinalUrl = true, $aParams = null, $iLang = null )
00177     {
00178         $aAddParams = $this->getAddUrlParams();
00179         if ( is_array($aParams) && count( $aParams ) ) {
00180             $aAddParams = array_merge( $aAddParams, $aParams );
00181         }
00182 
00183         $ret = oxSession::getInstance()->processUrl(
00184                     oxLang::getInstance()->processUrl(
00185                         $this->_appendUrl(
00186                                 $sUrl,
00187                                 $aAddParams
00188                         ),
00189                         $iLang
00190                     )
00191                 );
00192 
00193         if ($blFinalUrl) {
00194             $ret = getStr()->preg_replace('/(\?|&(amp;)?)$/', '', $ret);
00195         }
00196         return $ret;
00197     }
00198 
00206     public function processSeoUrl( $sUrl )
00207     {
00208         $ret = $this->getSession()->processUrl( $this->_appendUrl( $sUrl, $this->getAddUrlParams() ) );
00209         $ret = getStr()->preg_replace('/(\?|&(amp;)?)$/', '', $ret);
00210         return $ret;
00211     }
00212 
00227     public function processStdUrl( $sUrl, $aParams, $iLang, $blAddLangParam )
00228     {
00229         return $this->processUrl($sUrl, true, $aParams, $iLang);
00230     }
00231 
00239     public function appendParamSeparator($sUrl)
00240     {
00241         $oStr = getStr();
00242         if ( $oStr->preg_match('/(\?|&(amp;)?)$/i', $sUrl ) ) {
00243             // it is already ok
00244             return $sUrl;
00245         }
00246         if ( $oStr->strpos($sUrl, '?') === false ) {
00247             return $sUrl.'?';
00248         }
00249         return $sUrl.'&amp;';
00250     }
00251 }

Generated by  doxygen 1.6.2