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}
{*
{foreach from=$phpbb_topics item=phpbbItem}
From 275582628b4c6934dbc28a4b44ad3263bf65ae23 Mon Sep 17 00:00:00 2001
From: Nils Bohrs
Date: Tue, 2 Oct 2012 22:48:14 +0200
Subject: [PATCH 2/2] bugfixes and typo after testing news and forum via
RSS-feed
---
htdocs/index.php | 3 ++-
htdocs/lib2/common.inc.php | 2 +-
htdocs/templates2/ocstyle/start.tpl | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/htdocs/index.php b/htdocs/index.php
index ea197dc0..7fb8bb94 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -59,12 +59,13 @@
* requires $opt['forum']['count'] in settings for number of lastest forum-posts
* requires $opt['forum']['url'] in settings: RSS-feed-URL of the forum
*/
+ $tpl->assign('phpbb_enabled', $opt['forum']['count'] > 0);
$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'] != ''));
+// $tpl->assign('phpbb_enabled', ($opt['cron']['phpbbtopics']['url'] != ''));
$tpl->assign('phpbb_name', $opt['cron']['phpbbtopics']['name']);
$tpl->assign('phpbb_link', $opt['cron']['phpbbtopics']['link']);
diff --git a/htdocs/lib2/common.inc.php b/htdocs/lib2/common.inc.php
index 45ab8959..41808e1e 100644
--- a/htdocs/lib2/common.inc.php
+++ b/htdocs/lib2/common.inc.php
@@ -21,7 +21,7 @@ function __autoload($class_name)
$class_name = str_replace('_', '/', $class_name);
$file = $opt['rootpath'] . '../lib/classes/' . $class_name . '.php';
- $file2 = $opt['rootpath'] . 'lib2/class.' . $class_name2 . '.php';
+ $file2 = $opt['rootpath'] . 'lib2/' . $class_name2 . '.class.php';
if (file_exists($file)) {
require_once($file);
} elseif(file_exists($file2)) {
diff --git a/htdocs/templates2/ocstyle/start.tpl b/htdocs/templates2/ocstyle/start.tpl
index 5397a481..93ce0ab4 100644
--- a/htdocs/templates2/ocstyle/start.tpl
+++ b/htdocs/templates2/ocstyle/start.tpl
@@ -113,7 +113,7 @@
*}
-{forum}
+{$forum}
{*
{foreach from=$phpbb_topics item=phpbbItem}