summaryrefslogtreecommitdiff
path: root/timeline/rss.php
blob: 8be04f0342c1cbd8bd44572be280fb209bd50804 (plain)
    1 <?php
    2 require_once('DB.php');
    3 $limit = 10;
    4 if (isset($_GET['limit'])) {
    5 	$limit = intval($_GET['limit']);
    6 }
    7 
    8 $dsn = 'sqlite:////home/crux/public_html/local/timeline.db';
    9 $db =& DB::connect($dsn);
   10 if (DB::isError($db)) die("Cannot connect to database");
   11 $db->setFetchMode(DB_FETCHMODE_ASSOC);
   12 $sql = "select * from events order by event_tstamp desc limit $limit";
   13 $res =& $db->Query($sql);
   14 if (DB::isError($res)) die("Query error");
   15 
   16 header ("Content-type: text/xml");
   17 $timeline .= '<?xml version="1.0"?>'."\n";
   18 $timeline .= '<rss version="2.0"><channel><title>CRUX timeline</title><description>CRUX: timeline (commits, tasks, wiki edits)</description><link>http://crux.nu</link>';
   19 while ($evt =& $res->fetchRow()) {
   20 	$url = $evt['event_url'];
   21 	$url = str_replace("&","&amp;", $url);
   22 	# strip diff link
   23 	$description = preg_replace('/\(\[\[.*\]\]\)/s','', $evt['event_description']);
   24 	# strip wiki link with url
   25 	$description = preg_replace('/\[\[(.*)\|(\d+)\]\]/s','$2', $description);
   26 	# strip users (git)
   27 	$description = preg_replace('/\[\[~(.*)\|(.*)\]\]/s','$2', $description);
   28 	# strip wiki link without url
   29 	$description = preg_replace('/\[\[(\w+)\.(\w+)\]\] /s','$1.$2', $description);
   30 	# strip wiki user with ~
   31 	$description = preg_replace('/\[\[~(\w+)\]\] /s','$1', $description);
   32 	# Compact description for git commits
   33 	$description = preg_replace('/\[\[http(.*)\|(.*)\]\] committed by/','$2 by', $description);
   34 	# Compact description for wiki edits
   35 	$description = str_replace ("Wiki page ","", $description);
   36 	
   37 	$notes = "";
   38 	$titlenotes = "";
   39 	if ($evt['event_notes'] != "") {
   40 		$notes = $evt['event_notes'];
   41 		$titlenotes = ": ".$notes;
   42 		if (strlen($notes) > 40) {
   43 			$titlenotes = ": ".substr($notes,0,40)."...";
   44 		}
   45 	}
   46 	$timeline .= "
   47 		<item>
   48 			<title>$description$titlenotes</title>
   49 			<description>$notes</description>
   50 			<link>$url</link>
   51 		</item>\n";
   52 }
   53 $timeline .= "</channel></rss>\n";
   54 echo $timeline;
   55 ?>

Generated by cgit