oxutils.php

Go to the documentation of this file.
00001 <?php
00002 
00006 require_once getShopBasePath()."core/smarty/Smarty.class.php";
00007 
00012 class oxUtils extends oxSuperCfg
00013 {
00014 
00020     private static $_instance = null;
00021 
00027     protected $_iCurPrecision = null;
00028 
00034     protected $_sEmailTpl = "^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~\177])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~\177]+\\.)+[a-zA-Z]{2,6}\$";
00035 
00043     protected $_sPermanentCachePattern = "/c_fieldnames_/";
00044 
00050     public static function getInstance()
00051     {
00052         // disable caching for test modules
00053         if ( defined( 'OXID_PHP_UNIT' ) ) {
00054             static $inst = array();
00055             self::$_instance = $inst[oxClassCacheKey()];
00056 
00057         }
00058 
00059         if ( !self::$_instance instanceof oxUtils ) {
00060 
00061 
00062             self::$_instance = oxNew( 'oxUtils' );
00063 
00064             if ( defined( 'OXID_PHP_UNIT' ) ) {
00065                 $inst[oxClassCacheKey()] = self::$_instance;
00066             }
00067         }
00068         return self::$_instance;
00069     }
00070 
00076     protected $_aStaticCache;
00077 
00083     protected $_blSeoIsActive = null;
00084 
00090     public function stripGpcMagicQuotes()
00091     {
00092         if (!get_magic_quotes_gpc()) {
00093             return;
00094         }
00095         $_REQUEST = self::_stripQuotes($_REQUEST);
00096         $_POST = self::_stripQuotes($_POST);
00097         $_GET = self::_stripQuotes($_GET);
00098         $_COOKIE = self::_stripQuotes($_COOKIE);
00099     }
00100 
00109     public function strMan( $sVal, $sKey = null )
00110     {
00111         $sKey = $sKey?$sKey:'oxid123456789';
00112         $sVal = "ox{$sVal}id";
00113 
00114         $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00115         $sVal = $this->strRot13( $sVal );
00116         $sVal = $sVal ^ $sKey;
00117         $sVal = base64_encode( $sVal );
00118         $sVal = str_replace( "=", "!", $sVal );
00119 
00120         return "ox_$sVal";
00121     }
00122 
00131     public function strRem( $sVal, $sKey = null )
00132     {
00133         $sKey = $sKey?$sKey:'oxid123456789';
00134         $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00135 
00136         $sVal = substr( $sVal, 3 );
00137         $sVal = str_replace( '!', '=', $sVal );
00138         $sVal = base64_decode( $sVal );
00139         $sVal = $sVal ^ $sKey;
00140         $sVal = $this->strRot13( $sVal );
00141 
00142         return substr( $sVal, 2, -2 );
00143     }
00144 
00152     public function getArrFldName( $sName)
00153     {
00154         return str_replace( ".", "__", $sName);
00155     }
00156 
00165     public function assignValuesFromText( $sIn, $dVat = null)
00166     {
00167         $aRet = array();
00168         $aPieces = explode( '@@', $sIn );
00169         while ( list( $sKey, $sVal ) = each( $aPieces ) ) {
00170             if ( $sVal ) {
00171                 $aName = explode( '__', $sVal );
00172                 if ( isset( $aName[0] ) && isset( $aName[1] ) ) {
00173                     $aRet[] = $this->_fillExplodeArray( $aName, $dVat );
00174                 }
00175             }
00176         }
00177         return $aRet;
00178     }
00179 
00187     public function assignValuesToText( $aIn)
00188     {
00189         $sRet = "";
00190         reset( $aIn );
00191         while (list($sKey, $sVal) = each($aIn)) {
00192             $sRet .= $sKey;
00193             $sRet .= "__";
00194             $sRet .= $sVal;
00195             $sRet .= "@@";
00196         }
00197         return $sRet;
00198     }
00199 
00208     public function formatCurrency( $dValue, $oActCur = null )
00209     {
00210         if (!$oActCur) {
00211             $oActCur = $this->getConfig()->getActShopCurrencyObject();
00212         }
00213         $sFormated = number_format( $dValue, $oActCur->decimal, $oActCur->dec, $oActCur->thousand);
00214 
00215         return $sFormated;
00216     }
00217 
00225     public function currency2Float( $sValue)
00226     {
00227         $fRet = $sValue;
00228         $iPos = strrpos( $sValue, ".");
00229         if ($iPos && ((strlen($sValue)-1-$iPos) < 2+1)) {
00230             // replace decimal with ","
00231             $fRet = substr_replace( $fRet, ",", $iPos, 1);
00232         }
00233         // remove thousands
00234         $fRet = str_replace( array(" ","."), "", $fRet);
00235 
00236         $fRet = str_replace( ",", ".", $fRet);
00237         return (float) $fRet;
00238     }
00239 
00247     public function isSearchEngine( $sClient = null )
00248     {
00249         $myConfig = $this->getConfig();
00250         $blIsSe   = false;
00251 
00252         if ( !( $myConfig->getConfigParam( 'iDebug' ) && $this->isAdmin() ) ) {
00253 
00254             // caching
00255             $blIsSe = $myConfig->getGlobalParameter( 'blIsSearchEngine' );
00256             if ( !isset( $blIsSe ) ) {
00257 
00258                 $aRobots = $myConfig->getConfigParam( 'aRobots' );
00259                 $aRobots = is_array( $aRobots )?$aRobots:array();
00260 
00261                 $aRobotsExcept = $myConfig->getConfigParam( 'aRobotsExcept' );
00262                 $aRobotsExcept = is_array( $aRobotsExcept )?$aRobotsExcept:array();
00263 
00264                 $sClient = $sClient?$sClient:strtolower( getenv( 'HTTP_USER_AGENT' ) );
00265                 $blIsSe  = false;
00266                 $aRobots = array_merge( $aRobots, $aRobotsExcept );
00267                 foreach ( $aRobots as $sRobot ) {
00268                     if ( strpos( $sClient, $sRobot ) !== false ) {
00269                         $blIsSe = true;
00270                         break;
00271                     }
00272                 }
00273                 $myConfig->setGlobalParameter( 'blIsSearchEngine', $blIsSe );
00274             }
00275         }
00276 
00277         return $blIsSe;
00278     }
00279 
00288     public function isValidEmail( $sEmail )
00289     {
00290         $blValid = true;
00291         if ( $sEmail != 'admin' ) {
00292             $blValid = ( eregi( $this->_sEmailTpl, $sEmail ) != 0 );
00293         }
00294 
00295         return $blValid;
00296     }
00297 
00303     public function rebuildCache()
00304     {
00305         // not needed from 3.0 on and unused <- MK: not correct, its used for example in shop_config.php, oxbase.php
00306 
00307         //$smarty  = & oxUtils::getInstance()->getSmarty();
00308         //$smarty->clear_all_cache();
00309 
00310         if ( function_exists( "UserdefinedRebuildCache")) {
00311             UserdefinedRebuildCache();
00312         }
00313     }
00314 
00322     public function loadAdminProfile($aInterfaceProfiles)
00323     {
00324         // improved #533
00325         // checking for available profiles list
00326         $aInterfaceProfiles = $aInterfaceProfiles;
00327         if ( is_array( $aInterfaceProfiles ) ) {   //checking for previous profiles
00328             $sPrevProfile = oxUtilsServer::getInstance()->getOxCookie('oxidadminprofile');
00329             if (isset($sPrevProfile)) {
00330                 $aPrevProfile = @explode("@", trim($sPrevProfile));
00331             }
00332 
00333             //array to store profiles
00334             $aProfiles = array();
00335             foreach ( $aInterfaceProfiles as $iPos => $sProfile) {
00336                 $aProfileSettings = array($iPos, $sProfile);
00337                 $aProfiles[] = $aProfileSettings;
00338             }
00339             // setting previous used profile as active
00340             if (isset($aPrevProfile[0]) && isset($aProfiles[$aPrevProfile[0]])) {
00341                 $aProfiles[$aPrevProfile[0]][2] = 1;
00342             }
00343 
00344             oxSession::setVar("aAdminProfiles", $aProfiles);
00345             return $aProfiles;
00346         }
00347         return null;
00348     }
00349 
00358     public function fRound($sVal, $oCur = null)
00359     {
00360         startProfile('fround');
00361 
00362         //cached currency precision, this saves about 1% of execution time
00363         $iCurPrecision = null;
00364         if (! defined('OXID_PHP_UNIT')) {
00365             $iCurPrecision = $this->_iCurPrecision;
00366         }
00367 
00368         if (is_null($iCurPrecision)) {
00369             if ( !$oCur ) {
00370                 $oCur = $this->getConfig()->getActShopCurrencyObject();
00371             }
00372 
00373             $iCurPrecision = $oCur->decimal;
00374             $this->_iCurPrecision = $iCurPrecision;
00375         }
00376 
00377         // this is a workaround for #36008 bug in php - incorrect round() & number_format() result (R)
00378         static $dprez = null;
00379         if (!$dprez) {
00380             $prez = @ini_get("precision");
00381             if (!$prez) {
00382                 $prez = 9;
00383             }
00384             $dprez = pow(10, -$prez);
00385         }
00386 
00387 
00388         stopProfile('fround');
00389 
00390         return round($sVal + $dprez, $iCurPrecision);
00391     }
00392 
00402     public function toStaticCache( $sName, $sContent, $sKey = null )
00403     {
00404         // if it's an array then we add
00405         if ( $sKey ) {
00406             $this->_aStaticCache[$sName][$sKey] = $sContent;
00407         } else {
00408             $this->_aStaticCache[$sName] = $sContent;
00409         }
00410     }
00411 
00419     public function fromStaticCache( $sName)
00420     {
00421         if ( isset( $this->_aStaticCache[$sName])) {
00422             return $this->_aStaticCache[$sName];
00423         }
00424         return null;
00425     }
00426 
00434     public function cleanStaticCache($sCacheName = null)
00435     {
00436         if ($sCacheName) {
00437             unset($this->_aStaticCache[$sCacheName]);
00438         } else {
00439             $this->_aStaticCache = null;
00440         }
00441     }
00442 
00452     protected function _oxFileCache( $blMode, $sName, $sInput = null )
00453     {
00454         $sFilePath = $this->_getCacheFilePath( $sName );
00455         $sRet = null;
00456         if ( $blMode) {
00457             // write to cache
00458 
00459             //if ( is_writable($sFilePath))
00460             // dodger: somehow iswriteable always says no on windows machines
00461 
00462             $hFile = fopen( $sFilePath, "w");
00463             if ( $hFile) {
00464                 fwrite( $hFile, $sInput);
00465                 fclose( $hFile);
00466             }
00467         } else {   // read it
00468             if ( file_exists( $sFilePath) && is_readable($sFilePath)) {
00469                 // read it
00470                 $sRet = file_get_contents( $sFilePath);
00471             }
00472         }
00473         return $sRet;
00474     }
00475 
00484     public function toFileCache($sKey, $sContents)
00485     {
00486         $sStaticCacheKey = 'staticfilecache|' . $sKey;
00487         $this->toStaticCache($sStaticCacheKey, $sContents);
00488 
00489         $sContents = serialize($sContents);
00490         return $this->_oxFileCache(true, $sKey, $sContents);
00491     }
00492 
00500     public function fromFileCache( $sKey )
00501     {
00502         $sStaticCacheKey = "staticfilecache|$sKey";
00503 
00504         //using static cache for even faster fetch
00505         $sRes = $this->fromStaticCache( $sStaticCacheKey );
00506 
00507         if ( is_null( $sRes ) ) {
00508             $sRes = $this->_oxFileCache( false, $sKey );
00509             if (!is_null($sRes)) {
00510                 $sRes = unserialize( $sRes );
00511                 $this->toStaticCache( $sStaticCacheKey, $sRes );
00512             }
00513         }
00514 
00515         return $sRes;
00516     }
00517 
00525     public function oxResetFileCache()
00526     {
00527         $aPathes = glob( $this->_getCacheFilePath( null, true ) . '*' );
00528         if ( is_array( $aPathes ) ) {
00529             // delete all the files, except cached tables fieldnames
00530             $aPathes = preg_grep( $this->_sPermanentCachePattern, $aPathes, PREG_GREP_INVERT );
00531             foreach ( $aPathes as $sFilename ) {
00532                 @unlink( $sFilename );
00533             }
00534         }
00535     }
00536 
00546     public function getRemoteCachePath($sRemote, $sLocal)
00547     {
00548         clearstatcache();
00549         if ( file_exists( $sLocal ) && filemtime( $sLocal ) && filemtime( $sLocal ) > time() - 86400 ) {
00550             return $sLocal;
00551         }
00552         $hRemote = @fopen( $sRemote, "rb");
00553         $blSuccess = false;
00554         if ( isset( $hRemote) && $hRemote ) {
00555             $hLocal = fopen( $sLocal, "wb");
00556             stream_copy_to_stream($hRemote, $hLocal);
00557             fclose($hRemote);
00558             fclose($hLocal);
00559             $blSuccess = true;
00560         } else {
00561             // try via fsockopen
00562             $aUrl = @parse_url( $sRemote);
00563             if ( !empty( $aUrl["host"])) {
00564                 $sPath = $aUrl["path"];
00565                 if ( empty( $sPath ) ) {
00566                     $sPath = "/";
00567                 }
00568                 $sHost = $aUrl["host"];
00569 
00570                 $hSocket = @fsockopen( $sHost, 80, $iErrorNumber, $iErrStr, 5);
00571                 if ( $hSocket) {
00572                     fputs( $hSocket, "GET ".$sPath." HTTP/1.0\r\nHost: $sHost\r\n\r\n");
00573                     $headers = stream_get_line($hSocket, 4096, "\r\n\r\n");
00574                     $hLocal = @fopen( $sLocal, "wb");
00575                     stream_copy_to_stream($hSocket, $hLocal);
00576                     fclose( $hSocket);
00577                     fclose($hLocal);
00578                     $blSuccess = true;
00579                 }
00580             }
00581         }
00582         if ( $blSuccess || file_exists( $sLocal ) ) {
00583             return $sLocal;
00584         } else {
00585             return false;
00586         }
00587     }
00588 
00594     public function checkAccessRights()
00595     {
00596         $myConfig  = $this->getConfig();
00597 
00598         $blIsAuth = false;
00599 
00600         $sUserID = oxSession::getVar( "auth");
00601 
00602         // deleting admin marker
00603         oxSession::setVar( "malladmin", 0);
00604         oxSession::setVar( "blIsAdmin", 0);
00605         oxSession::deleteVar( "blIsAdmin" );
00606         $myConfig->setConfigParam( 'blMallAdmin', false );
00607         //#1552T
00608         $myConfig->setConfigParam( 'blAllowInheritedEdit', false );
00609 
00610         if ( $sUserID) {
00611             // escaping
00612             $oDb = oxDb::getDb();
00613             $sUserID = $oDb->quote($sUserID);
00614             $sRights = $oDb->getOne("select oxrights from oxuser where oxid = $sUserID");
00615 
00616             if ( $sRights != "user") {
00617                 // malladmin ?
00618                 if ( $sRights == "malladmin") {
00619                     oxSession::setVar( "malladmin", 1);
00620                     $myConfig->setConfigParam( 'blMallAdmin', true );
00621 
00622                     //#1552T
00623                     //So far this blAllowSharedEdit is Equal to blMallAdmin but in future to be solved over rights and roles
00624                     $myConfig->setConfigParam( 'blAllowSharedEdit', true );
00625 
00626                     $sShop = oxSession::getVar( "actshop");
00627                     if ( !isset($sShop)) {
00628                         oxSession::setVar( "actshop", $myConfig->getBaseShopId());
00629                     }
00630                     $blIsAuth = true;
00631                 } else {   // Shopadmin... check if this shop is valid and exists
00632                     $sShopID = $oDb->getOne("select oxid from oxshops where oxid = '{$sRights}'");
00633                     if ( isset( $sShopID) && $sShopID) {   // success, this shop exists
00634 
00635                         oxSession::setVar( "actshop", $sRights);
00636                         oxSession::setVar( "currentadminshop", $sRights);
00637                         oxSession::setVar( "shp", $sRights);
00638 
00639                         // check if this subshop admin is evil.
00640                         if ('chshp' == oxConfig::getParameter( 'fnc' )) {
00641                             // dont allow this call
00642                             $blIsAuth = false;
00643                         } else {
00644                             $blIsAuth = true;
00645 
00646                             $aShopIdVars = array('actshop', 'shp', 'currentadminshop');
00647                             foreach ($aShopIdVars as $sShopIdVar) {
00648                                 if ($sGotShop = oxConfig::getParameter( $sShopIdVar )) {
00649                                     if ($sGotShop != $sRights) {
00650                                         $blIsAuth = false;
00651                                         break;
00652                                     }
00653                                 }
00654                             }
00655                         }
00656                     }
00657                 }
00658                 // marking user as admin
00659                 oxSession::setVar( "blIsAdmin", 1);
00660             }
00661         }
00662         return $blIsAuth;
00663     }
00664 
00674     public function seoIsActive( $blReset = false, $sShopId = null, $iActLang = null )
00675     {
00676         if ( !is_null( $this->_blSeoIsActive ) && !$blReset ) {
00677             return $this->_blSeoIsActive;
00678         }
00679 
00680         $myConfig = $this->getConfig();
00681 
00682         if ( $this->isAdmin() ) {
00683             // allways off in admin
00684             $this->_blSeoIsActive = false;
00685         } elseif ( ( $this->_blSeoIsActive = $myConfig->getConfigParam( 'blSeoMode' ) ) === null ) {
00686             $this->_blSeoIsActive = true;
00687 
00688             $aSeoModes  = $myConfig->getconfigParam( 'aSeoModes' );
00689             $sActShopId = $sShopId ? $sShopId : $myConfig->getActiveShop()->getId();
00690             $iActLang   = $iActLang ? $iActLang : (int) oxLang::getInstance()->getBaseLanguage();
00691 
00692             // checking special config param for active shop and language
00693             if ( is_array( $aSeoModes ) && isset( $aSeoModes[$sActShopId] ) && isset( $aSeoModes[$sActShopId][$iActLang] ) ) {
00694                 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
00695             }
00696         }
00697 
00698         return $this->_blSeoIsActive;
00699     }
00700 
00710     public function getShopBit( $iShopId )
00711     {
00712         $iShopId = (int) $iShopId;
00713         //this works for large numbers when $sShopNr is up to (inclusive) 64
00714         $iRes = oxDb::getDb()->getOne( "select 1 << ( $iShopId - 1 ) as shopbit" );
00715 
00716         //as php ints supports only 32 bits, we return string.
00717         return $iRes;
00718     }
00719 
00729     public function bitwiseAnd( $iVal1, $iVal2 )
00730     {
00731         //this works for large numbers when $sShopNr is up to (inclusive) 64
00732         $iRes = oxDb::getDb()->getOne( "select ($iVal1 & $iVal2) as bitwiseAnd" );
00733 
00734         //as php ints supports only 32 bits, we return string.
00735         return $iRes;
00736     }
00737 
00747     public function bitwiseOr( $iVal1, $iVal2 )
00748     {
00749         //this works for large numbers when $sShopNr is up to (inclusive) 64
00750         $iRes = oxDb::getDb()->getOne( "select ($iVal1 | $iVal2) as bitwiseOr" );
00751 
00752         //as php ints supports only 32 bits, we return string.
00753         return $iRes;
00754     }
00755 
00763     public function isValidAlpha( $sField )
00764     {
00765         return (boolean) preg_match( "#^[\w]*$#", $sField );
00766     }
00767 
00777     protected function _simpleRedirect( $sUrl, $sHeaderCode )
00778     {
00779         header( $sHeaderCode );
00780         header( "Location: $sUrl" );
00781         header( "Connection: close" );
00782     }
00783 
00792     public function redirect( $sUrl, $blAddRedirectParam = true )
00793     {
00794         //preventing possible cyclic redirection
00795         //#M341 and check only if redirect paramater must be added
00796         if ( $blAddRedirectParam && oxConfig::getParameter( 'redirected' ) ) {
00797             return;
00798         }
00799 
00800         if ( $blAddRedirectParam ) {
00801             $sUrl = $this->_addUrlParameters( $sUrl, array( 'redirected' => 1 ) );
00802         }
00803 
00804         $sUrl = str_ireplace( "&amp;", "&", $sUrl );
00805         $this->_simpleRedirect( $sUrl, "HTTP/1.1 301 Moved Permanently" );
00806 
00807         try {//may occur in case db is lost
00808             $this->getSession()->freeze();
00809         } catch( oxException $oEx ) {
00810             $oEx->debugOut();
00811             //do nothing else to make sure the redirect takes place
00812         }
00813 
00814         if ( defined( 'OXID_PHP_UNIT' ) ) {
00815             return;
00816         }
00817 
00818         $this->showMessageAndExit( '' );
00819     }
00820 
00828     public function showMessageAndExit( $sMsg )
00829     {
00830         $this->getSession()->freeze();
00831 
00832         if ( defined( 'OXID_PHP_UNIT' ) ) {
00833             return;
00834         }
00835 
00836         die( $sMsg );
00837     }
00838 
00847     protected function _addUrlParameters( $sUrl, $aParams )
00848     {
00849         $sDelim = ( ( getStr()->strpos( $sUrl, '?' ) !== false ) )?'&':'?';
00850         foreach ( $aParams as $sName => $sVal ) {
00851             $sUrl = $sUrl . $sDelim . $sName . '=' . $sVal;
00852             $sDelim = '&';
00853         }
00854 
00855         return $sUrl;
00856     }
00857 
00869     protected function _fillExplodeArray( $aName, $dVat = null)
00870     {
00871         $myConfig = $this->getConfig();
00872         $oObject = new OxstdClass();
00873         $aPrice = explode( '!P!', $aName[0]);
00874 
00875         if ( ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) && isset( $aPrice[0] ) && isset( $aPrice[1] ) ) || $this->isAdmin() ) {
00876 
00877             // yes, price is there
00878             $oObject->price = $aPrice[1];
00879             $aName[0] = $aPrice[0];
00880 
00881             $iPercPos = getStr()->strpos( $oObject->price, '%' );
00882             if ( $iPercPos !== false ) {
00883                 $oObject->priceUnit = '%';
00884                 $oObject->fprice = $oObject->price;
00885                 $oObject->price  = substr( $oObject->price, 0, $iPercPos );
00886             } else {
00887                 $oCur = $myConfig->getActShopCurrencyObject();
00888                 $oObject->price = str_replace(',', '.', $oObject->price);
00889                 $oObject->fprice = oxLang::getInstance()->formatCurrency( $oObject->price  * $oCur->rate, $oCur);
00890                 $oObject->priceUnit = 'abs';
00891             }
00892 
00893             // add price info into list
00894             if ( !$this->isAdmin() && $oObject->price != 0 ) {
00895                 $aName[0] .= " ";
00896                 if ( $oObject->price > 0 ) {
00897                     $aName[0] .= "+";
00898                 }
00899                 //V FS#2616
00900                 if ( $dVat != null && $oObject->priceUnit == 'abs' ) {
00901                     $oPrice = oxNew('oxPrice');
00902                     $oPrice->setPrice($oObject->price, $dVat);
00903                     $aName[0] .= oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() * $oCur->rate, $oCur);
00904                 } else {
00905                     $aName[0] .= $oObject->fprice;
00906                 }
00907                 if ( $oObject->priceUnit == 'abs' ) {
00908                     $aName[0] .= " ".$oCur->sign;
00909                 }
00910             }
00911         } elseif ( isset( $aPrice[0] ) && isset($aPrice[1] ) ) {
00912             // A. removing unused part of information
00913             $aName[0] = ereg_replace( "!P!.*", "", $aName[0] );
00914         }
00915 
00916         $oObject->name  = $aName[0];
00917         $oObject->value = $aName[1];
00918         return $oObject;
00919     }
00920 
00928     public function oxMimeContentType( $sFileName )
00929     {
00930         $sFileName = strtolower( $sFileName );
00931         $iLastDot  = strrpos( $sFileName, '.' );
00932 
00933         if ( $iLastDot !== false ) {
00934             $sType = substr( $sFileName, $iLastDot + 1 );
00935             switch ( $sType ) {
00936                 case 'gif':
00937                     $sType = 'image/gif';
00938                     break;
00939                 case 'jpeg':
00940                 case 'jpg':
00941                     $sType = 'image/jpeg';
00942                     break;
00943                 case 'png':
00944                     $sType = 'image/png';
00945                     break;
00946                 default:
00947                     $sType = false;
00948                     break;
00949             }
00950         }
00951         return $sType;
00952     }
00953 
00962     public function logger( $sText, $blNewline = false )
00963     {   $myConfig = $this->getConfig();
00964 
00965         if ( $myConfig->getConfigParam( 'iDebug' ) == -2) {
00966             if ( gettype( $sText ) != 'string' ) {
00967                 $sText = var_export( $sText, true);
00968             }
00969             @error_log("----------------------------------------------\n$sText".( ( $blNewline ) ?"\n":"" )."\n", 3, $myConfig->getConfigParam( 'sCompileDir' ).'/log.txt' );
00970         }
00971 
00972     }
00973 
00981     protected function _stripQuotes($mInput)
00982     {
00983         return is_array($mInput) ? array_map( array( $this, '_stripQuotes' ), $mInput) : stripslashes( $mInput );
00984     }
00985 
00993     public function strRot13( $sStr )
00994     {
00995         $sFrom = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
00996         $sTo   = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
00997 
00998         return strtr( $sStr, $sFrom, $sTo );
00999     }
01000 
01001 
01011     public function prepareUrlForNoSession($sUrl)
01012     {
01013         if ( $this->seoIsActive() ) {
01014             return $sUrl;
01015         }
01016 
01017         $sUrl = preg_replace('/(force_)?sid=[a-z0-9\._]*&?(amp;)?/i', '', $sUrl);
01018 
01019         $oStr = getStr();
01020         if ($qpos = $oStr->strpos($sUrl, '?')) {
01021             if ($qpos == $oStr->strlen($sUrl)-1) {
01022                 $sSep = '';
01023             } else {
01024                 $sSep = '&amp;';
01025             }
01026         } else {
01027             $sSep = '?';
01028         }
01029 
01030         if (!preg_match('/[&?](amp;)?lang=[0-9]+/i', $sUrl)) {
01031             $sUrl .= "{$sSep}lang=".oxLang::getInstance()->getBaseLanguage();
01032             $sSep = '&amp;';
01033         }
01034 
01035         if (!preg_match('/[&?](amp;)?cur=[0-9]+/i', $sUrl)) {
01036             $iCur = (int) oxConfig::getParameter('currency');
01037             if ($iCur) {
01038                 $sUrl .= "{$sSep}cur=".$iCur;
01039                 $sSep = '&amp;';
01040             }
01041         }
01042 
01043         return $sUrl;
01044     }
01045 
01054     protected function _getCacheFilePath( $sCacheName, $blPathOnly = false )
01055     {
01056         $sVersionPrefix = "";
01057 
01058 
01059             $sVersionPrefix = 'pe';
01060 
01061         $sPath = $this->getConfig()->getConfigParam( 'sCompileDir' );
01062         return $blPathOnly ? "{$sPath}/" : "{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}.txt";
01063     }
01064 
01072     public function getLangCache( $sCacheName )
01073     {
01074         $aLangCache = null;
01075         $sFilePath = $this->_getCacheFilePath( $sCacheName );
01076         if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
01077             include $sFilePath;
01078         }
01079         return $aLangCache;
01080     }
01081 
01090     public function setLangCache( $sCacheName, $aLangCache )
01091     {
01092         $sCache = "<?php\n\$aLangCache = ".var_export( $aLangCache, true ).";";
01093         $this->_oxFileCache( true, $sCacheName, $sCache );
01094     }
01095 
01103     public function checkUrlEndingSlash( $sUrl )
01104     {
01105         if ( !preg_match("/\/$/", $sUrl) ) {
01106             $sUrl .= '/';
01107         }
01108 
01109         return $sUrl;
01110     }
01111 
01112 }

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5