From f6d0f92d581f6a6815f7badcd615610e9962d98e Mon Sep 17 00:00:00 2001 From: Nils Bohrs Date: Wed, 26 Sep 2012 22:21:15 +0200 Subject: [PATCH 1/2] added funcionality to get news and forum posts from RSS-feeds --- htdocs/index.php | 22 ++++++-- htdocs/lib2/RSSParser.class.php | 78 +++++++++++++++++++++++++++++ htdocs/lib2/common.inc.php | 9 +++- htdocs/templates2/ocstyle/start.tpl | 3 ++ 4 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 htdocs/lib2/RSSParser.class.php diff --git a/htdocs/index.php b/htdocs/index.php index 9cd94589..ea197dc0 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -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'] != '')); diff --git a/htdocs/lib2/RSSParser.class.php b/htdocs/lib2/RSSParser.class.php new file mode 100644 index 00000000..ffb9c90a --- /dev/null +++ b/htdocs/lib2/RSSParser.class.php @@ -0,0 +1,78 @@ + '."\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 .= '

'."\n"; + $html .= strftime('%e. %B %Y',strtotime($item->pubDate)).' - '. $item->title; + $html .= '

 [mehr...]

'."\n"; + $html .= '

'.$item->description.'

'."\n"; + } + + // increment counter + $i++; + } + + // finish html + $html .= '
 
'."\n"; + } + catch(Exception $e) { + $error = true; + } + } + } + + // return + if(!$error) { + return $html; + } else { + return ''; + } + } +} + +?> \ No newline at end of file diff --git a/htdocs/lib2/common.inc.php b/htdocs/lib2/common.inc.php index 489df313..45ab8959 100644 --- a/htdocs/lib2/common.inc.php +++ b/htdocs/lib2/common.inc.php @@ -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 diff --git a/htdocs/templates2/ocstyle/start.tpl b/htdocs/templates2/ocstyle/start.tpl index 05544fcb..5397a481 100644 --- a/htdocs/templates2/ocstyle/start.tpl +++ b/htdocs/templates2/ocstyle/start.tpl @@ -107,10 +107,13 @@ {t 1=$phpbb_name|escape}New forum topcis (%1){/t}

+{* adapted by bohrsty for forums-posts on homepage using RSS-feed

Unser neues Forum findest du unter forum.geocaching-network.org.

 
+*} +{forum} {*