vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   Latest Threads in RSS Feed (need help) (https://vborg.vbsupport.ru/showthread.php?t=45147)

Marshalus 10-29-2002 06:57 AM

Latest Threads in RSS Feed (need help)
 
OK, I digging though the bowels of the site, and stumbled apon a RSS feed hack that will pull the most recent threads from a forum you specify, and deliver them up in RSS format.

What I want to do, instead of having to specify the forum, is just have it dish out the latest threads from all forums.

Here is what I have to work with:
Code:

<?php echo '<?xml version="1.0"?>'; ?>

<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"
            "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">

  <channel>

<?php

echo "<!--\n";
require("global.php");
echo "-->\n";

        echo "<title>$bbtitle</title>\n";
        echo "<link>$bburl</link>\n";

// set defaults
if (isset($perpage)==0 or $perpage==0) {
  $perpage=$maxthreads;
}

$forumid = verifyid("forum",$forumid);


$foruminfo=$DB_site->query_first("SELECT title,description,active FROM forum WHERE forumid=$forumid");
$forumtitle=htmlspecialchars($foruminfo[title]);
if ($foruminfo[active]==0) {
  echo "<item><title>Forum Not Active</title></item></channel></rss>";
  exit;
}

$description=htmlspecialchars($foruminfo[description]);
$forumtitle=htmlspecialchars($foruminfo[title]);

$threads=$DB_site->query("SELECT threadid,title,lastpost,replycount,postusername FROM thread WHERE forumid=$forumid ORDER BY lastpost DESC LIMIT 0,$perpage");
while ($thread=$DB_site->fetch_array($threads)) {

  $threadtitle=htmlspecialchars($thread[title]);
  $threadid=$thread[threadid];

  $notes=htmlspecialchars($thread[notes]);
  $replies=$thread[replycount];
  $firstposter=htmlspecialchars($thread[postusername]);
  $lastreplydate=date($dateformat,$thread[lastpost]+($timeoffset*3600));
  $lastreplytime=date($timeformat,$thread[lastpost]+($timeoffset*3600));

 echo "<item>\n";
 echo "<title>$threadtitle</title>\n";
 echo "<link>". $bburl ."/showthread.php?threadid=$threadid</link>\n";
 echo "<description> $firstposter - $replies - $lastreplytime </description>\n";
 echo "</item>\n";

}

?>

  </channel>

</rss>

This would be very useful for programs like Trillian that can pull RSS news feeds, or for syndicating your latest threads on other websites.

Any help would be appreciated.

N!ck 10-29-2002 10:59 PM

whoa, slow down...trillian reads rss? how?

Marshalus 11-02-2002 04:58 PM

1 Attachment(s)
Trillian Pro has a plug to read RSS feed and display them on your buddy list.

Buddy List

pogo 12-13-2002 12:46 PM

I worked a little with you code Marshalus.
What had to be changed was the query to grab the latest active threads. My query shows only threads from non-private forums.
Then I added a replacement for german umlauts because Trillian doesn't show them correct.
You can tweak a lot to customize it further and for example insert some text from the latest post. But then you have to change the query.

PHP Code:

<?php
require("global.php");

//##############################################
// Variables used:
$description "The latest active threads";
$replyword "Replies";
$showthreadnumber "15"// show this many threads in the newsfeed
//##############################################

$search = array ("?","?","?","?","?","?","?");
$replace = array ("ue","oe","ae","Ue","Oe","Ae","ss");

header("Content-Type: text/xml");
echo 
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
echo 
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns=\"http://my.netscape.com/rdf/simple/0.9/\">";
echo 
"<channel>\n";
echo 
"<title>".$bbtitle."</title>\n";
echo 
"<link>".$bburl."</link>\n";
echo 
"<description>".$description."</description>";
echo 
"</channel>\n";

$threads=$DB_site->query("SELECT threadid,title,lastpost,replycount,postusername,thread.forumid
                          FROM thread
                          LEFT JOIN forumpermission USING(forumid)
                          WHERE visible=1
                          AND forumpermission.forumid IS NULL
                          ORDER BY lastpost DESC LIMIT "
.$showthreadnumber);
while (
$thread=$DB_site->fetch_array($threads)) {
  
  
$title str_replace($search$replace$thread[title]);
  
$threadid=$thread[threadid];
  
$replies=$thread[replycount];
  
$firstposter=htmlspecialchars($thread[postusername]);
  
$lastreplydate=date($dateformat,$thread[lastpost]+($timeoffset*3600));
  
$lastreplytime=date($timeformat,$thread[lastpost]+($timeoffset*3600));

  echo 
"<item>\n";
  echo 
"<title>".htmlspecialchars($title)."</title>\n";
  echo 
"<link>$bburl/showthread.php?threadid=$threadid</link>\n";
  echo 
"<description> $firstposter - $replies $replyword - $lastreplydate $lastreplytime </description>\n";
  echo 
"</item>\n";
}

echo 
"</rdf:RDF>";

?>


Highlander 02-03-2003 08:52 PM

WOW.. indeed..the best i ever saw.. .. is there any posobility .. to get read out on the same way another sql database?

what i have to to.. give me a starting point :)

PeterNRG 02-23-2003 04:59 PM

Any ideas how to add the first xxx characters of the first post as well, and put this as a description, based on pogo's exellent script?

I'm also looking for a way to not include the last reply features (last post name & date/time) if there is no reply yet.

PeterNRG 02-24-2003 08:32 AM

I found out that Pogo's code has a weird bug: as soon as someone starts a poll thread, the RSS script shows already the threadtitle and link, which results in a url which does not exist, as long as the creation of the poll isn't finished :)

pogo 02-24-2003 09:23 AM

Quote:

Originally posted by PeterNRG
I found out that Pogo's code has a weird bug: as soon as someone starts a poll thread, the RSS script shows already the threadtitle and link, which results in a url which does not exist, as long as the creation of the poll isn't finished :)
It is not a weird bug it is just how vBulletin works. Just created threads with the option to add a poll are invisible as long as the poll is not set up.

Now I added visible=1 AND to the query and such threads are not shown anymore.


To not include the last reply line you can change the code like this:

replace:
echo "<description> $firstposter - $replies $replyword - $lastreplydate $lastreplytime </description>\n";

with:
if ($replies > 0) {
echo "<description> $firstposter - $replies $replyword - $lastreplydate $lastreplytime </description>\n";
}

PeterNRG 02-26-2003 12:46 PM

Thanks for all your help so far pogo. I have another issue which is giving me headaches: I have an announcement forum, where only admins can start new posts (being custom set with vB's forum permissions), members can reply though.

For some reason, with your code, the new announcement headlines do not show up in our RSS feed. I guess it has to do with the forumpermission in the query. Can someone help me out on that?

pogo 02-26-2003 03:12 PM

It's getting complicated. ;)

Try this query instead of the above one

PHP Code:

SELECT threadid,title,lastpost,replycount,postusername,thread.forumid
                          FROM thread
                          LEFT JOIN forumpermission USING
(forumid)
                          
WHERE visible=1
                          
AND (forumpermission.forumid IS NULL OR forumpermission.canview=1)
                          
ORDER BY lastpost DESC LIMIT 



All times are GMT. The time now is 03:30 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01256 seconds
  • Memory Usage 1,765KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete