* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * @category JSON * @package DRI\API * @author Christoph Brill * @copyright 2012-2017 Christoph Brill * @license MIT https://opensource.org/licenses/MIT * @link https://people.freedesktop.org/~cbrill/ */ if (!isset($_GET['date'])) { $_GET['date'] = 'today'; } if (!isset($_GET['mode'])) { $_GET['mode'] = ''; } require_once 'common.inc.php'; // 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); } else { $lines = array(); } header("Content-type: application/json;"); $retval = array(); $retval['maxdate'] = validDate('today'); $retval['channel'] = $channel; $retval['date'] = $date; switch ($_GET['mode']) { case '': case 'watch': $retval['data'] = array(); // 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 (isFromChannel($line, $channel)) { if (!filterJoin($line)) { $user = substr(getUser($line), 2, -1); if (in_array($user, $ignore)) { continue; } if (in_array($user, $users)) { $elem = array(); $time = getTime($line); $userx = getUser($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]; } $image = getImage($user); if ($image != null) { $row['image'] = $image; } $row['data'] = $$user; array_push($retval['data'], $row); } break; case 'show': $retval['users'] = array(); $retval['data'] = array(); foreach ($lines as $line_num => $line) { if (isFromChannel($line, $channel)) { if (!filterJoin($line)) { $user = substr(getUser($line), 2, -1); if (in_array($user, $ignore)) { continue; } $elem = array(); $time = getTime($line); $userx = getUser($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]; } $image = getImage($user); if ($image != null) { $userdata['image'] = $image; } $retval['users'][$user] = $userdata; $elem['user'] = $user; array_push($retval['data'], $elem); } } } $retval['users'] = array_values($retval['users']); break; default: break; } echo json_encode($retval);