6 require_once getShopBasePath() .
"core/smarty/Smarty.class.php";
90 public function strMan($sVal, $sKey = null)
92 $oEncryptor =
oxNew(
'oxEncryptor');
93 $sKey = $sKey ? $sKey : $this->
getConfig()->getConfigParam(
'sConfigKey');
95 return $oEncryptor->encrypt($sVal, $sKey);
108 public function strRem($sVal, $sKey = null)
110 $oDecryptor =
oxNew(
'oxDecryptor');
111 $sKey = $sKey ? $sKey : $this->
getConfig()->getConfigParam(
'sConfigKey');
113 return $oDecryptor->decrypt($sVal, $sKey);
125 return str_replace(
".",
"__", $sName);
139 $aPieces = explode(
'@@', $sIn);
140 while (list($sKey, $sVal) = each($aPieces)) {
142 $aName = explode(
'__', $sVal);
143 if (isset($aName[0]) && isset($aName[1])) {
163 while (list($sKey, $sVal) = each($aIn)) {
183 $iPos = strrpos($sValue,
".");
184 if ($iPos && ((strlen($sValue) - 1 - $iPos) < 2 + 1)) {
186 $fRet = substr_replace($fRet,
",", $iPos, 1);
189 $fRet = str_replace(array(
" ",
"."),
"", $fRet);
191 $fRet = str_replace(
",",
".", $fRet);
193 return (
float) $fRet;
205 $fRet = str_replace(
" ",
"", $sValue);
206 $iCommaPos = strpos($fRet,
",");
207 $iDotPos = strpos($fRet,
".");
208 if (!$iDotPos xor !$iCommaPos) {
209 if (substr_count($fRet,
",") > 1 || substr_count($fRet,
".") > 1) {
210 $fRet = str_replace(array(
",",
"."),
"", $fRet);
212 $fRet = str_replace(
",",
".", $fRet);
215 if ($iDotPos < $iCommaPos) {
216 $fRet = str_replace(
".",
"", $fRet);
217 $fRet = str_replace(
",",
".", $fRet);
221 $fRet = str_replace(array(
" ",
","),
"", $fRet);
223 return (
float) $fRet;
235 if (is_null($this->_blIsSe)) {
252 if (isset($blIsSe)) {
253 $this->_blIsSe = $blIsSe;
257 startProfile(
"isSearchEngine");
263 $aRobots =
$myConfig->getConfigParam(
'aRobots');
264 $aRobots = is_array($aRobots) ? $aRobots : array();
266 $aRobotsExcept =
$myConfig->getConfigParam(
'aRobotsExcept');
267 $aRobotsExcept = is_array($aRobotsExcept) ? $aRobotsExcept : array();
269 $sClient = $sClient ? $sClient : strtolower(getenv(
'HTTP_USER_AGENT'));
271 $aRobots = array_merge($aRobots, $aRobotsExcept);
272 foreach ($aRobots as $sRobot) {
273 if (strpos($sClient, $sRobot) !==
false) {
280 $this->_blIsSe = $blIsSe;
282 stopProfile(
"isSearchEngine");
297 $oMailValidator =
oxNew(
'oxMailValidator');
299 return $oMailValidator->isValidEmail($sEmail);
313 if (is_array($aInterfaceProfiles)) {
315 $sPrevProfile =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'oxidadminprofile');
316 if (isset($sPrevProfile)) {
317 $aPrevProfile = @explode(
"@", trim($sPrevProfile));
321 $aProfiles = array();
322 foreach ($aInterfaceProfiles as $iPos => $sProfile) {
323 $aProfileSettings = array($iPos, $sProfile);
324 $aProfiles[] = $aProfileSettings;
327 if (isset($aPrevProfile[0]) && isset($aProfiles[$aPrevProfile[0]])) {
328 $aProfiles[$aPrevProfile[0]][2] = 1;
347 public function fRound($sVal, $oCur = null)
349 startProfile(
'fround');
352 $iCurPrecision = null;
353 if (!defined(
'OXID_PHP_UNIT')) {
357 if (is_null($iCurPrecision)) {
359 $oCur = $this->
getConfig()->getActShopCurrencyObject();
362 $iCurPrecision = $oCur->decimal;
363 $this->_iCurPrecision = $iCurPrecision;
367 static $dprez = null;
369 $prez = @ini_get(
"precision");
370 if (!$prez || $prez > 12) {
373 $dprez = pow(10, -$prez);
375 stopProfile(
'fround');
377 return round($sVal + $dprez * ($sVal >= 0 ? 1 : -1), $iCurPrecision);
396 $sResult = array_search((
string) $sNeedle, $aHaystack);
397 $sSecond = array_search((
string) $sNeedle, $aHaystack,
true);
401 if( $sResult != $sSecond) {
402 $aStringstack = array();
403 foreach ($aHaystack as $sValue) {
404 $aStringstack[] = (string) $sValue;
406 $sResult = array_search((
string) $sNeedle, $aStringstack,
true);
422 $this->_aStaticCache[$sName][$sKey] = $sContent;
424 $this->_aStaticCache[$sName] = $sContent;
437 if (isset($this->_aStaticCache[$sName])) {
438 return $this->_aStaticCache[$sName];
452 unset($this->_aStaticCache[$sCacheName]);
454 $this->_aStaticCache = null;
468 if (is_array($mContents) && ($sCachePath = $this->
getCacheFilePath($sKey,
false,
'php'))) {
471 $this->
setCacheMeta($sKey, array(
"serialize" =>
false,
"cachepath" => $sCachePath));
502 return isset($this->_aFileCacheMeta[$sKey]) ? $this->_aFileCacheMeta[$sKey] :
false;
514 $this->_aFileCacheMeta[$sKey] = $aMeta;
529 $aCacheData[
'content'] = $mContents;
532 $aCacheData[
'ttl'] = $iTtl;
535 $this->_aFileCacheContents[$sKey] = $aCacheData;
538 $sCachePath = isset($aMeta[
"cachepath"]) ? $aMeta[
"cachepath"] : $this->
getCacheFilePath($sKey);
540 return (
bool ) $this->
_lockFile($sCachePath, $sKey);
552 if (!array_key_exists($sKey, $this->_aFileCacheContents)) {
556 $blInclude = isset($aMeta[
"include"]) ? $aMeta[
"include"] :
false;
557 $sCachePath = isset($aMeta[
"cachepath"]) ? $aMeta[
"cachepath"] : $this->
getCacheFilePath($sKey);
560 $this->
_lockFile($sCachePath, $sKey, LOCK_SH);
563 if (is_readable($sCachePath)) {
567 if (isset($sRes[
'ttl']) && $sRes[
'ttl'] != 0) {
568 $iTimestamp = $sRes[
'timestamp'];
569 $iTtl = $sRes[
'ttl'];
572 if ($iTime > $iTimestamp + $iTtl) {
580 $this->_aFileCacheContents[$sKey] = $sRes;
583 return $this->_aFileCacheContents[$sKey][
'content'];
595 $sRes = file_get_contents($sFilePath);
597 return $sRes ? unserialize($sRes) : null;
609 $_aCacheContents = null;
612 return $_aCacheContents;
627 $blSerialize = isset($aCacheMeta[
"serialize"]) ? $aCacheMeta[
"serialize"] :
true;
630 $mContents = serialize($mContents);
632 $mContents =
"<?php\n//automatically generated file\n//" . date(
"Y-m-d H:i:s") .
"\n\n\$_aCacheContents = " . var_export($mContents,
true) .
"\n?>";
644 if (!empty($this->_aLockedFileHandles[LOCK_EX])) {
645 startProfile(
"!__SAVING CACHE__! (warning)");
646 foreach ($this->_aLockedFileHandles[LOCK_EX] as $sKey => $rHandle) {
647 if ($rHandle !==
false && isset($this->_aFileCacheContents[$sKey])) {
650 ftruncate($rHandle, 0);
653 fwrite($rHandle, $this->
_processCache($sKey, $this->_aFileCacheContents[$sKey]));
660 stopProfile(
"!__SAVING CACHE__! (warning)");
663 $this->_aFileCacheContents = array();
676 protected function _lockFile($sFilePath, $sIdent, $iLockMode = LOCK_EX)
678 $rHandle = isset($this->_aLockedFileHandles[$iLockMode][$sIdent]) ? $this->_aLockedFileHandles[$iLockMode][$sIdent] : null;
679 if ($rHandle === null) {
682 $rHandle = @fopen($sFilePath,
"a+");
684 if ($rHandle !==
false) {
686 if (flock($rHandle, $iLockMode | LOCK_NB)) {
687 if ($iLockMode === LOCK_EX) {
689 $blLocked = ftruncate($rHandle, 0);
692 $blLocked = fseek($rHandle, 0) === 0;
704 if (!$blLocked && $iLockMode === LOCK_EX) {
707 if (count($this->_aLockedFileHandles) == 0) {
712 if (!(file_exists($sFilePath) && !filesize($sFilePath) && abs(time() - filectime($sFilePath) < 40))) {
713 $rHandle = @fopen($sFilePath,
"w");
717 $this->_aLockedFileHandles[$iLockMode][$sIdent] = $rHandle;
734 if (isset($this->_aLockedFileHandles[$iLockMode][$sIdent]) &&
735 $this->_aLockedFileHandles[$iLockMode][$sIdent] !==
false
739 $blSuccess = flock($this->_aLockedFileHandles[$iLockMode][$sIdent], LOCK_UN) &&
740 fclose($this->_aLockedFileHandles[$iLockMode][$sIdent]);
741 unset($this->_aLockedFileHandles[$iLockMode][$sIdent]);
755 if (is_array($aFiles)) {
757 $aFiles = preg_grep($this->_sPermanentCachePattern, $aFiles, PREG_GREP_INVERT);
758 foreach ($aFiles as $sFile) {
773 $aFiles = glob($sSmartyDir .
'*');
775 if (is_array($aFiles) && is_array($aTemplates) && count($aTemplates)) {
777 foreach ($aTemplates as &$sTemplate) {
778 $sTemplate = preg_quote(basename(strtolower($sTemplate),
'.tpl'));
781 $sPattern = sprintf(
"/%%(%s)\.tpl\.php$/i", implode(
'|', $aTemplates));
782 $aFiles = preg_grep($sPattern, $aFiles);
784 if (is_array($aFiles)) {
785 foreach ($aFiles as $sFile) {
799 if (is_array($aFiles)) {
802 $aFiles = preg_grep($sPattern, $aFiles);
803 foreach ($aFiles as $sFile) {
815 if (is_array($aFiles)) {
818 $aFiles = preg_grep($sPattern, $aFiles);
819 foreach ($aFiles as $sFile) {
837 if (file_exists($sLocal) && filemtime($sLocal) && filemtime($sLocal) > time() - 86400) {
840 $hRemote = @fopen($sRemote,
"rb");
842 if (isset($hRemote) && $hRemote) {
843 $hLocal = fopen($sLocal,
"wb");
844 stream_copy_to_stream($hRemote, $hLocal);
850 $aUrl = @parse_url($sRemote);
851 if (!empty($aUrl[
"host"])) {
852 $sPath = $aUrl[
"path"];
856 $sHost = $aUrl[
"host"];
858 $hSocket = @fsockopen($sHost, 80, $iErrorNumber, $iErrStr, 5);
860 fputs($hSocket,
"GET " . $sPath .
" HTTP/1.0\r\nHost: $sHost\r\n\r\n");
861 $headers = stream_get_line($hSocket, 4096,
"\r\n\r\n");
862 if (($hLocal = @fopen($sLocal,
"wb")) !==
false) {
866 fwrite($hLocal, stream_get_contents($hSocket));
874 if ($blSuccess || file_exists($sLocal)) {
890 ($sAdminSid =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'admin_sid'))
893 $sTable = getViewName(
'oxuser');
895 $sQ =
"select 1 from $sTable where MD5( CONCAT( " . $oDb->quote($sAdminSid) .
", {$sTable}.oxid, {$sTable}.oxpassword, {$sTable}.oxrights ) ) = " .
oxDb::getDb()->quote($sPrevId);
896 $blCan = (bool) $oDb->getOne($sQ);
909 $sAdminSid =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'admin_sid');
910 if (($oUser = $this->
getUser())) {
911 return md5($sAdminSid . $oUser->getId() . $oUser->oxuser__oxpassword->value . $oUser->oxuser__oxrights->value);
932 $myConfig->setConfigParam(
'blMallAdmin',
false);
934 $myConfig->setConfigParam(
'blAllowInheritedEdit',
false);
939 $sRights = $oDb->getOne(
"select oxrights from oxuser where oxid = " . $oDb->quote($sUserID));
941 if ($sRights !=
"user") {
943 if ($sRights ==
"malladmin") {
945 $myConfig->setConfigParam(
'blMallAdmin',
true);
949 $myConfig->setConfigParam(
'blAllowSharedEdit',
true);
952 if (!isset($sShop)) {
958 $sShopID = $oDb->getOne(
"select oxid from oxshops where oxid = " . $oDb->quote($sRights));
959 if (isset($sShopID) && $sShopID) {
973 $aShopIdVars = array(
'actshop',
'shp',
'currentadminshop');
974 foreach ($aShopIdVars as $sShopIdVar) {
976 if ($sGotShop != $sRights) {
1002 public function seoIsActive($blReset =
false, $sShopId = null, $iActLang = null)
1004 if (!is_null($this->_blSeoIsActive) && !$blReset) {
1010 if (($this->_blSeoIsActive =
$myConfig->getConfigParam(
'blSeoMode')) === null) {
1011 $this->_blSeoIsActive =
true;
1013 $aSeoModes =
$myConfig->getconfigParam(
'aSeoModes');
1014 $sActShopId = $sShopId ? $sShopId :
$myConfig->getActiveShop()->getId();
1018 if (is_array($aSeoModes) && isset($aSeoModes[$sActShopId]) && isset($aSeoModes[$sActShopId][$iActLang])) {
1019 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
1035 return (
boolean)
getStr()->preg_match(
'/^[a-zA-Z0-9_]*$/', $sField);
1047 $oHeader =
oxNew(
"oxHeader");
1048 $oHeader->setHeader($sHeaderCode);
1049 $oHeader->setHeader(
"Location: $sUrl");
1050 $oHeader->setHeader(
"Connection: close");
1051 $oHeader->sendHeader();
1061 $sUrl = $this->
getConfig()->getShopUrl() .
'offline.html';
1062 $this->
redirect($sUrl,
false, $iHeaderCode);
1074 public function redirect($sUrl, $blAddRedirectParam =
true, $iHeaderCode = 302)
1082 if ($blAddRedirectParam) {
1086 $sUrl = str_ireplace(
"&",
"&", $sUrl);
1088 switch ($iHeaderCode) {
1090 $sHeaderCode =
"HTTP/1.1 301 Moved Permanently";
1093 $sHeaderCode =
"HTTP/1.1 500 Internal Server Error";
1097 $sHeaderCode =
"HTTP/1.1 302 Found";
1109 if (defined(
'OXID_PHP_UNIT')) {
1129 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];
1245 $oCurrency = $this->
getConfig()->getActShopCurrencyObject();
1247 $blEnterNetPrice = $this->
getConfig()->getConfigParam(
'blEnterNetPrice');
1248 if ($blCalculationModeNetto && !$blEnterNetPrice) {
1250 } elseif (!$blCalculationModeNetto && $blEnterNetPrice) {
1264 $blResult = (bool) $this->
getConfig()->getConfigParam(
'blShowNetPrice');
1267 $blResult = $oUser->isPriceViewModeNetto();
1280 if ($this->_oUser) {
1281 return $this->_oUser;
1296 $sFileName = strtolower($sFileName);
1297 $iLastDot = strrpos($sFileName,
'.');
1299 if ($iLastDot !==
false) {
1300 $sType = substr($sFileName, $iLastDot + 1);
1303 $sType =
'image/gif';
1307 $sType =
'image/jpeg';
1310 $sType =
'image/png';
1329 public function logger($sText, $blNewline =
false)
1333 if (
$myConfig->getConfigParam(
'iDebug') == -2) {
1334 if (gettype($sText) !=
'string') {
1335 $sText = var_export($sText,
true);
1337 $sLogMsg =
"----------------------------------------------\n{$sText}" . (($blNewline) ?
"\n" :
"") .
"\n";
1352 $sFrom =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
1353 $sTo =
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
1355 return strtr($sStr, $sFrom, $sTo);
1370 $sVersionPrefix =
'pe';
1372 $sPath = realpath($this->
getConfig()->getConfigParam(
'sCompileDir'));
1378 return $blPathOnly ?
"{$sPath}/" :
"{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}." . $sExtension;
1392 if (file_exists($sFilePath) && is_readable($sFilePath)) {
1409 $sCache =
"<?php\n\$aLangCache = " . var_export($aLangCache,
true) .
";\n?>";
1410 $blRes = file_put_contents($this->
getCacheFilePath($sCacheName), $sCache, LOCK_EX);
1424 if (!
getStr()->preg_match(
"/\/$/", $sUrl)) {
1443 $sLogDist = $this->
getConfig()->getLogsDir() . $sLogFileName;
1446 if (($oHandle = fopen($sLogDist,
'a')) !==
false) {
1447 fwrite($oHandle, $sLogMessage);
1448 $blOk = fclose($oHandle);
1461 $this->
setHeader(
"HTTP/1.0 404 Not Found");
1463 $this->
setHeader(
"Content-Type: text/html; charset=UTF-8");
1466 $sReturn =
"Page not found.";
1468 $oView =
oxNew(
'oxUBase');
1471 $oView->setClassName(
'oxUBase');
1472 $oView->addTplParam(
'sUrl', $sUrl);
1473 if ($sRet =
oxRegistry::get(
"oxUtilsView")->getTemplateOutput(
'message/err_404.tpl', $oView)) {
1491 if (!$oStr->preg_match(
'/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $sHost) &&
1492 ($iLastDot = strrpos($sHost,
'.')) !==
false
1494 $iLen = $oStr->strlen($sHost);
1495 if (($iNextDot = strrpos($sHost,
'.', ($iLen - $iLastDot + 1) * -1)) !==
false) {
1496 $sHost = trim($oStr->substr($sHost, $iNextDot),
'.');