////////////////////////////////////////////////////////////////////////
//
// Filename: rss/{news,tips}.rss
// Purpose : Serve news or articles tips as rss stream
// Method : RSS-0.91
// Author : J.van.der.Steen@gobase.org
// Date : Thu Sep 15 23:08:45 CEST 2005
//
////////////////////////////////////////////////////////////////////////
require("{$_SERVER['DOCUMENT_ROOT']}/php/gobase.php");
$module_list = gobase_modules(array
( 'img'
, 'news'
, 'tips'
, 'sgf'
)
);
foreach($module_list as $module) {
require("{$_SERVER['DOCUMENT_ROOT']}/php/$module.php");
}
function reEncodeString($string)
//
// Convert entities in supplied string to XML compliant string
//
{
$tmp = $string;
$table = array_diff(
get_html_translation_table(HTML_ENTITIES)
, get_html_translation_table()
);
foreach ($table as $item) {
$tmp = str_replace($item, "&" . substr($item, 1), $tmp);
}
return $tmp;
}
function rss_games()
//
// Collect new games
//
{
$newgames = array();
$days = array(1,2,3,4,5,6,7);
$mods = '/var/www/gobase.org/games/admin/mods';
foreach ($days as $kday => $day) {
if (file_exists("$mods/sgf.$day")) {
$games = file("$mods/sgf.$day");
if (!count($games)) continue;
$newgames[$kday] = array(
'url' => '/information/whatsnew/'
, 'date' => date('Y-m-d', strtotime("-$day days"))
, 'time' => '00:15:00'
, 'text' => "New games (select to replay):\n<p>\n"
);
foreach ($games as $kgame => $path) {
$url = str_replace( array( './' )
, array( '/games/')
, $path
) ;
$sgfphp = '/home/jansteen/gobase/bin/sgfphp';
eval("\$prop = " . `$sgfphp {$_SERVER['DOCUMENT_ROOT']}/$url` . ";");
$text = "{$prop['dt']} {$prop['ev']} (" . strtolower($prop['pc']) . "): ";
$text .= "{$prop['pb']},{$prop['br']} vs. {$prop['pw']},{$prop['wr']}";
$newgames[$kday]['text'] .= "<a target='gobase_gam' href='/replay/?gam=$url'>$text</a><br>\n";
}
}
}
return $newgames;
}
function rss_items()
//
// Emit news items as RSS records
//
{
global $news;
global $tips;
$rss_articles = array_merge($news, $tips);
$rss_articles = array_merge($rss_articles, rss_games());
uasort($rss_articles, 'cmp_news');
$now = strtotime(date('Y-m-d'));
foreach ($rss_articles as $key => $val) {
$news_item = $val;
if (!empty($news_item['expired'])) continue;
//
// Tips might not have an URL reference.
//
if (empty($news_item['url'])) $news_item['url'] = '/';
//
// Two month old, then break
//
$then = strtotime($news_item['date']);
if ($now - $then > 2 * (60 * 60 * 24 * 31)) break;
if (!preg_match('/^http:/', $news_item['url'])) {
$news_item['url'] = "http://gobase.org{$news_item['url']}";
}
$news_item['url'] = htmlentities($news_item['url']);
print "- \n";
print " ";
if (!empty($news_item['title'])) {
print $news_item['title'];
} else {
print $news_item['url'];
}
print "\n";
print " ";
print reEncodeString(strip_tags($news_item['text']));
print "\n";
if (false && !empty($news_item['ccode'])) {
flag_emit($news_item['ccode']);
}
if (!empty($news_item['url'])) {
print " ";
print "{$news_item['url']}";
print "\n";
}
if (false && !empty($news_item['pics'])) {
foreach ($news_item['pics'] as $k => $img) {
print " \n";
}
}
if (false && !empty($news_item['pics'])) {
foreach ($news_item['pics'] as $k => $img) {
print "\n";
print "{$img['alt']}\n";
print "http://gobase.org{$img['src']}\n";
print "http://gobase.org{$img['url']}\n";
print "{$img['w']}\n";
print "{$img['h']}\n";
print "\n";
}
}
//
// Emit date in RFC-822 format
//
if (!isset($news_item['time'])) {
$news_item['time'] = "00:00:00";
}
print " ";
print date( 'D, d M Y H:i:s O'
, strtotime( $news_item['date']
. " "
. $news_item['time']
)
) ;
print "\n";
print " editor@gobase.org\n";
print " \n";
print "
\n";
}
}
?>
header ("Content-type: application/rss+xml");
print "\n";
print "\n";
print "\n";
print "GoBase.org:Go games, Go information and Go study tools.\n";
print "http://gobase.org\n";
print "en-gb\n";
print "Copyright: GoBase.org, J. van der Steen\n";
print "GoBase.org | news\n";
print "\n";
print "GoBase.org\n";
print "/img/new/gobase-org-small.gif\n";
print "/\n";
print "\n";
rss_items();
print "\n";
print "\n";
?>