first commit

This commit is contained in:
aschwarz
2023-02-27 12:57:51 +01:00
commit 35f3994c25
2442 changed files with 470540 additions and 0 deletions

View File

@ -0,0 +1 @@
Deny from all

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,130 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
/**
* @file
* Adds vimline to files
*/
chdir(dirname(__FILE__) . '/..');
$FS = new FSTools();
$vimline = 'vim: et sw=4 sts=4';
$files = $FS->globr('.', '*');
foreach ($files as $file) {
if (
!is_file($file) ||
prefix_is('./docs/doxygen', $file) ||
prefix_is('./library/standalone', $file) ||
prefix_is('./docs/specimens', $file) ||
postfix_is('.ser', $file) ||
postfix_is('.tgz', $file) ||
postfix_is('.patch', $file) ||
postfix_is('.dtd', $file) ||
postfix_is('.ent', $file) ||
postfix_is('.png', $file) ||
postfix_is('.ico', $file) ||
// wontfix
postfix_is('.vtest', $file) ||
postfix_is('.svg', $file) ||
postfix_is('.phpt', $file) ||
postfix_is('VERSION', $file) ||
postfix_is('WHATSNEW', $file) ||
postfix_is('configdoc/usage.xml', $file) ||
postfix_is('library/HTMLPurifier.includes.php', $file) ||
postfix_is('library/HTMLPurifier.safe-includes.php', $file) ||
postfix_is('smoketests/xssAttacks.xml', $file) ||
// phpt files
postfix_is('.diff', $file) ||
postfix_is('.exp', $file) ||
postfix_is('.log', $file) ||
postfix_is('.out', $file) ||
$file == './library/HTMLPurifier/Lexer/PH5P.php' ||
$file == './maintenance/PH5P.php'
) continue;
$ext = strrchr($file, '.');
if (
postfix_is('README', $file) ||
postfix_is('LICENSE', $file) ||
postfix_is('CREDITS', $file) ||
postfix_is('INSTALL', $file) ||
postfix_is('NEWS', $file) ||
postfix_is('TODO', $file) ||
postfix_is('WYSIWYG', $file) ||
postfix_is('Changelog', $file)
) $ext = '.txt';
if (postfix_is('Doxyfile', $file)) $ext = 'Doxyfile';
if (postfix_is('.php.in', $file)) $ext = '.php';
$no_nl = false;
switch ($ext) {
case '.php':
case '.inc':
case '.js':
$line = '// %s';
break;
case '.html':
case '.xsl':
case '.xml':
case '.htc':
$line = "<!-- %s\n-->";
break;
case '.htmlt':
$no_nl = true;
$line = '--# %s';
break;
case '.ini':
$line = '; %s';
break;
case '.css':
$line = '/* %s */';
break;
case '.bat':
$line = 'rem %s';
break;
case '.txt':
case '.utf8':
if (
prefix_is('./library/HTMLPurifier/ConfigSchema', $file) ||
prefix_is('./smoketests/test-schema', $file) ||
prefix_is('./tests/HTMLPurifier/StringHashParser', $file)
) {
$no_nl = true;
$line = '--# %s';
} else {
$line = ' %s';
}
break;
case 'Doxyfile':
$line = '# %s';
break;
default:
throw new Exception('Unknown file: ' . $file);
}
echo "$file\n";
$contents = file_get_contents($file);
$regex = '~' . str_replace('%s', 'vim: .+', preg_quote($line, '~')) . '~m';
$contents = preg_replace($regex, '', $contents);
$contents = rtrim($contents);
if (strpos($contents, "\r\n") !== false) $nl = "\r\n";
elseif (strpos($contents, "\n") !== false) $nl = "\n";
elseif (strpos($contents, "\r") !== false) $nl = "\r";
else $nl = PHP_EOL;
if (!$no_nl) $contents .= $nl;
$contents .= $nl . str_replace('%s', $vimline, $line) . $nl;
file_put_contents($file, $contents);
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,25 @@
<?php
function assertCli()
{
if (php_sapi_name() != 'cli' && !getenv('PHP_IS_CLI')) {
echo 'Script cannot be called from web-browser (if you are indeed calling via cli,
set environment variable PHP_IS_CLI to work around this).';
exit(1);
}
}
function prefix_is($comp, $subject)
{
return strncmp($comp, $subject, strlen($comp)) === 0;
}
function postfix_is($comp, $subject)
{
return strlen($subject) < $comp ? false : substr($subject, -strlen($comp)) === $comp;
}
// Load useful stuff like FSTools
require_once dirname(__FILE__) . '/../extras/HTMLPurifierExtras.auto.php';
// vim: et sw=4 sts=4

