Beispiel #1
0
function compress_css($cssfile)
{
    // make these variables available locally
    global $file_selector;
    global $file_props;
    global $cssCompressor;
    // first, get the css that was sent, referenced or uploaded
    // save the size of the code
    $start_size = strlen($cssfile);
    // save the current time
    $start = explode(' ', microtime());
    // temporarily change semicolons in web links
    $cssfile = str_replace('://', '[!semi-colon!]//', $cssfile);
    // remove html and css comments
    kill_comments($cssfile);
    // trim whitespace from the start and end
    $cssfile = trim($cssfile);
    // turn all rgb values into hex
    if ($cssCompressor['opt_rgb2hex']) {
        rgb2hex($cssfile);
    }
    // shorten colours
    if ($cssCompressor['opt_colours2hex']) {
        long_colours_to_short_hex($cssfile);
    }
    if ($cssCompressor['opt_hex2colours']) {
        long_hex_to_short_colours($cssfile);
    }
    // remove any extra measurements that aren't needed
    if ($cssCompressor['opt_remove_zeros']) {
        remove_zero_measurements($cssfile);
    }
    // seperate into selectors and properties
    sort_css($cssfile);
    // change font weight text into numbers
    if ($cssCompressor['opt_text_weights_to_numbers']) {
        font_weight_text_to_numbers($cssfile);
    }
    // check if any selectors are used twice and combine the properties
    if ($cssCompressor['opt_combine_identical_selectors']) {
        combine_identical_selectors();
    }
    // remove any properties which are declared twice in one rule
    if ($cssCompressor['opt_remove_overwritten_properties']) {
        remove_overwritten_properties();
    }
    // check if properties should be combined
    if ($cssCompressor['opt_combine_props_list']) {
        // for each rule in the file
        for ($n = 0; $n < count($file_props); $n++) {
            // attempt to combine the different parts
            combine_props_list($file_props[$n]);
        }
    }
    // for each rule in the file
    for ($n = 0; $n < count($file_props); $n++) {
        // run all the individual functions to reduce their size
        array_walk($file_props[$n], 'reduce_prop', $cssCompressor);
    }
    // remove all the properties that were blanked out earlier
    remove_empty_rules();
    // check if any rules are the same as other ones and remove the first ones
    if ($cssCompressor['opt_combine_identical_rules']) {
        combine_identical_rules();
    }
    // one final run through to remove all unnecessary parts of the arrays
    remove_empty_rules();
    $output = create_output();
    // turn back colons
    $output = str_replace('[!semi-colon!]//', '://', $output);
    $output = stripslashes($output);
    // gather statistics
    $stats['original_size'] = round($start_size / 1024, 2) . ' kB';
    $stats['final_size'] = round(strlen(strip_tags($output)) / 1024, 2) . ' kB';
    $stats['reduction'] = round(100 - strlen(strip_tags($output)) / $start_size * 100, 2) . '%';
    $finish = explode(' ', microtime());
    // work out the differences between the times
    $seconds = $finish[1] - $start[1];
    $miliseconds = $finish[0] - $start[0];
    $stats['duration'] = round($seconds + $miliseconds, 5);
    $stats['num_rules'] = count($file_selector);
    for ($n = 0; $n < count($file_selector); $n++) {
        $stats['num_selectors'] += count($file_selector[$n]);
    }
    for ($n = 0; $n < count($file_props); $n++) {
        $stats['num_props'] += count($file_props[$n]);
    }
    return array($output, $stats);
}
function compress_css()
{
    // make these variables available locally
    global $file_selector;
    global $file_props;
    // first, get the css that was sent, referenced or uploaded
    $cssfile = get_sent_css();
    // check if the user wants to see statistics
    if ($_REQUEST['opt_output_stats']) {
        // save the size of the code
        $start_size = strlen($cssfile);
        // save the current time
        $start = explode(' ', microtime());
    }
    // check if no css was found
    if (!$cssfile) {
        // just die
        exit("/* You didn't upload anything or the stylesheet is empty - Ro" . "bson */");
    }
    // temporarily change semicolons in web links
    $cssfile = str_replace('://', '[!semi-colon!]//', $cssfile);
    // remove html and css comments
    kill_comments($cssfile);
    // trim whitespace from the start and end
    $cssfile = trim($cssfile);
    // turn all rgb values into hex
    if ($_REQUEST['opt_rgb2hex']) {
        rgb2hex($cssfile);
    }
    // shorten colours
    if ($_REQUEST['opt_colours2hex']) {
        long_colours_to_short_hex($cssfile);
    }
    if ($_REQUEST['opt_hex2colours']) {
        long_hex_to_short_colours($cssfile);
    }
    // remove any extra measurements that aren't needed
    if ($_REQUEST['opt_remove_zeros']) {
        remove_zero_measurements($cssfile);
    }
    // seperate into selectors and properties
    sort_css($cssfile);
    // change font weight text into numbers
    if ($_REQUEST['opt_text_weights_to_numbers']) {
        font_weight_text_to_numbers($cssfile);
    }
    // check if any selectors are used twice and combine the properties
    if ($_REQUEST['opt_combine_identical_selectors']) {
        combine_identical_selectors();
    }
    // remove any properties which are declared twice in one rule
    if ($_REQUEST['opt_remove_overwritten_properties']) {
        remove_overwritten_properties();
    }
    // check if properties should be combined
    if ($_REQUEST['opt_combine_props_list']) {
        // for each rule in the file
        for ($n = 0; $n < count($file_props); $n++) {
            // attempt to combine the different parts
            combine_props_list($file_props[$n]);
        }
    }
    // for each rule in the file
    for ($n = 0; $n < count($file_props); $n++) {
        // run all the individual functions to reduce their size
        array_walk($file_props[$n], 'reduce_prop');
    }
    // remove all the properties that were blanked out earlier
    remove_empty_rules();
    // check if any rules are the same as other ones and remove the first ones
    if ($_REQUEST['opt_combine_identical_rules']) {
        combine_identical_rules();
    }
    // one final run through to remove all unnecessary parts of the arrays
    remove_empty_rules();
    $output = create_output();
    // turn back colons
    $output = str_replace('[!semi-colon!]//', '://', $output);
    $output = stripslashes($output);
    // check if the user wants to view stats
    if ($_REQUEST['opt_output_stats']) {
        echo '<h1>Statistics</h1><ul>';
        echo '<li>Original size: ' . round($start_size / 1024, 2) . ' kB (' . number_format($start_size) . ' B)</li>';
        echo '<li>Final size: ' . round(strlen(strip_tags($output)) / 1024, 2) . ' kB (' . number_format(strlen(strip_tags($output))) . ' B)</li>';
        echo '<li>Saved: ' . round(($start_size - strlen(strip_tags($output))) / 1024, 2) . ' kB (' . number_format($start_size - strlen(strip_tags($output))) . ' B)</li>';
        echo '<li>Reduction: ' . round(100 - strlen(strip_tags($output)) / $start_size * 100, 2) . '%</li>';
        echo '</ul>';
        $finish = explode(' ', microtime());
        // work out the differences between the times
        $seconds = $finish[1] - $start[1];
        $miliseconds = $finish[0] - $start[0];
        $duration = round($seconds + $miliseconds, 5);
        echo '<ul>';
        echo '<li>Duration: ' . $duration . ' seconds</li>';
        echo '</ul>';
        echo '<ul>';
        echo '<li>Rules: ' . count($file_selector) . '</li>';
        for ($n = 0; $n < count($file_selector); $n++) {
            $selectors += count($file_selector[$n]);
        }
        for ($n = 0; $n < count($file_props); $n++) {
            $props += count($file_props[$n]);
        }
        echo '<li>Selectors: ' . $selectors . '</li>';
        echo '<li>Properties: ' . $props . '</li>';
        echo '</ul>';
        echo '<h1>CSS</h1>';
    }
    if ($_REQUEST['upload_link']) {
        $_REQUEST['upload_style'] = NULL;
        if (!$_POST['upload_link']) {
            $_POST = $_GET;
        }
        foreach ($_POST as $key => $value) {
            if ($value) {
                if (!$url) {
                    $url .= '?' . $key . '=' . $value;
                } else {
                    $url .= '&' . $key . '=' . $value;
                }
            }
        }
        echo '<ul><li><a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $url . '">Link to this output</a>.</ul>';
    }
    echo $output;
}
function view_images_period($period_n, $period, $camera, $file_path)
{
    $c = count($camera);
    $array_of_cams_img = array();
    $array_of_cams = array();
    $final_array = array();
    for ($i = 1; $i <= $c; $i++) {
        $folder_name = $camera[$i]['camera_name'];
        $camera_path = $file_path . $folder_name;
        // $scanned_directory = array_diff(scandir($camera_path,1), array('..', '.','test'));
        $scanned_directory = glob("{$camera_path}/*20*", GLOB_ONLYDIR);
        sort($scanned_directory);
        rsort($scanned_directory);
        $path_to_photos = $scanned_directory[0] . "/";
        $images_array = array_diff(scandir($path_to_photos, 1), array('..', '.', 'list.txt', 'divx2pass.log', 'divx2pass.log.mbtree', 'lights.mp4', '$avi_file_name', '$mp4_file', 'uk.txt', 'uk.mp4', 'au.txt', 'au.mp4', 'ph.txt', 'ph.mp4', 'test'));
        $i_count = count($images_array);
        $array_of_cams_img[] = $images_array;
        $array_of_cams[] = $camera[$i]['camera_name'];
    }
    // print_r($array_of_cams_img);
    for ($j = 0; $j < count($array_of_cams_img); $j++) {
        $url = "";
        for ($k = 0; $k < count($array_of_cams_img[$j]); $k++) {
            //echo "at beigaining:k=".$k."<br/>";
            $pieces = explode("_", $array_of_cams_img[$j][$k]);
            // echo  $pieces[2]."<br/>";
            $time = $pieces[2][8] . $pieces[2][9] . $pieces[2][10] . $pieces[2][11];
            //echo $time."<br/>";
            // if($period_n==1 ){
            $skip = 0;
            if ($time >= $period[$period_n]['period_start'] and $time <= $period[$period_n]['period_end']) {
                //echo $time."<br/>";
                $fn = $array_of_cams[$j];
                $cp = $file_path . $fn;
                $sd = array_diff(scandir($cp, 1), array('..', '.', 'test'));
                if ($sd[0] == "" or $sd[0] == NULL) {
                    $sd[0] = $sd[1];
                }
                $ptp = $cp . "/" . $sd[0] . "/";
                $url = $ptp . $array_of_cams_img[$j][$k];
                // echo $url."<br/>";
                if ($file_path !== "") {
                    $b1 = explode($file_path, $url);
                } else {
                    $b1[1] = $url;
                }
                $b2 = explode("_", $b1[1]);
                $b3 = substr($b2[2], 0, 12);
                $url2 = "";
                $new_url = "{$url},";
                for ($l = 1; $l <= 5; $l++) {
                    $nxt = $ptp . $array_of_cams_img[$j][$k + $l];
                    if ($file_path !== "") {
                        $c1 = explode($file_path, $nxt);
                    } else {
                        $c1[1] = $nxt;
                    }
                    $c2 = explode("_", $c1[1]);
                    $c3 = substr($c2[2], 0, 12);
                    if ($c3 == NULL or $c3 == 0 or $c3 == "") {
                        break;
                    }
                    if ($b3 == $c3) {
                        $new_url .= "{$nxt}" . ",";
                        $skip++;
                        continue;
                    } else {
                        break;
                    }
                }
                $final_array[$array_of_cams[$j]][][0] = $new_url;
            }
            //echo $k."before  + {$skip} <br/>";;
            $k = $k + $skip;
            //echo $k."after <br/>";;
            //  }
        }
        //var_dump($array_of_cams_img[$j]);
    }
    create_output($final_array, $camera, $file_path);
}