| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* File and input handling routines
|
|
|
4 |
*
|
|
|
5 |
* This class parses command-line options, and works with files to
|
|
|
6 |
* generate lists of files to parse based on the ignore/include options
|
|
|
7 |
*
|
|
|
8 |
* phpDocumentor :: automatic documentation generator
|
|
|
9 |
*
|
|
|
10 |
* PHP versions 4 and 5
|
|
|
11 |
*
|
|
|
12 |
* Copyright (c) 2000-2006 Joshua Eichorn, Gregory Beaver
|
|
|
13 |
*
|
|
|
14 |
* LICENSE:
|
|
|
15 |
*
|
|
|
16 |
* This library is free software; you can redistribute it
|
|
|
17 |
* and/or modify it under the terms of the GNU Lesser General
|
|
|
18 |
* Public License as published by the Free Software Foundation;
|
|
|
19 |
* either version 2.1 of the License, or (at your option) any
|
|
|
20 |
* later version.
|
|
|
21 |
*
|
|
|
22 |
* This library is distributed in the hope that it will be useful,
|
|
|
23 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
25 |
* Lesser General Public License for more details.
|
|
|
26 |
*
|
|
|
27 |
* You should have received a copy of the GNU Lesser General Public
|
|
|
28 |
* License along with this library; if not, write to the Free Software
|
|
|
29 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
30 |
*
|
|
|
31 |
* @package phpDocumentor
|
|
|
32 |
* @author Joshua Eichorn <jeichorn@phpdoc.org>
|
|
|
33 |
* @author Gregory Beaver <cellog@php.net>
|
|
|
34 |
* @copyright 2000-2006 Joshua Eichorn, Gregory Beaver
|
|
|
35 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
36 |
* @version CVS: $Id: Io.inc 286921 2009-08-08 05:01:24Z ashnazg $
|
|
|
37 |
* @filesource
|
|
|
38 |
* @link http://www.phpdoc.org
|
|
|
39 |
* @link http://pear.php.net/PhpDocumentor
|
|
|
40 |
* @since 0.1
|
|
|
41 |
*/
|
|
|
42 |
/**
|
|
|
43 |
* Class to handle file and user io opperations
|
|
|
44 |
*
|
|
|
45 |
* @author Joshua Eichorn <jeichorn@phpdoc.org>
|
|
|
46 |
* @author Gregory Beaver <cellog@php.net>
|
|
|
47 |
* @version $Id: Io.inc 286921 2009-08-08 05:01:24Z ashnazg $
|
|
|
48 |
* @package phpDocumentor
|
|
|
49 |
*/
|
|
|
50 |
class Io
|
|
|
51 |
{
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Holds all the options that are avaible to the cmd line interface
|
|
|
55 |
* and to the different web interfaces
|
|
|
56 |
*/
|
|
|
57 |
var $phpDocOptions;
|
|
|
58 |
/**
|
|
|
59 |
* Format: array(array(regexp-ready string to search for whole path,
|
|
|
60 |
* regexp-ready string to search for basename of ignore strings),...)
|
|
|
61 |
* @var false|array
|
|
|
62 |
*/
|
|
|
63 |
var $ignore;
|
|
|
64 |
/**
|
|
|
65 |
* A specific array of values that boolean-based arguments can understand,
|
|
|
66 |
* aided by the {@link decideOnOrOff()} helper method.
|
|
|
67 |
*
|
|
|
68 |
* Use lowercase letters always, to simplify string comparisons
|
|
|
69 |
* @var array
|
|
|
70 |
*/
|
|
|
71 |
var $valid_booleans = array
|
|
|
72 |
(
|
|
|
73 |
'', ' ', 'on', 'y', 'yes', 'true', '1',
|
|
|
74 |
'off', 'n', 'no', 'false', '0'
|
|
|
75 |
|
|
|
76 |
);
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* creates an array $this->phpDocOptions and sets program options in it.
|
|
|
80 |
* Array is in the format of:
|
|
|
81 |
* <pre>
|
|
|
82 |
* [filename][tag][] = "f";
|
|
|
83 |
* [filename][tag][] = "-file";
|
|
|
84 |
* [filename][desc] "name of file to parse"
|
|
|
85 |
* </pre>
|
|
|
86 |
*/
|
|
|
87 |
function Io()
|
|
|
88 |
{
|
|
|
89 |
$this->phpDocOptions['filename']['tag'] = array( "-f", "--filename");
|
|
|
90 |
$this->phpDocOptions['filename']['desc'] = "name of file(s) to parse ',' file1,file2. Can contain complete path and * ? wildcards";
|
|
|
91 |
$this->phpDocOptions['filename']['type'] = "path";
|
|
|
92 |
|
|
|
93 |
$this->phpDocOptions['directory']['tag'] = array( "-d", "--directory");
|
|
|
94 |
$this->phpDocOptions['directory']['desc'] = "name of a directory(s) to parse directory1,directory2";
|
|
|
95 |
$this->phpDocOptions['directory']['type'] = "path";
|
|
|
96 |
|
|
|
97 |
$this->phpDocOptions['examplesdir']['tag'] = array( "-ed", "--examplesdir");
|
|
|
98 |
$this->phpDocOptions['examplesdir']['desc'] = "full path of the directory to look for example files from @example tags";
|
|
|
99 |
$this->phpDocOptions['examplesdir']['type'] = "path";
|
|
|
100 |
|
|
|
101 |
$this->phpDocOptions['templatebase']['tag'] = array( "-tb", "--templatebase");
|
|
|
102 |
$this->phpDocOptions['templatebase']['desc'] = "base location of all templates for this parse.";
|
|
|
103 |
$this->phpDocOptions['templatebase']['type'] = "path";
|
|
|
104 |
|
|
|
105 |
$this->phpDocOptions['target']['tag'] = array("-t", "--target");
|
|
|
106 |
$this->phpDocOptions['target']['desc'] = "path where to save the generated files";
|
|
|
107 |
$this->phpDocOptions['target']['type'] = "path";
|
|
|
108 |
|
|
|
109 |
$this->phpDocOptions['ignore']['tag'] = array("-i", "--ignore");
|
|
|
110 |
$this->phpDocOptions['ignore']['desc'] = "file(s) that will be ignored, multiple separated by ','. Wildcards * and ? are ok";
|
|
|
111 |
$this->phpDocOptions['ignore']['type'] = "path";
|
|
|
112 |
|
|
|
113 |
$this->phpDocOptions['ignoresymlinks']['tag'] = array("-is", "--ignoresymlinks");
|
|
|
114 |
$this->phpDocOptions['ignoresymlinks']['desc'] = "ignore symlinks to other files or directories, default is off";
|
|
|
115 |
$this->phpDocOptions['ignoresymlinks']['type'] = "set";
|
|
|
116 |
$this->phpDocOptions['ignoresymlinks']['validvalues'] = $this->valid_booleans;
|
|
|
117 |
|
|
|
118 |
$this->phpDocOptions['ignoretags']['tag'] = array("-it", "--ignore-tags");
|
|
|
119 |
$this->phpDocOptions['ignoretags']['desc'] = "tags to ignore for this parse. @package, @subpackage, @access and @ignore may not be ignored.";
|
|
|
120 |
$this->phpDocOptions['ignoretags']['type'] = "value";
|
|
|
121 |
|
|
|
122 |
$this->phpDocOptions['hidden']['tag'] = array("-dh", "--hidden");
|
|
|
123 |
$this->phpDocOptions['hidden']['desc'] = "set equal to on (-dh on) to descend into hidden directories (directories starting with '.'), default is off";
|
|
|
124 |
$this->phpDocOptions['hidden']['type'] = "set";
|
|
|
125 |
$this->phpDocOptions['hidden']['validvalues'] = $this->valid_booleans;
|
|
|
126 |
|
|
|
127 |
$this->phpDocOptions['quiet']['tag'] = array("-q", "--quiet");
|
|
|
128 |
$this->phpDocOptions['quiet']['desc'] = "do not display parsing/conversion messages. Useful for cron jobs on/off default off";
|
|
|
129 |
$this->phpDocOptions['quiet']['type'] = "set";
|
|
|
130 |
$this->phpDocOptions['quiet']['validvalues'] = $this->valid_booleans;
|
|
|
131 |
|
|
|
132 |
$this->phpDocOptions['undocumentedelements']['tag'] = array("-ue", "--undocumentedelements");
|
|
|
133 |
$this->phpDocOptions['undocumentedelements']['desc'] = "Control whether or not warnings will be shown for undocumented elements. Useful for identifying classes and methods that haven't yet been documented on/off default off";
|
|
|
134 |
$this->phpDocOptions['undocumentedelements']['type'] = "set";
|
|
|
135 |
$this->phpDocOptions['undocumentedelements']['validvalues'] = $this->valid_booleans;
|
|
|
136 |
|
|
|
137 |
$this->phpDocOptions['title']['tag'] = array("-ti","--title");
|
|
|
138 |
$this->phpDocOptions['title']['desc'] = "title of generated documentation, default is 'Generated Documentation'";
|
|
|
139 |
$this->phpDocOptions['title']['type'] = "value";
|
|
|
140 |
|
|
|
141 |
$this->phpDocOptions['help']['tag'] = array("-h", "--help");
|
|
|
142 |
$this->phpDocOptions['help']['desc'] = " show this help message";
|
|
|
143 |
|
|
|
144 |
$this->phpDocOptions['useconfig']['tag'] = array("-c","--useconfig");
|
|
|
145 |
$this->phpDocOptions['useconfig']['desc'] = "Use a Config file in the users/ subdirectory for all command-line options";
|
|
|
146 |
$this->phpDocOptions['useconfig']['type'] = "value";
|
|
|
147 |
|
|
|
148 |
$this->phpDocOptions['parseprivate']['tag'] = array("-pp","--parseprivate");
|
|
|
149 |
$this->phpDocOptions['parseprivate']['desc'] = "parse @internal and elements marked private with @access. Use on/off, default off";
|
|
|
150 |
$this->phpDocOptions['parseprivate']['type'] = "set";
|
|
|
151 |
$this->phpDocOptions['parseprivate']['validvalues'] = array('on', 'off');
|
|
|
152 |
|
|
|
153 |
$this->phpDocOptions['packageoutput']['tag'] = array("-po","--packageoutput");
|
|
|
154 |
$this->phpDocOptions['packageoutput']['desc'] = "output documentation only for selected packages. Use a comma-delimited list";
|
|
|
155 |
$this->phpDocOptions['packageoutput']['type'] = "value";
|
|
|
156 |
|
|
|
157 |
$this->phpDocOptions['defaultpackagename']['tag'] = array("-dn","--defaultpackagename");
|
|
|
158 |
$this->phpDocOptions['defaultpackagename']['desc'] = "name to use for the default package. If not specified, uses 'default'";
|
|
|
159 |
$this->phpDocOptions['defaultpackagename']['type'] = "value";
|
|
|
160 |
|
|
|
161 |
$this->phpDocOptions['defaultcategoryname']['tag'] = array("-dc","--defaultcategoryname");
|
|
|
162 |
$this->phpDocOptions['defaultcategoryname']['desc'] = "name to use for the default category. If not specified, uses 'default'";
|
|
|
163 |
$this->phpDocOptions['defaultcategoryname']['type'] = "value";
|
|
|
164 |
|
|
|
165 |
$this->phpDocOptions['output']['tag'] = array("-o","--output");
|
|
|
166 |
$this->phpDocOptions['output']['desc'] = "output information to use separated by ','. Format: output:converter:templatedir like \"HTML:frames:phpedit\"";
|
|
|
167 |
$this->phpDocOptions['output']['type'] = "value";
|
|
|
168 |
|
|
|
169 |
$this->phpDocOptions['converterparams']['tag'] = array("-cp","--converterparams");
|
|
|
170 |
$this->phpDocOptions['converterparams']['desc'] = "dynamic parameters for a converter, separate values with commas";
|
|
|
171 |
$this->phpDocOptions['converterparams']['type'] = "value";
|
|
|
172 |
|
|
|
173 |
$this->phpDocOptions['customtags']['tag'] = array("-ct","--customtags");
|
|
|
174 |
$this->phpDocOptions['customtags']['desc'] = "custom tags, will be recognized and put in tags[] instead of unknowntags[]";
|
|
|
175 |
$this->phpDocOptions['customtags']['type'] = "value";
|
|
|
176 |
|
|
|
177 |
$this->phpDocOptions['sourcecode']['tag'] = array("-s","--sourcecode");
|
|
|
178 |
$this->phpDocOptions['sourcecode']['desc'] = "generate highlighted sourcecode for every parsed file (PHP 4.3.0+ only) on/off default off";
|
|
|
179 |
$this->phpDocOptions['sourcecode']['type'] = "set";
|
|
|
180 |
$this->phpDocOptions['sourcecode']['validvalues'] = array('on', 'off');
|
|
|
181 |
|
|
|
182 |
$this->phpDocOptions['javadocdesc']['tag'] = array("-j","--javadocdesc");
|
|
|
183 |
$this->phpDocOptions['javadocdesc']['desc'] = "JavaDoc-compliant description parsing. Use on/off, default off (more flexibility)";
|
|
|
184 |
$this->phpDocOptions['javadocdesc']['type'] = "set";
|
|
|
185 |
$this->phpDocOptions['javadocdesc']['validvalues'] = array('on', 'off');
|
|
|
186 |
|
|
|
187 |
$this->phpDocOptions['pear']['tag'] = array("-p","--pear");
|
|
|
188 |
$this->phpDocOptions['pear']['desc'] = "Parse a PEAR-style repository (package is directory, _members are @access private) on/off default off";
|
|
|
189 |
$this->phpDocOptions['pear']['type'] = "set";
|
|
|
190 |
$this->phpDocOptions['pear']['validvalues'] = array('on', 'off');
|
|
|
191 |
|
|
|
192 |
$this->phpDocOptions['readmeinstallchangelog']['tag'] = array("-ric","--readmeinstallchangelog");
|
|
|
193 |
$this->phpDocOptions['readmeinstallchangelog']['desc'] = "Specify custom filenames to parse like README, INSTALL or CHANGELOG files";
|
|
|
194 |
$this->phpDocOptions['readmeinstallchangelog']['type'] = "value";
|
|
|
195 |
|
|
|
196 |
$this->phpDocOptions['general']['message'] ="You can have multiple directories and multiple files, as well as a combination of both options";
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* create the help message for display on the command-line
|
|
|
202 |
* @return string a string containing a help message
|
|
|
203 |
*/
|
|
|
204 |
function displayHelpMsg()
|
|
|
205 |
{
|
|
|
206 |
unset($ret);
|
|
|
207 |
$ret = "\n";
|
|
|
208 |
foreach($this->phpDocOptions as $data)
|
|
|
209 |
{
|
|
|
210 |
unset($tag);
|
|
|
211 |
$tag = "";
|
|
|
212 |
if (isset($data['tag']))
|
|
|
213 |
{
|
|
|
214 |
if (is_array($data['tag'])) {
|
|
|
215 |
foreach($data['tag'] as $param) {
|
|
|
216 |
$tag .= "$param ";
|
|
|
217 |
}
|
|
|
218 |
}
|
|
|
219 |
$taglen = 34;
|
|
|
220 |
$outputwidth = 79;
|
|
|
221 |
$tagspace = str_repeat(" ",$taglen);
|
|
|
222 |
$tmp = " ".trim($tag).$tagspace;
|
|
|
223 |
$tmp = substr($tmp,0,$taglen);
|
|
|
224 |
$d = wordwrap(ltrim($data['desc']),($outputwidth-$taglen));
|
|
|
225 |
$dt = explode("\n",$d);
|
|
|
226 |
$dt[0] = $tmp .$dt[0];
|
|
|
227 |
for($i=1;$i<count($dt);$i++)
|
|
|
228 |
{
|
|
|
229 |
$dt[$i] = $tagspace.$dt[$i];
|
|
|
230 |
}
|
|
|
231 |
$ret .= implode("\n",$dt)."\n\n";
|
|
|
232 |
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
$ret .= "\n".wordwrap($data['message'],$outputwidth)."\n";
|
|
|
236 |
return $ret;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
/**
|
|
|
240 |
* calls {@link file_exists()} for each value in include_path,
|
|
|
241 |
* then calls {@link is_readable()} when it finds the file
|
|
|
242 |
* @param string
|
|
|
243 |
* @return boolean
|
|
|
244 |
*/
|
|
|
245 |
function isIncludeable($filename)
|
|
|
246 |
{
|
|
|
247 |
$test = realpath($filename);
|
|
|
248 |
if ($test && is_readable($test)) {
|
|
|
249 |
return true; // for absolute paths
|
|
|
250 |
}
|
|
|
251 |
$ip = get_include_path();
|
|
|
252 |
if (PHPDOCUMENTOR_WINDOWS)
|
|
|
253 |
{
|
|
|
254 |
$ip = explode(';', $ip);
|
|
|
255 |
} else {
|
|
|
256 |
$ip = explode(':', $ip);
|
|
|
257 |
}
|
|
|
258 |
foreach($ip as $path)
|
|
|
259 |
{
|
|
|
260 |
if ($a = realpath($path . DIRECTORY_SEPARATOR . $filename))
|
|
|
261 |
{
|
|
|
262 |
if (is_readable($a))
|
|
|
263 |
{
|
|
|
264 |
return true;
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
}
|
|
|
268 |
return false;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
/**
|
|
|
272 |
* Parses $_SERVER['argv'] and creates a setup array
|
|
|
273 |
* @return array a setup array
|
|
|
274 |
* @global array command-line arguments
|
|
|
275 |
* @todo replace with Console_* ?
|
|
|
276 |
*/
|
|
|
277 |
function parseArgv()
|
|
|
278 |
{
|
|
|
279 |
global $argv;
|
|
|
280 |
|
|
|
281 |
// defaults for setting
|
|
|
282 |
$setting['hidden'] = "off";
|
|
|
283 |
$setting['ignoresymlinks'] = 'off';
|
|
|
284 |
$setting['template'] = 'templates' . PATH_DELIMITER .'default' . PATH_DELIMITER;
|
|
|
285 |
|
|
|
286 |
$valnext = "junk";
|
|
|
287 |
$data = array();
|
|
|
288 |
if(isset($argv) && is_array($argv))
|
|
|
289 |
{
|
|
|
290 |
foreach ($argv as $cmd)
|
|
|
291 |
{
|
|
|
292 |
if ($cmd == '--') {
|
|
|
293 |
continue;
|
|
|
294 |
}
|
|
|
295 |
if ($cmd == '-h' || $cmd == '--help')
|
|
|
296 |
{
|
|
|
297 |
echo $this->displayHelpMsg();
|
|
|
298 |
die();
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
// at first, set the arg value as if we
|
|
|
302 |
// already know it's formatted normally, e.g.
|
|
|
303 |
// -q on
|
|
|
304 |
$setting[$valnext] = $cmd;
|
|
|
305 |
|
|
|
306 |
if (isset($data['type']) && $data['type'] == 'set') {
|
|
|
307 |
|
|
|
308 |
if ($valnext !== 'junk' && strpos(trim($cmd),'-') === 0) {
|
|
|
309 |
// if valnext isn't 'junk' (i.e it was an arg option)
|
|
|
310 |
// then the first arg needs an implicit "" as its value, e.g.
|
|
|
311 |
// ... -q -pp ... ===> ... -q '' -pp ...
|
|
|
312 |
$setting[$valnext] = '';
|
|
|
313 |
|
|
|
314 |
} else if (!in_array(strtolower($cmd), $data['validvalues'], true)) {
|
|
|
315 |
// the arg value is not a valid value
|
|
|
316 |
addErrorDie(PDERROR_INVALID_VALUES, $valnext, $cmd,
|
|
|
317 |
'(' . implode(', ', $data['validvalues']) . ')');
|
|
|
318 |
}
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
foreach( $this->phpDocOptions as $name => $data )
|
|
|
322 |
{
|
|
|
323 |
if (!empty($data['tag']))
|
|
|
324 |
{
|
|
|
325 |
if (in_array($cmd,$data['tag']))
|
|
|
326 |
{
|
|
|
327 |
$valnext = $name;
|
|
|
328 |
break;
|
|
|
329 |
}
|
|
|
330 |
else
|
|
|
331 |
{
|
|
|
332 |
$valnext = "junk";
|
|
|
333 |
}
|
|
|
334 |
}
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
if ($valnext == 'junk' && (strpos(trim($cmd),'-') === 0)) {
|
|
|
338 |
// this indicates the last arg of the command
|
|
|
339 |
// is an arg option (-) that was preceded by unrecognized "junk"
|
|
|
340 |
addErrorDie(PDERROR_UNKNOWN_COMMANDLINE,$cmd);
|
|
|
341 |
|
|
|
342 |
} else if ($valnext != 'junk' && (strpos(trim($cmd),'-') === 0)) {
|
|
|
343 |
// this indicates the last arg of the command
|
|
|
344 |
// is an arg option (-) without an arg value
|
|
|
345 |
|
|
|
346 |
// add an empty arg "value" for this arg "option"
|
|
|
347 |
$setting[$valnext] = '';
|
|
|
348 |
}
|
|
|
349 |
|
|
|
350 |
|
|
|
351 |
}
|
|
|
352 |
} else
|
|
|
353 |
{
|
|
|
354 |
echo "Please use php-cli.exe in windows, or set register_argc_argv On";
|
|
|
355 |
die;
|
|
|
356 |
}
|
|
|
357 |
/* $setting will always have at least 3 elements
|
|
|
358 |
[hidden] => off
|
|
|
359 |
[ignoresymlinks] => 'off'
|
|
|
360 |
[template] => templates/default
|
|
|
361 |
*/
|
|
|
362 |
if (count($setting) < 4) {
|
|
|
363 |
echo $this->displayhelpMsg();
|
|
|
364 |
die();
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
return $setting;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
/**
|
|
|
372 |
* @return array list of files in a directory
|
|
|
373 |
* @param string $directory full path to the directory you want the list of
|
|
|
374 |
* @param bool whether to list files that begin with . like .bash_history
|
|
|
375 |
* @param bool whether to ignore symlinks
|
|
|
376 |
*/
|
|
|
377 |
function dirList($orig_directory, $hidden = false, $ignore_symlinks = false)
|
|
|
378 |
{
|
|
|
379 |
$directory = realpath($orig_directory);
|
|
|
380 |
$ret = false;
|
|
|
381 |
if (! @is_dir($directory))
|
|
|
382 |
{
|
|
|
383 |
die("directory: '$directory' not found\n");
|
|
|
384 |
}
|
|
|
385 |
$ret = array();
|
|
|
386 |
$d = @dir($directory); // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix
|
|
|
387 |
while($d && ($entry=$d->read()) !== false) {
|
|
|
388 |
if (strcmp($entry,".") == 0 || strcmp($entry,"..") == 0) {
|
|
|
389 |
continue;
|
|
|
390 |
}
|
|
|
391 |
|
|
|
392 |
// skip hidden files, if we're supposed to
|
|
|
393 |
if (!$hidden)
|
|
|
394 |
{
|
|
|
395 |
if (substr($entry,0,1) == ".")
|
|
|
396 |
{
|
|
|
397 |
phpDocumentor_out("Hidden " . $directory . PATH_DELIMITER . $entry . " Ignored\n");
|
|
|
398 |
continue;
|
|
|
399 |
}
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
// skip symlink files, if we're supposed to
|
|
|
403 |
if ($ignore_symlinks)
|
|
|
404 |
{
|
|
|
405 |
if (is_link($directory . PATH_DELIMITER . $entry))
|
|
|
406 |
{
|
|
|
407 |
phpDocumentor_out("Symlink " . $directory . PATH_DELIMITER . $entry . " Ignored\n");
|
|
|
408 |
continue;
|
|
|
409 |
}
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
if (is_file($directory . PATH_DELIMITER . $entry)) {
|
|
|
413 |
$ret[] = $directory . PATH_DELIMITER . $entry;
|
|
|
414 |
}
|
|
|
415 |
if (is_dir($directory . PATH_DELIMITER . $entry)) {
|
|
|
416 |
$tmp = $this->dirList($directory . PATH_DELIMITER . $entry, $hidden, $ignore_symlinks);
|
|
|
417 |
if (is_array($tmp)) {
|
|
|
418 |
foreach($tmp as $ent) {
|
|
|
419 |
$ret[] = $ent;
|
|
|
420 |
}
|
|
|
421 |
}
|
|
|
422 |
}
|
|
|
423 |
}
|
|
|
424 |
if ($d) $d->close();
|
|
|
425 |
return $ret;
|
|
|
426 |
}
|
|
|
427 |
|
|
|
428 |
/**
|
|
|
429 |
* Retrieve common directory (case-insensitive in windows)
|
|
|
430 |
*
|
|
|
431 |
* takes the list of files, and returns the subdirectory they share in common,
|
|
|
432 |
* so in this list:
|
|
|
433 |
*
|
|
|
434 |
* <code>
|
|
|
435 |
* array(
|
|
|
436 |
* "/dir1/dir2/subdir/dir3/filename.ext",
|
|
|
437 |
* "/dir1/dir2/subdir/dir4/filename.ext",
|
|
|
438 |
* "/dir1/dir2/mydir/dir5/filename.ext");
|
|
|
439 |
* </code>
|
|
|
440 |
*
|
|
|
441 |
* getBase will return "/dir1/dir2"
|
|
|
442 |
* @param array array of strings
|
|
|
443 |
*/
|
|
|
444 |
function getBase($filelist)
|
|
|
445 |
{
|
|
|
446 |
$masterPath = false;
|
|
|
447 |
foreach($filelist as $path)
|
|
|
448 |
{
|
|
|
449 |
if (!$masterPath)
|
|
|
450 |
{
|
|
|
451 |
$masterPath = str_replace('\\','/',dirname($path));
|
|
|
452 |
} else
|
|
|
453 |
{
|
|
|
454 |
if (dirname($path) != $masterPath)
|
|
|
455 |
{
|
|
|
456 |
$mp = explode(PATH_DELIMITER, $masterPath);
|
|
|
457 |
$np = explode(PATH_DELIMITER, str_replace('\\', '/', dirname($path)));
|
|
|
458 |
if (count($np) < count($mp))
|
|
|
459 |
{
|
|
|
460 |
$masterPath = join($np, PATH_DELIMITER);
|
|
|
461 |
} else
|
|
|
462 |
{
|
|
|
463 |
$test = false;
|
|
|
464 |
$found = false;
|
|
|
465 |
for($i=0;$i < count($mp) && $i < count($np);$i++)
|
|
|
466 |
{
|
|
|
467 |
if (PHPDOCUMENTOR_WINDOWS)
|
|
|
468 |
{
|
|
|
469 |
if (strtolower($mp[$i]) != strtolower($np[$i])) $found = $i;
|
|
|
470 |
} else
|
|
|
471 |
{
|
|
|
472 |
if ($mp[$i] != $np[$i]) $found = $i;
|
|
|
473 |
}
|
|
|
474 |
}
|
|
|
475 |
if ($found !== false)
|
|
|
476 |
{
|
|
|
477 |
$mp = array_slice($mp,0,$found);
|
|
|
478 |
$masterPath = join($mp,PATH_DELIMITER);
|
|
|
479 |
}
|
|
|
480 |
}
|
|
|
481 |
}
|
|
|
482 |
}
|
|
|
483 |
}
|
|
|
484 |
return $masterPath;
|
|
|
485 |
}
|
|
|
486 |
|
|
|
487 |
/**
|
|
|
488 |
* Retrieve tutorial subdirectories and their contents from the list of
|
|
|
489 |
* files to parse
|
|
|
490 |
* @param array array of paths (strings)
|
|
|
491 |
* @return array array(filelist - tutorials, tutorials)
|
|
|
492 |
*/
|
|
|
493 |
function getTutorials($filelist)
|
|
|
494 |
{
|
|
|
495 |
$list = $tutorials = array();
|
|
|
496 |
foreach($filelist as $file)
|
|
|
497 |
{
|
|
|
498 |
if (strpos($file,'tutorials/') !== false)
|
|
|
499 |
{
|
|
|
500 |
$tutedir = explode('/',substr($file,strpos($file,'tutorials/')));
|
|
|
501 |
array_shift($tutedir);
|
|
|
502 |
if (count($tutedir) <= 3)
|
|
|
503 |
{
|
|
|
504 |
$res = array();
|
|
|
505 |
// kludge - will need to fix for 2.0
|
|
|
506 |
$res['category'] = $GLOBALS['phpDocumentor_DefaultCategoryName'];
|
|
|
507 |
$res['package'] = array_shift($tutedir);
|
|
|
508 |
$res['subpackage'] = '';
|
|
|
509 |
if (count($tutedir) > 1)
|
|
|
510 |
$res['subpackage'] = array_shift($tutedir);
|
|
|
511 |
$f = array_shift($tutedir);
|
|
|
512 |
$res['tutename'] = $f;
|
|
|
513 |
$f = explode('.',$f);
|
|
|
514 |
$res['tutetype'] = array_pop($f);
|
|
|
515 |
if ($res['tutetype'] == 'ini') continue;
|
|
|
516 |
$res['path'] = $file;
|
|
|
517 |
if (@file_exists($file . '.ini'))
|
|
|
518 |
{
|
|
|
519 |
$res['ini'] = phpDocumentor_parse_ini_file($file . '.ini', true);
|
|
|
520 |
} else
|
|
|
521 |
{
|
|
|
522 |
$res['ini'] = false;
|
|
|
523 |
}
|
|
|
524 |
$tutorials[] = $res;
|
|
|
525 |
}
|
|
|
526 |
} else $list[] = $file;
|
|
|
527 |
}
|
|
|
528 |
return array($list,$tutorials);
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
/**
|
|
|
532 |
* @param string base directory from {@link getBase()}
|
|
|
533 |
* @param array file list from {@link dirList()}
|
|
|
534 |
* @return array array(filelist - README/INSTALL/CHANGELOG,
|
|
|
535 |
* README/INSTALL/CHANGELOG)
|
|
|
536 |
*/
|
|
|
537 |
function getReadmeInstallChangelog($base,$filelist)
|
|
|
538 |
{
|
|
|
539 |
$list = $ric = array();
|
|
|
540 |
$names = $GLOBALS['_phpDocumentor_RIC_files'];
|
|
|
541 |
foreach($filelist as $file)
|
|
|
542 |
{
|
|
|
543 |
if ((dirname($file) == $base) && in_array(strtoupper(basename($file)), $names))
|
|
|
544 |
{ // be sure to change $this->checkIgnore() if any other files are added here!!
|
|
|
545 |
$ric[] = $file;
|
|
|
546 |
} else
|
|
|
547 |
{
|
|
|
548 |
$list[] = $file;
|
|
|
549 |
}
|
|
|
550 |
}
|
|
|
551 |
return array($list,$ric);
|
|
|
552 |
}
|
|
|
553 |
|
|
|
554 |
/**
|
|
|
555 |
* @param string directory
|
|
|
556 |
* @param string base directory
|
|
|
557 |
* @param array array of ignored items
|
|
|
558 |
* @param boolean the "hidden" flag
|
|
|
559 |
* @param boolean the "ignoresymlinks" flag
|
|
|
560 |
* @uses dirList
|
|
|
561 |
* @uses checkIgnore
|
|
|
562 |
* @uses setup_dirs
|
|
|
563 |
*/
|
|
|
564 |
function getDirTree($dir, $base_dir, $ignore = array(), $hidden = false, $ignoresymlinks = false)
|
|
|
565 |
{
|
|
|
566 |
$allfiles = $this->dirList($dir,$hidden,$ignoresymlinks);
|
|
|
567 |
$struc = array();
|
|
|
568 |
foreach($allfiles as $file)
|
|
|
569 |
{
|
|
|
570 |
if ($this->checkIgnore(basename($file),dirname(realpath($file)),$ignore,$ignoresymlinks)) continue;
|
|
|
571 |
if (PHPDOCUMENTOR_WINDOWS) {
|
|
|
572 |
$path = substr(dirname($file),strlen(str_replace('\\','/',realpath($base_dir))));
|
|
|
573 |
} else {
|
|
|
574 |
$path = substr(dirname($file),strlen(str_replace('\\','/',realpath($base_dir)))+1);
|
|
|
575 |
}
|
|
|
576 |
if (!$path) $path = '/';
|
|
|
577 |
$parts = pathinfo($file);
|
|
|
578 |
if (!isset($parts['extension']))
|
|
|
579 |
{
|
|
|
580 |
$parts['extension'] = '';
|
|
|
581 |
}
|
|
|
582 |
$struc[$path][] = array(
|
|
|
583 |
'file' => $parts['basename'],
|
|
|
584 |
'ext' => $parts['extension'],
|
|
|
585 |
'path' => $file);
|
|
|
586 |
}
|
|
|
587 |
uksort($struc,'strnatcasecmp');
|
|
|
588 |
foreach($struc as $key => $ind)
|
|
|
589 |
{
|
|
|
590 |
usort($ind,'Ioinc_sortfiles');
|
|
|
591 |
$struc[$key] = $ind;
|
|
|
592 |
$save = $key;
|
|
|
593 |
if ($key != '/')
|
|
|
594 |
{
|
|
|
595 |
$key = explode('/',$key);
|
|
|
596 |
while (count($key))
|
|
|
597 |
{
|
|
|
598 |
array_pop($key);
|
|
|
599 |
if (isset($struc[join('/',$key)]))
|
|
|
600 |
{
|
|
|
601 |
$struc[join('/',$key)][substr($save,strlen(join('/',$key)) + 1)] = $ind;
|
|
|
602 |
unset($struc[$save]);
|
|
|
603 |
}
|
|
|
604 |
}
|
|
|
605 |
}
|
|
|
606 |
}
|
|
|
607 |
foreach($struc as $key => $ind)
|
|
|
608 |
{
|
|
|
609 |
if ($key != '/')
|
|
|
610 |
{
|
|
|
611 |
if (count(explode('/',$key)) == 1)
|
|
|
612 |
{
|
|
|
613 |
$struc['/'][$key] = $struc[$key];
|
|
|
614 |
unset($struc[$key]);
|
|
|
615 |
}
|
|
|
616 |
}
|
|
|
617 |
}
|
|
|
618 |
$tempstruc = $struc;
|
|
|
619 |
unset($tempstruc['/']);
|
|
|
620 |
$leftover_dirs = array_keys($tempstruc);
|
|
|
621 |
$splitdirs = array();
|
|
|
622 |
foreach($leftover_dirs as $dir)
|
|
|
623 |
{
|
|
|
624 |
$splitdirs[] = explode('/',$dir);
|
|
|
625 |
}
|
|
|
626 |
$leftover_dirs = array();
|
|
|
627 |
|
|
|
628 |
foreach($splitdirs as $dir)
|
|
|
629 |
{
|
|
|
630 |
$save = join($dir,'/');
|
|
|
631 |
$struc['/'] = setup_dirs($struc['/'], $dir, $tempstruc[$save]);
|
|
|
632 |
unset($struc[$save]);
|
|
|
633 |
}
|
|
|
634 |
@uksort($struc['/'],'Ioinc_mystrucsort');
|
|
|
635 |
return $struc;
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
/**
|
|
|
639 |
* Reads a file and returns it as a string
|
|
|
640 |
* Does basic error checking
|
|
|
641 |
*
|
|
|
642 |
* file extensions are set in {@link phpdoc.inc}
|
|
|
643 |
*
|
|
|
644 |
* @global array PHP File extensions, used to validate that $path is a PHP File
|
|
|
645 |
* @global array PHP File extensions in a CVS repository, used to validate that $path is a PHP File
|
|
|
646 |
* @param string $path
|
|
|
647 |
*/
|
|
|
648 |
function readPhpFile($path, $quietMode = false)
|
|
|
649 |
{
|
|
|
650 |
global $_phpDocumentor_cvsphpfile_exts, $_phpDocumentor_phpfile_exts;
|
|
|
651 |
// tiberiusblue addition
|
|
|
652 |
$cvsExt = $_phpDocumentor_cvsphpfile_exts;
|
|
|
653 |
$ext = $_phpDocumentor_phpfile_exts;
|
|
|
654 |
if (file_exists($path))
|
|
|
655 |
{
|
|
|
656 |
if (is_file($path))
|
|
|
657 |
{
|
|
|
658 |
// check extension
|
|
|
659 |
$tmp = explode(".",$path);
|
|
|
660 |
// tiberiusblue addition
|
|
|
661 |
$tmp2 = $tmp;
|
|
|
662 |
if (in_array(array_pop($tmp),$ext))
|
|
|
663 |
{
|
|
|
664 |
phpDocumentor_out(" -- Parsing file\n");
|
|
|
665 |
flush();
|
|
|
666 |
if (function_exists('file_get_contents')) {
|
|
|
667 |
return file_get_contents($path);
|
|
|
668 |
}
|
|
|
669 |
$fp = fopen($path,"r");
|
|
|
670 |
$ret = fread($fp,filesize($path));
|
|
|
671 |
fclose($fp);
|
|
|
672 |
return $ret;
|
|
|
673 |
} elseif (in_array(array_pop($tmp2),$cvsExt))
|
|
|
674 |
{
|
|
|
675 |
phpDocumentor_out(" CVS file [EXPERIMENTAL]\n");
|
|
|
676 |
flush();
|
|
|
677 |
if (function_exists('file_get_contents')) {
|
|
|
678 |
$ret = file_get_contents($path);
|
|
|
679 |
} else {
|
|
|
680 |
$fp = fopen($path,"r");
|
|
|
681 |
$ret = fread($fp,filesize($path));
|
|
|
682 |
fclose($fp);
|
|
|
683 |
}
|
|
|
684 |
$ret = strstr($ret,"<?");
|
|
|
685 |
$ret = substr($ret,0,strpos($ret,"@\n"));
|
|
|
686 |
$ret = str_replace("@@","@",$ret);
|
|
|
687 |
return $ret;
|
|
|
688 |
} else
|
|
|
689 |
{
|
|
|
690 |
phpDocumentor_out(" -- File not parsed, not a php file\n");
|
|
|
691 |
flush();
|
|
|
692 |
}
|
|
|
693 |
} else {
|
|
|
694 |
phpDocumentor_out(" -- Unable to read file, not a file\n");
|
|
|
695 |
flush();
|
|
|
696 |
}
|
|
|
697 |
} else {
|
|
|
698 |
phpDocumentor_out(" -- Unable to read file, file does not exist\n");
|
|
|
699 |
flush();
|
|
|
700 |
}
|
|
|
701 |
}
|
|
|
702 |
|
|
|
703 |
/**
|
|
|
704 |
* Tell whether to ignore a file or a directory
|
|
|
705 |
* allows * and ? wildcards
|
|
|
706 |
*
|
|
|
707 |
* @author Greg Beaver <cellog@php.net>
|
|
|
708 |
* @param string $file just the file name of the file or directory,
|
|
|
709 |
* in the case of directories this is the last dir
|
|
|
710 |
* @param string $path the path to consider (should be checked by
|
|
|
711 |
* realpath() before, and may be relative)
|
|
|
712 |
* @param array $ignore
|
|
|
713 |
* @param bool
|
|
|
714 |
* @param bool Ignore symlinks?
|
|
|
715 |
* @return bool true if $path should be ignored, false if it should not
|
|
|
716 |
*/
|
|
|
717 |
function checkIgnore($file,$path,$ignore,$ignore_no_ext = true,$ignoresymlinks = false)
|
|
|
718 |
{
|
|
|
719 |
global $_phpDocumentor_RIC_files;
|
|
|
720 |
|
|
|
721 |
if ($ignoresymlinks && is_link($path . PATH_DELIMITER . $file)) return false;
|
|
|
722 |
|
|
|
723 |
if (!count($ignore)) return false;
|
|
|
724 |
|
|
|
725 |
if (!isset($this->ignore))
|
|
|
726 |
{
|
|
|
727 |
$this->_setupIgnore($ignore);
|
|
|
728 |
}
|
|
|
729 |
if (!$this->ignore)
|
|
|
730 |
{
|
|
|
731 |
return false;
|
|
|
732 |
}
|
|
|
733 |
|
|
|
734 |
if ($ignore_no_ext &&
|
|
|
735 |
!in_array(strtoupper($file), $_phpDocumentor_RIC_files))
|
|
|
736 |
{
|
|
|
737 |
if (!is_numeric(strpos($file,'.'))) return true;
|
|
|
738 |
}
|
|
|
739 |
if (is_array($this->ignore))
|
|
|
740 |
{
|
|
|
741 |
foreach($this->ignore as $match)
|
|
|
742 |
{
|
|
|
743 |
// match is an array if the ignore parameter was a /path/to/pattern
|
|
|
744 |
if (is_array($match))
|
|
|
745 |
{
|
|
|
746 |
// check to see if the path matches with a path delimiter appended
|
|
|
747 |
preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path) . PATH_DELIMITER,$find);
|
|
|
748 |
if (!count($find))
|
|
|
749 |
{
|
|
|
750 |
// check to see if it matches without an appended path delimiter
|
|
|
751 |
preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path), $find);
|
|
|
752 |
}
|
|
|
753 |
if (count($find))
|
|
|
754 |
{
|
|
|
755 |
// check to see if the file matches the file portion of the regex string
|
|
|
756 |
preg_match('/^' . strtoupper($match[1]).'$/', strtoupper($file), $find);
|
|
|
757 |
if (count($find))
|
|
|
758 |
{
|
|
|
759 |
return true;
|
|
|
760 |
}
|
|
|
761 |
}
|
|
|
762 |
// check to see if the full path matches the regex
|
|
|
763 |
preg_match('/^' . strtoupper($match[0]).'$/',
|
|
|
764 |
strtoupper($path . DIRECTORY_SEPARATOR . $file), $find);
|
|
|
765 |
if (count($find))
|
|
|
766 |
{
|
|
|
767 |
return true;
|
|
|
768 |
}
|
|
|
769 |
} else
|
|
|
770 |
{
|
|
|
771 |
// ignore parameter was just a pattern with no path delimiters
|
|
|
772 |
// check it against the path
|
|
|
773 |
preg_match('/^' . strtoupper($match).'$/', strtoupper($path), $find);
|
|
|
774 |
if (count($find))
|
|
|
775 |
{
|
|
|
776 |
return true;
|
|
|
777 |
}
|
|
|
778 |
// check it against the file only
|
|
|
779 |
preg_match('/^' . strtoupper($match).'$/', strtoupper($file), $find);
|
|
|
780 |
if (count($find))
|
|
|
781 |
{
|
|
|
782 |
return true;
|
|
|
783 |
}
|
|
|
784 |
}
|
|
|
785 |
}
|
|
|
786 |
}
|
|
|
787 |
return false;
|
|
|
788 |
}
|
|
|
789 |
|
|
|
790 |
/**
|
|
|
791 |
* Construct the {@link $ignore} array
|
|
|
792 |
* @author Greg Beaver <cellog@php.net>
|
|
|
793 |
* @param array strings of files/paths/wildcards to ignore
|
|
|
794 |
* @access protected
|
|
|
795 |
*/
|
|
|
796 |
function _setupIgnore($ignore)
|
|
|
797 |
{
|
|
|
798 |
$ig = array();
|
|
|
799 |
if ( ! is_array($ignore))
|
|
|
800 |
{
|
|
|
801 |
$this->ignore = false;
|
|
|
802 |
return;
|
|
|
803 |
}
|
|
|
804 |
for($i=0; $i<count($ignore);$i++)
|
|
|
805 |
{
|
|
|
806 |
if (empty($ignore[$i]))
|
|
|
807 |
continue;
|
|
|
808 |
|
|
|
809 |
$ignore[$i] = strtr($ignore[$i], '\\', '/');
|
|
|
810 |
$ignore[$i] = str_replace('//','/',$ignore[$i]);
|
|
|
811 |
|
|
|
812 |
if (!is_numeric(strpos($ignore[$i],PATH_DELIMITER)))
|
|
|
813 |
{
|
|
|
814 |
$ig[] = $this->getRegExpableSearchString($ignore[$i]);
|
|
|
815 |
} else
|
|
|
816 |
{
|
|
|
817 |
if (basename($ignore[$i]) . PATH_DELIMITER == $ignore[$i])
|
|
|
818 |
$ig[] = $this->getRegExpableSearchString($ignore[$i]);
|
|
|
819 |
else
|
|
|
820 |
$ig[] = array($this->getRegExpableSearchString($ignore[$i]),$this->getRegExpableSearchString(basename($ignore[$i])));
|
|
|
821 |
}
|
|
|
822 |
}
|
|
|
823 |
if (count($ig)) $this->ignore = $ig;
|
|
|
824 |
}
|
|
|
825 |
|
|
|
826 |
/**
|
|
|
827 |
* Converts $s into a string that can be used with preg_match
|
|
|
828 |
* @param string $s string with wildcards ? and *
|
|
|
829 |
* @author Greg Beaver <cellog@php.net>
|
|
|
830 |
* @return string converts * to .*, ? to ., etc.
|
|
|
831 |
*/
|
|
|
832 |
function getRegExpableSearchString($s)
|
|
|
833 |
{
|
|
|
834 |
$y = '\/';
|
|
|
835 |
if (DIRECTORY_SEPARATOR == '\\')
|
|
|
836 |
{
|
|
|
837 |
$y = '\\\\';
|
|
|
838 |
}
|
|
|
839 |
$s = str_replace('/', DIRECTORY_SEPARATOR, $s);
|
|
|
840 |
$x = strtr($s, array('?' => '.','*' => '.*','.' => '\\.','\\' => '\\\\','/' => '\\/',
|
|
|
841 |
'[' => '\\[',']' => '\\]','-' => '\\-'));
|
|
|
842 |
if (strpos($s, DIRECTORY_SEPARATOR) !== false &&
|
|
|
843 |
strrpos($s, DIRECTORY_SEPARATOR) === strlen($s) - 1)
|
|
|
844 |
{
|
|
|
845 |
$x = "(?:.*$y$x?.*|$x.*)";
|
|
|
846 |
}
|
|
|
847 |
return $x;
|
|
|
848 |
}
|
|
|
849 |
|
|
|
850 |
/**
|
|
|
851 |
* Removes files from the $dir array that do not match the search string in
|
|
|
852 |
* $match
|
|
|
853 |
* @param array $dir array of filenames (full path)
|
|
|
854 |
* @param string $match search string with wildcards
|
|
|
855 |
* @author Greg Beaver <cellog@php.net>
|
|
|
856 |
* @return string|array listing of every file in a directory that matches
|
|
|
857 |
* the search string
|
|
|
858 |
*/
|
|
|
859 |
function removeNonMatches($dir, $match)
|
|
|
860 |
{
|
|
|
861 |
$match = $this->getRegExpableSearchString($match);
|
|
|
862 |
$nodir = false;
|
|
|
863 |
if (!is_array($dir))
|
|
|
864 |
{
|
|
|
865 |
$dir = array($dir);
|
|
|
866 |
$nodir = true;
|
|
|
867 |
}
|
|
|
868 |
foreach($dir as $i => $file)
|
|
|
869 |
{
|
|
|
870 |
preg_match('/^'.$match.'$/',basename($file),$find);
|
|
|
871 |
if (!count($find)) unset($dir[$i]);
|
|
|
872 |
}
|
|
|
873 |
if ($nodir) return $dir[0];
|
|
|
874 |
return $dir;
|
|
|
875 |
}
|
|
|
876 |
|
|
|
877 |
/**
|
|
|
878 |
* Take a filename with wildcards and return all files that match the
|
|
|
879 |
* wildcards
|
|
|
880 |
* @param string $file a full path from the -f command-line parameter, with
|
|
|
881 |
* potential * and ? wildcards.
|
|
|
882 |
* @return mixed if $file contains wildcards, returns an array of matching
|
|
|
883 |
* files, otherwise returns false
|
|
|
884 |
* @author Greg Beaver <cellog@php.net>
|
|
|
885 |
* @uses dirList
|
|
|
886 |
* @uses removeNonMatches
|
|
|
887 |
*/
|
|
|
888 |
function getAllFiles($file)
|
|
|
889 |
{
|
|
|
890 |
$path = realpath(dirname($file));
|
|
|
891 |
$file = basename($file);
|
|
|
892 |
// any wildcards?
|
|
|
893 |
if (is_numeric(strpos($file,'?')) || is_numeric(strpos($file,'*')))
|
|
|
894 |
{
|
|
|
895 |
$files = $this->dirList($path);
|
|
|
896 |
$a = $this->removeNonMatches($files,$file);
|
|
|
897 |
return $a;
|
|
|
898 |
}
|
|
|
899 |
return false;
|
|
|
900 |
}
|
|
|
901 |
}
|
|
|
902 |
|
|
|
903 |
/**#@+
|
|
|
904 |
* Sorting functions for the file list
|
|
|
905 |
* @param string
|
|
|
906 |
* @param string
|
|
|
907 |
*/
|
|
|
908 |
function Ioinc_sortfiles($a, $b)
|
|
|
909 |
{
|
|
|
910 |
return strnatcasecmp($a['file'],$b['file']);
|
|
|
911 |
}
|
|
|
912 |
|
|
|
913 |
function Ioinc_mystrucsort($a, $b)
|
|
|
914 |
{
|
|
|
915 |
if (is_numeric($a) && is_string($b)) return 1;
|
|
|
916 |
if (is_numeric($b) && is_string($a)) return -1;
|
|
|
917 |
if (is_numeric($a) && is_numeric($b))
|
|
|
918 |
{
|
|
|
919 |
if ($a > $b) return 1;
|
|
|
920 |
if ($a < $b) return -1;
|
|
|
921 |
if ($a == $b) return 0;
|
|
|
922 |
}
|
|
|
923 |
return strnatcasecmp($a,$b);
|
|
|
924 |
}
|
|
|
925 |
/**#@-*/
|
|
|
926 |
|
|
|
927 |
/**
|
|
|
928 |
* Recursively add all the subdirectories of $contents to $dir without erasing anything in
|
|
|
929 |
* $dir
|
|
|
930 |
* @param array
|
|
|
931 |
* @param array
|
|
|
932 |
* @return array processed $dir
|
|
|
933 |
*/
|
|
|
934 |
function set_dir($dir,$contents)
|
|
|
935 |
{
|
|
|
936 |
while(list($one,$two) = each($contents))
|
|
|
937 |
{
|
|
|
938 |
if (isset($dir[$one]))
|
|
|
939 |
{
|
|
|
940 |
$dir[$one] = set_dir($dir[$one],$contents[$one]);
|
|
|
941 |
} else $dir[$one] = $two;
|
|
|
942 |
}
|
|
|
943 |
return $dir;
|
|
|
944 |
}
|
|
|
945 |
|
|
|
946 |
/**
|
|
|
947 |
* Recursively move contents of $struc into associative array
|
|
|
948 |
*
|
|
|
949 |
* The contents of $struc have many indexes like 'dir/subdir/subdir2'.
|
|
|
950 |
* This function converts them to
|
|
|
951 |
* array('dir' => array('subdir' => array('subdir2')))
|
|
|
952 |
* @param array struc is array('dir' => array of files in dir,'dir/subdir' => array of files in dir/subdir,...)
|
|
|
953 |
* @param array array form of 'dir/subdir/subdir2' array('dir','subdir','subdir2')
|
|
|
954 |
* @return array same as struc but with array('dir' => array(file1,file2,'subdir' => array(file1,...)))
|
|
|
955 |
*/
|
|
|
956 |
function setup_dirs($struc,$dir,$contents)
|
|
|
957 |
{
|
|
|
958 |
if (!count($dir))
|
|
|
959 |
{
|
|
|
960 |
foreach($contents as $dir => $files)
|
|
|
961 |
{
|
|
|
962 |
if (is_string($dir))
|
|
|
963 |
{
|
|
|
964 |
if (strpos($dir,'/'))
|
|
|
965 |
{
|
|
|
966 |
$test = true;
|
|
|
967 |
$a = $contents[$dir];
|
|
|
968 |
unset($contents[$dir]);
|
|
|
969 |
$b = explode('/',$dir);
|
|
|
970 |
$c = array_shift($b);
|
|
|
971 |
if (isset($contents[$c]))
|
|
|
972 |
{
|
|
|
973 |
$contents[$c] = set_dir($contents[$c],setup_dirs(array(),$b,$a));
|
|
|
974 |
} else $contents[$c] = setup_dirs(array(),$b,$a);
|
|
|
975 |
}
|
|
|
976 |
}
|
|
|
977 |
}
|
|
|
978 |
return $contents;
|
|
|
979 |
}
|
|
|
980 |
$me = array_shift($dir);
|
|
|
981 |
if (!isset($struc[$me])) $struc[$me] = array();
|
|
|
982 |
$struc[$me] = setup_dirs($struc[$me],$dir,$contents);
|
|
|
983 |
return $struc;
|
|
|
984 |
}
|
|
|
985 |
|
|
|
986 |
if (!function_exists('get_include_path')) {
|
|
|
987 |
function get_include_path()
|
|
|
988 |
{
|
|
|
989 |
return ini_get('include_path');
|
|
|
990 |
}
|
|
|
991 |
}
|
|
|
992 |
?>
|