View File

@ -0,0 +1,11 @@
#!/bin/bash
cd ..
mkdir docs/doxygen
rm -Rf docs/doxygen/*
doxygen 1>docs/doxygen/info.log 2>docs/doxygen/errors.log
if [ "$?" != 0 ]; then
cat docs/doxygen/errors.log
exit
fi
cd docs
tar czf doxygen.tgz doxygen

View File

@ -0,0 +1,155 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
require_once '../library/HTMLPurifier.auto.php';
assertCli();
if (version_compare(PHP_VERSION, '5.2.2', '<')) {
echo "This script requires PHP 5.2.2 or later, for tokenizer line numbers.";
exit(1);
}
/**
* @file
* Scans HTML Purifier source code for $config tokens and records the
* directive being used; configdoc can use this info later.
*
* Currently, this just dumps all the info onto the console. Eventually, it
* will create an XML file that our XSLT transform can use.
*/
$FS = new FSTools();
chdir(dirname(__FILE__) . '/../library/');
$raw_files = $FS->globr('.', '*.php');
$files = array();
foreach ($raw_files as $file) {
$file = substr($file, 2); // rm leading './'
if (strncmp('standalone/', $file, 11) === 0) continue; // rm generated files
if (substr_count($file, '.') > 1) continue; // rm meta files
$files[] = $file;
}
/**
* Moves the $i cursor to the next non-whitespace token
*/
function consumeWhitespace($tokens, &$i)
{
do {$i++;} while (is_array($tokens[$i]) && $tokens[$i][0] === T_WHITESPACE);
}
/**
* Tests whether or not a token is a particular type. There are three run-cases:
* - ($token, $expect_token): tests if the token is $expect_token type;
* - ($token, $expect_value): tests if the token is the string $expect_value;
* - ($token, $expect_token, $expect_value): tests if token is $expect_token type, and
* its string representation is $expect_value
*/
function testToken($token, $value_or_token, $value = null)
{
if (is_null($value)) {
if (is_int($value_or_token)) return is_array($token) && $token[0] === $value_or_token;
else return $token === $value_or_token;
} else {
return is_array($token) && $token[0] === $value_or_token && $token[1] === $value;
}
}
$counter = 0;
$full_counter = 0;
$tracker = array();
foreach ($files as $file) {
$tokens = token_get_all(file_get_contents($file));
$file = str_replace('\\', '/', $file);
for ($i = 0, $c = count($tokens); $i < $c; $i++) {
$ok = false;
// Match $config
if (!$ok && testToken($tokens[$i], T_VARIABLE, '$config')) $ok = true;
// Match $this->config
while (!$ok && testToken($tokens[$i], T_VARIABLE, '$this')) {
consumeWhitespace($tokens, $i);
if (!testToken($tokens[$i], T_OBJECT_OPERATOR)) break;
consumeWhitespace($tokens, $i);
if (testToken($tokens[$i], T_STRING, 'config')) $ok = true;
break;
}
if (!$ok) continue;
$ok = false;
for($i++; $i < $c; $i++) {
if ($tokens[$i] === ',' || $tokens[$i] === ')' || $tokens[$i] === ';') {
break;
}
if (is_string($tokens[$i])) continue;
if ($tokens[$i][0] === T_OBJECT_OPERATOR) {
$ok = true;
break;
}
}
if (!$ok) continue;
$line = $tokens[$i][2];
consumeWhitespace($tokens, $i);
if (!testToken($tokens[$i], T_STRING, 'get')) continue;
consumeWhitespace($tokens, $i);
if (!testToken($tokens[$i], '(')) continue;
$full_counter++;
$matched = false;
do {
// What we currently don't match are batch retrievals, and
// wildcard retrievals. This data might be useful in the future,
// which is why we have a do {} while loop that doesn't actually
// do anything.
consumeWhitespace($tokens, $i);
if (!testToken($tokens[$i], T_CONSTANT_ENCAPSED_STRING)) continue;
$id = substr($tokens[$i][1], 1, -1);
$counter++;
$matched = true;
if (!isset($tracker[$id])) $tracker[$id] = array();
if (!isset($tracker[$id][$file])) $tracker[$id][$file] = array();
$tracker[$id][$file][] = $line;
} while (0);
//echo "$file:$line uses $namespace.$directive\n";
}
}
echo "\n$counter/$full_counter instances of \$config or \$this->config found in source code.\n";
echo "Generating XML... ";
$xw = new XMLWriter();
$xw->openURI('../configdoc/usage.xml');
$xw->setIndent(true);
$xw->startDocument('1.0', 'UTF-8');
$xw->startElement('usage');
foreach ($tracker as $id => $files) {
$xw->startElement('directive');
$xw->writeAttribute('id', $id);
foreach ($files as $file => $lines) {
$xw->startElement('file');
$xw->writeAttribute('name', $file);
foreach ($lines as $line) {
$xw->writeElement('line', $line);
}
$xw->endElement();
}
$xw->endElement();
}
$xw->endElement();
$xw->flush();
echo "done!\n";
// vim: et sw=4 sts=4

