ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
generate-includes.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 
4 chdir(dirname(__FILE__));
5 require_once 'common.php';
6 require_once '../tests/path2class.func.php';
7 require_once '../library/HTMLPurifier/Bootstrap.php';
8 assertCli();
9 
17 chdir(dirname(__FILE__) . '/../library/');
18 $FS = new FSTools();
19 
21  'HTMLPurifier/Language/',
22  'HTMLPurifier/ConfigSchema/',
23  'HTMLPurifier/Filter/',
24  'HTMLPurifier/Printer/',
25  /* These should be excluded, but need to have ConfigSchema support first
26 
27  */
28 );
30  'HTMLPurifier/Lexer/PEARSax3.php',
31  'HTMLPurifier/Lexer/PH5P.php',
32  'HTMLPurifier/Printer.php',
33 );
34 
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
44  $ok = true;
45  foreach ($exclude_dirs as $dir) {
46  if (strncmp($dir, $file, strlen($dir)) === 0) {
47  $ok = false;
48  break;
49  }
50  }
51  if (!$ok) continue; // rm excluded directories
52  if (in_array($file, $exclude_files)) continue; // rm excluded files
53  $files[] = $file;
54 }
55 echo "done!\n";
56 
57 // Reorder list so that dependencies are included first:
58 
69 function get_dependency_lookup($file)
70 {
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";
75  return array();
76  }
77  $fh = fopen($file, 'r');
78  $deps = array();
79  while (!feof($fh)) {
80  $line = fgets($fh);
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;
86  $parent = $arr[1];
87  $dep_file = HTMLPurifier_Bootstrap::getPath($parent);
88  if (!$dep_file) break;
89  $deps[$dep_file] = true;
90  break;
91  }
92  }
93  fclose($fh);
94  foreach (array_keys($deps) as $file) {
95  // Extra dependencies must come *before* base dependencies
96  $deps = get_dependency_lookup($file) + $deps;
97  }
98  $cache[$file] = $deps;
99  return $deps;
100 }
101 
112 function dep_sort($files)
113 {
114  $ret = array();
115  $cache = array();
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])) {
121  $ret[] = $dep;
122  $cache[$dep] = true;
123  }
124  }
125  $cache[$file] = true;
126  $ret[] = $file;
127  }
128  return $ret;
129 }
130 
132 
133 // Build the actual include stub:
134 
135 $version = trim(file_get_contents('../VERSION'));
136 
137 // stub
138 $php = "<?php
139 
158 ";
159 
160 foreach ($files as $file) {
161  $php .= "require '$file';" . PHP_EOL;
162 }
163 
164 echo "Writing HTMLPurifier.includes.php... ";
165 file_put_contents('HTMLPurifier.includes.php', $php);
166 echo "done!\n";
167 
168 $php = "<?php
169 
180 \$__dir = dirname(__FILE__);
181 
182 ";
183 
184 foreach ($files as $file) {
185  $php .= "require_once \$__dir . '/$file';" . PHP_EOL;
186 }
187 
188 echo "Writing HTMLPurifier.safe-includes.php... ";
189 file_put_contents('HTMLPurifier.safe-includes.php', $php);
190 echo "done!\n";
191 
192 // vim: et sw=4 sts=4
$exclude_dirs
$exclude_files
Filesystem tools not provided by default; can recursively create, copy and delete folders...
Definition: FSTools.php:10
if($is_dev) echo "Review changes write something in WHATSNEW and and then commit with log PHP_EOL
static getPath($class)
Returns the path for a specific class.
Definition: Bootstrap.php:58
Create styles array
The data for the language used.
assertCli()
Definition: common.php:3
dep_sort($files)
Sorts files based on dependencies.
$ret
Definition: parser.php:6
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
get_dependency_lookup($file)
Returns a lookup array of dependencies for a file.