Page 1 of 19

[RC2]RSS Feed

Posted: Wed Apr 02, 2008 3:48 am
by joeroberts
I have greated a RSS FEED for phpBB3
demo
this feed as a few nice feature such as

1. Time limmet on how soon it can be updated
2. Theme slyle lay out
3. Easy install
4.works with phpBB 3.0.0 gold and also 3.0.1
Download ModX included


This feed well show the first post of the last 10 topics posted to no need to edit this script to make it work only need to add one line to your style's overall_header.html
all you need is to creat a file called forumrss.php and add this to it

Code: Select all

<?php /**
    *
    * @package phpBB3
    * @version $Id: rssforum.php,v 1.2.3 2008-06-22 13:48 joerobe Exp $
    * @copyright (c) 2005 phpBB Group
    * @license http://opensource.org/licenses/gpl-license.php GNU Public License
    *
    */

    /**
    * @ignore
    */

         define( 'IN_PHPBB', true );
        $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
        $phpEx = substr(strrchr(__FILE__, '.'), 1);
        include_once($phpbb_root_path . 'common.' . $phpEx);
        include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
        include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
        $postallowcount='';           
        $user->session_begin();
        $auth->acl( $user->data );
        $user->setup();
        $forum_folder = (strlen($config['script_path']) > 1) ? $config['script_path'] . '/' : '/' ;

        $bbcode = new bbcode();
      //start post count
      $postallowcount='';
        $topic_count = $config['posts_per_page']; // Change in the number of topics you want to show.
        $query = "
            SELECT distinct(p.topic_id) , p.forum_id, p.post_time, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid,
                u.user_id, u.user_email, u.username, u.user_allow_viewemail,
                t.topic_title, f.left_id, f.right_id, t.topic_replies as aantal_posts
            FROM " . POSTS_TABLE . " p JOIN " . USERS_TABLE . " u on p.poster_id = u.user_id JOIN " . TOPICS_TABLE . " t on p.topic_id = t.topic_id JOIN ". FORUMS_TABLE ." f on p.forum_id = f.forum_id
            ORDER BY p.post_time DESC";
        $result = $db->sql_query( $query );
        $rss = '';
        $rss .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">
        <channel>
        <title>".htmlspecialchars($config['sitename'])."</title>
		<atom:link href=\"".$config['server_protocol'].$config['server_name'].$forum_folder."forumrss.php\" rel=\"self\" type=\"application/rss+xml\" />
        <link>".htmlspecialchars($config['server_protocol'].$config['server_name']).$forum_folder."</link>
        <description>".htmlspecialchars($config['site_desc'])."</description>
        <language>en-us</language>
        <ttl>60</ttl>";//this is to lemmit the time in wich the feed can be updated

              while( $row = $db->sql_fetchrow($result) )
               {
            //gather extra information on each post
                 $sql_view_post ="SELECT * FROM " . POSTS_TABLE . "
                 WHERE post_time = ". $row['post_time'] . "";
                 $res_views_post = $db->sql_query($sql_view_post);
                 $row_views_post = $db->sql_fetchrow($res_views_post);
                 $sql_view ="SELECT * FROM " . TOPICS_TABLE . "
                 WHERE topic_id = ". $row['topic_id'] . "";
                $res_views = $db->sql_query($sql_view);
                $row_views = $db->sql_fetchrow($res_views);
                $sql_tracking ="SELECT * FROM " . TOPICS_TRACK_TABLE . "
                WHERE topic_id = ". $row_views_post['topic_id'] . " AND user_id = " . $user->data['user_id'] . "";
                $tracking_views = $db->sql_query($sql_tracking);
                $tracking_row = $db->sql_fetchrow($tracking_views);
                $sql_session ="SELECT * FROM " . SESSIONS_TABLE . "
                WHERE session_user_id = ". $user->data['user_id'] . "";
                $res_session = $db->sql_query($sql_session);
                $row_session = $db->sql_fetchrow($res_session);
                $forum_id = $row['forum_id'];
                $rowset = $announcement_list = $topic_list = $global_announce_list = array();

               // assume topic is read
               $unread_topic = true;
              // select information for topic from the topics_tracking table
              if (isset($tracking_row['mark_time']) && $tracking_row['mark_time'] >= $row_views_post['post_time'])
              {
                $unread_topic = false;
              }

              // select information for forum containing topic from the forums_tracking table, store in $tracking_row
             if ($row_views_post["poster_id"] == $user->data['user_id'])
             {
               $unread_topic = false;
             }
            if (!$user->data['is_registered'])$unread_topic = false;

               // if the user does not have permissions to list this forum, skip everything until next branch
             if ($auth->acl_get('f_read', $forum_id))
             {
                $postallowcount = $postallowcount+1;
               //when post count reachs board lemmit we stop listing
                if($postallowcount > $config['posts_per_page'])break;
                 // Parse the message and subject
                $message = censor_text($row['post_text']);
                $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row_views['topic_replies_real'] : $row_views['topic_replies'];
                $folder_img = $folder_alt = $topic_type = '';
                topic_status($row_views, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);

                // Second parse bbcode here
                if ($row['bbcode_bitfield'])
                {
                    $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
                }
                $message = bbcode_nl2br($message);
                $message = smiley_text($message);
                $message = str_replace($phpbb_root_path,'./',$message);//fix for smiles
                $message = str_replace('<a href="#" onclick="selectCode(this); return false;">Select all</a>','',$message);//fix for java not allowed in xml
                $message = str_replace(']]',']',$message);//keep xml compliant
                $message = str_replace('&nbsp;',' ',$message);
                $message = str_replace('./',$config['server_protocol'].$config['server_name'].$forum_folder,$message);
                $fids = $row['forum_id'];
                $ids = $row["topic_id"];
                $names = censor_text($row['post_subject']);
                $replies = $row['aantal_posts'];
                $views = $row_views['topic_views'];
                $last_post = $row_views['topic_last_post_id'];
                $last_poster = $row_views['topic_last_poster_name'];
                $last_poster_id = $row_views['topic_last_poster_id'];
                $last_poster_time = $row_views['topic_last_post_time'];
                $url_link = $config['server_protocol'].$config['server_name'].$forum_folder.'viewtopic.php?';
                $topic_read = $user->img($folder_img, $folder_alt);
                $topic_read = str_replace($phpbb_root_path,$config['server_protocol'].$config['server_name'].$forum_folder,$topic_read);//fix for smiles
                $author = ($row['username'] == 'Anonymous')? 'Anonymous@nowhere.com' : $row['user_email'];

                // Send data to output var
                $descrption = '<table cellpadding="1" cellspacing="1" style="border:1px solid #a1a1a1" width="100%" align="center"><div><tr><td><p>'. $topic_read .'<br /><font size="3"><b>Replies:</b></font> '.$replies .'<br />
                <font size="3"><b>Views:</b></font> '.$views .'<br />
                <font size="3"><b>Last Post By:</b></font> <a href="'.$config['server_protocol'].$config['server_name'].$forum_folder.'memberlist.php?mode=viewprofile&u=' . $last_poster_id . '">' . $last_poster .'</a>
                <a href="'.$config['server_protocol'].$config['server_name'].$forum_folder.'viewtopic.php?f='.$row['forum_id'].'&t='.$row["topic_id"].'&p='.$last_post.'#p'.$last_post.'">'.str_replace('./',$config['server_protocol'].$config['server_name'].$forum_folder,$user->img('icon_topic_newest', 'VIEW_LATEST_POST')).'</a><b> ON: '.$user->format_date($last_poster_time).'</b><br />
                <font size="3"><b>Topic By:</b></font> <a href="'.$config['server_protocol'].$config['server_name'].$forum_folder.'memberlist.php?mode=viewprofile&u=' . $row['user_id'] . '">' . $row['username'] .'</a><b> ON: '.$user->format_date($row['post_time']).'</b><br />'. $message .'</p></td></tr></div></table>';
header('Content-type: application/xml; charset=utf-8');
               $rss .= '
               <item>
               <title>'.htmlspecialchars($names).'</title>
               <link>'.$url_link.'f='.$fids.'&t='.$ids.'&p=' .$row_views_post["post_id"].'#p'.$row_views_post["post_id"].'</link>
               <description><![CDATA['. $descrption .'<hr>]]></description>
               <pubDate>' . $user->format_date($last_poster_time,"D, d M Y H:i:s T") . '</pubDate>
			   <guid>'.$url_link.'f='.$fids.'&t='.$ids.'&p=' .$row_views_post["post_id"].'#p'.$row_views_post["post_id"].'</guid>
               </item>';
          }
       }

     $rss .='
     </channel>
     </rss>';
     echo($rss);