View File

@ -0,0 +1,42 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
/**
* @file
* Flushes the definition serial cache. This file should be
* called if changes to any subclasses of HTMLPurifier_Definition
* or related classes (such as HTMLPurifier_HTMLModule) are made. This
* may also be necessary if you've modified a customized version.
*
* @param Accepts one argument, cache type to flush; otherwise flushes all
* the caches.
*/
echo "Flushing cache... \n";
require_once(dirname(__FILE__) . '/../library/HTMLPurifier.auto.php');
$config = HTMLPurifier_Config::createDefault();
$names = array('HTML', 'CSS', 'URI', 'Test');
if (isset($argv[1])) {
if (in_array($argv[1], $names)) {
$names = array($argv[1]);
} else {
throw new Exception("Cache parameter {$argv[1]} is not a valid cache");
}
}
foreach ($names as $name) {
echo " - Flushing $name\n";
$cache = new HTMLPurifier_DefinitionCache_Serializer($name);
$cache->flush($config);
}
echo "Cache flushed successfully.\n";
// vim: et sw=4 sts=4

View File

@ -0,0 +1,30 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
/**
* @file
* Runs all generation/flush cache scripts to ensure that somewhat volatile
* generated files are up-to-date.
*/
function e($cmd)
{
echo "\$ $cmd\n";
passthru($cmd, $status);
echo "\n";
if ($status) exit($status);
}
$php = empty($_SERVER['argv'][1]) ? 'php' : $_SERVER['argv'][1];
e($php . ' generate-includes.php');
e($php . ' generate-schema-cache.php');
e($php . ' flush-definition-cache.php');
e($php . ' generate-standalone.php');
e($php . ' config-scanner.php');
// vim: et sw=4 sts=4

View File

