Added SVN to abbr list
[htmlpurifier-web.git] / xhtml-compiler / XHTMLCompiler / DOMFilter / Acronymizer.php
blobdf5c41cf56834c64e9e3700202f48a707ac56069
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 * Associative array of recognized abbreviations/initialisms
14 * @note To be used when each letter should be spelled out, such
15 * as HTML.
17 protected $abbreviations = array(
18 // markup languages and related technologies
19 'SGML' => 'Standard Generalized Markup Language',
20 'HTML' => 'HyperText Markup Language',
21 'XHTML' => 'Extensible HyperText Markup Language',
22 'XML' => 'Extensible Markup Language',
23 'RSS' => 'Really Simple Syndication',
24 'DTD' => 'Document Type Definition',
25 'CSS' => 'Cascading Style Sheets',
26 // programming/apis
27 'PHP' => 'PHP: HyperText Preprocessor',
28 'CMS' => 'Content Management System',
29 'API' => 'Application Programming Interface',
30 'SVN' => 'Subversion',
31 // web-app security
32 'XSS' => 'Cross-Site Scripting',
33 // organizations/groups
34 'W3C' => 'World Wide Web Consortium',
35 'RFC' => 'Request for Comment',
36 'PECL' => 'PHP Extension Community Library',
37 // character encodings
38 'UTF-8' => '8-bit Unicode Transformation Format',
39 // other
40 'INI' => 'Initialization',
41 'CPU' => 'Central Processing Unit',
42 'LGPL' => 'Lesser GNU Public License',
43 'URI' => 'Uniform Resource Identifier',
46 /**
47 * Array of recognized acronyms.
48 * @note Acronyms can be spoken literally, if in doubt, make it
49 * an abbreviation.
50 * @todo Make a public API for this, allow multiple acronym sets
51 * and different precedences for them.
53 protected $acronyms = array(
54 // programming
55 'SAX' => 'Simple API for XML',
56 'DOM' => 'Document Object Module',
57 'PEAR' => 'PHP Extension and Application Repository',
58 'ASCII' => 'American Standard Code for Information Interchange',
59 'SHA-1' => 'Secure Hash Algorithm',
60 // paradigms
61 'WYSIWYG' => 'What You See Is What You Get',
62 'WYSIWYM' => 'What You See Is What You Mean',
65 public function process(DOMDocument $dom, $page, $manager) {
66 $nodes = $this->query("//html:acronym[not(@title)]");
67 foreach ($nodes as $node) $this->addAdvisoryTitle($node, $this->acronyms);
69 $nodes = $this->query("//html:abbr[not(@title)]");
70 foreach ($nodes as $node) $this->addAdvisoryTitle($node, $this->abbreviations);
72 // add self as dependency; when acronym lists change, so does the page
73 $manager->addDependency(__FILE__);
76 protected function addAdvisoryTitle($node, $lookup) {
77 $key = $node->textContent;
78 if (!isset($lookup[$key])) {
79 // not fatal, but good to let the document author know
80 trigger_error(htmlspecialchars($key) .
81 ' is not a recognized acronym/abbreviation (missing title attribute)');
82 return;
84 $node->setAttribute('title', $lookup[$key]);