Not logged in. · Lost password · Register
Forum: Support Ideas and suggestions RSS
RSS for one thread - easy?
Avatar
NFG #1
Member since Sep 2006 · 120 posts
Group memberships: Members
Show profile · Link to this post
Subject: RSS for one thread - easy?
I've got some threads on my forujm that would be useful for people to subscribe to, without having their feeds cluttered up with other, less focused updates.  For example, one thread is used for software updates, another for a particularly popular thread about my neighbors.

There's not currently a way to subscribe to one specific thread.  If I were to guess, a third TYPE would be needed, in addition to type 1 and type 2... 

Has anyone tried to do this?  Can anyone offer some suggestions?

The code in rss.inc.php seems tantalizingly simple, but I thought I'd ask before mucking about.  =)
Avatar
Yves (Administrator) #2
User title: UNB developer & webmaster
Member since Jan 2004 · 3814 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
At least I haven't done that. I'm not using newsfeeds though...
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Avatar
NFG #3
Member since Sep 2006 · 120 posts
Group memberships: Members
Show profile · Link to this post
OK, I think I've got this nailed.  I don't know much about UNB's mechanisms, so I kinda just copied and pasted and bashed my head against it until it worked.  Basically, I added a third type of feed, copying parts of type=1 and type=2 and changing the bits I needed to make it go.

Line 15 First, I added this line, to snag the threadid from the RSS request URL:
  1. $threadid = intval($_REQUEST['thread']); // Thread ID for type-3 lists

Line 31 Next, I added a line to fail the process if there's no thread ID:
  1. if ($type == 3 && !$threadid) die('No thread ID specified.');

Line 73 Next, I prepped the caching filename based on the threadID:
  1. if ($type == 3)
  2.     $filename = strtolower(str_replace('.', '', $format)) . '.' . $threadid . '.xml';

Line 78 Changed the feed title to reflect the thread title:
  1. if ($type == 3) {
  2.     $rss->link = rc('home_url') . UnbLink('@thread', 'id=' . $threadid, false, /*sid*/ false);
  3. } else {
  4.     $rss->link = rc('home_url');
  5. }

Line 104 Next up was the type 2 DB query (I think that's what it was...):
  1. if ($type == 3)
  2. {
  3.     $order = 'Date DESC';
  4.     $where = '';
  5.     $found = $post->Find('Thread = ' . $threadid, $order, $limit);
  6. }

Line 143 Then I copied the main routine from type 2:
  1. if ($type == 3)
  2.     {
  3.         $rss->title = $thread->GetSubject() . ' - From ' . rc('forum_title');
  4.         $thread->Load($post->GetThread());
  5.         if (!UnbCheckRights('viewforum', $thread->GetForum(), $thread->GetID()))
  6.         {
  7.             $foundmore = $post->FindNext();
  8.             continue;
  9.         }
  10.         $url = UnbMakePostLink($post, 0, 3);
  11.  
  12.         if ($post->GetDate() == $thread->GetDate())
  13.         {
  14.             $title = $thread->GetSubject();
  15.             if ($thread->GetDesc())
  16.                 $title .= ' (' . $thread->GetDesc() . ')';
  17.         }
  18.         else if ($post->GetSubject() != '')
  19.         {
  20.             $title = $post->GetSubject() . ' (' . $UNB_T['topic'] . ': ' . $thread->GetSubject() . ')';
  21.         }
  22.         else
  23.         {
  24.             $title = 'Re: ' . $thread->GetSubject();
  25.         }
  26.     }

Line 168 Then the GUID line for the feed:
  1.     if ($type == 3)
  2.         $item->guid .= '#' . $post->GetID();

Line 173 And finally, kicking off the loop:
  1. if ($type == 3) $foundmore = $post->FindNext();

To be honest I'm surprised it worked at all, but it did, and it seems to be reliable. 

If there's any cruft in the code, or any mistakes that I missed, please let me know.  =)

Now i need to work out a link in each page...
Avatar
NFG #4
Member since Sep 2006 · 120 posts
Group memberships: Members
Show profile · Link to this post
Template changes to include single-thread RSS link:

1. edited template file POSTLIST.HTML

End of file:
<a href="forum.php?req=rss&type=3&thread={$posteditorThreadId}" title="RSS Feed for this thread"><img {$UNBImage.rss}> RSS Feed for this thread</a>

2. edited template file _HEAD.HTML (invisible ALTERNATE link for RSS-aware browsers)

Line 25:
<link rel="alternate" type="application/rss+xml" href="forum.php?req=rss&type=3&thread={$posteditorThreadId}" title="RSS Feed for this thread" />

The alternate link in _HEAD.HTML is kind of a kludge, since it was just easier to include the link there than work out how and where the header was constructed, and then put an IF in there to only include the link during thread display.  Not sure if there's a better way to do that.
Avatar
Yves (Administrator) #5
User title: UNB developer & webmaster
Member since Jan 2004 · 3814 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
In reply to post #3
Line 73: You should make the file names for threads distinct from those for forums. The numeric IDs could overlap and you get entirely wrong results then. Putting a "t" in front of the number is okay, for example.
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20110527-dev, © 2003-2011 by Yves Goergen
Page created in 224.9 ms (136.9 ms) · 62 database queries in 139.5 ms
Current time: 2012-02-08, 09:03:30 (UTC +01:00)