add support for atom feeds
add support for atom feeds

--- a/include/controller/Controller.class.php
+++ b/include/controller/Controller.class.php
@@ -96,6 +96,10 @@
 				if ($action === 'blob_plain')
 					$controller->SetParam('plain', true);
 				break;
+			case 'atom':
+				require_once(GITPHP_CONTROLLERDIR . 'Controller_Atom.class.php');
+				$controller = new GitPHP_Controller_Atom();
+				break;
 			case 'rss':
 				require_once(GITPHP_CONTROLLERDIR . 'Controller_Rss.class.php');
 				$controller = new GitPHP_Controller_Rss();

--- /dev/null
+++ b/include/controller/Controller_Atom.class.php
@@ -1,1 +1,137 @@
+<?php
+/**
+ * GitPHP Controller Atom
+ *
+ * Controller for displaying a project's Atom feed
+ *
+ * @author Christopher Han <xiphux@gmail.com>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @copyright Copyright (c) 2010 Christopher Han
+ * @package GitPHP
+ * @subpackage Controller
+ */
 
+define('GITPHP_FEED_ITEMS', 150);
+
+/**
+ * Atom controller class
+ *
+ * @package GitPHP
+ * @subpackage Controller
+ */
+class GitPHP_Controller_Atom extends GitPHP_ControllerBase
+{
+	/**
+	 * __construct
+	 *
+	 * Constructor
+	 *
+	 * @access public
+	 * @return controller
+	 */
+	public function __construct()
+	{
+		parent::__construct();
+		if (!$this->project) {
+			throw new GitPHP_MessageException(GitPHP_Resource::GetInstance()->translate('Project is required'), true);
+		}
+	}
+
+	/**
+	 * GetTemplate
+	 *
+	 * Gets the template for this controller
+	 *
+	 * @access protected
+	 * @return string template filename
+	 */
+	protected function GetTemplate()
+	{
+		return 'atom.tpl';
+	}
+
+	/**
+	 * GetCacheKey
+	 *
+	 * Gets the cache key for this controller
+	 *
+	 * @access protected
+	 * @return string cache key
+	 */
+	protected function GetCacheKey()
+	{
+		return '';
+	}
+
+	/**
+	 * GetName
+	 *
+	 * Gets the name of this controller's action
+	 *
+	 * @access public
+	 * @param boolean $local true if caller wants the localized action name
+	 * @return string action name
+	 */
+	public function GetName($local = false)
+	{
+		if ($local) {
+			return GitPHP_Resource::GetInstance()->translate('rss');
+		}
+		return 'atom';
+	}
+
+	/**
+	 * ReadQuery
+	 *
+	 * Read query into parameters
+	 *
+	 * @access protected
+	 */
+	protected function ReadQuery()
+	{
+		GitPHP_Log::GetInstance()->SetEnabled(false);
+	}
+
+	/**
+	 * LoadHeaders
+	 *
+	 * Loads headers for this template
+	 *
+	 * @access protected
+	 */
+	protected function LoadHeaders()
+	{
+		$this->headers[] = "Content-type: application/atom+xml; charset=UTF-8";
+	}
+
+	/**
+	 * LoadData
+	 *
+	 * Loads data for this template
+	 *
+	 * @access protected
+	 */
+	protected function LoadData()
+	{
+		$log = $this->project->GetLog('HEAD', GITPHP_FEED_ITEMS);
+
+		$entries = count($log);
+
+		if ($entries > 20) {
+			/*
+			 * Don't show commits older than 48 hours,
+			 * but show a minimum of 20 entries
+			 */
+			for ($i = 20; $i < $entries; ++$i) {
+				if ((time() - $log[$i]->GetCommitterEpoch()) > 48*60*60) {
+					$log = array_slice($log, 0, $i);
+					break;
+				}
+			}
+		}
+
+		$this->tpl->assign('log', $log);
+	}
+
+}
+

