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

fredrik_w at users.sourceforge.net fredrik_w at users.sourceforge.net
Wed Jul 29 11:03:27 CEST 2009


Revision: 42882
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42882&view=rev
Author:   fredrik_w
Date:     2009-07-29 09:03:27 +0000 (Wed, 29 Jul 2009)

Log Message:
-----------
#2820377: "WEB: Unable to post more than single news item per day"

Modified Paths:
--------------
    web/trunk/.htaccess
    web/trunk/include/Models/NewsModel.php
    web/trunk/include/Objects/News.php
    web/trunk/include/Pages/NewsPage.php
    web/trunk/templates/feed_atom.tpl
    web/trunk/templates/feed_rss.tpl
    web/trunk/templates/news.tpl

Modified: web/trunk/.htaccess
===================================================================
--- web/trunk/.htaccess	2009-07-29 08:55:17 UTC (rev 42881)
+++ web/trunk/.htaccess	2009-07-29 09:03:27 UTC (rev 42882)
@@ -51,7 +51,7 @@
 ## 
 # News
 ##
-RewriteRule		^(news)(/([0-9]{8}|archive))?/?$							?p=$1&d=$3 [L]
+RewriteRule		^(news)(/([0-9]{8}[a-z]?|archive))?/?$							?p=$1&d=$3 [L]
 
 ##
 # Screenshots

Modified: web/trunk/include/Models/NewsModel.php
===================================================================
--- web/trunk/include/Models/NewsModel.php	2009-07-29 08:55:17 UTC (rev 42881)
+++ web/trunk/include/Models/NewsModel.php	2009-07-29 09:03:27 UTC (rev 42882)
@@ -31,14 +31,14 @@
 			throw new ErrorException(self::NO_FILES);
 		}
 		$news = array();
-		foreach ($files as $file) {
-			if (substr($file, -4) != '.xml') {
+		foreach ($files as $filename) {
+			if (substr($filename, -4) != '.xml') {
 				continue;
 			}
-			if (!($data = @file_get_contents(DIR_NEWS . "/{$file}"))) {
+			if (!($data = @file_get_contents(DIR_NEWS . "/{$filename}"))) {
 				continue;
 			}
-			$news[] = new News($data);
+			$news[] = new News($data, $filename);
 		}
 		return array_reverse($news);
 	}
@@ -55,22 +55,42 @@
 			$newslist = array_slice($newslist, 0, $num);
 			$news = array();
 			foreach ($newslist as $date) {
-				$news[] = NewsModel::getByDate($date);
+				$news[] = NewsModel::getOneByDate($date);
 			}
 			return $news;
 		}
 	}
 
 	/* Get the news item that was posted on a specific date. */
