[Scummvm-cvs-logs] SF.net SVN: scummvm: [23432] web/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Jul 20 22:37:38 CEST 2006


Revision: 23432
          http://svn.sourceforge.net/scummvm/?rev=23432&view=rev
Author:   fingolfin
Date:     2006-07-08 11:14:10 -0700 (Sat, 08 Jul 2006)

Log Message:
-----------
Added Atom + RSS 2.0 news feeds

Modified Paths:
--------------
    web/trunk/index.php

Added Paths:
-----------
    web/trunk/feed-atom.php
    web/trunk/feed-rss20.php
    web/trunk/include/news.php

Added: web/trunk/feed-atom.php
===================================================================
--- web/trunk/feed-atom.php	2006-07-08 17:38:00 UTC (rev 23431)
+++ web/trunk/feed-atom.php	2006-07-08 18:14:10 UTC (rev 23432)
@@ -0,0 +1,55 @@
+<?php
+$file_root = ".";
+
+// load libraries
+require($file_root."/include/"."incl.php");
+require($file_root."/include/"."news.php");
+
+
+header("Content-type: application/atom+xml");
+?>
+<feed xml:lang="en" xml:base="http://<?php echo $_SERVER['SERVER_NAME'];?>/" xmlns="http://www.w3.org/2005/Atom">
+    <id>tag:scummvm.org,2006:news/atom</id>
+    <title>ScummVM news</title>
+    <link rel="self" href="http://<?php echo $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>"/>
+
+    <author>
+
+        <name>ScummVM team</name>
+
+        <uri>http://scummvm.org/</uri>
+
+    </author>
+
+<?php
+
+// Fetch news (only show the first 5 records)
+$news = list_latest_news(5);
+
+// Get date of latest (first) item
+$published = date("Y-m-d\Th:i:s\Z", $news[0]["date"] - date("Z", $news[0]["date"]));
+
+echo "<updated>$published</updated>";
+
+// loop and gather news
+$newslist = "";
+while (list($key,$item) = each($news)) {
+  // Display news item
+  $newslist .= 
+
+       '<entry>'.
+	 '<title type="html">'.htmlentities($item["title"]).'</title>'.
+
+         '<id>tag:scummvm.org,2006:news/atom/'.$item["date"].'</id>'.
+	 '<link rel="alternate">http://scummvm.org/?shownews=archive#'.date("Y-m-d", $item["date"]).'</link>'.
+	 '<content type="html">'.htmlentities($item["body"]).'</content>'.
+	 '<published>'.date("Y-m-d\Th:i:s\Z", $item["date"] - date("Z", $item["date"])).'</published>'.
+
+         '<author><name>'.$item["author"].'</name></author>'.
+       '</entry>';
+} // end of news loop
+
+echo $newslist;
+
+?>
+</feed>


Property changes on: web/trunk/feed-atom.php
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: web/trunk/feed-rss20.php
===================================================================
--- web/trunk/feed-rss20.php	2006-07-08 17:38:00 UTC (rev 23431)
+++ web/trunk/feed-rss20.php	2006-07-08 18:14:10 UTC (rev 23432)
@@ -0,0 +1,34 @@
+<?php
+$file_root = ".";
+
+// load libraries
+require($file_root."/include/"."incl.php");
+require($file_root."/include/"."news.php");
+
+header("Content-type: text/xml");
+?>
+<rss version="2.0">
+    <channel>
+        <title>ScummVM</title>
+        <link>http://www.scummvm.org/</link>
+        <description>ScummVM - http://www.scummvm.org/</description>
+        <language>en</language>
+
+<?php
+
+// Fetch news (only show the first 5 records)
+$news = list_latest_news(5);
+
+// Display news items
+while (list($key,$item) = each($news)) {
+  echo '<item>'.
+	 '<title>'.htmlentities($item["title"]).'</title>'.
+	 '<link>http://www.scummvm.org/index.php#'.date("Y-m-d", $item["date"]).'</link>'.
+	 '<description>'.htmlentities($item["body"]).'</description>'.
+	 '<pubDate>'.date("r", $item["date"]).'</pubDate>'.
+       '</item>';
+} // end of news loop
+?>
+
+  </channel>
+</rss>


