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 
00041     public static function getInstance()
00042     {
00043         // disable caching for test modules
00044         if ( defined( 'OXID_PHP_UNIT' ) ) {
00045             static $inst = array();
00046             self::$_instance = $inst[oxClassCacheKey()];
00047 
00048         }
00049 
00050         if ( !self::$_instance instanceof oxUtils ) {
00051 
00052 
00053             self::$_instance = oxNew( 'oxUtils' );
00054 
00055             if ( defined( 'OXID_PHP_UNIT' ) ) {
00056                 $inst[oxClassCacheKey()] = self::$_instance;
00057             }
00058         }
00059         return self::$_instance;
00060     }
00061 
00067     protected $_aStaticCache;
00068 
00074     protected $_blSeoIsActive = null;
00075 
00081     public function stripGpcMagicQuotes()
00082     {
00083         if (!get_magic_quotes_gpc()) {
00084             return;
00085         }
00086         $_REQUEST = self::_stripQuotes($_REQUEST);
00087         $_POST = self::_stripQuotes($_POST);
00088         $_GET = self::_stripQuotes($_GET);
00089         $_COOKIE = self::_stripQuotes($_COOKIE);
00090     }
00091 
00100     public function strMan( $sVal, $sKey = null )
00101     {
00102         $sKey = $sKey?$sKey:'oxid123456789';
00103         $sVal = "ox{$sVal}id";
00104 
00105         $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00106         $sVal = $this->strRot13( $sVal );
00107         $sVal = $sVal ^ $sKey;
00108         $sVal = base64_encode( $sVal );
00109         $sVal = str_replace( "=", "!", $sVal );
00110 
00111         return "ox_$sVal";
00112     }
00113 
00122     public function strRem( $sVal, $sKey = null )
00123     {
00124         $sKey = $sKey?$sKey:'oxid123456789';
00125         $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00126 
00127         $sVal = substr( $sVal, 3 );
00128         $sVal = str_replace( '!', '=', $sVal );
00129         $sVal = base64_decode( $sVal );
00130         $sVal = $sVal ^ $sKey;
00131         $sVal = $this->strRot13( $sVal );
00132 
00133         return substr( $sVal, 2, -2 );
00134     }
00135 
00143     public function getArrFldName( $sName)
00144     {
00145         return str_replace( ".", "__", $sName);
00146     }
00147 
00156     public function assignValuesFromText( $sIn, $dVat = null)
00157     {
00158         $aRet = array();
00159         $aPieces = explode( '@@', $sIn );
00160         while ( list( $sKey, $sVal ) = each( $aPieces ) ) {
00161             if ( $sVal ) {
00162                 $aName = explode( '__', $sVal );
00163                 if ( isset( $aName[0] ) && isset( $aName[1] ) ) {
00164                     $aRet[] = $this->_fillExplodeArray( $aName, $dVat );
00165                 }
00166             }
00167         }
00168         return $aRet;
00169     }
00170 
00178     public function assignValuesToText( $aIn)
00179     {
00180         $sRet = "";
00181         reset( $aIn );
00182         while (list($sKey, $sVal) = each($aIn)) {
00183             $sRet .= $sKey;
00184             $sRet .= "__";
00185             $sRet .= $sVal;
00186             $sRet .= "@@";
00187         }
00188         return $sRet;
00189     }
00190 
00199     public function formatCurrency( $dValue, $oActCur = null )
00200     {
00201         if (!$oActCur) {
00202             $oActCur = $this->getConfig()->getActShopCurrencyObject();
00203         }
00204         $sFormated = number_format( $dValue, $oActCur->decimal, $oActCur->dec, $oActCur->thousand);
00205 
00206         return $sFormated;
00207     }
00208 
00216     public function currency2Float( $sValue)
00217     {
00218         $fRet = $sValue;
00219         $iPos = strrpos( $sValue, ".");
00220         if ($iPos && ((strlen($sValue)-1-$iPos) < 2+1)) {
00221             // replace decimal with ","
00222             $fRet = substr_replace( $fRet, ",", $iPos, 1);
00223         }
00224         // remove thousands
00225         $fRet = str_replace( array(" ","."), "", $fRet);
00226 
00227         $fRet = str_replace( ",", ".", $fRet);
00228         return (float) $fRet;
00229     }
00230 
00238     public function isSearchEngine( $sClient = null )
00239     {
00240         $myConfig = $this->getConfig();
00241         $blIsSe   = false;
00242 
00243         if ( !( $myConfig->getConfigParam( 'iDebug' ) && $this->isAdmin() ) ) {
00244 
00245             // caching
00246             $blIsSe = $myConfig->getGlobalParameter( 'blIsSearchEngine' );
00247             if ( !isset( $blIsSe ) ) {
00248 
00249                 $aRobots = $myConfig->getConfigParam( 'aRobots' );
00250                 $aRobots = is_array( $aRobots )?$aRobots:array();
00251 
00252                 $aRobotsExcept = $myConfig->getConfigParam( 'aRobotsExcept' );
00253                 $aRobotsExcept = is_array( $aRobotsExcept )?$aRobotsExcept:array();
00254 
00255                 $sClient = $sClient?$sClient:strtolower( getenv( 'HTTP_USER_AGENT' ) );
00256                 $blIsSe  = false;
00257                 $aRobots = array_merge( $aRobots, $aRobotsExcept );
00258                 foreach ( $aRobots as $sRobot ) {
00259                     if ( strpos( $sClient, $sRobot ) !== false ) {
00260                         $blIsSe = true;
00261                         break;
00262                     }
00263                 }
00264                 $myConfig->setGlobalParameter( 'blIsSearchEngine', $blIsSe );
00265             }
00266         }
00267 
00268         return $blIsSe;
00269     }
00270 
00279     public function isValidEmail( $sEmail )
00280     {
00281         $blValid = true;
00282         if ( $sEmail != 'admin' ) {
00283             $blValid = ( eregi( $this->_sEmailTpl, $sEmail ) != 0 );
00284         }
00285 
00286         return $blValid;
00287     }
00288 
00294     public function rebuildCache()
00295     {
00296         // not needed from 3.0 on and unused <- MK: not correct, its used for example in shop_config.php, oxbase.php
00297 
00298         //$smarty  = & oxUtils::getInstance()->getSmarty();
00299         //$smarty->clear_all_cache();
00300 
00301         if ( function_exists( "UserdefinedRebuildCache")) {
00302             UserdefinedRebuildCache();
00303         }
00304     }
00305 
00313     public function loadAdminProfile($aInterfaceProfiles)
00314     {
00315         // improved #533
00316         // checking for available profiles list
00317         $aInterfaceProfiles = $aInterfaceProfiles;
00318         if ( is_array( $aInterfaceProfiles ) ) {   //checking for previous profiles
00319             $sPrevProfile = oxUtilsServer::getInstance()->getOxCookie('oxidadminprofile');
00320             if (isset($sPrevProfile)) {
00321                 $aPrevProfile = @explode("@", trim($sPrevProfile));
00322             }
00323 
00324             //array to store profiles
00325             $aProfiles = array();
00326             foreach ( $aInterfaceProfiles as $iPos => $sProfile) {
00327                 $aProfileSettings = array($iPos, $sProfile);
00328                 $aProfiles[] = $aProfileSettings;
00329             }
00330             // setting previous used profile as active
00331             if (isset($aPrevProfile[0]) && isset($aProfiles[$aPrevProfile[0]])) {
00332                 $aProfiles[$aPrevProfile[0]][2] = 1;
00333             }
00334 
00335             oxSession::setVar("aAdminProfiles", $aProfiles);
00336             return $aProfiles;
00337         }
00338         return null;
00339     }
00340 
00349     public function fRound($sVal, $oCur = null)
00350     {
00351         startProfile('fround');
00352 
00353         //cached currency precision, this saves about 1% of execution time
00354         $iCurPrecision = null;
00355         if (! defined('OXID_PHP_UNIT')) {
00356             $iCurPrecision = $this->_iCurPrecision;
00357         }
00358 
00359         if (is_null($iCurPrecision)) {
00360             if ( !$oCur ) {
00361                 $oCur = $this->getConfig()->getActShopCurrencyObject();
00362             }
00363 
00364             $iCurPrecision = $oCur->decimal;
00365             $this->_iCurPrecision = $iCurPrecision;
00366         }
00367 
00368         // this is a workaround for #36008 bug in php - incorrect round() & number_format() result (R)
00369         static $dprez = null;
00370         if (!$dprez) {
00371             $prez = @ini_get("precision");
00372             if (!$prez) {
00373                 $prez = 9;
00374             }
00375             $dprez = pow(10, -$prez);
00376         }
00377 
00378 
00379         stopProfile('fround');
00380 
00381         return round($sVal + $dprez, $iCurPrecision);
00382     }
00383 
00393     public function toStaticCache( $sName, $sContent, $sKey = null )
00394     {
00395         // if it's an array then we add
00396         if ( $sKey ) {
00397             $this->_aStaticCache[$sName][$sKey] = $sContent;
00398         } else {
00399             $this->_aStaticCache[$sName] = $sContent;
00400         }
00401     }
00402 
00410     public function fromStaticCache( $sName)
00411     {
00412         if ( isset( $this->_aStaticCache[$sName])) {
00413             return $this->_aStaticCache[$sName];
00414         }
00415         return null;
00416     }
00417 
00425     public function cleanStaticCache($sCacheName = null)
00426     {
00427         if ($sCacheName) {
00428             unset($this->_aStaticCache[$sCacheName]);
00429         } else {
00430             $this->_aStaticCache = null;
00431         }
00432     }
00433 
00443     protected function _oxFileCache( $blMode, $sName, $sInput = null )
00444     {
00445         $sFilePath = $this->_getCacheFilePath( $sName );
00446         $sRet = null;
00447         if ( $blMode) {
00448             // write to cache
00449 
00450             //if ( is_writable($sFilePath))
00451             // dodger: somehow iswriteable always says no on windows machines
00452 
00453             $hFile = fopen( $sFilePath, "w");
00454             if ( $hFile) {
00455                 fwrite( $hFile, $sInput);
00456                 fclose( $hFile);
00457             }
00458         } else {   // read it
00459             if ( file_exists( $sFilePath) && is_readable($sFilePath)) {
00460                 // read it
00461                 $sRet = file_get_contents( $sFilePath);
00462             }
00463         }
00464         return $sRet;
00465     }
00466 
00475     public function toFileCache($sKey, $sContents)
00476     {
00477         $sStaticCacheKey = 'staticfilecache|' . $sKey;
00478         $this->toStaticCache($sStaticCacheKey, $sContents);
00479 
00480         $sContents = serialize($sContents);
00481         return $this->_oxFileCache(true, $sKey, $sContents);
00482     }
00483 
00491     public function fromFileCache( $sKey )
00492     {
00493         $sStaticCacheKey = "staticfilecache|$sKey";
00494 
00495         //using static cache for even faster fetch
00496         $sRes = $this->fromStaticCache( $sStaticCacheKey );
00497 
00498         if ( is_null( $sRes ) ) {
00499             $sRes = $this->_oxFileCache( false, $sKey );
00500             if (!is_null($sRes)) {
00501                 $sRes = unserialize( $sRes );
00502                 $this->toStaticCache( $sStaticCacheKey, $sRes );
00503             }
00504         }
00505 
00506         return $sRes;
00507     }
00508 
00515     public function oxResetFileCache()
00516     {
00517         $aPathes = glob( $this->_getCacheFilePath( '*' ) );
00518         if ( is_array( $aPathes ) ) {
00519             foreach ( $aPathes as $sFilename ) {
00520                 // delete all the files, except cached tables fieldnames
00521                 if ( strpos($sFilename, "c_fieldnames_") === false ) {
00522                     @unlink( $sFilename );
00523                 }
00524             }
00525         }
00526     }
00527 
00537     public function getRemoteCachePath($sRemote, $sLocal)
00538     {
00539         clearstatcache();
00540         if ( file_exists( $sLocal ) && filemtime( $sLocal ) && filemtime( $sLocal ) > time() - 86400 ) {
00541             return $sLocal;
00542         }
00543         $hRemote = @fopen( $sRemote, "rb");
00544         $blSuccess = false;
00545         if ( isset( $hRemote) && $hRemote ) {
00546             $hLocal = fopen( $sLocal, "wb");
00547             stream_copy_to_stream($hRemote, $hLocal);
00548             fclose($hRemote);
00549             fclose($hLocal);
00550             $blSuccess = true;
00551         } else {
00552             // try via fsockopen
00553             $aUrl = @parse_url( $sRemote);
00554             if ( !empty( $aUrl["host"])) {
00555                 $sPath = $aUrl["path"];
00556                 if ( empty( $sPath ) ) {
00557                     $sPath = "/";
00558                 }
00559                 $sHost = $aUrl["host"];
00560 
00561                 $hSocket = @fsockopen( $sHost, 80, $iErrorNumber, $iErrStr, 5);
00562                 if ( $hSocket) {
00563                     fputs( $hSocket, "GET ".$sPath." HTTP/1.0\r\nHost: $sHost\r\n\r\n");
00564                     $headers = stream_get_line($hSocket, 4096, "\r\n\r\n");
00565                     $hLocal = @fopen( $sLocal, "wb");
00566                     stream_copy_to_stream($hSocket, $hLocal);
00567                     fclose( $hSocket);
00568                     fclose($hLocal);
00569                     $blSuccess = true;
00570                 }
00571             }
00572         }
00573         if ( $blSuccess || file_exists( $sLocal ) ) {
00574             return $sLocal;
00575         } else {
00576             return false;
00577         }
00578     }
00579 
00585     public function checkAccessRights()
00586     {
00587         $myConfig  = $this->getConfig();
00588 
00589         $blIsAuth = false;
00590 
00591         $sUserID = oxSession::getVar( "auth");
00592 
00593         // deleting admin marker
00594         oxSession::setVar( "malladmin", 0);
00595         oxSession::setVar( "blIsAdmin", 0);
00596         oxSession::deleteVar( "blIsAdmin" );
00597         $myConfig->setConfigParam( 'blMallAdmin', false );
00598         //#1552T
00599         $myConfig->setConfigParam( 'blAllowInheritedEdit', false );
00600 
00601         if ( $sUserID) {
00602             // escaping
00603             $oDb = oxDb::getDb();
00604             $sUserID = $oDb->quote($sUserID);
00605             $sRights = $oDb->getOne("select oxrights from oxuser where oxid = $sUserID");
00606 
00607             if ( $sRights != "user") {
00608                 // malladmin ?
00609                 if ( $sRights == "malladmin") {
00610                     oxSession::setVar( "malladmin", 1);
00611                     $myConfig->setConfigParam( 'blMallAdmin', true );
00612 
00613                     //#1552T
00614                     //So far this blAllowSharedEdit is Equal to blMallAdmin but in future to be solved over rights and roles
00615                     $myConfig->setConfigParam( 'blAllowSharedEdit', true );
00616 
00617                     $sShop = oxSession::getVar( "actshop");
00618                     if ( !isset($sShop)) {
00619                         oxSession::setVar( "actshop", $myConfig->getBaseShopId());
00620                     }
00621                     $blIsAuth = true;
00622                 } else {   // Shopadmin... check if this shop is valid and exists
00623                     $sShopID = $oDb->getOne("select oxid from oxshops where oxid = '{$sRights}'");
00624                     if ( isset( $sShopID) && $sShopID) {   // success, this shop exists
00625 
00626                         oxSession::setVar( "actshop", $sRights);
00627                         oxSession::setVar( "currentadminshop", $sRights);
00628                         oxSession::setVar( "shp", $sRights);
00629 
00630                         // check if this subshop admin is evil.
00631                         if ('chshp' == oxConfig::getParameter( 'fnc' )) {
00632                             // dont allow this call
00633                             $blIsAuth = false;
00634                         } else {
00635                             $blIsAuth = true;
00636 
00637                             $aShopIdVars = array('actshop', 'shp', 'currentadminshop');
00638                             foreach ($aShopIdVars as $sShopIdVar) {
00639                                 if ($sGotShop = oxConfig::getParameter( $sShopIdVar )) {
00640                                     if ($sGotShop != $sRights) {
00641                                         $blIsAuth = false;
00642                                         break;
00643                                     }
00644                                 }
00645                             }
00646                         }
00647                     }
00648                 }
00649                 // marking user as admin
00650                 oxSession::setVar( "blIsAdmin", 1);
00651             }
00652         }
00653         return $blIsAuth;
00654     }
00655 
00665     public function seoIsActive( $blReset = false, $sShopId = null, $iActLang = null )
00666     {
00667         if ( !is_null( $this->_blSeoIsActive ) && !$blReset ) {
00668             return $this->_blSeoIsActive;
00669         }
00670 
00671         $myConfig = $this->getConfig();
00672 
00673         if ( $this->isAdmin() ) {
00674             // allways off in admin
00675             $this->_blSeoIsActive = false;
00676         } elseif ( ( $this->_blSeoIsActive = $myConfig->getConfigParam( 'blSeoMode' ) ) === null ) {
00677             $this->_blSeoIsActive = true;
00678 
00679             $aSeoModes  = $myConfig->getconfigParam( 'aSeoModes' );
00680             $sActShopId = $sShopId ? $sShopId : $myConfig->getActiveShop()->getId();
00681             $iActLang   = $iActLang ? $iActLang : (int) oxLang::getInstance()->getBaseLanguage();
00682 
00683             // checking special config param for active shop and language
00684             if ( is_array( $aSeoModes ) && isset( $aSeoModes[$sActShopId] ) && isset( $aSeoModes[$sActShopId][$iActLang] ) ) {
00685                 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
00686             }
00687         }
00688 
00689         return $this->_blSeoIsActive;
00690     }
00691 
00701     public function getShopBit( $iShopId )
00702     {
00703         $iShopId = (int) $iShopId;
00704         //this works for large numbers when $sShopNr is up to (inclusive) 64
00705         $iRes = oxDb::getDb()->getOne( "select 1 << ( $iShopId - 1 ) as shopbit" );
00706 
00707         //as php ints supports only 32 bits, we return string.
00708         return $iRes;
00709     }
00710 
00720     public function bitwiseAnd( $iVal1, $iVal2 )
00721     {
00722         //this works for large numbers when $sShopNr is up to (inclusive) 64
00723         $iRes = oxDb::getDb()->getOne( "select ($iVal1 & $iVal2) as bitwiseAnd" );
00724 
00725         //as php ints supports only 32 bits, we return string.
00726         return $iRes;
00727     }
00728 
00738     public function bitwiseOr( $iVal1, $iVal2 )
00739     {
00740         //this works for large numbers when $sShopNr is up to (inclusive) 64
00741         $iRes = oxDb::getDb()->getOne( "select ($iVal1 | $iVal2) as bitwiseOr" );
00742 
00743         //as php ints supports only 32 bits, we return string.
00744         return $iRes;
00745     }
00746 
00754     public function isValidAlpha( $sField )
00755     {
00756         return (boolean) preg_match( "#^[\w]*$#", $sField );
00757     }
00758 
00768     protected function _simpleRedirect( $sUrl, $sHeaderCode )
00769     {
00770         header( $sHeaderCode );
00771         header( "Location: $sUrl" );
00772         header( "Connection: close" );
00773     }
00774 
00783     public function redirect( $sUrl, $blAddRedirectParam = true )
00784     {
00785         //preventing possible cyclic redirection
00786         //#M341 and check only if redirect paramater must be added
00787         if ( $blAddRedirectParam && oxConfig::getParameter( 'redirected' ) ) {
00788             return;
00789         }
00790 
00791         if ( $blAddRedirectParam ) {
00792             $sUrl = $this->_addUrlParameters( $sUrl, array( 'redirected' => 1 ) );
00793         }
00794 
00795         $sUrl = str_ireplace( "&amp;", "&", $sUrl );
00796         $this->_simpleRedirect( $sUrl, "HTTP/1.1 301 Moved Permanently" );
00797 
00798         try {//may occur in case db is lost
00799             $this->getSession()->freeze();
00800         } catch( oxException $oEx ) {
00801             $oEx->debugOut();
00802             //do nothing else to make sure the redirect takes place
00803         }
00804 
00805         if ( defined( 'OXID_PHP_UNIT' ) ) {
00806             return;
00807         }
00808 
00809         $this->showMessageAndExit( '' );
00810     }
00811 
00819     public function showMessageAndExit( $sMsg )
00820     {
00821         $this->getSession()->freeze();
00822 
00823         if ( defined( 'OXID_PHP_UNIT' ) ) {
00824             return;
00825         }
00826 
00827         die( $sMsg );
00828     }
00829 
00838     protected function _addUrlParameters( $sUrl, $aParams )
00839     {
00840         $sDelim = ( ( getStr()->strpos( $sUrl, '?' ) !== false ) )?'&':'?';
00841         foreach ( $aParams as $sName => $sVal ) {
00842             $sUrl = $sUrl . $sDelim . $sName . '=' . $sVal;
00843             $sDelim = '&';
00844         }
00845 
00846         return $sUrl;
00847     }
00848 
00860     protected function _fillExplodeArray( $aName, $dVat = null)
00861     {
00862         $myConfig = $this->getConfig();
00863         $oObject = new OxstdClass();
00864         $aPrice = explode( '!P!', $aName[0]);
00865 
00866         if ( ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) && isset( $aPrice[0] ) && isset( $aPrice[1] ) ) || $this->isAdmin() ) {
00867 
00868             // yes, price is there
00869             $oObject->price = $aPrice[1];
00870             $aName[0] = $aPrice[0];
00871 
00872             $iPercPos = getStr()->strpos( $oObject->price, '%' );
00873             if ( $iPercPos !== false ) {
00874                 $oObject->priceUnit = '%';
00875                 $oObject->fprice = $oObject->price;
00876                 $oObject->price  = substr( $oObject->price, 0, $iPercPos );
00877             } else {
00878                 $oCur = $myConfig->getActShopCurrencyObject();
00879                 $oObject->price = str_replace(',', '.', $oObject->price);
00880                 $oObject->fprice = oxLang::getInstance()->formatCurrency( $oObject->price  * $oCur->rate, $oCur);
00881                 $oObject->priceUnit = 'abs';
00882             }
00883 
00884             // add price info into list
00885             if ( !$this->isAdmin() && $oObject->price != 0 ) {
00886                 $aName[0] .= " ";
00887                 if ( $oObject->price > 0 ) {
00888                     $aName[0] .= "+";
00889                 }
00890                 //V FS#2616
00891                 if ( $dVat != null && $oObject->priceUnit == 'abs' ) {
00892                     $oPrice = oxNew('oxPrice');
00893                     $oPrice->setPrice($oObject->price, $dVat);
00894                     $aName[0] .= oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() * $oCur->rate, $oCur);
00895                 } else {
00896                     $aName[0] .= $oObject->fprice;
00897                 }
00898                 if ( $oObject->priceUnit == 'abs' ) {
00899                     $aName[0] .= " ".$oCur->sign;
00900                 }
00901             }
00902         } elseif ( isset( $aPrice[0] ) && isset($aPrice[1] ) ) {
00903             // A. removing unused part of information
00904             $aName[0] = ereg_replace( "!P!.*", "", $aName[0] );
00905         }
00906 
00907         $oObject->name  = $aName[0];
00908         $oObject->value = $aName[1];
00909         return $oObject;
00910     }
00911 
00919     public function oxMimeContentType( $sFileName )
00920     {
00921         $sFileName = strtolower( $sFileName );
00922         $iLastDot  = strrpos( $sFileName, '.' );
00923 
00924         if ( $iLastDot !== false ) {
00925             $sType = substr( $sFileName, $iLastDot + 1 );
00926             switch ( $sType ) {
00927                 case 'gif':
00928                     $sType = 'image/gif';
00929                     break;
00930                 case 'jpeg':
00931                 case 'jpg':
00932                     $sType = 'image/jpeg';
00933                     break;
00934                 case 'png':
00935                     $sType = 'image/png';
00936                     break;
00937                 default:
00938                     $sType = false;
00939                     break;
00940             }
00941         }
00942         return $sType;
00943     }
00944 
00953     public function logger( $sText, $blNewline = false )
00954     {   $myConfig = $this->getConfig();
00955 
00956         if ( $myConfig->getConfigParam( 'iDebug' ) == -2) {
00957             if ( gettype( $sText ) != 'string' ) {
00958                 $sText = var_export( $sText, true);
00959             }
00960             @error_log("----------------------------------------------\n$sText".( ( $blNewline ) ?"\n":"" )."\n", 3, $myConfig->getConfigParam( 'sCompileDir' ).'/log.txt' );
00961         }
00962 
00963     }
00964 
00972     protected function _stripQuotes($mInput)
00973     {
00974         return is_array($mInput) ? array_map( array( $this, '_stripQuotes' ), $mInput) : stripslashes( $mInput );
00975     }
00976 
00984     public function strRot13( $sStr )
00985     {
00986         $sFrom = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
00987         $sTo   = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
00988 
00989         return strtr( $sStr, $sFrom, $sTo );
00990     }
00991 
00992 
01002     public function prepareUrlForNoSession($sUrl)
01003     {
01004         if ( $this->seoIsActive() ) {
01005             return $sUrl;
01006         }
01007 
01008         $sUrl = preg_replace('/(force_)?sid=[a-z0-9\._]*&?(amp;)?/i', '', $sUrl);
01009 
01010         $oStr = getStr();
01011         if ($qpos = $oStr->strpos($sUrl, '?')) {
01012             if ($qpos == $oStr->strlen($sUrl)-1) {
01013                 $sSep = '';
01014             } else {
01015                 $sSep = '&amp;';
01016             }
01017         } else {
01018             $sSep = '?';
01019         }
01020 
01021         if (!preg_match('/[&?](amp;)?lang=[0-9]+/i', $sUrl)) {
01022             $sUrl .= "{$sSep}lang=".oxLang::getInstance()->getBaseLanguage();
01023             $sSep = '&amp;';
01024         }
01025 
01026         if (!preg_match('/[&?](amp;)?cur=[0-9]+/i', $sUrl)) {
01027             $iCur = (int) oxConfig::getParameter('currency');
01028             if ($iCur) {
01029                 $sUrl .= "{$sSep}cur=".$iCur;
01030                 $sSep = '&amp;';
01031             }
01032         }
01033 
01034         return $sUrl;
01035     }
01036 
01044     protected function _getCacheFilePath( $sCacheName )
01045     {
01046         $sVersionPrefix = "";
01047 
01048 
01049             $sVersionPrefix = 'pe';
01050 
01051         return $this->getConfig()->getConfigParam( 'sCompileDir' ) . "/ox{$sVersionPrefix}c_{$sCacheName}.txt";
01052     }
01053 
01061     public function getLangCache( $sCacheName )
01062     {
01063         $aLangCache = null;
01064         $sFilePath = $this->_getCacheFilePath( $sCacheName );
01065         if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
01066             include $sFilePath;
01067         }
01068         return $aLangCache;
01069     }
01070 
01079     public function setLangCache( $sCacheName, $aLangCache )
01080     {
01081         $sCache = "<?php\n\$aLangCache = ".var_export( $aLangCache, true ).";";
01082         $this->_oxFileCache( true, $sCacheName, $sCache );
01083     }
01084 
01092     public function checkUrlEndingSlash( $sUrl )
01093     {
01094         if ( !preg_match("/\/$/", $sUrl) ) {
01095             $sUrl .= '/';
01096         }
01097 
01098         return $sUrl;
01099     }
01100 
01101 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5