timeline: added url field, added rss feed generator
This commit is contained in:
parent
2066e69f45
commit
e316a396e8
48
timeline/rss.php
Normal file
48
timeline/rss.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
require_once('DB.php');
|
||||
$days = 15;
|
||||
if (isset($_GET['days'])) {
|
||||
$days = intval($_GET['days']);
|
||||
}
|
||||
|
||||
$dsn = 'sqlite:////home/crux/public_html/local/timeline.db';
|
||||
$db =& DB::connect($dsn);
|
||||
if (DB::isError($db)) die("Cannot connect to database");
|
||||
$db->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
$from = time() - ($days * 24 * 60 * 60);
|
||||
$sql = "select * from events where event_tstamp >= $from order by event_tstamp desc";
|
||||
$res =& $db->Query($sql);
|
||||
if (DB::isError($res)) die("Query error");
|
||||
|
||||
header ("Content-type: text/xml");
|
||||
$timeline .= '<?xml version="1.0"?>'."\n";
|
||||
$timeline .= '<rss version="2.0"><channel><title>CRUX timeline</title><description>CRUX: timeline (commits, tasks, wiki edits)</description><link>http://crux.nu</link>';
|
||||
while ($evt =& $res->fetchRow()) {
|
||||
$event_description = $evt['event_description'];
|
||||
if ($evt['event_notes'] != "") {
|
||||
$event_description .= ": ".$evt['event_notes'];
|
||||
}
|
||||
$url = $evt['event_url'];
|
||||
$url = str_replace("&","&", $url);
|
||||
# strip diff link
|
||||
$description = preg_replace('/\(\[\[.*\]\]\)/s','', $evt['event_description']);
|
||||
# strip wiki link with url
|
||||
$description = preg_replace('/\[\[(.*)\|(\d+)\]\]/s','$2', $description);
|
||||
# strip users (svn)
|
||||
$description = preg_replace('/\[\[~(.*)\|(.*)\]\]/s','$2', $description);
|
||||
# strip wiki link without url
|
||||
$description = preg_replace('/\[\[(\w+)\.(\w+)\]\] /s','$1.$2', $description);
|
||||
# strip wiki user with ~
|
||||
$description = preg_replace('/\[\[~(\w+)\]\] /s','$1', $description);
|
||||
|
||||
$evt['event_notes'] = "Notes";
|
||||
$timeline .= "
|
||||
<item>
|
||||
<title>$description</title>
|
||||
<description></description>
|
||||
<link>$url</link>
|
||||
</item>\n";
|
||||
}
|
||||
$timeline .= "</channel></rss>\n";
|
||||
echo $timeline;
|
||||
?>
|
@ -2,10 +2,11 @@ create table events (
|
||||
event_id integer primary key,
|
||||
cache_id integer,
|
||||
event_tstamp integer,
|
||||
event_type varchar(20),
|
||||
event_date varchar(10),
|
||||
event_time varchar(5),
|
||||
event_user varchar(50),
|
||||
event_type varchar,
|
||||
event_date varchar,
|
||||
event_time varchar,
|
||||
event_user varchar,
|
||||
event_url varchar,
|
||||
event_description text,
|
||||
event_notes text
|
||||
);
|
||||
|
@ -41,7 +41,7 @@ $username_map = array(
|
||||
"sten" => "NickSteeves"
|
||||
);
|
||||
|
||||
// Event: cache_id, tstamp, type(icon), date, time, user, description, notes
|
||||
// Event: cache_id, tstamp, type(icon), date, time, user, url, description, notes
|
||||
$events = array();
|
||||
|
||||
/**************** Last cached events *******************/
|
||||
@ -101,15 +101,16 @@ while ($row =& $res->fetchRow()) {
|
||||
$description = "";
|
||||
$date = date("Y-m-d", $edate);
|
||||
$time = date("H:i", $edate);
|
||||
$url = sprintf($task_url,$etid);
|
||||
switch ($etype) {
|
||||
case "1": // new task
|
||||
$icon = "task_opened";
|
||||
$description = "New task [[ ".sprintf($task_url,$etid)." | $etid ]] opened by $euser";
|
||||
$description = "New task [[$url|$etid]] opened by $euser";
|
||||
$notes = $row['item_summary'];
|
||||
break;
|
||||
case "2": // task closed
|
||||
$icon = "task_closed";
|
||||
$description = "Task [[ ".sprintf($task_url,$etid)." | $etid ]] closed by $euser";
|
||||
$description = "Task [[$url|$etid]] closed by $euser";
|
||||
if ($row['closure_comment'] != "" && $row['closure_comment'] != 0) { // weird flyspray!
|
||||
$notes = $row['closure_comment'];
|
||||
} else {
|
||||
@ -130,13 +131,13 @@ while ($row =& $res->fetchRow()) {
|
||||
case "24":
|
||||
case "25":
|
||||
$icon = "task_changed";
|
||||
$description = "Task [[ ".sprintf($task_url,$etid)." | $etid ]] modified by $euser";
|
||||
$description = "Task [[$url|$etid]] modified by $euser";
|
||||
$notes = "";
|
||||
break;
|
||||
}
|
||||
if ($description !== "") {
|
||||
$events[] = array( 'cache_id' => $cache_id, 'tstamp' => $edate, 'icon' => $icon, 'date' => $date,
|
||||
'time' => $time, 'user' => $euser, 'description' => $description, 'notes' => $notes,);
|
||||
'time' => $time, 'user' => $euser, 'url'=> $url, 'description' => $description, 'notes' => $notes,);
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,14 +162,15 @@ if ($svn_latest != $last_svn) {
|
||||
}
|
||||
$date = substr($revline[2],1,10);
|
||||
$time = substr($revline[2],12,5);
|
||||
$revurl = "[[ ".sprintf($svn_url, $rev)." | $rev ]]";
|
||||
$url = sprintf($svn_url, $rev);
|
||||
$revurl = "[[$url|$rev]]";
|
||||
$description = "Revision $revurl committed by $user";
|
||||
$tstamp = strtotime("$date $time:00");
|
||||
} else {
|
||||
$icon = "svn_commit";
|
||||
$notes = trim($line);
|
||||
$events[] = array( 'cache_id' => $rev, 'tstamp' => $tstamp, 'icon' => $icon, 'date' => $date,
|
||||
'time' => $time, 'user' => $user, 'description' => $description, 'notes' => $notes);
|
||||
'time' => $time, 'user' => $user, 'url'=>$url, 'description' => $description, 'notes' => $notes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -199,19 +201,21 @@ if ($chline != "") {
|
||||
preg_match('/(..\:..)/',$date,$matches);
|
||||
$time = $matches[0];
|
||||
$date = date("Y-m-d", $tstamp);
|
||||
|
||||
$action = "?action=diff#" . urlencode($date . " " . $time) . "|diff";
|
||||
$page_diff = trim(str_replace("]]", $action."]]", $page))
|
||||
$action = "?action=diff#" . urlencode($date . " " . $time) . "|diff";
|
||||
$page_diff = trim(str_replace("]]", $action."]]", $page));
|
||||
preg_match('/\[\[(.*)\|diff\]\]/', $page_diff, $matches);
|
||||
$url = $matches[1];
|
||||
$url = "http://crux.nu/".str_replace(".","/", $url);
|
||||
$description = "Wiki page $page edited $user ($page_diff)";
|
||||
if ($tstamp > $last_wiki) {
|
||||
$events[] = array( 'cache_id' => $tstamp, 'tstamp' => $tstamp, 'icon' => $icon, 'date' => $date,
|
||||
'time' => $time, 'user' => $user, 'description' => $description, 'notes' => $notes);
|
||||
'time' => $time, 'user' => $user, 'url' => $url, 'description' => $description, 'notes' => $notes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************** Finally, all events *********************/
|
||||
$sth = $dbc->prepare("insert into events values (NULL, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$sth = $dbc->prepare("insert into events values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
foreach ($events as $evt) {
|
||||
$res = $dbc->execute($sth, $evt);
|
||||
if (DB::isError($res)) die("Query error");
|
||||
|
Loading…
x
Reference in New Issue
Block a user