4 * Extracts metadata from XHTMLCompiler_Page (which comes the version
5 * control system) and inserts it in the HTML page.
7 class XHTMLCompiler_DOMFilter_Metadata
extends XHTMLCompiler_DOMFilter
{
9 protected $name = 'Metadata';
11 public function process(DOMDocument
$dom, $page, $manager) {
13 $head = $dom->getElementsByTagName('head')->item(0);
15 $manager->addDependency(__FILE__
);
17 $date = $page->getCreatedTime();
18 // check if the meta element already exists
19 $meta = $dom->createElement('meta');
21 foreach ($head->getElementsByTagName('meta') as $node) {
22 if ($node->getAttribute('name') == 'Date') {
23 // it exists: use this date as the "real" date.
25 if ($t = $meta->getAttribute('content')) {
26 // this code is slightly redundant since getCreatedTime()
27 // will have already accounted for this. Still, can't hurt.
28 $date = new DateTime($t);
34 // only write if we have a valid date
36 $meta->setAttribute('name', 'Date');
37 $meta->setAttribute('content', $date->format('c'));
38 if ($append) $head->appendChild($meta);