Fibinger Ádám
8 days ago ef54434d88f2caf5b1e35b30a9c7380af624d190
JSON letöltés tournament ID alapján
2 files modified
38 ■■■■ changed files
index.php 34 ●●●● patch | view | raw | blame | history
templates/index.twig 4 ●●●● patch | view | raw | blame | history
index.php
@@ -2,10 +2,10 @@
error_reporting(E_ALL);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/Budapest');
session_start();
include 'vendor/autoload.php';
use TableGenerator\DataObject;
use Wargasz\FileHelper;
$twig = \Wargasz\TwigFactory::getEnvironment('templates/');
@@ -34,6 +34,29 @@
    'alias_history' => 'Alias history'
];
if (!empty($_POST['tournament_id']) && strlen($_POST['tournament_id']) == 24)
{
    // 5f71b30a3ba5b62baf0659a8
    // https://api.battlefy.com/tournaments/5f71b30a3ba5b62baf0659a8/teams?page=1&limit=64
    if (preg_match('/[a-f0-9]{24}/sm', $_POST['tournament_id']))
    {
        $string = file_get_contents('https://api.battlefy.com/tournaments/' . $_POST['tournament_id'] . '/teams?page=1&limit=64');
        $messages[] = 'Downloading tournament ID: ' . $_POST['tournament_id'] . ' => ' . strlen($string);
        if ($string && json_decode($string) !== false)
        {
            $_POST['teams_json'] = $string;
            $_SESSION['tournament_id'] = $_POST['tournament_id'];
        }
        else
        {
            $messages[] = 'Sikertelen JSON letöltés...';
        }
    }
}
if (!empty($_POST['teams_json']))
{
    $forceDownload = isset($_POST['force_download']) && $_POST['force_download'] == 'on';
@@ -41,7 +64,7 @@
    $parser = new \Wargasz\BattlefyTeamParser($_POST['teams_json']);
    $table = $parser->getTeamData($forceDownload);
    $messages = $parser->getMessages();
    $messages = array_merge($messages, $parser->getMessages());
    file_put_contents(\Wargasz\BattlefyTeamParser::getWorkDir() . '/table.json', json_encode($table));
    file_put_contents(\Wargasz\BattlefyTeamParser::getWorkDir() . '/source-' . time() . '.json', $_POST['teams_json']);
@@ -79,7 +102,8 @@
}
echo $twig->render('index.twig', [
    'last_access' => $last_access,
    'table'       => $tableData,
    'messages'    => $messages
    'tournament_id' => $_SESSION['tournament_id'] ?? '',
    'last_access'   => $last_access,
    'table'         => $tableData,
    'messages'      => $messages
]);
templates/index.twig
@@ -8,6 +8,10 @@
            <label for="exampleFormControlTextarea1">Teams JSON</label>
            <textarea name="teams_json" class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
        </div>
        <div class="form-group">
            <label for="tournament_id">Tournament ID</label>
            <input name="tournament_id" id="tournament_id" class="form-control" maxlength="24" minlength="24" pattern="[a-f0-9]{24}" value="{{ tournament_id }}"/>
        </div>
        <div class="form-check">
            <input type="checkbox" class="form-check-input" id="exampleCheck1" name="force_download">
            <label class="form-check-label" for="exampleCheck1">R6 Tracker fájlok újraletöltése (cache frissítés, ha van