--- /dev/null
+++ b/templates/atom.tpl
@@ -1,1 +1,46 @@
+{*
+ *  atom.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Atom feed template
+ *
+ *  Copyright (C) 2010 Christian Weiske <cweiske@cweiske.de>
+ *}
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
+  <title>{$project->GetProject()}</title>
+  <subtitle type="text">{$project->GetProject()} log</subtitle>
+  <link href="{scripturl}?p={$project->GetProject()|urlencode}&amp;a=summary"/>
+  <link rel="self" href="{scripturl}?p={$project->GetProject()|urlencode}&amp;a=atom"/>
+  <id>{scripturl}?p={$project->GetProject()|urlencode}</id>
+  <updated>{$log.0->GetCommitterEpoch()|date_format:"%FT%T+00:00"}</updated>
 
+{foreach from=$log item=logitem}
+  <entry>
+    <id>{scripturl}?p={$project->GetProject()|urlencode}&amp;a=commit&amp;h={$logitem->GetHash()}</id>
+    <title>{$logitem->GetTitle()|escape:'html'}</title>
+    <author>
+      <name>{$logitem->GetAuthorName()|escape:'html'}</name>
+    </author>
+    <published>{$logitem->GetCommitterEpoch()|date_format:"%FT%T+00:00"}</published>
+    <updated>{$logitem->GetCommitterEpoch()|date_format:"%FT%T+00:00"}</updated>
+    <link rel="alternate" href="{scripturl}?p={$project->GetProject()|urlencode}&amp;a=commit&amp;h={$logitem->GetHash()}"/>
+    <summary>{$logitem->GetTitle()|escape:'html'}</summary>
+    <content type="xhtml">
+      <div xmlns="http://www.w3.org/1999/xhtml">
+        <p>
+        {foreach from=$logitem->GetComment() item=line}
+          {$line|htmlspecialchars}<br />
+        {/foreach}
+        </p>
+        <ul>
+        {foreach from=$logitem->DiffToParent() item=diffline}
+          <li>{$diffline->GetToFile()|htmlspecialchars}</li>
+        {/foreach}
+        </ul>
+      </div>
+    </content>
+  </entry>
+{/foreach}
+
+</feed>
+

--- a/templates/footer.tpl
+++ b/templates/footer.tpl
@@ -8,7 +8,7 @@
     <div class="page_footer">
       {if $project}
         <div class="page_footer_text">{$project->GetDescription()}</div>
-        <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=rss" class="rss_logo">{t}RSS{/t}</a>
+        <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=atom" class="rss_logo">{t}Feed{/t}</a>
       {else}
         <a href="{$SCRIPT_NAME}?a=opml" class="rss_logo">{t}OPML{/t}</a>
         <a href="{$SCRIPT_NAME}?a=project_index" class="rss_logo">{t}TXT{/t}</a>

--- a/templates/header.tpl
+++ b/templates/header.tpl
@@ -13,7 +13,8 @@
     <title>{$pagetitle}{if $project} :: {$project->GetProject()}{if $actionlocal}/{$actionlocal}{/if}{/if}</title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     {if $project}
-      <link rel="alternate" title="{$project->GetProject()} log" href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=rss" type="application/rss+xml" />
+      <link rel="alternate" title="{$project->GetProject()} log (atom)" href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=atom" type="application/atom+xml" />
+      <link rel="alternate" title="{$project->GetProject()} log (RSS)" href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=rss" type="application/rss+xml" />
     {/if}
     <link rel="stylesheet" href="css/{$stylesheet}" type="text/css" />
     {if $extracss}

--- a/templates/opml.tpl
+++ b/templates/opml.tpl
@@ -11,10 +11,10 @@
     <title>{$pagetitle} OPML Export</title>
   </head>
   <body>
-    <outline text="git RSS feeds">
+    <outline text="git Atom feeds">
 
       {foreach from=$projectlist item=proj}
-      <outline type="rss" text="{$proj->GetProject()}" title="{$proj->GetProject()}" xmlUrl="{scripturl}?p={$proj->GetProject()|urlencode}&amp;a=rss" htmlUrl="{scripturl}?p={$proj->GetProject()|urlencode}&amp;a=summary" />
+      <outline type="rss" text="{$proj->GetProject()}" title="{$proj->GetProject()}" xmlUrl="{scripturl}?p={$proj->GetProject()|urlencode}&amp;a=atom" htmlUrl="{scripturl}?p={$proj->GetProject()|urlencode}&amp;a=summary" />
 
       {/foreach}
     </outline>

comments