Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2007-09-23 05:04:20
- fhsieh
- New Member
- Registered: 2007-09-23
- Posts: 2
Generating Dynamic XML for Images
I was wonering if TXP can dynamically generate an XML file, with a customizable schema (perhaps using TXP Forms), to populate data from the Images table of TXP (specifically all images under a given Category).
What I’m looking to do is integrate TXP with SlideShowPro, for the following model:
-A single “Photos” TXP Section, which has one article containing an embedded flash (SSP, perhaps through kimili’s flashembed)
-A URL for creating dynamic XML (eg: http://mydomain.com/xml/?category=Photos), which follows SSP’s XML schema (I suppose this can be a TXP Section with a custom Page structure)
-A publisher would then upload a new Image in the TXP admin panel, and assign the category “Photos”
-During the next dynamic call of the XML, the new image would be reflected in the generated XML
In this way, SSP can maintain a dynamic image gallery, using TXP’s Image db/table as the core “CMS” for the images, and dynamic XML as the conduit—without having to impose extra steps of publishing or modifying articles, or heavy data-modeling on existing gallery plugins.
Apologies if it’s a little unclear, and thanks in advance!
Last edited by fhsieh (2007-09-23 05:05:03)
Offline
Re: Generating Dynamic XML for Images
It’s not really answering your question but maybe you should look at gallery plugins
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2007-09-23 07:28:58
- fhsieh
- New Member
- Registered: 2007-09-23
- Posts: 2
Re: Generating Dynamic XML for Images
The problem I’m facing with existing gallery plugins is that they output straight to pre-formatted X/HTML, without providing a direct way to shape the data into XML (which is what SSP needs). Of course, if necessary I may just deconstruct a plugin and rebuild it as a one-shot solution, but if there is a more straightforward solution which doesn’t involve me reinventing the wheel, I would very much prefer that.
Offline
Re: Generating Dynamic XML for Images
I’ve done something similar before but using articles – see this thread. Since I wrote that someone has made a plug-in for serving the right content-type for XML, though it worked fine for me without that. Here’s a further article on creating custom XML feeds.
You might also want to look at plug-ins that allow you to access and sort particular image attributes such as upm_image or robert’s wet_for_each_image or other wet_...
plug-ins (check textpattern resources for more).
If you get it working, please write it up. I’m sure it would interest many.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Generating Dynamic XML for Images
I drop a file into my textpattern directory called img.php and it outputs the xml I need. Here’s the code:
<?php
$txpcfg = array();
require_once('config.php');
$link = mysql_connect($txpcfg['host'], $txpcfg['user'], $txpcfg['pass']);
if(!is_resource($link))
{
echo "Unable to connect to the database!";
exit();
}
$connected = mysql_select_db($txpcfg['db'], $link);
if(!$connected)
{
echo "Unable to use the database '" . $default_dbname . "'!";
exit();
}
if(isset($_GET['s']))
{
$channel=addslashes($_GET['s']);
$q = "SELECT * FROM `txp_image` WHERE category='".$channel."'";
} else {
$channel="";
$q = "SELECT * FROM `txp_image` WHERE category='".$channel."'";
}
$results = mysql_query($q);
echo '<?xml version="1.0" encoding="utf-8"?>
<'.$channel.'>
';
if(mysql_num_rows($results)>0)
{
while($row = mysql_fetch_row($results))
{
echo '<item><title>'.$row[1].'</title><caption>'.$row[7].'</caption><img>http://yourdomain.com/image/'.$row[0].$row[3].'</img><width>'.$row[4].'</width><height>'.$row[5].'</height></item>
';
}
}
echo '</'.$channel.'>';
?>
I have used this method
to enable the easy building of flash image galleries.
Offline
Re: Generating Dynamic XML for Images
You could skip some if’s in the code if you want to tidy up the code a bit.
Ex:
$link = mysql_connect($txpcfg['host'], $txpcfg['user'], $txpcfg['pass']);
if(!is_resource($link))
{
echo "Unable to connect to the database!";
exit();
}
$connected = mysql_select_db($txpcfg['db'], $link);
if(!$connected)
{
echo "Unable to use the database '" . $default_dbname . "'!";
exit();
}
Becomes:
$link = mysql_connect($txpcfg['host'], $txpcfg['user'], $txpcfg['pass']) or die( "Unable to connect to the database!" );
$connected = mysql_select_db($txpcfg['db'], $link) or die( "Unable to use the database $default_dbname!" );
die does the same as exit so if you don’t want it to sound so harsh, change the dies to exits.
Plugins:
ob1_advanced_search 1.032b, ob1_search_score 1.0, ob1_pagination 2.5, ob1_title 4.1, ob1_modified 2.1
“Let your plans be dark and as impenetratable as night, and when you move, fall like a thunderbolt.”
— Sun Tzu
Offline
Re: Generating Dynamic XML for Images
dude…you did nothing to help this guy and everything to critique a secondary portion of my code…..the fucking sql connection.
die.
Offline
Re: Generating Dynamic XML for Images
?!
What’s with the language? I like tidy code. Your solution was a good one, just wanted to tidy it up a bit, no diss, pun or anything else intended. So just wind down, please.
Plugins:
ob1_advanced_search 1.032b, ob1_search_score 1.0, ob1_pagination 2.5, ob1_title 4.1, ob1_modified 2.1
“Let your plans be dark and as impenetratable as night, and when you move, fall like a thunderbolt.”
— Sun Tzu
Offline
Pages: 1