Topic: Replacing gallery.xml file with PHP code

A chap over at the 4homepages de forum detailed a mod to the xmlURL changing it to call some PHP code that generated the XML code that was streamed back directly. It wasn't written to a file.  Has anybody got this to work? I haven't even though the xml is being generated ok. The topic title on the 4homepages forum is '[MOD] TiltViewer for 4images'.


Re: Replacing gallery.xml file with PHP code

Here's a TiltViewer gallery using PHP to generate an XML file.
[Test gallery removed by original poster.]

Use the code:

fo.addVariable("xmlURL", "gallery.php");

... and instead of a traditional 'gallery.xml' file, create a file called 'gallery.php' containing the following code:

function GetDirArray($folder)
    while ($file=readdir($handle))
        if ($file!="." && $file!="..")
    return $ret;
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<tiltviewergallery>';
echo '<photos>';
for ($i=0; $i<sizeof($gallery); $i++)
    echo '<photo imageurl="images/'.$gallery[$i].'">';
    echo '<title></title>';
    echo '<description></description>';
    echo '</photo>';
echo '</photos>';
echo '</tiltviewergallery>';

The images for my gallery above are in a folder called 'slides'.
There are two references to this folder in the PHP code which you might have to change.

Steven Speirs
SimpleViewer Support Team

Re: Replacing gallery.xml file with PHP code

Thanks for the response, monkeyboy, I've tried that and it works fine. The trouble I have, however, is when I add title and description data it stops working. I used CDATA to accommodate special characters but that made no difference. Here's the strange thing, though, if I save the xml to the file gallery.xml and use that as the xmlURL, it works fine...

This is my code:

$xmlcode = '<?xml version="1.0" encoding="UTF-8"?>'; 
  $xmlcode .= "<tiltviewergallery>";
  $xmlcode .= "<photos>";

  while ($image_row = tep_db_fetch_array($products_query)) {

       $xmlcode .= '<photo imageurl="images/' . $image_row&['products_image'] . '" linkurl="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $image_row['products_id']) . '">';
       $xmlcode .= "<title><![[CDATA[" . $image_row['products_name'] . "]]></title>";
       $xmlcode .= "<description><![CDATA[" . $image_row['products_description'] . "<br><br>" . $currencies->format($image_row['products_price']0  . "]]></description>";
       $xmlcode .= "</photo>";

  } // end while
  $xmlcode .= "</photos>";
  $xmlcode .= "</tiltviewergallery>";
  echo $xmlcode;

If I dump the contents of $xmlcode and put it into gallery.xml manually, it works. I'm just wondering if there are any special characters in the data that get lost when written to a file but break the direct data stream...


Re: Replacing gallery.xml file with PHP code

are you using UTF-8 encoding on the XML output?

Felix Turner
SimpleViewer Support Team.

Re: Replacing gallery.xml file with PHP code

Yes, I specified that in the first line of my code:

  $xmlcode = '<?xml version="1.0" encoding="UTF-8"?>'

6 (edited by godyn 2009-08-04 11:19:28)

Re: Replacing gallery.xml file with PHP code

I got it working :-)
Now, I would like to have it random ;-)

Re: Replacing gallery.xml file with PHP code

Yeah.. How do I get this thing to do random!?

Re: Replacing gallery.xml file with PHP code

I did like this long time back. But don't remember exactly. But I had taken help from one book named "PHP in Nutshell"...perhaps ch - 9 explains about how to do it random.
You can easily find this O'Rellay book. Just need to do google.

Re: Replacing gallery.xml file with PHP code

This is not working for me... Please help.  I tried a lot of options.

Re: Replacing gallery.xml file with PHP code

Hello, here a little PHP script that reads the content of the actual directory and save the xml file gallery.xml with all the needed code. Whith this all you have to do is upload your images into the directory.

$dir_nom = '.'; // list of actual directory 
$dir = opendir($dir_nom); // opens directory
$fichier= array(); // declaration of table who contents file names

while($element = readdir($dir)) {
    if($element != '.' && $element != '..') {
        if (!is_dir($dir_nom.'/'.$element)) {$fichier[] = $element;}
        else {$dossier[] = $element;}


$fp = fopen("gallery.xml",a);//Opens xml file 
//fwrite($fp,"<tiltviewergallery>\n    <photos>\n");// write first lines of xml file
    rsort($fichier);// ... becomes sort() if you want
    foreach($fichier as $lien) {
    if (strlen(strstr($lien,".jpg"))>0) {//writes file if it is an image.. else go the the next one
         //fwrite($fp,"        <photo imageurl='imgs/$lien' linkurl=''>\n<title>Photo $lien</title>\n<description>album photo</description>\n</photo>\n");
//fwrite($fp,"</photos>\n </tiltviewergallery>\n";//writes 2 last lines of xml file