Copyright © 2005-2008 Andrea Tincani

AndreaPHP | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (Dynamic image) New Topic New Poll Post Reply
AndreaPHP Forum : PHP General : RSS mod for tForum
Poster Message
usdrunk
Level: Protégé

Registered: 20-03-2006
Posts: 6

icon 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
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 35

icon Re: RSS mod for tForum

try to modify these lines


<?php echo $TopDownSubject?>
</title>
<link>
<?php echo $TopDownSubjectURL?>




with this

<?php echo $ent['TopDownSubject']; ?>
</title>
<link>
<?php echo $ent['TopDownSubjectURL']; ?>




please let me know if it worked

[Edited by admin on 20-03-2006 at 02:50 PM GMT]

____________________________
AndreaVB

20-03-2006 at 01:50 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
usdrunk
Level: Protégé

Registered: 20-03-2006
Posts: 6

icon Re: RSS mod for tForum

Yes, it works. Thank man!

20-03-2006 at 05:13 PM
View Profile Send Email to User Show All Posts | Quote Reply
usdrunk
Level: Protégé

Registered: 20-03-2006
Posts: 6

icon 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($fp4096)) {
    if (!
xml_parse($xml_parser$datafeof($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
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 35

icon Re: RSS mod for tForum

this code seems to be based on a input file passed using variable $file = "RSS URL";

to display two different RSS you should execute the entire code twice (maybe inside a for loop) using two different files as source...
i.e. use $file as an array of two files name or more


<?
$file
=array("file1","file2")
for (
$i=0;$i<2;$i++) {
//..the rest of the code
if (!($fp fopen($file[$i], "r"))) {
    die(
"could not open XML input");
}
//output HTML
}
?>




____________________________
AndreaVB

21-03-2006 at 07:19 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Mikedai
Level: Trainee

Registered: 18-01-2008
Posts: 3

icon Re: RSS mod for tForum

You guys are genius. I admire you!    

http://www.digitalrev.com/en/product_details.php?item_id=2146

Jeffrey


____________________________
Jeffrey

18-01-2008 at 02:13 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaPHP Forum : PHP General : RSS mod for tForum
Next Topic (Dynamic image) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: AndreaVB

Copyright © 2005-2008 Andrea Tincani

Powered by: tForum tForum Edition b0.92p1
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team.