?>
add it to your forum root dir.
now open your style overall_header.php(if your style is data base driven the go to your admin style theme overall_header.html)
and right below <html> add

Code: Select all

<link rel="alternate" type="application/rss+xml" title="Forum" href="forumrss.php">

clear your cache and your done

edits
  1. fix for google rss reader
  2. fixed for updating new topic post
  3. fix (Post()) at end of tittle
    2008-05-26 13:48
  4. fix post read
  5. roported errors in phpBB
  6. set post limit by configs post limit not topic limit
  7. clean up code add more explanations
    2008-06-22 12:28
  8. fix utf-8 compliant
  9. image fix for smiles

Re: [beta]RSS Feed

Posted: Wed Apr 02, 2008 4:56 am
by bonelifer
This shouldn't show HIDDEN FORUMS. Right now while I'm logged out it shows posts from my Administrators forum which is hidden.

Re: [beta]RSS Feed

Posted: Wed Apr 02, 2008 10:21 am
by fiorefrank
bonelifer wrote:This shouldn't show HIDDEN FORUMS. Right now while I'm logged out it shows posts from my Administrators forum which is hidden.
ow no!
This is not good!

Re: [beta]RSS Feed

Posted: Wed Apr 02, 2008 11:04 am
by joeroberts
bonelifer wrote:This shouldn't show HIDDEN FORUMS. Right now while I'm logged out it shows posts from my Administrators forum which is hidden.
it should not no

