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 clearstatcache();
00471 if (!isset($this->_aFileCacheContents[$sKey]) && file_exists($sFilePath) && (!filesize($sFilePath)) && abs($iCurTime - filectime($sFilePath) < 40) ) {
00472
00473 return false;
00474 }
00475
00476
00477 if (!isset($this->_aFileCacheContents[$sKey])) {
00478
00479 $hFile = fopen($sFilePath, "w");
00480 if ($hFile) {
00481 fclose($hFile);
00482 }
00483 clearstatcache();
00484 }
00485
00486 $this->_aFileCacheContents[$sKey] = $mContents;
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 $this->_aFileCacheContents = array();
00540 clearstatcache ();
00541 }
00542
00550 public function oxResetFileCache()
00551 {
00552 $aPathes = glob( $this->_getCacheFilePath( null, true ) . '*' );
00553 if ( is_array( $aPathes ) ) {
00554
00555 $aPathes = preg_grep( $this->_sPermanentCachePattern, $aPathes, PREG_GREP_INVERT );
00556 foreach ( $aPathes as $sFilename ) {
00557 @unlink( $sFilename );
00558 }
00559 }
00560 }
00561
00571 public function getRemoteCachePath($sRemote, $sLocal)
00572 {
00573 clearstatcache();
00574 if ( file_exists( $sLocal ) && filemtime( $sLocal ) && filemtime( $sLocal ) > time() - 86400 ) {
00575 return $sLocal;
00576 }
00577 $hRemote = @fopen( $sRemote, "rb");
00578 $blSuccess = false;
00579 if ( isset( $hRemote) && $hRemote ) {
00580 $hLocal = fopen( $sLocal, "wb");
00581 stream_copy_to_stream($hRemote, $hLocal);
00582 fclose($hRemote);
00583 fclose($hLocal);
00584 $blSuccess = true;
00585 } else {
00586
00587 $aUrl = @parse_url( $sRemote);
00588 if ( !empty( $aUrl["host"])) {
00589 $sPath = $aUrl["path"];
00590 if ( empty( $sPath ) ) {
00591 $sPath = "/";
00592 }
00593 $sHost = $aUrl["host"];
00594
00595 $hSocket = @fsockopen( $sHost, 80, $iErrorNumber, $iErrStr, 5);
00596 if ( $hSocket) {
00597 fputs( $hSocket, "GET ".$sPath." HTTP/1.0\r\nHost: $sHost\r\n\r\n");
00598 $headers = stream_get_line($hSocket, 4096, "\r\n\r\n");
00599 if ( ( $hLocal = @fopen( $sLocal, "wb") ) !== false ) {
00600 rewind($hLocal);
00601
00602
00603 fwrite ( $hLocal, stream_get_contents( $hSocket ) );
00604 fclose( $hLocal );
00605 fclose( $hSocket );
00606 $blSuccess = true;
00607 }
00608 }
00609 }
00610 }
00611 if ( $blSuccess || file_exists( $sLocal ) ) {
00612 return $sLocal;
00613 } else {
00614 return false;
00615 }
00616 }
00617
00623 public function checkAccessRights()
00624 {
00625 $myConfig = $this->getConfig();
00626
00627 $blIsAuth = false;
00628
00629 $sUserID = oxSession::getVar( "auth");
00630
00631
00632 oxSession::setVar( "malladmin", 0);
00633 oxSession::setVar( "blIsAdmin", 0);
00634 oxSession::deleteVar( "blIsAdmin" );
00635 $myConfig->setConfigParam( 'blMallAdmin', false );
00636
00637 $myConfig->setConfigParam( 'blAllowInheritedEdit', false );
00638
00639 if ( $sUserID) {
00640
00641 $oDb = oxDb::getDb();
00642 $sRights = $oDb->getOne("select oxrights from oxuser where oxid = ".$oDb->quote($sUserID));
00643
00644 if ( $sRights != "user") {
00645
00646 if ( $sRights == "malladmin") {
00647 oxSession::setVar( "malladmin", 1);
00648 $myConfig->setConfigParam( 'blMallAdmin', true );
00649
00650
00651
00652 $myConfig->setConfigParam( 'blAllowSharedEdit', true );
00653
00654 $sShop = oxSession::getVar( "actshop");
00655 if ( !isset($sShop)) {
00656 oxSession::setVar( "actshop", $myConfig->getBaseShopId());
00657 }
00658 $blIsAuth = true;
00659 } else {
00660 $sShopID = $oDb->getOne("select oxid from oxshops where oxid = " . $oDb->quote( $sRights ) );
00661 if ( isset( $sShopID) && $sShopID) {
00662
00663 oxSession::setVar( "actshop", $sRights);
00664 oxSession::setVar( "currentadminshop", $sRights);
00665 oxSession::setVar( "shp", $sRights);
00666
00667
00668 if ('chshp' == oxConfig::getParameter( 'fnc' )) {
00669
00670 $blIsAuth = false;
00671 } else {
00672 $blIsAuth = true;
00673
00674 $aShopIdVars = array('actshop', 'shp', 'currentadminshop');
00675 foreach ($aShopIdVars as $sShopIdVar) {
00676 if ($sGotShop = oxConfig::getParameter( $sShopIdVar )) {
00677 if ($sGotShop != $sRights) {
00678 $blIsAuth = false;
00679 break;
00680 }
00681 }
00682 }
00683 }
00684 }
00685 }
00686
00687 oxSession::setVar( "blIsAdmin", 1);
00688 }
00689 }
00690 return $blIsAuth;
00691 }
00692
00702 public function seoIsActive( $blReset = false, $sShopId = null, $iActLang = null )
00703 {
00704 if ( !is_null( $this->_blSeoIsActive ) && !$blReset ) {
00705 return $this->_blSeoIsActive;
00706 }
00707
00708 $myConfig = $this->getConfig();
00709
00710 if ( ( $this->_blSeoIsActive = $myConfig->getConfigParam( 'blSeoMode' ) ) === null ) {
00711 $this->_blSeoIsActive = true;
00712
00713 $aSeoModes = $myConfig->getconfigParam( 'aSeoModes' );
00714 $sActShopId = $sShopId ? $sShopId : $myConfig->getActiveShop()->getId();
00715 $iActLang = $iActLang ? $iActLang : (int) oxLang::getInstance()->getBaseLanguage();
00716
00717
00718 if ( is_array( $aSeoModes ) && isset( $aSeoModes[$sActShopId] ) && isset( $aSeoModes[$sActShopId][$iActLang] ) ) {
00719 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
00720 }
00721 }
00722
00723 return $this->_blSeoIsActive;
00724 }
00725
00735 public function getShopBit( $iShopId )
00736 {
00737 $iShopId = (int) $iShopId;
00738
00739 $iRes = oxDb::getDb()->getOne( "select 1 << ( $iShopId - 1 ) as shopbit" );
00740
00741
00742 return $iRes;
00743 }
00744
00754 public function bitwiseAnd( $iVal1, $iVal2 )
00755 {
00756
00757 $iRes = oxDb::getDb()->getOne( "select ($iVal1 & $iVal2) as bitwiseAnd" );
00758
00759
00760 return $iRes;
00761 }
00762
00772 public function bitwiseOr( $iVal1, $iVal2 )
00773 {
00774
00775 $iRes = oxDb::getDb()->getOne( "select ($iVal1 | $iVal2) as bitwiseOr" );
00776
00777
00778 return $iRes;
00779 }
00780
00788 public function isValidAlpha( $sField )
00789 {
00790 return (boolean) preg_match( "#^[\w]*$#", $sField );
00791 }
00792
00802 protected function _simpleRedirect( $sUrl, $sHeaderCode )
00803 {
00804 header( $sHeaderCode );
00805 header( "Location: $sUrl" );
00806 header( "Connection: close" );
00807 }
00808
00817 public function redirect( $sUrl, $blAddRedirectParam = true, $iHeaderCode = 301 )
00818 {
00819
00820
00821 if ( $blAddRedirectParam && oxConfig::getParameter( 'redirected' ) ) {
00822 return;
00823 }
00824
00825 if ( $blAddRedirectParam ) {
00826 $sUrl = $this->_addUrlParameters( $sUrl, array( 'redirected' => 1 ) );
00827 }
00828
00829 $sUrl = str_ireplace( "&", "&", $sUrl );
00830
00831 $sHeaderCode = '';
00832 switch ($iHeaderCode) {
00833 case 301:
00834 $sHeaderCode = "HTTP/1.1 301 Moved Permanently";
00835 break;
00836 case 302:
00837 default:
00838 $sHeaderCode = "HTTP/1.1 302 Found";
00839 }
00840
00841 $this->_simpleRedirect( $sUrl, $sHeaderCode );
00842
00843 try {
00844 $this->getSession()->freeze();
00845 } catch( oxException $oEx ) {
00846 $oEx->debugOut();
00847
00848 }
00849
00850 if ( defined( 'OXID_PHP_UNIT' ) ) {
00851 return;
00852 }
00853
00854 $this->showMessageAndExit( '' );
00855 }
00856
00864 public function showMessageAndExit( $sMsg )
00865 {
00866 $this->getSession()->freeze();
00867
00868 if ( defined( 'OXID_PHP_UNIT' ) ) {
00869 return;
00870 }
00871
00872 die( $sMsg );
00873 }
00874
00882 public function setHeader($sHeader)
00883 {
00884 header($sHeader);
00885 }
00886
00895 protected function _addUrlParameters( $sUrl, $aParams )
00896 {
00897 $sDelim = ( ( getStr()->strpos( $sUrl, '?' ) !== false ) )?'&':'?';
00898 foreach ( $aParams as $sName => $sVal ) {
00899 $sUrl = $sUrl . $sDelim . $sName . '=' . $sVal;
00900 $sDelim = '&';
00901 }
00902
00903 return $sUrl;
00904 }
00905
00917 protected function _fillExplodeArray( $aName, $dVat = null)
00918 {
00919 $myConfig = $this->getConfig();
00920 $oObject = new OxstdClass();
00921 $aPrice = explode( '!P!', $aName[0]);
00922
00923 if ( ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) && isset( $aPrice[0] ) && isset( $aPrice[1] ) ) || $this->isAdmin() ) {
00924
00925
00926 $oObject->price = $aPrice[1];
00927 $aName[0] = $aPrice[0];
00928
00929 $iPercPos = getStr()->strpos( $oObject->price, '%' );
00930 if ( $iPercPos !== false ) {
00931 $oObject->priceUnit = '%';
00932 $oObject->fprice = $oObject->price;
00933 $oObject->price = substr( $oObject->price, 0, $iPercPos );
00934 } else {
00935 $oCur = $myConfig->getActShopCurrencyObject();
00936 $oObject->price = str_replace(',', '.', $oObject->price);
00937 $oObject->fprice = oxLang::getInstance()->formatCurrency( $oObject->price * $oCur->rate, $oCur);
00938 $oObject->priceUnit = 'abs';
00939 }
00940
00941
00942 if ( !$this->isAdmin() && $oObject->price != 0 ) {
00943 $aName[0] .= " ";
00944 if ( $oObject->price > 0 ) {
00945 $aName[0] .= "+";
00946 }
00947
00948 if ( $dVat != null && $oObject->priceUnit == 'abs' ) {
00949 $oPrice = oxNew('oxPrice');
00950 $oPrice->setPrice($oObject->price, $dVat);
00951 $aName[0] .= oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() * $oCur->rate, $oCur);
00952 } else {
00953 $aName[0] .= $oObject->fprice;
00954 }
00955 if ( $oObject->priceUnit == 'abs' ) {
00956 $aName[0] .= " ".$oCur->sign;
00957 }
00958 }
00959 } elseif ( isset( $aPrice[0] ) && isset($aPrice[1] ) ) {
00960
00961 $aName[0] = preg_replace( "/!P!.*/", "", $aName[0] );
00962 }
00963
00964 $oObject->name = $aName[0];
00965 $oObject->value = $aName[1];
00966 return $oObject;
00967 }
00968
00976 public function oxMimeContentType( $sFileName )
00977 {
00978 $sFileName = strtolower( $sFileName );
00979 $iLastDot = strrpos( $sFileName, '.' );
00980
00981 if ( $iLastDot !== false ) {
00982 $sType = substr( $sFileName, $iLastDot + 1 );
00983 switch ( $sType ) {
00984 case 'gif':
00985 $sType = 'image/gif';
00986 break;
00987 case 'jpeg':
00988 case 'jpg':
00989 $sType = 'image/jpeg';
00990 break;
00991 case 'png':
00992 $sType = 'image/png';
00993 break;
00994 default:
00995 $sType = false;
00996 break;
00997 }
00998 }
00999 return $sType;
01000 }
01001
01010 public function logger( $sText, $blNewline = false )
01011 { $myConfig = $this->getConfig();
01012
01013 if ( $myConfig->getConfigParam( 'iDebug' ) == -2) {
01014 if ( gettype( $sText ) != 'string' ) {
01015 $sText = var_export( $sText, true);
01016 }
01017 $sLogMsg = "----------------------------------------------\n{$sText}".( ( $blNewline ) ?"\n":"" )."\n";
01018 $this->writeToLog( $sLogMsg, "log.txt" );
01019 }
01020
01021 }
01022
01030 protected function _stripQuotes($mInput)
01031 {
01032 return is_array($mInput) ? array_map( array( $this, '_stripQuotes' ), $mInput) : stripslashes( $mInput );
01033 }
01034
01042 public function strRot13( $sStr )
01043 {
01044 $sFrom = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
01045 $sTo = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
01046
01047 return strtr( $sStr, $sFrom, $sTo );
01048 }
01049
01050
01060 public function prepareUrlForNoSession($sUrl)
01061 {
01062 if ( $this->seoIsActive() ) {
01063 return $sUrl;
01064 }
01065
01066 $sUrl = preg_replace('/(force_)?sid=[a-z0-9\._]*&?(amp;)?/i', '', $sUrl);
01067
01068 $oStr = getStr();
01069 if ($qpos = $oStr->strpos($sUrl, '?')) {
01070 if ($qpos == $oStr->strlen($sUrl)-1) {
01071 $sSep = '';
01072 } else {
01073 $sSep = '&';
01074 }
01075 } else {
01076 $sSep = '?';
01077 }
01078
01079 if (!preg_match('/[&?](amp;)?lang=[0-9]+/i', $sUrl)) {
01080 $sUrl .= "{$sSep}lang=".oxLang::getInstance()->getBaseLanguage();
01081 $sSep = '&';
01082 }
01083
01084 if (!preg_match('/[&?](amp;)?cur=[0-9]+/i', $sUrl)) {
01085 $iCur = (int) oxConfig::getParameter('currency');
01086 if ($iCur) {
01087 $sUrl .= "{$sSep}cur=".$iCur;
01088 $sSep = '&';
01089 }
01090 }
01091
01092 return $sUrl;
01093 }
01094
01103 protected function _getCacheFilePath( $sCacheName, $blPathOnly = false )
01104 {
01105 $sVersionPrefix = "";
01106
01107
01108 $sVersionPrefix = 'pe';
01109
01110 $sPath = realpath($this->getConfig()->getConfigParam( 'sCompileDir' ));
01111 return $blPathOnly ? "{$sPath}/" : "{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}.txt";
01112 }
01113
01121 public function getLangCache( $sCacheName )
01122 {
01123 $aLangCache = null;
01124 $sFilePath = $this->_getCacheFilePath( $sCacheName );
01125 if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
01126 include $sFilePath;
01127 }
01128 return $aLangCache;
01129 }
01130
01139 public function setLangCache( $sCacheName, $aLangCache )
01140 {
01141 $sCache = "<?php\n\$aLangCache = ".var_export( $aLangCache, true ).";";
01142 $blRes = file_put_contents($this->_getCacheFilePath($sCacheName), $sCache);
01143 return $blRes;
01144 }
01145
01153 public function checkUrlEndingSlash( $sUrl )
01154 {
01155 if ( !preg_match("/\/$/", $sUrl) ) {
01156 $sUrl .= '/';
01157 }
01158
01159 return $sUrl;
01160 }
01161
01170 public function writeToLog( $sLogMessage, $sLogFileName )
01171 {
01172 $sLogDist = $this->getConfig()->getLogsDir().$sLogFileName;
01173 $blOk = false;
01174
01175 if ( ( $oHandle = fopen( $sLogDist, 'a' ) ) !== false ) {
01176 fwrite( $oHandle, $sLogMessage );
01177 $blOk = fclose( $oHandle );
01178 }
01179
01180 return $blOk;
01181 }
01182 }