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);
391 $this->_aStaticCache[$sName][$sKey] = $sContent;
393 $this->_aStaticCache[$sName] = $sContent;
406 if (isset($this->_aStaticCache[$sName])) {
407 return $this->_aStaticCache[$sName];
421 unset($this->_aStaticCache[$sCacheName]);
423 $this->_aStaticCache = null;
437 if (is_array($mContents) && ($sCachePath = $this->
getCacheFilePath($sKey,
false,
'php'))) {
440 $this->
setCacheMeta($sKey, array(
"serialize" =>
false,
"cachepath" => $sCachePath));
471 return isset($this->_aFileCacheMeta[$sKey]) ? $this->_aFileCacheMeta[$sKey] :
false;
483 $this->_aFileCacheMeta[$sKey] = $aMeta;
498 $aCacheData[
'content'] = $mContents;
501 $aCacheData[
'ttl'] = $iTtl;
504 $this->_aFileCacheContents[$sKey] = $aCacheData;
507 $sCachePath = isset($aMeta[
"cachepath"]) ? $aMeta[
"cachepath"] : $this->
getCacheFilePath($sKey);
509 return (
bool ) $this->
_lockFile($sCachePath, $sKey);
521 if (!array_key_exists($sKey, $this->_aFileCacheContents)) {
525 $blInclude = isset($aMeta[
"include"]) ? $aMeta[
"include"] :
false;
526 $sCachePath = isset($aMeta[
"cachepath"]) ? $aMeta[
"cachepath"] : $this->
getCacheFilePath($sKey);
529 $this->
_lockFile($sCachePath, $sKey, LOCK_SH);
532 if (is_readable($sCachePath)) {
536 if (isset($sRes[
'ttl']) && $sRes[
'ttl'] != 0) {
537 $iTimestamp = $sRes[
'timestamp'];
538 $iTtl = $sRes[
'ttl'];
541 if ($iTime > $iTimestamp + $iTtl) {
549 $this->_aFileCacheContents[$sKey] = $sRes;
552 return $this->_aFileCacheContents[$sKey][
'content'];
564 $sRes = file_get_contents($sFilePath);
566 return $sRes ? unserialize($sRes) : null;
578 $_aCacheContents = null;
581 return $_aCacheContents;
596 $blSerialize = isset($aCacheMeta[
"serialize"]) ? $aCacheMeta[
"serialize"] :
true;
599 $mContents = serialize($mContents);
601 $mContents =
"<?php\n//automatically generated file\n//" . date(
"Y-m-d H:i:s") .
"\n\n\$_aCacheContents = " . var_export($mContents,
true) .
"\n?>";
613 if (!empty($this->_aLockedFileHandles[LOCK_EX])) {
614 startProfile(
"!__SAVING CACHE__! (warning)");
615 foreach ($this->_aLockedFileHandles[LOCK_EX] as $sKey => $rHandle) {
616 if ($rHandle !==
false && isset($this->_aFileCacheContents[$sKey])) {
619 ftruncate($rHandle, 0);
622 fwrite($rHandle, $this->
_processCache($sKey, $this->_aFileCacheContents[$sKey]));
629 stopProfile(
"!__SAVING CACHE__! (warning)");
632 $this->_aFileCacheContents = array();
645 protected function _lockFile($sFilePath, $sIdent, $iLockMode = LOCK_EX)
647 $rHandle = isset($this->_aLockedFileHandles[$iLockMode][$sIdent]) ? $this->_aLockedFileHandles[$iLockMode][$sIdent] : null;
648 if ($rHandle === null) {
651 $rHandle = @fopen($sFilePath,
"a+");
653 if ($rHandle !==
false) {
655 if (flock($rHandle, $iLockMode | LOCK_NB)) {
656 if ($iLockMode === LOCK_EX) {
658 $blLocked = ftruncate($rHandle, 0);
661 $blLocked = fseek($rHandle, 0) === 0;
673 if (!$blLocked && $iLockMode === LOCK_EX) {
676 if (count($this->_aLockedFileHandles) == 0) {
681 if (!(file_exists($sFilePath) && !filesize($sFilePath) && abs(time() - filectime($sFilePath) < 40))) {
682 $rHandle = @fopen($sFilePath,
"w");
686 $this->_aLockedFileHandles[$iLockMode][$sIdent] = $rHandle;
703 if (isset($this->_aLockedFileHandles[$iLockMode][$sIdent]) &&
704 $this->_aLockedFileHandles[$iLockMode][$sIdent] !==
false
708 $blSuccess = flock($this->_aLockedFileHandles[$iLockMode][$sIdent], LOCK_UN) &&
709 fclose($this->_aLockedFileHandles[$iLockMode][$sIdent]);
710 unset($this->_aLockedFileHandles[$iLockMode][$sIdent]);
724 if (is_array($aFiles)) {
726 $aFiles = preg_grep($this->_sPermanentCachePattern, $aFiles, PREG_GREP_INVERT);
727 foreach ($aFiles as $sFile) {
742 $aFiles = glob($sSmartyDir .
'*');
744 if (is_array($aFiles) && is_array($aTemplates) && count($aTemplates)) {
746 foreach ($aTemplates as &$sTemplate) {
747 $sTemplate = preg_quote(basename(strtolower($sTemplate),
'.tpl'));
750 $sPattern = sprintf(
"/%%(%s)\.tpl\.php$/i", implode(
'|', $aTemplates));
751 $aFiles = preg_grep($sPattern, $aFiles);
753 if (is_array($aFiles)) {
754 foreach ($aFiles as $sFile) {
768 if (is_array($aFiles)) {
771 $aFiles = preg_grep($sPattern, $aFiles);
772 foreach ($aFiles as $sFile) {
784 if (is_array($aFiles)) {
787 $aFiles = preg_grep($sPattern, $aFiles);
788 foreach ($aFiles as $sFile) {
806 if (file_exists($sLocal) && filemtime($sLocal) && filemtime($sLocal) > time() - 86400) {
809 $hRemote = @fopen($sRemote,
"rb");
811 if (isset($hRemote) && $hRemote) {
812 $hLocal = fopen($sLocal,
"wb");
813 stream_copy_to_stream($hRemote, $hLocal);
819 $aUrl = @parse_url($sRemote);
820 if (!empty($aUrl[
"host"])) {
821 $sPath = $aUrl[
"path"];
825 $sHost = $aUrl[
"host"];
827 $hSocket = @fsockopen($sHost, 80, $iErrorNumber, $iErrStr, 5);
829 fputs($hSocket,
"GET " . $sPath .
" HTTP/1.0\r\nHost: $sHost\r\n\r\n");
830 $headers = stream_get_line($hSocket, 4096,
"\r\n\r\n");
831 if (($hLocal = @fopen($sLocal,
"wb")) !==
false) {
835 fwrite($hLocal, stream_get_contents($hSocket));
843 if ($blSuccess || file_exists($sLocal)) {
859 ($sAdminSid =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'admin_sid'))
862 $sTable = getViewName(
'oxuser');
864 $sQ =
"select 1 from $sTable where MD5( CONCAT( " . $oDb->quote($sAdminSid) .
", {$sTable}.oxid, {$sTable}.oxpassword, {$sTable}.oxrights ) ) = " .
oxDb::getDb()->quote($sPrevId);
865 $blCan = (bool) $oDb->getOne($sQ);
878 $sAdminSid =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'admin_sid');
879 if (($oUser = $this->
getUser())) {
880 return md5($sAdminSid . $oUser->getId() . $oUser->oxuser__oxpassword->value . $oUser->oxuser__oxrights->value);
901 $myConfig->setConfigParam(
'blMallAdmin',
false);
903 $myConfig->setConfigParam(
'blAllowInheritedEdit',
false);
908 $sRights = $oDb->getOne(
"select oxrights from oxuser where oxid = " . $oDb->quote($sUserID));
910 if ($sRights !=
"user") {
912 if ($sRights ==
"malladmin") {
914 $myConfig->setConfigParam(
'blMallAdmin',
true);
918 $myConfig->setConfigParam(
'blAllowSharedEdit',
true);
921 if (!isset($sShop)) {
927 $sShopID = $oDb->getOne(
"select oxid from oxshops where oxid = " . $oDb->quote($sRights));
928 if (isset($sShopID) && $sShopID) {
942 $aShopIdVars = array(
'actshop',
'shp',
'currentadminshop');
943 foreach ($aShopIdVars as $sShopIdVar) {
945 if ($sGotShop != $sRights) {
971 public function seoIsActive($blReset =
false, $sShopId = null, $iActLang = null)
973 if (!is_null($this->_blSeoIsActive) && !$blReset) {
979 if (($this->_blSeoIsActive =
$myConfig->getConfigParam(
'blSeoMode')) === null) {
980 $this->_blSeoIsActive =
true;
982 $aSeoModes =
$myConfig->getconfigParam(
'aSeoModes');
983 $sActShopId = $sShopId ? $sShopId :
$myConfig->getActiveShop()->getId();
987 if (is_array($aSeoModes) && isset($aSeoModes[$sActShopId]) && isset($aSeoModes[$sActShopId][$iActLang])) {
988 $this->_blSeoIsActive = (bool) $aSeoModes[$sActShopId][$iActLang];
1004 return (
boolean)
getStr()->preg_match(
'/^[a-zA-Z0-9_]*$/', $sField);
1016 $oHeader =
oxNew(
"oxHeader");
1017 $oHeader->setHeader($sHeaderCode);
1018 $oHeader->setHeader(
"Location: $sUrl");
1019 $oHeader->setHeader(
"Connection: close");
1020 $oHeader->sendHeader();
1030 $sUrl = $this->
getConfig()->getShopUrl() .
'offline.html';
1031 $this->
redirect($sUrl,
false, $iHeaderCode);
1043 public function redirect($sUrl, $blAddRedirectParam =
true, $iHeaderCode = 302)
1051 if ($blAddRedirectParam) {
1055 $sUrl = str_ireplace(
"&",
"&", $sUrl);
1057 switch ($iHeaderCode) {
1059 $sHeaderCode =
"HTTP/1.1 301 Moved Permanently";
1062 $sHeaderCode =
"HTTP/1.1 500 Internal Server Error";
1066 $sHeaderCode =
"HTTP/1.1 302 Found";
1078 if (defined(
'OXID_PHP_UNIT')) {
1098 if (defined(
'OXID_PHP_UNIT')) {
1126 $sDelimiter = ((
getStr()->strpos($sUrl,
'?') !==
false)) ?
'&' :
'?';
1127 foreach ($aParams as $sName => $sVal) {
1128 $sUrl = $sUrl . $sDelimiter . $sName .
'=' . $sVal;
1149 $oObject =
new stdClass();
1150 $aPrice = explode(
'!P!', $aName[0]);
1152 if ((
$myConfig->getConfigParam(
'bl_perfLoadSelectLists') &&
$myConfig->getConfigParam(
'bl_perfUseSelectlistPrice') && isset($aPrice[0]) && isset($aPrice[1])) || $this->
isAdmin()) {
1155 $oObject->price = isset($aPrice[1]) ? $aPrice[1] : 0;
1156 $aName[0] = isset($aPrice[0]) ? $aPrice[0] :
'';
1158 $iPercPos =
getStr()->strpos($oObject->price,
'%');
1159 if ($iPercPos !==
false) {
1160 $oObject->priceUnit =
'%';
1161 $oObject->fprice = $oObject->price;
1162 $oObject->price = substr($oObject->price, 0, $iPercPos);
1164 $oCur =
$myConfig->getActShopCurrencyObject();
1165 $oObject->price = str_replace(
',',
'.', $oObject->price);
1166 $oObject->fprice =
oxRegistry::getLang()->formatCurrency($oObject->price * $oCur->rate, $oCur);
1167 $oObject->priceUnit =
'abs';
1171 if (!$this->
isAdmin() && $oObject->price != 0) {
1176 if ($oObject->price > 0) {
1180 if ($dVat != null && $oObject->priceUnit ==
'abs') {
1181 $oPrice =
oxNew(
'oxPrice');
1182 $oPrice->setPrice($oObject->price, $dVat);
1185 $aName[0] .= $oObject->fprice;
1187 if ($oObject->priceUnit ==
'abs') {
1188 $aName[0] .=
" " . $oCur->sign;
1191 } elseif (isset($aPrice[0]) && isset($aPrice[1])) {
1193 $aName[0] =
getStr()->preg_replace(
"/!P!.*/",
"", $aName[0]);
1196 $oObject->name = $aName[0];
1197 $oObject->value = $aName[1];
1214 $oCurrency = $this->
getConfig()->getActShopCurrencyObject();
1216 $blEnterNetPrice = $this->
getConfig()->getConfigParam(
'blEnterNetPrice');
1217 if ($blCalculationModeNetto && !$blEnterNetPrice) {
1219 } elseif (!$blCalculationModeNetto && $blEnterNetPrice) {
1233 $blResult = (bool) $this->
getConfig()->getConfigParam(
'blShowNetPrice');
1236 $blResult = $oUser->isPriceViewModeNetto();
1249 if ($this->_oUser) {
1250 return $this->_oUser;
1265 $sFileName = strtolower($sFileName);
1266 $iLastDot = strrpos($sFileName,
'.');
1268 if ($iLastDot !==
false) {
1269 $sType = substr($sFileName, $iLastDot + 1);
1272 $sType =
'image/gif';
1276 $sType =
'image/jpeg';
1279 $sType =
'image/png';
1296 public function logger($sText, $blNewline =
false)
1300 if (
$myConfig->getConfigParam(
'iDebug') == -2) {
1301 if (gettype($sText) !=
'string') {
1302 $sText = var_export($sText,
true);
1304 $sLogMsg =
"----------------------------------------------\n{$sText}" . (($blNewline) ?
"\n" :
"") .
"\n";
1319 $sFrom =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
1320 $sTo =
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
1322 return strtr($sStr, $sFrom, $sTo);
1337 $sVersionPrefix =
'pe';
1339 $sPath = realpath($this->
getConfig()->getConfigParam(
'sCompileDir'));
1345 return $blPathOnly ?
"{$sPath}/" :
"{$sPath}/ox{$sVersionPrefix}c_{$sCacheName}." . $sExtension;
1359 if (file_exists($sFilePath) && is_readable($sFilePath)) {
1376 $sCache =
"<?php\n\$aLangCache = " . var_export($aLangCache,
true) .
";\n?>";
1377 $blRes = file_put_contents($this->
getCacheFilePath($sCacheName), $sCache, LOCK_EX);
1391 if (!
getStr()->preg_match(
"/\/$/", $sUrl)) {
1408 $sLogDist = $this->
getConfig()->getLogsDir() . $sLogFileName;
1411 if (($oHandle = fopen($sLogDist,
'a')) !==
false) {
1412 fwrite($oHandle, $sLogMessage);
1413 $blOk = fclose($oHandle);
1426 $this->
setHeader(
"HTTP/1.0 404 Not Found");
1428 $this->
setHeader(
"Content-Type: text/html; charset=UTF-8");
1431 $sReturn =
"Page not found.";
1433 $oView =
oxNew(
'oxUBase');
1436 $oView->setClassName(
'oxUBase');
1437 $oView->addTplParam(
'sUrl', $sUrl);
1438 if ($sRet =
oxRegistry::get(
"oxUtilsView")->getTemplateOutput(
'message/err_404.tpl', $oView)) {
1456 if (!$oStr->preg_match(
'/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $sHost) &&
1457 ($iLastDot = strrpos($sHost,
'.')) !==
false
1459 $iLen = $oStr->strlen($sHost);
1460 if (($iNextDot = strrpos($sHost,
'.', ($iLen - $iLastDot + 1) * -1)) !==
false) {
1461 $sHost = trim($oStr->substr($sHost, $iNextDot),
'.');