Release 1.6.1, merged in 931 to HEAD.
[htmlpurifier.git] / smoketests / printDefinition.php
blob2c66fa4e7248b3247c2b1b92e1b3b8c917b707fa
1 <?php
3 require_once 'common.php'; // load library
5 require_once 'HTMLPurifier/Printer/HTMLDefinition.php';
6 require_once 'HTMLPurifier/Printer/CSSDefinition.php';
8 $config = HTMLPurifier_Config::createDefault();
10 // you can do custom configuration!
11 if (file_exists('printDefinition.settings.php')) {
12 include 'printDefinition.settings.php';
15 $get = $_GET;
16 foreach ($_GET as $key => $value) {
17 if (!strncmp($key, 'Null_', 5) && !empty($value)) {
18 unset($get[substr($key, 5)]);
19 unset($get[$key]);
23 @$config->loadArray($get);
25 /* // sample local definition, obviously needs to be less clunky
26 $html_definition =& $config->getHTMLDefinition(true);
27 $module = new HTMLPurifier_HTMLModule();
28 $module->name = 'Marquee';
29 $module->info['marquee'] = new HTMLPurifier_ElementDef();
30 $module->info['marquee']->content_model = '#PCDATA | Inline';
31 $module->info['marquee']->content_model_type = 'optional';
32 $module->content_sets = array('Inline' => 'marquee');
33 $html_definition->manager->addModule($module);
36 $printer_html_definition = new HTMLPurifier_Printer_HTMLDefinition();
37 $printer_css_definition = new HTMLPurifier_Printer_CSSDefinition();
39 echo '<?xml version="1.0" encoding="UTF-8" ?>';
41 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
42 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
43 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
44 <head>
45 <title>HTML Purifier Printer Smoketest</title>
46 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
47 <style type="text/css">
48 form table {margin:1em auto;}
49 form th {text-align:right;padding-right:1em;}
50 form .c {display:none;}
51 .HTMLPurifier_Printer table {border-collapse:collapse;
52 border:1px solid #000; width:600px;
53 margin:1em auto;font-family:sans-serif;font-size:75%;}
54 .HTMLPurifier_Printer td, .HTMLPurifier_Printer th {padding:3px;
55 border:1px solid #000;background:#CCC; vertical-align: baseline;}
56 .HTMLPurifier_Printer th {text-align:left;background:#CCF;width:20%;}
57 .HTMLPurifier_Printer caption {font-size:1.5em; font-weight:bold;
58 width:100%;}
59 .HTMLPurifier_Printer .heavy {background:#99C;text-align:center;}
60 dt {font-weight:bold;}
61 </style>
62 <script type="text/javascript">
63 function toggleWriteability(id_of_patient, checked) {
64 document.getElementById(id_of_patient).disabled = checked;
66 </script>
67 </head>
68 <body>
70 <h1>HTML Purifier Printer Smoketest</h1>
72 <p>HTML Purifier claims to have a robust yet permissive whitelist: this
73 page will allow you to see precisely what HTML Purifier's internal
74 whitelist is. You can
75 also twiddle with the configuration settings to see how a directive
76 influences the internal workings of the definition objects.</p>
78 <h2>Modify configuration</h2>
80 <p>You can specify an array by typing in a comma-separated
81 list of items, HTML Purifier will take care of the rest (including
82 transformation into a real array list or a lookup table).</p>
84 <form id="edit-config" name="edit-config" method="get" action="printDefinition.php">
85 <table>
86 <?php
87 $directives = $config->getBatch('HTML');
88 // can't handle hashes
89 foreach ($directives as $key => $value) {
90 $directive = "HTML.$key";
91 if (is_array($value)) {
92 $keys = array_keys($value);
93 if ($keys === array_keys($keys)) {
94 $value = implode(',', $keys);
95 } else {
96 $new_value = '';
97 foreach ($value as $name => $bool) {
98 if ($bool !== true) continue;
99 $new_value .= "$name,";
101 $value = rtrim($new_value, ',');
104 $allow_null = $config->def->info['HTML'][$key]->allow_null;
106 <tr>
107 <th>
108 <a href="http://htmlpurifier.org/live/configdoc/plain.html#<?php echo $directive ?>">
109 <label for="<?php echo $directive; ?>">%<?php echo $directive; ?></label>
110 </a>
111 </th>
112 <?php if (is_bool($value)) { ?>
113 <td id="<?php echo $directive; ?>">
114 <label for="Yes_<?php echo $directive; ?>"><span class="c">%<?php echo $directive; ?>:</span> Yes</label>
115 <input type="radio" name="<?php echo $directive; ?>" id="Yes_<?php echo $directive; ?>" value="1"<?php if ($value) { ?> checked="checked"<?php } ?> /> &nbsp;
116 <label for="No_<?php echo $directive; ?>"><span class="c">%<?php echo $directive; ?>:</span> No</label>
117 <input type="radio" name="<?php echo $directive; ?>" id="No_<?php echo $directive; ?>" value="0"<?php if (!$value) { ?> checked="checked"<?php } ?> />
118 <?php } else { ?>
119 <td>
120 <?php if($allow_null) { ?>
121 <label for="Null_<?php echo $directive; ?>"><span class="c">%<?php echo $directive; ?>:</span> Null/Disabled*</label>
122 <input
123 type="checkbox"
124 value="1"
125 onclick="toggleWriteability('<?php echo $directive ?>',checked)"
126 name="Null_<?php echo $directive; ?>"
127 id="Null_<?php echo $directive; ?>"
128 <?php if ($value === null) { ?> checked="checked"<?php } ?>
129 /> or <br />
130 <?php } ?>
131 <input
132 type="text"
133 name="<?php echo $directive; ?>"
134 id="<?php echo $directive; ?>"
135 value="<?php echo escapeHTML($value); ?>"
136 <?php if($value === null) {echo 'disabled="disabled"';} ?>
138 <?php } ?>
139 </td>
140 </tr>
141 <?php
144 <tr>
145 <td colspan="2" style="text-align:right;">
146 [<a href="printDefinition.php">Reset</a>]
147 <input type="submit" value="Submit" />
148 </td>
149 </tr>
150 </table>
151 <p>* Some configuration directives make a distinction between an empty
152 variable and a null variable. A whitelist, for example, will take an
153 empty array as meaning <em>no</em> allowed elements, while checking
154 Null/Disabled will mean that user whitelisting functionality is disabled.</p>
155 </form>
157 <h2>Definitions</h2>
159 <dl>
160 <dt>Parent of Fragment</dt>
161 <dd>HTML that HTML Purifier does not live in a void: when it's
162 output, it has to be placed in another element by means of
163 something like <code>&lt;element&gt; &lt;?php echo $html
164 ?&gt; &lt;/element&gt;</code>. The parent in this example
165 is <code>element</code>.</dd>
166 <dt>Strict mode</dt>
167 <dd>Whether or not HTML Purifier's output is Transitional or
168 Strict compliant. Non-strict mode still actually a little strict
169 and converts many deprecated elements.</dd>
170 <dt>#PCDATA</dt>
171 <dd>Literally <strong>Parsed Character Data</strong>, it is regular
172 text. Tags like <code>ul</code> don't allow text in them, so
173 #PCDATA is missing.</dd>
174 <dt>Tag transform</dt>
175 <dd>A tag transform will change one tag to another. Example: <code>font</code>
176 turns into a <code>span</code> tag with appropriate CSS.</dd>
177 <dt>Attr Transform</dt>
178 <dd>An attribute transform changes a group of attributes based on one
179 another. Currently, only <code>lang</code> and <code>xml:lang</code>
180 use this hook, to synchronize each other's values. Pre/Post indicates
181 whether or not the transform is done before/after validation.</dd>
182 <dt>Excludes</dt>
183 <dd>Tags that an element excludes are excluded for all descendants of
184 that element, and not just the children of them.</dd>
185 <dt>Name(Param1, Param2)</dt>
186 <dd>Represents an internal data-structure. You'll have to check out
187 the corresponding classes in HTML Purifier to find out more.</dd>
188 </dl>
190 <h2>HTMLDefinition</h2>
191 <?php echo $printer_html_definition->render($config) ?>
192 <h2>CSSDefinition</h2>
193 <?php echo $printer_css_definition->render($config) ?>
194 </body>
195 </html>