Beispiel #1
0
 public static function OnBeforeProlog()
 {
     if (defined("BX_CHECK_SHORT_URI") && BX_CHECK_SHORT_URI) {
         $upload_dir = "/" . trim(COption::GetOptionString("main", "upload_dir", "upload"), "/") . "/";
         $request_uri = urldecode($_SERVER["REQUEST_URI"]);
         $request_uri = CCloudUtil::URLEncode($request_uri, LANG_CHARSET);
         foreach (CCloudStorageBucket::GetAllBuckets() as $arBucket) {
             if ($arBucket["ACTIVE"] == "Y") {
                 $obBucket = new CCloudStorageBucket($arBucket["ID"]);
                 if ($obBucket->Init()) {
                     $match = array();
                     if ($obBucket->FileExists($request_uri)) {
                         if (COption::GetOptionString("clouds", "log_404_errors") === "Y") {
                             CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
                         }
                         LocalRedirect($obBucket->GetFileSRC($request_uri), true);
                     } elseif (strpos($request_uri, $upload_dir) === 0) {
                         $check_url = substr($request_uri, strlen($upload_dir) - 1);
                         if ($obBucket->FileExists($check_url)) {
                             if (COption::GetOptionString("clouds", "log_404_errors") === "Y") {
                                 CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
                             }
                             LocalRedirect($obBucket->GetFileSRC($check_url), true);
                         }
                     } elseif (COption::GetOptionString("clouds", "delayed_resize") === "Y" && preg_match("#^(/" . $obBucket->PREFIX . "|)(/resize_cache/.*\$)#", $request_uri, $match)) {
                         session_write_close();
                         $to_file = $obBucket->GetFileSRC(urldecode($match[2]));
                         if (CCloudStorage::ResizeImageFileCheck($obBucket, $to_file)) {
                             LocalRedirect($to_file, true);
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
	function OnBeforeProlog()
	{
		if(defined("BX_CHECK_SHORT_URI") && BX_CHECK_SHORT_URI)
		{
			$upload_dir = "/".trim(COption::GetOptionString("main", "upload_dir", "upload"), "/")."/";
			$request_uri = urldecode($_SERVER["REQUEST_URI"]);
			$request_uri = CCloudUtil::URLEncode($request_uri, LANG_CHARSET);
			foreach(CCloudStorageBucket::GetAllBuckets() as $arBucket)
			{
				if($arBucket["ACTIVE"] == "Y")
				{
					$obBucket = new CCloudStorageBucket($arBucket["ID"]);
					if($obBucket->Init())
					{
						$match = array();
						if(
							COption::GetOptionString("clouds", "delayed_resize") === "Y"
							&& preg_match("#^(/".$obBucket->PREFIX."|)(/resize_cache/.*\$)#", $request_uri, $match)
						)
						{
							session_write_close();
							$to_file = $obBucket->GetFileSRC(urldecode($match[2]));
							if (CCloudStorage::ResizeImageFileCheck($obBucket, $to_file))
							{
								$cache_time = 3600*24*30; // 30 days
								header("Cache-Control: max-age=".$cache_time);
								header("Expires: ".gmdate("D, d M Y H:i:s", time()+$cache_time)." GMT");
								header_remove("Pragma");
								LocalRedirect($to_file, true, "301 Moved Permanently");
							}
						}
						elseif($obBucket->FileExists($request_uri))
						{
							if(COption::GetOptionString("clouds", "log_404_errors") === "Y")
								CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
							LocalRedirect($obBucket->GetFileSRC($request_uri), true);
						}
						elseif(strpos($request_uri, $upload_dir) === 0)
						{
							$check_url = substr($request_uri, strlen($upload_dir)-1);
							if($obBucket->FileExists($check_url))
							{
								if(COption::GetOptionString("clouds", "log_404_errors") === "Y")
									CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
								LocalRedirect($obBucket->GetFileSRC($check_url), true);
							}
						}
					}
				}
			}
		}
	}