root / branches / new-dialogs / contrib / compress_yui.php

Revision 951, 2.6 kB (checked in by ray, 4 years ago)
  • one more attempt to properly fix #1136
  • added compression script for yui_compressor (though not going to use it)
  • removed some evitable uses of eval()
  • removed alerts for very old Geckos, because the seem to fire with recent versions of Safari
Line 
1<?
2// This is script that uses the YUI compressor (http://www.julienlecomte.net/blog/2007/08/11/)
3// It yields gradually better results than the dojo comressor, but it produces unreadable code
4die("Run this script to batch-compress the current Xinha snapshot. To run the script, open the file and comment out the die() command");
5
6error_reporting(E_ALL);
7ini_set('show_errors',1);
8
9$return = array();
10function scan($dir, $durl = '',$min_size="3000")
11{
12    static $seen = array();
13    global $return;
14    $files = array();
15
16    $dir = realpath($dir);
17    if(isset($seen[$dir]))
18    {
19        return $files;
20    }
21    $seen[$dir] = TRUE;
22    $dh = @opendir($dir);
23
24
25    while($dh && ($file = readdir($dh)))
26    {
27        if($file !== '.' && $file !== '..')
28        {
29            $path = realpath($dir . '/' . $file);
30            $url  = $durl . '/' . $file;
31
32            if(preg_match("/\.svn|lang/",$path)) continue;
33           
34            if(is_dir($path))
35            {
36                scan($path);
37            }
38            elseif(is_file($path))
39            {
40                if(!preg_match("/\.(js|css)$/",$path) || filesize($path) < $min_size) continue;
41                $return[] =  $path;
42            }
43
44        }
45    }
46    @closedir($dh);
47
48    return $files;
49}
50scan("../",0);
51$cwd = getcwd();
52print "Processing ".count($return)." files<br />";
53
54$prefix = "/* This compressed file is part of Xinha. For uncomressed sources, forum, and bug reports, go to xinha.org */";
55$core_prefix = '
56  /*--------------------------------------------------------------------------
57    --  Xinha (is not htmlArea) - http://xinha.org
58    --
59    --  Use of Xinha is granted by the terms of the htmlArea License (based on
60    --  BSD license)  please read license.txt in this package for details.
61    --
62    --  Copyright (c) 2005-2008 Xinha Developer Team and contributors
63    -- 
64    --  Xinha was originally based on work by Mihai Bazon which is:
65    --      Copyright (c) 2003-2004 dynarch.com.
66    --      Copyright (c) 2002-2003 interactivetools.com, inc.
67    --      This copyright notice MUST stay intact for use.
68    -------------------------------------------------------------------------*/
69';
70
71foreach ($return as $file)
72{
73    set_time_limit ( 60 );
74    print "Processing $file<br />";
75    flush();
76    $ext = preg_replace('/.*?(\.js|\.css)$/','$1',$file);
77   
78    file_put_contents($file."_uncompr${ext}", preg_replace('/(\/\/[^\n]*)?(?![*])\\\[\n]/','',file_get_contents($file)));
79
80    exec("echo \"".(preg_match('/XinhaCore.js$/',$file) ? $prefix.$core_prefix : $prefix)."\" > $file && java -jar ${cwd}/yuicompressor-2.2.5.jar  --charset UTF-8 ${file}_uncompr${ext} >> $file 2>&1");
81    if (preg_match('/\d+:\d+:syntax error/',file_get_contents($file)))
82    {
83        unlink($file);
84        rename($file."_uncompr${ext}",$file);
85    }
86    else
87    {
88        unlink($file."_uncompr${ext}");
89    }
90
91}
92print "Operation complete."
93?>
Note: See TracBrowser for help on using the browser.