includes/functions.php
changeset 610 de33b0d26741
parent 606 daf8c556ada7
child 613 c08670a77871
equal deleted inserted replaced
609:ffa5decbb305 610:de33b0d26741
  2995   $tag = trim($tag);
  2995   $tag = trim($tag);
  2996   return $tag;
  2996   return $tag;
  2997 }
  2997 }
  2998 
  2998 
  2999 /**
  2999 /**
       
  3000  * Replacement for gzencode() which doesn't always work.
       
  3001  * @param string Data to compress
       
  3002  * @param int Compression level - 0 (no compression) to 9 (maximum compression)
       
  3003  * @param string Filename to encode into the compressed data - defaults to blank
       
  3004  * @param string Comment for archive - defaults to blank
       
  3005  * @return string Compressed data
       
  3006  */
       
  3007 
       
  3008 if ( !function_exists('gzencode') )
       
  3009 {
       
  3010   function gzencode($data = "", $level = 6, $filename = "", $comments = "")
       
  3011   {
       
  3012     $flags = (empty($comment)? 0 : 16) + (empty($filename)? 0 : 8);
       
  3013     $mtime = time();
       
  3014     
       
  3015     if ( !function_exists('gzdeflate') )
       
  3016       return false;
       
  3017    
       
  3018     return (pack("C1C1C1C1VC1C1", 0x1f, 0x8b, 8, $flags, $mtime, 2, 0xFF) .
       
  3019             (empty($filename) ? "" : $filename . "\0") .
       
  3020             (empty($comment) ? "" : $comment . "\0") .
       
  3021             gzdeflate($data, $level) .
       
  3022             pack("VV", crc32($data), strlen($data)));
       
  3023   }
       
  3024 }
       
  3025 
       
  3026 /**
  3000  * Gzips the output buffer.
  3027  * Gzips the output buffer.
  3001  */
  3028  */
  3002 
  3029 
  3003 function gzip_output()
  3030 function gzip_output()
  3004 {
  3031 {
  3005   global $do_gzip;
  3032   global $do_gzip;
  3006   
  3033   
  3007   //
  3034   //
  3008   // Compress buffered output if required and send to browser
  3035   // Compress buffered output if required and send to browser
  3009   //
  3036   //
  3010   if ( $do_gzip && function_exists('ob_gzhandler') )
  3037   if ( $do_gzip && function_exists('gzdeflate') )
  3011   {
  3038   {
  3012     $gzip_contents = ob_get_contents();
  3039     $gzip_contents = ob_get_contents();
  3013     ob_end_clean();
  3040     ob_end_clean();
  3014     
  3041     
  3015     $return = @ob_gzhandler($gzip_contents, PHP_OUTPUT_HANDLER_START);
  3042     $return = @gzencode($gzip_contents);
  3016     if ( $return )
  3043     if ( $return )
  3017     {
  3044     {
  3018       header('Content-encoding: gzip');
  3045       header('Content-encoding: gzip');
  3019       echo $return;
  3046       echo $return;
  3020     }
  3047     }