mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-16 11:03:58 +02:00
[1.7.0] Create ConfigForm printer classes
- Extend hash to convert strings from form key,value,key,value - Hack up configdoc to accommodate configForm.php smoketest git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1101 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
|
||||
|
66
smoketests/configForm.php
Normal file
66
smoketests/configForm.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
require_once 'common.php';
|
||||
|
||||
if (isset($_GET['doc'])) {
|
||||
require_once 'testSchema.php';
|
||||
$new_schema = $custom_schema;
|
||||
HTMLPurifier_ConfigSchema::instance($old);
|
||||
define('HTMLPURIFIER_CUSTOM_SCHEMA', 'new_schema');
|
||||
define('HTMLPURIFIER_SCRIPT_LOCATION', '../configdoc/');
|
||||
require_once '../configdoc/generate.php';
|
||||
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 )
|
||||
$get = isset($_GET) ? $_GET : array();
|
||||
$mq = get_magic_quotes_gpc();
|
||||
foreach ($_GET as $key => $value) {
|
||||
if (!strncmp($key, 'Null_', 5) && !empty($value)) {
|
||||
unset($get[substr($key, 5)]);
|
||||
unset($get[$key]);
|
||||
}
|
||||
if ($mq) $get[$key] = stripslashes($value);
|
||||
}
|
||||
$config = @HTMLPurifier_Config::create($get);
|
||||
|
||||
$printer = new HTMLPurifier_Printer_ConfigForm('?doc');
|
||||
echo $printer->render($config);
|
||||
|
||||
?>
|
||||
<div style="text-align:right;">
|
||||
<input type="submit" value="Submit" />
|
||||
[<a href="?">Reset</a>]
|
||||
</div>
|
||||
</form>
|
||||
<pre>
|
||||
<?php
|
||||
print_r($config->getAll());
|
||||
?>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
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