4 * Based on a list of known acronyms, populates of the title attribute
5 * of acronym elements in documents.
7 class XHTMLCompiler_DOMFilter_Acronymizer
extends XHTMLCompiler_DOMFilter
10 protected $name = 'Acronymizer';
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) {
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)');
40 $node->setAttribute('title', $this->acronyms
[$acronym]);