lib/PageTransform.class.php

Go to the documentation of this file.
00001 <?php
00008 class PageTransform {
00009   public static function buildIfNeeded($target, $xslt, $xml = 'index.xml') {
00010     $obj = new self($target, $xslt, $xml);
00011     if ($obj->needUpdate())
00012       $obj->buildTarget();
00013   }
00014   // Avoid class instantiation
00015   private function __construct($target, $xslt, $xml) {
00016     $config = Config::instance();
00017     $this->pageDir_ = $config->documentRoot().$config->pageDir();
00018     $this->target_ = $target;
00019     $this->xslt_ = $xslt;
00020     $this->xml_ = $xml;
00021   }
00022   private $pageDir_;
00023   private $target_;
00024   private $xslt_;
00025   private $xml_;
00026   private function needUpdate() {
00027     if (!file_exists($this->target_))
00028       return true;
00029     
00030     $ts = filemtime($this->target_);
00031     if (filemtime($this->pageDir_)>$ts)
00032       return true;
00033     $fileList = scandir($this->pageDir_);
00034     array_shift($fileList);
00035     array_shift($fileList);
00036     foreach($fileList as $current)
00037       if (filemtime($this->pageDir_.'/'.$current)>$ts)
00038         return true;
00039     return false;
00040   }
00041   private function buildTarget() {
00042     // Load the XML source
00043     $xml = new DOMDocument;
00044     $xml->load($this->pageDir_.'/'.$this->xml_);
00045     $xsl = new DOMDocument;
00046     $xsl->load($this->pageDir_.'/'.$this->xslt_);
00047 
00048     // Configure the transformer
00049     $proc = new XSLTProcessor;
00050     $proc->importStyleSheet($xsl); // attach the xsl rules
00051 
00052     // Process XSLT and write to $this->target_
00053     $fd = fopen($this->target_, 'w');
00054     fwrite($fd, $proc->transformToXML($xml));
00055     fclose($fd);
00056   }
00057 };
00058 ?>

Generated on Sat Mar 8 10:26:43 2008 for Dudka.cz by  doxygen 1.5.4