mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-27 07:44:31 +02:00
Release 2.0.0, merged in 1026 to HEAD.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/strict@1179 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -29,6 +29,7 @@ while (false !== ($filename = readdir($dh))) {
|
||||
if (strpos($filename, '.php') === false) continue;
|
||||
if ($filename == 'common.php') continue;
|
||||
if ($filename == 'all.php') continue;
|
||||
if ($filename == 'testSchema.php') continue;
|
||||
?>
|
||||
<iframe src="<?php echo escapeHTML($filename); ?>"></iframe>
|
||||
<?php
|
||||
|
@@ -42,6 +42,7 @@ $xml = simplexml_load_file('attrTransform.xml');
|
||||
|
||||
// attr transform enabled HTML Purifier
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->set('HTML', 'Doctype', 'XHTML 1.0 Strict');
|
||||
$purifier = new HTMLPurifier($config);
|
||||
|
||||
$title = isset($_GET['title']) ? $_GET['title'] : true;
|
||||
|
77
smoketests/configForm.php
Normal file
77
smoketests/configForm.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
require_once 'common.php';
|
||||
|
||||
if (isset($_GET['doc'])) {
|
||||
|
||||
if (
|
||||
file_exists('testSchema.html') &&
|
||||
filemtime('testSchema.php') < filemtime('testSchema.html') &&
|
||||
!isset($_GET['purge'])
|
||||
) {
|
||||
echo file_get_contents('testSchema.html');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (version_compare('5', PHP_VERSION, '>')) exit('Requires PHP 5 or higher.');
|
||||
|
||||
// setup schema for parsing
|
||||
require_once 'testSchema.php';
|
||||
$new_schema = $custom_schema; // dereference the reference
|
||||
HTMLPurifier_ConfigSchema::instance($old); // restore old version
|
||||
|
||||
// setup ConfigDoc environment
|
||||
require_once '../configdoc/library/ConfigDoc.auto.php';
|
||||
|
||||
// perform the ConfigDoc generation
|
||||
$configdoc = new ConfigDoc();
|
||||
$html = $configdoc->generate($new_schema, 'plain', array(
|
||||
'css' => '../configdoc/styles/plain.css',
|
||||
'title' => 'Sample Configuration Documentation'
|
||||
));
|
||||
$configdoc->cleanup();
|
||||
|
||||
file_put_contents('testSchema.html', $html);
|
||||
echo $html;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
?><!DOCTYPE html
|
||||
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>HTML Purifier Config Form Smoketest</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<link rel="stylesheet" href="../library/HTMLPurifier/Printer/ConfigForm.css" type="text/css" />
|
||||
<script defer="defer" type="text/javascript" src="../library/HTMLPurifier/Printer/ConfigForm.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>HTML Purifier Config Form Smoketest</h1>
|
||||
<p>This file outputs the configuration form for every single type
|
||||
of directive possible.</p>
|
||||
<form id="htmlpurifier-config" name="htmlpurifier-config" method="get" action=""
|
||||
style="float:right;">
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/Printer/ConfigForm.php';
|
||||
|
||||
// fictional set, attempts to cover every possible data-type
|
||||
// see source at ConfigTest.php
|
||||
require_once 'testSchema.php';
|
||||
|
||||
// cleanup ( this should be rolled into Config )
|
||||
$config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config');
|
||||
$printer = new HTMLPurifier_Printer_ConfigForm('config', '?doc#%s');
|
||||
echo $printer->render($config);
|
||||
|
||||
?>
|
||||
</form>
|
||||
<pre>
|
||||
<?php
|
||||
print_r($config->getAll());
|
||||
?>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@@ -4,24 +4,15 @@ require_once 'common.php'; // load library
|
||||
|
||||
require_once 'HTMLPurifier/Printer/HTMLDefinition.php';
|
||||
require_once 'HTMLPurifier/Printer/CSSDefinition.php';
|
||||
require_once 'HTMLPurifier/Printer/ConfigForm.php';
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config');
|
||||
|
||||
// you can do custom configuration!
|
||||
if (file_exists('printDefinition.settings.php')) {
|
||||
include 'printDefinition.settings.php';
|
||||
}
|
||||
|
||||
$get = $_GET;
|
||||
foreach ($_GET as $key => $value) {
|
||||
if (!strncmp($key, 'Null_', 5) && !empty($value)) {
|
||||
unset($get[substr($key, 5)]);
|
||||
unset($get[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
@$config->loadArray($get);
|
||||
|
||||
/* // sample local definition, obviously needs to be less clunky
|
||||
$html_definition =& $config->getHTMLDefinition(true);
|
||||
$module = new HTMLPurifier_HTMLModule();
|
||||
@@ -36,6 +27,11 @@ $html_definition->manager->addModule($module);
|
||||
$printer_html_definition = new HTMLPurifier_Printer_HTMLDefinition();
|
||||
$printer_css_definition = new HTMLPurifier_Printer_CSSDefinition();
|
||||
|
||||
$printer_config_form = new HTMLPurifier_Printer_ConfigForm(
|
||||
'config',
|
||||
'http://htmlpurifier.org/live/configdoc/plain.html#%s'
|
||||
);
|
||||
|
||||
echo '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
@@ -45,9 +41,7 @@ echo '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
<title>HTML Purifier Printer Smoketest</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<style type="text/css">
|
||||
form table {margin:1em auto;}
|
||||
form th {text-align:right;padding-right:1em;}
|
||||
form .c {display:none;}
|
||||
.hp-config {margin-left:auto; margin-right:auto;}
|
||||
.HTMLPurifier_Printer table {border-collapse:collapse;
|
||||
border:1px solid #000; width:600px;
|
||||
margin:1em auto;font-family:sans-serif;font-size:75%;}
|
||||
@@ -59,11 +53,8 @@ echo '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
.HTMLPurifier_Printer .heavy {background:#99C;text-align:center;}
|
||||
dt {font-weight:bold;}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
function toggleWriteability(id_of_patient, checked) {
|
||||
document.getElementById(id_of_patient).disabled = checked;
|
||||
}
|
||||
</script>
|
||||
<link rel="stylesheet" href="../library/HTMLPurifier/Printer/ConfigForm.css" type="text/css" />
|
||||
<script defer="defer" type="text/javascript" src="../library/HTMLPurifier/Printer/ConfigForm.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -81,73 +72,10 @@ influences the internal workings of the definition objects.</p>
|
||||
list of items, HTML Purifier will take care of the rest (including
|
||||
transformation into a real array list or a lookup table).</p>
|
||||
|
||||
<form id="edit-config" name="edit-config" method="get" action="printDefinition.php">
|
||||
<table>
|
||||
<form method="get" action="" name="hp-configform">
|
||||
<?php
|
||||
$directives = $config->getBatch('HTML');
|
||||
// can't handle hashes
|
||||
foreach ($directives as $key => $value) {
|
||||
$directive = "HTML.$key";
|
||||
if (is_array($value)) {
|
||||
$keys = array_keys($value);
|
||||
if ($keys === array_keys($keys)) {
|
||||
$value = implode(',', $keys);
|
||||
} else {
|
||||
$new_value = '';
|
||||
foreach ($value as $name => $bool) {
|
||||
if ($bool !== true) continue;
|
||||
$new_value .= "$name,";
|
||||
}
|
||||
$value = rtrim($new_value, ',');
|
||||
}
|
||||
}
|
||||
$allow_null = $config->def->info['HTML'][$key]->allow_null;
|
||||
echo $printer_config_form->render($config, 'HTML');
|
||||
?>
|
||||
<tr>
|
||||
<th>
|
||||
<a href="http://htmlpurifier.org/live/configdoc/plain.html#<?php echo $directive ?>">
|
||||
<label for="<?php echo $directive; ?>">%<?php echo $directive; ?></label>
|
||||
</a>
|
||||
</th>
|
||||
<?php if (is_bool($value)) { ?>
|
||||
<td id="<?php echo $directive; ?>">
|
||||
<label for="Yes_<?php echo $directive; ?>"><span class="c">%<?php echo $directive; ?>:</span> Yes</label>
|
||||
<input type="radio" name="<?php echo $directive; ?>" id="Yes_<?php echo $directive; ?>" value="1"<?php if ($value) { ?> checked="checked"<?php } ?> />
|
||||
<label for="No_<?php echo $directive; ?>"><span class="c">%<?php echo $directive; ?>:</span> No</label>
|
||||
<input type="radio" name="<?php echo $directive; ?>" id="No_<?php echo $directive; ?>" value="0"<?php if (!$value) { ?> checked="checked"<?php } ?> />
|
||||
<?php } else { ?>
|
||||
<td>
|
||||
<?php if($allow_null) { ?>
|
||||
<label for="Null_<?php echo $directive; ?>"><span class="c">%<?php echo $directive; ?>:</span> Null/Disabled*</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
value="1"
|
||||
onclick="toggleWriteability('<?php echo $directive ?>',checked)"
|
||||
name="Null_<?php echo $directive; ?>"
|
||||
id="Null_<?php echo $directive; ?>"
|
||||
<?php if ($value === null) { ?> checked="checked"<?php } ?>
|
||||
/> or <br />
|
||||
<?php } ?>
|
||||
<input
|
||||
type="text"
|
||||
name="<?php echo $directive; ?>"
|
||||
id="<?php echo $directive; ?>"
|
||||
value="<?php echo escapeHTML($value); ?>"
|
||||
<?php if($value === null) {echo 'disabled="disabled"';} ?>
|
||||
/>
|
||||
<?php } ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="2" style="text-align:right;">
|
||||
[<a href="printDefinition.php">Reset</a>]
|
||||
<input type="submit" value="Submit" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>* Some configuration directives make a distinction between an empty
|
||||
variable and a null variable. A whitelist, for example, will take an
|
||||
empty array as meaning <em>no</em> allowed elements, while checking
|
||||
|
44
smoketests/testSchema.php
Normal file
44
smoketests/testSchema.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
// overload default configuration schema temporarily
|
||||
$custom_schema = new HTMLPurifier_ConfigSchema();
|
||||
$old = HTMLPurifier_ConfigSchema::instance();
|
||||
$custom_schema =& HTMLPurifier_ConfigSchema::instance($custom_schema);
|
||||
|
||||
if (!class_exists('CS')) {
|
||||
class CS extends HTMLPurifier_ConfigSchema {}
|
||||
}
|
||||
|
||||
CS::defineNamespace('Element', 'Chemical substances that cannot be further decomposed');
|
||||
|
||||
CS::define('Element', 'Abbr', 'H', 'string', 'Abbreviation of element name.');
|
||||
CS::define('Element', 'Name', 'hydrogen', 'istring', 'Full name of atoms.');
|
||||
CS::define('Element', 'Number', 1, 'int', 'Atomic number, is identity.');
|
||||
CS::define('Element', 'Mass', 1.00794, 'float', 'Atomic mass.');
|
||||
CS::define('Element', 'Radioactive', false, 'bool', 'Does it have rapid decay?');
|
||||
CS::define('Element', 'Isotopes', array('1' => true, '2' => true, '3' => true), 'lookup',
|
||||
'What numbers of neutrons for this element have been observed?');
|
||||
CS::define('Element', 'Traits', array('nonmetallic', 'odorless', 'flammable'), 'list',
|
||||
'What are general properties of the element?');
|
||||
CS::define('Element', 'IsotopeNames', array('1' => 'protium', '2' => 'deuterium', '3' => 'tritium'), 'hash',
|
||||
'Lookup hash of neutron counts to formal names.');
|
||||
|
||||
CS::defineNamespace('Instrument', 'Of the musical type.');
|
||||
|
||||
CS::define('Instrument', 'Manufacturer', 'Yamaha', 'string', 'Who made it?');
|
||||
CS::defineAllowedValues('Instrument', 'Manufacturer', array(
|
||||
'Yamaha', 'Conn-Selmer', 'Vandoren', 'Laubin', 'Buffet', 'other'));
|
||||
CS::defineValueAliases('Instrument', 'Manufacturer', array(
|
||||
'Selmer' => 'Conn-Selmer'));
|
||||
|
||||
CS::define('Instrument', 'Family', 'woodwind', 'istring', 'What family is it?');
|
||||
CS::defineAllowedValues('Instrument', 'Family', array(
|
||||
'brass', 'woodwind', 'percussion', 'string', 'keyboard', 'electronic'));
|
||||
CS::defineValueAliases('Instrument', 'Family', array(
|
||||
'synth' => 'electronic'));
|
||||
|
||||
CS::defineNamespace('ReportCard', 'It is for grades.');
|
||||
CS::define('ReportCard', 'English', null, 'string/null', 'Grade from English class.');
|
||||
CS::define('ReportCard', 'Absences', 0, 'int', 'How many times missing from school?');
|
||||
|
||||
?>
|
Reference in New Issue
Block a user