Hey Guys,
Got myself the photo gallery component from the guys at flash relief (advertised on the front of kirupa.)
And decided to use a dynamic XML file to provide the content.
Using a PHP include (credited in my script) i wrote the following:
<?php
include("functions.php");//includes db connection etc
// Simon Willison, 16th April 2003
// Based on Lars Marius Garshol's Python XMLWriter class
// See http://www.xml.com/pub/a/2003/04/09/py-xml.html
class XmlWriter {
var $xml;
var $indent;
var $stack = array();
function XmlWriter($indent = ' ') {
$this->indent = $indent;
/*$this->xml = '<?xml version="1.0" encoding="utf-8"?>'."
";*/
}
function _indent() {
for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
$this->xml .= $this->indent;
}
}
function push($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= ">
";
$this->stack[] = $element;
}
function element($element, $content, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= '>'.htmlentities($content).'</'.$element.'>'."
";
}
function emptyelement($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= " />
";
}
function pop() {
$element = array_pop($this->stack);
$this->_indent();
$this->xml .= "</$element>
";
}
function getXml() {
return $this->xml;
}
}
$xml = new XmlWriter();
$sql = "SELECT * FROM gallery";
$query = mysql_query($sql);
//echo $result['caption'];
$xml->push('gallery');
$xml->emptyelement('setup path="gallery/"');
while ($result = mysql_fetch_array($query)) {
$xml->push('item');
$xml->element('thumb', $result[1]);
$xml->element('img', $result[0]);
$xml->element('caption', $result[2]);
$xml->pop();
}
$xml->pop();
header("Content-Type: application/xml; charset=ISO-8859-1");
print $xml->getXml();
?>
In a browser this out puts just fine …prooducing infact identical markup to the static file:
−
<gallery>
<setup path=“gallery/”/>
−
<item>
<thumb>tWinter.jpg</thumb>
<img>Winter.jpg</img>
<caption>Photo Caption</caption>
</item>
−
<item>
<thumb>tWater lilies.jpg</thumb>
<img>Water lilies.jpg</img>
<caption>Photo Caption</caption>
</item>
−
<item>
<thumb>tSunset.jpg</thumb>
<img>Sunset.jpg</img>
<caption>Photo Caption</caption>
</item>
−
<item>
<thumb>tBlue hills.jpg</thumb>
<img>Blue hills.jpg</img>
<caption>Photo Caption</caption>
</item>
</gallery>
I can only assume that the gallery component isnt recognising the script because of its .php extention.
Is there any way to have an XML extention?
Thansk for your help …if I can crack this ill also be making public a script to up load an image, resize it, provide the thumbnail and …if i can get it to work…produce this dynamic xml file!
Zaid