Skip to content

Commit a64fc97

Browse files
authored
Outono Azul
1 parent dfc8347 commit a64fc97

File tree

1 file changed

+135
-19
lines changed

1 file changed

+135
-19
lines changed

Html.php

Lines changed: 135 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Html
2828

2929
private $name = '';
3030
private $cached = false;
31-
private $mode = 'dev'; //pro|dev
31+
private $mode = 'pro'; //pro|dev
3232

3333
private $pathHtml = null;
3434
private $pathHtmlCache = null;
@@ -328,39 +328,51 @@ function forceCompress($b = true)
328328

329329
private function assetsComp()
330330
{
331+
ini_set('max_execution_time', '200');
332+
333+
$java = 'java -jar '.__DIR__.'/min/yc.jar ';
334+
$allcss = strtolower($this->pathStyle.$this->name).'_all.css';
335+
$alljs = strtolower($this->pathScript.$this->name).'_all.js';
336+
331337
//CSS STYLES
332-
if (file_exists($this->pathStyle.$this->name.'_all.css') && !$this->forceCompress) {
333-
$content = file_get_contents($this->pathStyle.$this->name.'_all.css');
338+
if (file_exists($allcss) && !$this->forceCompress) {
339+
$content = file_get_contents($allcss);
334340
} else {
335341
$content = '';
336342
foreach ($this->styles as $file) {
337-
$content .= exec('java -jar '.__DIR__.'/min/yc.jar "'.$this->pathStyle.$file.'.css"');
343+
$temp = exec($java.'"'.$this->pathStyle.$file.'.css"');
344+
//echo "\n\n<br><br>".$file.' == '.substr($temp, 0, 10);
345+
$content .= $temp;
338346
}
339-
file_put_contents($this->pathStyle.$this->name.'_all.css', $content);
340-
$content = exec('java -jar '.__DIR__.'/min/yc.jar "'.$this->pathStyle.$this->name.'_all.css"');
341-
file_put_contents($this->pathStyle.$this->name.'_all.css', $content);
347+
file_put_contents($allcss, $content);
348+
//$content = exec($java.$allcss.'"');
349+
//file_put_contents($allcss, $content);
342350
}
343-
$this->val('style', '<style id="stylesheet_base">'.$content.'</style>');
351+
$this->val('style', '<link id="stylesheet_base" rel="stylesheet" href="'.strtolower($this->url.'css/'.$this->name).'_all.css">'); //>'.$content.'</style>');
344352

345353
//JAVASCRIPTS
346-
if (file_exists($this->pathScript.$this->name.'_all.js') && !$this->forceCompress) {
347-
$content = file_get_contents($this->pathScript.$this->name.'_all.js');
354+
if (file_exists($alljs) && !$this->forceCompress) {
355+
$content = file_get_contents($alljs);
348356
} else {
349357
$content = ';';
350358
foreach ($this->scripts as $file) {
351-
$content .= exec('java -jar '.__DIR__.'/min/yc.jar "'.$this->pathScript.$file.'.js"');
359+
$temp = exec($java.'"'.$this->pathScript.$file.'.js"');
360+
//echo "\n\n<br><br>".$file.' == '.substr($temp, 0, 10);
361+
$content .= $temp;
352362
}
353-
file_put_contents($this->pathScript.$this->name.'_all.js', $content);
354-
$content = exec('java -jar '.__DIR__.'/min/yc.jar "'.$this->pathScript.$this->name.'_all.js"');
355-
file_put_contents($this->pathScript.$this->name.'_all.js', $content);
363+
file_put_contents($alljs, $content);
364+
//$content = exec($java.'"'.$alljs.'"');
365+
//file_put_contents($alljs, $content);
356366
}
357367

358368
$s = '<script id="javascript_base">var _URL=\''.$this->url.'\'';
359369
foreach ($this->jsvalues as $n => $v) {
360370
$s .= ','.$n.'='.(is_string($v) ? '\''.str_replace("'", '"', $v).'\'' : $v);
361371
}
362372
$s .= ';';
363-
$this->val('script', $s.$content.'</script>');
373+
$this->val('script', $s.'</script><script src="'.strtolower($this->url.'js/'.$this->name).'_all.js"></script>');
374+
375+
//exit('ok');
364376
}
365377

366378

@@ -404,13 +416,15 @@ function send()
404416
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
405417
header('Cache-Control: must_revalidate, public, max-age=31536000');
406418
header('X-Server: Qzumba/0.1.8.beta');//for safety ...
407-
header('X-Powered-By: NEOS PHP FRAMEWORK/1.3.0');//for safety ...
419+
header('X-Powered-By: DevBrasil/0.1.1');//for safety ...
408420

409421
if ($this->cached &&
410422
file_exists($this->pathHtmlCache.$this->name.'_cache.html')) {
411423
return $this->sendWithCach();
412424
} else {
413-
exit(eval('?>'.$this->content));
425+
//$this->content = $this->minify_html($this->content);
426+
//\Lib\App::e($this);
427+
exit(eval('?>'.$this->minify_html($this->content)));
414428
}
415429
}
416430

@@ -677,7 +691,7 @@ private function _var($ret)
677691
return '';
678692
}
679693
//$ret['-content-'] .= $v;
680-
$ret['-content-'] .= '<?php echo Lib\Html::get("'.trim($ret['var']).'")?>';
694+
$ret['-content-'] .= '<?php echo Lib\Html::minify_html(Lib\Html::get("'.trim($ret['var']).'"))?>';
681695

