00001 <?php
00002
00006 require_once getShopBasePath()."core/smarty/Smarty.class.php";
00007
00012 class oxUtils extends oxSuperCfg
00013 {
00019 private static $_instance = null;
00020
00026 protected $_iCurPrecision = null;
00027
00033 protected $_sEmailTpl = "/^([-!#\$%&'*+.\/0-9=?A-Z^_`a-z{|}~\177])+@([-!#\$%&'*+\/0-9=?A-Z^_`a-z{|}~\177]+\\.)+[a-zA-Z]{2,6}\$/i";
00034
00042 protected $_sPermanentCachePattern = "/c_fieldnames_/";
00043
00049 protected $_aFileCacheContents = array();
00050
00056 public static function getInstance()
00057 {
00058
00059 if ( defined( 'OXID_PHP_UNIT' ) ) {
00060 static $inst = array();
00061 self::$_instance = $inst[oxClassCacheKey()];
00062
00063 }
00064
00065 if ( !self::$_instance instanceof oxUtils ) {
00066
00067
00068 self::$_instance = oxNew( 'oxUtils' );
00069
00070 if ( defined( 'OXID_PHP_UNIT' ) ) {
00071 $inst[oxClassCacheKey()] = self::$_instance;
00072 }
00073 }
00074 return self::$_instance;
00075 }
00076
00082 protected $_aStaticCache;
00083
00089 protected $_blSeoIsActive = null;
00090
00096 public function stripGpcMagicQuotes()
00097 {
00098 if (!get_magic_quotes_gpc()) {
00099 return;
00100 }
00101 $_REQUEST = self::_stripQuotes($_REQUEST);
00102 $_POST = self::_stripQuotes($_POST);
00103 $_GET = self::_stripQuotes($_GET);
00104 $_COOKIE = self::_stripQuotes($_COOKIE);
00105 }
00106
00115 public function strMan( $sVal, $sKey = null )
00116 {
00117 $sKey = $sKey?$sKey:'oxid123456789';
00118 $sVal = "ox{$sVal}id";
00119
00120 $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00121 $sVal = $this->strRot13( $sVal );
00122 $sVal = $sVal ^ $sKey;
00123 $sVal = base64_encode( $sVal );
00124 $sVal = str_replace( "=", "!", $sVal );
00125
00126 return "ox_$sVal";
00127 }
00128
00137 public function strRem( $sVal, $sKey = null )
00138 {
00139 $sKey = $sKey?$sKey:'oxid123456789';
00140 $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00141
00142 $sVal = substr( $sVal, 3 );
00143 $sVal = str_replace( '!', '=', $sVal );
00144 $sVal = base64_decode( $sVal );
00145 $sVal = $sVal ^ $sKey;
00146 $sVal = $this->strRot13( $sVal );
00147
00148 return substr( $sVal, 2, -2 );
00149 }
00150
00158 public function getArrFldName( $sName)
00159 {
00160 return str_replace( ".", "__", $sName);
00161 }
00162
00171 public function assignValuesFromText( $sIn, $dVat = null)
00172 {
00173 $aRet = array();
00174 $aPieces = explode( '@@', $sIn );
00175 while ( list( $sKey, $sVal ) = each( $aPieces ) ) {
00176 if ( $sVal ) {
00177 $aName = explode( '__', $sVal );
00178 if ( isset( $aName[0] ) && isset( $aName[1] ) ) {
00179 $aRet[] = $this->_fillExplodeArray( $aName, $dVat );
00180 }
00181 }
00182 }
00183 return $aRet;
00184 }
00185
00193 public function assignValuesToText( $aIn)
00194 {
00195 $sRet = "";
00196 reset( $aIn );
00197 while (list($sKey, $sVal) = each($aIn)) {
00198 $sRet .= $sKey;
00199 $sRet .= "__";
00200 $sRet .= $sVal;
00201 $sRet .= "@@";
00202 }
00203 return $sRet;
00204 }
00205
00216 public function formatCurrency( $dValue, $oActCur = null )
00217 {
00218 if (!$oActCur) {
00219 $oActCur = $this->getConfig()->getActShopCurrencyObject();
00220 }
00221 $sFormated = number_format( $dValue, $oActCur->decimal, $oActCur->dec, $oActCur->thousand);
00222
00223 return $sFormated;
00224 }
00225
00233 public function currency2Float( $sValue)
00234 {
00235 $fRet = $sValue;
00236 $iPos = strrpos( $sValue, ".");
00237 if ($iPos && ((strlen($sValue)-1-$iPos) < 2+1)) {
00238
00239 $fRet = substr_replace( $fRet, ",", $iPos, 1);
00240 }
00241
00242 $fRet = str_replace( array(" ","."), "", $fRet);
00243
00244 $fRet = str_replace( ",", ".", $fRet);
00245 return (float) $fRet;
00246 }
00247
00255 public function isSearchEngine( $sClient = null )
00256 {
00257 $myConfig = $this->getConfig();
00258 $blIsSe = false;
00259
00260 if ( !( $myConfig->getConfigParam( 'iDebug' ) && $this->isAdmin() ) ) {
00261
00262
00263 $blIsSe = $myConfig->getGlobalParameter( 'blIsSearchEngine' );
00264 if ( !isset( $blIsSe ) ) {
00265
00266 $aRobots = $myConfig->getConfigParam( 'aRobots' );
00267 $aRobots = is_array( $aRobots )?$aRobots:array();
00268
00269 $aRobotsExcept = $myConfig->getConfigParam( 'aRobotsExcept' );
00270 $aRobotsExcept = is_array( $aRobotsExcept )?$aRobotsExcept:array();
00271
00272 $sClient = $sClient?$sClient:strtolower( getenv( 'HTTP_USER_AGENT' ) );
00273 $blIsSe = false;
00274 $aRobots = array_merge( $aRobots, $aRobotsExcept );
00275 foreach ( $aRobots as $sRobot ) {
00276 if ( strpos( $sClient, $sRobot ) !== false ) {
00277 $blIsSe = true;
00278 break;
00279 }
00280 }
00281 $myConfig->setGlobalParameter( 'blIsSearchEngine', $blIsSe );
00282 }
00283 }
00284
00285 return $blIsSe;
00286 }
00287
00296 public function isValidEmail( $sEmail )
00297 {
00298 $blValid = true;
00299 if ( $sEmail != 'admin' ) {
00300 $blValid = ( preg_match( $this->_sEmailTpl, $sEmail ) != 0 );
00301 }
00302
00303 return $blValid;
00304 }
00305
00311 public function rebuildCache()
00312 {
00313
00314
00315
00316
00317
00318 if ( function_exists( "UserdefinedRebuildCache")) {
00319 UserdefinedRebuildCache();
00320 }
00321 }
00322
00330 public function loadAdminProfile($aInterfaceProfiles)
00331 {
00332
00333
00334 $aInterfaceProfiles = $aInterfaceProfiles;
00335 if ( is_array( $aInterfaceProfiles ) ) {
00336 $sPrevProfile = oxUtilsServer::getInstance()->getOxCookie('oxidadminprofile');
00337 if (isset($sPrevProfile)) {
00338 $aPrevProfile = @explode("@", trim($sPrevProfile));
00339 }
00340
00341
00342 $aProfiles = array();
00343 foreach ( $aInterfaceProfiles as $iPos => $sProfile) {
00344 $aProfileSettings = array($iPos, $sProfile);
00345 $aProfiles[] = $aProfileSettings;
00346 }
00347
00348 if (isset($aPrevProfile[0]) && isset($aProfiles[$aPrevProfile[0]])) {
00349 $aProfiles[$aPrevProfile[0]][2] = 1;
00350 }
00351
00352 oxSession::setVar("aAdminProfiles", $aProfiles);
00353 return $aProfiles;
00354 }
00355 return null;
00356 }
00357
00366 public function fRound($sVal, $oCur = null)
00367 {
00368 startProfile('fround');
00369
00370
00371 $iCurPrecision = null;
00372 if (! defined('OXID_PHP_UNIT')) {
00373 $iCurPrecision = $this->_iCurPrecision;
00374 }
00375
00376 if (is_null($iCurPrecision)) {
00377 if ( !$oCur ) {
00378 $oCur = $this->getConfig()->getActShopCurrencyObject();
00379 }
00380
00381 $iCurPrecision = $oCur->decimal;
00382 $this->_iCurPrecision = $iCurPrecision;
00383 }
00384
00385
00386 static $dprez = null;
00387 if (!$dprez) {
00388 $prez = @ini_get("precision");
00389 if (!$prez) {
00390 $prez = 9;
00391 }
00392 $dprez = pow(10, -$prez);
00393 }
00394
00395
00396 stopProfile('fround');
00397
00398 return round($sVal + $dprez, $iCurPrecision);
00399 }
00400
00410 public function toStaticCache( $sName, $sContent, $sKey = null )
00411 {
00412
00413 if ( $sKey ) {
00414 $this->_aStaticCache[$sName][$sKey] = $sContent;
00415 } else {
00416 $this->_aStaticCache[$sName] = $sContent;
00417 }
00418 }
00419
00427 public function fromStaticCache( $sName)
00428 {
00429 if ( isset( $this->_aStaticCache[$sName])) {
00430 return $this->_aStaticCache[$sName];
00431 }
00432 return null;
00433 }
00434
00442 public function cleanStaticCache($sCacheName = null)
00443 {
00444 if ($sCacheName) {
00445 unset($this->_aStaticCache[$sCacheName]);
00446 } else {
00447 $this->_aStaticCache = null;
00448 }
00449 }
00450
00451
00461 public function toFileCache($sKey, $mContents)
00462 {
00463 $sFilePath = $this->_getCacheFilePath( $sKey );
00464 $iCurTime = oxUtilsDate::getInstance()->getTime();
00465
00466
00467
00468
00469
00470 if (!isset($this->_aFileCacheContents[$sKey]) && file_exists($sFilePath) && abs($iCurTime - filectime($sFilePath) < 40) ) {
00471
00472 return false;
00473 }
00474
00475
00476
00477 $this->_aFileCacheContents[$sKey] = $mContents;
00478
00479
00480 if (!file_exists($sFilePath)) {
00481 $hFile = fopen( $sFilePath, "w");
00482 if ( $hFile) {
00483 fwrite( $hFile, null);
00484 fclose( $hFile);
00485 }
00486 }
00487
00488 return true;
00489 }
00490
00498 public function fromFileCache( $sKey )
00499 {
00500 if (isset($this->_aFileCacheContents[$sKey]))
00501 return $this->_aFileCacheContents[$sKey];
00502
00503 $sRes = null;
00504
00505 $sFilePath = $this->_getCacheFilePath( $sKey );
00506 if (!file_exists( $sFilePath))
00507 return null;
00508 if ( file_exists( $sFilePath) && is_readable($sFilePath)) {
00509
00510 $sRes = file_get_contents( $sFilePath);
00511 if (!$sRes)
00512 return null;
00513 }
00514 $sRes = unserialize($sRes);
00515
00516 return $sRes;
00517 }
00518
00524 public function commitFileCache()
00525 {
00526 foreach($this->_aFileCacheContents as $sKey => $mContents) {
00527 $mContents = serialize($mContents);
00528 $sFilePath = $this->_getCacheFilePath( $sKey );
00529
00530
00531 $hFile = fopen( $sFilePath, "w");
00532 if ( $hFile) {
00533 fwrite( $hFile, $mContents);
00534 fclose( $hFile);
00535 }
00536 }
00537
00538
00539
00540 }
00541
00549 public function oxResetFileCache()
00550 {
00551 $aPathes = glob( $this->_getCacheFilePath( null, true ) . '*' );
00552 if ( is_array( $aPathes ) ) {
00553
00554 $aPathes = preg_grep( $this->_sPermanentCachePattern, $aPathes, PREG_GREP_INVERT );
00555 foreach ( $aPathes as $sFilename ) {
00556 @unlink( $sFilename );
00557 }
00558 }
00559 }
00560
00570 public function getRemoteCachePath($sRemote, $sLocal)
00571 {
00572 clearstatcache();
00573 if ( file_exists( $sLocal ) && filemtime( $sLocal ) && filemtime( $sLocal ) > time() - 86400 ) {
00574 return $sLocal;
00575 }
00576 $hRemote = @fopen( $sRemote, "rb");
00577 $blSuccess = false;
00578 if ( isset( $hRemote) && $hRemote ) {
00579 $hLocal = fopen( $sLocal, "wb");
00580 stream_copy_to_stream($hRemote, $hLocal);
00581 fclose($hRemote);
00582 fclose($hLocal);
00583 $blSuccess = true;
00584 } else {
00585
00586 $aUrl = @parse_url( $sRemote);
00587 if ( !empty( $aUrl["host"])) {
00588 $sPath = $aUrl["path"];
00589 if ( empty( $sPath ) ) {
00590 $sPath = "/";
00591 }
00592 $sHost = $aUrl["host"];
00593
00594 $hSocket = @fsockopen( $sHost, 80, $iErrorNumber, $iErrStr, 5);
00595 if ( $hSocket) {
00596 fputs( $hSocket, "GET ".$sPath." HTTP/1.0\r\nHost: $sHost\r\n\r\n");
00597 $headers = stream_get_line($hSocket, 4096, "\r\n\r\n");
00598 if ( ( $hLocal = @fopen( $sLocal, "wb") ) !== false ) {
00599 rewind($hLocal);
00600
00601
00602 fwrite ( $hLocal, stream_get_contents( $hSocket ) );
00603 fclose( $hLocal );
00604 fclose( $hSocket );
00605 $blSuccess = true;
00606 }
00607 }
00608 }
00609 }
00610 if ( $blSuccess || file_exists( $sLocal ) ) {
00611 return $sLocal;
00612 } else {
00613 return false;
00614 }
00615 }
00616
00622 public function checkAccessRights()
00623 {
00624 $myConfig = $this->getConfig();
00625
00626 $blIsAuth = false;
00627
00628 $sUserID = oxSession::getVar( "auth");
00629
00630
00631 oxSession::setVar( "malladmin", 0);
00632 oxSession::setVar( "blIsAdmin", 0);
00633 oxSession::deleteVar( "blIsAdmin" );
00634 $myConfig->setConfigParam( 'blMallAdmin', false );
00635
00636 $myConfig->setConfigParam( 'blAllowInheritedEdit', false );
00637
00638 if ( $sUserID) {
00639
00640 $oDb = oxDb::getDb();
00641 $sRights = $oDb->getOne("select oxrights from oxuser where oxid = ".$oDb->quote($sUserID));
00642
00643 if ( $sRights != "user") {
00644
00645 if ( $sRights == "malladmin") {
00646 oxSession::setVar( "malladmin", 1);
00647 $myConfig->setConfigParam( 'blMallAdmin', true );
00648
00649
00650
00651 $myConfig->setConfigParam( 'blAllowSharedEdit', true );
00652
00653 $sShop = oxSession::getVar( "actshop");
00654 if ( !isset($sShop)) {
00655 oxSession::setVar( "actshop", $myConfig->getBaseShopId());
00656 }
00657 $blIsAuth = true;
00658 } else {
00659 $sShopID = $oDb->getOne("select oxid from oxshops where oxid = " . $oDb->quote( $sRights ) );
00660 if ( isset( $sShopID) && $sShopID) {
00661
00662 oxSession::setVar( "actshop", $sRights);
00663 oxSession::setVar( "currentadminshop", $sRights);
00664 oxSession::setVar( "shp", $sRights);
00665
00666
00667 if ('chshp' == oxConfig::getParameter( 'fnc' )) {
00668
00669 $blIsAuth = false;
00670 } else {
00671 $blIsAuth = true;
00672
00673 $aShopIdVars = array('actshop', 'shp', 'currentadminshop');
00674 foreach ($aShopIdVars as $sShopIdVar) {
00675 if ($sGotShop = oxConfig::getParameter( $sShopIdVar )) {
00676 if ($sGotShop != $sRights) {
00677 $blIsAuth = false;
00678 break;
00679 }
00680 }
00681 }
00682 }
00683 }
00684 }
00685
00686 oxSession::setVar( "blIsAdmin", 1);
00687 }
00688 }
00689 return $blIsAuth;
00690 }
00691
00701 public function seoIsActive( $blReset = false, $sShopId = null, $iActLang = null )
00702 {
00703 if ( !is_null( $this->_blSeoIsActive ) && !$blReset ) {
00704 return $this->_blSeoIsActive;
00705 }
00706
00707 $myConfig = $this->getConfig();
00708
00709 if ( $this->isAdmin() ) {
00710
00711 $this->_blSeoIsActive = false;
00712 } elseif ( ( $this->_blSeoIsActive = $myConfig->getConfigParam( 'blSeoMode' ) ) === null ) {
00713 $this->_blSeoIsActive = true;
00714
00715 $aSeoModes = $myConfig->getconfigParam( 'aSeoModes' );
00716 $sActShopId = $sShopId ? $sShopId : $myConfig->getActiveShop()->getId();
00717 $iActLang = $iActLang ? $iActLang : (int) oxLang::getInstance()->getBaseLanguage();
00718
00719
00720 if ( is_array( $aSeoModes ) && isset( $aSeoModes[$sActShopId] ) && isset( $aSeoModes[$sActShopId][$iActLang] ) ) {
00721 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
00722 }
00723 }
00724
00725 return $this->_blSeoIsActive;
00726 }
00727
00737 public function getShopBit( $iShopId )
00738 {
00739 $iShopId = (int) $iShopId;
00740
00741 $iRes = oxDb::getDb()->getOne( "select 1 << ( $iShopId - 1 ) as shopbit" );
00742
00743
00744 return $iRes;
00745 }
00746
00756 public function bitwiseAnd( $iVal1, $iVal2 )
00757 {
00758
00759 $iRes = oxDb::getDb()->getOne( "select ($iVal1 & $iVal2) as bitwiseAnd" );
00760
00761
00762 return $iRes;
00763 }
00764
00774 public function bitwiseOr( $iVal1, $iVal2 )
00775 {
00776
00777 $iRes = oxDb::getDb()->getOne( "select ($iVal1 | $iVal2) as bitwiseOr" );
00778
00779
00780 return $iRes;
00781 }
00782
00790 public function isValidAlpha( $sField )
00791 {
00792 return (boolean) preg_match( "#^[\w]*$#", $sField );
00793 }
00794
00804 protected function _simpleRedirect( $sUrl, $sHeaderCode )
00805 {
00806 header( $sHeaderCode );
00807 header( "Location: $sUrl" );
00808 header( "Connection: close" );
00809 }
00810
00819 public function redirect( $sUrl, $blAddRedirectParam = true, $iHeaderCode = 301 )
00820 {
00821
00822
00823 if ( $blAddRedirectParam && oxConfig::getParameter( 'redirected' ) ) {
00824 return;
00825 }
00826
00827 if ( $blAddRedirectParam ) {
00828 $sUrl = $this->_addUrlParameters( $sUrl, array( 'redirected' => 1 ) );
00829 }
00830
00831 $sUrl = str_ireplace( "&", "&", $sUrl );
00832
00833 $sHeaderCode = '';
00834 switch ($iHeaderCode) {
00835 case 301:
00836 $sHeaderCode = "HTTP/1.1 301 Moved Permanently";
00837 break;
00838 case 302:
00839 default:
00840 $sHeaderCode = "HTTP/1.1 302 Found";
00841 }
00842
00843 $this->_simpleRedirect( $sUrl, $sHeaderCode );
00844
00845 try {
00846 $this->getSession()->freeze();
00847 } catch( oxException $oEx ) {
00848 $oEx->debugOut();
00849
00850 }
00851
00852 if ( defined( 'OXID_PHP_UNIT' ) ) {
00853 return;
00854 }
00855
00856 $this->showMessageAndExit( '' );
00857 }
00858
00866 public function showMessageAndExit( $sMsg )
00867 {
00868 $this->getSession()->freeze();
00869
00870 if ( defined( 'OXID_PHP_UNIT' ) ) {
00871 return;
00872 }
00873
00874 die( $sMsg );
00875 }
00876
00884 public function setHeader($sHeader)
00885 {
00886 header($sHeader);
00887 }
00888
00897 protected function _addUrlParameters( $sUrl, $aParams )
00898 {
00899 $sDelim = ( ( getStr()->strpos( $sUrl, '?' ) !== false ) )?'&':'?';
00900 foreach ( $aParams as $sName => $sVal ) {
00901 $sUrl = $sUrl . $sDelim . $sName . '=' . $sVal;
00902 $sDelim = '&';
00903 }
00904
00905 return $sUrl;
00906 }
00907
00919 protected function _fillExplodeArray( $aName, $dVat = null)
00920 {
00921 $myConfig = $this->getConfig();
00922 $oObject = new OxstdClass();
00923 $aPrice = explode( '!P!', $aName[0]);
00924
00925 if ( ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) && isset( $aPrice[0] ) && isset( $aPrice[1] ) ) || $this->isAdmin() ) {
00926
00927
00928 $oObject->price = $aPrice[1];
00929 $aName[0] = $aPrice[0];
00930
00931 $iPercPos = getStr()->strpos( $oObject->price, '%' );
00932 if ( $iPercPos !== false ) {
00933 $oObject->priceUnit = '%';
00934 $oObject->fprice = $oObject->price;
00935 $oObject->price = substr( $oObject->price, 0, $iPercPos );
00936 } else {
00937 $oCur = $myConfig->getActShopCurrencyObject();
00938 $oObject->price = str_replace(',', '.', $oObject->price);
00939 $oObject->fprice = oxLang::getInstance()->formatCurrency( $oObject->price * $oCur->rate, $oCur);
00940 $oObject->priceUnit = 'abs';
00941 }
00942
00943
00944 if ( !$this->isAdmin() && $oObject->price != 0 ) {
00945 $aName[0] .= " ";
00946 if ( $oObject->price > 0 ) {
00947 $aName[0] .= "+";
00948 }
00949
00950 if ( $dVat != null && $oObject->priceUnit == 'abs' ) {
00951 $oPrice = oxNew('oxPrice');
00952 $oPrice->setPrice($oObject->price, $dVat);
00953 $aName[0] .= oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() * $oCur->rate, $oCur);
00954 } else {
00955 $aName[0] .= $oObject->fprice;
00956 }
00957 if ( $oObject->priceUnit == 'abs' ) {
00958 $aName[0] .= " ".$oCur->sign;
00959 }
00960 }
00961 } elseif ( isset( $aPrice[0] ) && isset($aPrice[1] ) ) {
00962
00963 $aName[0] = preg_replace( "/!P!.*/", "", $aName[0] );
00964 }
00965
00966 $oObject->name = $aName[0];
00967 $oObject->value = $aName[1];
00968 return $oObject;
00969 }
00970
00978 public function oxMimeContentType( $sFileName )
00979 {
00980 $sFileName = strtolower( $sFileName );
00981 $iLastDot = strrpos( $sFileName, '.' );
00982
00983 if ( $iLastDot !== false ) {
00984 $sType = substr( $sFileName, $iLastDot + 1 );
00985 switch ( $sType ) {
00986 case 'gif':
00987 $sType = 'image/gif';
00988 break;
00989 case 'jpeg':
00990 case 'jpg':
00991 $sType = 'image/jpeg';
00992 break;
00993 case 'png':
00994 $sType = 'image/png';
00995 break;
00996 default:
00997 $sType = false;
00998 break;
00999 }
01000 }
01001 return $sType;
01002 }
01003
01012 public function logger( $sText, $blNewline = false )
01013 { $myConfig = $this->getConfig();
01014
01015 if ( $myConfig->getConfigParam( 'iDebug' ) == -2) {
01016 if ( gettype( $sText ) != 'string' ) {
01017 $sText = var_export( $sText, true);
01018 }
01019 @error_log("----------------------------------------------\n$sText".( ( $blNewline ) ?"\n":"" )."\n", 3, $myConfig->getConfigParam( 'sCompileDir' ).'/log.txt' );
01020 }
01021
01022 }
01023
01031 protected function _stripQuotes($mInput)
01032 {
01033 return is_array($mInput) ? array_map( array( $this, '_stripQuotes' ), $mInput) : stripslashes( $mInput );
01034 }
01035
01043 public function strRot13( $sStr )
01044 {
01045 $sFrom = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
01046 $sTo = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
01047
01048 return strtr( $sStr, $sFrom, $sTo );
01049 }
01050
01051
01061 public function prepareUrlForNoSession($sUrl)
01062 {
01063 if ( $this->seoIsActive() ) {
01064 return $sUrl;
01065 }
01066
01067 $sUrl = preg_replace('/(force_)?sid=[a-z0-9\._]*&?(amp;)?/i', '', $sUrl);
01068
01069 $oStr = getStr();
01070 if ($qpos = $oStr->strpos($sUrl, '?')) {
01071 if ($qpos == $oStr->strlen($sUrl)-1) {
01072 $sSep = '';
01073 } else {
01074 $sSep = '&';
01075 }
01076 } else {
01077 $sSep = '?';
01078 }
01079
01080 if (!preg_match('/[&?](amp;)?lang=[0-9]+/i', $sUrl)) {
01081 $sUrl .= "{$sSep}lang=".oxLang::getInstance()->getBaseLanguage();
01082 $sSep = '&';
01083 }
01084
01085 if (!preg_match('/[&?](amp;)?cur=[0-9]+/i', $sUrl)) {
01086 $iCur = (int) oxConfig::getParameter('currency');
01087 if ($iCur) {
01088 $sUrl .= "{$sSep}cur=".$iCur;
01089 $sSep = '&';
01090 }
01091 }
01092
01093 return $sUrl;
01094 }
01095
01104 protected function _getCacheFilePath( $sCacheName, $blPathOnly = false )
01105 {
01106 $sVersionPrefix = "";
01107
01108
01109 $sVersionPrefix = 'pe';
01110
01111 $sPath = $this->getConfig()->getConfigParam( 'sCompileDir' );
01112 return $blPathOnly ? "{$sPath}/" : "{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}.txt";
01113 }
01114
01122 public function getLangCache( $sCacheName )
01123 {
01124 $aLangCache = null;
01125 $sFilePath = $this->_getCacheFilePath( $sCacheName );
01126 if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
01127 include $sFilePath;
01128 }
01129 return $aLangCache;
01130 }
01131
01140 public function setLangCache( $sCacheName, $aLangCache )
01141 {
01142 $sCache = "<?php\n\$aLangCache = ".var_export( $aLangCache, true ).";";
01143 $blRes = file_put_contents($this->_getCacheFilePath($sCacheName), $sCache);
01144 return $blRes;
01145 }
01146
01154 public function checkUrlEndingSlash( $sUrl )
01155 {
01156 if ( !preg_match("/\/$/", $sUrl) ) {
01157 $sUrl .= '/';
01158 }
01159
01160 return $sUrl;
01161 }
01162
01163 }