Skip to content

Commit

Permalink
remove html minify
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvan committed Jan 19, 2019
1 parent 8ca27d7 commit 689b238
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 62 deletions.
7 changes: 1 addition & 6 deletions src/Components/Bootstrap/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use InnStudio\Prober\Components\Config\ConfigApi;
use InnStudio\Prober\Components\Events\EventsApi;
use InnStudio\Prober\Components\Helper\HelperApi;
use InnStudio\Prober\Components\I18n\I18nApi;

class Bootstrap
Expand All @@ -13,11 +12,7 @@ public function __construct()
{
EventsApi::emit('init');

if (DEBUG === true) {
echo $this->getDisplay();
} else {
echo HelperApi::htmlMinify($this->getDisplay());
}
echo $this->getDisplay();
}

private function getFieldsets()
Expand Down
56 changes: 0 additions & 56 deletions src/Components/Helper/HelperApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,62 +309,6 @@ public static function isWin()
return \PHP_OS === 'WINNT';
}

public static function htmlMinify($buffer)
{
// @see https://stackoverflow.com/questions/27878158/php-bufffer-output-minify-not-textarea-pre
\preg_match_all('#\<textarea.*\>.*\<\/textarea\>#Uis', $buffer, $foundTxt);
\preg_match_all('#\<pre.*\>.*\<\/pre\>#Uis', $buffer, $foundPre);

// replacing both with <textarea>$index</textarea> / <pre>$index</pre>
$textareas = array();

foreach (\array_keys($foundTxt[0]) as $item) {
$textareas[] = '<textarea>' . $item . '</textarea>';
}

$pres = array();

foreach (\array_keys($foundPre[0]) as $item) {
$pres[] = '<pre>' . $item . '</pre>';
}

$buffer = \str_replace($foundTxt[0], $textareas, $buffer);
$buffer = \str_replace($foundPre[0], $pres, $buffer);

// your stuff
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s', // shorten multiple whitespace sequences
);

$replace = array(
'>',
'<',
'\\1',
);

$buffer = \preg_replace($search, $replace, $buffer);

// Replacing back with content
$textareas = array();

foreach (\array_keys($foundTxt[0]) as $item) {
$textareas[] = '<textarea>' . $item . '</textarea>';
}

$pres = array();

foreach (\array_keys($foundPre[0]) as $item) {
$pres[] = '<pre>' . $item . '</pre>';
}

$buffer = \str_replace($textareas, $foundTxt[0], $buffer);
$buffer = \str_replace($pres, $foundPre[0], $buffer);

return $buffer;
}

public static function getClientIp()
{
$keys = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR');
Expand Down

0 comments on commit 689b238

Please sign in to comment.