Skip to content
Permalink
Browse files

added funcionality to get news and forum posts from RSS-feeds

  • Loading branch information...
bohrsty committed Sep 26, 2012
1 parent b2022b9 commit f6d0f92d581f6a6815f7badcd615610e9962d98e
Showing with 107 additions and 5 deletions.
  1. +19 −3 htdocs/index.php
  2. +78 −0 htdocs/lib2/RSSParser.class.php
  3. +7 −2 htdocs/lib2/common.inc.php
  4. +3 −0 htdocs/templates2/ocstyle/start.tpl
@@ -33,9 +33,16 @@
}
else
{
$url = $opt['news']['include'];
$url = str_replace('{style}', $opt['template']['style'], $url);
$newscontent = read_file($url, $opt['news']['maxsize']);
/*
* changed by bohrsty to fix error in displaying news from blog
* requires $opt['news']['count'] in settings for number of blog-items
* $opt['news']['include'] needs to be the RSS-URL of the blog
*
$url = $opt['news']['include'];
$url = str_replace('{style}', $opt['template']['style'], $url);
$newscontent = read_file($url, $opt['news']['maxsize']);
*/
$newscontent = RSSParser::parse($opt['news']['count'],$opt['news']['include']);
$tpl->assign('news', $newscontent);
$tpl->assign('extern_news', true);
@@ -46,6 +53,15 @@
require_once($opt['rootpath'] . 'cache2/phpbb.inc.php');
else
*/
/*
* changed by bohrsty to add lastest forum-entries using RSS-feed
* requires $opt['forum']['count'] in settings for number of lastest forum-posts
* requires $opt['forum']['url'] in settings: RSS-feed-URL of the forum
*/
$forumcontent = RSSParser::parse($opt['forum']['count'],$opt['forum']['url']);
$tpl->assign('forum',$forumcontent);
$phpbb_topics = array();
$tpl->assign('phpbb_topics', $phpbb_topics);
$tpl->assign('phpbb_enabled', ($opt['cron']['phpbbtopics']['url'] != ''));
@@ -0,0 +1,78 @@
<?php
class RSSParser {
/**
* parse
* @param int $items number of feeditems to parse from feed
* @param string $url url of the feed to parse
* @return string $item feeditems as HTML-string
*/
public static function parse($items,$url) {
// error
$error = false;
// check $url
if(!preg_match('!^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&amp;%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&amp;%\$#\=~_\-]+))*$!',$url)) {
$error = true;
} else {
// output
$html = '<div class="buffer" style="width: 500px;height: 2px;">&nbsp;</div>'."\n";
// get xml-data
$data = file_get_contents($url);
// check data
if($data === false || strpos($data, 'rss version=') === false) {
$error = true;
} else {
// parse XML
try {
// get SimpleXML-object
$xml = new SimpleXMLElement($data);
// walk through items
$i=0;
foreach($xml->channel->item as $item) {
// check length
if($items != 0 && $i >= $items) {
break;
} else {
// add html
$html .= '<p class="content-title-noshade-size2" style="display: inline;">'."\n";
$html .= strftime('%e. %B %Y',strtotime($item->pubDate)).' - '. $item->title;
$html .= '</p> <p style="line-height: 1.6em;display: inline;">&emsp;[<b><a class="link" href="'.$item->link.'">mehr...</a></b>]</p>'."\n";
$html .= '<p>'.$item->description.'</p>'."\n";
}
// increment counter
$i++;
}
// finish html
$html .= '<div class="buffer" style="width: 500px;">&nbsp;</div>'."\n";
}
catch(Exception $e) {
$error = true;
}
}
}
// return
if(!$error) {
return $html;
} else {
return '';
}
}
}
?>
@@ -17,11 +17,16 @@ function __autoload($class_name)
if (!preg_match('/^[\w]{1,}$/', $class_name))
return;
$class_name2 = $class_name;
$class_name = str_replace('_', '/', $class_name);
$file = $opt['rootpath'] . '../lib/classes/' . $class_name . '.php';
if (file_exists($file))
require_once($file);
$file2 = $opt['rootpath'] . 'lib2/class.' . $class_name2 . '.php';
if (file_exists($file)) {
require_once($file);
} elseif(file_exists($file2)) {
require_once($file2);
}
}
// yepp, we will use UTF-8
@@ -107,10 +107,13 @@
<a href="{$phpbb_link|escape}" style="color: rgb(88, 144, 168); text-decoration: none;">{t 1=$phpbb_name|escape}New forum topcis (%1){/t}</a>
</p>
</div>
{* adapted by bohrsty for forums-posts on homepage using RSS-feed
<div class="content-txtbox-noshade">
<p style="line-height: 1.6em;">Unser neues Forum findest du unter <a href="http://forum.geocaching-network.org">forum.geocaching-network.org</a>.</p>
<div class="buffer" style="width: 500px;">&nbsp;</div>
</div>
*}
{forum}
{*
<ul class="nodot">
{foreach from=$phpbb_topics item=phpbbItem}

0 comments on commit f6d0f92

Please sign in to comment.
You can’t perform that action at this time.