Page 1 of 2

RSS feed block

Posted: 2. April 2008 21:38
by frold
All the rss.php credit goes to DaMysterious from: http://damysterious.xs4all.nl/plusxl40/

Demo: http://studmed.dk The block "RSS Feed".

Create a new file in your root. Call it rss.php Paste in:

Code: Select all

<?php 
/** 
*
* @name syndicate.php
* @package phpBB3 Portal XL 4.0
* @version $Id: syndicate.php,v 1.4 2008/01/25 16:54:34 damysterious Exp $
*
* @copyright (c) 2007 Portal XL 4.0 Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

// XML and nocaching headers
header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
header ('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
header ('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header ('Content-Type: text/xml');

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/lang_portal');

$count = request_var('count', 0);
$chars = request_var('chars', 0);
$type = request_var('type', '');
$fid = request_var('fid', 0);
$titlepattern = request_var('titlepattern', '');

// If not set, set the output count to 20
$count = (!isset($HTTP_GET_VARS['count'])) ? 50 : intval($HTTP_GET_VARS['count']);
$count = ($count == 0) ? 50 : $count;

// characters
$chars = (isset($HTTP_GET_VARS['chars'])) ? intval($HTTP_GET_VARS['chars']) : 200;
if ($chars < 0 || $chars > 500) $chars = 500; //Maximum
$type = (isset($HTTP_GET_VARS['type'])) ? $HTTP_GET_VARS['type'] : 'latest';
$news = ($type == 'news');

// Create main board url
$script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($config['script_path']));
$viewtopic = ($script_name != '') ? $script_name . '/viewtopic.' . $phpEx : 'viewtopic.'. $phpEx;
$index = ($script_name != '') ? $script_name . '/portal.' . $phpEx : 'portal.'. $phpEx;
$server_name = trim($config['server_name']);
$server_protocol = ($config['cookie_secure']) ? 'https://' : 'http://';
$server_port = ($config['server_port'] <> 80) ? ':' . trim($config['server_port']) . '/' : '/';

$index_url = $server_protocol . $server_name . $server_port . $index;
$viewtopic_url = $server_protocol . $server_name . $server_port . $viewtopic;

// Strip all BBCodes and Smileys from the post
function strip_post($text, $uid)
{
   $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=.*?)?(?::[a-z])?(\:?$uid)\]#", '', $text); // for BBCode
   $text = preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s(.*?) \-\->#', '', $text); // for smileys
   $text = str_replace('&#', '&#', htmlspecialchars($text, ENT_QUOTES)); // html format
   return $text;
}

$rdf  = '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . "\n";
$rdf .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:annotate="http://purl.org/rss/1.0/modules/annotate/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">' . "\n";
$rdf .= '<channel>' . "\n";
$rdf .= '<title>' . strip_tags($config['sitename']) . ' Forum</title>' . "\n";
$rdf .= '<link>' . $index_url . '</link>' . "\n";
$rdf .= '<description>' . strip_tags($config['site_desc']) . '</description>' . "\n";
$rdf .= '<pubDate>' . date("D, d M Y H:G:s O") . '</pubDate>' . "\n";
$rdf .= '<lastBuildDate>' . date("D, d M Y H:G:s O") . '</lastBuildDate>' . "\n";
$rdf .= '<copyright>Copyright 2007, ' . $config['sitename'] . '</copyright>' . "\n";
$rdf .= '<webMaster>' . $config['board_email'] . '</webMaster>' . "\n";
$rdf .= '<managingEditor>' . $config['board_email'] . '</managingEditor>' . "\n";

$fid = (isset($HTTP_GET_VARS['fid'])) ? $HTTP_GET_VARS['fid'] : array();
if (!is_array($fid)) $fid = array($fid);

$fid_new = array();
for ($i=0; $i < sizeof($fid); $i++)
{
   if (intval($fid[$i]) > 0)
   {
      if (!in_array($fid[$i], $fid_new))
      {
         $fid_new[] = $fid[$i];
      }
   }
}
$fid = $fid_new;
$sql_where = (sizeof($fid) > 0) ? " AND f.forum_id IN (" . implode($fid, ", ") . ")" : " ";

$sql_orderby = $news ? 't.topic_time DESC' : 'p.post_time DESC';
$sql_post_id_field = $news ? 't.topic_first_post_id' : 't.topic_last_post_id';

// SQL statement to fetch active topics of public forums
$sql = "SELECT t.topic_id, t.topic_title, p.post_id, p.post_time, p.post_text, p.bbcode_uid, p.post_approved, f.forum_name, f.forum_id
      FROM " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p, " . FORUMS_TABLE . " AS f
      WHERE f.forum_id = t.forum_id
          AND p.topic_id = t.topic_id
          AND p.post_id = " . $sql_post_id_field . "
          AND p.post_id = p.post_id
      AND p.post_approved = 1
          " . $sql_where . "
      ORDER BY " . $sql_orderby ." LIMIT " . $count . "";
$topics_query = $db->sql_query($sql);

if (!$topics_query)
{
    die("Failed obtaining list of active topics");
} else
{
    $topics = $db->sql_fetchrowset($topics_query);
}

if (count($topics) == 0)
{
    die("No topics found");
}
else
{
   // $topics contains all interesting data
   for ($i = 0; $i < count($topics); $i++)
    {
       if (isset($HTTP_GET_VARS['titlepattern']))
       {
         $title = $HTTP_GET_VARS['titlepattern'];
            $title = str_replace('__DATE__', date("D, d M Y H:G:s O", $topics[$i]['post_time']), $title);
            $title = str_replace('__TITLE__', $topics[$i]['topic_title'], $title);
            $title = str_replace('__FORUM__', $topics[$i]['forum_name'], $title);
      } else
      {
           $title = $topics[$i]['topic_title'];
      }
      
      $url = ($news) ? $viewtopic_url . "?" . 't' . "=" . $topics[$i]['topic_id'] : $viewtopic_url . "?" . 'p' . "=" . $topics[$i]['post_id'];

      $message = $topics[$i]['post_text'];
      $message = strip_tags($message);
      $message = strip_post($message, $topics[$i]['bbcode_uid']);
      $message = str_replace("\n", '<br />', $message);

        if ($chars > 0) 
      	{
           $message = (strlen($message) > $chars) ? substr($message, 0, ($chars - 4)) . ' ...' : $message;
        }

      if ($auth->acl_get('f_read', $topics[$i]['forum_id'])) 
      {
         $rdf .= "<item>";
         $rdf .= "<title>" . $title . "</title>";
         $rdf .= "<link>" . $url . "</link>";
         $rdf .= "<pubDate>" . date("D, d M Y H:G:s O", $topics[$i]['post_time']) . "</pubDate>";
         $rdf .= "<description>" . htmlspecialchars($message) . "</description>";
         $rdf .= "</item>";
      }
    }
}
$db->sql_freeresult($topics_query);
unset($topics[$i]);

$rdf .= "</channel></rss>";

// Output the RDF
echo $rdf;
?>
OPEN
styles/prosilver/template/overall_header.html

FIND

Code: Select all

<title>{SITENAME} &bull; <!-- IF S_IN_MCP -->{L_MCP} &bull; <!-- ELSEIF S_IN_UCP -->{L_UCP} &bull; <!-- ENDIF -->{PAGE_TITLE}</title>
ADD AFTER

Code: Select all

<link rel="alternate" type="application/rss+xml" title="{SITENAME} RSS-Portal" href="./rss.php" />
OPEN
styles/prosilver/template/portal/portal_body.html

FIND

Code: Select all

			<!-- //INCLUDE portal/block/_sample_block_design.html-->
ADD AFTER

Code: Select all

<!-- INCLUDE portal/block/rss.html -->
Create a new file in styles/prosilver/template/portal/block and call it rss.html

OPEN
styles/prosilver/template/portal/block/rss.html

REPLACE ALL WITH

Code: Select all

<div class="panel">
   <div class="inner">
      <span class="corners-top"><span></span></span>
         <h3>RSS feed</h3>
			<span><a href="rss.php" target="_blank"><img src="images/rssforum.png" title="RSS feed" width="90" height="15" border="0"></a></span>
      <span class="corners-bottom"><span></span></span>
   </div>
</div>
<br style="clear:both" />
UPLOAD
Image
to the folder "Images"

Then go to ACP and refresh your style!

Demo http://www.studmed.dk the block "RSS FEED".

Re: RSS feed from your own forum

Posted: 4. April 2008 21:50
by portal6
:D

Re: RSS feed from your own forum

Posted: 5. April 2008 16:29
by frold
I dont understand your error - where do you see it, what phpBB version do you use, where did you put the rss.php file etc...

I cant use that copy paste very much, sry....

Re: RSS feed from your own forum

Posted: 5. April 2008 17:03
by portal6
i see it when i open the site rss.php
in root/

Re: RSS feed from your own forum

Posted: 5. April 2008 20:44
by frold
It might be your Server URL settings settings I can see it write http twice...

What do you have in;

Server protocol:
This is used as the server protocol if these settings are forced. If empty or not forced the protocol is determined by the cookie secure settings (http:// or https://).

AND

Domain name:
The domain name this board runs from (for example: http://www.example.com).

AND

Script path:
The path where phpBB is located relative to the domain name, e.g. /phpBB3.

Re: RSS feed from your own forum

Posted: 5. April 2008 22:51
by portal6
my rss.php is in /
and phpbb is also /

Re: RSS feed from your own forum

Posted: 6. April 2008 09:07
by frold
Sry I cant help...

You might use this code instead: http://www.phpbb.com/community/viewtopi ... 0&t=867465

Re: RSS feed from your own forum

Posted: 6. April 2008 09:14
by portal6
My new rss.php is the syndication mod

Re: RSS feed from your own forum

Posted: 6. April 2008 09:54
by frold
portal6 wrote:My new rss.php is the syndication mod
Im glad you found a solution that worked for you...

I hope someone can use "my" mod without the same trouble you had....

Re: RSS feed from your own forum

Posted: 6. April 2008 10:14
by portal6
but thanks for the block in the portal ;)

Re: RSS feed from your own forum

Posted: 26. May 2008 22:23
by frold
portal6 wrote:but thanks for the block in the portal ;)
np ;-)

To avoid heavy serverload by evil ppl
Thanks you AlleyKat @ http://phpbb2.dk

OPEN rss.php

FIND

Code: Select all

// If not set, set the output count to 20
$count = (!isset($HTTP_GET_VARS['count'])) ? 50 : intval($HTTP_GET_VARS['count']);
$count = ($count == 0) ? 50 : $count;
AFTER ADD

Code: Select all

 if ($count < 0 || $count > 100) $count = 100; //Maximum
So if ppl try /rss.php?count=20000 it will not send your server down :D

Re: RSS feed and RSS block

Posted: 4. June 2008 02:50
by liquidspark
This isn't showing up for me. Is there a step that I missed? I really don't know why it isn't working - it should. :?

Re: RSS feed and RSS block

Posted: 4. June 2008 07:52
by frold
liquidspark wrote:This isn't showing up for me. Is there a step that I missed? I really don't know why it isn't working - it should. :?
refreshed the template?

Re: RSS feed and RSS block

Posted: 6. June 2008 03:21
by liquidspark
I see it now on the right side of the portal, at the bottom. I was expecting a banner at the top like is shown on this site:
http://studmed.dk/ (under "RSS NYHEDER")
I was also expecting preferences under the ACP - .MOD - Portal section, but this seems unnecessary for the scope of this mod.

How might I create a news feed banner like the one on that site?

EDIT: I just noticed it's a JavaScript. That sheds light on that one! (/me digs deeper.)
EDIT2: I found this in the page's code. I guess I can add something similar to the template, but without an editable mod format, I'll just have to change things manually to update them. It looks like an advertisement block, rather than an RSS news feed. (I don't speak this language.)

Code: Select all

<!-- [+] center block area -->
	<td valign="top">
	<br style="clear:both" />

		<div id="lastrss" class="forabg">
	<div class="inner"><span class="corners-top"><span></span></span>
		<ul class="topiclist">
			<li class="header">
				<dl>
					<dt>RSS Nyheder</dt>
				</dl>
			</li>
		</ul>
		<dl>
			<dd class="bg2" style="height:20px;line-height:20px;">
        <div id="newsticker">
          <ul style="list-style: none;">
                            <li style="text-align:center;margin:auto;">
                  <a style="font-weight:bold;" href="http://www.dagensmedicin.dk//" onclick="window.open(this.href);return false;">Dagens Medicin - Nyheder</a> &bull; <a href="http://www.dagensmedicin.dk//nyheder/2008/06/05/hellere-end-undskyldning-e/index.xml" title="Hellere end undskyldning end en retssag" onclick="window.open(this.href);return false;">Hellere end undskyldning end en retssag</a>
                </li>
                                <li style="text-align:center;margin:auto;">
                  <a style="font-weight:bold;" href="http://www.dagensmedicin.dk//" onclick="window.open(this.href);return false;">Dagens Medicin - Nyheder</a> &bull; <a href="http://www.dagensmedicin.dk//nyheder/2008/06/05/hjerteforeningen-vil-stopp/index.xml" title="Hjerteforeningen vil stoppe nye tilskudsregler" onclick="window.open(this.href);return false;">Hjerteforeningen vil stoppe nye tilskudsregler</a>
                </li>
                                <li style="text-align:center;margin:auto;">
                  <a style="font-weight:bold;" href="http://www.dagensmedicin.dk//" onclick="window.open(this.href);return false;">Dagens Medicin - Nyheder</a> &bull; <a href="http://www.dagensmedicin.dk//nyheder/2008/06/05/krftens-bekmpelse-uddeler-/index.xml" title="Kræftens Bekæmpelse uddeler 75 mio. til forskning" onclick="window.open(this.href);return false;">Kræftens Bekæmpelse uddeler 75 mio. til forskning</a>
                </li>
                                <li style="text-align:center;margin:auto;">
                  <a style="font-weight:bold;" href="http://www.dagensmedicin.dk//" onclick="window.open(this.href);return false;">Dagens Medicin - Nyheder</a> &bull; <a href="http://www.dagensmedicin.dk//nyheder/2008/06/05/forhandlinger-om-snderjysk/index.xml" title="Forhandlinger om sønderjysk sygehus er brudt sammen" onclick="window.open(this.href);return false;">Forhandlinger om sønderjysk sygehus er brudt sammen</a>
                </li>
                                <li style="text-align:center;margin:auto;">
                  <a style="font-weight:bold;" href="http://www.dagensmedicin.dk//" onclick="window.open(this.href);return false;">Dagens Medicin - Nyheder</a> &bull; <a href="http://www.dagensmedicin.dk//nyheder/2008/06/05/bent-hansen-er-klar-til-at/index.xml" title="Bent Hansen er klar til at bede om indgreb" onclick="window.open(this.href);return false;">Bent Hansen er klar til at bede om indgreb</a>
                </li>
                          </ul>
        </div>
			</dd>
		</dl>
	<span class="corners-bottom"><span></span></span></div>

Re: RSS feed and RSS block

Posted: 6. June 2008 07:44
by frold
liquidspark wrote:I see it now on the right side of the portal, at the bottom. I was expecting a banner at the top like is shown on this site:
http://studmed.dk/ (under "RSS NYHEDER")
You might want this block viewtopic.php?f=9&t=399