6 require_once getShopBasePath().
"core/smarty/Smarty.class.php";
98 if (!get_magic_quotes_gpc()) {
117 public function strMan( $sVal, $sKey = null )
119 $oEncryptor =
oxNew(
'oxEncryptor');
120 $sKey = $sKey ? $sKey : $this->
getConfig()->getConfigParam(
'sConfigKey');
122 return $oEncryptor->encrypt($sVal, $sKey);
135 public function strRem( $sVal, $sKey = null )
137 $oDecryptor =
oxNew(
'oxDecryptor');
138 $sKey = $sKey ? $sKey : $this->
getConfig()->getConfigParam(
'sConfigKey');
140 return $oDecryptor->decrypt($sVal, $sKey);
152 return str_replace(
".",
"__", $sName);
166 $aPieces = explode(
'@@', $sIn );
167 while ( list( $sKey, $sVal ) = each( $aPieces ) ) {
169 $aName = explode(
'__', $sVal );
170 if ( isset( $aName[0] ) && isset( $aName[1] ) ) {
189 while (list($sKey, $sVal) = each($aIn)) {
208 $iPos = strrpos( $sValue,
".");
209 if ($iPos && ((strlen($sValue)-1-$iPos) < 2+1)) {
211 $fRet = substr_replace( $fRet,
",", $iPos, 1);
214 $fRet = str_replace( array(
" ",
"."),
"", $fRet);
216 $fRet = str_replace(
",",
".", $fRet);
217 return (
float) $fRet;
229 $fRet = str_replace(
" ",
"", $sValue);
230 $iCommaPos = strpos( $fRet,
",");
231 $iDotPos = strpos( $fRet,
".");
232 if (!$iDotPos xor !$iCommaPos) {
233 if (substr_count( $fRet,
",") > 1 || substr_count( $fRet,
".") > 1) {
234 $fRet = str_replace( array(
",",
"."),
"", $fRet);
236 $fRet = str_replace(
",",
".", $fRet);
238 }
else if ( $iDotPos < $iCommaPos ) {
239 $fRet = str_replace(
".",
"", $fRet);
240 $fRet = str_replace(
",",
".", $fRet);
243 $fRet = str_replace( array(
" ",
","),
"", $fRet);
244 return (
float) $fRet;
256 if (is_null($this->_blIsSe)) {
272 if (isset($blIsSe)) {
273 $this->_blIsSe = $blIsSe;
276 startProfile(
"isSearchEngine");
282 $aRobots =
$myConfig->getConfigParam(
'aRobots' );
283 $aRobots = is_array( $aRobots )?$aRobots:array();
285 $aRobotsExcept =
$myConfig->getConfigParam(
'aRobotsExcept' );
286 $aRobotsExcept = is_array( $aRobotsExcept )?$aRobotsExcept:array();
288 $sClient = $sClient?$sClient:strtolower( getenv(
'HTTP_USER_AGENT' ) );
290 $aRobots = array_merge( $aRobots, $aRobotsExcept );
291 foreach ( $aRobots as $sRobot ) {
292 if ( strpos( $sClient, $sRobot ) !==
false ) {
299 $this->_blIsSe = $blIsSe;
301 stopProfile(
"isSearchEngine");
315 if ( $sEmail !=
'admin' ) {
316 $sEmailTpl =
"/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/i";
317 $blValid = (
getStr()->preg_match( $sEmailTpl, $sEmail ) != 0 );
334 if ( is_array( $aInterfaceProfiles ) ) {
336 $sPrevProfile =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'oxidadminprofile');
337 if (isset($sPrevProfile)) {
338 $aPrevProfile = @explode(
"@", trim($sPrevProfile));
342 $aProfiles = array();
343 foreach ( $aInterfaceProfiles as $iPos => $sProfile) {
344 $aProfileSettings = array($iPos, $sProfile);
345 $aProfiles[] = $aProfileSettings;
348 if (isset($aPrevProfile[0]) && isset($aProfiles[$aPrevProfile[0]])) {
349 $aProfiles[$aPrevProfile[0]][2] = 1;
366 public function fRound($sVal, $oCur = null)
368 startProfile(
'fround');
371 $iCurPrecision = null;
372 if (! defined(
'OXID_PHP_UNIT')) {
376 if (is_null($iCurPrecision)) {
378 $oCur = $this->
getConfig()->getActShopCurrencyObject();
381 $iCurPrecision = $oCur->decimal;
382 $this->_iCurPrecision = $iCurPrecision;
386 static $dprez = null;
388 $prez = @ini_get(
"precision");
389 if (!$prez || $prez > 12 ) {
392 $dprez = pow(10, -$prez);
394 stopProfile(
'fround');
395 return round($sVal + $dprez * ( $sVal >= 0 ? 1 : -1 ), $iCurPrecision);
411 $this->_aStaticCache[$sName][$sKey] = $sContent;
413 $this->_aStaticCache[$sName] = $sContent;
426 if ( isset( $this->_aStaticCache[$sName])) {
427 return $this->_aStaticCache[$sName];
442 unset($this->_aStaticCache[$sCacheName]);
444 $this->_aStaticCache = null;
460 if ( is_array( $mContents ) && ( $sCachePath = $this->
getCacheFilePath( $sKey,
false,
'php' ) ) ) {
463 $this->
setCacheMeta( $sKey, array(
"serialize" =>
false,
"cachepath" => $sCachePath ) );
493 return isset( $this->_aFileCacheMeta[$sKey] ) ? $this->_aFileCacheMeta[$sKey] :
false;
507 $this->_aFileCacheMeta[$sKey] = $aMeta;
522 $aCacheData[
'content'] = $mContents;
525 $aCacheData[
'ttl'] = $iTtl;
528 $this->_aFileCacheContents[$sKey] = $aCacheData;
531 $sCachePath = isset( $aMeta[
"cachepath"] ) ? $aMeta[
"cachepath"] : $this->
getCacheFilePath( $sKey );
532 return (
bool ) $this->
_lockFile( $sCachePath, $sKey );
544 if ( !array_key_exists( $sKey, $this->_aFileCacheContents ) ) {
548 $blInclude = isset( $aMeta[
"include"] ) ? $aMeta[
"include"] :
false;
549 $sCachePath = isset( $aMeta[
"cachepath"] ) ? $aMeta[
"cachepath"] : $this->
getCacheFilePath( $sKey );
552 $this->
_lockFile( $sCachePath, $sKey, LOCK_SH );
555 if ( is_readable( $sCachePath ) ) {
559 if ( isset( $sRes[
'ttl'] ) && $sRes[
'ttl'] != 0 ) {
560 $iTimestamp = $sRes[
'timestamp'];
561 $iTtl = $sRes[
'ttl'];
564 if ( $iTime > $iTimestamp + $iTtl ) {
572 $this->_aFileCacheContents[$sKey] = $sRes;
575 return $this->_aFileCacheContents[$sKey][
'content'];
587 $sRes = file_get_contents( $sFilePath );
588 return $sRes ? unserialize( $sRes ) : null;
600 $_aCacheContents = null;
602 return $_aCacheContents;
617 $blSerialize = isset( $aCacheMeta[
"serialize"] ) ? $aCacheMeta[
"serialize"] :
true;
619 if ( $blSerialize ) {
620 $mContents = serialize( $mContents );
622 $mContents =
"<?php\n//automatically generated file\n//" . date(
"Y-m-d H:i:s" ) .
"\n\n\$_aCacheContents = " . var_export( $mContents,
true ) .
"\n?>";
636 if ( count( $this->_aLockedFileHandles[LOCK_EX] ) ) {
637 startProfile(
"!__SAVING CACHE__! (warning)");
638 foreach ( $this->_aLockedFileHandles[LOCK_EX] as $sKey => $rHandle ) {
639 if ( $rHandle !==
false && isset( $this->_aFileCacheContents[$sKey] ) ) {
642 ftruncate( $rHandle, 0 );
645 fwrite( $rHandle, $this->
_processCache( $sKey, $this->_aFileCacheContents[$sKey] ) );
652 stopProfile(
"!__SAVING CACHE__! (warning)");
655 $this->_aFileCacheContents = array();
668 protected function _lockFile( $sFilePath, $sIdent, $iLockMode = LOCK_EX )
670 $rHandle = isset( $this->_aLockedFileHandles[$iLockMode][$sIdent] ) ? $this->_aLockedFileHandles[$iLockMode][$sIdent] : null;
671 if ( $rHandle === null ) {
674 $rHandle = @fopen( $sFilePath,
"a+" );
676 if ( $rHandle !==
false ) {
678 if ( flock( $rHandle, $iLockMode | LOCK_NB ) ) {
679 if ( $iLockMode === LOCK_EX ) {
681 $blLocked = ftruncate( $rHandle, 0 );
684 $blLocked = fseek( $rHandle, 0 ) === 0;
696 if ( !$blLocked && $iLockMode === LOCK_EX ) {
699 if ( count( $this->_aLockedFileHandles ) == 0 ) {
704 if (!( file_exists( $sFilePath ) && !filesize( $sFilePath ) && abs( time() - filectime( $sFilePath ) < 40 ) ) ) {
705 $rHandle = @fopen( $sFilePath,
"w" );
709 $this->_aLockedFileHandles[$iLockMode][$sIdent] = $rHandle;
726 if ( isset( $this->_aLockedFileHandles[$iLockMode][$sIdent] ) &&
727 $this->_aLockedFileHandles[$iLockMode][$sIdent] !==
false ) {
730 $blSuccess = flock( $this->_aLockedFileHandles[$iLockMode][$sIdent], LOCK_UN ) &&
731 fclose( $this->_aLockedFileHandles[$iLockMode][$sIdent] );
732 unset( $this->_aLockedFileHandles[$iLockMode][$sIdent] );
748 if ( is_array( $aFiles ) ) {
750 $aFiles = preg_grep( $this->_sPermanentCachePattern, $aFiles, PREG_GREP_INVERT );
751 foreach ( $aFiles as $sFile ) {
768 $aFiles = glob( $sSmartyDir .
'*' );
770 if ( is_array( $aFiles ) && is_array( $aTemplates ) && count($aTemplates) ) {
772 foreach ($aTemplates as &$sTemplate) {
773 $sTemplate = preg_quote(basename(strtolower($sTemplate),
'.tpl'));
776 $sPattern = sprintf(
"/%%(%s)\.tpl\.php$/i", implode(
'|', $aTemplates));
777 $aFiles = preg_grep( $sPattern, $aFiles );
779 if (is_array( $aFiles ) ) {
780 foreach ( $aFiles as $sFile ) {
796 if ( is_array( $aFiles ) ) {
799 $aFiles = preg_grep( $sPattern, $aFiles );
800 foreach ( $aFiles as $sFile ) {
814 if ( is_array( $aFiles ) ) {
817 $aFiles = preg_grep( $sPattern, $aFiles );
818 foreach ( $aFiles as $sFile ) {
836 if ( file_exists( $sLocal ) && filemtime( $sLocal ) && filemtime( $sLocal ) > time() - 86400 ) {
839 $hRemote = @fopen( $sRemote,
"rb");
841 if ( isset( $hRemote) && $hRemote ) {
842 $hLocal = fopen( $sLocal,
"wb");
843 stream_copy_to_stream($hRemote, $hLocal);
849 $aUrl = @parse_url( $sRemote);
850 if ( !empty( $aUrl[
"host"])) {
851 $sPath = $aUrl[
"path"];
852 if ( empty( $sPath ) ) {
855 $sHost = $aUrl[
"host"];
857 $hSocket = @fsockopen( $sHost, 80, $iErrorNumber, $iErrStr, 5);
859 fputs( $hSocket,
"GET ".$sPath.
" HTTP/1.0\r\nHost: $sHost\r\n\r\n");
860 $headers = stream_get_line($hSocket, 4096,
"\r\n\r\n");
861 if ( ( $hLocal = @fopen( $sLocal,
"wb") ) !==
false ) {
865 fwrite ( $hLocal, stream_get_contents( $hSocket ) );
873 if ( $blSuccess || file_exists( $sLocal ) ) {
888 ( $sAdminSid =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'admin_sid' ) ) ) {
890 $sTable = getViewName(
'oxuser' );
892 $sQ =
"select 1 from $sTable where MD5( CONCAT( ".$oDb->quote($sAdminSid).
", {$sTable}.oxid, {$sTable}.oxpassword, {$sTable}.oxrights ) ) = ".
oxDb::getDb()->quote($sPrevId);
893 $blCan = (bool) $oDb->getOne( $sQ );
906 $sAdminSid =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'admin_sid' );
907 if ( ( $oUser = $this->
getUser() ) ) {
908 return md5( $sAdminSid . $oUser->getId() . $oUser->oxuser__oxpassword->value . $oUser->oxuser__oxrights->value );
929 $myConfig->setConfigParam(
'blMallAdmin',
false );
931 $myConfig->setConfigParam(
'blAllowInheritedEdit',
false );
936 $sRights = $oDb->getOne(
"select oxrights from oxuser where oxid = ".$oDb->quote($sUserID));
938 if ( $sRights !=
"user") {
940 if ( $sRights ==
"malladmin") {
942 $myConfig->setConfigParam(
'blMallAdmin',
true );
946 $myConfig->setConfigParam(
'blAllowSharedEdit',
true );
949 if ( !isset($sShop)) {
955 $sShopID = $oDb->getOne(
"select oxid from oxshops where oxid = " . $oDb->quote( $sRights ) );
956 if ( isset( $sShopID) && $sShopID) {
970 $aShopIdVars = array(
'actshop',
'shp',
'currentadminshop');
971 foreach ($aShopIdVars as $sShopIdVar) {
973 if ($sGotShop != $sRights) {
998 public function seoIsActive( $blReset =
false, $sShopId = null, $iActLang = null )
1000 if ( !is_null( $this->_blSeoIsActive ) && !$blReset ) {
1006 if ( ( $this->_blSeoIsActive =
$myConfig->getConfigParam(
'blSeoMode' ) ) === null ) {
1007 $this->_blSeoIsActive =
true;
1009 $aSeoModes =
$myConfig->getconfigParam(
'aSeoModes' );
1010 $sActShopId = $sShopId ? $sShopId :
$myConfig->getActiveShop()->getId();
1014 if ( is_array( $aSeoModes ) && isset( $aSeoModes[$sActShopId] ) && isset( $aSeoModes[$sActShopId][$iActLang] ) ) {
1015 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
1031 return (
boolean)
getStr()->preg_match(
'/^[a-zA-Z0-9_]*$/', $sField );
1045 $oHeader =
oxNew(
"oxHeader" );
1046 $oHeader->setHeader( $sHeaderCode );
1047 $oHeader->setHeader(
"Location: $sUrl" );
1048 $oHeader->setHeader(
"Connection: close" );
1049 $oHeader->sendHeader();
1059 $sUrl = $this->
getConfig()->getShopUrl() .
'offline.html';
1060 $this->
redirect($sUrl,
false, $iHeaderCode);
1072 public function redirect( $sUrl, $blAddRedirectParam =
true, $iHeaderCode = 302 )
1080 if ( $blAddRedirectParam ) {
1084 $sUrl = str_ireplace(
"&",
"&", $sUrl );
1086 switch ($iHeaderCode) {
1088 $sHeaderCode =
"HTTP/1.1 301 Moved Permanently";
1091 $sHeaderCode =
"HTTP/1.1 500 Internal Server Error";
1095 $sHeaderCode =
"HTTP/1.1 302 Found";
1107 if ( defined(
'OXID_PHP_UNIT' ) ) {
1127 if ( defined(
'OXID_PHP_UNIT' ) ) {
1157 $sDelimiter = ( (
getStr()->strpos( $sUrl,
'?' ) !== false ) )?
'&':
'?';
1158 foreach ( $aParams as $sName => $sVal ) {
1159 $sUrl = $sUrl . $sDelimiter . $sName .
'=' . $sVal;
1180 $oObject =
new stdClass();
1181 $aPrice = explode(
'!P!', $aName[0]);
1183 if ( (
$myConfig->getConfigParam(
'bl_perfLoadSelectLists' ) &&
$myConfig->getConfigParam(
'bl_perfUseSelectlistPrice' ) && isset( $aPrice[0] ) && isset( $aPrice[1] ) ) || $this->
isAdmin() ) {
1186 $oObject->price = isset( $aPrice[1] ) ? $aPrice[1] : 0;
1187 $aName[0] = isset( $aPrice[0] ) ? $aPrice[0] :
'';
1189 $iPercPos =
getStr()->strpos( $oObject->price,
'%' );
1190 if ( $iPercPos !==
false ) {
1191 $oObject->priceUnit =
'%';
1192 $oObject->fprice = $oObject->price;
1193 $oObject->price = substr( $oObject->price, 0, $iPercPos );
1195 $oCur =
$myConfig->getActShopCurrencyObject();
1196 $oObject->price = str_replace(
',',
'.', $oObject->price);
1197 $oObject->fprice =
oxRegistry::getLang()->formatCurrency( $oObject->price * $oCur->rate, $oCur);
1198 $oObject->priceUnit =
'abs';
1202 if ( !$this->
isAdmin() && $oObject->price != 0 ) {
1207 if ( $oObject->price > 0 ) {
1211 if ( $dVat != null && $oObject->priceUnit ==
'abs' ) {
1212 $oPrice =
oxNew(
'oxPrice');
1213 $oPrice->setPrice($oObject->price, $dVat);
1216 $aName[0] .= $oObject->fprice;
1218 if ( $oObject->priceUnit ==
'abs' ) {
1219 $aName[0] .=
" ".$oCur->sign;
1222 } elseif ( isset( $aPrice[0] ) && isset($aPrice[1] ) ) {
1224 $aName[0] =
getStr()->preg_replace(
"/!P!.*/",
"", $aName[0] );
1227 $oObject->name = $aName[0];
1228 $oObject->value = $aName[1];
1244 $oCurrency = $this->
getConfig()->getActShopCurrencyObject();
1246 $blEnterNetPrice = $this->
getConfig()->getConfigParam(
'blEnterNetPrice');
1247 if ( $blCalculationModeNetto && !$blEnterNetPrice ) {
1249 } elseif ( !$blCalculationModeNetto && $blEnterNetPrice ) {
1263 $blResult = (bool) $this->
getConfig()->getConfigParam(
'blShowNetPrice');
1266 $blResult = $oUser->isPriceViewModeNetto();
1279 if ($this->_oUser) {
1280 return $this->_oUser;
1295 $sFileName = strtolower( $sFileName );
1296 $iLastDot = strrpos( $sFileName,
'.' );
1298 if ( $iLastDot !==
false ) {
1299 $sType = substr( $sFileName, $iLastDot + 1 );
1302 $sType =
'image/gif';
1306 $sType =
'image/jpeg';
1309 $sType =
'image/png';
1327 public function logger( $sText, $blNewline =
false )
1330 if (
$myConfig->getConfigParam(
'iDebug' ) == -2) {
1331 if ( gettype( $sText ) !=
'string' ) {
1332 $sText = var_export( $sText,
true);
1334 $sLogMsg =
"----------------------------------------------\n{$sText}".( ( $blNewline ) ?
"\n":
"" ).
"\n";
1349 return is_array($mInput) ? array_map( array( $this,
'_stripQuotes' ), $mInput) : stripslashes( $mInput );
1361 $sFrom =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
1362 $sTo =
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
1364 return strtr( $sStr, $sFrom, $sTo );
1379 $sVersionPrefix =
'pe';
1381 $sPath = realpath($this->
getConfig()->getConfigParam(
'sCompileDir' ));
1387 return $blPathOnly ?
"{$sPath}/" :
"{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}." . $sExtension;
1401 if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
1417 $sCache =
"<?php\n\$aLangCache = ".var_export( $aLangCache,
true ).
";\n?>";
1418 $blRes = file_put_contents($this->
getCacheFilePath($sCacheName), $sCache, LOCK_EX);
1431 if ( !
getStr()->preg_match(
"/\/$/", $sUrl) ) {
1448 $sLogDist = $this->
getConfig()->getLogsDir().$sLogFileName;
1451 if ( ( $oHandle = fopen( $sLogDist,
'a' ) ) !==
false ) {
1452 fwrite( $oHandle, $sLogMessage );
1453 $blOk = fclose( $oHandle );
1468 $this->
setHeader(
"HTTP/1.0 404 Not Found");
1470 $this->
setHeader(
"Content-Type: text/html; charset=UTF-8");
1473 $sReturn =
"Page not found.";
1475 $oView =
oxNew(
'oxUBase');
1478 $oView->setClassName(
'oxUBase' );
1479 $oView->addTplParam(
'sUrl', $sUrl);
1480 if ($sRet =
oxRegistry::get(
"oxUtilsView")->getTemplateOutput(
'message/err_404.tpl', $oView)) {
1498 if ( !$oStr->preg_match(
'/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $sHost ) &&
1499 ( $iLastDot = strrpos( $sHost,
'.' ) ) !==
false ) {
1500 $iLen = $oStr->strlen( $sHost );
1501 if ( ( $iNextDot = strrpos( $sHost,
'.', ( $iLen - $iLastDot + 1 ) * - 1 ) ) !==
false ) {
1502 $sHost = trim( $oStr->substr( $sHost, $iNextDot ),
'.' );