$_GET["method"]); include("bin/utils.php"); } else { include("bin/init.php"); } // make sure our htaccess is up to date $refreshHtaccess = false; if (file_exists(".htaccess")) { $htaccessCreateDate = new DateTime(); $htaccessCreateDate->setTimestamp(filemtime(".htaccess")); $htaccessCreateDate->setTime(0, 0, 0); $today = new DateTime(); $today->setTime(0, 0, 0); $diff = $today->diff($htaccessCreateDate); $refreshHtaccess = (int)$diff->format("%R%a") != 0; } else { $refreshHtaccess = true; } if ($refreshHtaccess) { $url = "http://".$_SERVER["HTTP_HOST"]."/htaccess.php"; // $url = './htaccess.php'; @file_get_contents($url); } // first we check if we need to perform a specific method if ($R->method != "") { switch ($R->method) { case "qr": $url = isset($_GET["url"]) ? $_GET["url"] : ""; $result = (object)array("key" => "", "value" => ""); if ($url != "") { // handle setRetailer stuff $result->key = "loadURL"; $result->value = $url; } _json($result); break; case "retailersSellingAccessory": include("bin/config.php"); include("lib/businessLayerClient.php"); $DAL_OLD = new BusinessLayerClient(); $DAL_OLD->setBaseUrl(_config(_config("environment", "production") == "production" ? "oldBusinessLayerUrl" : "oldBusinessLayerUrlDEV", "")); $DAL_OLD->setOutputErrors(true); $DAL_OLD->setUseCache(_config("useBLCache", false)); $productId = isset($_GET["productId"]) ? (int)$_GET["productId"] : 0; $accessoryId = isset($_GET["accessoryId"]) ? (int)$_GET["accessoryId"] : 0; $defaultRetailerId = _config("defaultRetailerId", 0); $list = array(); if ($productId > 0 && $accessoryId > 0) { $retailersSellingMainProduct = (array)$DAL_OLD->get("retailerSearch.php", array("rid" => $defaultRetailerId, "productId" => $productId)); $retailersSellingAccessory = (array)$DAL_OLD->get("retailerSearch.php", array("rid" => $defaultRetailerId, "productId" => $accessoryId)); foreach ($retailersSellingMainProduct as $retailerSellingMainProduct) { foreach ($retailersSellingAccessory as $retailerSellingAccessory) { if ($retailerSellingMainProduct->id == $retailerSellingAccessory->id) { $list[] = (object)array("id" => $retailerSellingAccessory->id, "name" => $retailerSellingAccessory->name); break; } } } } _json($list); break; case "newsletterRegistration": $email = isset($_GET["email"]) ? $_GET["email"] : ""; $language = $R->language; $retailerId = $R->retailerId; $DAL_OLD = new BusinessLayerClient(); $DAL_OLD->setBaseUrl($CONFIG->oldBusinessLayerUrl); $DAL_OLD->setOutputErrors(true); if ($email != "") { $newsletterRegistrationResponse = $DAL_OLD->get("newsletterRegistration.php", array("email" => $email, "lang" => $language, "rid" => $retailerId)); _json($newsletterRegistrationResponse); } else { _json((object)array("error" => "NewsletterRegistrationFailed_EmptyEmailAddress")); } break; case "optivo_broadmail": $cid = isset($_GET["cid"]) ? $_GET["cid"] : ""; if ($cid != "") { header("Content-Type:text/xml"); ob_end_clean(); echo trim(_getRequest($CONFIG->oldBusinessLayerUrl."productOptivo.php", array("eID" => "optivo_broadmail", "cid" => $cid), false)); die(); } break; case "sanitizeCache": $h = fopen("log.txt", "a"); fwrite($h, "\r\n\r\n".date("Ymd H:i:s")." sanitize cache\r\n"); fclose($h); set_time_limit(300); $cacheDir = dir("cache"); while (false !== ($e = $cacheDir->read())) { if ($e != "." && $e != ".." && $e != date("Ymd") && is_dir("cache/".$e)) { _removeDirectory("cache/".$e); } } die(); break; case "clearCache": case "blUpdate": set_time_limit(600); $directories = array(); $blDirectories = array(); $eventName = isset($_REQUEST["eventName"]) ? $_REQUEST["eventName"] : ""; $eventParams = isset($_REQUEST["eventParams"]) ? $_REQUEST["eventParams"] : ""; if ($R->method == "blUpdate") { $eventName = "blUpdate"; } $h = fopen("log.txt", "a"); fwrite($h, "\r\n".date("Ymd His"). " - clear cache - ".$eventName); fclose($h); // we got an event from the Business Layer if ($eventName != "") { switch ($eventName) { case "blUpdate": $directories[] = array("bl"); break; // a slide was updated, we need to clear all // cache files for "home" case "slideUpdate": case "slideRemove": $directories[] = array("page", "home"); break; // a content page was updated, clear the "content" // directory case "contentUpdate": $directories[] = array("content", ""); break; // a product was updated, find out if it was only // one otherwise clear the "products" directory case "itemUpdate": $directories[] = array("page", "home"); $productsFilter = ""; if (isset($eventParams["id"]) && $eventParams["id"] > 0) { $productsFilter = "product-".$eventParams["id"]."-"; } $directories[] = array("products", $productsFilter); break; // a retailer was updated, find out if it was only // one otherwise clear everything case "retailerUpdate": $directories[] = array("none"); break; // changes were made to the blog, clear the content // cache for "magazine" case "articleUpdate": case "articleCategoryUpdate": case "articleRemove": case "articleCategoryRemove": $directories[] = array("page", "magazine"); $blDirectories = array("article"); break; case "advertisementUpdate": $directories[] = array(array("page", "advertisement-"), array("categories", "offers-")); $blDirectories = array("advertisement"); break; } } else if (isset($_GET["dir"])) { $directories[] = array($_GET["dir"]); } $cacheDirectory = "cache/".date("Ymd"); if (!file_exists($cacheDirectory)) { echo "cache directory not found"; die(); } $d = dir($cacheDirectory); $cnt = 0; $directoryCount = count($directories); $blDirectoryCount = count($blDirectories); // we don't have any cache dir specified, let's just rename the // directory if ($directoryCount == 0) { $deletedCacheDirectory = "cache/del"; _ensureDirectoryExists($deletedCacheDirectory); $newCacheDirectoryName = $deletedCacheDirectory."/".date("YmdHis"); rename($cacheDirectory, $newCacheDirectoryName); echo "whole cache directory renamed to \"".$newCacheDirectoryName."\""; } else { $blCacheDirectory = $cacheDirectory."/bl-".date("H"); if ($blDirectoryCount > 0 && file_exists($blCacheDirectory)) { $bld = dir($blCacheDirectory); while (false !== ($e = $bld->read())) { foreach ($blDirectories as $blDirectory) { if ($e != "." && $e != ".." && is_dir($blCacheDirectory."/".$e) && $e == $blDirectory) { $bld2 = dir($blCacheDirectory."/".$e); while (false !== ($e2 = $bld2->read())) { if ($e2 != "." && $e2 != "..") { unlink($blCacheDirectory."/".$e."/".$e2); } } } } } } while (false !== ($e = $d->read())) { if ($e != "." && $e != ".." && is_dir($cacheDirectory."/".$e)) { $directoryInfo = null; if ($directoryCount == 0) { $directoryInfo = array(); } else { foreach ($directories as $directory) { if ($directory[0] == $e) { $directoryInfo = $directory; break; } } } if ($directoryInfo !== null) { $fileFilter = count($directoryInfo) > 1 ? $directoryInfo[1] : ""; echo "clear ".$cacheDirectory."/".$e." (Filter: ".$fileFilter.")
"; $d2 = dir($cacheDirectory."/".$e); if ($fileFilter == "") { $deletedCacheDirectory = "cache/del"; _ensureDirectoryExists($deletedCacheDirectory); rename($cacheDirectory."/".$e, $deletedCacheDirectory."/".$e."-".date("YmdHis")); } else { while (false !== ($e2 = $d2->read())) { if ($e2 != "." && $e2 != "..") { if ($fileFilter == "" || strpos($e2, $fileFilter) !== false) { unlink($cacheDirectory."/".$e."/".$e2); $cnt++; } } } } } } } echo "

