All pastes #110733 Raw Edit

Mine

public php v1 · immutable
·published 2006-08-01 21:38 UTC
rendered paste body
#class/xsl.php<?phpclass xsl{  function xsl(){    $this->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<?phprequire("../inc/config.php");require("../inc/mysql.php");require("class/yaml.php");class Query{  var $table_list;  var $datamap;  function datamap(){    if(file_exists("inc/datamap.php")){      require("inc/datamap.php");      $datamap = new Datamap;    }    else{      $this->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 .= "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";    $ret .= "<entries>\n";    while($f = mysql_fetch_array($g)){      $ret .= "<entry>\n";      for($i = 0; $i < count($a["fields"]); $i++){        $ret .= "\t<".$a["fields"][$i].">".$f[$i]."</".$a["fields"][$i].">\n";      }      $ret .= "</entry>\n";    }    $ret .= "</entries>\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<?phpecho $GLOBALS["query"]->exec(array(      'source' => 'news',      'fields' => array("id", "headline")      ));/*<?xml version="1.0" encoding="ISO-8859-1"?><entries><entry>	<id>4</id>	<headline>Tux magasine 15</headline></entry><entry>	<id>3</id>	<headline>Foobar dsa dsa</headline></entry><entry>	<id>2</id>	<headline>foof</headline></entry><entry>	<id>1</id>	<headline>New page</headline></entry></entries>*/?>#nyheder.xsl<?xml version="1.0" encoding="ISO-8859-15"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  <xsl:template match="/entries" name="fpp">    <xsl:for-each select="entry">      <xsl:value-of select="id" />    </xsl:for-each>  </xsl:template></xsl:stylesheet>#index.php<?phprequire("../inc/config.php");require("../inc/mysql.php");#require("inc/flash.php");#require("class/user_preferences.php");require("class/xsl.php");require("query.php");$xsl = new xsl;$query = new query();$yaml = new Spyc;$user->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;?>