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 $hLocal = @fopen( $sLocal, "wb");
00599 stream_copy_to_stream($hSocket, $hLocal);
00600 fclose( $hSocket);
00601 fclose($hLocal);
00602 $blSuccess = true;
00603 }
00604 }
00605 }
00606 if ( $blSuccess || file_exists( $sLocal ) ) {
00607 return $sLocal;
00608 } else {
00609 return false;
00610 }
00611 }
00612
00618 public function checkAccessRights()
00619 {
00620 $myConfig = $this->getConfig();
00621
00622 $blIsAuth = false;
00623
00624 $sUserID = oxSession::getVar( "auth");
00625
00626
00627 oxSession::setVar( "malladmin", 0);
00628 oxSession::setVar( "blIsAdmin", 0);
00629 oxSession::deleteVar( "blIsAdmin" );
00630 $myConfig->setConfigParam( 'blMallAdmin', false );
00631
00632 $myConfig->setConfigParam( 'blAllowInheritedEdit', false );
00633
00634 if ( $sUserID) {
00635
00636 $oDb = oxDb::getDb();
00637 $sUserID = $oDb->quote($sUserID);
00638 $sRights = $oDb->getOne("select oxrights from oxuser where oxid = $sUserID");
00639
00640 if ( $sRights != "user") {
00641
00642 if ( $sRights == "malladmin") {
00643 oxSession::setVar( "malladmin", 1);
00644 $myConfig->setConfigParam( 'blMallAdmin', true );
00645
00646
00647
00648 $myConfig->setConfigParam( 'blAllowSharedEdit', true );
00649
00650 $sShop = oxSession::getVar( "actshop");
00651 if ( !isset($sShop)) {
00652 oxSession::setVar( "actshop", $myConfig->getBaseShopId());
00653 }
00654 $blIsAuth = true;
00655 } else {
00656 $sShopID = $oDb->getOne("select oxid from oxshops where oxid = '{$sRights}'");
00657 if ( isset( $sShopID) && $sShopID) {
00658
00659 oxSession::setVar( "actshop", $sRights);
00660 oxSession::setVar( "currentadminshop", $sRights);
00661 oxSession::setVar( "shp", $sRights);
00662
00663
00664 if ('chshp' == oxConfig::getParameter( 'fnc' )) {
00665
00666 $blIsAuth = false;
00667 } else {
00668 $blIsAuth = true;
00669
00670 $aShopIdVars = array('actshop', 'shp', 'currentadminshop');
00671 foreach ($aShopIdVars as $sShopIdVar) {
00672 if ($sGotShop = oxConfig::getParameter( $sShopIdVar )) {
00673 if ($sGotShop != $sRights) {
00674 $blIsAuth = false;
00675 break;
00676 }
00677 }
00678 }
00679 }
00680 }
00681 }
00682
00683 oxSession::setVar( "blIsAdmin", 1);
00684 }
00685 }
00686 return $blIsAuth;
00687 }
00688
00698 public function seoIsActive( $blReset = false, $sShopId = null, $iActLang = null )
00699 {
00700 if ( !is_null( $this->_blSeoIsActive ) && !$blReset ) {
00701 return $this->_blSeoIsActive;
00702 }
00703
00704 $myConfig = $this->getConfig();
00705
00706 if ( $this->isAdmin() ) {
00707
00708 $this->_blSeoIsActive = false;
00709 } elseif ( ( $this->_blSeoIsActive = $myConfig->getConfigParam( 'blSeoMode' ) ) === null ) {
00710 $this->_blSeoIsActive = true;
00711
00712 $aSeoModes = $myConfig->getconfigParam( 'aSeoModes' );
00713 $sActShopId = $sShopId ? $sShopId : $myConfig->getActiveShop()->getId();
00714 $iActLang = $iActLang ? $iActLang : (int) oxLang::getInstance()->getBaseLanguage();
00715
00716
00717 if ( is_array( $aSeoModes ) && isset( $aSeoModes[$sActShopId] ) && isset( $aSeoModes[$sActShopId][$iActLang] ) ) {
00718 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
00719 }
00720 }
00721
00722 return $this->_blSeoIsActive;
00723 }
00724
00734 public function getShopBit( $iShopId )
00735 {
00736 $iShopId = (int) $iShopId;
00737
00738 $iRes = oxDb::getDb()->getOne( "select 1 << ( $iShopId - 1 ) as shopbit" );
00739
00740
00741 return $iRes;
00742 }
00743
00753 public function bitwiseAnd( $iVal1, $iVal2 )
00754 {
00755
00756 $iRes = oxDb::getDb()->getOne( "select ($iVal1 & $iVal2) as bitwiseAnd" );
00757
00758
00759 return $iRes;
00760 }
00761
00771 public function bitwiseOr( $iVal1, $iVal2 )
00772 {
00773
00774 $iRes = oxDb::getDb()->getOne( "select ($iVal1 | $iVal2) as bitwiseOr" );
00775
00776
00777 return $iRes;
00778 }
00779
00787 public function isValidAlpha( $sField )
00788 {
00789 return (boolean) preg_match( "#^[\w]*$#", $sField );
00790 }
00791
00801 protected function _simpleRedirect( $sUrl, $sHeaderCode )
00802 {
00803 header( $sHeaderCode );
00804 header( "Location: $sUrl" );
00805 header( "Connection: close" );
00806 }
00807
00816 public function redirect( $sUrl, $blAddRedirectParam = true )
00817 {
00818
00819
00820 if ( $blAddRedirectParam && oxConfig::getParameter( 'redirected' ) ) {
00821 return;
00822 }
00823
00824 if ( $blAddRedirectParam ) {
00825 $sUrl = $this->_addUrlParameters( $sUrl, array( 'redirected' => 1 ) );
00826 }
00827
00828 $sUrl = str_ireplace( "&", "&", $sUrl );
00829 $this->_simpleRedirect( $sUrl, "HTTP/1.1 301 Moved Permanently" );
00830
00831 try {
00832 $this->getSession()->freeze();
00833 } catch( oxException $oEx ) {
00834 $oEx->debugOut();
00835
00836 }
00837
00838 if ( defined( 'OXID_PHP_UNIT' ) ) {
00839 return;
00840 }
00841
00842 $this->showMessageAndExit( '' );
00843 }
00844
00852 public function showMessageAndExit( $sMsg )
00853 {
00854 $this->getSession()->freeze();
00855
00856 if ( defined( 'OXID_PHP_UNIT' ) ) {
00857 return;
00858 }
00859
00860 die( $sMsg );
00861 }
00862
00870 public function setHeader($sHeader)
00871 {
00872 header($sHeader);
00873 }
00874
00883 protected function _addUrlParameters( $sUrl, $aParams )
00884 {
00885 $sDelim = ( ( getStr()->strpos( $sUrl, '?' ) !== false ) )?'&':'?';
00886 foreach ( $aParams as $sName => $sVal ) {
00887 $sUrl = $sUrl . $sDelim . $sName . '=' . $sVal;
00888 $sDelim = '&';
00889 }
00890
00891 return $sUrl;
00892 }
00893
00905 protected function _fillExplodeArray( $aName, $dVat = null)
00906 {
00907 $myConfig = $this->getConfig();
00908 $oObject = new OxstdClass();
00909 $aPrice = explode( '!P!', $aName[0]);
00910
00911 if ( ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) && isset( $aPrice[0] ) && isset( $aPrice[1] ) ) || $this->isAdmin() ) {
00912
00913
00914 $oObject->price = $aPrice[1];
00915 $aName[0] = $aPrice[0];
00916
00917 $iPercPos = getStr()->strpos( $oObject->price, '%' );
00918 if ( $iPercPos !== false ) {
00919 $oObject->priceUnit = '%';
00920 $oObject->fprice = $oObject->price;
00921 $oObject->price = substr( $oObject->price, 0, $iPercPos );
00922 } else {
00923 $oCur = $myConfig->getActShopCurrencyObject();
00924 $oObject->price = str_replace(',', '.', $oObject->price);
00925 $oObject->fprice = oxLang::getInstance()->formatCurrency( $oObject->price * $oCur->rate, $oCur);
00926 $oObject->priceUnit = 'abs';
00927 }
00928
00929
00930 if ( !$this->isAdmin() && $oObject->price != 0 ) {
00931 $aName[0] .= " ";
00932 if ( $oObject->price > 0 ) {
00933 $aName[0] .= "+";
00934 }
00935
00936 if ( $dVat != null && $oObject->priceUnit == 'abs' ) {
00937 $oPrice = oxNew('oxPrice');
00938 $oPrice->setPrice($oObject->price, $dVat);
00939 $aName[0] .= oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() * $oCur->rate, $oCur);
00940 } else {
00941 $aName[0] .= $oObject->fprice;
00942 }
00943 if ( $oObject->priceUnit == 'abs' ) {
00944 $aName[0] .= " ".$oCur->sign;
00945 }
00946 }
00947 } elseif ( isset( $aPrice[0] ) && isset($aPrice[1] ) ) {
00948
00949 $aName[0] = preg_replace( "/!P!.*/", "", $aName[0] );
00950 }
00951
00952 $oObject->name = $aName[0];
00953 $oObject->value = $aName[1];
00954 return $oObject;
00955 }
00956
00964 public function oxMimeContentType( $sFileName )
00965 {
00966 $sFileName = strtolower( $sFileName );
00967 $iLastDot = strrpos( $sFileName, '.' );
00968
00969 if ( $iLastDot !== false ) {
00970 $sType = substr( $sFileName, $iLastDot + 1 );
00971 switch ( $sType ) {
00972 case 'gif':
00973 $sType = 'image/gif';
00974 break;
00975 case 'jpeg':
00976 case 'jpg':
00977 $sType = 'image/jpeg';
00978 break;
00979 case 'png':
00980 $sType = 'image/png';
00981 break;
00982 default:
00983 $sType = false;
00984 break;
00985 }
00986 }
00987 return $sType;
00988 }
00989
00998 public function logger( $sText, $blNewline = false )
00999 { $myConfig = $this->getConfig();
01000
01001 if ( $myConfig->getConfigParam( 'iDebug' ) == -2) {
01002 if ( gettype( $sText ) != 'string' ) {
01003 $sText = var_export( $sText, true);
01004 }
01005 @error_log("----------------------------------------------\n$sText".( ( $blNewline ) ?"\n":"" )."\n", 3, $myConfig->getConfigParam( 'sCompileDir' ).'/log.txt' );
01006 }
01007
01008 }
01009
01017 protected function _stripQuotes($mInput)
01018 {
01019 return is_array($mInput) ? array_map( array( $this, '_stripQuotes' ), $mInput) : stripslashes( $mInput );
01020 }
01021
01029 public function strRot13( $sStr )
01030 {
01031 $sFrom = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
01032 $sTo = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
01033
01034 return strtr( $sStr, $sFrom, $sTo );
01035 }
01036
01037
01047 public function prepareUrlForNoSession($sUrl)
01048 {
01049 if ( $this->seoIsActive() ) {
01050 return $sUrl;
01051 }
01052
01053 $sUrl = preg_replace('/(force_)?sid=[a-z0-9\._]*&?(amp;)?/i', '', $sUrl);
01054
01055 $oStr = getStr();
01056 if ($qpos = $oStr->strpos($sUrl, '?')) {
01057 if ($qpos == $oStr->strlen($sUrl)-1) {
01058 $sSep = '';
01059 } else {
01060 $sSep = '&';
01061 }
01062 } else {
01063 $sSep = '?';
01064 }
01065
01066 if (!preg_match('/[&?](amp;)?lang=[0-9]+/i', $sUrl)) {
01067 $sUrl .= "{$sSep}lang=".oxLang::getInstance()->getBaseLanguage();
01068 $sSep = '&';
01069 }
01070
01071 if (!preg_match('/[&?](amp;)?cur=[0-9]+/i', $sUrl)) {
01072 $iCur = (int) oxConfig::getParameter('currency');
01073 if ($iCur) {
01074 $sUrl .= "{$sSep}cur=".$iCur;
01075 $sSep = '&';
01076 }
01077 }
01078
01079 return $sUrl;
01080 }
01081
01090 protected function _getCacheFilePath( $sCacheName, $blPathOnly = false )
01091 {
01092 $sVersionPrefix = "";
01093
01094
01095 $sVersionPrefix = 'pe';
01096
01097 $sPath = $this->getConfig()->getConfigParam( 'sCompileDir' );
01098 return $blPathOnly ? "{$sPath}/" : "{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}.txt";
01099 }
01100
01108 public function getLangCache( $sCacheName )
01109 {
01110 $aLangCache = null;
01111 $sFilePath = $this->_getCacheFilePath( $sCacheName );
01112 if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
01113 include $sFilePath;
01114 }
01115 return $aLangCache;
01116 }
01117
01126 public function setLangCache( $sCacheName, $aLangCache )
01127 {
01128 $sCache = "<?php\n\$aLangCache = ".var_export( $aLangCache, true ).";";
01129 $blRes = file_put_contents($this->_getCacheFilePath($sCacheName), $sCache);
01130 return $blRes;
01131 }
01132
01140 public function checkUrlEndingSlash( $sUrl )
01141 {
01142 if ( !preg_match("/\/$/", $sUrl) ) {
01143 $sUrl .= '/';
01144 }
01145
01146 return $sUrl;
01147 }
01148
01149 }