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 {
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     protected $_aFileCacheWritable = array();
00057 
00063     public static function getInstance()
00064     {
00065         // disable caching for test modules
00066         if ( defined( 'OXID_PHP_UNIT' ) ) {
00067             self::$_instance = modInstances::getMod( __CLASS__ );
00068         }
00069 
00070         if ( !(self::$_instance instanceof oxUtils) ) {
00071 
00072             self::$_instance = oxNew( 'oxUtils' );
00073 
00074             if ( defined( 'OXID_PHP_UNIT' ) ) {
00075                 modInstances::addMod( __CLASS__, self::$_instance);
00076             }
00077         }
00078         return self::$_instance;
00079     }
00080 
00086     protected $_aStaticCache;
00087 
00093     protected $_blSeoIsActive = null;
00094 
00100     public function stripGpcMagicQuotes()
00101     {
00102         if (!get_magic_quotes_gpc()) {
00103             return;
00104         }
00105         $_REQUEST = self::_stripQuotes($_REQUEST);
00106         $_POST = self::_stripQuotes($_POST);
00107         $_GET = self::_stripQuotes($_GET);
00108         $_COOKIE = self::_stripQuotes($_COOKIE);
00109     }
00110 
00119     public function strMan( $sVal, $sKey = null )
00120     {
00121         $sKey = $sKey?$sKey:'oxid123456789';
00122         $sVal = "ox{$sVal}id";
00123 
00124         $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00125         $sVal = $this->strRot13( $sVal );
00126         $sVal = $sVal ^ $sKey;
00127         $sVal = base64_encode( $sVal );
00128         $sVal = str_replace( "=", "!", $sVal );
00129 
00130         return "ox_$sVal";
00131     }
00132 
00141     public function strRem( $sVal, $sKey = null )
00142     {
00143         $sKey = $sKey?$sKey:'oxid123456789';
00144         $sKey = str_repeat( $sKey, strlen( $sVal ) / strlen( $sKey ) + 5 );
00145 
00146         $sVal = substr( $sVal, 3 );
00147         $sVal = str_replace( '!', '=', $sVal );
00148         $sVal = base64_decode( $sVal );
00149         $sVal = $sVal ^ $sKey;
00150         $sVal = $this->strRot13( $sVal );
00151 
00152         return substr( $sVal, 2, -2 );
00153     }
00154 
00162     public function getArrFldName( $sName)
00163     {
00164         return str_replace( ".", "__", $sName);
00165     }
00166 
00175     public function assignValuesFromText( $sIn, $dVat = null)
00176     {
00177         $aRet = array();
00178         $aPieces = explode( '@@', $sIn );
00179         while ( list( $sKey, $sVal ) = each( $aPieces ) ) {
00180             if ( $sVal ) {
00181                 $aName = explode( '__', $sVal );
00182                 if ( isset( $aName[0] ) && isset( $aName[1] ) ) {
00183                     $aRet[] = $this->_fillExplodeArray( $aName, $dVat );
00184                 }
00185             }
00186         }
00187         return $aRet;
00188     }
00189 
00197     public function assignValuesToText( $aIn)
00198     {
00199         $sRet = "";
00200         reset( $aIn );
00201         while (list($sKey, $sVal) = each($aIn)) {
00202             $sRet .= $sKey;
00203             $sRet .= "__";
00204             $sRet .= $sVal;
00205             $sRet .= "@@";
00206         }
00207         return $sRet;
00208     }
00209 
00220     public function formatCurrency( $dValue, $oActCur = null )
00221     {
00222         if (!$oActCur) {
00223             $oActCur = $this->getConfig()->getActShopCurrencyObject();
00224         }
00225         $sFormated = number_format( (double)$dValue, $oActCur->decimal, $oActCur->dec, $oActCur->thousand);
00226 
00227         return $sFormated;
00228     }
00229 
00237     public function currency2Float( $sValue)
00238     {
00239         $fRet = $sValue;
00240         $iPos = strrpos( $sValue, ".");
00241         if ($iPos && ((strlen($sValue)-1-$iPos) < 2+1)) {
00242             // replace decimal with ","
00243             $fRet = substr_replace( $fRet, ",", $iPos, 1);
00244         }
00245         // remove thousands
00246         $fRet = str_replace( array(" ","."), "", $fRet);
00247 
00248         $fRet = str_replace( ",", ".", $fRet);
00249         return (float) $fRet;
00250     }
00251 
00259     public function isSearchEngine( $sClient = null )
00260     {
00261         $myConfig = $this->getConfig();
00262         $blIsSe   = false;
00263 
00264         if ( !( $myConfig->getConfigParam( 'iDebug' ) && $this->isAdmin() ) ) {
00265 
00266             // caching
00267             $blIsSe = $myConfig->getGlobalParameter( 'blIsSearchEngine' );
00268             if ( !isset( $blIsSe ) ) {
00269 
00270                 $aRobots = $myConfig->getConfigParam( 'aRobots' );
00271                 $aRobots = is_array( $aRobots )?$aRobots:array();
00272 
00273                 $aRobotsExcept = $myConfig->getConfigParam( 'aRobotsExcept' );
00274                 $aRobotsExcept = is_array( $aRobotsExcept )?$aRobotsExcept:array();
00275 
00276                 $sClient = $sClient?$sClient:strtolower( getenv( 'HTTP_USER_AGENT' ) );
00277                 $blIsSe  = false;
00278                 $aRobots = array_merge( $aRobots, $aRobotsExcept );
00279                 foreach ( $aRobots as $sRobot ) {
00280                     if ( strpos( $sClient, $sRobot ) !== false ) {
00281                         $blIsSe = true;
00282                         break;
00283                     }
00284                 }
00285                 $myConfig->setGlobalParameter( 'blIsSearchEngine', $blIsSe );
00286             }
00287         }
00288 
00289         return $blIsSe;
00290     }
00291 
00300     public function isValidEmail( $sEmail )
00301     {
00302         $blValid = true;
00303         if ( $sEmail != 'admin' ) {
00304             $blValid = ( getStr()->preg_match( $this->_sEmailTpl, $sEmail ) != 0 );
00305         }
00306 
00307         return $blValid;
00308     }
00309 
00315     public function rebuildCache()
00316     {
00317         // not needed from 3.0 on and unused <- MK: not correct, its used for example in shop_config.php, oxbase.php
00318 
00319         //$smarty  = & oxUtils::getInstance()->getSmarty();
00320         //$smarty->clear_all_cache();
00321 
00322         if ( function_exists( "UserdefinedRebuildCache")) {
00323             UserdefinedRebuildCache();
00324         }
00325     }
00326 
00334     public function loadAdminProfile($aInterfaceProfiles)
00335     {
00336         // improved #533
00337         // checking for available profiles list
00338         $aInterfaceProfiles = $aInterfaceProfiles;
00339         if ( is_array( $aInterfaceProfiles ) ) {
00340             //checking for previous profiles
00341             $sPrevProfile = oxUtilsServer::getInstance()->getOxCookie('oxidadminprofile');
00342             if (isset($sPrevProfile)) {
00343                 $aPrevProfile = @explode("@", trim($sPrevProfile));
00344             }
00345 
00346             //array to store profiles
00347             $aProfiles = array();
00348             foreach ( $aInterfaceProfiles as $iPos => $sProfile) {
00349                 $aProfileSettings = array($iPos, $sProfile);
00350                 $aProfiles[] = $aProfileSettings;
00351             }
00352             // setting previous used profile as active
00353             if (isset($aPrevProfile[0]) && isset($aProfiles[$aPrevProfile[0]])) {
00354                 $aProfiles[$aPrevProfile[0]][2] = 1;
00355             }
00356 
00357             oxSession::setVar("aAdminProfiles", $aProfiles);
00358             return $aProfiles;
00359         }
00360         return null;
00361     }
00362 
00371     public function fRound($sVal, $oCur = null)
00372     {
00373         startProfile('fround');
00374 
00375         //cached currency precision, this saves about 1% of execution time
00376         $iCurPrecision = null;
00377         if (! defined('OXID_PHP_UNIT')) {
00378             $iCurPrecision = $this->_iCurPrecision;
00379         }
00380 
00381         if (is_null($iCurPrecision)) {
00382             if ( !$oCur ) {
00383                 $oCur = $this->getConfig()->getActShopCurrencyObject();
00384             }
00385 
00386             $iCurPrecision = $oCur->decimal;
00387             $this->_iCurPrecision = $iCurPrecision;
00388         }
00389 
00390         // this is a workaround for #36008 bug in php - incorrect round() & number_format() result (R)
00391         static $dprez = null;
00392         if (!$dprez) {
00393             $prez = @ini_get("precision");
00394             if (!$prez) {
00395                 $prez = 9;
00396             }
00397             $dprez = pow(10, -$prez);
00398         }
00399 
00400 
00401         stopProfile('fround');
00402 
00403         return round($sVal + $dprez, $iCurPrecision);
00404     }
00405 
00415     public function toStaticCache( $sName, $sContent, $sKey = null )
00416     {
00417         // if it's an array then we add
00418         if ( $sKey ) {
00419             $this->_aStaticCache[$sName][$sKey] = $sContent;
00420         } else {
00421             $this->_aStaticCache[$sName] = $sContent;
00422         }
00423     }
00424 
00432     public function fromStaticCache( $sName)
00433     {
00434         if ( isset( $this->_aStaticCache[$sName])) {
00435             return $this->_aStaticCache[$sName];
00436         }
00437         return null;
00438     }
00439 
00447     public function cleanStaticCache($sCacheName = null)
00448     {
00449         if ($sCacheName) {
00450             unset($this->_aStaticCache[$sCacheName]);
00451         } else {
00452             $this->_aStaticCache = null;
00453         }
00454     }
00455 
00465     public function toPhpFileCache($sKey, $mContents)
00466     {
00467         $sFilePath = $this->getCacheFilePath( $sKey, false, 'php' );
00468 
00469         if (!$sFilePath) {
00470             return;
00471         }
00472 
00473         $sDate = date("Y-m-d H:i:s");
00474         $sVarName = '$_aCacheContents';
00475 
00476         //only simple arrays are supported
00477         if (!is_array($mContents))
00478             return;
00479 
00480         $sContents = "<?php ?>";
00481         if (is_array($mContents)) {
00482             $sContents  = "<?php\n//automatically generated file\n//$sDate\n\n$sVarName = array (\n";
00483             foreach ($mContents as $sKey => $mVal) {
00484                 if (!is_numeric($mVal)) {
00485                     $mVal = "'$mVal'";
00486                 }
00487                 if (!is_numeric($sKey)) {
00488                     $sKey = "'$sKey'";
00489                 }
00490                 $sContents .= "  $sKey => $mVal,\n";
00491             }
00492             $sContents .= ");\n?>";
00493         }
00494 
00495         $hFile = fopen( $sFilePath, "w");
00496         if ( $hFile) {
00497             fwrite( $hFile, $sContents);
00498             fclose( $hFile);
00499         }
00500 
00501     }
00502 
00510     public function fromPhpFileCache($sKey)
00511     {
00512         $sFilePath = $this->getCacheFilePath( $sKey, false, 'php' );
00513 
00514         if (file_exists($sFilePath)) {
00515             include $sFilePath;
00516             return $_aCacheContents;
00517         }
00518 
00519         return null;
00520     }
00521 
00531     public function toFileCache($sKey, $mContents)
00532     {
00533         $sFilePath = $this->getCacheFilePath( $sKey );
00534         $iCurTime = oxUtilsDate::getInstance()->getTime();
00535 
00536         //T2009-05-26
00537         //due to possible race conditions
00538         //check if there are any other cache files already opened for writing by another process
00539         //additionally perform the check for older (aged 40 or more secs) locked files
00540         clearstatcache();
00541         if (!isset($this->_aFileCacheContents[$sKey]) && file_exists($sFilePath) && (!filesize($sFilePath)) && abs($iCurTime - filectime($sFilePath) < 40) ) {
00542             //then leave the cache to be dealt by another process and do nothing
00543             return false;
00544         }
00545         //the above code ensures that $mContents is writen only in case cache file has not been started
00546         //by another process
00547 
00548         //start a blank file to inform other processes we are dealing with it.
00549         $hFile = fopen($sFilePath, "w");
00550         if ($hFile) {
00551             fclose($hFile);
00552         }
00553         clearstatcache();
00554 
00555         $this->_aFileCacheWritable[$sKey] = $mContents;
00556         $this->_aFileCacheContents[$sKey] = $mContents;
00557 
00558         return true;
00559     }
00560 
00568     public function fromFileCache( $sKey )
00569     {
00570         if ( !isset( $this->_aFileCacheContents[$sKey] ) ) {
00571             $sRes = null;
00572 
00573             // read the file
00574             $sFilePath = $this->getCacheFilePath( $sKey );
00575             if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
00576                 // read it
00577                 $sRes = file_get_contents( $sFilePath );
00578                 $sRes = $sRes ? unserialize( $sRes ) : null;
00579             }
00580 
00581             $this->_aFileCacheContents[$sKey] = $sRes;
00582         }
00583 
00584         return $this->_aFileCacheContents[$sKey];
00585     }
00586 
00592     public function commitFileCache()
00593     {
00594         foreach ($this->_aFileCacheWritable as $sKey => $mContents) {
00595             startProfile("!__SAVING CACHE__! (warning)");
00596             $mContents = serialize($mContents);
00597             $sFilePath = $this->getCacheFilePath( $sKey );
00598             $hFile = fopen( $sFilePath, "w");
00599             if ( $hFile) {
00600                 fwrite( $hFile, $mContents);
00601                 fclose( $hFile);
00602             }
00603             stopProfile("!__SAVING CACHE__! (warning)");
00604         }
00605 
00606         //empty buffer
00607         $this->_aFileCacheWritable = array();
00608         clearstatcache ();
00609     }
00610 
00618     public function oxResetFileCache()
00619     {
00620         $aPathes = glob( $this->getCacheFilePath( null, true ) . '*' );
00621         if ( is_array( $aPathes ) ) {
00622             // delete all the files, except cached tables fieldnames
00623             $aPathes = preg_grep( $this->_sPermanentCachePattern, $aPathes, PREG_GREP_INVERT );
00624             foreach ( $aPathes as $sFilename ) {
00625                 @unlink( $sFilename );
00626             }
00627         }
00628     }
00629 
00639     public function getRemoteCachePath($sRemote, $sLocal)
00640     {
00641         clearstatcache();
00642         if ( file_exists( $sLocal ) && filemtime( $sLocal ) && filemtime( $sLocal ) > time() - 86400 ) {
00643             return $sLocal;
00644         }
00645         $hRemote = @fopen( $sRemote, "rb");
00646         $blSuccess = false;
00647         if ( isset( $hRemote) && $hRemote ) {
00648             $hLocal = fopen( $sLocal, "wb");
00649             stream_copy_to_stream($hRemote, $hLocal);
00650             fclose($hRemote);
00651             fclose($hLocal);
00652             $blSuccess = true;
00653         } else {
00654             // try via fsockopen
00655             $aUrl = @parse_url( $sRemote);
00656             if ( !empty( $aUrl["host"])) {
00657                 $sPath = $aUrl["path"];
00658                 if ( empty( $sPath ) ) {
00659                     $sPath = "/";
00660                 }
00661                 $sHost = $aUrl["host"];
00662 
00663                 $hSocket = @fsockopen( $sHost, 80, $iErrorNumber, $iErrStr, 5);
00664                 if ( $hSocket) {
00665                     fputs( $hSocket, "GET ".$sPath." HTTP/1.0\r\nHost: $sHost\r\n\r\n");
00666                     $headers = stream_get_line($hSocket, 4096, "\r\n\r\n");
00667                     if ( ( $hLocal = @fopen( $sLocal, "wb") ) !== false ) {
00668                         rewind($hLocal);
00669                         // does not copy all the data
00670                         // stream_copy_to_stream($hSocket, $hLocal);
00671                         fwrite ( $hLocal, stream_get_contents( $hSocket ) );
00672                         fclose( $hLocal );
00673                         fclose( $hSocket );
00674                         $blSuccess = true;
00675                     }
00676                 }
00677             }
00678         }
00679         if ( $blSuccess || file_exists( $sLocal ) ) {
00680             return $sLocal;
00681         }
00682         return false;
00683     }
00684 
00690     public function checkAccessRights()
00691     {
00692         $myConfig  = $this->getConfig();
00693 
00694         $blIsAuth = false;
00695 
00696         $sUserID = oxSession::getVar( "auth");
00697 
00698         // deleting admin marker
00699         oxSession::setVar( "malladmin", 0);
00700         oxSession::setVar( "blIsAdmin", 0);
00701         oxSession::deleteVar( "blIsAdmin" );
00702         $myConfig->setConfigParam( 'blMallAdmin', false );
00703         //#1552T
00704         $myConfig->setConfigParam( 'blAllowInheritedEdit', false );
00705 
00706         if ( $sUserID) {
00707             // escaping
00708             $oDb = oxDb::getDb();
00709             $sRights = $oDb->getOne("select oxrights from oxuser where oxid = ".$oDb->quote($sUserID));
00710 
00711             if ( $sRights != "user") {
00712                 // malladmin ?
00713                 if ( $sRights == "malladmin") {
00714                     oxSession::setVar( "malladmin", 1);
00715                     $myConfig->setConfigParam( 'blMallAdmin', true );
00716 
00717                     //#1552T
00718                     //So far this blAllowSharedEdit is Equal to blMallAdmin but in future to be solved over rights and roles
00719                     $myConfig->setConfigParam( 'blAllowSharedEdit', true );
00720 
00721                     $sShop = oxSession::getVar( "actshop");
00722                     if ( !isset($sShop)) {
00723                         oxSession::setVar( "actshop", $myConfig->getBaseShopId());
00724                     }
00725                     $blIsAuth = true;
00726                 } else {
00727                     // Shopadmin... check if this shop is valid and exists
00728                     $sShopID = $oDb->getOne("select oxid from oxshops where oxid = " . $oDb->quote( $sRights ) );
00729                     if ( isset( $sShopID) && $sShopID) {
00730                         // success, this shop exists
00731 
00732                         oxSession::setVar( "actshop", $sRights);
00733                         oxSession::setVar( "currentadminshop", $sRights);
00734                         oxSession::setVar( "shp", $sRights);
00735 
00736                         // check if this subshop admin is evil.
00737                         if ('chshp' == oxConfig::getParameter( 'fnc' )) {
00738                             // dont allow this call
00739                             $blIsAuth = false;
00740                         } else {
00741                             $blIsAuth = true;
00742 
00743                             $aShopIdVars = array('actshop', 'shp', 'currentadminshop');
00744                             foreach ($aShopIdVars as $sShopIdVar) {
00745                                 if ($sGotShop = oxConfig::getParameter( $sShopIdVar )) {
00746                                     if ($sGotShop != $sRights) {
00747                                         $blIsAuth = false;
00748                                         break;
00749                                     }
00750                                 }
00751                             }
00752                         }
00753                     }
00754                 }
00755                 // marking user as admin
00756                 oxSession::setVar( "blIsAdmin", 1);
00757             }
00758         }
00759         return $blIsAuth;
00760     }
00761 
00771     public function seoIsActive( $blReset = false, $sShopId = null, $iActLang = null )
00772     {
00773         if ( !is_null( $this->_blSeoIsActive ) && !$blReset ) {
00774             return $this->_blSeoIsActive;
00775         }
00776 
00777         $myConfig = $this->getConfig();
00778 
00779         if ( ( $this->_blSeoIsActive = $myConfig->getConfigParam( 'blSeoMode' ) ) === null ) {
00780             $this->_blSeoIsActive = true;
00781 
00782             $aSeoModes  = $myConfig->getconfigParam( 'aSeoModes' );
00783             $sActShopId = $sShopId ? $sShopId : $myConfig->getActiveShop()->getId();
00784             $iActLang   = $iActLang ? $iActLang : (int) oxLang::getInstance()->getBaseLanguage();
00785 
00786             // checking special config param for active shop and language
00787             if ( is_array( $aSeoModes ) && isset( $aSeoModes[$sActShopId] ) && isset( $aSeoModes[$sActShopId][$iActLang] ) ) {
00788                 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
00789             }
00790         }
00791 
00792         return $this->_blSeoIsActive;
00793     }
00794 
00804     public function getShopBit( $iShopId )
00805     {
00806         $iShopId = (int) $iShopId;
00807         //this works for large numbers when $sShopNr is up to (inclusive) 64
00808         $iRes = oxDb::getDb()->getOne( "select 1 << ( $iShopId - 1 ) as shopbit" );
00809 
00810         //as php ints supports only 32 bits, we return string.
00811         return $iRes;
00812     }
00813 
00823     public function bitwiseAnd( $iVal1, $iVal2 )
00824     {
00825         //this works for large numbers when $sShopNr is up to (inclusive) 64
00826         $iRes = oxDb::getDb()->getOne( "select ($iVal1 & $iVal2) as bitwiseAnd" );
00827 
00828         //as php ints supports only 32 bits, we return string.
00829         return $iRes;
00830     }
00831 
00841     public function bitwiseOr( $iVal1, $iVal2 )
00842     {
00843         //this works for large numbers when $sShopNr is up to (inclusive) 64
00844         $iRes = oxDb::getDb()->getOne( "select ($iVal1 | $iVal2) as bitwiseOr" );
00845 
00846         //as php ints supports only 32 bits, we return string.
00847         return $iRes;
00848     }
00849 
00857     public function isValidAlpha( $sField )
00858     {
00859         return (boolean) getStr()->preg_match( "#^[\w]*$#", $sField );
00860     }
00861 
00871     protected function _simpleRedirect( $sUrl, $sHeaderCode )
00872     {
00873         header( $sHeaderCode );
00874         header( "Location: $sUrl" );
00875         header( "Connection: close" );
00876     }
00877 
00887     public function redirect( $sUrl, $blAddRedirectParam = true, $iHeaderCode = 301 )
00888     {
00889         //preventing possible cyclic redirection
00890         //#M341 and check only if redirect paramater must be added
00891         if ( $blAddRedirectParam && oxConfig::getParameter( 'redirected' ) ) {
00892             return;
00893         }
00894 
00895         if ( $blAddRedirectParam ) {
00896             $sUrl = $this->_addUrlParameters( $sUrl, array( 'redirected' => 1 ) );
00897         }
00898 
00899         $sUrl = str_ireplace( "&amp;", "&", $sUrl );
00900 
00901         $sHeaderCode = '';
00902         switch ($iHeaderCode) {
00903             case 301:
00904                 $sHeaderCode = "HTTP/1.1 301 Moved Permanently";
00905                 break;
00906             case 302:
00907             default:
00908                 $sHeaderCode = "HTTP/1.1 302 Found";
00909         }
00910 
00911         $this->_simpleRedirect( $sUrl, $sHeaderCode );
00912 
00913         try {//may occur in case db is lost
00914             $this->getSession()->freeze();
00915         } catch( oxException $oEx ) {
00916             $oEx->debugOut();
00917             //do nothing else to make sure the redirect takes place
00918         }
00919 
00920         if ( defined( 'OXID_PHP_UNIT' ) ) {
00921             return;
00922         }
00923 
00924         $this->showMessageAndExit( '' );
00925     }
00926 
00934     public function showMessageAndExit( $sMsg )
00935     {
00936         $this->getSession()->freeze();
00937         $this->commitFileCache();
00938 
00939         if ( defined( 'OXID_PHP_UNIT' ) ) {
00940             return;
00941         }
00942 
00943         exit( $sMsg );
00944     }
00945 
00953     public function setHeader($sHeader)
00954     {
00955         header($sHeader);
00956     }
00957 
00966     protected function _addUrlParameters( $sUrl, $aParams )
00967     {
00968         $sDelim = ( ( getStr()->strpos( $sUrl, '?' ) !== false ) )?'&':'?';
00969         foreach ( $aParams as $sName => $sVal ) {
00970             $sUrl = $sUrl . $sDelim . $sName . '=' . $sVal;
00971             $sDelim = '&';
00972         }
00973 
00974         return $sUrl;
00975     }
00976 
00988     protected function _fillExplodeArray( $aName, $dVat = null)
00989     {
00990         $myConfig = $this->getConfig();
00991         $oObject = new OxstdClass();
00992         $aPrice = explode( '!P!', $aName[0]);
00993 
00994         if ( ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) && isset( $aPrice[0] ) && isset( $aPrice[1] ) ) || $this->isAdmin() ) {
00995 
00996             // yes, price is there
00997             $oObject->price = $aPrice[1];
00998             $aName[0] = $aPrice[0];
00999 
01000             $iPercPos = getStr()->strpos( $oObject->price, '%' );
01001             if ( $iPercPos !== false ) {
01002                 $oObject->priceUnit = '%';
01003                 $oObject->fprice = $oObject->price;
01004                 $oObject->price  = substr( $oObject->price, 0, $iPercPos );
01005             } else {
01006                 $oCur = $myConfig->getActShopCurrencyObject();
01007                 $oObject->price = str_replace(',', '.', $oObject->price);
01008                 $oObject->fprice = oxLang::getInstance()->formatCurrency( $oObject->price  * $oCur->rate, $oCur);
01009                 $oObject->priceUnit = 'abs';
01010             }
01011 
01012             // add price info into list
01013             if ( !$this->isAdmin() && $oObject->price != 0 ) {
01014                 $aName[0] .= " ";
01015                 if ( $oObject->price > 0 ) {
01016                     $aName[0] .= "+";
01017                 }
01018                 //V FS#2616
01019                 if ( $dVat != null && $oObject->priceUnit == 'abs' ) {
01020                     $oPrice = oxNew('oxPrice');
01021                     $oPrice->setPrice($oObject->price, $dVat);
01022                     $aName[0] .= oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() * $oCur->rate, $oCur);
01023                 } else {
01024                     $aName[0] .= $oObject->fprice;
01025                 }
01026                 if ( $oObject->priceUnit == 'abs' ) {
01027                     $aName[0] .= " ".$oCur->sign;
01028                 }
01029             }
01030         } elseif ( isset( $aPrice[0] ) && isset($aPrice[1] ) ) {
01031             // A. removing unused part of information
01032             $aName[0] = getStr()->preg_replace( "/!P!.*/", "", $aName[0] );
01033         }
01034 
01035         $oObject->name  = $aName[0];
01036         $oObject->value = $aName[1];
01037         return $oObject;
01038     }
01039 
01047     public function oxMimeContentType( $sFileName )
01048     {
01049         $sFileName = strtolower( $sFileName );
01050         $iLastDot  = strrpos( $sFileName, '.' );
01051 
01052         if ( $iLastDot !== false ) {
01053             $sType = substr( $sFileName, $iLastDot + 1 );
01054             switch ( $sType ) {
01055                 case 'gif':
01056                     $sType = 'image/gif';
01057                     break;
01058                 case 'jpeg':
01059                 case 'jpg':
01060                     $sType = 'image/jpeg';
01061                     break;
01062                 case 'png':
01063                     $sType = 'image/png';
01064                     break;
01065                 default:
01066                     $sType = false;
01067                     break;
01068             }
01069         }
01070         return $sType;
01071     }
01072 
01081     public function logger( $sText, $blNewline = false )
01082     {   $myConfig = $this->getConfig();
01083 
01084         if ( $myConfig->getConfigParam( 'iDebug' ) == -2) {
01085             if ( gettype( $sText ) != 'string' ) {
01086                 $sText = var_export( $sText, true);
01087             }
01088             $sLogMsg = "----------------------------------------------\n{$sText}".( ( $blNewline ) ?"\n":"" )."\n";
01089             $this->writeToLog( $sLogMsg, "log.txt" );
01090         }
01091 
01092     }
01093 
01101     protected function _stripQuotes($mInput)
01102     {
01103         return is_array($mInput) ? array_map( array( $this, '_stripQuotes' ), $mInput) : stripslashes( $mInput );
01104     }
01105 
01113     public function strRot13( $sStr )
01114     {
01115         $sFrom = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
01116         $sTo   = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
01117 
01118         return strtr( $sStr, $sFrom, $sTo );
01119     }
01120 
01121 
01132     public function prepareUrlForNoSession( $sUrl )
01133     {
01134         if ( $this->seoIsActive() ) {
01135             return $sUrl;
01136         }
01137 
01138         return oxUtilsUrl::getInstance()->prepareUrlForNoSession( $sUrl );
01139     }
01140 
01151     protected function _getCacheFilePath( $sCacheName, $blPathOnly = false )
01152     {
01153         return $this->getCacheFilePath( $sCacheName, $blPathOnly );
01154     }
01155 
01165     public function getCacheFilePath( $sCacheName, $blPathOnly = false, $sExtension = 'txt' )
01166     {
01167         $sVersionPrefix = "";
01168 
01169 
01170             $sVersionPrefix = 'pe';
01171 
01172         $sPath = realpath($this->getConfig()->getConfigParam( 'sCompileDir' ));
01173 
01174         if (!$sPath) {
01175             return false;
01176         }
01177 
01178         return $blPathOnly ? "{$sPath}/" : "{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}." . $sExtension;
01179     }
01180 
01188     public function getLangCache( $sCacheName )
01189     {
01190         $aLangCache = null;
01191         $sFilePath = $this->getCacheFilePath( $sCacheName );
01192         if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
01193             include $sFilePath;
01194         }
01195         return $aLangCache;
01196     }
01197 
01206     public function setLangCache( $sCacheName, $aLangCache )
01207     {
01208         $sCache = "<?php\n\$aLangCache = ".var_export( $aLangCache, true ).";";
01209         $blRes = file_put_contents($this->getCacheFilePath($sCacheName), $sCache);
01210         return $blRes;
01211     }
01212 
01220     public function checkUrlEndingSlash( $sUrl )
01221     {
01222         if ( !getStr()->preg_match("/\/$/", $sUrl) ) {
01223             $sUrl .= '/';
01224         }
01225 
01226         return $sUrl;
01227     }
01228 
01237     public function writeToLog( $sLogMessage, $sLogFileName )
01238     {
01239         $sLogDist = $this->getConfig()->getLogsDir().$sLogFileName;
01240         $blOk = false;
01241 
01242         if ( ( $oHandle = fopen( $sLogDist, 'a' ) ) !== false ) {
01243             fwrite( $oHandle, $sLogMessage );
01244             $blOk = fclose( $oHandle );
01245         }
01246 
01247         return $blOk;
01248     }
01249 
01257     public function handlePageNotFoundError($sUrl = '')
01258     {
01259         $this->setHeader("HTTP/1.0 404 Not Found");
01260         $sReturn = "Page not found.";
01261         try {
01262             $oView = oxNew('oxubase');
01263             $oView->init();
01264             $oView->render();
01265             $oView->addTplParam('sUrl', $sUrl);
01266             if ($sRet = oxUtilsView::getInstance()->getTemplateOutput('err_404.tpl', $oView)) {
01267                 $sReturn = $sRet;
01268             }
01269         } catch (Exception $e) {
01270         }
01271         $this->showMessageAndExit( $sReturn );
01272     }
01273 }

Generated by  doxygen 1.6.2