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) {
70 static $cache = array();
71 if (isset($cache[$file])) return $cache[$file];
72 if (!file_exists($file)) {
73 echo "File doesn't exist: $file\n";
76 $fh = fopen($file, 'r');
80 if (strncmp('class', $line, 5) === 0) {
81 // The implementation here is fragile and will break if we attempt
82 // to use interfaces. Beware!
83 $arr = explode(' extends ', trim($line, ' {'."\n\r"), 2);
84 if (count($arr) < 2) break;
86 $dep_file = HTMLPurifier_Bootstrap
::getPath($parent);
87 if (!$dep_file) break;
88 $deps[$dep_file] = true;
93 foreach (array_keys($deps) as $file) {
94 // Extra dependencies must come *before* base dependencies
95 $deps = get_dependency_lookup($file) +
$deps;
97 $cache[$file] = $deps;
102 * Sorts files based on dependencies. This function is lazy and will not
103 * group files with dependencies together; it will merely ensure that a file
104 * is never included before its dependencies are.
107 * Files array to sort.
109 * Sorted array ($files is not modified by reference!)
111 function dep_sort($files) {
114 foreach ($files as $file) {
115 if (isset($cache[$file])) continue;
116 $deps = get_dependency_lookup($file);
117 foreach (array_keys($deps) as $dep) {
118 if (!isset($cache[$dep])) {
123 $cache[$file] = true;
129 $files = dep_sort($files);
131 // Build the actual include stub:
133 $version = trim(file_get_contents('../VERSION'));
140 * This file was auto-generated by generate-includes.php and includes all of
141 * the core files required by HTML Purifier. Use this if performance is a
142 * primary concern and you are using an opcode cache. PLEASE DO NOT EDIT THIS
143 * FILE, changes will be overwritten the next time the script is run.
148 * You must *not* include any other HTML Purifier files before this file,
149 * because 'require' not 'require_once' is used.
152 * This file requires that the include path contains the HTML Purifier
153 * library directory; this is not auto-set.
158 foreach ($files as $file) {
159 $php .= "require '$file';" . PHP_EOL
;
162 echo "Writing HTMLPurifier.includes.php... ";
163 file_put_contents('HTMLPurifier.includes.php', $php);
170 * This file was auto-generated by generate-includes.php and includes all of
171 * the core files required by HTML Purifier. This is a convenience stub that
172 * includes all files using dirname(__FILE__) and require_once. PLEASE DO NOT
173 * EDIT THIS FILE, changes will be overwritten the next time the script is run.
175 * Changes to include_path are not necessary.
178 \$__dir = dirname(__FILE__);
182 foreach ($files as $file) {
183 $php .= "require_once \$__dir . '/$file';" . PHP_EOL
;
186 echo "Writing HTMLPurifier.safe-includes.php... ";
187 file_put_contents('HTMLPurifier.safe-includes.php', $php);
190 // vim: et sw=4 sts=4