Have filters add self as dependencies, rm whitespace.
[xhtml-compiler.git] / XHTMLCompiler / DOMFilter / AbsolutePath.php
blobc247e3b2f3e5f7c9e7c60ecb9cfcedd907c8db5f
1 <?php
3 /**
4 * Implements the xc:absolute attribute, which allows links to be made
5 * relative to the XHTML Compiler configured document root (and not
6 * the absolute web root.) This greatly simplifies inter-directory linking
7 * and styling.
8 */
9 class XHTMLCompiler_DOMFilter_AbsolutePath extends XHTMLCompiler_DOMFilter
12 protected $name = 'AbsolutePath';
13 protected $xcAttr = array('absolute');
15 public function process(DOMDocument $dom, $page, $manager) {
17 // this is the absolute path implementation of the functionality
18 $xc = XHTMLCompiler::getInstance();
19 $prefix = $xc->getConf('web_path') . '/';
21 // this is the relative path implementation of the functionality
22 //$prefix = str_repeat('../', $page->getDepth());
24 $nodes = $this->query("//*[@xc:absolute]");
25 if ($nodes) $manager->addDependency(__FILE__);
27 foreach ($nodes as $node) {
28 $attribute = $this->confiscateAttr($node, $this->ns, 'absolute');
29 if ($attribute) {
30 // $attribute is the name of the attribute to convert
31 // to absolute form, we can extend the syntax to allow
32 // multiple attributes.
33 $uri = $node->getAttribute($attribute);
34 // special cases
35 if ($uri == '.' && $prefix) $uri = '';
36 $node->setAttribute($attribute, $prefix . $uri);