-
Notifications
You must be signed in to change notification settings - Fork 4
/
feed.php
126 lines (99 loc) · 3.23 KB
/
feed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
define("SITE_ROOT", realpath(dirname(__file__)));
require_once SITE_ROOT . "/lib/init.php";
function parse_email($email)
{
$ret = array("name" => $email, "email" => "");
if (preg_match("|([^\<]*)<([^>]*)>|", $email, $m)) {
$ret["name"] = trim($m[1]);
$ret["email"] = trim($m[2]);
}
return $ret;
}
function sort_by_date($a, $b)
{
if ($a["time"] < $b["time"]) {
return 1;
} else if ($a["time"] > $b["time"]) {
return -1;
}
return 0;
}
function print_changeset($row)
{
$author = parse_email($row["author"]);
$gid = md5($author["email"]);
$avatar = (USE_SSL ? "https://secure.gravatar.com" : "http://www.gravatar.com") .
"/avatar/$gid?r=x&d=mm&s=48";
return '<tr><td valign="top" align="center"><img src="' . $avatar . '" alt="Avatar"/><br/>'
. htmlspecialchars($author["name"]) . '</td>'
. '<td valign="top"><a href="https://github.com/siana/SingularityViewer/commit/' . htmlspecialchars($row["hash"]) . '">' . htmlspecialchars($row["hash"]) . '</a><br/>'
. htmlspecialchars($row["time"]). "<br/><br/>\n\n<pre>"
. htmlspecialchars($row["message"]) . '</pre></td>';
}
function print_changes($current, $next)
{
global $DB;
$ret = "";
$revs = array();
if (!($res = $DB->query(kl_str_sql("select revisions from changes where build<=!i and build>!i order by build desc", $current->nr, $next->nr)))) {
return $ret;
} else {
while ($row = $DB->fetchRow($res)) {
$revs = array_merge($revs, explode(",", $row["revisions"]));
}
}
if ($res = $DB->query("select * from revs where hash in ('" . implode("','", $revs) . "')")) {
$ret .= '<table width="100%">';
$changesets = array();
while ($row = $DB->fetchRow($res)) {
$changesets[] = $row;
}
usort($changesets, "sort_by_date");
foreach ($changesets as $change) {
$ret .= print_changeset($change);
}
$ret .= '</table>';
}
return $ret;
}
$buildFeed = new FeedWriter(ATOM);
$buildFeed->setTitle('Singularity Automatic Development Builds');
$buildFeed->setLink('http://files.streamgrid.net/singularity/');
$buildFeed->setDescription('Latest automated build of the Singularity Viewer project');
// $buildFeed->setImage('Testing the RSS writer class',
// 'http://www.ajaxray.com/projects/rss',
// 'http://www.rightbrainsolution.com/images/logo.gif');
$chan = "SingularityAlpha";
$pageSize = 20;
$builds = array();
if ($res = $DB->query(kl_str_sql("select * from builds where chan=!s order by nr desc limit !i", $chan, $pageSize + 1))) {
while ($row = $DB->fetchRow($res)) {
$build = new stdClass;
$DB->loadFromDbRow($build, $res, $row);
$builds[] = $build;
}
}
$nrBuilds = count($builds);
if ($nrBuilds) {
for ($i = 0; $i < $pageSize; $i++) {
if (!isset($builds[$i])) continue;
$newItem = $buildFeed->createNewItem();
$newItem->setTitle("Singularity Alpha build " . $builds[$i]->nr);
$newItem->setLink("http://files.streamgrid.net/singularity/?build_id=" . $builds[$i]->nr);
$newItem->setDate($builds[$i]->modified);
if (isset($builds[$i+1])) {
$newItem->setDescription(print_changes($builds[$i], $builds[$i + 1]));
}
$buildFeed->addItem($newItem);
}
$buildFeed->genarateFeed();
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/