".$cnt." files removed."; } die(); break; } } $maintenance = _config("maintenance", false) && !isset($_GET["nomaintenance"]); $fromCache = false; $R->cachePath .= ".zip"; if ($R->useCache && !$R->updateCache && !$noCache && !$maintenance && _browserCheckInfo() == "" && file_exists($R->cachePath)) { ob_end_clean(); $cacheContent = gzuncompress(file_get_contents($R->cachePath)); if (strpos($cacheContent, ""; $fromCache = true; } } // otherwise generate the content and store to the cache path if (!$fromCache) { if ($maintenance) { die(file_get_contents("html/maintenance.html")); } // output.php populates the $OUT variable with the rendered // content include("lib/output.php"); $OUT = _appendBusinessLayerLog($OUT, $sts); $blErrorCount = $DAL->getErrorCount(); // only write to cache if useCache is enabled, the business layer // did not fail on any requests and we at least find a body // tag in the output (so we don't cache empty white pages) if ($R->useCache && $blErrorCount == 0 && strpos($OUT, "cachePath, 0, strrpos($R->cachePath, "/")); _ensureDirectoryExists($directory); $h = fopen($R->cachePath.".zip", "w"); fwrite($h, gzcompress($OUT)); fclose($h); } if (!_config("debugMode", false)) { ob_end_clean(); } echo $OUT; } echo "\n"; $url = $_SERVER['PHP_SELF']; $parts = array(); foreach( $_GET as $k=>$v ) { $parts[] = "$k=" . urlencode($v); } $url .= "?" . implode("&", $parts); echo "\n"; //echo microtime() - $R->ts; ?>