includes/functions.php
changeset 81 d7fc25acd3f3
parent 80 cb7dde69c301
child 82 03c7f5ec1e4c
equal deleted inserted replaced
80:cb7dde69c301 81:d7fc25acd3f3
  2678   //
  2678   //
  2679   // Compress buffered output if required and send to browser
  2679   // Compress buffered output if required and send to browser
  2680   //
  2680   //
  2681   if ( $do_gzip && function_exists('ob_gzhandler') )
  2681   if ( $do_gzip && function_exists('ob_gzhandler') )
  2682   {
  2682   {
  2683     //
       
  2684     // Copied from phpBB, which was in turn borrowed from php.net
       
  2685     //
       
  2686     $gzip_contents = ob_get_contents();
  2683     $gzip_contents = ob_get_contents();
  2687     ob_end_clean();
  2684     ob_end_clean();
  2688     
  2685     
  2689     header('Content-encoding: gzip');
  2686     $return = ob_gzhandler($gzip_contents);
  2690     $gzip_contents = ob_gzhandler($gzip_contents);
  2687     if ( $return )
  2691     echo $gzip_contents;
  2688     {
       
  2689       header('Content-encoding: gzip');
       
  2690       echo $gzip_contents;
       
  2691     }
       
  2692     else
       
  2693     {
       
  2694       echo $gzip_contents;
       
  2695     }
  2692   }
  2696   }
  2693 }
  2697 }
  2694 
  2698 
  2695 /**
  2699 /**
  2696  * Aggressively and hopefully non-destructively optimizes a blob of HTML.
  2700  * Aggressively and hopefully non-destructively optimizes a blob of HTML.
  2761     $js = preg_replace("/(\)|;)\n$reserved_words/is", '\\1\\2', $js);
  2765     $js = preg_replace("/(\)|;)\n$reserved_words/is", '\\1\\2', $js);
  2762     
  2766     
  2763     // fix for firefox issue
  2767     // fix for firefox issue
  2764     $js = preg_replace('/\};([\s]*)(else|\))/i', '}\\2', $js);
  2768     $js = preg_replace('/\};([\s]*)(else|\))/i', '}\\2', $js);
  2765     
  2769     
       
  2770     $replacement = "<script{$jscript[1][$i]}>/* <![CDATA[ */ $js /* ]]> */</script>";
  2766     // apply changes
  2771     // apply changes
  2767     $html = str_replace($jscript[0][$i], "<script{$jscript[1][$i]}>$js</script>", $html);
  2772     $html = str_replace($jscript[0][$i], $replacement, $html);
  2768   }
  2773   }
  2769   
  2774   
  2770   // Which tags to strip - you can change this if needed
  2775   // Which tags to strip - you can change this if needed
  2771   $strip_tags = Array('pre', 'script', 'style', 'enano:no-opt');
  2776   $strip_tags = Array('pre', 'script', 'style', 'enano:no-opt');
  2772   $strip_tags = implode('|', $strip_tags);
  2777   $strip_tags = implode('|', $strip_tags);
  2795   $html = preg_replace('#<(\/|)enano:no-opt(.*?)>#', '', $html);
  2800   $html = preg_replace('#<(\/|)enano:no-opt(.*?)>#', '', $html);
  2796   
  2801   
  2797   $size_after = strlen($html);
  2802   $size_after = strlen($html);
  2798   
  2803   
  2799   // Tell snoopish users what's going on
  2804   // Tell snoopish users what's going on
  2800   $html = str_replace('<html>', "\n".'<!-- NOTE: Enano has performed an HTML optimization routine on the HTML you see here. This is to enhance page loading speeds.
  2805   $html = str_replace('<html', "\n".'<!-- NOTE: Enano has performed an HTML optimization routine on the HTML you see here. This is to enhance page loading speeds.
  2801      To view the uncompressed source of this page, add the "nocompress" parameter to the URI of this page: index.php?title=Main_Page&nocompress or Main_Page?nocompress'."
  2806      To view the uncompressed source of this page, add the "nocompress" parameter to the URI of this page: index.php?title=Main_Page&nocompress or Main_Page?nocompress'."
  2802      Size before compression: $size_before bytes
  2807      Size before compression: $size_before bytes
  2803      Size after compression:  $size_after bytes
  2808      Size after compression:  $size_after bytes
  2804      -->\n<html>", $html);
  2809      -->\n<html", $html);
  2805   return $html;
  2810   return $html;
  2806 }
  2811 }
  2807 
  2812 
  2808 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  2813 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  2809 
  2814