4 chdir(dirname(__FILE__
));
5 require_once 'common.php';
6 require_once '../tests/path2class.func.php';
7 require_once '../library/HTMLPurifier/Bootstrap.php';
12 * Generates an include stub for users who do not want to use the autoloader.
13 * When new files are added to HTML Purifier's main codebase, this file should
17 chdir(dirname(__FILE__
) . '/../library/');
20 $exclude_dirs = array(
21 'HTMLPurifier/Language/',
22 'HTMLPurifier/ConfigSchema/',
23 'HTMLPurifier/Filter/',
24 'HTMLPurifier/Printer/',
25 /* These should be excluded, but need to have ConfigSchema support first
29 $exclude_files = array(
30 'HTMLPurifier/Lexer/PEARSax3.php',
31 'HTMLPurifier/Lexer/PH5P.php',
32 'HTMLPurifier/Printer.php',
35 // Determine what files need to be included:
36 echo 'Scanning for files... ';
37 $raw_files = $FS->globr('.', '*.php');
38 if (!$raw_files) throw new Exception('Did not find any PHP source files');
40 foreach ($raw_files as $file) {
41 $file = substr($file, 2); // rm leading './'
42 if (strncmp('standalone/', $file, 11) === 0) continue; // rm generated files
43 if (substr_count($file, '.') > 1) continue; // rm meta files
45 foreach ($exclude_dirs as $dir) {
46 if (strncmp($dir, $file, strlen($dir)) === 0) {
51 if (!$ok) continue; // rm excluded directories
52 if (in_array($file, $exclude_files)) continue; // rm excluded files
57 // Reorder list so that dependencies are included first:
60 * Returns a lookup array of dependencies for a file.
62 * @note This function expects that format $name extends $parent on one line
65 * File to check dependencies of.
67 * Lookup array of files the file is dependent on, sorted accordingly.
69 function get_dependency_lookup($file)
71 static $cache = array();
72 if (isset($cache[$file])) return $cache[$file];
73 if (!file_exists($file)) {
74 echo "File doesn't exist: $file\n";
77 $fh = fopen($file, 'r');
81 if (strncmp('class', $line, 5) === 0) {
82 // The implementation here is fragile and will break if we attempt
83 // to use interfaces. Beware!
84 $arr = explode(' extends ', trim($line, ' {'."\n\r"), 2);
85 if (count($arr) < 2) break;
87 $dep_file = HTMLPurifier_Bootstrap
::getPath($parent);
88 if (!$dep_file) break;
89 $deps[$dep_file] = true;
94 foreach (array_keys($deps) as $file) {
95 // Extra dependencies must come *before* base dependencies
96 $deps = get_dependency_lookup($file) +
$deps;
98 $cache[$file] = $deps;
103 * Sorts files based on dependencies. This function is lazy and will not
104 * group files with dependencies together; it will merely ensure that a file
105 * is never included before its dependencies are.
108 * Files array to sort.
110 * Sorted array ($files is not modified by reference!)
112 function dep_sort($files)
116 foreach ($files as $file) {
117 if (isset($cache[$file])) continue;
118 $deps = get_dependency_lookup($file);
119 foreach (array_keys($deps) as $dep) {
120 if (!isset($cache[$dep])) {
125 $cache[$file] = true;
131 $files = dep_sort($files);
133 // Build the actual include stub:
135 $version = trim(file_get_contents('../VERSION'));
142 * This file was auto-generated by generate-includes.php and includes all of
143 * the core files required by HTML Purifier. Use this if performance is a
144 * primary concern and you are using an opcode cache. PLEASE DO NOT EDIT THIS
145 * FILE, changes will be overwritten the next time the script is run.
150 * You must *not* include any other HTML Purifier files before this file,
151 * because 'require' not 'require_once' is used.
154 * This file requires that the include path contains the HTML Purifier
155 * library directory; this is not auto-set.
160 foreach ($files as $file) {
161 $php .= "require '$file';" . PHP_EOL
;
164 echo "Writing HTMLPurifier.includes.php... ";
165 file_put_contents('HTMLPurifier.includes.php', $php);
172 * This file was auto-generated by generate-includes.php and includes all of
173 * the core files required by HTML Purifier. This is a convenience stub that
174 * includes all files using dirname(__FILE__) and require_once. PLEASE DO NOT
175 * EDIT THIS FILE, changes will be overwritten the next time the script is run.
177 * Changes to include_path are not necessary.
180 \$__dir = dirname(__FILE__);
184 foreach ($files as $file) {
185 $php .= "require_once \$__dir . '/$file';" . PHP_EOL
;
188 echo "Writing HTMLPurifier.safe-includes.php... ";
189 file_put_contents('HTMLPurifier.safe-includes.php', $php);
192 // vim: et sw=4 sts=4