Re: [beta]RSS Feed

Posted: Wed Apr 02, 2008 2:09 pm
by joeroberts
fix for auth()

Re: [beta]RSS Feed

Posted: Thu Apr 03, 2008 6:03 pm
by joeroberts
update to feed
  1. fix for New Post No New Post
  2. fix for post icons matching catigory(stick, lock,and announcement)
  3. fix lay out to display properly
  4. fix code box

Re: [beta]RSS Feed

Posted: Thu Apr 03, 2008 10:02 pm
by joeroberts
cleaned up for valid-rss

Re: [beta]RSS Feed

Posted: Thu Apr 03, 2008 11:40 pm
by stickerboy
Not sure if it's a bug or not, and if it is, how important it is to fix.
But if you check my feed here
See the 3rd post down (MODs on this Forum).

My MOD prefixes aren't showing correctly i.e. [RC" instead of [RC]
It's not anything major to me, but I don't know if this goes any deeper?
Using the code from your last post btw :)
Other than that, I like the layout, very nice work.

Re: [beta]RSS Feed

Posted: Fri Apr 04, 2008 12:23 am
by joeroberts
sorry thought there was a error with one of the tittle's from my site so I removed the ] from messages and turnned out to be something else and forgot to put them back
here is the fixed

Re: [beta]RSS Feed

Posted: Fri Apr 04, 2008 12:31 am
by stickerboy
Perfect, that seems to work nicely :)

Re: [beta]RSS Feed

Posted: Fri Apr 04, 2008 1:24 pm
by gmartin
There is a reference to an rsssheet.css theme ... which is not installed, and is not mentioned here in the post.
Which other requeriments are there to get it to work?

Re: [beta]RSS Feed

Posted: Fri Apr 04, 2008 1:31 pm
by joeroberts
the .css sheet is not needed at this time and well be overlooked
and nothing else is need to make this work but what was said on post one

Re: [beta]RSS Feed

Posted: Fri Apr 04, 2008 10:13 pm
by bonelifer
It's customary to update the code in the first post so people don't have to guess which one's correct.

Re: [beta]RSS Feed

Posted: Fri Apr 04, 2008 11:26 pm
by joeroberts
bonelifer wrote:It's customary to update the code in the first post so people don't have to guess which one's correct.
last one as staed
sorry thought there was a error with one of the tittle's from my site so I removed the ] from messages and turnned out to be something else and forgot to put them back
here is the fixed

Re: [beta]RSS Feed

Posted: Sat Apr 05, 2008 4:01 am
by chainprayer
Love the MOD! Exactly what I was looking for!

Any specific place to put the code in the overall_header that works best?

Thanks!