Property changes on: web/trunk/feed-rss20.php
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: web/trunk/include/news.php
===================================================================
--- web/trunk/include/news.php	2006-07-08 17:38:00 UTC (rev 23431)
+++ web/trunk/include/news.php	2006-07-08 18:14:10 UTC (rev 23432)
@@ -0,0 +1,68 @@
+<?php
+/*
+ * Read the $num most recent news items (if $num is -1, then read all),
+ * and return them in an array, ordered by date.
+ *
+ * TODO: It might be more elegant to solve this with a "News" class
+ * which could offer extended functionality. I.e. it would allow
+ * code to query the total number of news items, would load and cache news items
+ * on-demand etc.
+ */
+function list_latest_news ($num = -1) {
+  global $file_root;
+
+  $news_files = get_files($file_root."/news","xml");
+  $news_files = array_reverse ($news_files);
+  
+  $news = array();
+  
+  // loop and display news
+  $c = 0;
+  while (list($key,$item) = each($news_files)) {
+	// Load news item file
+	$file = $file_root."/news/".$item;
+	if (!file_exists($file)) {
+	  continue;
+	}
+
+	$fp = @fopen($file, "r");
+	$data = fread($fp, filesize($file));
+	@fclose($fp);
+
+	// Parse the (pseudo-XML) contents of the news file.
+
+	$news[$c]["date"] = "";
+	if (eregi("<DATE>(.*)</DATE>", $data, $out)) {
+	  $news[$c]["date"] = strtotime($out[1]);
+	}
+
+	$news[$c]["author"] = "";
+	if (eregi("<AUTHOR>(.*)</AUTHOR>", $data, $out)) {
+	  $news[$c]["author"] = "Posted by ".$out[1];
+	}
+
+	$news[$c]["title"] = "";
+	if (eregi("<NAME>(.*)</NAME>", $data, $out)) {
+	  $news[$c]["title"] = $out[1];
+	}
+
+	$news[$c]["img"] = "";
+	if (eregi("<IMG>(.*)</IMG>", $data, $out)) {
+	  $news[$c]["img"] = $out[1];
+	}
+
+	$news[$c]["body"] = "";
+	if (eregi("<BODY>(.*)</BODY>", $data, $out)) {
+	  $news[$c]["body"] = $out[1];
+	}
+
+	$c++;
+	
+	if ($num >= 0 && $c >= $num) {
+	  break;
+	}
+  }
+
+  return $news;
+}
+?>
\ No newline at end of file


Property changes on: web/trunk/include/news.php
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Modified: web/trunk/index.php
===================================================================
--- web/trunk/index.php	2006-07-08 17:38:00 UTC (rev 23431)
+++ web/trunk/index.php	2006-07-08 18:14:10 UTC (rev 23432)
@@ -4,6 +4,7 @@
 // load libraries
 require($file_root."/include/"."incl.php");
 require($file_root."/include/"."scr-categories.php");
+require($file_root."/include/"."news.php");
 
 html_page_header('ScummVM :: Home', array("index.css"));
 
@@ -211,72 +212,33 @@
 
 html_content_begin('Latest Developments');
 
-//display News
-
-// get list of news items
-$news = get_files($file_root."/news","xml");
-$news = array_reverse ($news);
-
 // loop and display news
-$c = 0;
-while (list($key,$item) = each($news)) {
-  $c++;
-	
-  // Load news item (it's in a pseudo XML format).
-  $file = $file_root."/news/".$item;
-  if (file_exists($file)) { 
-    $fp = @fopen($file, "r");
-    $data = fread($fp, filesize($file));
-    @fclose($fp);
+if ($shownews) {
+  $news = list_latest_news(-1);
+} else {
+  $news = list_latest_news(4);
+}
 
-    $news_date = "";
-    if (eregi("<DATE>(.*)</DATE>", $data, $out)) {
-      $news_date = strtotime($out[1]);
-    }
-
-    $news_author = "";
-    if (eregi("<AUTHOR>(.*)</AUTHOR>", $data, $out)) {
-      $news_author = "Posted by ".$out[1];
-    }
-
-    $news_title = "";
-    if (eregi("<NAME>(.*)</NAME>", $data, $out)) {
-      $news_title = $out[1];
-    }
-
-    $news_img = "";
-    if (eregi("<IMG>(.*)</IMG>", $data, $out)) {
-      $news_img = $out[1];
-    }
-
-    $news_body = "";
-    if (eregi("<BODY>(.*)</BODY>", $data, $out)) {
-      $news_body = $out[1];
-    }
-  }
-	
+while (list($key,$item) = each($news)) {
   // Display news item
-
   echo '<div class="par-item">'.
 	 '<div class="par-head">'.
-	   '<a name="' . date("Y-m-d", $news_date) . '"></a><span class="newsdate">' . date("M. jS, Y", $news_date) . "</span>: ".
-           $news_title.
+	   '<a name="' . date("Y-m-d", $item["date"]) . '"></a><span class="newsdate">' . date("M. jS, Y", $item["date"]) . "</span>: ".
+           $item["title"].
 	 '</div>'.
          '<div class="par-content">'.
-		 	 '<div class="news-author">'.$news_author."</div> ".
-  		$news_img.
-		$news_body.
+		 	 '<div class="news-author">'.$item["author"]."</div> ".
+  		$item["img"].
+		$item["body"].
 	 '</div>'.
        '</div>';
-	
-	
-  // Only show first five records, unless we are in "news" mode
-  if ($c == 4 && !$shownews) {
-    echo '<p class="bottom-link"><a href="?shownews=archive">More News...</a></p>'."\n";
-    break;
-  }
 } // end of news loop
 
+// Show 'More News...' link, unless we are already in the showsnews mode.
+if (!$shownews) {
+  echo '<p class="bottom-link"><a href="?shownews=archive">More News...</a></p>'."\n";
+}
+
 html_content_end();
 html_page_footer();
 






More information about the Scummvm-git-logs mailing list