Add fragment processing. This will temporarily fix our PHP template inclusion woes.
[xhtml-compiler.git] / XHTMLCompiler / DOMFilter / AbsolutePath.php
blobb62ca1b7a2a28156a37205666cc5a684b9907c89
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]");
26 foreach ($nodes as $node) {
27 $attribute = $this->confiscateAttr($node, $this->ns, 'absolute');
28 if ($attribute) {
29 // $attribute is the name of the attribute to convert
30 // to absolute form, we can extend the syntax to allow
31 // multiple attributes.
32 $uri = $node->getAttribute($attribute);
33 // special cases
34 if ($uri == '.' && $prefix) $uri = '';
35 $node->setAttribute($attribute, $prefix . $uri);