Merge pull request #42 from bohrsty/news_and_forum_from_rss-feed
News and forum from rss feed
This commit is contained in:
commit
b0ce657556
@ -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,9 +53,19 @@
|
||||
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
|
||||
*/
|
||||
$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']);
|
||||
|
||||
|
78
htdocs/lib2/RSSParser.class.php
Normal file
78
htdocs/lib2/RSSParser.class.php
Normal file
@ -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\.&%\$\-]+)*@)*((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\.\,\?\'\\\+&%\$#\=~_\-]+))*$!',$url)) {
|
||||
$error = true;
|
||||
} else {
|
||||
|
||||
// output
|
||||
$html = '<div class="buffer" style="width: 500px;height: 2px;"> </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;"> [<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;"> </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_name2 . '.class.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;"> </div>
|
||||
</div>
|
||||
*}
|
||||
{$forum}
|
||||
{*
|
||||
<ul class="nodot">
|
||||
{foreach from=$phpbb_topics item=phpbbItem}
|
||||
|
Loading…
x
Reference in New Issue
Block a user