includes/functions.php
changeset 125 fb31c951d3a2
parent 112 008b1c42be72
child 128 01955bf53f96
equal deleted inserted replaced
118:0c5efda996bf 125:fb31c951d3a2
   510  */
   510  */
   511 
   511 
   512 function grinding_halt($t, $p)
   512 function grinding_halt($t, $p)
   513 {
   513 {
   514   global $db, $session, $paths, $template, $plugins; // Common objects
   514   global $db, $session, $paths, $template, $plugins; // Common objects
   515 
   515   
   516   $db->close();
   516   if ( !defined('scriptPath') )
       
   517     require( ENANO_ROOT . '/config.php' );
       
   518 
       
   519   if ( is_object($db) )
       
   520     $db->close();
   517 
   521 
   518   if ( ob_get_status() )
   522   if ( ob_get_status() )
   519     ob_end_clean();
   523     ob_end_clean();
   520 
   524 
   521   dc_here('functions: <span style="color: red">calling grinding_halt</span>');
   525   dc_here('functions: <span style="color: red">calling grinding_halt</span>');
  2720 {
  2724 {
  2721   $size_before = strlen($html);
  2725   $size_before = strlen($html);
  2722   
  2726   
  2723   // kill carriage returns
  2727   // kill carriage returns
  2724   $html = str_replace("\r", "", $html);
  2728   $html = str_replace("\r", "", $html);
       
  2729   
       
  2730   // Which tags to strip for JAVASCRIPT PROCESSING ONLY - you can change this if needed
       
  2731   $strip_tags = Array('enano:no-opt');
       
  2732   $strip_tags = implode('|', $strip_tags);
       
  2733   
       
  2734   // Strip out the tags and replace with placeholders
       
  2735   preg_match_all("#<($strip_tags)(.*?)>(.*?)</($strip_tags)>#is", $html, $matches);
       
  2736   $seed = md5(microtime() . mt_rand()); // Random value used for placeholders
       
  2737   for ($i = 0;$i < sizeof($matches[1]); $i++)
       
  2738   {
       
  2739     $html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
       
  2740   }
  2725   
  2741   
  2726   // Optimize (but don't obfuscate) Javascript
  2742   // Optimize (but don't obfuscate) Javascript
  2727   preg_match_all('/<script(.*?)>(.+?)<\/script>/is', $html, $jscript);
  2743   preg_match_all('/<script(.*?)>(.+?)<\/script>/is', $html, $jscript);
  2728   
  2744   
  2729   // list of Javascript reserved words - from about.com
  2745   // list of Javascript reserved words - from about.com
  2784     $replacement = "<script{$jscript[1][$i]}>/* <![CDATA[ */ $js /* ]]> */</script>";
  2800     $replacement = "<script{$jscript[1][$i]}>/* <![CDATA[ */ $js /* ]]> */</script>";
  2785     // apply changes
  2801     // apply changes
  2786     $html = str_replace($jscript[0][$i], $replacement, $html);
  2802     $html = str_replace($jscript[0][$i], $replacement, $html);
  2787   }
  2803   }
  2788   
  2804   
       
  2805   // Re-insert untouchable tags
       
  2806   for ($i = 0;$i < sizeof($matches[1]); $i++)
       
  2807   {
       
  2808     $html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
       
  2809   }
       
  2810   
  2789   // Which tags to strip - you can change this if needed
  2811   // Which tags to strip - you can change this if needed
  2790   $strip_tags = Array('pre', 'script', 'style', 'enano:no-opt');
  2812   $strip_tags = Array('pre', 'script', 'style', 'enano:no-opt');
  2791   $strip_tags = implode('|', $strip_tags);
  2813   $strip_tags = implode('|', $strip_tags);
  2792   
  2814   
  2793   // Strip out the tags and replace with placeholders
  2815   // Strip out the tags and replace with placeholders