1 | <?php |
---|
2 | die("Run this script to batch-compress the current Xinha snapshot. To run the script, open the file and comment out the die() command"); |
---|
3 | $repository_url = 'http://svn.xinha.org/trunk'; |
---|
4 | $version =''; |
---|
5 | $date = date('r'); |
---|
6 | error_reporting(E_ALL); |
---|
7 | ini_set('show_errors',1); |
---|
8 | |
---|
9 | $return = array(); |
---|
10 | function scan($dir, $durl = '',$min_size="0") |
---|
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$/",$path) || filesize($path) < $min_size) continue; |
---|
41 | $return[] = $path; |
---|
42 | } |
---|
43 | |
---|
44 | } |
---|
45 | } |
---|
46 | @closedir($dh); |
---|
47 | |
---|
48 | return $files; |
---|
49 | } |
---|
50 | scan("../"); |
---|
51 | $cwd = getcwd(); |
---|
52 | |
---|
53 | $root_dir = realpath($cwd.'/..'); |
---|
54 | |
---|
55 | print "Processing ".count($return)." files<br />"; |
---|
56 | |
---|
57 | $prefix = "/* This compressed file is part of Xinha. For uncompressed sources, forum, and bug reports, go to xinha.org */"; |
---|
58 | if ($version) $prefix .= "\n/* This file is part of version $version released $date */"; |
---|
59 | |
---|
60 | $core_prefix = ' |
---|
61 | /*-------------------------------------------------------------------------- |
---|
62 | -- Xinha (is not htmlArea) - http://xinha.org |
---|
63 | -- |
---|
64 | -- Use of Xinha is granted by the terms of the htmlArea License (based on |
---|
65 | -- BSD license) please read license.txt in this package for details. |
---|
66 | -- |
---|
67 | -- Copyright (c) 2005-2008 Xinha Developer Team and contributors |
---|
68 | -- |
---|
69 | -- Xinha was originally based on work by Mihai Bazon which is: |
---|
70 | -- Copyright (c) 2003-2004 dynarch.com. |
---|
71 | -- Copyright (c) 2002-2003 interactivetools.com, inc. |
---|
72 | -- This copyright notice MUST stay intact for use. |
---|
73 | -------------------------------------------------------------------------*/ |
---|
74 | '; |
---|
75 | foreach ($return as $file) |
---|
76 | { |
---|
77 | set_time_limit ( 60 ); |
---|
78 | print "Processed $file<br />"; |
---|
79 | flush(); |
---|
80 | $file_url = $repository_url.str_replace($root_dir,'',$file); |
---|
81 | |
---|
82 | copy($file,$file."_uncompr.js"); |
---|
83 | |
---|
84 | $file_prefix = $prefix."\n/* The URL of the most recent version of this file is $file_url */"; |
---|
85 | |
---|
86 | exec("echo \"".(preg_match('/XinhaCore.js$/',$file) ? $file_prefix.$core_prefix : $file_prefix)."\" > $file && java -jar ${cwd}/dojo_js_compressor.jar -c ${file}_uncompr.js >> $file 2>&1"); |
---|
87 | if (preg_match('/js: ".*?", line \d+:/',file_get_contents($file)) || preg_match('/sh: java: command not found/', file_get_contents($file))) |
---|
88 | { |
---|
89 | unlink($file); |
---|
90 | rename($file."_uncompr.js",$file); |
---|
91 | } |
---|
92 | else |
---|
93 | { |
---|
94 | unlink($file."_uncompr.js"); |
---|
95 | } |
---|
96 | |
---|
97 | } |
---|
98 | print "Operation complete." |
---|
99 | ?> |
---|