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     public static function getInstance()
00057     {
00058         // disable caching for test modules
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( (double)$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             // replace decimal with ","
00236             $fRet = substr_replace( $fRet, ",", $iPos, 1);
00237         }
00238         // remove thousands
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             // caching
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 = ( getStr()->preg_match( $this->_sEmailTpl, $sEmail ) != 0 );
00298         }
00299 
00300         return $blValid;
00301     }
00302 
00308     public function rebuildCache()
00309     {
00310         // not needed from 3.0 on and unused <- MK: not correct, its used for example in shop_config.php, oxbase.php
00311 
00312         //$smarty  = & oxUtils::getInstance()->getSmarty();
00313         //$smarty->clear_all_cache();
00314 
00315         if ( function_exists( "UserdefinedRebuildCache")) {
00316             UserdefinedRebuildCache();
00317         }
00318     }
00319 
00327     public function loadAdminProfile($aInterfaceProfiles)
00328     {
00329         // improved #533
00330         // checking for available profiles list
00331         $aInterfaceProfiles = $aInterfaceProfiles;
00332         if ( is_array( $aInterfaceProfiles ) ) {
00333             //checking for previous profiles
00334             $sPrevProfile = oxUtilsServer::getInstance()->getOxCookie('oxidadminprofile');
00335             if (isset($sPrevProfile)) {
00336                 $aPrevProfile = @explode("@", trim($sPrevProfile));
00337             }
00338 
00339             //array to store profiles
00340             $aProfiles = array();
00341             foreach ( $aInterfaceProfiles as $iPos => $sProfile) {
00342                 $aProfileSettings = array($iPos, $sProfile);
00343                 $aProfiles[] = $aProfileSettings;
00344             }
00345             // setting previous used profile as active
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         //cached currency precision, this saves about 1% of execution time
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         // this is a workaround for #36008 bug in php - incorrect round() & number_format() result (R)
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         // if it's an array then we add
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         //T2009-05-26
00465         //due to possible race conditions
00466         //check if there are any other cache files already opened for writing by another process
00467         //additionally perform the check for older (aged 40 or more secs) locked files
00468         clearstatcache();
00469         if (!isset($this->_aFileCacheContents[$sKey]) && file_exists($sFilePath) && (!filesize($sFilePath)) && abs($iCurTime - filectime($sFilePath) < 40) ) {
00470             //then leave the cache to be dealt by another process and do nothing
00471             return false;
00472         }
00473         //the above code ensures that $_aFileCacheContet is writen only in case cache file has not been started
00474         //by another process
00475         if (!isset($this->_aFileCacheContents[$sKey])) {
00476             //start a blank file to inform other processes we are dealing with it.
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 
00502         if (!$sFilePath) {
00503             return;
00504         }
00505 
00506         $sDate = date("Y-m-d H:i:s");
00507         $sVarName = '$_aCacheContents';
00508 
00509         //only simple arrays are supported
00510         if (!is_array($mContents))
00511             return;
00512 
00513         $sContents = "<?php ?>";
00514         if (is_array($mContents)) {
00515             $sContents  = "<?php\n//automatically generated file\n//$sDate\n\n$sVarName = array (\n";
00516             foreach ($mContents as $sKey => $mVal) {
00517                 if (!is_numeric($mVal)) {
00518                     $mVal = "'$mVal'";
00519                 }
00520                 if (!is_numeric($sKey)) {
00521                     $sKey = "'$sKey'";
00522                 }
00523                 $sContents .= "  $sKey => $mVal,\n";
00524             }
00525             $sContents .= ");\n?>";
00526         }
00527 
00528         $hFile = fopen( $sFilePath, "w");
00529         if ( $hFile) {
00530             fwrite( $hFile, $sContents);
00531             fclose( $hFile);
00532         }
00533 
00534     }
00535 
00543     public function fromPhpFileCache($sKey)
00544     {
00545         $sFilePath = $this->getCacheFilePath( $sKey, false, 'php' );
00546 
00547         if (file_exists($sFilePath)) {
00548             include $sFilePath;
00549             return $_aCacheContents;
00550         }
00551 
00552         return null;
00553     }
00554 
00562     public function fromFileCache( $sKey )
00563     {
00564         if ( !isset( $this->_aFileCacheContents[$sKey] ) ) {
00565             $sRes = null;
00566 
00567             // read the file
00568             $sFilePath = $this->getCacheFilePath( $sKey );
00569             if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
00570                 // read it
00571                 $sRes = file_get_contents( $sFilePath );
00572                 $sRes = $sRes ? unserialize( $sRes ) : null;
00573             }
00574 
00575             $this->_aFileCacheContents[$sKey] = $sRes;
00576         }
00577 
00578         return $this->_aFileCacheContents[$sKey];
00579     }
00580 
00586     public function commitFileCache()
00587     {
00588         foreach ($this->_aFileCacheContents as $sKey => $mContents) {
00589             $mContents = serialize($mContents);
00590             $sFilePath = $this->getCacheFilePath( $sKey );
00591             //if ( is_writable($sFilePath))
00592             // dodger: somehow is_writeable() always says no on windows machines
00593             $hFile = fopen( $sFilePath, "w");
00594             if ( $hFile) {
00595                 fwrite( $hFile, $mContents);
00596                 fclose( $hFile);
00597             }
00598         }
00599 
00600         //empty buffer
00601         $this->_aFileCacheContents = array();
00602         clearstatcache ();
00603     }
00604 
00612     public function oxResetFileCache()
00613     {
00614         $aPathes = glob( $this->getCacheFilePath( null, true ) . '*' );
00615         if ( is_array( $aPathes ) ) {
00616             // delete all the files, except cached tables fieldnames
00617             $aPathes = preg_grep( $this->_sPermanentCachePattern, $aPathes, PREG_GREP_INVERT );
00618             foreach ( $aPathes as $sFilename ) {
00619                 @unlink( $sFilename );
00620             }
00621         }
00622     }
00623 
00633     public function getRemoteCachePath($sRemote, $sLocal)
00634     {
00635         clearstatcache();
00636         if ( file_exists( $sLocal ) && filemtime( $sLocal ) && filemtime( $sLocal ) > time() - 86400 ) {
00637             return $sLocal;
00638         }
00639         $hRemote = @fopen( $sRemote, "rb");
00640         $blSuccess = false;
00641         if ( isset( $hRemote) && $hRemote ) {
00642             $hLocal = fopen( $sLocal, "wb");
00643             stream_copy_to_stream($hRemote, $hLocal);
00644             fclose($hRemote);
00645             fclose($hLocal);
00646             $blSuccess = true;
00647         } else {
00648             // try via fsockopen
00649             $aUrl = @parse_url( $sRemote);
00650             if ( !empty( $aUrl["host"])) {
00651                 $sPath = $aUrl["path"];
00652                 if ( empty( $sPath ) ) {
00653                     $sPath = "/";
00654                 }
00655                 $sHost = $aUrl["host"];
00656 
00657                 $hSocket = @fsockopen( $sHost, 80, $iErrorNumber, $iErrStr, 5);
00658                 if ( $hSocket) {
00659                     fputs( $hSocket, "GET ".$sPath." HTTP/1.0\r\nHost: $sHost\r\n\r\n");
00660                     $headers = stream_get_line($hSocket, 4096, "\r\n\r\n");
00661                     if ( ( $hLocal = @fopen( $sLocal, "wb") ) !== false ) {
00662                         rewind($hLocal);
00663                         // does not copy all the data
00664                         // stream_copy_to_stream($hSocket, $hLocal);
00665                         fwrite ( $hLocal, stream_get_contents( $hSocket ) );
00666                         fclose( $hLocal );
00667                         fclose( $hSocket );
00668                         $blSuccess = true;
00669                     }
00670                 }
00671             }
00672         }
00673         if ( $blSuccess || file_exists( $sLocal ) ) {
00674             return $sLocal;
00675         }
00676         return false;
00677     }
00678 
00684     public function checkAccessRights()
00685     {
00686         $myConfig  = $this->getConfig();
00687 
00688         $blIsAuth = false;
00689 
00690         $sUserID = oxSession::getVar( "auth");
00691 
00692         // deleting admin marker
00693         oxSession::setVar( "malladmin", 0);
00694         oxSession::setVar( "blIsAdmin", 0);
00695         oxSession::deleteVar( "blIsAdmin" );
00696         $myConfig->setConfigParam( 'blMallAdmin', false );
00697         //#1552T
00698         $myConfig->setConfigParam( 'blAllowInheritedEdit', false );
00699 
00700         if ( $sUserID) {
00701             // escaping
00702             $oDb = oxDb::getDb();
00703             $sRights = $oDb->getOne("select oxrights from oxuser where oxid = ".$oDb->quote($sUserID));
00704 
00705             if ( $sRights != "user") {
00706                 // malladmin ?
00707                 if ( $sRights == "malladmin") {
00708                     oxSession::setVar( "malladmin", 1);
00709                     $myConfig->setConfigParam( 'blMallAdmin', true );
00710 
00711                     //#1552T
00712                     //So far this blAllowSharedEdit is Equal to blMallAdmin but in future to be solved over rights and roles
00713                     $myConfig->setConfigParam( 'blAllowSharedEdit', true );
00714 
00715                     $sShop = oxSession::getVar( "actshop");
00716                     if ( !isset($sShop)) {
00717                         oxSession::setVar( "actshop", $myConfig->getBaseShopId());
00718                     }
00719                     $blIsAuth = true;
00720                 } else {
00721                     // Shopadmin... check if this shop is valid and exists
00722                     $sShopID = $oDb->getOne("select oxid from oxshops where oxid = " . $oDb->quote( $sRights ) );
00723                     if ( isset( $sShopID) && $sShopID) {
00724                         // success, this shop exists
00725 
00726                         oxSession::setVar( "actshop", $sRights);
00727                         oxSession::setVar( "currentadminshop", $sRights);
00728                         oxSession::setVar( "shp", $sRights);
00729 
00730                         // check if this subshop admin is evil.
00731                         if ('chshp' == oxConfig::getParameter( 'fnc' )) {
00732                             // dont allow this call
00733                             $blIsAuth = false;
00734                         } else {
00735                             $blIsAuth = true;
00736 
00737                             $aShopIdVars = array('actshop', 'shp', 'currentadminshop');
00738                             foreach ($aShopIdVars as $sShopIdVar) {
00739                                 if ($sGotShop = oxConfig::getParameter( $sShopIdVar )) {
00740                                     if ($sGotShop != $sRights) {
00741                                         $blIsAuth = false;
00742                                         break;
00743                                     }
00744                                 }
00745                             }
00746                         }
00747                     }
00748                 }
00749                 // marking user as admin
00750                 oxSession::setVar( "blIsAdmin", 1);
00751             }
00752         }
00753         return $blIsAuth;
00754     }
00755 
00765     public function seoIsActive( $blReset = false, $sShopId = null, $iActLang = null )
00766     {
00767         if ( !is_null( $this->_blSeoIsActive ) && !$blReset ) {
00768             return $this->_blSeoIsActive;
00769         }
00770 
00771         $myConfig = $this->getConfig();
00772 
00773         if ( ( $this->_blSeoIsActive = $myConfig->getConfigParam( 'blSeoMode' ) ) === null ) {
00774             $this->_blSeoIsActive = true;
00775 
00776             $aSeoModes  = $myConfig->getconfigParam( 'aSeoModes' );
00777             $sActShopId = $sShopId ? $sShopId : $myConfig->getActiveShop()->getId();
00778             $iActLang   = $iActLang ? $iActLang : (int) oxLang::getInstance()->getBaseLanguage();
00779 
00780             // checking special config param for active shop and language
00781             if ( is_array( $aSeoModes ) && isset( $aSeoModes[$sActShopId] ) && isset( $aSeoModes[$sActShopId][$iActLang] ) ) {
00782                 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
00783             }
00784         }
00785 
00786         return $this->_blSeoIsActive;
00787     }
00788 
00798     public function getShopBit( $iShopId )
00799     {
00800         $iShopId = (int) $iShopId;
00801         //this works for large numbers when $sShopNr is up to (inclusive) 64
00802         $iRes = oxDb::getDb()->getOne( "select 1 << ( $iShopId - 1 ) as shopbit" );
00803 
00804         //as php ints supports only 32 bits, we return string.
00805         return $iRes;
00806     }
00807 
00817     public function bitwiseAnd( $iVal1, $iVal2 )
00818     {
00819         //this works for large numbers when $sShopNr is up to (inclusive) 64
00820         $iRes = oxDb::getDb()->getOne( "select ($iVal1 & $iVal2) as bitwiseAnd" );
00821 
00822         //as php ints supports only 32 bits, we return string.
00823         return $iRes;
00824     }
00825 
00835     public function bitwiseOr( $iVal1, $iVal2 )
00836     {
00837         //this works for large numbers when $sShopNr is up to (inclusive) 64
00838         $iRes = oxDb::getDb()->getOne( "select ($iVal1 | $iVal2) as bitwiseOr" );
00839 
00840         //as php ints supports only 32 bits, we return string.
00841         return $iRes;
00842     }
00843 
00851     public function isValidAlpha( $sField )
00852     {
00853         return (boolean) getStr()->preg_match( "#^[\w]*$#", $sField );
00854     }
00855 
00865     protected function _simpleRedirect( $sUrl, $sHeaderCode )
00866     {
00867         header( $sHeaderCode );
00868         header( "Location: $sUrl" );
00869         header( "Connection: close" );
00870     }
00871 
00881     public function redirect( $sUrl, $blAddRedirectParam = true, $iHeaderCode = 301 )
00882     {
00883         //preventing possible cyclic redirection
00884         //#M341 and check only if redirect paramater must be added
00885         if ( $blAddRedirectParam && oxConfig::getParameter( 'redirected' ) ) {
00886             return;
00887         }
00888 
00889         if ( $blAddRedirectParam ) {
00890             $sUrl = $this->_addUrlParameters( $sUrl, array( 'redirected' => 1 ) );
00891         }
00892 
00893         $sUrl = str_ireplace( "&amp;", "&", $sUrl );
00894 
00895         $sHeaderCode = '';
00896         switch ($iHeaderCode) {
00897             case 301:
00898                 $sHeaderCode = "HTTP/1.1 301 Moved Permanently";
00899                 break;
00900             case 302:
00901             default:
00902                 $sHeaderCode = "HTTP/1.1 302 Found";
00903         }
00904 
00905         $this->_simpleRedirect( $sUrl, $sHeaderCode );
00906 
00907         try {//may occur in case db is lost
00908             $this->getSession()->freeze();
00909         } catch( oxException $oEx ) {
00910             $oEx->debugOut();
00911             //do nothing else to make sure the redirect takes place
00912         }
00913 
00914         if ( defined( 'OXID_PHP_UNIT' ) ) {
00915             return;
00916         }
00917 
00918         $this->showMessageAndExit( '' );
00919     }
00920 
00928     public function showMessageAndExit( $sMsg )
00929     {
00930         $this->getSession()->freeze();
00931         $this->commitFileCache();
00932 
00933         if ( defined( 'OXID_PHP_UNIT' ) ) {
00934             return;
00935         }
00936 
00937         exit( $sMsg );
00938     }
00939 
00947     public function setHeader($sHeader)
00948     {
00949         header($sHeader);
00950     }
00951 
00960     protected function _addUrlParameters( $sUrl, $aParams )
00961     {
00962         $sDelim = ( ( getStr()->strpos( $sUrl, '?' ) !== false ) )?'&':'?';
00963         foreach ( $aParams as $sName => $sVal ) {
00964             $sUrl = $sUrl . $sDelim . $sName . '=' . $sVal;
00965             $sDelim = '&';
00966         }
00967 
00968         return $sUrl;
00969     }
00970 
00982     protected function _fillExplodeArray( $aName, $dVat = null)
00983     {
00984         $myConfig = $this->getConfig();
00985         $oObject = new OxstdClass();
00986         $aPrice = explode( '!P!', $aName[0]);
00987 
00988         if ( ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) && isset( $aPrice[0] ) && isset( $aPrice[1] ) ) || $this->isAdmin() ) {
00989 
00990             // yes, price is there
00991             $oObject->price = $aPrice[1];
00992             $aName[0] = $aPrice[0];
00993 
00994             $iPercPos = getStr()->strpos( $oObject->price, '%' );
00995             if ( $iPercPos !== false ) {
00996                 $oObject->priceUnit = '%';
00997                 $oObject->fprice = $oObject->price;
00998                 $oObject->price  = substr( $oObject->price, 0, $iPercPos );
00999             } else {
01000                 $oCur = $myConfig->getActShopCurrencyObject();
01001                 $oObject->price = str_replace(',', '.', $oObject->price);
01002                 $oObject->fprice = oxLang::getInstance()->formatCurrency( $oObject->price  * $oCur->rate, $oCur);
01003                 $oObject->priceUnit = 'abs';
01004             }
01005 
01006             // add price info into list
01007             if ( !$this->isAdmin() && $oObject->price != 0 ) {
01008                 $aName[0] .= " ";
01009                 if ( $oObject->price > 0 ) {
01010                     $aName[0] .= "+";
01011                 }
01012                 //V FS#2616
01013                 if ( $dVat != null && $oObject->priceUnit == 'abs' ) {
01014                     $oPrice = oxNew('oxPrice');
01015                     $oPrice->setPrice($oObject->price, $dVat);
01016                     $aName[0] .= oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() * $oCur->rate, $oCur);
01017                 } else {
01018                     $aName[0] .= $oObject->fprice;
01019                 }
01020                 if ( $oObject->priceUnit == 'abs' ) {
01021                     $aName[0] .= " ".$oCur->sign;
01022                 }
01023             }
01024         } elseif ( isset( $aPrice[0] ) && isset($aPrice[1] ) ) {
01025             // A. removing unused part of information
01026             $aName[0] = getStr()->preg_replace( "/!P!.*/", "", $aName[0] );
01027         }
01028 
01029         $oObject->name  = $aName[0];
01030         $oObject->value = $aName[1];
01031         return $oObject;
01032     }
01033 
01041     public function oxMimeContentType( $sFileName )
01042     {
01043         $sFileName = strtolower( $sFileName );
01044         $iLastDot  = strrpos( $sFileName, '.' );
01045 
01046         if ( $iLastDot !== false ) {
01047             $sType = substr( $sFileName, $iLastDot + 1 );
01048             switch ( $sType ) {
01049                 case 'gif':
01050                     $sType = 'image/gif';
01051                     break;
01052                 case 'jpeg':
01053                 case 'jpg':
01054                     $sType = 'image/jpeg';
01055                     break;
01056                 case 'png':
01057                     $sType = 'image/png';
01058                     break;
01059                 default:
01060                     $sType = false;
01061                     break;
01062             }
01063         }
01064         return $sType;
01065     }
01066 
01075     public function logger( $sText, $blNewline = false )
01076     {   $myConfig = $this->getConfig();
01077 
01078         if ( $myConfig->getConfigParam( 'iDebug' ) == -2) {
01079             if ( gettype( $sText ) != 'string' ) {
01080                 $sText = var_export( $sText, true);
01081             }
01082             $sLogMsg = "----------------------------------------------\n{$sText}".( ( $blNewline ) ?"\n":"" )."\n";
01083             $this->writeToLog( $sLogMsg, "log.txt" );
01084         }
01085 
01086     }
01087 
01095     protected function _stripQuotes($mInput)
01096     {
01097         return is_array($mInput) ? array_map( array( $this, '_stripQuotes' ), $mInput) : stripslashes( $mInput );
01098     }
01099 
01107     public function strRot13( $sStr )
01108     {
01109         $sFrom = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
01110         $sTo   = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
01111 
01112         return strtr( $sStr, $sFrom, $sTo );
01113     }
01114 
01115 
01126     public function prepareUrlForNoSession( $sUrl )
01127     {
01128         if ( $this->seoIsActive() ) {
01129             return $sUrl;
01130         }
01131 
01132         return oxUtilsUrl::getInstance()->prepareUrlForNoSession( $sUrl );
01133     }
01134 
01145     protected function _getCacheFilePath( $sCacheName, $blPathOnly = false )
01146     {
01147         return $this->getCacheFilePath( $sCacheName, $blPathOnly );
01148     }
01149 
01159     public function getCacheFilePath( $sCacheName, $blPathOnly = false, $sExtension = 'txt' )
01160     {
01161         $sVersionPrefix = "";
01162 
01163 
01164             $sVersionPrefix = 'pe';
01165 
01166         $sPath = realpath($this->getConfig()->getConfigParam( 'sCompileDir' ));
01167 
01168         if (!$sPath) {
01169             return false;
01170         }
01171 
01172         return $blPathOnly ? "{$sPath}/" : "{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}." . $sExtension;
01173     }
01174 
01182     public function getLangCache( $sCacheName )
01183     {
01184         $aLangCache = null;
01185         $sFilePath = $this->getCacheFilePath( $sCacheName );
01186         if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
01187             include $sFilePath;
01188         }
01189         return $aLangCache;
01190     }
01191 
01200     public function setLangCache( $sCacheName, $aLangCache )
01201     {
01202         $sCache = "<?php\n\$aLangCache = ".var_export( $aLangCache, true ).";";
01203         $blRes = file_put_contents($this->getCacheFilePath($sCacheName), $sCache);
01204         return $blRes;
01205     }
01206 
01214     public function checkUrlEndingSlash( $sUrl )
01215     {
01216         if ( !getStr()->preg_match("/\/$/", $sUrl) ) {
01217             $sUrl .= '/';
01218         }
01219 
01220         return $sUrl;
01221     }
01222 
01231     public function writeToLog( $sLogMessage, $sLogFileName )
01232     {
01233         $sLogDist = $this->getConfig()->getLogsDir().$sLogFileName;
01234         $blOk = false;
01235 
01236         if ( ( $oHandle = fopen( $sLogDist, 'a' ) ) !== false ) {
01237             fwrite( $oHandle, $sLogMessage );
01238             $blOk = fclose( $oHandle );
01239         }
01240 
01241         return $blOk;
01242     }
01243 
01251     public function handlePageNotFoundError($sUrl = '')
01252     {
01253         $this->setHeader("HTTP/1.0 404 Not Found");
01254         $sReturn = "Page not found.";
01255         try {
01256             $oView = oxNew('oxubase');
01257             $oView->init();
01258             $oView->render();
01259             $oView->addTplParam('sUrl', $sUrl);
01260             if ($sRet = oxUtilsView::getInstance()->getTemplateOutput('err_404.tpl', $oView)) {
01261                 $sReturn = $sRet;
01262             }
01263         } catch (Exception $e) {
01264         }
01265         $this->showMessageAndExit( $sReturn );
01266     }
01267 }

Generated by  doxygen 1.6.2