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 self::$_instance = modInstances::getMod( __CLASS__ );
00061 }
00062
00063 if ( !(self::$_instance instanceof oxUtils) ) {
00064
00065 self::$_instance = oxNew( 'oxUtils' );
00066
00067 if ( defined( 'OXID_PHP_UNIT' ) ) {
00068 modInstances::addMod( __CLASS__, self::$_instance);
00069 }
00070 }
00071 return self::$_instance;
00072 }
00073
00079 protected $_aStaticCache;
00080
00086 protected $_blSeoIsActive = null;
00087
00093 public function stripGpcMagicQuotes()
00094 {
00095 if (!get_magic_quotes_gpc()) {
00096 return;
00097 }
00098 $_REQUEST = self::_stripQuotes($_REQUEST);
00099 $_POST = self::_stripQuotes($_POST);
00100 $_GET = self::_stripQuotes($_GET);
00101 $_COOKIE = self::_stripQuotes($_COOKIE);
00102 }
00103
00112 public function strMan( $sVal, $sKey = null )
00113 {
00114 $sKey = $sKey?$sKey:'oxid123456789';
00115 $sVal = "ox{$sVal}id";
00116
00117 $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00118 $sVal = $this->strRot13( $sVal );
00119 $sVal = $sVal ^ $sKey;
00120 $sVal = base64_encode( $sVal );
00121 $sVal = str_replace( "=", "!", $sVal );
00122
00123 return "ox_$sVal";
00124 }
00125
00134 public function strRem( $sVal, $sKey = null )
00135 {
00136 $sKey = $sKey?$sKey:'oxid123456789';
00137 $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00138
00139 $sVal = substr( $sVal, 3 );
00140 $sVal = str_replace( '!', '=', $sVal );
00141 $sVal = base64_decode( $sVal );
00142 $sVal = $sVal ^ $sKey;
00143 $sVal = $this->strRot13( $sVal );
00144
00145 return substr( $sVal, 2, -2 );
00146 }
00147
00155 public function getArrFldName( $sName)
00156 {
00157 return str_replace( ".", "__", $sName);
00158 }
00159
00168 public function assignValuesFromText( $sIn, $dVat = null)
00169 {
00170 $aRet = array();
00171 $aPieces = explode( '@@', $sIn );
00172 while ( list( $sKey, $sVal ) = each( $aPieces ) ) {
00173 if ( $sVal ) {
00174 $aName = explode( '__', $sVal );
00175 if ( isset( $aName[0] ) && isset( $aName[1] ) ) {
00176 $aRet[] = $this->_fillExplodeArray( $aName, $dVat );
00177 }
00178 }
00179 }
00180 return $aRet;
00181 }
00182
00190 public function assignValuesToText( $aIn)
00191 {
00192 $sRet = "";
00193 reset( $aIn );
00194 while (list($sKey, $sVal) = each($aIn)) {
00195 $sRet .= $sKey;
00196 $sRet .= "__";
00197 $sRet .= $sVal;
00198 $sRet .= "@@";
00199 }
00200 return $sRet;
00201 }
00202
00213 public function formatCurrency( $dValue, $oActCur = null )
00214 {
00215 if (!$oActCur) {
00216 $oActCur = $this->getConfig()->getActShopCurrencyObject();
00217 }
00218 $sFormated = number_format( $dValue, $oActCur->decimal, $oActCur->dec, $oActCur->thousand);
00219
00220 return $sFormated;
00221 }
00222
00230 public function currency2Float( $sValue)
00231 {
00232 $fRet = $sValue;
00233 $iPos = strrpos( $sValue, ".");
00234 if ($iPos && ((strlen($sValue)-1-$iPos) < 2+1)) {
00235
00236 $fRet = substr_replace( $fRet, ",", $iPos, 1);
00237 }
00238
00239 $fRet = str_replace( array(" ","."), "", $fRet);
00240
00241 $fRet = str_replace( ",", ".", $fRet);
00242 return (float) $fRet;
00243 }
00244
00252 public function isSearchEngine( $sClient = null )
00253 {
00254 $myConfig = $this->getConfig();
00255 $blIsSe = false;
00256
00257 if ( !( $myConfig->getConfigParam( 'iDebug' ) && $this->isAdmin() ) ) {
00258
00259
00260 $blIsSe = $myConfig->getGlobalParameter( 'blIsSearchEngine' );
00261 if ( !isset( $blIsSe ) ) {
00262
00263 $aRobots = $myConfig->getConfigParam( 'aRobots' );
00264 $aRobots = is_array( $aRobots )?$aRobots:array();
00265
00266 $aRobotsExcept = $myConfig->getConfigParam( 'aRobotsExcept' );
00267 $aRobotsExcept = is_array( $aRobotsExcept )?$aRobotsExcept:array();
00268
00269 $sClient = $sClient?$sClient:strtolower( getenv( 'HTTP_USER_AGENT' ) );
00270 $blIsSe = false;
00271 $aRobots = array_merge( $aRobots, $aRobotsExcept );
00272 foreach ( $aRobots as $sRobot ) {
00273 if ( strpos( $sClient, $sRobot ) !== false ) {
00274 $blIsSe = true;
00275 break;
00276 }
00277 }
00278 $myConfig->setGlobalParameter( 'blIsSearchEngine', $blIsSe );
00279 }
00280 }
00281
00282 return $blIsSe;
00283 }
00284
00293 public function isValidEmail( $sEmail )
00294 {
00295 $blValid = true;
00296 if ( $sEmail != 'admin' ) {
00297 $blValid = ( preg_match( $this->_sEmailTpl, $sEmail ) != 0 );
00298 }
00299
00300 return $blValid;
00301 }
00302
00308 public function rebuildCache()
00309 {
00310
00311
00312
00313
00314
00315 if ( function_exists( "UserdefinedRebuildCache")) {
00316 UserdefinedRebuildCache();
00317 }
00318 }
00319
00327 public function loadAdminProfile($aInterfaceProfiles)
00328 {
00329
00330
00331 $aInterfaceProfiles = $aInterfaceProfiles;
00332 if ( is_array( $aInterfaceProfiles ) ) {
00333
00334 $sPrevProfile = oxUtilsServer::getInstance()->getOxCookie('oxidadminprofile');
00335 if (isset($sPrevProfile)) {
00336 $aPrevProfile = @explode("@", trim($sPrevProfile));
00337 }
00338
00339
00340 $aProfiles = array();
00341 foreach ( $aInterfaceProfiles as $iPos => $sProfile) {
00342 $aProfileSettings = array($iPos, $sProfile);
00343 $aProfiles[] = $aProfileSettings;
00344 }
00345
00346 if (isset($aPrevProfile[0]) && isset($aProfiles[$aPrevProfile[0]])) {
00347 $aProfiles[$aPrevProfile[0]][2] = 1;
00348 }
00349
00350 oxSession::setVar("aAdminProfiles", $aProfiles);
00351 return $aProfiles;
00352 }
00353 return null;
00354 }
00355
00364 public function fRound($sVal, $oCur = null)
00365 {
00366 startProfile('fround');
00367
00368
00369 $iCurPrecision = null;
00370 if (! defined('OXID_PHP_UNIT')) {
00371 $iCurPrecision = $this->_iCurPrecision;
00372 }
00373
00374 if (is_null($iCurPrecision)) {
00375 if ( !$oCur ) {
00376 $oCur = $this->getConfig()->getActShopCurrencyObject();
00377 }
00378
00379 $iCurPrecision = $oCur->decimal;
00380 $this->_iCurPrecision = $iCurPrecision;
00381 }
00382
00383
00384 static $dprez = null;
00385 if (!$dprez) {
00386 $prez = @ini_get("precision");
00387 if (!$prez) {
00388 $prez = 9;
00389 }
00390 $dprez = pow(10, -$prez);
00391 }
00392
00393
00394 stopProfile('fround');
00395
00396 return round($sVal + $dprez, $iCurPrecision);
00397 }
00398
00408 public function toStaticCache( $sName, $sContent, $sKey = null )
00409 {
00410
00411 if ( $sKey ) {
00412 $this->_aStaticCache[$sName][$sKey] = $sContent;
00413 } else {
00414 $this->_aStaticCache[$sName] = $sContent;
00415 }
00416 }
00417
00425 public function fromStaticCache( $sName)
00426 {
00427 if ( isset( $this->_aStaticCache[$sName])) {
00428 return $this->_aStaticCache[$sName];
00429 }
00430 return null;
00431 }
00432
00440 public function cleanStaticCache($sCacheName = null)
00441 {
00442 if ($sCacheName) {
00443 unset($this->_aStaticCache[$sCacheName]);
00444 } else {
00445 $this->_aStaticCache = null;
00446 }
00447 }
00448
00449
00459 public function toFileCache($sKey, $mContents)
00460 {
00461 $sFilePath = $this->getCacheFilePath( $sKey );
00462 $iCurTime = oxUtilsDate::getInstance()->getTime();
00463
00464
00465
00466
00467
00468 clearstatcache();
00469 if (!isset($this->_aFileCacheContents[$sKey]) && file_exists($sFilePath) && (!filesize($sFilePath)) && abs($iCurTime - filectime($sFilePath) < 40) ) {
00470
00471 return false;
00472 }
00473
00474
00475 if (!isset($this->_aFileCacheContents[$sKey])) {
00476
00477 $hFile = fopen($sFilePath, "w");
00478 if ($hFile) {
00479 fclose($hFile);
00480 }
00481 clearstatcache();
00482 }
00483
00484 $this->_aFileCacheContents[$sKey] = $mContents;
00485
00486 return true;
00487 }
00488
00498 public function toPhpFileCache($sKey, $mContents)
00499 {
00500 $sFilePath = $this->getCacheFilePath( $sKey, false, 'php' );
00501 $sDate = date("Y-m-d H:i:s");
00502 $sVarName = '$_aCacheContents';
00503
00504
00505 if (!is_array($mContents))
00506 return;
00507
00508 $sContents = "<?php ?>";
00509 if (is_array($mContents)) {
00510 $sContents = "<?php\n//automatically generated file\n//$sDate\n\n$sVarName = array (\n";
00511 foreach ($mContents as $sKey => $mVal) {
00512 if (!is_numeric($mVal)) {
00513 $mVal = "'$mVal'";
00514 }
00515 if (!is_numeric($sKey)) {
00516 $sKey = "'$sKey'";
00517 }
00518 $sContents .= " $sKey => $mVal,\n";
00519 }
00520 $sContents .= ");\n?>";
00521 }
00522
00523 $hFile = fopen( $sFilePath, "w");
00524 if ( $hFile) {
00525 fwrite( $hFile, $sContents);
00526 fclose( $hFile);
00527 }
00528
00529 }
00530
00538 public function fromPhpFileCache($sKey)
00539 {
00540 $sFilePath = $this->getCacheFilePath( $sKey, false, 'php' );
00541
00542 if (file_exists($sFilePath)) {
00543 include $sFilePath;
00544 return $_aCacheContents;
00545 }
00546
00547 return null;
00548 }
00549
00557 public function fromFileCache( $sKey )
00558 {
00559 if ( !isset( $this->_aFileCacheContents[$sKey] ) ) {
00560 $sRes = null;
00561
00562
00563 $sFilePath = $this->getCacheFilePath( $sKey );
00564 if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
00565
00566 $sRes = file_get_contents( $sFilePath );
00567 $sRes = $sRes ? unserialize( $sRes ) : null;
00568 }
00569
00570 $this->_aFileCacheContents[$sKey] = $sRes;
00571 }
00572
00573 return $this->_aFileCacheContents[$sKey];
00574 }
00575
00581 public function commitFileCache()
00582 {
00583 foreach ($this->_aFileCacheContents as $sKey => $mContents) {
00584 $mContents = serialize($mContents);
00585 $sFilePath = $this->getCacheFilePath( $sKey );
00586
00587
00588 $hFile = fopen( $sFilePath, "w");
00589 if ( $hFile) {
00590 fwrite( $hFile, $mContents);
00591 fclose( $hFile);
00592 }
00593 }
00594
00595
00596 $this->_aFileCacheContents = array();
00597 clearstatcache ();
00598 }
00599
00607 public function oxResetFileCache()
00608 {
00609 $aPathes = glob( $this->getCacheFilePath( null, true ) . '*' );
00610 if ( is_array( $aPathes ) ) {
00611
00612 $aPathes = preg_grep( $this->_sPermanentCachePattern, $aPathes, PREG_GREP_INVERT );
00613 foreach ( $aPathes as $sFilename ) {
00614 @unlink( $sFilename );
00615 }
00616 }
00617 }
00618
00628 public function getRemoteCachePath($sRemote, $sLocal)
00629 {
00630 clearstatcache();
00631 if ( file_exists( $sLocal ) && filemtime( $sLocal ) && filemtime( $sLocal ) > time() - 86400 ) {
00632 return $sLocal;
00633 }
00634 $hRemote = @fopen( $sRemote, "rb");
00635 $blSuccess = false;
00636 if ( isset( $hRemote) && $hRemote ) {
00637 $hLocal = fopen( $sLocal, "wb");
00638 stream_copy_to_stream($hRemote, $hLocal);
00639 fclose($hRemote);
00640 fclose($hLocal);
00641 $blSuccess = true;
00642 } else {
00643
00644 $aUrl = @parse_url( $sRemote);
00645 if ( !empty( $aUrl["host"])) {
00646 $sPath = $aUrl["path"];
00647 if ( empty( $sPath ) ) {
00648 $sPath = "/";
00649 }
00650 $sHost = $aUrl["host"];
00651
00652 $hSocket = @fsockopen( $sHost, 80, $iErrorNumber, $iErrStr, 5);
00653 if ( $hSocket) {
00654 fputs( $hSocket, "GET ".$sPath." HTTP/1.0\r\nHost: $sHost\r\n\r\n");
00655 $headers = stream_get_line($hSocket, 4096, "\r\n\r\n");
00656 if ( ( $hLocal = @fopen( $sLocal, "wb") ) !== false ) {
00657 rewind($hLocal);
00658
00659
00660 fwrite ( $hLocal, stream_get_contents( $hSocket ) );
00661 fclose( $hLocal );
00662 fclose( $hSocket );
00663 $blSuccess = true;
00664 }
00665 }
00666 }
00667 }
00668 if ( $blSuccess || file_exists( $sLocal ) ) {
00669 return $sLocal;
00670 }
00671 return false;
00672 }
00673
00679 public function checkAccessRights()
00680 {
00681 $myConfig = $this->getConfig();
00682
00683 $blIsAuth = false;
00684
00685 $sUserID = oxSession::getVar( "auth");
00686
00687
00688 oxSession::setVar( "malladmin", 0);
00689 oxSession::setVar( "blIsAdmin", 0);
00690 oxSession::deleteVar( "blIsAdmin" );
00691 $myConfig->setConfigParam( 'blMallAdmin', false );
00692
00693 $myConfig->setConfigParam( 'blAllowInheritedEdit', false );
00694
00695 if ( $sUserID) {
00696
00697 $oDb = oxDb::getDb();
00698 $sRights = $oDb->getOne("select oxrights from oxuser where oxid = ".$oDb->quote($sUserID));
00699
00700 if ( $sRights != "user") {
00701
00702 if ( $sRights == "malladmin") {
00703 oxSession::setVar( "malladmin", 1);
00704 $myConfig->setConfigParam( 'blMallAdmin', true );
00705
00706
00707
00708 $myConfig->setConfigParam( 'blAllowSharedEdit', true );
00709
00710 $sShop = oxSession::getVar( "actshop");
00711 if ( !isset($sShop)) {
00712 oxSession::setVar( "actshop", $myConfig->getBaseShopId());
00713 }
00714 $blIsAuth = true;
00715 } else {
00716
00717 $sShopID = $oDb->getOne("select oxid from oxshops where oxid = " . $oDb->quote( $sRights ) );
00718 if ( isset( $sShopID) && $sShopID) {
00719
00720
00721 oxSession::setVar( "actshop", $sRights);
00722 oxSession::setVar( "currentadminshop", $sRights);
00723 oxSession::setVar( "shp", $sRights);
00724
00725
00726 if ('chshp' == oxConfig::getParameter( 'fnc' )) {
00727
00728 $blIsAuth = false;
00729 } else {
00730 $blIsAuth = true;
00731
00732 $aShopIdVars = array('actshop', 'shp', 'currentadminshop');
00733 foreach ($aShopIdVars as $sShopIdVar) {
00734 if ($sGotShop = oxConfig::getParameter( $sShopIdVar )) {
00735 if ($sGotShop != $sRights) {
00736 $blIsAuth = false;
00737 break;
00738 }
00739 }
00740 }
00741 }
00742 }
00743 }
00744
00745 oxSession::setVar( "blIsAdmin", 1);
00746 }
00747 }
00748 return $blIsAuth;
00749 }
00750
00760 public function seoIsActive( $blReset = false, $sShopId = null, $iActLang = null )
00761 {
00762 if ( !is_null( $this->_blSeoIsActive ) && !$blReset ) {
00763 return $this->_blSeoIsActive;
00764 }
00765
00766 $myConfig = $this->getConfig();
00767
00768 if ( ( $this->_blSeoIsActive = $myConfig->getConfigParam( 'blSeoMode' ) ) === null ) {
00769 $this->_blSeoIsActive = true;
00770
00771 $aSeoModes = $myConfig->getconfigParam( 'aSeoModes' );
00772 $sActShopId = $sShopId ? $sShopId : $myConfig->getActiveShop()->getId();
00773 $iActLang = $iActLang ? $iActLang : (int) oxLang::getInstance()->getBaseLanguage();
00774
00775
00776 if ( is_array( $aSeoModes ) && isset( $aSeoModes[$sActShopId] ) && isset( $aSeoModes[$sActShopId][$iActLang] ) ) {
00777 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
00778 }
00779 }
00780
00781 return $this->_blSeoIsActive;
00782 }
00783
00793 public function getShopBit( $iShopId )
00794 {
00795 $iShopId = (int) $iShopId;
00796
00797 $iRes = oxDb::getDb()->getOne( "select 1 << ( $iShopId - 1 ) as shopbit" );
00798
00799
00800 return $iRes;
00801 }
00802
00812 public function bitwiseAnd( $iVal1, $iVal2 )
00813 {
00814
00815 $iRes = oxDb::getDb()->getOne( "select ($iVal1 & $iVal2) as bitwiseAnd" );
00816
00817
00818 return $iRes;
00819 }
00820
00830 public function bitwiseOr( $iVal1, $iVal2 )
00831 {
00832
00833 $iRes = oxDb::getDb()->getOne( "select ($iVal1 | $iVal2) as bitwiseOr" );
00834
00835
00836 return $iRes;
00837 }
00838
00846 public function isValidAlpha( $sField )
00847 {
00848 return (boolean) preg_match( "#^[\w]*$#", $sField );
00849 }
00850
00860 protected function _simpleRedirect( $sUrl, $sHeaderCode )
00861 {
00862 header( $sHeaderCode );
00863 header( "Location: $sUrl" );
00864 header( "Connection: close" );
00865 }
00866
00876 public function redirect( $sUrl, $blAddRedirectParam = true, $iHeaderCode = 301 )
00877 {
00878
00879
00880 if ( $blAddRedirectParam && oxConfig::getParameter( 'redirected' ) ) {
00881 return;
00882 }
00883
00884 if ( $blAddRedirectParam ) {
00885 $sUrl = $this->_addUrlParameters( $sUrl, array( 'redirected' => 1 ) );
00886 }
00887
00888 $sUrl = str_ireplace( "&", "&", $sUrl );
00889
00890 $sHeaderCode = '';
00891 switch ($iHeaderCode) {
00892 case 301:
00893 $sHeaderCode = "HTTP/1.1 301 Moved Permanently";
00894 break;
00895 case 302:
00896 default:
00897 $sHeaderCode = "HTTP/1.1 302 Found";
00898 }
00899
00900 $this->_simpleRedirect( $sUrl, $sHeaderCode );
00901
00902 try {
00903 $this->getSession()->freeze();
00904 } catch( oxException $oEx ) {
00905 $oEx->debugOut();
00906
00907 }
00908
00909 if ( defined( 'OXID_PHP_UNIT' ) ) {
00910 return;
00911 }
00912
00913 $this->showMessageAndExit( '' );
00914 }
00915
00923 public function showMessageAndExit( $sMsg )
00924 {
00925 $this->getSession()->freeze();
00926 $this->commitFileCache();
00927
00928 if ( defined( 'OXID_PHP_UNIT' ) ) {
00929 return;
00930 }
00931
00932 exit( $sMsg );
00933 }
00934
00942 public function setHeader($sHeader)
00943 {
00944 header($sHeader);
00945 }
00946
00955 protected function _addUrlParameters( $sUrl, $aParams )
00956 {
00957 $sDelim = ( ( getStr()->strpos( $sUrl, '?' ) !== false ) )?'&':'?';
00958 foreach ( $aParams as $sName => $sVal ) {
00959 $sUrl = $sUrl . $sDelim . $sName . '=' . $sVal;
00960 $sDelim = '&';
00961 }
00962
00963 return $sUrl;
00964 }
00965
00977 protected function _fillExplodeArray( $aName, $dVat = null)
00978 {
00979 $myConfig = $this->getConfig();
00980 $oObject = new OxstdClass();
00981 $aPrice = explode( '!P!', $aName[0]);
00982
00983 if ( ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) && isset( $aPrice[0] ) && isset( $aPrice[1] ) ) || $this->isAdmin() ) {
00984
00985
00986 $oObject->price = $aPrice[1];
00987 $aName[0] = $aPrice[0];
00988
00989 $iPercPos = getStr()->strpos( $oObject->price, '%' );
00990 if ( $iPercPos !== false ) {
00991 $oObject->priceUnit = '%';
00992 $oObject->fprice = $oObject->price;
00993 $oObject->price = substr( $oObject->price, 0, $iPercPos );
00994 } else {
00995 $oCur = $myConfig->getActShopCurrencyObject();
00996 $oObject->price = str_replace(',', '.', $oObject->price);
00997 $oObject->fprice = oxLang::getInstance()->formatCurrency( $oObject->price * $oCur->rate, $oCur);
00998 $oObject->priceUnit = 'abs';
00999 }
01000
01001
01002 if ( !$this->isAdmin() && $oObject->price != 0 ) {
01003 $aName[0] .= " ";
01004 if ( $oObject->price > 0 ) {
01005 $aName[0] .= "+";
01006 }
01007
01008 if ( $dVat != null && $oObject->priceUnit == 'abs' ) {
01009 $oPrice = oxNew('oxPrice');
01010 $oPrice->setPrice($oObject->price, $dVat);
01011 $aName[0] .= oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() * $oCur->rate, $oCur);
01012 } else {
01013 $aName[0] .= $oObject->fprice;
01014 }
01015 if ( $oObject->priceUnit == 'abs' ) {
01016 $aName[0] .= " ".$oCur->sign;
01017 }
01018 }
01019 } elseif ( isset( $aPrice[0] ) && isset($aPrice[1] ) ) {
01020
01021 $aName[0] = preg_replace( "/!P!.*/", "", $aName[0] );
01022 }
01023
01024 $oObject->name = $aName[0];
01025 $oObject->value = $aName[1];
01026 return $oObject;
01027 }
01028
01036 public function oxMimeContentType( $sFileName )
01037 {
01038 $sFileName = strtolower( $sFileName );
01039 $iLastDot = strrpos( $sFileName, '.' );
01040
01041 if ( $iLastDot !== false ) {
01042 $sType = substr( $sFileName, $iLastDot + 1 );
01043 switch ( $sType ) {
01044 case 'gif':
01045 $sType = 'image/gif';
01046 break;
01047 case 'jpeg':
01048 case 'jpg':
01049 $sType = 'image/jpeg';
01050 break;
01051 case 'png':
01052 $sType = 'image/png';
01053 break;
01054 default:
01055 $sType = false;
01056 break;
01057 }
01058 }
01059 return $sType;
01060 }
01061
01070 public function logger( $sText, $blNewline = false )
01071 { $myConfig = $this->getConfig();
01072
01073 if ( $myConfig->getConfigParam( 'iDebug' ) == -2) {
01074 if ( gettype( $sText ) != 'string' ) {
01075 $sText = var_export( $sText, true);
01076 }
01077 $sLogMsg = "----------------------------------------------\n{$sText}".( ( $blNewline ) ?"\n":"" )."\n";
01078 $this->writeToLog( $sLogMsg, "log.txt" );
01079 }
01080
01081 }
01082
01090 protected function _stripQuotes($mInput)
01091 {
01092 return is_array($mInput) ? array_map( array( $this, '_stripQuotes' ), $mInput) : stripslashes( $mInput );
01093 }
01094
01102 public function strRot13( $sStr )
01103 {
01104 $sFrom = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
01105 $sTo = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
01106
01107 return strtr( $sStr, $sFrom, $sTo );
01108 }
01109
01110
01121 public function prepareUrlForNoSession( $sUrl )
01122 {
01123 if ( $this->seoIsActive() ) {
01124 return $sUrl;
01125 }
01126
01127 return oxUtilsUrl::getInstance()->prepareUrlForNoSession( $sUrl );
01128 }
01129
01140 protected function _getCacheFilePath( $sCacheName, $blPathOnly = false )
01141 {
01142 return $this->getCacheFilePath( $sCacheName, $blPathOnly );
01143 }
01144
01154 public function getCacheFilePath( $sCacheName, $blPathOnly = false, $sExtension = 'txt' )
01155 {
01156 $sVersionPrefix = "";
01157
01158
01159 $sVersionPrefix = 'pe';
01160
01161 $sPath = realpath($this->getConfig()->getConfigParam( 'sCompileDir' ));
01162 return $blPathOnly ? "{$sPath}/" : "{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}." . $sExtension;
01163 }
01164
01172 public function getLangCache( $sCacheName )
01173 {
01174 $aLangCache = null;
01175 $sFilePath = $this->getCacheFilePath( $sCacheName );
01176 if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
01177 include $sFilePath;
01178 }
01179 return $aLangCache;
01180 }
01181
01190 public function setLangCache( $sCacheName, $aLangCache )
01191 {
01192 $sCache = "<?php\n\$aLangCache = ".var_export( $aLangCache, true ).";";
01193 $blRes = file_put_contents($this->getCacheFilePath($sCacheName), $sCache);
01194 return $blRes;
01195 }
01196
01204 public function checkUrlEndingSlash( $sUrl )
01205 {
01206 if ( !preg_match("/\/$/", $sUrl) ) {
01207 $sUrl .= '/';
01208 }
01209
01210 return $sUrl;
01211 }
01212
01221 public function writeToLog( $sLogMessage, $sLogFileName )
01222 {
01223 $sLogDist = $this->getConfig()->getLogsDir().$sLogFileName;
01224 $blOk = false;
01225
01226 if ( ( $oHandle = fopen( $sLogDist, 'a' ) ) !== false ) {
01227 fwrite( $oHandle, $sLogMessage );
01228 $blOk = fclose( $oHandle );
01229 }
01230
01231 return $blOk;
01232 }
01233
01241 public function handlePageNotFoundError($sUrl = '')
01242 {
01243 $this->setHeader("HTTP/1.0 404 Not Found");
01244 $sReturn = "Page not found.";
01245 try {
01246 $oView = oxNew('oxubase');
01247 $oView->init();
01248 $oView->render();
01249 $oView->addTplParam('sUrl', $sUrl);
01250 if ($sRet = oxUtilsView::getInstance()->getTemplateOutput('err_404.tpl', $oView)) {
01251 $sReturn = $sRet;
01252 }
01253 } catch (Exception $e) {
01254 }
01255 $this->showMessageAndExit( $sReturn );
01256 }
01257 }