Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit fa9204f

Browse files
author
chrisisbeef
committed
Preparing to repackage source again
1 parent f69ff6c commit fa9204f

File tree

6 files changed

+373
-201
lines changed

6 files changed

+373
-201
lines changed

build-functions.php

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
<?php
2+
/*
3+
* OWASP Enterprise Security API (ESAPI)
4+
*
5+
* This file is part of the Open Web Application Security Project (OWASP)
6+
* Enterprise Security API (ESAPI) project. For details, please see
7+
* <a href="http://www.owasp.org/index.php/ESAPI">http://www.owasp.org/index.php/ESAPI</a>.
8+
*
9+
* Copyright (c) 2008 - The OWASP Foundation
10+
*
11+
* The ESAPI is published by OWASP under the BSD license. You should read and accept the
12+
* LICENSE before you use, modify, and/or redistribute this software.
13+
*/
14+
15+
/**
16+
* Delete a file, or a folder and its contents (recursive algorithm)
17+
*
18+
* @author Aidan Lister <[email protected]>
19+
* @version 1.0.3
20+
* @link http://aidanlister.com/repos/v/function.rmdirr.php
21+
* @param string $dirname Directory to delete
22+
* @return bool Returns TRUE on success, FALSE on failure
23+
*/
24+
function rmdirr($dirname)
25+
{
26+
// Sanity check
27+
if (!file_exists($dirname)) {
28+
return false;
29+
}
30+
31+
// Simple delete for a file
32+
if (is_file($dirname) || is_link($dirname)) {
33+
return unlink($dirname);
34+
}
35+
36+
// Loop through the folder
37+
$dir = dir($dirname);
38+
while (false !== $entry = $dir->read()) {
39+
// Skip pointers
40+
if ($entry == '.' || $entry == '..') {
41+
continue;
42+
}
43+
44+
// Recurse
45+
rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
46+
}
47+
48+
// Clean up
49+
$dir->close();
50+
return rmdir($dirname);
51+
}
52+
53+
/**
54+
* Compress Javascript/CSS using the YUI Compressor
55+
*
56+
* You must set $jarFile and $tempDir before calling the minify functions.
57+
* Also, depending on your shell's environment, you may need to specify
58+
* the full path to java in $javaExecutable or use putenv() to setup the
59+
* Java environment.
60+
*
61+
* <code>
62+
* Minify_YUICompressor::$jarFile = '/path/to/yuicompressor-2.3.5.jar';
63+
* Minify_YUICompressor::$tempDir = '/tmp';
64+
* $code = Minify_YUICompressor::minifyJs(
65+
* $code
66+
* ,array('nomunge' => true, 'line-break' => 1000)
67+
* );
68+
* </code>
69+
*
70+
* @todo unit tests, $options docs
71+
*
72+
* @package Minify
73+
* @author Stephen Clay <[email protected]>
74+
*/
75+
class Minify_YUICompressor {
76+
77+
/**
78+
* Filepath of the YUI Compressor jar file. This must be set before
79+
* calling minifyJs() or minifyCss().
80+
*
81+
* @var string
82+
*/
83+
public static $jarFile = null;
84+
85+
/**
86+
* Writable temp directory. This must be set before calling minifyJs()
87+
* or minifyCss().
88+
*
89+
* @var string
90+
*/
91+
public static $tempDir = null;
92+
93+
/**
94+
* Filepath of "java" executable (may be needed if not in shell's PATH)
95+
*
96+
* @var string
97+
*/
98+
public static $javaExecutable = 'java';
99+
100+
/**
101+
* Minify a Javascript string
102+
*
103+
* @param string $js
104+
*
105+
* @param array $options (verbose is ignored)
106+
*
107+
* @see http://www.julienlecomte.net/yuicompressor/README
108+
*
109+
* @return string
110+
*/
111+
public static function minifyJs($js, $options = array())
112+
{
113+
return self::_minify('js', $js, $options);
114+
}
115+
116+
/**
117+
* Minify a CSS string
118+
*
119+
* @param string $css
120+
*
121+
* @param array $options (verbose is ignored)
122+
*
123+
* @see http://www.julienlecomte.net/yuicompressor/README
124+
*
125+
* @return string
126+
*/
127+
public static function minifyCss($css, $options = array())
128+
{
129+
return self::_minify('css', $css, $options);
130+
}
131+
132+
private static function _minify($type, $content, $options)
133+
{
134+
self::_prepare();
135+
if (! ($tmpFile = tempnam(self::$tempDir, 'yuic_'))) {
136+
throw new Exception('Minify_YUICompressor : could not create temp file.');
137+
}
138+
file_put_contents($tmpFile, $content);
139+
exec(self::_getCmd($options, $type, $tmpFile), $output);
140+
unlink($tmpFile);
141+
return implode("\n", $output);
142+
}
143+
144+
private static function _getCmd($userOptions, $type, $tmpFile)
145+
{
146+
$o = array_merge(
147+
array(
148+
'charset' => ''
149+
,'line-break' => 5000
150+
,'type' => $type
151+
,'nomunge' => false
152+
,'preserve-semi' => false
153+
,'disable-optimizations' => false
154+
)
155+
,$userOptions
156+
);
157+
$cmd = self::$javaExecutable . ' -jar ' . escapeshellarg(self::$jarFile)
158+
. " --type {$type}"
159+
. (preg_match('/^[a-zA-Z\\-]+$/', $o['charset'])
160+
? " --charset {$o['charset']}"
161+
: '')
162+
. (is_numeric($o['line-break']) && $o['line-break'] >= 0
163+
? ' --line-break ' . (int)$o['line-break']
164+
: '');
165+
if ($type === 'js') {
166+
foreach (array('nomunge', 'preserve-semi', 'disable-optimizations') as $opt) {
167+
$cmd .= $o[$opt]
168+
? " --{$opt}"
169+
: '';
170+
}
171+
}
172+
return $cmd . ' ' . escapeshellarg($tmpFile);
173+
}
174+
175+
private static function _prepare()
176+
{
177+
if (! is_file(self::$jarFile)
178+
|| ! is_dir(self::$tempDir)
179+
|| ! is_writable(self::$tempDir)
180+
) {
181+
throw new Exception('Minify_YUICompressor : $jarFile and $tempDir must be set.');
182+
}
183+
}
184+
}
185+
186+
function get_files($root_dir, $allow_extensions = array( 'js' ), $ignore_files = array( ), $ignore_regex = '/^_/', $ignore_dirs = array(".","..",".svn"), $all_data=array() )
187+
{
188+
// run through content of root directory
189+
$dir_content = scandir($root_dir);
190+
foreach($dir_content as $key => $content)
191+
{
192+
$path = $root_dir.'/'.$content;
193+
if(is_file($path) && is_readable($path))
194+
{
195+
// skip ignored files
196+
if(!in_array($content, $ignore_files))
197+
{
198+
if (preg_match($ignore_regex,$content) == 0)
199+
{
200+
$content_chunks = explode(".",$content);
201+
$ext = $content_chunks[count($content_chunks) - 1];
202+
// only include files with desired extensions
203+
if (in_array($ext, $allow_extensions))
204+
{
205+
// save file name with path
206+
$all_data[] = $path;
207+
}
208+
}
209+
}
210+
}
211+
// if content is a directory and readable, add path and name
212+
elseif(is_dir($path) && is_readable($path))
213+
{
214+
// skip any ignored dirs
215+
if(!in_array($content, $ignore_dirs))
216+
{
217+
// recursive callback to open new directory
218+
$all_data = get_files($path, $allow_extensions, $ignore_files, $ignore_regex, $ignore_dirs, $all_data);
219+
}
220+
}
221+
} // end foreach
222+
return $all_data;
223+
} // end get_files()
224+
225+
function getDirectoryTree( $outerDir, $filters = array() ){
226+
$dirs = array_diff( scandir( $outerDir ), array_merge( Array( ".", "..",".svn" ), $filters ) );
227+
$dir_array = Array();
228+
foreach( $dirs as $d )
229+
$dir_array[ $d ] = is_dir($outerDir."/".$d) ? getDirectoryTree( $outerDir."/".$d, $filters ) : $dir_array[ $d ] = $d;
230+
return $dir_array;
231+
}
232+
233+
function getRelativePath( $a ) {
234+
$o = "";
235+
if ( is_array($a) ) {
236+
foreach( $a as $e ) {
237+
$o .= getRelativePath( $e );
238+
}
239+
}
240+
return $o.$a;
241+
}
242+
?>

0 commit comments

Comments
 (0)