Update of /cvsroot/php-blog/serendipity/plugins/serendipity_plugin_remoterss
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13233/plugins/serendipity_plugin_remoterss
Added Files:
serendipity_plugin_remoterss.php
Log Message:
News remote rss plugin contributed by udo gerhards
--- NEW FILE: serendipity_plugin_remoterss.php ---
<?php
// Contributed by Udo Gerhards <ud...@ba...>
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_REMOTERSS_TITLE', 'Fremder RSS Feed');
@define('PLUGIN_REMOTERSS_BLAHBLAH', 'Zeigt Einträge eines externen RSS-Feeds an');
@define('PLUGIN_REMOTERSS_NUMBER', 'Anzahl der Einträge');
@define('PLUGIN_REMOTERSS_NUMBER_BLAHBLAH', 'Wieviele Einträge sollen angezeigt werden? (Standard: alle im Feed)');
@define('PLUGIN_REMOTERSS_SIDEBARTITLE', 'Feed-Titel');
@define('PLUGIN_REMOTERSS_SIDEBARTITLE_BLAHBLAH', 'Titel der Feed-Anzeige in der Sidebar des Blogs');
@define('PLUGIN_REMOTERSS_RSSURI', 'RSS-URI');
@define('PLUGIN_REMOTERSS_RSSURI_BLAHBLAH', 'URI des RSS-Feeds, der angezeigt werden soll');
@define('PLUGIN_REMOTERSS_RSSTARGET', 'Link-Target');
@define('PLUGIN_REMOTERSS_RSSTARGET_BLAHBLAH', 'Target des Links zu einem der angezeigten RSS-Einträge (Standard: _blank)');
@define('PLUGIN_REMOTERSS_NOURI', 'Kein RSS-Feed gewählt');
@define('PLUGIN_REMOTERSS_CACHETIME', 'Wann wird der Feed aktualisiert?');
@define('PLUGIN_REMOTERSS_CACHETIME_BLAHBLAH', 'Die Inhalte des fremden Feeds werden gecached. Sobald der Cache älter ist als X Minuten wird er aktualisiert (Standard: 3 Stunden)');
break;
case 'en':
case 'es':
default:
@define('PLUGIN_REMOTERSS_TITLE', 'Remote RSS Feed');
@define('PLUGIN_REMOTERSS_BLAHBLAH', 'Show items of a remote RSS feed');
@define('PLUGIN_REMOTERSS_NUMBER', 'Number of entries');
@define('PLUGIN_REMOTERSS_NUMBER_BLAHBLAH', 'How many entries should be displayed? (Default: every entry of the feed)');
@define('PLUGIN_REMOTERSS_SIDEBARTITLE', 'Feed-Title');
@define('PLUGIN_REMOTERSS_SIDEBARTITLE_BLAHBLAH', 'Title of the feed in the blog sidebar');
@define('PLUGIN_REMOTERSS_RSSURI', 'RSS URI');
@define('PLUGIN_REMOTERSS_RSSURI_BLAHBLAH', 'URI of the RSS feed which you want to display');
@define('PLUGIN_REMOTERSS_NOURI', 'No RSS feed selected');
@define('PLUGIN_REMOTERSS_RSSTARGET', 'RSS target');
@define('PLUGIN_REMOTERSS_RSSTARGET_BLAHBLAH', 'Target of the link to one of the displayed RSS items (Default: _blank)');
@define('PLUGIN_REMOTERSS_CACHETIME', 'When to update the feed?');
@define('PLUGIN_REMOTERSS_CACHETIME_BLAHBLAH', 'The contents of a feed are stored in a cache which will be updated as soon as its older than X minutes (Default: 3 hours)');
break;
}
class serendipity_plugin_remoterss extends serendipity_plugin {
function introspect(&$propbag) {
$propbag->add('name', PLUGIN_REMOTERSS_TITLE);
$propbag->add('description', PLUGIN_REMOTERSS_BLAHBLAH);
$propbag->add('configuration', array('number', 'dateformat', 'sidebartitle', 'rssuri', 'target', 'cachetime'));
}
function introspect_config_item($name, &$propbag) {
switch($name) {
case 'number':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_REMOTERSS_NUMBER);
$propbag->add('description', PLUGIN_REMOTERSS_NUMBER_BLAHBLAH);
break;
case 'dateformat':
$propbag->add('type', 'string');
$propbag->add('name', GENERAL_PLUGIN_DATEFORMAT);
$propbag->add('description', sprintf(GENERAL_PLUGIN_DATEFORMAT_BLAHBLAH, '%A, %B %e. %Y'));
break;
case 'sidebartitle':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_REMOTERSS_SIDEBARTITLE);
$propbag->add('description', PLUGIN_REMOTERSS_SIDEBARTITLE_BLAHBLAH);
break;
case 'rssuri':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_REMOTERSS_RSSURI);
$propbag->add('description', PLUGIN_REMOTERSS_RSSURI_BLAHBLAH);
break;
case 'target':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_REMOTERSS_RSSTARGET);
$propbag->add('description', PLUGIN_REMOTERSS_RSSTARGET_BLAHBLAH);
break;
case 'cachetime':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_REMOTERSS_CACHETIME);
$propbag->add('description', PLUGIN_REMOTERSS_CACHETIME_BLAHBLAH);
break;
default:
return false;
}
return true;
}
function generate_content(&$title) {
global $serendipity;
$number = $this->get_config('number');
$dateformat = $this->get_config('dateformat');
$sidebartitle = $this->get_config('sidebartitle');
$rssuri = $this->get_config('rssuri');
$target = $this->get_config('target');
$target = $this->get_config('cachetime');
$title = $sidebartitle;
if (!$number || !is_numeric($number) || $number < 1) {
$showAll = true;
} else {
$showAll = false;
}
if (!$dateformat || strlen($dateformat) < 1) {
$dateformat = '%A, %B %e. %Y';
}
if (!$target || strlen($target) < 1) {
$target = '_blank';
}
if (!$cachetime || !is_numeric($cachetime)) {
$cachetime = 10800; // 3 hours in seconds
}
if (trim($rssuri)) {
$feedcache = $serendipity['serendipityPath'] . 'archives/remoterss_cache_' . preg_replace('@[^a-z0-9]*@i', '', $rssuri) . '.dat';
if (!file_exists($feedcache) || filemtime($feedcache) < (time() - $cachetime)) {
require_once 'bundled-libs/Onyx/RSS.php';
$c = &new Onyx_RSS();
$c->parse($rssuri);
$i = 0;
$content = '';
while (($showAll || ($i < $number)) && ($item = $c->getNextItem())) {
$content .= '<a href="' . $item['link'] . '" target="'.$target.'">' . $item['title'] . "</a><br>\n";
$item['timestamp'] = strtotime(isset($item['pubdate']) ? $item['pubdate'] : $item['dc:date']);
if (!($item['timestamp'] == -1)) {
$content .= '<div class="serendipitySideBarDate">'
. htmlspecialchars(serendipity_formatTime($dateformat, $item['timestamp']))
. '</div><br />';
}
++$i;
}
$fp = @fopen($feedcache, 'w');
if ($fp) {
fwrite($fp, $content);
fclose($fp);
} else {
echo '<!-- Cache failed to ' . $feedcache . ' in ' . getcwd() . ' --><br />';
}
} else {
$content = file_get_contents($feedcache);
}
echo $content;
} else {
echo PLUGIN_REMOTERSS_NOURI;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
|