summaryrefslogtreecommitdiff
path: root/json.php
diff options
context:
space:
mode:
authorChristoph Brill <egore911@egore911.de>2012-01-26 22:37:17 +0100
committerChristoph Brill <egore911@egore911.de>2012-03-26 00:15:40 +0200
commit766c04347a22925c1bdbb328b0517bc9d32f68ac (patch)
tree10f6d9067b494671d627c72deeffb9557abd4c34 /json.php
parent0dc4e33cd335bbe26a28a8f11fc31e39ae78e194 (diff)
Experiment with a json API for the dri log
No idea where this will lead us to
Diffstat (limited to 'json.php')
-rw-r--r--json.php80
1 files changed, 80 insertions, 0 deletions
diff --git a/json.php b/json.php
new file mode 100644
index 0000000..c173d8a
--- /dev/null
+++ b/json.php
@@ -0,0 +1,80 @@
+<?php
+
+/**
+ * json.php - Part of the dri-devel IRC logging facilities
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) 2012 Christoph Brill <egore911@egore911.de>
+ */
+
+if (!isset($_GET['date'])) {
+ $_GET['date'] = 'today';
+}
+
+require_once('common.inc.php');
+
+if (isset($_GET['users'])) {
+ $users = explode(',', $_GET['users']);
+} else {
+ $users = array();
+}
+
+
+$filename = 'dri-devel-'.$date.'.log';
+$lines = file(LOG_DIR.$filename);
+
+foreach ($users as $user) {
+ $$user = array();
+}
+
+foreach ($lines as $line_num => $line) {
+ if (is_from_selected_channel($line, $channel)) {
+ if (!filter_join($line)) {
+ $user = substr(get_user($line), 2, -1);
+ if (in_array($user, $users)) {
+ array_push($$user, trim($line));
+ }
+ }
+ }
+}
+
+header("Content-type: application/json;");
+
+echo '{'.PHP_EOL;
+echo ' "channel": "'.$channel.'",'.PHP_EOL;
+echo ' "users": ['.PHP_EOL;
+echo ' "'.join('",'.PHP_EOL.' "', $users).'"'.PHP_EOL;
+echo ' ],'.PHP_EOL;
+echo ' "data": ['.PHP_EOL;
+
+$isuser=false;
+foreach ($users as $user) {
+ if (empty($$user)) {
+ continue;
+ }
+ if ($isuser) echo ','.PHP_EOL;
+ echo ' {'.PHP_EOL;
+ echo ' "name": "'.$user.'",'.PHP_EOL;
+ echo ' "data": ['.PHP_EOL;
+ $isline=false;
+ foreach ($$user as $line) {
+ if ($isline) echo ','.PHP_EOL;
+ echo ' "'.$line.'"';
+ $isline=true;
+ }
+ echo PHP_EOL;
+ echo ' ]'.PHP_EOL;
+ echo ' }';
+ $isuser=true;
+}
+echo PHP_EOL;
+echo ' ]'.PHP_EOL;
+echo '}';