| 1 | <? |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | $repository_url = 'http://svn.xinha.org/trunk'; |
|---|
| 7 | $version =''; |
|---|
| 8 | $date = date('r'); |
|---|
| 9 | |
|---|
| 10 | $xinha_root = realpath(dirname(__FILE__).'/..'); |
|---|
| 11 | |
|---|
| 12 | error_reporting(E_ALL); |
|---|
| 13 | ini_set('show_errors',1); |
|---|
| 14 | |
|---|
| 15 | $return = array(); |
|---|
| 16 | function scan($dir, $durl = '',$min_size="3000") |
|---|
| 17 | { |
|---|
| 18 | static $seen = array(); |
|---|
| 19 | global $return; |
|---|
| 20 | $files = array(); |
|---|
| 21 | |
|---|
| 22 | $dir = realpath($dir); |
|---|
| 23 | if(isset($seen[$dir])) |
|---|
| 24 | { |
|---|
| 25 | return $files; |
|---|
| 26 | } |
|---|
| 27 | $seen[$dir] = TRUE; |
|---|
| 28 | $dh = @opendir($dir); |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | while($dh && ($file = readdir($dh))) |
|---|
| 32 | { |
|---|
| 33 | if($file !== '.' && $file !== '..') |
|---|
| 34 | { |
|---|
| 35 | $path = realpath($dir . '/' . $file); |
|---|
| 36 | $url = $durl . '/' . $file; |
|---|
| 37 | |
|---|
| 38 | if(preg_match("/\.svn|lang/",$path)) continue; |
|---|
| 39 | |
|---|
| 40 | if(is_dir($path)) |
|---|
| 41 | { |
|---|
| 42 | scan($path); |
|---|
| 43 | } |
|---|
| 44 | elseif(is_file($path)) |
|---|
| 45 | { |
|---|
| 46 | if(!preg_match("/\.(js|css)$/",$path) || filesize($path) < $min_size) continue; |
|---|
| 47 | $return[] = $path; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | @closedir($dh); |
|---|
| 53 | |
|---|
| 54 | return $files; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | scan($xinha_root,0); |
|---|
| 58 | |
|---|
| 59 | print "Processing ".count($return)." files<br />"; |
|---|
| 60 | |
|---|
| 61 | $prefix = "/* This compressed file is part of Xinha. For uncompressed sources, forum, and bug reports, go to xinha.org */"; |
|---|
| 62 | if ($version) $prefix .= "\n/* This file is part of version $version released $date */"; |
|---|
| 63 | $core_prefix = ' |
|---|
| 64 | /*-------------------------------------------------------------------------- |
|---|
| 65 | -- Xinha (is not htmlArea) - http://xinha.org |
|---|
| 66 | -- |
|---|
| 67 | -- Use of Xinha is granted by the terms of the htmlArea License (based on |
|---|
| 68 | -- BSD license) please read license.txt in this package for details. |
|---|
| 69 | -- |
|---|
| 70 | -- Copyright (c) 2005-'.date('Y').' Xinha Developer Team and contributors |
|---|
| 71 | -- |
|---|
| 72 | -- Xinha was originally based on work by Mihai Bazon which is: |
|---|
| 73 | -- Copyright (c) 2003-2004 dynarch.com. |
|---|
| 74 | -- Copyright (c) 2002-2003 interactivetools.com, inc. |
|---|
| 75 | -- This copyright notice MUST stay intact for use. |
|---|
| 76 | -------------------------------------------------------------------------*/ |
|---|
| 77 | '; |
|---|
| 78 | |
|---|
| 79 | foreach ($return as $file) |
|---|
| 80 | { |
|---|
| 81 | set_time_limit ( 60 ); |
|---|
| 82 | print "Processing $file\n"; |
|---|
| 83 | flush(); |
|---|
| 84 | |
|---|
| 85 | $file_url = $repository_url.str_replace($xinha_root,'',$file); |
|---|
| 86 | |
|---|
| 87 | copy($file,$file."_uncompr.js"); |
|---|
| 88 | |
|---|
| 89 | $file_prefix = $prefix."\n/* The URL of the most recent uncompressed version of this file is $file_url */"; |
|---|
| 90 | $ext = preg_replace('/.*?(\.js|\.css)$/','$1',$file); |
|---|
| 91 | |
|---|
| 92 | file_put_contents($file."_uncompr${ext}", preg_replace('/(\/\/[^\n]*)?(?![*])\\\[\n]/','',file_get_contents($file))); |
|---|
| 93 | |
|---|
| 94 | passthru("echo \"".(preg_match('/XinhaCore.js$/',$file) ? $file_prefix.$core_prefix : $prefix)."\" > $file && java -jar {$xinha_root}/contrib/yuicompressor-2.4.2.jar --charset UTF-8 ${file}_uncompr${ext} >> $file 2>&1"); |
|---|
| 95 | if (preg_match('/\d+:\d+:syntax error/',file_get_contents($file)) || preg_match('/sh: java: command not found/', file_get_contents($file))) |
|---|
| 96 | { |
|---|
| 97 | unlink($file); |
|---|
| 98 | rename($file."_uncompr${ext}",$file); |
|---|
| 99 | } |
|---|
| 100 | else |
|---|
| 101 | { |
|---|
| 102 | unlink($file."_uncompr${ext}"); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | } |
|---|
| 106 | print "Operation complete." |
|---|
| 107 | ?> |
|---|