@ -0,0 +1,75 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
/**
* @file
* Parses *.ent files into an entity lookup table, and then serializes and
* writes the whole kaboodle to a file. The resulting file is cached so
* that this script does not need to be run. This script should rarely,
* if ever, be run, since HTML's entities are fairly immutable.
*/
// here's where the entity files are located, assuming working directory
// is the same as the location of this PHP file. Needs trailing slash.
$entity_dir = '../docs/entities/';
// defines the output file for the serialized content.
$output_file = '../library/HTMLPurifier/EntityLookup/entities.ser';
// courtesy of a PHP manual comment
function unichr($dec)
{
if ($dec < 128) {
$utf = chr($dec);
} elseif ($dec < 2048) {
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
} else {
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
return $utf;
}
if ( !is_dir($entity_dir) ) exit("Fatal Error: Can't find entity directory.\n");
if ( file_exists($output_file) ) exit("Fatal Error: output file already exists.\n");
$dh = @opendir($entity_dir);
if ( !$dh ) exit("Fatal Error: Cannot read entity directory.\n");
$entity_files = array();
while (($file = readdir($dh)) !== false) {
if (@$file[0] === '.') continue;
if (substr(strrchr($file, "."), 1) !== 'ent') continue;
$entity_files[] = $file;
}
closedir($dh);
if ( !$entity_files ) exit("Fatal Error: No entity files to parse.\n");
$entity_table = array();
$regexp = '/<!ENTITY\s+([A-Za-z0-9]+)\s+"&#(?:38;#)?([0-9]+);">/';
foreach ( $entity_files as $file ) {
$contents = file_get_contents($entity_dir . $file);
$matches = array();
preg_match_all($regexp, $contents, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$entity_table[$match[1]] = unichr($match[2]);
}
}
$output = serialize($entity_table);
$fh = fopen($output_file, 'w');
fwrite($fh, $output);
fclose($fh);
echo "Completed successfully.";
// vim: et sw=4 sts=4

View File

@ -0,0 +1,192 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
require_once '../tests/path2class.func.php';
require_once '../library/HTMLPurifier/Bootstrap.php';
assertCli();
/**
* @file
* Generates an include stub for users who do not want to use the autoloader.
* When new files are added to HTML Purifier's main codebase, this file should
* be called.
*/
chdir(dirname(__FILE__) . '/../library/');
$FS = new FSTools();
$exclude_dirs = array(
'HTMLPurifier/Language/',
'HTMLPurifier/ConfigSchema/',
'HTMLPurifier/Filter/',
'HTMLPurifier/Printer/',
/* These should be excluded, but need to have ConfigSchema support first
*/
);
$exclude_files = array(
'HTMLPurifier/Lexer/PEARSax3.php',
'HTMLPurifier/Lexer/PH5P.php',
'HTMLPurifier/Printer.php',
);
// Determine what files need to be included:
echo 'Scanning for files... ';
$raw_files = $FS->globr('.', '*.php');
if (!$raw_files) throw new Exception('Did not find any PHP source files');
$files = array();
foreach ($raw_files as $file) {
$file = substr($file, 2); // rm leading './'
if (strncmp('standalone/', $file, 11) === 0) continue; // rm generated files
if (substr_count($file, '.') > 1) continue; // rm meta files
$ok = true;
foreach ($exclude_dirs as $dir) {
if (strncmp($dir, $file, strlen($dir)) === 0) {
$ok = false;
break;
}
}
if (!$ok) continue; // rm excluded directories
if (in_array($file, $exclude_files)) continue; // rm excluded files
$files[] = $file;
}
echo "done!\n";
// Reorder list so that dependencies are included first:
/**
* Returns a lookup array of dependencies for a file.
*
* @note This function expects that format $name extends $parent on one line
*
* @param string $file
* File to check dependencies of.
* @return array
* Lookup array of files the file is dependent on, sorted accordingly.
*/
function get_dependency_lookup($file)
{
static $cache = array();
if (isset($cache[$file])) return $cache[$file];
if (!file_exists($file)) {
echo "File doesn't exist: $file\n";
return array();
}
$fh = fopen($file, 'r');
$deps = array();
while (!feof($fh)) {
$line = fgets($fh);
if (strncmp('class', $line, 5) === 0) {
// The implementation here is fragile and will break if we attempt
// to use interfaces. Beware!
$arr = explode(' extends ', trim($line, ' {'."\n\r"), 2);
if (count($arr) < 2) break;
$parent = $arr[1];
$dep_file = HTMLPurifier_Bootstrap::getPath($parent);
if (!$dep_file) break;
$deps[$dep_file] = true;
break;
}
}
fclose($fh);
foreach (array_keys($deps) as $file) {
// Extra dependencies must come *before* base dependencies
$deps = get_dependency_lookup($file) + $deps;
}
$cache[$file] = $deps;
return $deps;
}
/**
* Sorts files based on dependencies. This function is lazy and will not
* group files with dependencies together; it will merely ensure that a file
* is never included before its dependencies are.
*
* @param $files
* Files array to sort.
* @return
* Sorted array ($files is not modified by reference!)
*/
function dep_sort($files)
{
$ret = array();
$cache = array();
foreach ($files as $file) {
if (isset($cache[$file])) continue;
$deps = get_dependency_lookup($file);
foreach (array_keys($deps) as $dep) {
if (!isset($cache[$dep])) {
$ret[] = $dep;
$cache[$dep] = true;
}
}
$cache[$file] = true;
$ret[] = $file;
}
return $ret;
}
$files = dep_sort($files);
// Build the actual include stub:
$version = trim(file_get_contents('../VERSION'));
// stub
$php = "<?php
/**
* @file
* This file was auto-generated by generate-includes.php and includes all of
* the core files required by HTML Purifier. Use this if performance is a
* primary concern and you are using an opcode cache. PLEASE DO NOT EDIT THIS
* FILE, changes will be overwritten the next time the script is run.
*
* @version $version
*
* @warning
* You must *not* include any other HTML Purifier files before this file,
* because 'require' not 'require_once' is used.
*
* @warning
* This file requires that the include path contains the HTML Purifier
* library directory; this is not auto-set.
*/
";
foreach ($files as $file) {
$php .= "require '$file';" . PHP_EOL;
}
echo "Writing HTMLPurifier.includes.php... ";
file_put_contents('HTMLPurifier.includes.php', $php);
echo "done!\n";
$php = "<?php
/**
* @file
* This file was auto-generated by generate-includes.php and includes all of
* the core files required by HTML Purifier. This is a convenience stub that
* includes all files using dirname(__FILE__) and require_once. PLEASE DO NOT
* EDIT THIS FILE, changes will be overwritten the next time the script is run.
*
* Changes to include_path are not necessary.
*/
\$__dir = dirname(__FILE__);
";
foreach ($files as $file) {
$php .= "require_once \$__dir . '/$file';" . PHP_EOL;
}
echo "Writing HTMLPurifier.safe-includes.php... ";
file_put_contents('HTMLPurifier.safe-includes.php', $php);
echo "done!\n";
// vim: et sw=4 sts=4

View File

@ -0,0 +1,22 @@
<?php
/**
* @file
* This file compares our version of PH5P with Jero's original version, and
* generates a patch of the differences. This script should be run whenever
* library/HTMLPurifier/Lexer/PH5P.php is modified.
*/
$orig = realpath(dirname(__FILE__) . '/PH5P.php');
$new = realpath(dirname(__FILE__) . '/../library/HTMLPurifier/Lexer/PH5P.php');
$newt = dirname(__FILE__) . '/PH5P.new.php'; // temporary file
// minor text-processing of new file to get into same format as original
$new_src = file_get_contents($new);
$new_src = '<?php' . PHP_EOL . substr($new_src, strpos($new_src, 'class HTML5 {'));
file_put_contents($newt, $new_src);
shell_exec("diff -u \"$orig\" \"$newt\" > PH5P.patch");
unlink($newt);
// vim: et sw=4 sts=4

View File

@ -0,0 +1,45 @@
#!/usr/bin/php
<?php
require_once dirname(__FILE__) . '/common.php';
require_once dirname(__FILE__) . '/../library/HTMLPurifier.auto.php';
assertCli();
/**
* @file
* Generates a schema cache file, saving it to
* library/HTMLPurifier/ConfigSchema/schema.ser.
*
* This should be run when new configuration options are added to
* HTML Purifier. A cached version is available via the repository
* so this does not normally have to be regenerated.
*
* If you have a directory containing custom configuration schema files,
* you can simple add a path to that directory as a parameter to
* this, and they will get included.
*/
$target = dirname(__FILE__) . '/../library/HTMLPurifier/ConfigSchema/schema.ser';
$builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
$builder->buildDir($interchange);
$loader = dirname(__FILE__) . '/../config-schema.php';
if (file_exists($loader)) include $loader;
foreach ($_SERVER['argv'] as $i => $dir) {
if ($i === 0) continue;
$builder->buildDir($interchange, realpath($dir));
}
$interchange->validate();
$schema_builder = new HTMLPurifier_ConfigSchema_Builder_ConfigSchema();
$schema = $schema_builder->build($interchange);
echo "Saving schema... ";
file_put_contents($target, serialize($schema));
echo "done!\n";
// vim: et sw=4 sts=4

View File

@ -0,0 +1,159 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
/**
* @file
* Compiles all of HTML Purifier's library files into one big file
* named HTMLPurifier.standalone.php. This is usually called during the
* release process.
*/
/**
* Global hash that tracks already loaded includes
*/
$GLOBALS['loaded'] = array();
/**
* Custom FSTools for this script that overloads some behavior
* @warning The overloading of copy() is not necessarily global for
* this script. Watch out!
*/
class MergeLibraryFSTools extends FSTools
{
public function copyable($entry)
{
// Skip hidden files
if ($entry[0] == '.') {
return false;
}
return true;
}
public function copy($source, $dest)
{
copy_and_remove_includes($source, $dest);
}
}
$FS = new MergeLibraryFSTools();
/**
* Replaces the includes inside PHP source code with the corresponding
* source.
* @param string $text PHP source code to replace includes from
*/
function replace_includes($text)
{
// also remove vim modelines
return preg_replace_callback(
"/require(?:_once)? ['\"]([^'\"]+)['\"];/",
'replace_includes_callback',
$text
);
}
/**
* Removes leading PHP tags from included files. Assumes that there is
* no trailing tag. Also removes vim modelines.
* @note This is safe for files that have internal <?php
* @param string $text Text to have leading PHP tag from
*/
function remove_php_tags($text)
{
$text = preg_replace('#// vim:.+#', '', $text);
return substr($text, 5);
}
/**
* Copies the contents of a directory to the standalone directory
* @param string $dir Directory to copy
*/
function make_dir_standalone($dir)
{
global $FS;
return $FS->copyr($dir, 'standalone/' . $dir);
}
/**
* Copies the contents of a file to the standalone directory
* @param string $file File to copy
*/
function make_file_standalone($file)
{
global $FS;
$FS->mkdirr('standalone/' . dirname($file));
copy_and_remove_includes($file, 'standalone/' . $file);
return true;
}
/**
* Copies a file to another location recursively, if it is a PHP file
* remove includes
* @param string $file Original file
* @param string $sfile New location of file
*/
function copy_and_remove_includes($file, $sfile)
{
$contents = file_get_contents($file);
if (strrchr($file, '.') === '.php') $contents = replace_includes($contents);
return file_put_contents($sfile, $contents);
}
/**
* @param $matches preg_replace_callback matches array, where index 1
* is the filename to include
*/
function replace_includes_callback($matches)
{
$file = $matches[1];
$preserve = array(
// PEAR (external)
'XML/HTMLSax3.php' => 1
);
if (isset($preserve[$file])) {
return $matches[0];
}
if (isset($GLOBALS['loaded'][$file])) return '';
$GLOBALS['loaded'][$file] = true;
return replace_includes(remove_php_tags(file_get_contents($file)));
}
echo 'Generating includes file... ';
shell_exec('php generate-includes.php');
echo "done!\n";
chdir(dirname(__FILE__) . '/../library/');
echo 'Creating full file...';
$contents = replace_includes(file_get_contents('HTMLPurifier.includes.php'));
$contents = str_replace(
// Note that bootstrap is now inside the standalone file
"define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));",
"define('HTMLPURIFIER_PREFIX', dirname(__FILE__) . '/standalone');
set_include_path(HTMLPURIFIER_PREFIX . PATH_SEPARATOR . get_include_path());",
$contents
);
file_put_contents('HTMLPurifier.standalone.php', $contents);
echo ' done!' . PHP_EOL;
echo 'Creating standalone directory...';
$FS->rmdirr('standalone'); // ensure a clean copy
// data files
$FS->mkdirr('standalone/HTMLPurifier/DefinitionCache/Serializer');
make_file_standalone('HTMLPurifier/EntityLookup/entities.ser');
make_file_standalone('HTMLPurifier/ConfigSchema/schema.ser');
// non-standard inclusion setup
make_dir_standalone('HTMLPurifier/ConfigSchema');
make_dir_standalone('HTMLPurifier/Language');
make_dir_standalone('HTMLPurifier/Filter');
make_dir_standalone('HTMLPurifier/Printer');
make_file_standalone('HTMLPurifier/Printer.php');
make_file_standalone('HTMLPurifier/Lexer/PH5P.php');
echo ' done!' . PHP_EOL;
// vim: et sw=4 sts=4

View File

@ -0,0 +1,11 @@
#!/usr/bin/php
<?php
/**
* @file
* Deprecated in favor of generate-standalone.php.
*/
require dirname(__FILE__) . '/generate-standalone.php';
// vim: et sw=4 sts=4

View File

@ -0,0 +1,71 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
echo "Please do not run this script. It is here for historical purposes only.";
exit;
/**
* @file
* Extracts all definitions inside a configuration schema
* (HTMLPurifier_ConfigSchema) and exports them as plain text files.
*
* @todo Extract version numbers.
*/
define('HTMLPURIFIER_SCHEMA_STRICT', true); // description data needs to be collected
require_once dirname(__FILE__) . '/../library/HTMLPurifier.auto.php';
// We need includes to ensure all HTMLPurifier_ConfigSchema calls are
// performed.
require_once 'HTMLPurifier.includes.php';
// Also, these extra files will be necessary.
require_once 'HTMLPurifier/Filter/ExtractStyleBlocks.php';
/**
* Takes a hash and saves its contents to library/HTMLPurifier/ConfigSchema/
*/
function saveHash($hash)
{
if ($hash === false) return;
$dir = realpath(dirname(__FILE__) . '/../library/HTMLPurifier/ConfigSchema');
$name = $hash['ID'] . '.txt';
$file = $dir . '/' . $name;
if (file_exists($file)) {
trigger_error("File already exists; skipped $name");
return;
}
$file = new FSTools_File($file);
$file->open('w');
$multiline = false;
foreach ($hash as $key => $value) {
$multiline = $multiline || (strpos($value, "\n") !== false);
if ($multiline) {
$file->put("--$key--" . PHP_EOL);
$file->put(str_replace("\n", PHP_EOL, $value) . PHP_EOL);
} else {
if ($key == 'ID') {
$file->put("$value" . PHP_EOL);
} else {
$file->put("$key: $value" . PHP_EOL);
}
}
}
$file->close();
}
$schema = HTMLPurifier_ConfigSchema::instance();
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($schema);
foreach ($schema->info as $ns => $ns_array) {
saveHash($adapter->get($ns));
foreach ($ns_array as $dir => $x) {
saveHash($adapter->get($ns, $dir));
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,32 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
echo "Please do not run this script. It is here for historical purposes only.";
exit;
/**
* @file
* Removes leading includes from files.
*
* @note
* This does not remove inline includes; those must be handled manually.
*/
chdir(dirname(__FILE__) . '/../tests/HTMLPurifier');
$FS = new FSTools();
$files = $FS->globr('.', '*.php');
foreach ($files as $file) {
if (substr_count(basename($file), '.') > 1) continue;
$old_code = file_get_contents($file);
$new_code = preg_replace("#^require_once .+[\n\r]*#m", '', $old_code);
if ($old_code !== $new_code) {
file_put_contents($file, $new_code);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,32 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
echo "Please do not run this script. It is here for historical purposes only.";
exit;
/**
* @file
* Removes ConfigSchema function calls from source files.
*/
chdir(dirname(__FILE__) . '/../library/');
$FS = new FSTools();
$files = $FS->globr('.', '*.php');
foreach ($files as $file) {
if (substr_count(basename($file), '.') > 1) continue;
$old_code = file_get_contents($file);
$new_code = preg_replace("#^HTMLPurifier_ConfigSchema::.+?\);[\n\r]*#ms", '', $old_code);
if ($old_code !== $new_code) {
file_put_contents($file, $new_code);
}
if (preg_match('#^\s+HTMLPurifier_ConfigSchema::#m', $new_code)) {
echo "Indented ConfigSchema call in $file\n";
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,5 @@
#!/bin/bash -e
./compile-doxygen.sh
cd ../docs
scp doxygen.tgz htmlpurifier.org:/home/ezyang/htmlpurifier.org
ssh htmlpurifier.org "cd /home/ezyang/htmlpurifier.org && ./reload-docs.sh"

View File

@ -0,0 +1,37 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
/**
* @file
* Removes trailing whitespace from files.
*/
chdir(dirname(__FILE__) . '/..');
$FS = new FSTools();
$files = $FS->globr('.', '{,.}*', GLOB_BRACE);
foreach ($files as $file) {
if (
!is_file($file) ||
prefix_is('./.git', $file) ||
prefix_is('./docs/doxygen', $file) ||
postfix_is('.ser', $file) ||
postfix_is('.tgz', $file) ||
postfix_is('.patch', $file) ||
postfix_is('.dtd', $file) ||
postfix_is('.ent', $file) ||
$file == './library/HTMLPurifier/Lexer/PH5P.php' ||
$file == './maintenance/PH5P.php'
) continue;
$contents = file_get_contents($file);
$result = preg_replace('/^(.*?)[ \t]+(\r?)$/m', '\1\2', $contents, -1, $count);
if (!$count) continue;
echo "$file\n";
file_put_contents($file, $result);
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,84 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
require_once '../library/HTMLPurifier.auto.php';
assertCli();
/**
* @file
* Renames a configuration directive. This involves renaming the file,
* adding an alias, and then regenerating the cache. You still have to
* manually go through and fix any calls to the directive.
* @warning This script doesn't handle multi-stringhash files.
*/
$argv = $_SERVER['argv'];
if (count($argv) < 3) {
echo "Usage: {$argv[0]} OldName NewName\n";
exit(1);
}
chdir('../library/HTMLPurifier/ConfigSchema/schema');
$old = $argv[1];
$new = $argv[2];
if (!file_exists("$old.txt")) {
echo "Cannot move undefined configuration directive $old\n";
exit(1);
}
if ($old === $new) {
echo "Attempting to move to self, aborting\n";
exit(1);
}
if (file_exists("$new.txt")) {
echo "Cannot move to already defined directive $new\n";
exit(1);
}
$file = "$old.txt";
$builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
$builder->buildFile($interchange, $file);
$contents = file_get_contents($file);
if (strpos($contents, "\r\n") !== false) {
$nl = "\r\n";
} elseif (strpos($contents, "\r") !== false) {
$nl = "\r";
} else {
$nl = "\n";
}
// replace name with new name
$contents = str_replace($old, $new, $contents);
if ($interchange->directives[$old]->aliases) {
$pos_alias = strpos($contents, 'ALIASES:');
$pos_ins = strpos($contents, $nl, $pos_alias);
if ($pos_ins === false) $pos_ins = strlen($contents);
$contents =
substr($contents, 0, $pos_ins) . ", $old" . substr($contents, $pos_ins);
file_put_contents($file, $contents);
} else {
$lines = explode($nl, $contents);
$insert = false;
foreach ($lines as $n => $line) {
if (strncmp($line, '--', 2) === 0) {
$insert = $n;
break;
}
}
if (!$insert) {
$lines[] = "ALIASES: $old";
} else {
array_splice($lines, $insert, 0, "ALIASES: $old");
}
file_put_contents($file, implode($nl, $lines));
}
rename("$old.txt", "$new.txt") || exit(1);

View File

@ -0,0 +1,34 @@
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
/**
* @file
* Converts all instances of $config->set and $config->get to the new
* format, as described by docs/dev-config-bcbreaks.txt
*/
$FS = new FSTools();
chdir(dirname(__FILE__) . '/..');
$raw_files = $FS->globr('.', '*.php');
foreach ($raw_files as $file) {
$file = substr($file, 2); // rm leading './'
if (strpos($file, 'library/standalone/') === 0) continue;
if (strpos($file, 'maintenance/update-config.php') === 0) continue;
if (strpos($file, 'test-settings.php') === 0) continue;
if (substr_count($file, '.') > 1) continue; // rm meta files
// process the file
$contents = file_get_contents($file);
$contents = preg_replace(
"#config->(set|get)\('(.+?)', '(.+?)'#",
"config->\\1('\\2.\\3'",
$contents
);
if ($contents === '') continue;
file_put_contents($file, $contents);
}
// vim: et sw=4 sts=4