@rainphp you broke the Compress plugin apparently, and I wanted it to have the ability to only compress if debug is false, so here is yours from a previous raintpl version with the debug thingy:
<?php
namespace Rain\Tpl\Plugin;
class Compress extends \Rain\Tpl\Plugin {
protected $hooks = array('afterDraw'), $cache_dir;
/**
* Function called in the hook afterDraw
* @param \ArrayAccess $context
*/
public function afterDraw(\ArrayAccess $context) {
// get the cache directory
$this->cache_dir = $context->conf['cache_dir'];
$html = $context->code;
if(!$context->conf['debug'])
$html = $this->compressHTML($html);
// save the compressed code
$context->code = $html;
}
/**
* Compress the HTML
* @param type $html
* @return type
*/
protected function compressHTML($html) {
// Set PCRE recursion limit to sane value = STACKSIZE / 500
// ini_set("pcre.recursion_limit", "524"); // 256KB stack. Win32 Apache
ini_set("pcre.recursion_limit", "16777"); // 8MB stack. *nix
$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.
(?!/?(?:textarea|pre|script)\b)
[^<]*+ # more non-"<" {normal*}
)*+ # Finish "unrolling-the-loop"
(?: # Begin alternation group.
< # Either a blacklist start tag.
(?>textarea|pre|script)\b
| \z # or end of file.
) # End alternation group.
) # If we made it here, we are not in a blacklist tag.
%Six';
$html = preg_replace($re, " ", $html);
if ($html === null)
exit("PCRE Error! File too big.\n");
return $html;
}
public function configure( $setting, $value ){
$this->conf[$setting] = self::$configure[$setting] = $value;
}
public function configureLocal( $setting, $value ){
$this->conf[$setting] = $value;
}
}
Hi,
@rainphp you broke the Compress plugin apparently, and I wanted it to have the ability to only compress if debug is false, so here is yours from a previous raintpl version with the debug thingy: