[geeklog-devtalk] mode = XML for stories

Gavin Mahan gavin at theouldsod.com
Thu Jun 10 02:01:41 EDT 2004


I added a feature to article.php that gives you a new mode (just like
print) that will display the story in XML format. It uses a new
template file so you can customize the xml feed to different formats
(like RSS/RDF). It seems like it would handy for others to use. I did
it cause I needed to display stories in a flash site (I know flash is
evil but I have to pay the rent, spare me the rant). I added this code
right below the else if mode == print statement. I think it might be a
handy addition to Geeklog.

Because I used this for a specific purpose this doesn't result in a
valid rss feed I don't believe (I never really checked it) but if
anyone wanted to add it to the core Geeklog I would be more then happy
to make it a valid feed. I can think of tons of uses for this right off
the top of my head, what do you think?

My addition to article.php is as follows:

} elseif (($mode == 'xml') && ($_CONF['hideprintericon'] == 0)) {
$story_template = new Template($_CONF['path_layout'] .
'article');
$story_template->set_file('article','xml.thtml');
$icount = DB_count($_TABLES['article_images'],'ai_sid',
$A['sid']);
if ($icount > 0) {
$result_articles = DB_query("SELECT * FROM
{$_TABLES['article_images']} WHERE ai_sid = '{$A['sid']}'");
for ($z = 1; $z <= $icount; $z++) {
$I = DB_fetchArray($result_articles);
$blah .= '<image>' . $_CONF['site_url'] .
'/images/articles/' . $I['ai_filename'] . '</image>';
}
}
$story_template->set_var('article_images',
$blah);
$story_template->set_var('page_title',
$_CONF['site_name'] . ': ' .
stripslashes($A['title']));

$story_template->set_var('story_title',stripslashes($A['title']));
$curtime = COM_getUserDateTimeFormat($A['day']);
$story_template->set_var('story_date', $curtime[0]);
if ($_CONF['contributedbyline'] == 1) {
$story_template->set_var('lang_contributedby',
$LANG01[1]);
$story_template->set_var('story_author',
DB_getItem($_TABLES['users'],'username',"uid = '{$A['uid']}'"));
}
//$A['introtext'] = preg_replace("/(\<img)(.*?)(\>)/si",
"", $A['introtext']);
$A['introtext'] = htmlspecialchars($A['introtext']);
$A['introtext'] = mysql_escape_string($A['introtext']);
$A['introtext'] = stripslashes($A['introtext']);
$A['bodytext'] = htmlspecialchars($A['bodytext']);
$A['bodytext'] = mysql_escape_string($A['bodytext']);
$A['bodytext'] = stripslashes($A['bodytext']);
if ($A['postmode'] == 'html') {
$story_template->set_var ('story_introtext',
stripslashes ($A['introtext']));
$story_template->set_var ('story_bodytext',
stripslashes ($A['bodytext']));
} else {
$story_template->set_var ('story_introtext',
stripslashes ($A['introtext']));
$A['story_bodytext'] =
preg_replace("/(\<img)(.*?)(\>)/si", "", $A['story_bodytext']);
$story_template->set_var ('story_bodytext',
stripslashes ($A['bodytext']));
}
$story_template->set_var('site_url',$_CONF['site_url']);

$story_template->set_var('site_slogan',$_CONF['site_slogan']);
$story_template->set_var('layout_url',$_CONF['layout_url']);
$story_template->set_var('story_id', $A['sid']);
$story_template->set_var('story_comments',
DB_count($_TABLES['comments'],'sid',$A['sid']));
$story_template->set_var('lang_comments', $LANG01[3]);
$story_template->parse('output','article');
$display =
$story_template->finish($story_template->get_var('output'));



The template file I am using is called xml.thtml, is in the
layout/theme/article directory and looks like:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="0.91">
<channel>
<title>{page_title}</title>
<language>en-gb</language>
<link>{site_url}</link>
<description>{site_slogan}</description>
<language>en-gb</language>
<item>
<title>{story_title}</title>
<link><a
href="{site_url}/article.php?story={story_id}">{site_url}/article.php?
story={story_id}</a></link>
<description html_text="{story_introtext}"
body_text="{story_bodytext}"></description>
{article_images}
</item>
</channel>
</rss>




More information about the geeklog-devtalk mailing list