2015-12-15 23:13:23 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('snapshot.php');
|
|
|
|
require_once('report.php');
|
|
|
|
require_once('message.php');
|
|
|
|
require_once('player.php');
|
|
|
|
|
2015-12-16 01:22:55 +01:00
|
|
|
const dataDir = 'data/';
|
2015-12-15 23:13:23 +01:00
|
|
|
|
|
|
|
// In Java this is "DateTimeFormatter.ISO_LOCAL_DATE_TIME"
|
2015-12-18 17:20:57 +01:00
|
|
|
const jsonDateTimeFormat = 'Y-m-d\TH:i:s';
|
2015-12-15 23:13:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param String $filename
|
|
|
|
* @return array JSON data array.
|
|
|
|
*/
|
|
|
|
function toDataArray($filename)
|
|
|
|
{
|
|
|
|
return json_decode(file_get_contents($filename), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param String $identifier
|
|
|
|
* @param array $snapshotData Snapshot data array.
|
|
|
|
* @return Snapshot
|
|
|
|
*/
|
|
|
|
function toSnapshot($identifier, $snapshotData)
|
|
|
|
{
|
|
|
|
$timezone = new DateTimeZone($snapshotData["timezone"]);
|
|
|
|
$players = toPlayers($snapshotData['usernames']);
|
|
|
|
$messages = toMessages($players, $snapshotData['snapshots'], $timezone);
|
|
|
|
$generated = parseDateTime($snapshotData["generated"], $timezone);
|
|
|
|
return new Snapshot($identifier, $messages, $players, $generated);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $reportData
|
|
|
|
* @param Player[] $players
|
|
|
|
* @return Report
|
|
|
|
*/
|
|
|
|
function toReport($reportData, $players)
|
|
|
|
{
|
|
|
|
$id = $reportData["id"];
|
|
|
|
$serverName = $reportData["serverName"];
|
2015-12-16 17:01:19 +01:00
|
|
|
$handler = array_key_exists("handler", $reportData) ? getPlayer($players, $reportData["handler"]) : null;
|
2015-12-15 23:13:23 +01:00
|
|
|
$suspect = getPlayer($players, $reportData["suspect"]);
|
|
|
|
$reporters = toReporters($players, $reportData["reporters"]);
|
2015-12-16 17:01:19 +01:00
|
|
|
return new Report($id, $serverName, $handler, $suspect, $reporters);
|
2015-12-15 23:13:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Player[] $players
|
|
|
|
* @param array $messagesData Messages data array.
|
|
|
|
* @param DateTimeZone $timezone
|
|
|
|
* @return Message[]
|
|
|
|
*/
|
|
|
|
function toMessages($players, $messagesData, $timezone)
|
|
|
|
{
|
|
|
|
$messages = array();
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($messagesData); $i++)
|
|
|
|
{
|
|
|
|
$messages[$i] = getMessage($players, $messagesData[$i], $timezone);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $messages;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Player[] $players
|
|
|
|
* @param array $messageData Message data array.
|
|
|
|
* @param DateTimeZone $timezone
|
|
|
|
* @return Message
|
|
|
|
*/
|
|
|
|
function getMessage($players, $messageData, $timezone)
|
|
|
|
{
|
|
|
|
$sender = getPlayer($players, $messageData['sender']);
|
|
|
|
$recipients = getPlayersFromUUIDs($players, $messageData['recipients']);
|
|
|
|
$dateTime = parseDateTime($messageData['time'], $timezone);
|
2015-12-16 01:22:55 +01:00
|
|
|
$type = Message::getTypeFromString($messageData['type']);
|
2015-12-15 23:13:23 +01:00
|
|
|
$message = $messageData['message'];
|
|
|
|
|
|
|
|
return new Message($sender, $recipients, $dateTime, $type, $message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Player[] $players
|
|
|
|
* @param String[] $uuidArray the UUIDs of the players to fetch
|
|
|
|
* @return Player[]
|
|
|
|
*/
|
|
|
|
function getPlayersFromUUIDs($players, $uuidArray)
|
|
|
|
{
|
|
|
|
$matchedPlayers = array();
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($uuidArray); $i++)
|
|
|
|
{
|
|
|
|
$matchedPlayers[$i] = getPlayer($players, $uuidArray[$i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $matchedPlayers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Player[] $playersArray
|
|
|
|
* @return Player[]
|
|
|
|
*/
|
|
|
|
function toPlayers($playersArray) // String UUID as Key
|
|
|
|
{
|
|
|
|
$players = array();
|
|
|
|
|
|
|
|
foreach ($playersArray as $uuid => $username)
|
|
|
|
{
|
|
|
|
$players[$uuid] = new Player($uuid, $username);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $players;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $playersArray
|
|
|
|
* @param $reportersArray
|
|
|
|
* @return SplObjectStorage
|
|
|
|
*/
|
|
|
|
function toReporters($playersArray, $reportersArray)
|
|
|
|
{
|
|
|
|
$reporters = new SplObjectStorage();
|
|
|
|
|
|
|
|
foreach ($reportersArray as $reporterUUID => $reason)
|
|
|
|
{
|
|
|
|
$reporters[getPlayer($playersArray, $reporterUUID)] = $reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $reporters;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Player[] $players
|
|
|
|
* @param String $uuid
|
|
|
|
* @return Player
|
|
|
|
*/
|
|
|
|
function getPlayer($players, $uuid)
|
|
|
|
{
|
|
|
|
$player = $players[$uuid];
|
|
|
|
|
|
|
|
if ($player != null)
|
|
|
|
{
|
|
|
|
return $player;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new RuntimeException('Player for UUID not found.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param String $dateTime
|
|
|
|
* @param DateTimeZone $timezone
|
|
|
|
* @return DateTime
|
|
|
|
*/
|
|
|
|
function parseDateTime($dateTime, $timezone)
|
|
|
|
{
|
2015-12-18 17:20:57 +01:00
|
|
|
return DateTime::createFromFormat(jsonDateTimeFormat, $dateTime, $timezone);
|
2015-12-15 23:13:23 +01:00
|
|
|
}
|
|
|
|
|
2015-12-29 06:51:50 +01:00
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Converts an interval to minutes, days or months, depending on the size.
|
|
|
|
*
|
|
|
|
* @param DateInterval $interval
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function approximateHumanInterval($interval)
|
|
|
|
{
|
|
|
|
if ($interval->m > 0)
|
|
|
|
{
|
|
|
|
return $interval->m . " months";
|
|
|
|
}
|
|
|
|
else if ($interval->d > 0)
|
|
|
|
{
|
|
|
|
return $interval->d . " days";
|
|
|
|
}
|
|
|
|
else if ($interval->h > 0)
|
|
|
|
{
|
|
|
|
return $interval->h . " hours";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $interval->i . " minutes";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 23:13:23 +01:00
|
|
|
/**
|
|
|
|
* @param String $input
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
function removeBadCharacters($input)
|
|
|
|
{
|
|
|
|
return preg_replace('/[^A-Za-z0-9_\-]/', '_', $input);
|
|
|
|
}
|
2015-12-18 17:20:57 +01:00
|
|
|
|
2015-12-18 18:41:03 +01:00
|
|
|
$validIdentifier = isset($_GET['identifier']);
|
|
|
|
$identifierError = "";
|
2015-12-18 17:20:57 +01:00
|
|
|
|
|
|
|
$identifier = null;
|
|
|
|
$filePath = null;
|
|
|
|
$snapshot = null;
|
|
|
|
$report = null;
|
|
|
|
|
2015-12-18 18:41:03 +01:00
|
|
|
if ($validIdentifier)
|
2015-12-18 17:20:57 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
$identifier = removeBadCharacters($_GET['identifier']); // prevents escaping
|
|
|
|
$filePath = dataDir . $identifier . '.json';
|
|
|
|
|
|
|
|
if (file_exists($filePath))
|
|
|
|
{
|
|
|
|
$dataArray = toDataArray($filePath);
|
|
|
|
$snapshot = toSnapshot($identifier, $dataArray);
|
|
|
|
$report = toReport($dataArray['report'], $snapshot->getPlayers());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-18 18:41:03 +01:00
|
|
|
$validIdentifier = false;
|
|
|
|
$identifierError = "Invalid identifier.";
|
2015-12-18 17:20:57 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-15 23:13:23 +01:00
|
|
|
?>
|
2015-12-16 01:22:55 +01:00
|
|
|
<!DOCTYPE html>
|
2015-12-15 23:13:23 +01:00
|
|
|
<html>
|
|
|
|
<head>
|
2015-12-16 01:22:55 +01:00
|
|
|
<script src="js/jquery.js"></script>
|
|
|
|
<link rel="stylesheet" href="css/bootstrap.min.css">
|
|
|
|
<script src="js/bootstrap.min.js"></script>
|
|
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
|
|
|
|
<link rel="stylesheet" href="css/tiger.css">
|
|
|
|
<link href='https://fonts.googleapis.com/css?family=Crete+Round' rel='stylesheet' type='text/css'>
|
|
|
|
<link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
|
2015-12-18 17:20:57 +01:00
|
|
|
<title>
|
2015-12-18 18:41:03 +01:00
|
|
|
<?php if ($validIdentifier) { ?>
|
2015-12-18 17:20:57 +01:00
|
|
|
Report #<?= $report->getId() ?>
|
|
|
|
<?php } else { ?>
|
|
|
|
Report System
|
|
|
|
<?php } ?>
|
2015-12-16 01:22:55 +01:00
|
|
|
|
2015-12-18 17:20:57 +01:00
|
|
|
· Mineplex
|
|
|
|
</title>
|
2015-12-16 01:22:55 +01:00
|
|
|
<script>
|
|
|
|
$("#test").click(function (){
|
|
|
|
alert("test!");
|
|
|
|
});
|
|
|
|
</script>
|
2015-12-15 23:13:23 +01:00
|
|
|
</head>
|
|
|
|
<body>
|
2015-12-16 01:22:55 +01:00
|
|
|
<div id="wrapper">
|
|
|
|
<div id="header">
|
|
|
|
<img src="img/logo.png" height="70px" width="70px" />
|
|
|
|
<h1>Report System</h1>
|
|
|
|
<!-- <h2><i class="fa fa-camera"></i> Chat Snap</h2> -->
|
|
|
|
</div>
|
|
|
|
<div id="search">
|
2015-12-18 16:52:20 +01:00
|
|
|
<form id="identifier-input" name="identifier-input" action="view.php" method="get">
|
|
|
|
<div class="input-group">
|
|
|
|
<input name="identifier" type="text" class="form-control" placeholder="Enter an identifier provided in-game...">
|
|
|
|
<span class="input-group-btn">
|
|
|
|
<button class="btn btn-secondary" type="submit" form="identifier-input"><i class="fa fa-search"></i> Search</button>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</form>
|
2015-12-16 01:22:55 +01:00
|
|
|
</div>
|
2015-12-18 18:41:03 +01:00
|
|
|
|
2015-12-18 19:11:25 +01:00
|
|
|
<?php if (isset($_GET['identifier']) && !$validIdentifier && !empty($identifierError)) { ?>
|
|
|
|
<div id="content" class="center-block" style="text-align: center; background-color: rgba(204, 34, 42, 0.52);">
|
|
|
|
<p class="error-oh-no" style="font-size: 60px;">What did you do?!?!?</p>
|
|
|
|
<img src="img/shaun.gif" />
|
|
|
|
<p class="error-oh-no" style="font-size: 40px;">Error: <?= $identifierError ?></p>
|
|
|
|
<br>
|
2015-12-16 01:22:55 +01:00
|
|
|
</div>
|
2015-12-18 19:11:25 +01:00
|
|
|
<?php } else { ?>
|
2016-01-07 17:21:33 +01:00
|
|
|
<?php if (!isset($_GET['identifier'])) {
|
|
|
|
exit();
|
|
|
|
}?>
|
|
|
|
|
2015-12-18 19:11:25 +01:00
|
|
|
<div id="content">
|
|
|
|
<div>
|
2015-12-16 01:22:55 +01:00
|
|
|
<hr>
|
2015-12-18 19:11:25 +01:00
|
|
|
<h2 style="font-family: 'Oswald', sans-serif; text-align: center;">
|
|
|
|
Report #<?= $report->getId() ?>
|
|
|
|
</h2>
|
|
|
|
<hr>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div id="chat" class="col-lg-7">
|
|
|
|
<h4><i class="fa fa-comments"></i> Chat Log</h4>
|
|
|
|
<hr>
|
|
|
|
<div id="log" class="text-muted ">
|
|
|
|
<?php
|
|
|
|
$messages = $snapshot->getMessages();
|
2015-12-16 01:22:55 +01:00
|
|
|
|
2015-12-18 19:11:25 +01:00
|
|
|
foreach($messages as $message):
|
|
|
|
$typeId = $message->getType();
|
|
|
|
$typeDisplayName = Message::$TYPE_DISPLAY_NAMES[$typeId];
|
|
|
|
$isPM = $typeId == Message::TYPE_PM;
|
2015-12-16 01:22:55 +01:00
|
|
|
|
2015-12-18 19:11:25 +01:00
|
|
|
// If this is a PM, then the "-> <recipient>" suffix will be applied.
|
|
|
|
$involved = $message->getSender()->getUsername() . ($isPM ? " -> " . $message->getRecipients()[0]->getUsername() : "");
|
|
|
|
?>
|
2015-12-16 01:22:55 +01:00
|
|
|
|
2015-12-18 19:11:25 +01:00
|
|
|
<span class="label <?php if($isPM) echo "label-primary chat pm"; else echo "label-info chat"; ?>" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><?= $typeDisplayName ?></span>
|
|
|
|
<span class="black"><?= $involved; ?>:</span> <?= $message->getMessage(); ?>
|
2015-12-16 01:22:55 +01:00
|
|
|
|
2015-12-18 19:11:25 +01:00
|
|
|
<?php if ($message != end($messages)){ // Don't break on the last element ?>
|
|
|
|
<br>
|
|
|
|
<?php } ?>
|
|
|
|
<?php endforeach; ?>
|
2015-12-16 01:22:55 +01:00
|
|
|
</div>
|
2015-12-18 19:11:25 +01:00
|
|
|
</div>
|
|
|
|
<div id="users" class="col-lg-5">
|
|
|
|
<h4><i class="fa fa-info-circle"></i> Information</h4>
|
|
|
|
<hr>
|
|
|
|
<div class="row">
|
2016-01-07 16:52:03 +01:00
|
|
|
<div class="col-lg-12">
|
2015-12-18 19:11:25 +01:00
|
|
|
<?php
|
2015-12-29 07:09:45 +01:00
|
|
|
$dateTime = $snapshot->getTimeGenerated();
|
2015-12-29 07:20:13 +01:00
|
|
|
$dateTimeFormatted = $dateTime->format('Y/m/d H:i:s T'); // originally m/d/Y H:i:s T
|
2015-12-29 07:09:45 +01:00
|
|
|
$age = approximateHumanInterval($dateTime->diff(new DateTime('now', $dateTime->getTimezone())));
|
2015-12-29 06:51:50 +01:00
|
|
|
|
2015-12-18 19:11:25 +01:00
|
|
|
$reporters = array();
|
2015-12-16 01:22:55 +01:00
|
|
|
|
2015-12-18 19:11:25 +01:00
|
|
|
foreach ($report->getReporters() as $reporter)
|
|
|
|
{
|
|
|
|
$reporters[count($reporters)] = $reporter->getUsername();
|
|
|
|
}
|
2015-12-16 01:22:55 +01:00
|
|
|
|
2015-12-18 19:11:25 +01:00
|
|
|
$reportersString = implode(", ", $reporters);
|
|
|
|
?>
|
2015-12-16 01:22:55 +01:00
|
|
|
|
2016-01-07 16:52:03 +01:00
|
|
|
<i class="fa fa-clock-o fa-fw"></i>
|
|
|
|
<span class="label label-pill label-default" title="<?= $dateTimeFormatted ?>"><?= $age . ' old' ?></span>
|
|
|
|
<br>
|
|
|
|
|
|
|
|
<i class="fa fa-user-plus fa-fw"></i>
|
|
|
|
<span class="label label-pill label-success">Reported by <?= $reportersString ?></span>
|
|
|
|
<br>
|
|
|
|
|
|
|
|
<i class="fa fa-user-times fa-fw"></i>
|
|
|
|
<span class="label label-pill label-danger">Suspect is <?= $report->getSuspect()->getUsername() ?></span>
|
|
|
|
<br>
|
|
|
|
|
|
|
|
<i class="fa fa-gavel fa-fw"></i>
|
|
|
|
<span class="label label-pill label-warning">
|
|
|
|
<?php
|
|
|
|
$handler = $report->getHandler();
|
|
|
|
echo $handler != null ? "Staff Member assigned is " . $handler->getUsername() : "No Staff Member assigned";
|
|
|
|
?>
|
2016-01-08 16:06:13 +01:00
|
|
|
</span>
|
2016-01-07 16:52:03 +01:00
|
|
|
<br>
|
2015-12-18 19:11:25 +01:00
|
|
|
</div>
|
2015-12-16 01:22:55 +01:00
|
|
|
</div>
|
2015-12-18 19:11:25 +01:00
|
|
|
<br>
|
|
|
|
|
|
|
|
<h4><i class="fa fa-users"></i> Users</h4>
|
|
|
|
<hr>
|
|
|
|
<?php foreach($snapshot->getPlayers() as $player): ?>
|
|
|
|
<img src="http://cravatar.eu/avatar/<?= $player->getUUID() ?>/55.png" class="pull-left" />
|
|
|
|
<b class="name"><?= $player->getUsername() ?></b> <span class="label label-staff name" hidden="hidden">TODO</span><br> <!-- TODO (unhide) -->
|
|
|
|
<code style="font-size: 11px;"><?= $player->getUUID() ?></code>
|
|
|
|
<br><br>
|
|
|
|
<?php endforeach; ?>
|
2015-12-16 01:22:55 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2015-12-18 19:11:25 +01:00
|
|
|
<?php } ?>
|
2016-01-07 16:52:03 +01:00
|
|
|
<div id="footer">
|
2015-12-16 01:22:55 +01:00
|
|
|
<a href="http://www.mineplex.com"><img src="img/logo-full.png" width="225px" /></a>
|
|
|
|
<div class="btn-group pull-right indent-link" style="font-family: 'Crete Round', serif; padding-top: 10px;">
|
|
|
|
<a href="http://www.mineplex.com" class="btn btn-link btn-small text-muted">Home</a>
|
|
|
|
<a href="http://www.mineplex.com/shop/" class="btn btn-link btn-small text-muted">Shop</a>
|
|
|
|
<a href="http://www.mineplex.com/forums/" class="btn btn-link btn-small text-muted">Forums</a>
|
|
|
|
<a href="http://www.mineplex.com/supporthub/" class="btn btn-link btn-small text-muted">Support</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2015-12-15 23:13:23 +01:00
|
|
|
</body>
|
|
|
|
</html>
|