Ejemplo n.º 1
0
        echo GetMessage("MAIN_OPTION_HTML_CACHE_BUTTON_ON");
        ?>
"<?php 
        if (!$isAdmin) {
            echo " disabled";
        }
        ?>
 class="adm-btn-save">
		<?php 
    }
    ?>
	</td>
</tr>
<?php 
    if (CHTMLPagesCache::IsOn()) {
        $arStatistic = CHTMLPagesCache::readStatistic();
        ?>
<tr class="heading">
	<td colspan="2"><?php 
        echo GetMessage("MAIN_OPTION_HTML_CACHE_STAT");
        ?>
</td>
	<?php 
        $arHTMLCacheOptions = CHTMLPagesCache::GetOptions();
        ?>
</tr>
<tr>
	<td valign="top" colspan="2" align="center">
		<table border="0" cellpadding="0" cellspacing="0" class="internal">
		<tr class="heading">
			<td align="center"><?php 
Ejemplo n.º 2
0
	public static function writeFile($file_name, $content)
	{
		global $USER;
		if(is_object($USER) && $USER->IsAuthorized())
			return;

		$content_len = function_exists('mb_strlen')? mb_strlen($content, 'latin1'): strlen($content);
		if($content_len <= 0)
			return;

		$arHTMLPagesOptions = CHTMLPagesCache::GetOptions();

		//Let's be pessimists
		$bQuota = false;

		if(class_exists("cdiskquota"))
		{
			$quota = new CDiskQuota();
			if($quota->checkDiskQuota(array("FILE_SIZE" => $content_len)))
				$bQuota = true;
		}
		else
		{
			$bQuota = true;
		}

		$arStat = CHTMLPagesCache::readStatistic();
		if($arStat)
			$cached_size = $arStat["FILE_SIZE"];
		else
			$cached_size = 0.0;

		$cache_quota = doubleval($arHTMLPagesOptions["~FILE_QUOTA"]);
		if($bQuota && ($cache_quota > 0.0))
		{
			if($cache_quota  < ($cached_size + $content_len))
				$bQuota = false;
		}

		if($bQuota)
		{
			CheckDirPath($file_name);
			$written = 0;
			$tmp_filename = $file_name.md5(mt_rand()).".tmp";
			$file = @fopen($tmp_filename, "wb");
			if($file !== false)
			{
				$written = fwrite($file, $content);
				if($written == $content_len)
				{
					fclose($file);
					if(file_exists($file_name))
						unlink($file_name);
					rename($tmp_filename, $file_name);
					@chmod($file_name, defined("FX_FILE_PERMISSIONS")? FX_FILE_PERMISSIONS: 0664);
					if(class_exists("cdiskquota"))
					{
						CDiskQuota::updateDiskQuota("file", $content_len, "copy");
					}
				}
				else
				{
					$written = 0;
					fclose($file);
					if(file_exists($file_name))
						unlink($file_name);
					if(file_exists($tmp_filename))
						unlink($tmp_filename);
				}
			}
			$arStat = CHTMLPagesCache::writeStatistic(
				0, //hit
				1, //miss
				0, //quota
				0, //posts
				$written //files
			);
		}
		else
		{
			//Fire cleanup
			CHTMLPagesCache::CleanAll();
			CHTMLPagesCache::writeStatistic(0, 0, 1, 0, false);
		}
	}