forked from php/doc-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-skel.php
More file actions
executable file
·113 lines (86 loc) · 3.05 KB
/
script-skel.php
File metadata and controls
executable file
·113 lines (86 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/*
+----------------------------------------------------------------------+
| Copyright (c) 1997-2023 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net, so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Etienne Kneuss <colder@php.net> |
+----------------------------------------------------------------------+
*/
if (PHP_SAPI !== 'cli') {
echo "This script is ment to be run under CLI\n";
exit(1);
}
if ($_SERVER['argc'] == 2 &&
in_array($_SERVER['argv'][1], array('--help', '-help', '-h', '-?'))
||
$_SERVER['argc'] < 2) {
echo "<Description>\n\n";
echo "Usage: {$_SERVER['argv'][0]} <path>\n";
echo " --help, -help, -h, -? - to get this help\n";
die;
}
// Ensure the trailing /
$fullpath_dir = rtrim($_SERVER['argv'][1], '/').'/';
if (!is_dir($fullpath_dir)) {
echo "ERROR: ($fullpath_dir) is not a directory.\n";
exit(1);
}
$log = array('nonfiles' => array(),
'error' => array(),
'rewritten' => array());
// Start the processing
list_files($fullpath_dir, '', $log);
echo count($log['rewritten'])." file(s) have been affected.\n";
if (!empty($log['error'])) {
echo count($log['error'])." error(s) occured:\n";
foreach($log['error'] as $error) {
echo " $error\n";
}
}
/**
* List files recursivly and scan them
*
* @return bool
*/
function list_files($prefix, $path, &$userdata)
{
if (is_dir($prefix.$path) && is_resource($handle = @opendir($prefix.$path))) {
while ($name = readdir($handle)) {
if (strpos($name, ".xml") !== false) {
scan_file($prefix, $path.$name, $userdata);
} else if(is_dir($prefix.$path.$name) && $name !== 'CVS' && $name !== '.' && $name !== '..') {
list_files($prefix, $path.$name.DIRECTORY_SEPARATOR, $userdata);
}
}
closedir($handle);
return true;
} else {
return false;
}
}
/**
* Scan files for examples, and insert them
*
* @return null
*/
function scan_file($prefix, $path, &$userdata)
{
if (!is_file($prefix.$path)) {
$userdata['nonfiles'][] = $path;
return false;
}
$content = file_get_contents($prefix.$path);
echo "scanning $path\n";
if ($number = preg_match_all('/regex/', $content, $matches)) {
// Process
$userdata['rewritten'][] = $path;
}
}