diff options
author | Christoph Brill <egore911@egore911.de> | 2012-03-17 00:15:46 +0100 |
---|---|---|
committer | Christoph Brill <egore911@egore911.de> | 2012-03-26 00:17:34 +0200 |
commit | f88108b739563b98929af399462014dfab07070d (patch) | |
tree | b0fc4954b9513d771b055af4cc57b69f5cda8940 /json.php | |
parent | d4bdba2e7bf69e1f2aaa372a9738bb55bfcb6550 (diff) |
Add a 'mode' to show all log lines for a day and a channel
Diffstat (limited to 'json.php')
-rw-r--r-- | json.php | 142 |
1 files changed, 95 insertions, 47 deletions
@@ -21,13 +21,7 @@ if (!isset($_GET['date'])) { require_once('common.inc.php'); -if (isset($_GET['users'])) { - $users = explode(',', $_GET['users']); -} else { - $users = array(); -} - - +// Read all lines of the log into an array $filename = 'dri-devel-'.$date.'.log'; if (file_exists(LOG_DIR.$filename)) { $lines = file(LOG_DIR.$filename); @@ -35,52 +29,106 @@ if (file_exists(LOG_DIR.$filename)) { $lines = array(); } -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)) { - $elem = array(); - $time = get_time($line); - $userx = get_user($line); - $elem['anchor'] = 't-'.str_replace(':', '', $time); - $elem['time'] = $time; - $line = str_replace($time.' ', '', $line); - $line = str_replace('#'.$channel.': ', '', $line); - $line = str_replace($userx, '', $line); - $elem['content'] = trim($line); - array_push($$user, $elem); - } - } - } -} - header("Content-type: application/json;"); $retval = array(); - $retval['maxdate'] = valid_date('today'); $retval['channel'] = $channel; $retval['date'] = $date; $retval['data'] = array(); -foreach ($users as $user) { - if (empty($$user)) { - continue; - } - $row = array(); - $row['name'] = $user; - if (isset($realname[$user])) { - $row['realname'] = $realname[$user]; - } - if (isset($gravatars[$user])) { - $row['image'] = 'http://www.gravatar.com/avatar/'.$gravatars[$user]; - } - $row['data'] = $$user; - array_push($retval['data'], $row); +switch ($_GET['mode']) { + case '': + case 'watch': + + // Determine which users will be watched + if (isset($_GET['users'])) { + $users = explode(',', $_GET['users']); + } else { + $users = array(); + } + + // No users given, this will return a empty result + if (count($users) == 0) { + break; + } + + // Create an array for every user to hold his/her lines + foreach ($users as $user) { + $$user = array(); + } + + // Assign all lines to a user + 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)) { + $elem = array(); + $time = get_time($line); + $userx = get_user($line); + $elem['anchor'] = 't-'.str_replace(':', '', $time); + $elem['time'] = $time; + $line = str_replace($time.' ', '', $line); + $line = str_replace('#'.$channel.': ', '', $line); + $line = str_replace($userx, '', $line); + $elem['content'] = trim($line); + array_push($$user, $elem); + } + } + } + } + + // Add all the lines to the return value + foreach ($users as $user) { + if (empty($$user)) { + continue; + } + $row = array(); + $row['name'] = $user; + if (isset($realname[$user])) { + $row['realname'] = $realname[$user]; + } + if (isset($gravatars[$user])) { + $row['image'] = 'http://www.gravatar.com/avatar/'.$gravatars[$user]; + } + $row['data'] = $$user; + array_push($retval['data'], $row); + } + break; + case 'show': + foreach ($lines as $line_num => $line) { + if (is_from_selected_channel($line, $channel)) { + if (!filter_join($line)) { + $user = substr(get_user($line), 2, -1); + + $elem = array(); + $time = get_time($line); + $userx = get_user($line); + $elem['anchor'] = 't-'.str_replace(':', '', $time); + $elem['time'] = $time; + $line = str_replace($time.' ', '', $line); + $line = str_replace('#'.$channel.': ', '', $line); + $line = str_replace($userx, '', $line); + $elem['content'] = trim($line); + + $userdata = array(); + $userdata['name'] = $user; + if (isset($realname[$user])) { + $userdata['realname'] = $realname[$user]; + } + if (isset($gravatars[$user])) { + $userdata['image'] = 'http://www.gravatar.com/avatar/'.$gravatars[$user]; + } + $elem['user'] = $userdata; + + array_push($retval['data'], $elem); + } + } + } + break; + default: + break; } -echo json_encode($retval); + +echo json_encode($retval);
\ No newline at end of file |