<?php

define('ROOT', dirname(dirname(__FILE__)));

/* initialize ob_gzhandler to send and compress data */
ob_start ("ob_gzhandler");

/* initialize compress function for whitespace removal */
ob_start("compress");

/* required header info and character set */
header("Content-type: text/css;charset: UTF-8");

/* cache control to process */
header("Cache-Control: must-revalidate");

/* duration of cached content (1 hour) */
$offset = 60 * 60 * 24 * 7 ; 

/* expiration header format */
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s",time() + $offset) . " GMT";

/* send cache expiration header to broswer */
header($ExpStr);

$content = '';
$content .= file_get_contents(ROOT . "/css/default.css");
$content .= file_get_contents(ROOT . "/css/toolbar.css");
$content .= file_get_contents(ROOT . "/css/jquery.fancybox-1.3.4.css");
$content .= file_get_contents(ROOT . "/css/ticker-style.css");
$content .= file_get_contents(ROOT . "/css/select2.css");
$content .= file_get_contents(ROOT . "/css/prettyPhoto.css");
$content .= file_get_contents(ROOT . "/css/panels.css");
$content .= file_get_contents(ROOT . "/pixit/admin/assets/plugins/mcustom-scrollbar/jquery.mCustomScrollbar.css");
$content .= file_get_contents(ROOT . "/js/summernote/summernote.css");
$content .= file_get_contents(ROOT . "/pixit/admin/assets/plugins/magnific/magnific-popup.css");

#$content = preg_replace("/width:   100%;/","width: 1200px;", $content);

echo ($content);
#include($_SERVER['DOCUMENT_ROOT'] ."/cometchat/cometchatcss.php");

function minify( $css ) {
    $css = preg_replace( '#\s+#', ' ', $css );
    $css = preg_replace( '#/\*.*?\*/#s', '', $css );
    $css = str_replace( '; ', ';', $css );
    $css = str_replace( ': ', ':', $css );
    $css = str_replace( ' {', '{', $css ); 
    $css = str_replace( '{ ', '{', $css );
    $css = str_replace( ', ', ',', $css );
    $css = str_replace( '} ', '}', $css );
    $css = str_replace( ';}', '}', $css );
    return trim( $css );
}

function compress($buffer) {
    
    /* remove comments */
    $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
    
    /* remove tabs, spaces, new lines, etc. */        
    $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
    
    /* remove unnecessary spaces */        
    $buffer = str_replace('{ ', '{', $buffer);
    $buffer = str_replace(' }', '}', $buffer);
    $buffer = str_replace('; ', ';', $buffer);
    $buffer = str_replace(', ', ',', $buffer);
    $buffer = str_replace(' {', '{', $buffer);
    $buffer = str_replace('} ', '}', $buffer);
    $buffer = str_replace(': ', ':', $buffer);
    $buffer = str_replace(' ,', ',', $buffer);
    $buffer = str_replace(' ;', ';', $buffer);
    
    return $buffer;
}
