 |
|
 |
usdrunk Level: Protégé
 Registered: 20-03-2006 Posts: 6
|
RSS mod for tForum
Hi,
I try to write RSS mod for my tforum but I could not. What I need is a RSS generator Most View topic of 1 board but I fail.
Here is my code
<?php
@require('./includes/grab_globals.php');
$GLOBALS['query_count'] = 0;
@require('./language/text.php');
@require('./templates/buttons.php');
@require('./includes/template_parser.php');
@require('./db.php');
@require('./includes/functions.php');
$GLOBALS['start_time'] = Getmicrotime();
$fSettings = GetSettings();
@require('./includes/gzip_begin.php');
$sql = new DB_SQL;
$sql2 = new DB_SQL;
include "config.php";
header('Content-type: text/xml');
echo "<?xml version='1.0' encoding='UTF-8' ?>";
?>
<rss version="2.0">
<chanel>
<title>Top 5 viewed</title>
<?php
$ent['BoardID'] = (isset($_GET['BoardID'])) ? intval($_GET['BoardID']) : 0;
$query = mysql_query("SELECT M.* FROM " . PREFIX . "messages M, " . PREFIX . "topics T WHERE M.TopicID = T.TopicID AND T.BoardID = " . $BoardID . " ORDER BY T.numViews DESC LIMIT 5");
while($row = mysql_fetch_array($query))
{ $ent['TopDownSubjectURL'] = 'viewtopic.php?TopicID='.$row['TopicID'];
$ent['TopDownSubject'] = $row['Subject'];
echo ParseTemp($templates['loop'],$ent);
?>
<item>
<title>
<?php echo $TopDownSubject; ?>
</title>
<link>
<?php echo $TopDownSubjectURL; ?>
</link>
</item>
<?php
}
?>
</chanel>
</rss>
|
and what I got
<?xml version="1.0" encoding="UTF-8" ?>
- <rss version="2.0">
- <chanel>
<title>Top 5 viewed</title>
- <item>
<title />
<link />
</item>
- <item>
<title />
<link />
</item>
- <item>
<title />
<link />
</item>
- <item>
<title />
<link />
</item>
- <item>
<title />
<link />
</item>
</chanel>
</rss>
|
I did not know where is my mistake. Please help. I am very stupid in PHP and SQL
|
|
20-03-2006 at 05:05 AM |
|
|
usdrunk Level: Protégé
 Registered: 20-03-2006 Posts: 6
|
Re: RSS mod for tForum
Yes, it works. Thank man!
|
|
20-03-2006 at 05:13 PM |
|
|
usdrunk Level: Protégé
 Registered: 20-03-2006 Posts: 6
|
Re: RSS mod for tForum
I have this code for displaying RSS fee in webpage
<?php
/*
Created by Global Syndication's RSS Parser http://www.globalsyndication.com/rss-parser
*/
$file = "RSS URL";
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
function startElement($parser, $name, $attrs) {
global $rss_channel, $currently_writing, $main;
switch($name) {
case "RSS":
case "RDF:RDF":
case "ITEMS":
$currently_writing = "";
break;
case "CHANNEL":
$main = "CHANNEL";
break;
case "IMAGE":
$main = "IMAGE";
$rss_channel["IMAGE"] = array();
break;
case "ITEM":
$main = "ITEMS";
break;
default:
$currently_writing = $name;
break;
}
}
function endElement($parser, $name) {
global $rss_channel, $currently_writing, $item_counter;
$currently_writing = "";
if ($name == "ITEM") {
$item_counter++;
}
}
function characterData($parser, $data) {
global $rss_channel, $currently_writing, $main, $item_counter;
if ($currently_writing != "") {
switch($main) {
case "CHANNEL":
if (isset($rss_channel[$currently_writing])) {
$rss_channel[$currently_writing] .= $data;
} else {
$rss_channel[$currently_writing] = $data;
}
break;
case "IMAGE":
if (isset($rss_channel[$main][$currently_writing])) {
$rss_channel[$main][$currently_writing] .= $data;
} else {
$rss_channel[$main][$currently_writing] = $data;
}
break;
case "ITEMS":
if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
} else {
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
// output HTML
print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>");
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
} else {
print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
}
}
} else {
print ("<b>There are no articles in this feed.</b>");
}
}
?>
|
Could anyone tell me how to code to display 2 RSS feed at the same page. Thank you
[Edited by admin on 21-03-2006 at 08:03 AM GMT]
|
|
21-03-2006 at 04:19 AM |
|
|
|
|
 |
 |