Project

General

Profile

Revision 246

View differences:

branches/extplorer2/admin.extplorer.php
41 41
// The eXtplorer version number
42 42
$GLOBALS['ext_version'] = '2.1.8';
43 43
$GLOBALS['ext_home'] = 'http://extplorer.net';
44

  
44
$dir = '';
45 45
//------------------------------------------------------------------------------
46 46
if( defined( 'E_STRICT' ) ) { // Suppress Strict Standards Warnings
47 47
	error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
branches/extplorer2/fetchscript.php
113 113
* This is necessary, because this file is (usually) located somewhere else than the CSS file! That makes
114 114
* relative URL references point to wrong directories - so we need to fix that!
115 115
*/
116
function cssUrl( $ref, $subdir ) {
116
function cssUrl( $refs  ) {
117

  
118
	$ref = $refs[1];
119

  
120
	$subdir = $GLOBALS['subdir'];
117 121
	$ref = str_replace( "'", '', stripslashes( $ref ));
118 122
	$ref = trim( str_replace( '"', '', $ref) );
119 123
	// Absolute References don't need to be fixed
120 124
	if( substr( $ref, 0, 4 ) == 'http' ) {
121 125
		return 'url( "'. $ref.'" )';
122 126
	}
127

  
123 128
	chdir( dirname( __FILE__ ).'/'.$subdir );
124 129
	$ref = str_replace( dirname( __FILE__ ), '', realpath( $ref ));
125 130
	$ref = str_replace( "\\", '/', $ref );
131

  
126 132
	return 'url( "'. substr( $ref, 1 ).'" )';
127 133

  
128 134
}
......
223 229
			$mime_type = 'text/css'; 
224 230
			header( 'Content-Type: '.$mime_type.';');
225 231
			$css = implode( '', file( $file ));
226

  
227
			$str_css =	preg_replace("/url\((.+?)\)/ie","cssUrl('\\1', '$subdir')", $css);
232
			$GLOBALS['subdir'] = $subdir;
233
			$str_css =	preg_replace_callback("/url\((.+?)\)/i", 'cssUrl', $css);
228 234
			echo $str_css;
229 235

  
230 236
			break;
branches/extplorer2/config/mimes.php
5 5
//------------------------------------------------------------------------------
6 6
// editable files:
7 7
$GLOBALS["editable_ext"]=
8
	"\.asm$|\.rc$|\.hh$|\.hxx$|\.odl$|\.idl$|\.rc2$|\.dlg$|\.less$"
9
	."|\.php$|\.php3$|\.php4$|\.php5$|\.phtml$|\.inc$|\.sql$|\.csv$"
10
	."|\.vb$|\.vbs$|\.bas$|\.frm$|\.cls$|\.ctl$|\.rb$|\.htm$|\.html$|\.shtml$|\.dhtml$|\.xml$"
11
	."|\.js$|\.css$|\.cgi$|\.cpp$|\.c$|\.cc$|\.cxx$|\.hpp$|\.h$|\.lua$"
12
	."|\.pas$|\.p$|\.pl$|\.java$|\.py$|\.sh$|\.bat$|\.tcl$|\.tk$"
13
	."|\.txt$|\.ini$|\.conf$|\.properties$|\.htaccess$|\.htpasswd$";
8
	array(".asm", ".rc", ".hh", ".hxx", ".odl", ".idl", ".rc2", ".dlg", ".less"
9
	,".php", ".php3", ".php4", ".php5", ".phtml", ".inc", ".sql", ".csv"
10
	,".vb", ".vbs", ".bas", ".frm", ".cls", ".ctl", ".rb", ".htm", ".html", ".shtml", ".dhtml", ".xml"
11
	,".js", ".css", ".cgi", ".cpp", ".c", ".cc", ".cxx", ".hpp", ".h", ".lua"
12
	,".pas", ".p", ".pl", ".java", ".py", ".sh", ".bat", ".tcl", ".tk"
13
	,".txt", ".ini", ".conf", ".properties", ".htaccess", ".htpasswd");
14 14

  
15 15
//------------------------------------------------------------------------------
16 16
// image files:
17
$GLOBALS["images_ext"]="\.png$|\.bmp$|\.jpg$|\.jpeg$|\.gif$|\.tif$|\.ico$";
17
$GLOBALS["images_ext"]=array(".png", ".bmp", ".jpg", ".jpeg", ".gif", ".tif", ".ico" );
18 18
//------------------------------------------------------------------------------
19 19
// mime types: (description,image,extension)
20 20
$GLOBALS["super_mimes"]=array(
21 21
	// dir, exe, file
22 22
	"dir"	=> array(extGetParam( $GLOBALS["mimes"], 'dir', 'Dir' ),"extension/folder.png"),
23
	"exe"	=> array(extGetParam( $GLOBALS["mimes"], 'exe', 'exe' ),"extension/exe.png","\.exe$|\.com$|\.bin$"),
23
	"exe"	=> array(extGetParam( $GLOBALS["mimes"], 'exe', 'exe' ),"extension/exe.png",".exe", ".com", ".bin"),
24 24
	"file"	=> array(extGetParam( $GLOBALS["mimes"], 'file', 'file' ),"extension/document.png")
25 25
);
26 26
$GLOBALS["used_mime_types"]=array(
27 27
	// text
28
	"text"	=> array(extGetParam( $GLOBALS["mimes"], 'text', 'Text' ),  "extension/txt.png",   "\.txt$"),
28
	"text"	=> array(extGetParam( $GLOBALS["mimes"], 'text', 'Text' ),  "extension/txt.png",   ".txt"),
29 29

  
30 30
	// programming
31
	"php"	=> array(extGetParam( $GLOBALS["mimes"], 'php', 'php' ),   "extension/php.png",   "\.php$"),
32
	"php3"	=> array(extGetParam( $GLOBALS["mimes"], 'php3', 'php3' ),  "extension/php3.png",  "\.php3$"),
33
	"php4"	=> array(extGetParam( $GLOBALS["mimes"], 'php4', 'php4' ),  "extension/php4.png",  "\.php4$"),
34
	"php5"	=> array(extGetParam( $GLOBALS["mimes"], 'php5', 'php5' ),  "extension/php5.png",  "\.php5$"),
35
	"phtml"	=> array(extGetParam( $GLOBALS["mimes"], 'phtml', 'phtml' ), "extension/phtml.png", "\.phtml$"),
36
	"inc"	=> array(extGetParam( $GLOBALS["mimes"], 'inc', 'inc' ),   "extension/inc.png",   "\.inc$"),
37
	"sql"	=> array(extGetParam( $GLOBALS["mimes"], 'sql', 'SQL' ),   "extension/sql.png",   "\.sql$"),
38
	"pl"	=> array(extGetParam( $GLOBALS["mimes"], 'pl', 'Perl' ),    "extension/pl.png",    "\.pl$"),
39
	"cgi"	=> array(extGetParam( $GLOBALS["mimes"], 'cgi', 'CGI' ),   "extension/cgi.png",   "\.cgi$"),
40
	"py"	=> array(extGetParam( $GLOBALS["mimes"], 'py', 'Python' ),    "extension/py.png",    "\.py$"),
41
	"sh"	=> array(extGetParam( $GLOBALS["mimes"], 'sh', 'Shell' ),    "extension/sh.png",    "\.sh$"),
42
	"c" 	=> array(extGetParam( $GLOBALS["mimes"], 'c', 'C' ),     "extension/c.png",     "\.c$"),
43
	"cc"	=> array(extGetParam( $GLOBALS["mimes"], 'cc', 'CC' ),    "extension/cc.png",    "\.cc$"),
44
	"cpp"	=> array(extGetParam( $GLOBALS["mimes"], 'cpp', 'CPP' ),   "extension/cpp.png",   "\.cpp$"),
45
	"cxx"	=> array(extGetParam( $GLOBALS["mimes"], 'cxx', 'CXX' ),   "extension/cxx.png",   "\.cxx$"),
46
	"h" 	=> array(extGetParam( $GLOBALS["mimes"], 'h', 'H' ),     "extension/h.png",     "\.h$"),
47
	"hpp" 	=> array(extGetParam( $GLOBALS["mimes"], 'hpp', 'hpp' ),   "extension/hpp.png",   "\.hpp$"),
48
	"java"	=> array(extGetParam( $GLOBALS["mimes"], 'java', 'Java' ),  "extension/java.png",  "\.java$"),
49
	"class"	=> array(extGetParam( $GLOBALS["mimes"], 'class', 'Class' ), "extension/class.png", "\.class$"),
50
	"jar"	=> array(extGetParam( $GLOBALS["mimes"], 'jar', 'Jar' ),   "extension/jar.png",   "\.jar$"),
31
	"php"	=> array(extGetParam( $GLOBALS["mimes"], 'php', 'php' ),   "extension/php.png",   ".php"),
32
	"php3"	=> array(extGetParam( $GLOBALS["mimes"], 'php3', 'php3' ),  "extension/php3.png",  ".php3"),
33
	"php4"	=> array(extGetParam( $GLOBALS["mimes"], 'php4', 'php4' ),  "extension/php4.png",  ".php4"),
34
	"php5"	=> array(extGetParam( $GLOBALS["mimes"], 'php5', 'php5' ),  "extension/php5.png",  ".php5"),
35
	"phtml"	=> array(extGetParam( $GLOBALS["mimes"], 'phtml', 'phtml' ), "extension/phtml.png", ".phtml"),
36
	"inc"	=> array(extGetParam( $GLOBALS["mimes"], 'inc', 'inc' ),   "extension/inc.png",   ".inc"),
37
	"sql"	=> array(extGetParam( $GLOBALS["mimes"], 'sql', 'SQL' ),   "extension/sql.png",   ".sql"),
38
	"pl"	=> array(extGetParam( $GLOBALS["mimes"], 'pl', 'Perl' ),    "extension/pl.png",    ".pl"),
39
	"cgi"	=> array(extGetParam( $GLOBALS["mimes"], 'cgi', 'CGI' ),   "extension/cgi.png",   ".cgi"),
40
	"py"	=> array(extGetParam( $GLOBALS["mimes"], 'py', 'Python' ),    "extension/py.png",    ".py"),
41
	"sh"	=> array(extGetParam( $GLOBALS["mimes"], 'sh', 'Shell' ),    "extension/sh.png",    ".sh"),
42
	"c" 	=> array(extGetParam( $GLOBALS["mimes"], 'c', 'C' ),     "extension/c.png",     ".c"),
43
	"cc"	=> array(extGetParam( $GLOBALS["mimes"], 'cc', 'CC' ),    "extension/cc.png",    ".cc"),
44
	"cpp"	=> array(extGetParam( $GLOBALS["mimes"], 'cpp', 'CPP' ),   "extension/cpp.png",   ".cpp"),
45
	"cxx"	=> array(extGetParam( $GLOBALS["mimes"], 'cxx', 'CXX' ),   "extension/cxx.png",   ".cxx"),
46
	"h" 	=> array(extGetParam( $GLOBALS["mimes"], 'h', 'H' ),     "extension/h.png",     ".h"),
47
	"hpp" 	=> array(extGetParam( $GLOBALS["mimes"], 'hpp', 'hpp' ),   "extension/hpp.png",   ".hpp"),
48
	"java"	=> array(extGetParam( $GLOBALS["mimes"], 'java', 'Java' ),  "extension/java.png",  ".java"),
49
	"class"	=> array(extGetParam( $GLOBALS["mimes"], 'class', 'Class' ), "extension/class.png", ".class"),
50
	"jar"	=> array(extGetParam( $GLOBALS["mimes"], 'jar', 'Jar' ),   "extension/jar.png",   ".jar"),
51 51

  
52 52
	// browser
53
	"htm"	=> array(extGetParam( $GLOBALS["mimes"], 'htm', 'HTML' ),   "extension/htm.png",   "\.htm$"),
54
	"html"	=> array(extGetParam( $GLOBALS["mimes"], 'html', 'HTML' ),  "extension/html.png",  "\.html$"),
55
	"shtml"	=> array(extGetParam( $GLOBALS["mimes"], 'shtml', 'sHTML' ), "extension/shtml.png", "\.shtml$"),
56
	"dhtml"	=> array(extGetParam( $GLOBALS["mimes"], 'dhtml', 'dHTML' ), "extension/dhtml.png", "\.dhtml$"),
57
	"xhtml"	=> array(extGetParam( $GLOBALS["mimes"], 'xhtml', 'XHTML' ), "extension/xhtml.png", "\.xhtml$"),
58
	"xml"	=> array(extGetParam( $GLOBALS["mimes"], 'xml', 'XML' ),   "extension/xml.png",   "\.xml$"),
59
	"js"	=> array(extGetParam( $GLOBALS["mimes"], 'js', 'JS' ),    "extension/js.png",    "\.js$"),
60
	"css"	=> array(extGetParam( $GLOBALS["mimes"], 'css', 'CSS' ),   "extension/css.png",   "\.css$"),
53
	"htm"	=> array(extGetParam( $GLOBALS["mimes"], 'htm', 'HTML' ),   "extension/htm.png",   ".htm"),
54
	"html"	=> array(extGetParam( $GLOBALS["mimes"], 'html', 'HTML' ),  "extension/html.png",  ".html"),
55
	"shtml"	=> array(extGetParam( $GLOBALS["mimes"], 'shtml', 'sHTML' ), "extension/shtml.png", ".shtml"),
56
	"dhtml"	=> array(extGetParam( $GLOBALS["mimes"], 'dhtml', 'dHTML' ), "extension/dhtml.png", ".dhtml"),
57
	"xhtml"	=> array(extGetParam( $GLOBALS["mimes"], 'xhtml', 'XHTML' ), "extension/xhtml.png", ".xhtml"),
58
	"xml"	=> array(extGetParam( $GLOBALS["mimes"], 'xml', 'XML' ),   "extension/xml.png",   ".xml"),
59
	"js"	=> array(extGetParam( $GLOBALS["mimes"], 'js', 'JS' ),    "extension/js.png",    ".js"),
60
	"css"	=> array(extGetParam( $GLOBALS["mimes"], 'css', 'CSS' ),   "extension/css.png",   ".css"),
61 61
	
62 62
	// images
63
	"gif"	=> array(extGetParam( $GLOBALS["mimes"], 'gif', 'GIF' ),   "extension/gif.png",   "\.gif$"),
64
	"jpg"	=> array(extGetParam( $GLOBALS["mimes"], 'jpg', 'JPG' ),   "extension/jpg.png",   "\.jpg$"),
65
	"jpeg"	=> array(extGetParam( $GLOBALS["mimes"], 'jpeg', 'JPEG' ),  "extension/jpeg.png",  "\.jpeg$"),
66
	"bmp"	=> array(extGetParam( $GLOBALS["mimes"], 'bmp', 'Bitmap' ),   "extension/bmp.png",   "\.bmp$"),
67
	"png"	=> array(extGetParam( $GLOBALS["mimes"], 'png', 'PNG' ),   "extension/png.png",   "\.png$"),
63
	"gif"	=> array(extGetParam( $GLOBALS["mimes"], 'gif', 'GIF' ),   "extension/gif.png",   ".gif"),
64
	"jpg"	=> array(extGetParam( $GLOBALS["mimes"], 'jpg', 'JPG' ),   "extension/jpg.png",   ".jpg"),
65
	"jpeg"	=> array(extGetParam( $GLOBALS["mimes"], 'jpeg', 'JPEG' ),  "extension/jpeg.png",  ".jpeg"),
66
	"bmp"	=> array(extGetParam( $GLOBALS["mimes"], 'bmp', 'Bitmap' ),   "extension/bmp.png",   ".bmp"),
67
	"png"	=> array(extGetParam( $GLOBALS["mimes"], 'png', 'PNG' ),   "extension/png.png",   ".png"),
68 68
	
69 69
	// compressed
70
	"zip"	=> array(extGetParam( $GLOBALS["mimes"], 'zip', 'ZIP' ),   "extension/zip.png",   "\.zip$"),
71
	"tar"	=> array(extGetParam( $GLOBALS["mimes"], 'tar', 'TAR' ),   "extension/tar.png",   "\.tar$"),
72
	"tgz"	=> array(extGetParam( $GLOBALS["mimes"], 'tgz', 'Tar/GZ' ),   "extension/tgz.png",   "\.tgz$"),
73
	"gz"	=> array(extGetParam( $GLOBALS["mimes"], 'gz', 'GZip' ),    "extension/gz.png",    "\.gz$"),
70
	"zip"	=> array(extGetParam( $GLOBALS["mimes"], 'zip', 'ZIP' ),   "extension/zip.png",   ".zip"),
71
	"tar"	=> array(extGetParam( $GLOBALS["mimes"], 'tar', 'TAR' ),   "extension/tar.png",   ".tar"),
72
	"tgz"	=> array(extGetParam( $GLOBALS["mimes"], 'tgz', 'Tar/GZ' ),   "extension/tgz.png",   ".tgz"),
73
	"gz"	=> array(extGetParam( $GLOBALS["mimes"], 'gz', 'GZip' ),    "extension/gz.png",    ".gz"),
74 74

  
75 75

  
76
	"bz2"	=> array(extGetParam( $GLOBALS["mimes"], 'bz2', 'Bzip2' ),   "extension/bz2.png",   "\.bz2$"),
77
	"tbz"	=> array(extGetParam( $GLOBALS["mimes"], 'tbz', 'Tar/Bz2' ),   "extension/tbz.png",   "\.tbz$"),
78
	"rar"	=> array(extGetParam( $GLOBALS["mimes"], 'rar', 'RAR' ),   "extension/rar.png",   "\.rar$"),
76
	"bz2"	=> array(extGetParam( $GLOBALS["mimes"], 'bz2', 'Bzip2' ),   "extension/bz2.png",   ".bz2"),
77
	"tbz"	=> array(extGetParam( $GLOBALS["mimes"], 'tbz', 'Tar/Bz2' ),   "extension/tbz.png",   ".tbz"),
78
	"rar"	=> array(extGetParam( $GLOBALS["mimes"], 'rar', 'RAR' ),   "extension/rar.png",   ".rar"),
79 79

  
80 80
	// music
81
	"mp3"	=> array(extGetParam( $GLOBALS["mimes"], 'mp3', 'Mp3' ),   "extension/mp3.png",   "\.mp3$"),
82
	"wav"	=> array(extGetParam( $GLOBALS["mimes"], 'wav', 'WAV' ),   "extension/wav.png",   "\.wav$"),
83
	"midi"	=> array(extGetParam( $GLOBALS["mimes"], 'midi', 'Midi' ),  "extension/midi.png",  "\.mid$"),
84
	"rm"	=> array(extGetParam( $GLOBALS["mimes"], 'real', 'Real Media' ),  "extension/rm.png",    "\.rm$"),
85
	"ra"	=> array(extGetParam( $GLOBALS["mimes"], 'real', 'Real Audio' ),  "extension/ra.png",    "\.ra$"),
86
	"ram"	=> array(extGetParam( $GLOBALS["mimes"], 'real', 'Real Media' ),  "extension/ram.png",   "\.ram$"),
87
	"pls"	=> array(extGetParam( $GLOBALS["mimes"], 'pls', 'pls' ),   "extension/pls.png",   "\.pls$"),
88
	"m3u"	=> array(extGetParam( $GLOBALS["mimes"], 'm3u', 'm3u' ),   "extension/m3u.png",   "\.m3u$"),
81
	"mp3"	=> array(extGetParam( $GLOBALS["mimes"], 'mp3', 'Mp3' ),   "extension/mp3.png",   ".mp3"),
82
	"wav"	=> array(extGetParam( $GLOBALS["mimes"], 'wav', 'WAV' ),   "extension/wav.png",   ".wav"),
83
	"midi"	=> array(extGetParam( $GLOBALS["mimes"], 'midi', 'Midi' ),  "extension/midi.png",  ".mid"),
84
	"rm"	=> array(extGetParam( $GLOBALS["mimes"], 'real', 'Real Media' ),  "extension/rm.png",    ".rm"),
85
	"ra"	=> array(extGetParam( $GLOBALS["mimes"], 'real', 'Real Audio' ),  "extension/ra.png",    ".ra"),
86
	"ram"	=> array(extGetParam( $GLOBALS["mimes"], 'real', 'Real Media' ),  "extension/ram.png",   ".ram"),
87
	"pls"	=> array(extGetParam( $GLOBALS["mimes"], 'pls', 'pls' ),   "extension/pls.png",   ".pls"),
88
	"m3u"	=> array(extGetParam( $GLOBALS["mimes"], 'm3u', 'm3u' ),   "extension/m3u.png",   ".m3u"),
89 89

  
90 90
	// movie
91
	"mpg"	=> array(extGetParam( $GLOBALS["mimes"], 'mpg', 'MPG' ),   "extension/mpg.png",   "\.mpg$"),
92
	"mpeg"	=> array(extGetParam( $GLOBALS["mimes"], 'mpeg', 'MPG'),  "extension/mpeg.png",  "\.mpeg$"),
93
	"mov"	=> array(extGetParam( $GLOBALS["mimes"], 'mov', 'MOV' ),   "extension/mov.png",   "\.mov$"),
94
	"avi"	=> array(extGetParam( $GLOBALS["mimes"], 'avi', 'AVI' ),   "extension/avi.png",   "\.avi$"),
95
	"swf"	=> array(extGetParam( $GLOBALS["mimes"], 'swf', 'SWF' ),   "extension/swf.png",   "\.swf$"),
91
	"mpg"	=> array(extGetParam( $GLOBALS["mimes"], 'mpg', 'MPG' ),   "extension/mpg.png",   ".mpg"),
92
	"mpeg"	=> array(extGetParam( $GLOBALS["mimes"], 'mpeg', 'MPG'),  "extension/mpeg.png",  ".mpeg"),
93
	"mov"	=> array(extGetParam( $GLOBALS["mimes"], 'mov', 'MOV' ),   "extension/mov.png",   ".mov"),
94
	"avi"	=> array(extGetParam( $GLOBALS["mimes"], 'avi', 'AVI' ),   "extension/avi.png",   ".avi"),
95
	"swf"	=> array(extGetParam( $GLOBALS["mimes"], 'swf', 'SWF' ),   "extension/swf.png",   ".swf"),
96 96
	
97 97
	// Micosoft / Adobe
98
	"doc"	=> array(extGetParam( $GLOBALS["mimes"], 'doc', 'Word' ),   "extension/doc.png",   "\.doc$"),
99
	"docx"	=> array(extGetParam( $GLOBALS["mimes"], 'docx', 'Word' ),  "extension/docx.png",  "\.docx$"),
100
	"xls"	=> array(extGetParam( $GLOBALS["mimes"], 'xls', 'Excel' ),   "extension/xls.png",   "\.xls$"),
101
	"xlsx"	=> array(extGetParam( $GLOBALS["mimes"], 'xlsx', 'Excel' ),  "extension/xlsx.png",  "\.xlsx$"),
102
	"rtf"	=> array(extGetParam( $GLOBALS["mimes"], 'rtf', 'Rich Text Format' ),  "extension/doc.png",  "\.rtf$"),
98
	"doc"	=> array(extGetParam( $GLOBALS["mimes"], 'doc', 'Word' ),   "extension/doc.png",   ".doc"),
99
	"docx"	=> array(extGetParam( $GLOBALS["mimes"], 'docx', 'Word' ),  "extension/docx.png",  ".docx"),
100
	"xls"	=> array(extGetParam( $GLOBALS["mimes"], 'xls', 'Excel' ),   "extension/xls.png",   ".xls"),
101
	"xlsx"	=> array(extGetParam( $GLOBALS["mimes"], 'xlsx', 'Excel' ),  "extension/xlsx.png",  ".xlsx"),
102
	"rtf"	=> array(extGetParam( $GLOBALS["mimes"], 'rtf', 'Rich Text Format' ),  "extension/doc.png",  ".rtf"),
103 103
	
104
	"pdf"	=> array(extGetParam( $GLOBALS["mimes"], 'pdf', 'PDF' ),   "extension/pdf.png",   "\.pdf$")
104
	"pdf"	=> array(extGetParam( $GLOBALS["mimes"], 'pdf', 'PDF' ),   "extension/pdf.png",   ".pdf")
105 105
);
106 106
//------------------------------------------------------------------------------
branches/extplorer2/libraries/System.php
1 1
<?php
2
//
3
// +----------------------------------------------------------------------+
4
// | PHP Version 5                                                        |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2004 The PHP Group                                |
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 3.0 of the PHP license,       |
9
// | that is bundled with this package in the file LICENSE, and is        |
10
// | available through the world-wide-web at the following url:           |
11
// | http://www.php.net/license/3_0.txt.                                  |
12
// | If you did not receive a copy of the PHP license and are unable to   |
13
// | obtain it through the world-wide-web, please send a note to          |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
16
// | Authors: Tomas V.V.Cox <cox@idecnet.com>                             |
17
// +----------------------------------------------------------------------+
18
//
19
// $Id: System.php,v 1.36 2004/06/15 16:33:46 pajoye Exp $
20
//
2
/**
3
 * File/Directory manipulation
4
 *
5
 * PHP versions 4 and 5
6
 *
7
 * @category   pear
8
 * @package    System
9
 * @author     Tomas V.V.Cox <cox@idecnet.com>
10
 * @copyright  1997-2009 The Authors
11
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
12
 * @link       http://pear.php.net/package/PEAR
13
 * @since      File available since Release 0.1
14
 */
21 15

  
16
/**
17
 * base class
18
 */
22 19
require_once 'PEAR.php';
23
require_once( dirname(__FILE__).'/Console/Getopt.php');
20
require_once 'Console/Getopt.php';
24 21

  
25 22
$GLOBALS['_System_temp_files'] = array();
26 23

  
......
31 28
* Unix and Windows. The names and usage has been taken from its respectively
32 29
* GNU commands. The functions will return (bool) false on error and will
33 30
* trigger the error with the PHP trigger_error() function (you can silence
34
* the error by prefixing a '@' sign after the function call).
31
* the error by prefixing a '@' sign after the function call, but this
32
* is not recommended practice.  Instead use an error handler with
33
* {@link set_error_handler()}).
35 34
*
36 35
* Documentation on this class you can find in:
37 36
* http://pear.php.net/manual/
......
46 45
*
47 46
* System::rm(array('-r', $file1, $dir1));
48 47
*
49
* @package  System
50
* @author   Tomas V.V.Cox <cox@idecnet.com>
51
* @version  $Revision: 1.36 $
52
* @access   public
53
* @see      http://pear.php.net/manual/
48
* @category   pear
49
* @package    System
50
* @author     Tomas V.V. Cox <cox@idecnet.com>
51
* @copyright  1997-2006 The PHP Group
52
* @license    http://opensource.org/licenses/bsd-license.php New BSD License
53
* @version    Release: 1.10.1
54
* @link       http://pear.php.net/package/PEAR
55
* @since      Class available since Release 0.1
56
* @static
54 57
*/
55 58
class System
56 59
{
57 60
    /**
58
    * returns the commandline arguments of a function
59
    *
60
    * @param    string  $argv           the commandline
61
    * @param    string  $short_options  the allowed option short-tags
62
    * @param    string  $long_options   the allowed option long-tags
63
    * @return   array   the given options and there values
64
    * @access private
65
    */
66
    function _parseArgs($argv, $short_options, $long_options = null)
61
     * returns the commandline arguments of a function
62
     *
63
     * @param    string  $argv           the commandline
64
     * @param    string  $short_options  the allowed option short-tags
65
     * @param    string  $long_options   the allowed option long-tags
66
     * @return   array   the given options and there values
67
     */
68
    public static function _parseArgs($argv, $short_options, $long_options = null)
67 69
    {
68 70
        if (!is_array($argv) && $argv !== null) {
69
            $argv = preg_split('/\s+/', $argv);
71
            /*
72
            // Quote all items that are a short option
73
            $av = preg_split('/(\A| )--?[a-z0-9]+[ =]?((?<!\\\\)((,\s*)|((?<!,)\s+))?)/i', $argv, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
74
            $offset = 0;
75
            foreach ($av as $a) {
76
                $b = trim($a[0]);
77
                if ($b{0} == '"' || $b{0} == "'") {
78
                    continue;
79
                }
80

  
81
                $escape = escapeshellarg($b);
82
                $pos = $a[1] + $offset;
83
                $argv = substr_replace($argv, $escape, $pos, strlen($b));
84
                $offset += 2;
85
            }
86
            */
87

  
88
            // Find all items, quoted or otherwise
89
            preg_match_all("/(?:[\"'])(.*?)(?:['\"])|([^\s]+)/", $argv, $av);
90
            $argv = $av[1];
91
            foreach ($av[2] as $k => $a) {
92
                if (empty($a)) {
93
                    continue;
94
                }
95
                $argv[$k] = trim($a) ;
96
            }
70 97
        }
71
        return Console_Getopt::getopt2($argv, $short_options);
98

  
99
        return Console_Getopt::getopt2($argv, $short_options, $long_options);
72 100
    }
73 101

  
74 102
    /**
75
    * Output errors with PHP trigger_error(). You can silence the errors
76
    * with prefixing a "@" sign to the function call: @System::mkdir(..);
77
    *
78
    * @param mixed $error a PEAR error or a string with the error message
79
    * @return bool false
80
    * @access private
81
    */
82
    function raiseError($error)
103
     * Output errors with PHP trigger_error(). You can silence the errors
104
     * with prefixing a "@" sign to the function call: @System::mkdir(..);
105
     *
106
     * @param mixed $error a PEAR error or a string with the error message
107
     * @return bool false
108
     */
109
    protected static function raiseError($error)
83 110
    {
84 111
        if (PEAR::isError($error)) {
85 112
            $error = $error->getMessage();
......
89 116
    }
90 117

  
91 118
    /**
92
    * Creates a nested array representing the structure of a directory
93
    *
94
    * System::_dirToStruct('dir1', 0) =>
95
    *   Array
96
    *    (
97
    *    [dirs] => Array
98
    *        (
99
    *            [0] => dir1
100
    *        )
101
    *
102
    *    [files] => Array
103
    *        (
104
    *            [0] => dir1/file2
105
    *            [1] => dir1/file3
106
    *        )
107
    *    )
108
    * @param    string  $sPath      Name of the directory
109
    * @param    integer $maxinst    max. deep of the lookup
110
    * @param    integer $aktinst    starting deep of the lookup
111
    * @return   array   the structure of the dir
112
    * @access   private
113
    */
114

  
115
    function _dirToStruct($sPath, $maxinst, $aktinst = 0)
119
     * Creates a nested array representing the structure of a directory
120
     *
121
     * System::_dirToStruct('dir1', 0) =>
122
     *   Array
123
     *    (
124
     *    [dirs] => Array
125
     *        (
126
     *            [0] => dir1
127
     *        )
128
     *
129
     *    [files] => Array
130
     *        (
131
     *            [0] => dir1/file2
132
     *            [1] => dir1/file3
133
     *        )
134
     *    )
135
     * @param    string  $sPath      Name of the directory
136
     * @param    integer $maxinst    max. deep of the lookup
137
     * @param    integer $aktinst    starting deep of the lookup
138
     * @param    bool    $silent     if true, do not emit errors.
139
     * @return   array   the structure of the dir
140
     */
141
    protected static function _dirToStruct($sPath, $maxinst, $aktinst = 0, $silent = false)
116 142
    {
117 143
        $struct = array('dirs' => array(), 'files' => array());
118 144
        if (($dir = @opendir($sPath)) === false) {
119
            System::raiseError("Could not open dir $sPath");
145
            if (!$silent) {
146
                System::raiseError("Could not open dir $sPath");
147
            }
120 148
            return $struct; // XXX could not open error
121 149
        }
122
        $struct['dirs'][] = $sPath; // XXX don't add if '.' or '..' ?
150

  
151
        $struct['dirs'][] = $sPath = realpath($sPath); // XXX don't add if '.' or '..' ?
123 152
        $list = array();
124
        while ($file = readdir($dir)) {
153
        while (false !== ($file = readdir($dir))) {
125 154
            if ($file != '.' && $file != '..') {
126 155
                $list[] = $file;
127 156
            }
128 157
        }
158

  
129 159
        closedir($dir);
130
        sort($list);
160
        natsort($list);
131 161
        if ($aktinst < $maxinst || $maxinst == 0) {
132
            foreach($list as $val) {
162
            foreach ($list as $val) {
133 163
                $path = $sPath . DIRECTORY_SEPARATOR . $val;
134
                if (is_dir($path)) {
135
                    $tmp = System::_dirToStruct($path, $maxinst, $aktinst+1);
136
                    $struct = array_merge_recursive($tmp, $struct);
164
                if (is_dir($path) && !is_link($path)) {
165
                    $tmp    = System::_dirToStruct($path, $maxinst, $aktinst+1, $silent);
166
                    $struct = array_merge_recursive($struct, $tmp);
137 167
                } else {
138 168
                    $struct['files'][] = $path;
139 169
                }
140 170
            }
141 171
        }
172

  
142 173
        return $struct;
143 174
    }
144 175

  
145 176
    /**
146
    * Creates a nested array representing the structure of a directory and files
147
    *
148
    * @param    array $files Array listing files and dirs
149
    * @return   array
150
    * @see System::_dirToStruct()
151
    */
152
    function _multipleToStruct($files)
177
     * Creates a nested array representing the structure of a directory and files
178
     *
179
     * @param    array $files Array listing files and dirs
180
     * @return   array
181
     * @static
182
     * @see System::_dirToStruct()
183
     */
184
    protected static function _multipleToStruct($files)
153 185
    {
154 186
        $struct = array('dirs' => array(), 'files' => array());
155 187
        settype($files, 'array');
156 188
        foreach ($files as $file) {
157
            if (is_dir($file)) {
158
                $tmp = System::_dirToStruct($file, 0);
189
            if (is_dir($file) && !is_link($file)) {
190
                $tmp    = System::_dirToStruct($file, 0);
159 191
                $struct = array_merge_recursive($tmp, $struct);
160 192
            } else {
161
                $struct['files'][] = $file;
193
                if (!in_array($file, $struct['files'])) {
194
                    $struct['files'][] = $file;
195
                }
162 196
            }
163 197
        }
164 198
        return $struct;
165 199
    }
166 200

  
167 201
    /**
168
    * The rm command for removing files.
169
    * Supports multiple files and dirs and also recursive deletes
170
    *
171
    * @param    string  $args   the arguments for rm
172
    * @return   mixed   PEAR_Error or true for success
173
    * @access   public
174
    */
175
    function rm($args)
202
     * The rm command for removing files.
203
     * Supports multiple files and dirs and also recursive deletes
204
     *
205
     * @param    string  $args   the arguments for rm
206
     * @return   mixed   PEAR_Error or true for success
207
     * @static
208
     * @access   public
209
     */
210
    public static function rm($args)
176 211
    {
177
        $opts = System::_parseArgs($args, 'rf'); // "f" do nothing but like it :-)
212
        $opts = System::_parseArgs($args, 'rf'); // "f" does nothing but I like it :-)
178 213
        if (PEAR::isError($opts)) {
179 214
            return System::raiseError($opts);
180 215
        }
181
        foreach($opts[0] as $opt) {
216
        foreach ($opts[0] as $opt) {
182 217
            if ($opt[0] == 'r') {
183 218
                $do_recursive = true;
184 219
            }
......
186 221
        $ret = true;
187 222
        if (isset($do_recursive)) {
188 223
            $struct = System::_multipleToStruct($opts[1]);
189
            foreach($struct['files'] as $file) {
224
            foreach ($struct['files'] as $file) {
190 225
                if (!@unlink($file)) {
191 226
                    $ret = false;
192 227
                }
193 228
            }
194
            foreach($struct['dirs'] as $dir) {
229

  
230
            rsort($struct['dirs']);
231
            foreach ($struct['dirs'] as $dir) {
195 232
                if (!@rmdir($dir)) {
196 233
                    $ret = false;
197 234
                }
......
208 245
    }
209 246

  
210 247
    /**
211
    * Make directories. Note that we use call_user_func('mkdir') to avoid
212
    * a problem with ZE2 calling System::mkDir instead of the native PHP func.
213
    *
214
    * @param    string  $args    the name of the director(y|ies) to create
215
    * @return   bool    True for success
216
    * @access   public
217
    */
218
    function mkDir($args)
248
     * Make directories.
249
     *
250
     * The -p option will create parent directories
251
     * @param    string  $args    the name of the director(y|ies) to create
252
     * @return   bool    True for success
253
     */
254
    public static function mkDir($args)
219 255
    {
220 256
        $opts = System::_parseArgs($args, 'pm:');
221 257
        if (PEAR::isError($opts)) {
222 258
            return System::raiseError($opts);
223 259
        }
260

  
224 261
        $mode = 0777; // default mode
225
        foreach($opts[0] as $opt) {
262
        foreach ($opts[0] as $opt) {
226 263
            if ($opt[0] == 'p') {
227 264
                $create_parents = true;
228
            } elseif($opt[0] == 'm') {
265
            } elseif ($opt[0] == 'm') {
229 266
                // if the mode is clearly an octal number (starts with 0)
230 267
                // convert it to decimal
231 268
                if (strlen($opt[1]) && $opt[1]{0} == '0') {
......
237 274
                $mode = $opt[1];
238 275
            }
239 276
        }
277

  
240 278
        $ret = true;
241 279
        if (isset($create_parents)) {
242
            foreach($opts[1] as $dir) {
280
            foreach ($opts[1] as $dir) {
243 281
                $dirstack = array();
244
                while (!@is_dir($dir) && $dir != DIRECTORY_SEPARATOR) {
282
                while ((!file_exists($dir) || !is_dir($dir)) &&
283
                        $dir != DIRECTORY_SEPARATOR) {
245 284
                    array_unshift($dirstack, $dir);
246 285
                    $dir = dirname($dir);
247 286
                }
287

  
248 288
                while ($newdir = array_shift($dirstack)) {
249
                    if (!call_user_func('mkdir', $newdir, $mode)) {
289
                    if (!is_writeable(dirname($newdir))) {
250 290
                        $ret = false;
291
                        break;
251 292
                    }
293

  
294
                    if (!mkdir($newdir, $mode)) {
295
                        $ret = false;
296
                    }
252 297
                }
253 298
            }
254 299
        } else {
255 300
            foreach($opts[1] as $dir) {
256
                if (!@is_dir($dir) && !call_user_func('mkdir', $dir, $mode)) {
301
                if ((@file_exists($dir) || !is_dir($dir)) && !mkdir($dir, $mode)) {
257 302
                    $ret = false;
258 303
                }
259 304
            }
260 305
        }
306

  
261 307
        return $ret;
262 308
    }
263 309

  
264 310
    /**
265
    * Concatenate files
266
    *
267
    * Usage:
268
    * 1) $var = System::cat('sample.txt test.txt');
269
    * 2) System::cat('sample.txt test.txt > final.txt');
270
    * 3) System::cat('sample.txt test.txt >> final.txt');
271
    *
272
    * Note: as the class use fopen, urls should work also (test that)
273
    *
274
    * @param    string  $args   the arguments
275
    * @return   boolean true on success
276
    * @access   public
277
    */
278
    function &cat($args)
311
     * Concatenate files
312
     *
313
     * Usage:
314
     * 1) $var = System::cat('sample.txt test.txt');
315
     * 2) System::cat('sample.txt test.txt > final.txt');
316
     * 3) System::cat('sample.txt test.txt >> final.txt');
317
     *
318
     * Note: as the class use fopen, urls should work also (test that)
319
     *
320
     * @param    string  $args   the arguments
321
     * @return   boolean true on success
322
     */
323
    public static function &cat($args)
279 324
    {
280 325
        $ret = null;
281 326
        $files = array();
282 327
        if (!is_array($args)) {
283
            $args = preg_split('/\s+/', $args);
328
            $args = preg_split('/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
284 329
        }
285
        for($i=0; $i < count($args); $i++) {
330

  
331
        $count_args = count($args);
332
        for ($i = 0; $i < $count_args; $i++) {
286 333
            if ($args[$i] == '>') {
287 334
                $mode = 'wb';
288 335
                $outputfile = $args[$i+1];
......
295 342
                $files[] = $args[$i];
296 343
            }
297 344
        }
345
        $outputfd = false;
298 346
        if (isset($mode)) {
299 347
            if (!$outputfd = fopen($outputfile, $mode)) {
300 348
                $err = System::raiseError("Could not open $outputfile");
......
308 356
                continue;
309 357
            }
310 358
            while ($cont = fread($fd, 2048)) {
311
                if (isset($outputfd)) {
359
                if (is_resource($outputfd)) {
312 360
                    fwrite($outputfd, $cont);
313 361
                } else {
314 362
                    $ret .= $cont;
......
316 364
            }
317 365
            fclose($fd);
318 366
        }
319
        if (@is_resource($outputfd)) {
367
        if (is_resource($outputfd)) {
320 368
            fclose($outputfd);
321 369
        }
322 370
        return $ret;
323 371
    }
324 372

  
325 373
    /**
326
    * Creates temporary files or directories. This function will remove
327
    * the created files when the scripts finish its execution.
328
    *
329
    * Usage:
330
    *   1) $tempfile = System::mktemp("prefix");
331
    *   2) $tempdir  = System::mktemp("-d prefix");
332
    *   3) $tempfile = System::mktemp();
333
    *   4) $tempfile = System::mktemp("-t /var/tmp prefix");
334
    *
335
    * prefix -> The string that will be prepended to the temp name
336
    *           (defaults to "tmp").
337
    * -d     -> A temporary dir will be created instead of a file.
338
    * -t     -> The target dir where the temporary (file|dir) will be created. If
339
    *           this param is missing by default the env vars TMP on Windows or
340
    *           TMPDIR in Unix will be used. If these vars are also missing
341
    *           c:\windows\temp or /tmp will be used.
342
    *
343
    * @param   string  $args  The arguments
344
    * @return  mixed   the full path of the created (file|dir) or false
345
    * @see System::tmpdir()
346
    * @access  public
347
    */
348
    function mktemp($args = null)
374
     * Creates temporary files or directories. This function will remove
375
     * the created files when the scripts finish its execution.
376
     *
377
     * Usage:
378
     *   1) $tempfile = System::mktemp("prefix");
379
     *   2) $tempdir  = System::mktemp("-d prefix");
380
     *   3) $tempfile = System::mktemp();
381
     *   4) $tempfile = System::mktemp("-t /var/tmp prefix");
382
     *
383
     * prefix -> The string that will be prepended to the temp name
384
     *           (defaults to "tmp").
385
     * -d     -> A temporary dir will be created instead of a file.
386
     * -t     -> The target dir where the temporary (file|dir) will be created. If
387
     *           this param is missing by default the env vars TMP on Windows or
388
     *           TMPDIR in Unix will be used. If these vars are also missing
389
     *           c:\windows\temp or /tmp will be used.
390
     *
391
     * @param   string  $args  The arguments
392
     * @return  mixed   the full path of the created (file|dir) or false
393
     * @see System::tmpdir()
394
     */
395
    public static function mktemp($args = null)
349 396
    {
350 397
        static $first_time = true;
351 398
        $opts = System::_parseArgs($args, 't:d');
352 399
        if (PEAR::isError($opts)) {
353 400
            return System::raiseError($opts);
354 401
        }
355
        foreach($opts[0] as $opt) {
356
            if($opt[0] == 'd') {
402

  
403
        foreach ($opts[0] as $opt) {
404
            if ($opt[0] == 'd') {
357 405
                $tmp_is_dir = true;
358
            } elseif($opt[0] == 't') {
406
            } elseif ($opt[0] == 't') {
359 407
                $tmpdir = $opt[1];
360 408
            }
361 409
        }
410

  
362 411
        $prefix = (isset($opts[1][0])) ? $opts[1][0] : 'tmp';
363 412
        if (!isset($tmpdir)) {
364 413
            $tmpdir = System::tmpdir();
365 414
        }
366
        if (!System::mkDir("-p $tmpdir")) {
415

  
416
        if (!System::mkDir(array('-p', $tmpdir))) {
367 417
            return false;
368 418
        }
419

  
369 420
        $tmp = tempnam($tmpdir, $prefix);
370 421
        if (isset($tmp_is_dir)) {
371 422
            unlink($tmp); // be careful possible race condition here
372
            if (!call_user_func('mkdir', $tmp, 0700)) {
423
            if (!mkdir($tmp, 0700)) {
373 424
                return System::raiseError("Unable to create temporary directory $tmpdir");
374 425
            }
375 426
        }
427

  
376 428
        $GLOBALS['_System_temp_files'][] = $tmp;
429
        if (isset($tmp_is_dir)) {
430
            //$GLOBALS['_System_temp_files'][] = dirname($tmp);
431
        }
432

  
377 433
        if ($first_time) {
378 434
            PEAR::registerShutdownFunc(array('System', '_removeTmpFiles'));
379 435
            $first_time = false;
380 436
        }
437

  
381 438
        return $tmp;
382 439
    }
383 440

  
384 441
    /**
385
    * Remove temporary files created my mkTemp. This function is executed
386
    * at script shutdown time
387
    *
388
    * @access private
389
    */
390
    function _removeTmpFiles()
442
     * Remove temporary files created my mkTemp. This function is executed
443
     * at script shutdown time
444
     */
445
    public static function _removeTmpFiles()
391 446
    {
392 447
        if (count($GLOBALS['_System_temp_files'])) {
393 448
            $delete = $GLOBALS['_System_temp_files'];
394 449
            array_unshift($delete, '-r');
395 450
            System::rm($delete);
451
            $GLOBALS['_System_temp_files'] = array();
396 452
        }
397 453
    }
398 454

  
399 455
    /**
400
    * Get the path of the temporal directory set in the system
401
    * by looking in its environments variables.
402
    * Note: php.ini-recommended removes the "E" from the variables_order setting,
403
    * making unavaible the $_ENV array, that s why we do tests with _ENV
404
    *
405
    * @return string The temporal directory on the system
406
    */
407
    function tmpdir()
456
     * Get the path of the temporal directory set in the system
457
     * by looking in its environments variables.
458
     * Note: php.ini-recommended removes the "E" from the variables_order setting,
459
     * making unavaible the $_ENV array, that s why we do tests with _ENV
460
     *
461
     * @return string The temporary directory on the system
462
     */
463
    public static function tmpdir()
408 464
    {
409 465
        if (OS_WINDOWS) {
466
            if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) {
467
                return $var;
468
            }
410 469
            if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) {
411 470
                return $var;
412 471
            }
413
            if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) {
472
            if ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : getenv('USERPROFILE')) {
414 473
                return $var;
415 474
            }
416 475
            if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) {
......
421 480
        if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) {
422 481
            return $var;
423 482
        }
424
        return '/tmp';
483
        return realpath('/tmp');
425 484
    }
426 485

  
427 486
    /**
428
    * The "which" command (show the full path of a command)
429
    *
430
    * @param string $program The command to search for
431
    * @return mixed A string with the full path or false if not found
432
    * @author Stig Bakken <ssb@php.net>
433
    */
434
    function which($program, $fallback = false)
487
     * The "which" command (show the full path of a command)
488
     *
489
     * @param string $program The command to search for
490
     * @param mixed  $fallback Value to return if $program is not found
491
     *
492
     * @return mixed A string with the full path or false if not found
493
     * @author Stig Bakken <ssb@php.net>
494
     */
495
    public static function which($program, $fallback = false)
435 496
    {
436
        // is_executable() is not available on windows
437
        if (OS_WINDOWS) {
438
            $pear_is_executable = 'is_file';
439
        } else {
440
            $pear_is_executable = 'is_executable';
497
        // enforce API
498
        if (!is_string($program) || '' == $program) {
499
            return $fallback;
441 500
        }
442 501

  
443 502
        // full path given
444 503
        if (basename($program) != $program) {
445
            return (@$pear_is_executable($program)) ? $program : $fallback;
504
            $path_elements[] = dirname($program);
505
            $program = basename($program);
506
        } else {
507
            $path = getenv('PATH');
508
            if (!$path) {
509
                $path = getenv('Path'); // some OSes are just stupid enough to do this
510
            }
511

  
512
            $path_elements = explode(PATH_SEPARATOR, $path);
446 513
        }
447 514

  
448
        // XXX FIXME honor safe mode
449
        $path_delim = OS_WINDOWS ? ';' : ':';
450
        $exe_suffixes = OS_WINDOWS ? array('.exe','.bat','.cmd','.com') : array('');
451
        $path_elements = explode($path_delim, getenv('PATH'));
515
        if (OS_WINDOWS) {
516
            $exe_suffixes = getenv('PATHEXT')
517
                                ? explode(PATH_SEPARATOR, getenv('PATHEXT'))
518
                                : array('.exe','.bat','.cmd','.com');
519
            // allow passing a command.exe param
520
            if (strpos($program, '.') !== false) {
521
                array_unshift($exe_suffixes, '');
522
            }
523
        } else {
524
            $exe_suffixes = array('');
525
        }
526

  
452 527
        foreach ($exe_suffixes as $suff) {
453 528
            foreach ($path_elements as $dir) {
454 529
                $file = $dir . DIRECTORY_SEPARATOR . $program . $suff;
455
                if (@is_file($file) && @$pear_is_executable($file)) {
530
                if (is_executable($file)) {
456 531
                    return $file;
457 532
                }
458 533
            }
......
461 536
    }
462 537

  
463 538
    /**
464
    * The "find" command
465
    *
466
    * Usage:
467
    *
468
    * System::find($dir);
469
    * System::find("$dir -type d");
470
    * System::find("$dir -type f");
471
    * System::find("$dir -name *.php");
472
    * System::find("$dir -name *.php -name *.htm*");
473
    * System::find("$dir -maxdepth 1");
474
    *
475
    * Params implmented:
476
    * $dir            -> Start the search at this directory
477
    * -type d         -> return only directories
478
    * -type f         -> return only files
479
    * -maxdepth <n>   -> max depth of recursion
480
    * -name <pattern> -> search pattern (bash style). Multiple -name param allowed
481
    *
482
    * @param  mixed Either array or string with the command line
483
    * @return array Array of found files
484
    *
485
    */
486
    function find($args)
539
     * The "find" command
540
     *
541
     * Usage:
542
     *
543
     * System::find($dir);
544
     * System::find("$dir -type d");
545
     * System::find("$dir -type f");
546
     * System::find("$dir -name *.php");
547
     * System::find("$dir -name *.php -name *.htm*");
548
     * System::find("$dir -maxdepth 1");
549
     *
550
     * Params implmented:
551
     * $dir            -> Start the search at this directory
552
     * -type d         -> return only directories
553
     * -type f         -> return only files
554
     * -maxdepth <n>   -> max depth of recursion
555
     * -name <pattern> -> search pattern (bash style). Multiple -name param allowed
556
     *
557
     * @param  mixed Either array or string with the command line
558
     * @return array Array of found files
559
     */
560
    public static function find($args)
487 561
    {
488 562
        if (!is_array($args)) {
489 563
            $args = preg_split('/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
490 564
        }
491
        $dir = array_shift($args);
565
        $dir = realpath(array_shift($args));
566
        if (!$dir) {
567
            return array();
568
        }
492 569
        $patterns = array();
493 570
        $depth = 0;
494 571
        $do_files = $do_dirs = true;
495
        for ($i = 0; $i < count($args); $i++) {
572
        $args_count = count($args);
573
        for ($i = 0; $i < $args_count; $i++) {
496 574
            switch ($args[$i]) {
497 575
                case '-type':
498 576
                    if (in_array($args[$i+1], array('d', 'f'))) {
499 577
                        if ($args[$i+1] == 'd') {
500
                             $do_files = false;
578
                            $do_files = false;
501 579
                        } else {
502 580
                            $do_dirs = false;
503 581
                        }
......
505 583
                    $i++;
506 584
                    break;
507 585
                case '-name':
508
                    $patterns[] = "(" . preg_replace(array('/\./', '/\*/'),
509
                                                     array('\.', '.*'),
510
                                                     $args[$i+1])
511
                                      . ")";
586
                    $name = preg_quote($args[$i+1], '#');
587
                    // our magic characters ? and * have just been escaped,
588
                    // so now we change the escaped versions to PCRE operators
589
                    $name = strtr($name, array('\?' => '.', '\*' => '.*'));
590
                    $patterns[] = '('.$name.')';
512 591
                    $i++;
513 592
                    break;
514 593
                case '-maxdepth':
......
516 595
                    break;
517 596
            }
518 597
        }
519
        $path = System::_dirToStruct($dir, $depth);
598
        $path = System::_dirToStruct($dir, $depth, 0, true);
520 599
        if ($do_files && $do_dirs) {
521 600
            $files = array_merge($path['files'], $path['dirs']);
522 601
        } elseif ($do_dirs) {
......
525 604
            $files = $path['files'];
526 605
        }
527 606
        if (count($patterns)) {
528
            $patterns = implode('|', $patterns);
607
            $dsq = preg_quote(DIRECTORY_SEPARATOR, '#');
608
            $pattern = '#(^|'.$dsq.')'.implode('|', $patterns).'($|'.$dsq.')#';
529 609
            $ret = array();
530
            for ($i = 0; $i < count($files); $i++) {
531
                if (preg_match("#^$patterns\$#", $files[$i])) {
610
            $files_count = count($files);
611
            for ($i = 0; $i < $files_count; $i++) {
612
                // only search in the part of the file below the current directory
613
                $filepart = basename($files[$i]);
614
                if (preg_match($pattern, $filepart)) {
532 615
                    $ret[] = $files[$i];
533 616
                }
534 617
            }
......
536 619
        }
537 620
        return $files;
538 621
    }
539
}
540
?>
622
}
branches/extplorer2/libraries/Tar.php
39 39
 * @link      http://pear.php.net/package/Archive_Tar
40 40
 */
41 41

  
42
if( !class_exists('PEAR')) {
43
	require_once 'PEAR.php';
44
}
42
require_once 'PEAR.php';
45 43

  
46 44
define('ARCHIVE_TAR_ATT_SEPARATOR', 90001);
47 45
define('ARCHIVE_TAR_END_BLOCK', pack("a512", ''));
48 46

  
47
if (!function_exists('gzopen') && function_exists('gzopen64')) {
48
    function gzopen($filename, $mode, $use_include_path = 0)
49
    {
50
        return gzopen64($filename, $mode, $use_include_path);
51
    }
52
}
53

  
54
if (!function_exists('gztell') && function_exists('gztell64')) {
55
    function gztell($zp)
56
    {
57
        return gztell64($zp);
58
    }
59
}
60

  
61
if (!function_exists('gzseek') && function_exists('gzseek64')) {
62
    function gzseek($zp, $offset, $whence = SEEK_SET)
63
    {
64
        return gzseek64($zp, $offset, $whence);
65
    }
66
}
67

  
49 68
/**
50
* Creates a (compressed) Tar archive
51
*
52
* @package Archive_Tar
53
* @author  Vincent Blavet <vincent@phpconcept.net>
54
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
55
* @version $Revision$
56
*/
69
 * Creates a (compressed) Tar archive
70
 *
71
 * @package Archive_Tar
72
 * @author  Vincent Blavet <vincent@phpconcept.net>
73
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
74
 * @version $Revision$
75
 */
57 76
class Archive_Tar extends PEAR
58 77
{
59 78
    /**
60
    * @var string Name of the Tar
61
    */
62
    var $_tarname='';
79
     * @var string Name of the Tar
80
     */
81
    public $_tarname = '';
63 82

  
64 83
    /**
65
    * @var boolean if true, the Tar file will be gzipped
66
    */
67
    var $_compress=false;
84
     * @var boolean if true, the Tar file will be gzipped
85
     */
86
    public $_compress = false;
68 87

  
69 88
    /**
70
    * @var string Type of compression : 'none', 'gz' or 'bz2'
71
    */
72
    var $_compress_type='none';
89
     * @var string Type of compression : 'none', 'gz', 'bz2' or 'lzma2'
90
     */
91
    public $_compress_type = 'none';
73 92

  
74 93
    /**
75
    * @var string Explode separator
76
    */
77
    var $_separator=' ';
94
     * @var string Explode separator
95
     */
96
    public $_separator = ' ';
78 97

  
79 98
    /**
80
    * @var file descriptor
81
    */
82
    var $_file=0;
99
     * @var file descriptor
100
     */
101
    public $_file = 0;
83 102

  
84 103
    /**
85
    * @var string Local Tar name of a remote Tar (http:// or ftp://)
86
    */
87
    var $_temp_tarname='';
104
     * @var string Local Tar name of a remote Tar (http:// or ftp://)
105
     */
106
    public $_temp_tarname = '';
88 107

  
89 108
    /**
90
    * @var string regular expression for ignoring files or directories
91
    */
92
    var $_ignore_regexp='';
109
     * @var string regular expression for ignoring files or directories
110
     */
111
    public $_ignore_regexp = '';
93 112

  
94 113
    /**
95 114
     * @var object PEAR_Error object
96 115
     */
97
    var $error_object=null; 
116
    public $error_object = null;
98 117

  
99
    // {{{ constructor
100 118
    /**
101
    * Archive_Tar Class constructor. This flavour of the constructor only
102
    * declare a new Archive_Tar object, identifying it by the name of the
103
    * tar file.
104
    * If the compress argument is set the tar will be read or created as a
105
    * gzip or bz2 compressed TAR file.
106
    *
107
    * @param string $p_tarname  The name of the tar archive to create
108
    * @param string $p_compress can be null, 'gz' or 'bz2'. This
109
    *               parameter indicates if gzip or bz2 compression
110
    *               is required.  For compatibility reason the
111
    *               boolean value 'true' means 'gz'.
112
    *
113
    * @access public
114
    */
115
    function Archive_Tar($p_tarname, $p_compress = null)
119
     * Archive_Tar Class constructor. This flavour of the constructor only
120
     * declare a new Archive_Tar object, identifying it by the name of the
121
     * tar file.
122
     * If the compress argument is set the tar will be read or created as a
123
     * gzip or bz2 compressed TAR file.
124
     *
125
     * @param string $p_tarname The name of the tar archive to create
126
     * @param string $p_compress can be null, 'gz', 'bz2' or 'lzma2'. This
127
     *               parameter indicates if gzip, bz2 or lzma2 compression
128
     *               is required.  For compatibility reason the
129
     *               boolean value 'true' means 'gz'.
130
     *
131
     * @return bool
132
     */
133
    public function __construct($p_tarname, $p_compress = null)
116 134
    {
117
        $this->PEAR();
135
        parent::__construct();
136
        
118 137
        $this->_compress = false;
119 138
        $this->_compress_type = 'none';
120 139
        if (($p_compress === null) || ($p_compress == '')) {
......
130 149
                    } elseif ($data == "BZ") {
131 150
                        $this->_compress = true;
132 151
                        $this->_compress_type = 'bz2';
152
                    } elseif (file_get_contents($p_tarname, false, null, 1, 4) == '7zXZ') {
153
                        $this->_compress = true;
154
                        $this->_compress_type = 'lzma2';
133 155
                    }
134 156
                }
135 157
            } else {
......
139 161
                    $this->_compress = true;
140 162
                    $this->_compress_type = 'gz';
141 163
                } elseif ((substr($p_tarname, -3) == 'bz2') ||
142
                          (substr($p_tarname, -2) == 'bz')) {
164
                    (substr($p_tarname, -2) == 'bz')
165
                ) {
143 166
                    $this->_compress = true;
144 167
                    $this->_compress_type = 'bz2';
168
                } else {
169
                    if (substr($p_tarname, -2) == 'xz') {
170
                        $this->_compress = true;
171
                        $this->_compress_type = 'lzma2';
172
                    }
145 173
                }
146 174
            }
147 175
        } else {
148 176
            if (($p_compress === true) || ($p_compress == 'gz')) {
149 177
                $this->_compress = true;
150 178
                $this->_compress_type = 'gz';
151
            } else if ($p_compress == 'bz2') {
152
                $this->_compress = true;
153
                $this->_compress_type = 'bz2';
154 179
            } else {
155
                $this->_error("Unsupported compression type '$p_compress'\n".
156
                    "Supported types are 'gz' and 'bz2'.\n");
157
                return false;
180
                if ($p_compress == 'bz2') {
181
                    $this->_compress = true;
182
                    $this->_compress_type = 'bz2';
183
                } else {
184
                    if ($p_compress == 'lzma2') {
185
                        $this->_compress = true;
186
                        $this->_compress_type = 'lzma2';
187
                    } else {
188
                        $this->_error(
189
                            "Unsupported compression type '$p_compress'\n" .
190
                            "Supported types are 'gz', 'bz2' and 'lzma2'.\n"
191
                        );
192
                        return false;
193
                    }
194
                }
158 195
            }
159 196
        }
160 197
        $this->_tarname = $p_tarname;
161
        if ($this->_compress) { // assert zlib or bz2 extension support
162
            if ($this->_compress_type == 'gz')
198
        if ($this->_compress) { // assert zlib or bz2 or xz extension support
199
            if ($this->_compress_type == 'gz') {
163 200
                $extname = 'zlib';
164
            else if ($this->_compress_type == 'bz2')
165
                $extname = 'bz2';
201
            } else {
202
                if ($this->_compress_type == 'bz2') {
203
                    $extname = 'bz2';
204
                } else {
205
                    if ($this->_compress_type == 'lzma2') {
206
                        $extname = 'xz';
207
                    }
208
                }
209
            }
166 210

  
167 211
            if (!extension_loaded($extname)) {
168 212
                PEAR::loadExtension($extname);
169 213
            }
170 214
            if (!extension_loaded($extname)) {
171
                $this->_error("The extension '$extname' couldn't be found.\n".
172
                    "Please make sure your version of PHP was built ".
173
                    "with '$extname' support.\n");
215
                $this->_error(
216
                    "The extension '$extname' couldn't be found.\n" .
217
                    "Please make sure your version of PHP was built " .
218
                    "with '$extname' support.\n"
219
                );
174 220
                return false;
175 221
            }
176 222
        }
177 223
    }
178
    // }}}
179 224

  
180
    // {{{ destructor
181
    function _Archive_Tar()
225
    public function __destruct()
182 226
    {
183 227
        $this->_close();
184 228
        // ----- Look for a local copy to delete
185
        if ($this->_temp_tarname != '')
229
        if ($this->_temp_tarname != '') {
186 230
            @unlink($this->_temp_tarname);
187
        $this->_PEAR();
231
        }
188 232
    }
189
    // }}}
190 233

  
191
    // {{{ create()
192 234
    /**
193
    * This method creates the archive file and add the files / directories
194
    * that are listed in $p_filelist.
195
    * If a file with the same name exist and is writable, it is replaced
196
    * by the new tar.
197
    * The method return false and a PEAR error text.
198
    * The $p_filelist parameter can be an array of string, each string
199
    * representing a filename or a directory name with their path if
200
    * needed. It can also be a single string with names separated by a
201
    * single blank.
202
    * For each directory added in the archive, the files and
203
    * sub-directories are also added.
204
    * See also createModify() method for more details.
205
    *
206
    * @param array $p_filelist An array of filenames and directory names, or a
207
    *              single string with names separated by a single
208
    *              blank space.
209
    *
210
    * @return true on success, false on error.
211
    * @see    createModify()
212
    * @access public
213
    */
214
    function create($p_filelist)
235
     * This method creates the archive file and add the files / directories
236
     * that are listed in $p_filelist.
237
     * If a file with the same name exist and is writable, it is replaced
238
     * by the new tar.
239
     * The method return false and a PEAR error text.
240
     * The $p_filelist parameter can be an array of string, each string
241
     * representing a filename or a directory name with their path if
242
     * needed. It can also be a single string with names separated by a
243
     * single blank.
244
     * For each directory added in the archive, the files and
245
     * sub-directories are also added.
246
     * See also createModify() method for more details.
247
     *
248
     * @param array $p_filelist An array of filenames and directory names, or a
249
     *              single string with names separated by a single
250
     *              blank space.
251
     *
252
     * @return true on success, false on error.
253
     * @see    createModify()
254
     */
255
    public function create($p_filelist)
215 256
    {
216 257
        return $this->createModify($p_filelist, '', '');
217 258
    }
218
    // }}}
219 259

  
220
    // {{{ add()
221 260
    /**
222
    * This method add the files / directories that are listed in $p_filelist in
223
    * the archive. If the archive does not exist it is created.
224
    * The method return false and a PEAR error text.
225
    * The files and directories listed are only added at the end of the archive,
226
    * even if a file with the same name is already archived.
227
    * See also createModify() method for more details.
228
    *
229
    * @param array $p_filelist An array of filenames and directory names, or a
230
    *              single string with names separated by a single
231
    *              blank space.
232
    *
233
    * @return true on success, false on error.
234
    * @see    createModify()
235
    * @access public
236
    */
237
    function add($p_filelist)
261
     * This method add the files / directories that are listed in $p_filelist in
262
     * the archive. If the archive does not exist it is created.
263
     * The method return false and a PEAR error text.
264
     * The files and directories listed are only added at the end of the archive,
265
     * even if a file with the same name is already archived.
266
     * See also createModify() method for more details.
267
     *
268
     * @param array $p_filelist An array of filenames and directory names, or a
269
     *              single string with names separated by a single
270
     *              blank space.
271
     *
272
     * @return true on success, false on error.
273
     * @see    createModify()
274
     * @access public
275
     */
276
    public function add($p_filelist)
238 277
    {
239 278
        return $this->addModify($p_filelist, '', '');
240 279
    }
241
    // }}}
242 280

  
243
    // {{{ extract()
244
    function extract($p_path='', $p_preserve=false)
281
    /**
282
     * @param string $p_path
283
     * @param bool $p_preserve
284
     * @return bool
285
     */
286
    public function extract($p_path = '', $p_preserve = false)
245 287
    {
246 288
        return $this->extractModify($p_path, '', $p_preserve);
247 289
    }
248
    // }}}
249 290

  
250
    // {{{ listContent()
251
    function listContent()
291
    /**
292
     * @return array|int
293
     */
294
    public function listContent()
252 295
    {
253 296
        $v_list_detail = array();
254 297

  
......
262 305

  
263 306
        return $v_list_detail;
264 307
    }
265
    // }}}
266 308

  
267
    // {{{ createModify()
268 309
    /**
269
    * This method creates the archive file and add the files / directories
270
    * that are listed in $p_filelist.
271
    * If the file already exists and is writable, it is replaced by the
272
    * new tar. It is a create and not an add. If the file exists and is
273
    * read-only or is a directory it is not replaced. The method return
274
    * false and a PEAR error text.
275
    * The $p_filelist parameter can be an array of string, each string
276
    * representing a filename or a directory name with their path if
277
    * needed. It can also be a single string with names separated by a
278
    * single blank.
279
    * The path indicated in $p_remove_dir will be removed from the
280
    * memorized path of each file / directory listed when this path
281
    * exists. By default nothing is removed (empty path '')
282
    * The path indicated in $p_add_dir will be added at the beginning of
283
    * the memorized path of each file / directory listed. However it can
284
    * be set to empty ''. The adding of a path is done after the removing
285
    * of path.
286
    * The path add/remove ability enables the user to prepare an archive
287
    * for extraction in a different path than the origin files are.
288
    * See also addModify() method for file adding properties.
289
    *
290
    * @param array  $p_filelist   An array of filenames and directory names,
291
    *                             or a single string with names separated by
292
    *                             a single blank space.
293
    * @param string $p_add_dir    A string which contains a path to be added
294
    *                             to the memorized path of each element in
295
    *                             the list.
296
    * @param string $p_remove_dir A string which contains a path to be
297
    *                             removed from the memorized path of each
298
    *                             element in the list, when relevant.
299
    *
300
    * @return boolean true on success, false on error.
301
    * @access public
302
    * @see addModify()
303
    */
304
    function createModify($p_filelist, $p_add_dir, $p_remove_dir='')
310
     * This method creates the archive file and add the files / directories
311
     * that are listed in $p_filelist.
312
     * If the file already exists and is writable, it is replaced by the
313
     * new tar. It is a create and not an add. If the file exists and is
314
     * read-only or is a directory it is not replaced. The method return
315
     * false and a PEAR error text.
316
     * The $p_filelist parameter can be an array of string, each string
317
     * representing a filename or a directory name with their path if
318
     * needed. It can also be a single string with names separated by a
319
     * single blank.
320
     * The path indicated in $p_remove_dir will be removed from the
321
     * memorized path of each file / directory listed when this path
322
     * exists. By default nothing is removed (empty path '')
323
     * The path indicated in $p_add_dir will be added at the beginning of
324
     * the memorized path of each file / directory listed. However it can
325
     * be set to empty ''. The adding of a path is done after the removing
326
     * of path.
327
     * The path add/remove ability enables the user to prepare an archive
328
     * for extraction in a different path than the origin files are.
329
     * See also addModify() method for file adding properties.
330
     *
331
     * @param array $p_filelist An array of filenames and directory names,
332
     *                             or a single string with names separated by
333
     *                             a single blank space.
334
     * @param string $p_add_dir A string which contains a path to be added
335
     *                             to the memorized path of each element in
336
     *                             the list.
337
     * @param string $p_remove_dir A string which contains a path to be
338
     *                             removed from the memorized path of each
339
     *                             element in the list, when relevant.
340
     *
341
     * @return boolean true on success, false on error.
342
     * @see addModify()
343
     */
344
    public function createModify($p_filelist, $p_add_dir, $p_remove_dir = '')
305 345
    {
306 346
        $v_result = true;
307 347

  
308
        if (!$this->_openWrite())
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff