1
|
|
|
<? |
|
|
|
|
2
|
|
|
|
3
|
|
|
die('Run this script to batch-compress the current Xinha snapshot. To run the script, open the file and comment out the die() command'); |
4
|
|
|
$repository_url = 'http://svn.xinha.org/trunk'; |
5
|
|
|
$version = ''; |
6
|
|
|
$date = date('r'); |
7
|
|
|
error_reporting(E_ALL); |
8
|
|
|
ini_set('show_errors', 1); |
9
|
|
|
|
10
|
|
|
$return = []; |
11
|
|
|
function scan($dir, $durl = '', $min_size = '0') |
12
|
|
|
{ |
13
|
|
|
static $seen = []; |
14
|
|
|
global $return; |
15
|
|
|
$files = []; |
16
|
|
|
|
17
|
|
|
$dir = realpath($dir); |
18
|
|
|
if (isset($seen[$dir])) { |
19
|
|
|
return $files; |
20
|
|
|
} |
21
|
|
|
$seen[$dir] = true; |
22
|
|
|
$dh = @opendir($dir); |
23
|
|
|
|
24
|
|
|
while ($dh && ($file = readdir($dh))) { |
25
|
|
|
if ('.' !== $file && '..' !== $file) { |
26
|
|
|
$path = realpath($dir . '/' . $file); |
27
|
|
|
$url = $durl . '/' . $file; |
28
|
|
|
|
29
|
|
|
if (preg_match("/\.svn|lang/", $path)) { |
30
|
|
|
continue; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if (is_dir($path)) { |
34
|
|
|
scan($path); |
35
|
|
|
} elseif (is_file($path)) { |
36
|
|
|
if (!preg_match("/\.js$/", $path) || filesize($path) < $min_size) { |
37
|
|
|
continue; |
38
|
|
|
} |
39
|
|
|
$return[] = $path; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
@closedir($dh); |
|
|
|
|
44
|
|
|
|
45
|
|
|
return $files; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
scan('../'); |
49
|
|
|
$cwd = getcwd(); |
50
|
|
|
|
51
|
|
|
$root_dir = realpath($cwd . '/..'); |
52
|
|
|
|
53
|
|
|
print 'Processing ' . count($return) . ' files<br />'; |
54
|
|
|
|
55
|
|
|
$prefix = '/* This compressed file is part of Xinha. For uncompressed sources, forum, and bug reports, go to xinha.org */'; |
56
|
|
|
if ($version) { |
57
|
|
|
$prefix .= "\n/* This file is part of version $version released $date */"; |
58
|
|
|
} |
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
|
|
|
set_time_limit(60); |
77
|
|
|
print "Processed $file<br />"; |
78
|
|
|
flush(); |
79
|
|
|
$file_url = $repository_url . str_replace($root_dir, '', $file); |
80
|
|
|
|
81
|
|
|
copy($file, $file . '_uncompr.js'); |
82
|
|
|
|
83
|
|
|
$file_prefix = $prefix . "\n/* The URL of the most recent version of this file is $file_url */"; |
84
|
|
|
|
85
|
|
|
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"); |
86
|
|
|
if (preg_match('/js: ".*?", line \d+:/', file_get_contents($file)) || preg_match('/sh: java: command not found/', file_get_contents($file))) { |
87
|
|
|
unlink($file); |
88
|
|
|
rename($file . '_uncompr.js', $file); |
89
|
|
|
} else { |
90
|
|
|
unlink($file . '_uncompr.js'); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
print "Operation complete." |
94
|
|
|
?> |
|
|
|
|
95
|
|
|
|
96
|
|
|
|
97
|
|
|
|
Short opening tags are disabled in PHP?s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.
As a precaution to avoid these problems better use the long opening tag
<?php
.