ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
generate-standalone.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 assertCli();
7 
18 $GLOBALS['loaded'] = array();
19 
26 {
27  public function copyable($entry)
28  {
29  // Skip hidden files
30  if ($entry[0] == '.') {
31  return false;
32  }
33  return true;
34  }
35  public function copy($source, $dest)
36  {
37  copy_and_remove_includes($source, $dest);
38  }
39 }
41 
48 {
49  // also remove vim modelines
50  return preg_replace_callback(
51  "/require(?:_once)? ['\"]([^'\"]+)['\"];/",
52  'replace_includes_callback',
53  $text
54  );
55 }
56 
64 {
65  $text = preg_replace('#// vim:.+#', '', $text);
66  return substr($text, 5);
67 }
68 
73 function make_dir_standalone($dir)
74 {
75  global $FS;
76  return $FS->copyr($dir, 'standalone/' . $dir);
77 }
78 
84 {
85  global $FS;
86  $FS->mkdirr('standalone/' . dirname($file));
87  copy_and_remove_includes($file, 'standalone/' . $file);
88  return true;
89 }
90 
98 {
99  $contents = file_get_contents($file);
100  if (strrchr($file, '.') === '.php') $contents = replace_includes($contents);
101  return file_put_contents($sfile, $contents);
102 }
103 
108 function replace_includes_callback($matches)
109 {
110  $file = $matches[1];
111  $preserve = array(
112  // PEAR (external)
113  'XML/HTMLSax3.php' => 1
114  );
115  if (isset($preserve[$file])) {
116  return $matches[0];
117  }
118  if (isset($GLOBALS['loaded'][$file])) return '';
119  $GLOBALS['loaded'][$file] = true;
120  return replace_includes(remove_php_tags(file_get_contents($file)));
121 }
122 
123 echo 'Generating includes file... ';
124 shell_exec('php generate-includes.php');
125 echo "done!\n";
126 
127 chdir(dirname(__FILE__) . '/../library/');
128 
129 echo 'Creating full file...';
130 $contents = replace_includes(file_get_contents('HTMLPurifier.includes.php'));
131 $contents = str_replace(
132  // Note that bootstrap is now inside the standalone file
133  "define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));",
134  "define('HTMLPURIFIER_PREFIX', dirname(__FILE__) . '/standalone');
135  set_include_path(HTMLPURIFIER_PREFIX . PATH_SEPARATOR . get_include_path());",
136  $contents
137 );
138 file_put_contents('HTMLPurifier.standalone.php', $contents);
139 echo ' done!' . PHP_EOL;
140 
141 echo 'Creating standalone directory...';
142 $FS->rmdirr('standalone'); // ensure a clean copy
143 
144 // data files
145 $FS->mkdirr('standalone/HTMLPurifier/DefinitionCache/Serializer');
146 make_file_standalone('HTMLPurifier/EntityLookup/entities.ser');
147 make_file_standalone('HTMLPurifier/ConfigSchema/schema.ser');
148 
149 // non-standard inclusion setup
150 make_dir_standalone('HTMLPurifier/ConfigSchema');
151 make_dir_standalone('HTMLPurifier/Language');
152 make_dir_standalone('HTMLPurifier/Filter');
153 make_dir_standalone('HTMLPurifier/Printer');
154 make_file_standalone('HTMLPurifier/Printer.php');
155 make_file_standalone('HTMLPurifier/Lexer/PH5P.php');
156 
157 echo ' done!' . PHP_EOL;
158 
159 // vim: et sw=4 sts=4
remove_php_tags($text)
Removes leading PHP tags from included files.
replace_includes_callback($matches)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Filesystem tools not provided by default; can recursively create, copy and delete folders...
Definition: FSTools.php:10
make_dir_standalone($dir)
Copies the contents of a directory to the standalone directory.
replace_includes($text)
Replaces the includes inside PHP source code with the corresponding source.
copy_and_remove_includes($file, $sfile)
Copies a file to another location recursively, if it is a PHP file remove includes.
if($is_dev) echo "Review changes write something in WHATSNEW and and then commit with log PHP_EOL
Create styles array
The data for the language used.
make_file_standalone($file)
Copies the contents of a file to the standalone directory.
assertCli()
Definition: common.php:3
Custom FSTools for this script that overloads some behavior.
$text
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file