ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
generate-standalone.php
Go to the documentation of this file.
1#!/usr/bin/php
2<?php
3
4chdir(dirname(__FILE__));
5require_once 'common.php';
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 {
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
73function 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
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
123echo 'Generating includes file... ';
124shell_exec('php generate-includes.php');
125echo "done!\n";
126
127chdir(dirname(__FILE__) . '/../library/');
128
129echo '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());",
137);
138file_put_contents('HTMLPurifier.standalone.php', $contents);
139echo ' done!' . PHP_EOL;
140
141echo 'Creating standalone directory...';
142$FS->rmdirr('standalone'); // ensure a clean copy
143
144// data files
145$FS->mkdirr('standalone/HTMLPurifier/DefinitionCache/Serializer');
146make_file_standalone('HTMLPurifier/EntityLookup/entities.ser');
147make_file_standalone('HTMLPurifier/ConfigSchema/schema.ser');
148
149// non-standard inclusion setup
150make_dir_standalone('HTMLPurifier/ConfigSchema');
151make_dir_standalone('HTMLPurifier/Language');
152make_dir_standalone('HTMLPurifier/Filter');
153make_dir_standalone('HTMLPurifier/Printer');
154make_file_standalone('HTMLPurifier/Printer.php');
155make_file_standalone('HTMLPurifier/Lexer/PH5P.php');
156
157echo ' done!' . PHP_EOL;
158
159// vim: et sw=4 sts=4
$source
Definition: linkback.php:22
An exception for terminatinating execution or to throw for unit testing.
Filesystem tools not provided by default; can recursively create, copy and delete folders.
Definition: FSTools.php:11
Custom FSTools for this script that overloads some behavior.
copyable($entry)
Overloadable function that tests a filename for copyability.
assertCli()
Definition: common.php:3
replace_includes_callback($matches)
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.
make_file_standalone($file)
Copies the contents of a file to the standalone directory.
copy_and_remove_includes($file, $sfile)
Copies a file to another location recursively, if it is a PHP file remove includes.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
remove_php_tags($text)
Removes leading PHP tags from included files.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$text
Definition: errorreport.php:18