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         $sUrl = preg_replace('/(force_)?(admin_)?sid=[a-z0-9\._]*&?(amp;)?/i', '', $sUrl);
00089 
00090         $oStr = getStr();
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 (!preg_match('/[&?](amp;)?lang=[0-9]+/i', $sUrl)) {
00102             $sUrl .= "{$sSep}lang=".oxLang::getInstance()->getBaseLanguage();
00103             $sSep = '&amp;';
00104         }
00105 
00106         if (!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         $sSep = '&amp;';
00128         if ( getStr()->strpos( $sUrl, '?' ) === false ) {
00129             $sSep = '?';
00130         }
00131 
00132         if ( count( $aAddParams ) ) {
00133 
00134             foreach ( $aAddParams as $sName => $sValue ) {
00135                 if ( $sValue && !preg_match("/\?(.*&(amp;)?)?$sName=/", $sUrl)) {
00136                     $sUrl .= $sSep . $sName . "=" . $sValue;
00137                     $sSep = '&amp;';
00138                 }
00139             }
00140         }
00141         if ($sUrl) {
00142             return $sUrl.$sSep;
00143         }
00144         return '';
00145     }
00146 
00157     public function processUrl( $sUrl, $blFinalUrl = true, $aParams = null, $iLang = null )
00158     {
00159         $aAddParams = $this->getAddUrlParams();
00160         if ( is_array($aParams) && count( $aParams ) ) {
00161             $aAddParams = array_merge( $aAddParams, $aParams );
00162         }
00163 
00164         $ret = oxSession::getInstance()->processUrl(
00165                     oxLang::getInstance()->processUrl(
00166                         $this->_appendUrl( 
00167                                 $sUrl, 
00168                                 $aAddParams
00169                         ),
00170                         $iLang
00171                     )
00172                 );
00173 
00174         if ($blFinalUrl) {
00175             $ret = preg_replace('/(\?|&(amp;)?)$/', '', $ret);
00176         }
00177         return $ret;
00178     }
00179 
00187     public function processSeoUrl( $sUrl )
00188     {
00189         $ret = $this->getSession()->processUrl( $this->_appendUrl( $sUrl, $this->getAddUrlParams() ) );
00190         $ret = preg_replace('/(\?|&(amp;)?)$/', '', $ret);
00191         return $ret;
00192     }
00193 
00208     public function processStdUrl( $sUrl, $aParams, $iLang, $blAddLangParam )
00209     {
00210         return $this->processUrl($sUrl, true, $aParams, $iLang);
00211     }
00212 
00220     public function appendParamSeparator($sUrl)
00221     {
00222         if (preg_match('/(\?|&(amp;)?)$/i', $sUrl)) {
00223             // it is already ok
00224             return $sUrl;
00225         }
00226         if (strpos($sUrl, '?') === false) {
00227             return $sUrl.'?';
00228         }
00229         return $sUrl.'&amp;';
00230     }
00231 }

Generated by  doxygen 1.6.2