diff options
author | Jose V Beneyto <sepen@crux.nu> | 2013-03-16 12:15:20 +0100 |
---|---|---|
committer | Jose V Beneyto <sepen@crux.nu> | 2013-03-16 12:15:20 +0100 |
commit | ce690847288aec23b738ff67382db77051ea46a1 (patch) | |
tree | d250b2f2cb844f83679549f5ad1f556a8c862bb4 | |
parent | edc2b6ca03dc645897e4961866c94548a2c7a050 (diff) | |
download | webtools-ce690847288aec23b738ff67382db77051ea46a1.tar.gz webtools-ce690847288aec23b738ff67382db77051ea46a1.tar.xz |
timeline: added support for markup user profiles in flyspray tasks. Code cleanup and restructured in a more comprehensible way
-rw-r--r-- | timeline/timeline.php | 131 |
1 files changed, 94 insertions, 37 deletions
diff --git a/timeline/timeline.php b/timeline/timeline.php index 4bc1d4e..08c1cb4 100644 --- a/timeline/timeline.php +++ b/timeline/timeline.php @@ -1,47 +1,104 @@ <?php -// Useless comment + +// to obtain a list of wiki profiles: +// $ ls -1 /home/crux/public_html/wiki.d/Profiles.* | cut -d'.' -f3- +$profiles = array( +"AnttiNykanen", +"BrettGoulder", +"DanielMueller", +"DannyRawlins", +"FalkHamann", +"FredrikRinnestam", +"Frinnst", +"Jaeger", +"JamesMills", +"JasonThomasDolan", +"JohannesWinkelmann", +"JonathanAsghar", +"JoseBeneyto", +"JoseVBeneyto", +"JuergenDaubert", +"JukkaHeino", +"JustinRebelo", +"LucasHazel", +"MattHoush", +"NickSteeves", +"PerLiden", +"SimoneRota", +"ThomasPenteker", +"TillBiedermann", +"TilmanSauerbeck", +); + +// DB class from php pear require_once('DB.php'); -Markup("timeline", "directives", "/\\(:timeline(\\s+.*)?\\s*:\\)/e", - "'<:block>'.GetEvents()"); + +Markup("timeline", "directives", "/\\(:timeline(\\s+.*)?\\s*:\\)/e", "'<:block>'.GetEvents()"); function GetEvents() { -$days = 14; -if (isset($_POST['days'])) { - $days = intval($_POST['days']); -} + global $profiles; -$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 distinct event_date, event_description, event_notes, event_type, event_time from events where event_tstamp >= $from order by event_tstamp desc"; -$res =& $db->Query($sql); -if (DB::isError($res)) die("Query error"); - -$timeline .= '<table cellspacing="0" border="0" cellpadding="0">'."\n"; -$currdate = "noway"; -while ($evt =& $res->fetchRow()) { - if ($evt['event_date'] != $currdate) { - $timeline .= '<tr><td class="timeline-head" colspan="3"><span class="timeline-date">'.$evt['event_date']."</span></td></tr>\n"; - } - $event_description = $evt['event_description']; - if ($evt['event_notes'] != "") { - $event_description .= ": ".$evt['event_notes']; - } - $event_type = ""; - if (substr($evt['event_type'], 0, 11) == "git_commit_") { - $event_type = "Changeset ".substr($evt['event_type'], 11, strlen($evt['event_type'])).".git "; + $days = 14; + if (isset($_POST['days'])) $days = intval($_POST['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 distinct event_date, event_description, event_notes, event_type, event_time from events where event_tstamp >= $from order by event_tstamp desc"; + $res =& $db->Query($sql); + if (DB::isError($res)) die("Query error"); + + $timeline .= '<table cellspacing="0" border="0" cellpadding="0">'."\n"; + $currdate = "noway"; + + while ($evt =& $res->fetchRow()) { + + // date header + if ($evt['event_date'] != $currdate) { + $timeline .= '<tr><td class="timeline-head" colspan="3"><span class="timeline-date">'.$evt['event_date']."</span></td></tr>\n"; + } + + // description + $event_description = ""; + if (substr($evt['event_type'], 0, 5) == "task_") { + // flyspray events + $real_name = strstr($evt['event_description'], 'by'); + $real_name = substr($real_name, 3, strlen($real_name)); + $trim_name = str_replace(' ', '', $real_name); + if (in_array($trim_name, $profiles)) { + $event_description = str_replace($real_name, "[[~".$trim_name."]]", $evt['event_description']); + } + else { + $event_description = $evt['event_description']; + } + } + elseif (substr($evt['event_type'], 0, 5) == "wiki_") { + // wiki events + $event_description = $evt['event_description']; + } + elseif (substr($evt['event_type'], 0, 11) == "git_commit_") { + // git events + $event_description = "Changeset ".substr($evt['event_type'], 11, strlen($evt['event_type'])).".git ".$evt['event_description']; + } + + // append notes + if ($evt['event_notes'] != "") $event_description .= ": ".$evt['event_notes']; + + // image + $img = '<img src="/images/'.$evt['event_type'].'.png">'; + + // final string + $timeline .= '<tr><td align="right" valign="top" width="60">'.$evt['event_time'].'</td><td align="center" valign="top" width="30">'.$img.'</td><td valign="top">'.$event_description.'</td></tr>'."\n"; + $currdate = $evt['event_date']; } - $img = '<img src="/images/'.$evt['event_type'].'.png">'; - $timeline .= '<tr><td align="right" valign="top" width="60">'.$evt['event_time'].'</td><td align="center" valign="top" width="30">'.$img.'</td><td valign="top">'.$event_type.$event_description.'</td></tr>'; - $timeline .= "\n"; - $currdate = $evt['event_date']; -} -$timeline .= "</table>\n"; -$timeline .= '<br><form method="post" action="pmwiki.php?n=Main.Timeline">Show the latest <input size="4" type="text" name="days" value="'.$days.'"> days <input type="submit" value="Show"></form>'."\n"; -return $timeline; + $timeline .= "</table>\n"; + $timeline .= '<br><form method="post" action="pmwiki.php?n=Main.Timeline">Show the latest <input size="4" type="text" name="days" value="'.$days.'"> days <input type="submit" value="Show"></form>'."\n"; + + return $timeline; } + ?> |