<?php
define('CACHED_STATUS', 1);

function process_data_jmr1($text) // 
{
    $re = '%# Collapse whitespace everywhere but in blacklisted elements.
        (?>             # Match all whitespans other than single space.
          [^\S ]\s*     # Either one [\t\r\n\f\v] and zero or more ws,
        | \s{2,}        # or two or more consecutive-any-whitespace.
        ) # Note: The remaining regex consumes no text at all...
        (?=             # Ensure we are not in a blacklist tag.
          [^<]*+        # Either zero or more non-"<" {normal*}
          (?:           # Begin {(special normal*)*} construct
            <           # or a < starting a non-blacklist tag.|script
            (?!/?(?:textarea|pre)\b)
            [^<]*+      # more non-"<" {normal*}
          )*+           # Finish "unrolling-the-loop"
          (?:           # Begin alternation group.
            <           # Either a blacklist start tag.|script
            (?>textarea|pre)\b
          | \z          # or end of file.
          )             # End alternation group.
        )  # If we made it here, we are not in a blacklist tag.
        %Six';
    $text = preg_replace($re.'u', " ", $text);
    if ($text === null) exit("PCRE Error! File too big.\n");
    return $text;
}

function cachedTOP($time){
	if(CACHED_STATUS == 1){
		$cachefile = 'cached/'.md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']).'.html';

		if (file_exists($cachefile) && time() - $time < filemtime($cachefile)) {
			include($cachefile);
			echo "<!-- Cached copy, generated ".date('d-m-Y/H:i', filemtime($cachefile))." | filename ".md5($_SERVER['REQUEST_URI'])."-->\n";
			exit;
		}
		ob_start('process_data_jmr1');
	}
}
function cachedFOOT(){
	if(CACHED_STATUS == 1){
		$cached = fopen('cached/'.md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']).'.html', 'w');
		fwrite($cached, process_data_jmr1(ob_get_contents()));
		fclose($cached);
		ob_end_flush();
	}
}