includes/functions.php
changeset 183 91127e62f38f
parent 174 4c5c2b66a34d
child 184 d74ff822acc9
equal deleted inserted replaced
176:1bc7e849a264 183:91127e62f38f
  2794   // Which tags to strip for JAVASCRIPT PROCESSING ONLY - you can change this if needed
  2794   // Which tags to strip for JAVASCRIPT PROCESSING ONLY - you can change this if needed
  2795   $strip_tags = Array('enano:no-opt');
  2795   $strip_tags = Array('enano:no-opt');
  2796   $strip_tags = implode('|', $strip_tags);
  2796   $strip_tags = implode('|', $strip_tags);
  2797   
  2797   
  2798   // Strip out the tags and replace with placeholders
  2798   // Strip out the tags and replace with placeholders
  2799   preg_match_all("#<($strip_tags)(.*?)>(.*?)</($strip_tags)>#is", $html, $matches);
  2799   preg_match_all("#<($strip_tags)([ ]+.*?)?>(.*?)</($strip_tags)>#is", $html, $matches);
  2800   $seed = md5(microtime() . mt_rand()); // Random value used for placeholders
  2800   $seed = md5(microtime() . mt_rand()); // Random value used for placeholders
  2801   for ($i = 0;$i < sizeof($matches[1]); $i++)
  2801   for ($i = 0;$i < sizeof($matches[1]); $i++)
  2802   {
  2802   {
  2803     $html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
  2803     $html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
  2804   }
  2804   }
  2805   
  2805   
  2806   // Optimize (but don't obfuscate) Javascript
  2806   // Optimize (but don't obfuscate) Javascript
  2807   preg_match_all('/<script(.*?)>(.+?)<\/script>/is', $html, $jscript);
  2807   preg_match_all('/<script([ ]+.*?)?>(.*?)<\/script>/is', $html, $jscript);
  2808   
  2808   
  2809   // list of Javascript reserved words - from about.com
  2809   // list of Javascript reserved words - from about.com
  2810   $reserved_words = array('abstract', 'as', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', 'continue', 'const', 'debugger', 'default', 'delete', 'do',
  2810   $reserved_words = array('abstract', 'as', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', 'continue', 'const', 'debugger', 'default', 'delete', 'do',
  2811                           'double', 'else', 'enum', 'export', 'extends', 'false', 'final', 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import',
  2811                           'double', 'else', 'enum', 'export', 'extends', 'false', 'final', 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import',
  2812                           'in', 'instanceof', 'int', 'interface', 'is', 'long', 'namespace', 'native', 'new', 'null', 'package', 'private', 'protected', 'public',
  2812                           'in', 'instanceof', 'int', 'interface', 'is', 'long', 'namespace', 'native', 'new', 'null', 'package', 'private', 'protected', 'public',
  2816   $reserved_words = '(' . implode('|', $reserved_words) . ')';
  2816   $reserved_words = '(' . implode('|', $reserved_words) . ')';
  2817   
  2817   
  2818   for ( $i = 0; $i < count($jscript[0]); $i++ )
  2818   for ( $i = 0; $i < count($jscript[0]); $i++ )
  2819   {
  2819   {
  2820     $js =& $jscript[2][$i];
  2820     $js =& $jscript[2][$i];
       
  2821     
       
  2822     // echo('<pre>' . "-----------------------------------------------------------------------------\n" . htmlspecialchars($js) . '</pre>');
  2821     
  2823     
  2822     // for line optimization, explode it
  2824     // for line optimization, explode it
  2823     $particles = explode("\n", $js);
  2825     $particles = explode("\n", $js);
  2824     
  2826     
  2825     foreach ( $particles as $j => $atom )
  2827     foreach ( $particles as $j => $atom )