예제 #1
0
 public static function minify($js, $options = array())
 {
     try {
         $currentOptions = array_merge(self::$defaultOptions, $options);
         ob_start();
         $currentOptions = array_merge(self::$defaultOptions, $options);
         $me = new JShrink();
         $me->breakdownScript($js, $currentOptions);
         $output = ob_get_clean();
         return $output;
     } catch (Exception $e) {
         ob_end_clean();
         throw $e;
     }
 }
예제 #2
0
 /**
  * Takes a string containing javascript and removes unneeded characters in
  * order to shrink the code without altering it's functionality.
  *
  * @param  string      $js      The raw javascript to be minified
  * @param  array       $options Various runtime options in an associative array
  * @throws \Exception
  * @return bool|string
  */
 public static function minify($js, $options = array())
 {
     try {
         ob_start();
         $jshrink = new JShrink();
         $js = $jshrink->lock($js);
         $jshrink->minifyDirectToOutput($js, $options);
         // Sometimes there's a leading new line, so we trim that out here.
         $js = ltrim(ob_get_clean());
         $js = $jshrink->unlock($js);
         unset($jshrink);
         return $js;
     } catch (\Exception $e) {
         if (isset($jshrink)) {
             // Since the breakdownScript function probably wasn't finished
             // we clean it out before discarding it.
             $jshrink->clean();
             unset($jshrink);
         }
         // without this call things get weird, with partially outputted js.
         ob_end_clean();
         throw $e;
     }
 }
예제 #3
0
 /**
  * Minifier::minify takes a string containing javascript and removes
  * unneeded characters in order to shrink the code without altering it's
  * functionality.
  */
 public static function minify($js, $options = array())
 {
     try {
         ob_start();
         $currentOptions = array_merge(self::$defaultOptions, $options);
         if (!isset(self::$jshrink)) {
             self::$jshrink = new JShrink();
         }
         self::$jshrink->breakdownScript($js, $currentOptions);
         return ob_get_clean();
     } catch (Exception $e) {
         if (isset(self::$jshrink)) {
             self::$jshrink->clean();
         }
         ob_end_clean();
         throw $e;
     }
 }
예제 #4
0
     // Replace www_root/ and Minify
     $data = str_replace(array('$www_root', 'www_root/', '$static_root', 'static_root/', '$admin_root/', 'admin_root/'), array(WWW_ROOT, WWW_ROOT, STATIC_ROOT, STATIC_ROOT, ADMIN_ROOT, ADMIN_ROOT), $data);
     if (is_array($_GET)) {
         foreach ($_GET as $key => $val) {
             if ($key != "bigtree_htaccess_url") {
                 $data = str_replace('$' . $key, $val, $data);
             }
         }
     }
     if (is_array($bigtree["config"]["js"]["vars"])) {
         foreach ($bigtree["config"]["js"]["vars"] as $key => $val) {
             $data = str_replace('$' . $key, $val, $data);
         }
     }
     if ($bigtree["config"]["js"]["minify"]) {
         $data = JShrink::minify($data);
     }
     BigTree::putFile($cfile, $data);
     header("Content-type: text/javascript");
     die($data);
 } else {
     // Added a line to .htaccess to hopefully give us IF_MODIFIED_SINCE when running as CGI
     if (function_exists("apache_request_headers")) {
         $headers = apache_request_headers();
         $ims = $headers["If-Modified-Since"];
     } else {
         $ims = $_SERVER["HTTP_IF_MODIFIED_SINCE"];
     }
     if (!$ims || strtotime($ims) != $last_modified) {
         header("Content-type: text/javascript");
         header("Last-Modified: " . gmdate("D, d M Y H:i:s", $last_modified) . ' GMT', true, 200);
예제 #5
0
     readfile($file['cacheFile']);
     continue;
 }
 $source = file_get_contents($file['path']);
 if (array_key_exists('preProcessor', $file)) {
     $source = $file['preProcessor']($source);
 }
 $path = dirname($file['path']);
 $headers = array();
 if (!$file['compress']) {
     $headers[] = 'File not compressed due to configuration';
 } else {
     switch ($group['type']) {
         case 'javascript':
             try {
                 $source = JShrink::minify($source, array('flaggedComments' => false));
             } catch (Exception $ex) {
                 $headers[] = 'Error during compression, file not compressed!';
                 @ob_flush();
                 ob_start();
                 var_dump($ex->getMessage());
                 $headers[] = rtrim(ob_get_contents(), "\r\n");
                 ob_end_clean();
             }
             break;
         case 'css':
             $source = str_replace(array("\r", "\n"), '', $source);
             // remove newlines
             $source = preg_replace('#/\\*.*?\\*/|\\s*([{};,])\\s*|(:)\\s+#', '$1$2', $source);
             // remove comments, and whitespace around { } ; , and after :
             $source = str_replace('}', "}\n", $source);
예제 #6
0
//Include the js groups
$groups = (require "./config/js_groups.php");
$js = '';
$modified = array();
if (isset($groups[$_GET['g']])) {
    foreach ($groups[$_GET['g']] as $file) {
        $new_file = realpath($base_path . $file);
        $js .= file_get_contents($new_file);
        $modified[] = filemtime($new_file);
    }
}
//Add this page too
$modified[] = filemtime($base_path . "js.php");
//Get the latest modified date
rsort($modified);
$last_modified = $modified[0];
if (!isset($_GET['debug'])) {
    $js = JShrink::minify($js, array('flaggedComments' => false));
}
$requested_time = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : time();
if ($last_modified === $requested_time) {
    header("HTTP/1.1 304 Not Modified");
    exit;
}
header("Content-Type: application/x-javascript; charset=utf8");
header("Cache-control: public, max-age=691200, must-revalidate");
header("Last-Modified: " . gmdate('D, d M Y H:i:s', $last_modified) . " GMT");
header("Expires: " . gmdate('D, d M Y H:i:s', filemtime($base_path . 'js.php') + 691200) . " GMT");
echo $js;
ob_end_flush();
//end of js.php
예제 #7
0
            return true;
        },
        afterClose:function(){
            window.location.reload()
        }
    });
});
</script>
<?php 
// Capture output end
$output = ob_get_clean();
// Remove script tags
$output = str_replace("<script type=\"text/javascript\">\n", '', $output);
$output = str_replace("</script>", '', $output);
// Minify
$output = JShrink::minify($output);
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
        Remove this if you use the .htaccess -->
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>ScraperLink</title>
        <meta name="description" content="">
        <meta name="author" content="gazbond">
        <meta name="viewport" content="width=device-width; initial-scale=1.0">
        <!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
        <link rel="shortcut icon" href="/favicon.ico">
        <link rel="apple-touch-icon" href="/apple-touch-icon.png">