[Gnucash-changes] r14290 - htdocs/trunk - Atom 1.0 feed generator;
refactoring of news script to support, general cleanliness.
Joshua Sled
jsled at cvs.gnucash.org
Thu Jun 1 21:01:27 EDT 2006
Author: jsled
Date: 2006-06-01 21:01:26 -0400 (Thu, 01 Jun 2006)
New Revision: 14290
Trac: http://svn.gnucash.org/trac/changeset/14290
Added:
htdocs/trunk/atom-feed.php
Modified:
htdocs/trunk/index.phtml
htdocs/trunk/news/news-script.php
htdocs/trunk/oldnews.phtml
Log:
Atom 1.0 feed generator; refactoring of news script to support, general cleanliness.
Added: htdocs/trunk/atom-feed.php
===================================================================
--- htdocs/trunk/atom-feed.php 2006-06-01 23:06:01 UTC (rev 14289)
+++ htdocs/trunk/atom-feed.php 2006-06-02 01:01:26 UTC (rev 14290)
@@ -0,0 +1,64 @@
+<?php
+ // TODO:
+ // - reasonable permalinks
+
+ include("local.php");
+
+ $contentType = "application/atom+xml";
+ $overrideContentType = $_GET["content-type"];
+ if (isset($overrideContentType))
+ {
+ $contentType = $overrideContentType;
+ }
+ $charset = "iso-8859-1";
+ header("Content-Type: $contentType; charset=$charset");
+
+?>
+<?="<?xml version=\"1.0\" encoding=\"<?=$charset?>\"?>"?>
+<?php
+ $entry_count = 10;
+ $newsdir = "${top_dir}/news/";
+ include("$top_dir/news/news-script.php");
+?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <id>http://www.gnucash.org/atom.php</id>
+ <title>GnuCash News</title>
+ <generator>GnuCash htdocs/trunk/atom-feed.php 1.0 <gnucash-devel at gnucash.org></generator>
+ <logo>http://www.gnucash.org/images/gnucash_logo.png</logo>
+ <link href="http://www.gnucash.org/" />
+
+ <?php
+ $news_items = get_news($newsdir, $newsdir);
+ $news_items = array_slice($news_items, 0, $entry_count);
+ reset($news_items);
+ $most_recent = null;
+ ?>
+ <updated><?=$most_recent?></updated>
+
+ <?php for (reset($news_items); $key = key($news_items); next($news_items))
+ {
+ $fa = file($key);
+ $n = count($fa);
+ $title = strip_tags(chop($fa[0]));
+ $update_date = chop($fa[1]);
+ if ($most_recent == null || $update_date > $most_recent )
+ {
+ $most_recent = $update_date;
+ }
+ ?>
+ <entry>
+ <id>urn:x-gnucash:news:<?= $key ?></id>
+ <title><?= $title ?></title>
+ <updated><?= $update_date ?></updated>
+ <content type="xhtml">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <? for ($i=2; $i<$n; $i++) {
+ print $fa[$i];
+ } ?>
+ </div>
+ </content>
+ </entry>
+ <?php } ?>
+
+ <updated><?= $most_recent ?></updated>
+</feed>
Modified: htdocs/trunk/index.phtml
===================================================================
--- htdocs/trunk/index.phtml 2006-06-01 23:06:01 UTC (rev 14289)
+++ htdocs/trunk/index.phtml 2006-06-02 01:01:26 UTC (rev 14290)
@@ -40,14 +40,15 @@
<?php
echo("<!-- top_dir = $top_dir , home = $home -->\n");
-# News will continue to be translated separately because
-# of the .txt format.
+ # News will continue to be translated separately because
+ # of the .txt format.
# for english, the lang and en news path are identical
$en_newspath = $top_dir."/news/";
$lang_newspath = $top_dir."/news/".$lang_dir."/";
$oldnews = false;
- include("$top_dir/news/news-script.php"); ?>
-
+ include("$top_dir/news/news-script.php");
+ emit_news($en_newspath, $lang_newspath, $oldnews);
+?>
<div class="newsborder">
<div class="newsheader"><img alt="news panel" src="<?=$top_dir;?>/images/icons/document.txt.gif">
<a href="oldnews.phtml">Older Announcements ...</a>
Modified: htdocs/trunk/news/news-script.php
===================================================================
--- htdocs/trunk/news/news-script.php 2006-06-01 23:06:01 UTC (rev 14289)
+++ htdocs/trunk/news/news-script.php 2006-06-02 01:01:26 UTC (rev 14290)
@@ -23,14 +23,9 @@
// second line does not create a valid timestamp, the inode
// change time of file is used.
- # Be sure to define the following path to newsdirs
- if (!$en_newspath) { exit; }
- if (!$lang_newspath) { exit; }
+ function get_news($en_newspath, $lang_newspath)
+ {
- // This is how many news items to display on the main page.
- // Everything after this is displayed on the "oldnews" page.
- $cutoff = 10;
-
// array of displayed filenames is indexed with filenames, holds timestamps.
$newsfile = array();
@@ -46,15 +41,15 @@
$hd = dir($lang_newspath);
// Get all translated files in the translated-news directory
- while( $filename = $hd->read() ) {
- $s=strtolower($filename);
- if (strstr($s, ".news")) {
+ while ($filename = $hd->read()) {
+ $s = strtolower($filename);
+ if (strstr($s, ".news")) {
$lang_files[$filename] = $lang_newspath.$filename;
$display_filename = $lang_newspath.$filename;
- //echo("<!-- found locale news: $display_filename -->\n");
+ // echo("<!-- found locale news: $display_filename -->\n");
$about = file($display_filename);
- $lastchanged=$about[1];
- if($lastchanged == "\n")
+ $lastchanged = $about[1];
+ if ($lastchanged == "\n")
{
$lastchanged = date("Y-m-d H:m:s", filectime($display_filename));
}
@@ -65,22 +60,22 @@
// ------------------------------------------
// Are there english language articles to display?
- $hd = dir($en_newspath);
+ $hd = dir($en_newspath);
// Get all the english-language files, and display them
// only if there isn't a matching native language article.
- while( $filename = $hd->read() ) {
- $s=strtolower($filename);
- if (strstr($s, ".news")) {
- //echo("<!-- found english file: $s -->\n");
+ while ($filename = $hd->read()) {
+ $s = strtolower($filename);
+ if (strstr($s, ".news")) {
+ // echo("<!-- found english file: $s -->\n");
if (! array_key_exists($filename, $lang_files)) {
$display_filename = $en_newspath.$filename;
- //echo("<!-- using untranslated english file: $display_filename -->\n");
+ // echo("<!-- using untranslated english file: $display_filename -->\n");
$about = file($display_filename);
- $lastchanged=$about[1];
- if($lastchanged == "\n")
+ $lastchanged = $about[1];
+ if ($lastchanged == "\n")
{
- $lastchanged = date("Y-m-d H:m:s", filectime($display_filename));
+ $lastchanged = date("Y-m-d H:m:s", filectime($display_filename));
}
$newsfile[$display_filename] = $lastchanged;
}
@@ -92,28 +87,50 @@
// Sort files in descending date order
arsort($newsfile);
+ return $newsfile;
+}
+
+
+function emit_news($en_newspath, $lang_newspath, $oldnews)
+{
+ global $top_dir;
+
+ # Be sure to define the following path to newsdirs
+ if (!$en_newspath) { exit; }
+ if (!$lang_newspath) { exit; }
+
+ // This is how many news items to display on the main page.
+ // Everything after this is displayed on the "oldnews" page.
+ $cutoff = 10;
+
+ $newsfiles = get_news($en_newspath, $lang_newspath);
+ if ($oldnews)
+ {
+ $newsfile = array_slice($newsfiles, $cutoff, -1, true);
+ }
+ else
+ {
+ $newsfile = array_slice($newsfiles, 0, $cutoff, true);
+ }
// Output files to browser
$filecount = 0;
for(reset($newsfile); $key = key($newsfile); next($newsfile))
{
- $filecount++;
- if ( ($oldnews && $filecount > $cutoff) ||
- (! $oldnews && $filecount <= $cutoff) )
- {
- $fa = file($key);
- $n=count($fa);
-
- echo ("<div class=\"newsborder\"><div class=\"newsheader\">");
- echo("<img alt=\"news panel\" src=\"${top_dir}/images/icons/document.txt.gif\"> ");
- print $fa[0];
- print " - <b>" . $newsfile[$key] . "</b></div>\n";
- echo "<div class=\"newsinner\">";
- for ($i=2; $i<$n; $i++) {
- print $fa[$i];
- }
- echo "</div>";
- echo "</div>";
- }
+ $fa = file($key);
+ $n = count($fa);
+?>
+<div class="newsborder">
+ <div class="newsheader">
+ <img alt="news panel" src="<?=${top_dir}?>/images/icons/document.txt.gif" width="16" height="16" alt="[news]"/>
+ <?= $fa[0]; ?> - <b><?= $newsfile[$key] ?></b>
+ </div>
+ <div class="newsinner">
+ <? for ($i=2; $i<$n; $i++) {
+ print $fa[$i];
+ } ?>
+ </div>
+</div>
+<?
}
-
+}
?>
Modified: htdocs/trunk/oldnews.phtml
===================================================================
--- htdocs/trunk/oldnews.phtml 2006-06-01 23:06:01 UTC (rev 14289)
+++ htdocs/trunk/oldnews.phtml 2006-06-02 01:01:26 UTC (rev 14290)
@@ -16,12 +16,13 @@
<?php
echo("<!-- top_dir = $top_dir , home = $home -->\n");
-# News will continue to be translated separately because
-# of the .txt format.
+ # News will continue to be translated separately because
+ # of the .txt format.
# for english, the lang and en news path are identical
$en_newspath = $top_dir."/news/";
$lang_newspath = $top_dir."/news/".$lang_dir."/";
$oldnews = true;
- include("$top_dir/news/news-script.php"); ?>
-
+ include("$top_dir/news/news-script.php");
+ emit_news($en_newspath, $lang_newspath, $oldnews);
+?>
<?php include("externals/footer.phtml"); ?>
More information about the gnucash-changes
mailing list