Add Acronymizer DOMFilter. index.xhtml edited accordingly. <?xml declarations added...
[htmlpurifier-web.git] / xhtml-compiler / XHTMLCompiler / DOMFilter / Acronymizer.php
blob5a7ab79e4790ec8a662a4f5150cc6057ac8dab84
1 <?php
3 /**
4 * Based on a list of known acronyms, populates of the title attribute
5 * of acronym elements in documents.
6 */
7 class XHTMLCompiler_DOMFilter_Acronymizer extends XHTMLCompiler_DOMFilter
10 protected $name = 'Acronymizer';
12 /**
13 * Array of recognized acronyms.
14 * @todo Make a public API for this, allow multiple acronym sets
15 * and different precedences for them.
17 protected $acronyms = array(
18 'PHP' => 'PHP: HyperText Preprocessor',
19 'HTML' => 'HyperText Markup Language',
20 'XHTML' => 'eXtensible HyperText Markup Language',
21 'XSS' => 'Cross-Site Scripting',
22 'W3C' => 'World Wide Web Consortium',
23 'WYSIWYG' => 'What You See Is What You Get',
24 'WYSIWYM' => 'What You See Is What You Mean',
25 'PEAR' => 'PHP Extension and Application Repository',
26 'DTD' => 'Document Type Definition',
27 'XML' => 'eXtensible Markup Language',
28 'RFC' => 'Request for Comment',
31 public function process(DOMDocument $dom, $page) {
32 $this->setup($dom);
33 $nodes = $this->query("//html:acronym[not(@title)]");
34 foreach ($nodes as $node) {
35 $acronym = $node->textContent;
36 if (!isset($this->acronyms[$acronym])) {
37 trigger_error(htmlspecialchars($acronym) . ' is not a recognized acronym (missing title attribute)');
38 continue;
40 $node->setAttribute('title', $this->acronyms[$acronym]);