682696
//List type
683697
if (is_array($v)) {
@@ -756,14 +770,15 @@ private function _block($ret)
756770
*/
757771
private function _select($ret)
758772
{
773+
//App::e($ret);
759774
$var = $this->getVar($ret['data']);
760775
if (!$var) {
761776
return false;
762777
}
763778

764779
$o = '';
765780
foreach ($var['data'] as $k => $v) {
766-
$o .= '<option value="'.$k.'"'.($var['default'] == $k ? ' selected':'').'>'.$v.'</option>';
781+
$o .= '<option value="'.$k.'"'.(isset($var['default']) && $var['default'] == $k ? ' selected':'').'>'.$v.'</option>';
767782
}
768783
$ret['-content-'] = $o;
769784
$ret['tag'] = 'select';
@@ -821,4 +836,105 @@ function clearData($ret)
821836
$ret['data']);
822837
return $ret;
823838
}
839+
840+
841+
/**
842+
* Minify HTML
843+
* @param string $input content for html
844+
* @return string Minified html string
845+
*/
846+
static function minify_html($input)
847+
{
848+
if (trim($input) === "") {
849+
return $input;
850+
}
851+
// Remove extra white-space(s) between HTML attribute(s)
852+
$input = preg_replace_callback('#<([^\/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#s', function ($matches) {
853+
return '<' . $matches[1] . preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]) . $matches[3] . '>';
854+
}, str_replace("\r", "", $input));
855+
// Minify inline CSS declaration(s)
856+
if (strpos($input, ' style=') !== false) {
857+
$input = preg_replace_callback('#<([^<]+?)\s+style=([\'"])(.*?)\2(?=[\/\s>])#s', function ($matches) {
858+
return '<' . $matches[1] . ' style=' . $matches[2] . static::minify_css($matches[3]) . $matches[2];
859+
}, $input);
860+
}
861+
return preg_replace(
862+
array(
863+
// t = text
864+
// o = tag open
865+
// c = tag close
866+
// Keep important white-space(s) after self-closing HTML tag(s)
867+
'#<(img|input)(>| .*?>)#s',
868+
// Remove a line break and two or more white-space(s) between tag(s)
869+
'#(<!--.*?-->)|(>)(?:\n*|\s{2,})(<)|^\s*|\s*$#s',
870+
'#(<!--.*?-->)|(?<!\>)\s+(<\/.*?>)|(<[^\/]*?>)\s+(?!\<)#s', // t+c || o+t
871+
'#(<!--.*?-->)|(<[^\/]*?>)\s+(<[^\/]*?>)|(<\/.*?>)\s+(<\/.*?>)#s', // o+o || c+c
872+
'#(<!--.*?-->)|(<\/.*?>)\s+(\s)(?!\<)|(?<!\>)\s+(\s)(<[^\/]*?\/?>)|(<[^\/]*?\/?>)\s+(\s)(?!\<)#s', // c+t || t+o || o+t -- separated by long white-space(s)
873+
'#(<!--.*?-->)|(<[^\/]*?>)\s+(<\/.*?>)#s', // empty tag
874+
'#<(img|input)(>| .*?>)<\/\1>#s', // reset previous fix
875+
'#(&nbsp;)&nbsp;(?![<\s])#', // clean up ...
876+
'#(?<=\>)(&nbsp;)(?=\<)#', // --ibid
877+
// Remove HTML comment(s) except IE comment(s)
878+
'#\s*<!--(?!\[if\s).*?-->\s*|(?<!\>)\n+(?=\<[^!])#s'
879+
),
880+
array(
881+
'<$1$2</$1>',
882+
'$1$2$3',
883+
'$1$2$3',
884+
'$1$2$3$4$5',
885+
'$1$2$3$4$5$6$7',
886+
'$1$2$3',
887+
'<$1$2',
888+
'$1 ',
889+
'$1',
890+
""
891+
),
892+
$input);
893+
}
894+
895+
896+
static function minify_css($input)
897+
{
898+
if (trim($input) === "") {
899+
return $input;
900+
}
901+
return preg_replace(
902+
array(
903+
// Remove comment(s)
904+
'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s',
905+
// Remove unused white-space(s)
906+
'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*+-(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si',
907+
// Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0`
908+
'#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si',
909+
// Replace `:0 0 0 0` with `:0`
910+
'#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i',
911+
// Replace `background-position:0` with `background-position:0 0`
912+
'#(background-position):0(?=[;\}])#si',
913+
// Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space
914+
'#(?<=[\s:,\-])0+\.(\d+)#s',
915+
// Minify string value
916+
'#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si',
917+
'#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si',
918+
// Minify HEX color code
919+
'#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i',
920+
// Replace `(border|outline):none` with `(border|outline):0`
921+
'#(?<=[\{;])(border|outline):none(?=[;\}\!])#',
922+
// Remove empty selector(s)
923+
'#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s'
924+
),
925+
array(
926+
'$1',
927+
'$1$2$3$4$5$6$7',
928+
'$1',
929+
':0',
930+
'$1:0 0',
931+
'.$1',
932+
'$1$3',
933+
'$1$2$4$5',
934+
'$1$2$3',
935+
'$1:0',
936+
'$1$2'
937+
),
938+
$input);
939+
}
824940
}

0 commit comments

Comments
 (0)