Mineplex2018-withcommit/Plugins/Mineplex.ChatSnapManager/web/report.php

39 lines
969 B
PHP
Raw Normal View History

2015-12-07 18:05:58 +01:00
<?php
$dataDir = "data/";
$uuidPattern = "/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i";
2015-12-07 18:05:58 +01:00
// ID corresponds to the Report ID
if (!isset($_GET["id"]) || empty($_GET["id"])) {
echo "No id defined.";
2015-12-07 18:05:58 +01:00
return;
}
$id = $_GET["id"];
$filePath = $dataDir . $id . ".json";
if (file_exists($filePath) && preg_match($uuidPattern, $id)) {
2015-12-07 18:05:58 +01:00
displayMessages($filePath);
} else {
echo "Invalid id.";
2015-12-07 18:05:58 +01:00
}
2015-12-07 18:05:58 +01:00
function displayMessages($filePath) {
$dataArray = getData($filePath);
$snapshotArray = $dataArray["snapshots"];
$usernameMap = $dataArray["usernames"];
2015-12-07 18:05:58 +01:00
foreach ($snapshotArray as $snapshotData) {
echo getMessageLine($snapshotData, $usernameMap);
2015-12-07 18:05:58 +01:00
echo "<br \>";
}
}
function getData($filename) {
2015-12-07 18:05:58 +01:00
return json_decode(file_get_contents($filename), true);
}
function getMessageLine($messageData, $usernameMap) {
return $usernameMap[$messageData["sender"]] . ": " . $messageData["message"];
2015-12-07 18:05:58 +01:00
}