-	static public function getByDate($date) {
-		if ($date == null || !is_numeric($date) || strlen($date) != 8) {
+	static public function getOneByDate($date) {
+		if (is_null($date) || !preg_match('/^\d{8}[a-z]?$/', $date)) {
 			throw new ErrorException(self::INVALID_DATE);
 		}
 		if (!is_file(($fname = DIR_NEWS . "/{$date}.xml"))
 			|| !is_readable($fname) || !($data = @file_get_contents($fname))) {
 			throw new ErrorException(self::FILE_NOT_FOUND);
 		}
-		return new News($data);
+		return new News($data, $fname);
 	}
+
+	/* Get the news item that was posted on a specific date. */
+	static public function getAllByDate($date) {
+		if ($date == null || !is_numeric($date) || strlen($date) != 8) {
+			throw new ErrorException(self::INVALID_DATE);
+		}
+		$files = glob(DIR_NEWS . "/{$date}*.xml");
+		if (!is_array($files) || count($files) == 0) {
+			throw new ErrorException(self::FILE_NOT_FOUND);
+		}
+		natsort($files);
+		$files = array_reverse($files);
+		$news = array();
+		foreach ($files as $filename) {
+			if (($data = @file_get_contents($filename))) {
+				$news[] = new News($data, $filename);
+			}
+		}
+		return $news;
+	}
 }
 ?>

Modified: web/trunk/include/Objects/News.php
===================================================================
--- web/trunk/include/Objects/News.php	2009-07-29 08:55:17 UTC (rev 42881)
+++ web/trunk/include/Objects/News.php	2009-07-29 09:03:27 UTC (rev 42882)
@@ -9,6 +9,7 @@
 	private $_author;
 	private $_image;
 	private $_content;
+	private $_filename;
 
 	/**
 	 * News object constructor that extracts the data from the pseudo-XML scheme
@@ -23,7 +24,7 @@
 	 *
 	 * FIXME: It currently fails at grabbing the image (see 20020214.xml)
 	 */
-	public function __construct($data) {
+	public function __construct($data, $filename) {
 		$vars = array();
 		preg_match("/<NAME>(.*)<\/NAME>.*		# Grab the title
 					<DATE>(.*)<\/DATE>.*		# Grab the date
@@ -39,6 +40,7 @@
 			$this->_image = $vars[4];
 			$this->_content = $vars[5];
 		}
+		$this->_filename = basename($filename);
 	}
 
 	/* Get the title. */
@@ -65,5 +67,10 @@
 	public function getContent() {
 		return $this->_content;
 	}
+
+	/* Get the filename. */
+	public function getFilename() {
+		return $this->_filename;
+	}
 }
 ?>

Modified: web/trunk/include/Pages/NewsPage.php
===================================================================
--- web/trunk/include/Pages/NewsPage.php	2009-07-29 08:55:17 UTC (rev 42881)
+++ web/trunk/include/Pages/NewsPage.php	2009-07-29 09:03:27 UTC (rev 42882)
@@ -29,12 +29,17 @@
 	public function getNews($date = null) {
 		if ($date == null) {
 			$news_items = NewsModel::getAllNews();
+			$date = 'archive';
 		} else {
-			$news_items = array(NewsModel::getByDate($date));
+			if (strlen($date) == 8) {
+				$news_items = NewsModel::getAllByDate($date);
+			} else {
+				$news_items = array(NewsModel::getOneByDate($date));
+			}
 		}
-		
+
 		$this->addCSSFiles('news.css');
-		
+
 		return $this->renderPage(
 			array(
 				'title' => 'Home',
@@ -42,6 +47,7 @@
 				'show_intro' => false,
 				'news_items' => $news_items,
 				'news_archive_link' => false,
+				'date' => $date,
 			),
 			$this->_template
 		);

Modified: web/trunk/templates/feed_atom.tpl
===================================================================
--- web/trunk/templates/feed_atom.tpl	2009-07-29 08:55:17 UTC (rev 42881)
+++ web/trunk/templates/feed_atom.tpl	2009-07-29 09:03:27 UTC (rev 42882)
@@ -17,9 +17,11 @@
 	{foreach from=$news item=n}
 		{assign var='timezone_offset' value=$n->getDate()|date_f:'Z'}
 		{assign var='updated' value=$n->getDate()-$timezone_offset}
+		{assign var='news_filename' value=$n->getFilename()|substr:'0':'-4'}
+
 		<entry xml:lang="en">
 			<id>{$baseurl}news/archive/#{$n->getDate()|date_f:'Y-m-d'}</id>
-			<link rel="alternate" href="{$baseurl}news/#{$n->getDate()|date_f:'Y-m-d'}" />
+			<link rel="alternate" href="{$baseurl}news/{$news_filename}/" />
 			<updated>{$updated|date_f:'Y-m-d\Th:i:s\Z'}</updated>
 			<published>{$updated|date_f:'Y-m-d\Th:i:s\Z'}</published>
 			<title type="html">{$n->getTitle()}</title>

Modified: web/trunk/templates/feed_rss.tpl
===================================================================
--- web/trunk/templates/feed_rss.tpl	2009-07-29 08:55:17 UTC (rev 42881)
+++ web/trunk/templates/feed_rss.tpl	2009-07-29 09:03:27 UTC (rev 42882)
@@ -7,6 +7,7 @@
 		<description>ScummVM is a cross-platform interpreter for several point-and-click adventure engines. This includes all SCUMM-based adventures by LucasArts, Simon the Sorcerer 1&2 by AdventureSoft, Beneath a Steel Sky and Broken Sword 1&2 by Revolution, and many more.</description>
 		<language>en</language>
 		{foreach from=$news item=n}
+		{assign var='news_filename' value=$n->getFilename()|substr:'0':'-4'}
 		<item>
 			<title>{$n->getTitle()}</title>
 			<description><![CDATA[{$n->getContent()}]]></description>
@@ -14,8 +15,8 @@
 			{if $n->getAuthor() != ''}
 			<author>nospam at scummvm.org ({$n->getAuthor()})</author>
 			{/if}
-			<guid isPermaLink='true'>{$baseurl}news/archive/#{$n->getDate()|date_f:'Y-m-d'}</guid>
-			<link>{$baseurl}news/#{$n->getDate()|date_f:'Y-m-d'}</link>
+			<guid isPermaLink='true'>{$baseurl}news/archive/#{$n->getDate()|date_f:'Y-m-d'}{if $news_filename|strlen == 9}{$news_filename|substr:'-1'}{/if}</guid>
+			<link>{$baseurl}news/{$news_filename}/</link>
 		</item>
 		{/foreach}
 	</channel>

Modified: web/trunk/templates/news.tpl
===================================================================
--- web/trunk/templates/news.tpl	2009-07-29 08:55:17 UTC (rev 42881)
+++ web/trunk/templates/news.tpl	2009-07-29 09:03:27 UTC (rev 42882)
@@ -1,8 +1,14 @@
 {foreach from=$news_items item=news}
+{assign var='news_date' value=$news->getDate()|date_format:"%Y%m%d"}
+{assign var='news_filename' value=$news->getFilename()|substr:'0':'-4'}
+{if !empty($date) && ($date == 'archive' || strlen($date) == 8)}
+	{assign var='news_date' value=$news_filename}
+{/if}
+
 <div class="box">
-	<a name="{$news->getDate()|date_format:"%Y-%m-%d"}"></a>
+	<a name="{$news->getDate()|date_format:"%Y-%m-%d"}{if $news_filename|strlen == 9}{$news_filename|substr:'-1'}{/if}"></a>
 	<div class="head">
-		<a href="{$baseurl}news/{$news->getDate()|date_format:"%Y%m%d"}/">
+		<a href="{$baseurl}news/{$news_date}/">
 			<span class="news-date">{$news->getDate()|date_f:"M j, Y"}</span>:
 			{$news->getTitle()}
 		</a>


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list