#class/xsl.php xml = new DOMDocument; $this->xsl = new DOMDocument; $this->proc = new XSLTProcessor; } function parse($xmlFile, $xslFile = ""){ if(!$xslFile){ $tmp = "templates/".$GLOBALS["user"]->preferences->template."/xsl/".str_replace(array(".php", ".xml"), ".xsl", $xmlFile); if(file_exists($tmp)){ $xslFile = $tmp; } elseif(file_exists("xsl/".str_replace(array(".php", ".xml"), ".xsl", $xmlFile))){ $xslFile = "xsl/".str_replace(array(".php", ".xml"), ".xsl", $xmlFile); } else{ echo "xsl/".str_replace(array(".php", ".xml"), ".xsl", $xmlFile); } } ob_start(); require($xmlFile); $xml = ob_get_contents(); ob_end_clean(); $this->xml->loadXML($xml); $this->xsl->load($xslFile); $this->proc->importStyleSheet($this->xsl); return $this->proc->transformToXML($this->xml); } } ?> #query.php datamap = Spyc::YAMLLoad("inc/datamap.yml"); } } function mysql2xml($a){ if(!$a["fields"]){ $a["fields"] = array_keys($this->table_list["linuxin"][ $a["source"] ]); } $q = ''; $q = 'SELECT '; if($a["fields"]){ for($i = 0; $i < count($a["fields"]); $i++){ $q .= $a["fields"][$i]; if($i < (count($a["fields"]) -1)){ $q .= ', '; } else{ $q .= ' '; } } } else{ $q .= '* '; } $q .= 'FROM '; $q .= $a["source"]." "; if($a["order"]){ $q .= "ORDER BY ".$a["order"]." "; } else{ $q .= "ORDER BY id "; } if(!$a["asc"]){ $q .= "DESC "; } if($a["entries"]){ } $g = mysql_query($q); $ret .= "\n"; $ret .= "\n"; while($f = mysql_fetch_array($g)){ $ret .= "\n"; for($i = 0; $i < count($a["fields"]); $i++){ $ret .= "\t<".$a["fields"][$i].">".$f[$i]."\n"; } $ret .= "\n"; } $ret .= "\n"; echo $ret; return $ret; } function exec($a){ $this->datamap(); $this->table_list = Spyc::YAMLLoad("db.yml"); if(!$a["source"]){ die("No source"); } switch($this->datamap[ $a["source"] ]["type"]){ case "mysql": $this->mysql2xml($a); break; case "xml": $this->getxml($a); break; } if(!$a){ die("Query without a query (DOH!)"); } } } ?> #sections/nyheder/nyheder.php exec(array( 'source' => 'news', 'fields' => array("id", "headline") )); /* 4 Tux magasine 15 3 Foobar dsa dsa 2 foof 1 New page */ ?> #nyheder.xsl #index.php preferences->template = "default"; $url = explode("/", $_GET["url"]); echo $xsl->parse("sections/nyheder/news.php"); if($_GET["action"] && file_exists("action/".$_GET["action"].".php")){ require("action/".$_GET["action"].".php"); } $xsl = new xsl; ?>