Refactored whitespacer trimmer.
This commit is contained in:
parent
6bd87d270d
commit
4f83d3ebe3
1 changed files with 39 additions and 6 deletions
|
@ -90,15 +90,48 @@ class Display_PHP extends Display_Common
|
|||
// Grabs the buffer contents and clears it out
|
||||
$buffer = ob_get_clean();
|
||||
|
||||
// Minifies the output
|
||||
// @todo Need to add logic to not minify blocks of CSS or Javascript
|
||||
//$buffer = str_replace(array(' ', "\r\n", "\n", "\t"), null, $buffer);
|
||||
$buffer = str_replace(array(' ', "\t"), null, $buffer);
|
||||
/*
|
||||
@todo this wasn't working as well as I'd like:
|
||||
|
||||
// Spits out the minified buffer
|
||||
echo $buffer;
|
||||
$regex = array(
|
||||
'PRE' => '!<pre>.+?</pre>!is',
|
||||
'SCRIPT' => '!<script[^>]+>.+?</script>!is',
|
||||
'TEXTAREA' => '!<textarea[^>]+>.+?</textarea>!is',
|
||||
);
|
||||
|
||||
$search_replace = array();
|
||||
|
||||
// Cleans up the stuff we don't want to minify
|
||||
foreach ($regex as $type => $pattern)
|
||||
{
|
||||
$hash = '@@@PICKLES::' . $type . '@@@';
|
||||
|
||||
preg_match_all($pattern, $buffer, $matches);
|
||||
$search_replace[$hash] = $matches[0];
|
||||
$buffer = preg_replace($pattern, $hash, $buffer);
|
||||
}
|
||||
|
||||
// Strips the whitespace
|
||||
$buffer = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $buffer));
|
||||
|
||||
// Kills any HTML comments
|
||||
$buffer = preg_replace('/<!--.*-->/U', '', $buffer);
|
||||
|
||||
// Injects the stuff we stripped earlier
|
||||
foreach ($search_replace as $search => $replacements)
|
||||
{
|
||||
foreach ($replacements as $replacement)
|
||||
{
|
||||
$buffer = preg_replace('/'.$search.'/', $replacement, $buffer, 1);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Kills any whitespace and HTML comments
|
||||
$buffer = preg_replace(array('/^[\s]+/m', '/<!--.*-->/U'), '', $buffer);
|
||||
|
||||
// Note, this doesn't exit in case you want to run code after the display of the page
|
||||
echo $buffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue