From efd075f8fc860a544d36531f0af725aa91a98aa9 Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Wed, 25 Jun 2008 15:47:25 +0300 Subject: [PATCH] Added a simple RSS feed of project changes. --- doc/TODO | 2 -- inc/config.php | 6 ++++++ index.php | 35 +++++++++++++++++++++++++++++++++++ templates/header.php | 5 +++++ templates/rss.php | 4 +++- 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/doc/TODO b/doc/TODO index 60a196e..2548e65 100644 --- a/doc/TODO +++ b/doc/TODO @@ -23,8 +23,6 @@ - mandatory features (0.0.1) - project list (configurable or from a root, using globs perhaps?) - root dir, under which all directories are shown on viewgit -- optional - - RSS feeds: projects, shortlog [misc] - license? diff --git a/inc/config.php b/inc/config.php index 953d351..dbe7edc 100644 --- a/inc/config.php +++ b/inc/config.php @@ -19,4 +19,10 @@ $conf['summary_shortlog'] = 30; // Allow checking out projects via "git clone" $conf['allow_checkout'] = true; +// RSS time to live (how often clients should update the feed), in minutes. +$conf['rss_ttl'] = 10; + +// RSS: Maximum number of items in feed +$conf['rss_max_items'] = 30; + include_once('localconfig.php'); diff --git a/index.php b/index.php index 4b07d6d..0438b96 100644 --- a/index.php +++ b/index.php @@ -245,6 +245,11 @@ function makelink($dict) return ''; } +function rss_pubdate($secs) +{ + return date('D, d M Y H:i:s O', $secs); +} + /** * Executes a git command in the project repo. * @return array of output lines @@ -434,6 +439,36 @@ elseif ($action === 'commitdiff') { list($page['files'], $page['diffdata']) = format_diff($text); //$page['diffdata'] = format_diff($text); } +elseif ($action === 'rss-log') { + $page['project'] = validate_project($_REQUEST['p']); + + $ext_url = 'http://'. $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) .'/'; + + $page['rss_title'] = "Log for $page[project]"; + $page['rss_link'] = $ext_url . makelink(array('a' => 'summary', 'p' => $page['project'])); + $page['rss_description'] = "Git log for project $page[project], generated by ViewGit."; + $page['rss_pubDate'] = rss_pubdate(time()); + $page['rss_ttl'] = $conf['rss_ttl']; + + $page['rss_items'] = array(); + + $revs = git_get_rev_list($page['project'], $conf['rss_max_items']); + foreach ($revs as $rev) { + $info = git_get_commit_info($page['project'], $rev); + $link = $ext_url . makelink(array('a' => 'commit', 'p' => $page['project'], 'h' => $rev)); + + $page['rss_items'][] = array( + 'title' => $info['message_firstline'], + 'guid' => $link, + 'link' => $link, + 'description' => '('. $info['author_name'] .') '. $info['message'], + 'pubdate' => rss_pubdate($info['author_stamp']), + ); + } + + require('templates/rss.php'); + die(); +} elseif ($action === 'shortlog') { $template = 'shortlog'; $page['project'] = validate_project($_REQUEST['p']); diff --git a/templates/header.php b/templates/header.php index f70f180..8721cdf 100644 --- a/templates/header.php +++ b/templates/header.php @@ -7,6 +7,11 @@ echo "\n"; <?php echo $page['title']; ?> + 'rss-log', 'p' => $page['project'])) ."\" />\n"; +} +?> diff --git a/templates/rss.php b/templates/rss.php index 220c596..487ee1f 100644 --- a/templates/rss.php +++ b/templates/rss.php @@ -1,4 +1,5 @@ '."\n"; ?> @@ -14,8 +15,9 @@ echo ''."\n"; \n"; + echo "\t\t\t". htmlentities($item['title']) ."\n"; echo "\t\t\t$item[link]\n"; - echo "\t\t\t$item[description]\n"; + echo "\t\t\t". htmlentities($item['description']) ."\n"; echo "\t\t\t$item[pubdate]\n"; echo "\t\t\t$item[guid]\n"; echo "\t\t\n\n"; -- 2.11.4.GIT