Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
fanir | 16947714ec | ||
fanir | 2844fe18cc | ||
fanir | e575bb3a72 | ||
fanir | 606aaa1f03 |
152
index.php
152
index.php
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>MtG Card Data Gatherer</title>
|
||||
<title>MtG Card Data Collector</title>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
|
@ -11,10 +11,19 @@
|
|||
}
|
||||
h1 {
|
||||
font-size: 2rem;
|
||||
border-bottom: 0.2rem solid lightgray;
|
||||
border-bottom: 0.1em solid lightgray;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: inline-block;
|
||||
border-top: 0.2em solid lightgray;
|
||||
}
|
||||
footer,
|
||||
footer * {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
table#result {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
@ -58,6 +67,10 @@
|
|||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
label small {
|
||||
font-size: 0.75em;
|
||||
font-weight: normal;
|
||||
}
|
||||
textarea#query {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
@ -72,15 +85,39 @@
|
|||
border-color: hsl(224, 78%, 75%);
|
||||
background-color: hsl(224, 78%, 90%);
|
||||
}
|
||||
button[type=submit]:disabled {
|
||||
border-color: hsl(224, 20%, 90%);
|
||||
background-color: hsl(224, 20%, 75%);
|
||||
}
|
||||
|
||||
:required:invalid, :focus:invalid {
|
||||
/* insert your own styles for invalid form input */
|
||||
background-color: #ffeeee;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
function updateLineCounter() {
|
||||
var linecounter = document.getElementById("linecounter");
|
||||
var submit = document.getElementById("submit");
|
||||
var queryfield = document.getElementById("query");
|
||||
|
||||
var count = query.value.split(/\r|\r\n|\n/).length;
|
||||
linecounter.textContent = count+"/100";
|
||||
|
||||
if (count > 100) {
|
||||
linecounter.setAttribute("style", "color: red;");
|
||||
submit.setAttribute("disabled", "disabled");
|
||||
} else {
|
||||
linecounter.removeAttribute("style");
|
||||
submit.removeAttribute("disabled");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>MtG Card Data Collector</h1>
|
||||
<header>
|
||||
<h1>MtG Card Data Collector</h1>
|
||||
</header>
|
||||
<main>
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
@ -118,12 +155,15 @@ function x() {
|
|||
}
|
||||
|
||||
switch ($_REQUEST['format']) {
|
||||
case "set:num":
|
||||
case "cardname":
|
||||
$template = "{name}";
|
||||
break;
|
||||
case "set:number":
|
||||
$template = "{set}: {number}";
|
||||
break;
|
||||
case "cardname":
|
||||
case "setname:cardname":
|
||||
default:
|
||||
$template = "{name}";
|
||||
$template = "{setName}: {name}";
|
||||
}
|
||||
|
||||
$lines = explode("\n", $q);
|
||||
|
@ -139,12 +179,14 @@ function x() {
|
|||
$urls_only = false;
|
||||
foreach ($lines as $i => $line) {
|
||||
$parts = explode(' ', trim($line));
|
||||
if (count($parts) !== 2)
|
||||
continue;
|
||||
|
||||
$url = "https://api.magicthegathering.io/v1/cards?set=$parts[0]&number=$parts[1]";
|
||||
|
||||
if (!$urls_only) {
|
||||
$response = get_card_data($url);
|
||||
if ($i > 1){
|
||||
#if (isset($response["header"]["Ratelimit-Remaining"]) and $response["header"]["Ratelimit-Remaining"] === "0") {
|
||||
if (isset($response["header"]["Ratelimit-Remaining"]) and $response["header"]["Ratelimit-Remaining"] === "0") {
|
||||
echo "<br>Rate limit exceeded. Please try again in a few hours or use the raw result URLs.<br><br>";
|
||||
$urls_only = true;
|
||||
}
|
||||
|
@ -174,47 +216,75 @@ function x() {
|
|||
}
|
||||
x()
|
||||
?>
|
||||
<form id=form method=post>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<label for="format">Output Format:</label>
|
||||
<div>
|
||||
<select type="text" id="format" name="format" required>
|
||||
<form id=form method=post>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<label for="format">Output Format:</label>
|
||||
<div>
|
||||
<select type="text" id="format" name="format" required>
|
||||
<?php
|
||||
foreach ([
|
||||
"Card name" => "cardname",
|
||||
"Set: Number" => "set:num",
|
||||
"Set name: Card name" => "setname:cardname",
|
||||
"Set: Number" => "set:number",
|
||||
] as $label => $value) {
|
||||
$selected = $_REQUEST["format"] === $value ? " selected" : "";
|
||||
echo "<option value=\"$value\" $selected>$label</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<label style="display: block; margin: 0.25em 0;">
|
||||
<input name=prefix value=1 type=checkbox <?= !empty($_REQUEST["prefix"]) ? "checked" : "" ?>>
|
||||
Prefix with input and raw result URL
|
||||
</label>
|
||||
</select>
|
||||
<label style="display: block; margin: 0.25em 0;">
|
||||
<input name=prefix value=1 type=checkbox <?= !empty($_REQUEST["prefix"]) ? "checked" : "" ?>>
|
||||
Prefix with input and raw result URL
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label for="query">Cards:<br><small id=linecounter>0/100</small></label>
|
||||
<textarea id="query" name="query" rows="20" onkeyup="updateLineCounter();" <?= !isset($_REQUEST['query']) ? "autofocus" : "" ?> required placeholder="M12 7
|
||||
ORI 25
|
||||
AER 178"><?= !empty($_REQUEST['query']) ? $_REQUEST['query'] : "" ?></textarea>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div></div>
|
||||
<div>
|
||||
<p>
|
||||
Please keep in mind the data source for this service enforces a daily request limit,
|
||||
so please don't waste it. If no cards are found and you are sure your set codes and
|
||||
card numbers are valid, try again in a few hours or use the raw result URLs.
|
||||
</p>
|
||||
<p>
|
||||
Depending on how many cards you entered, loading the data will take a while.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span></span>
|
||||
<button id=submit type="submit">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label for="query">Cards:</label>
|
||||
<textarea id="query" name="query" rows="20" <?= !isset($_REQUEST['query']) ? "autofocus" : "" ?> required placeholder="M12 7
|
||||
ORI 25
|
||||
AER 178"><?= !empty($_REQUEST['query']) ? $_REQUEST['query'] : "M12 7\nORI 25\nAER 178" ?></textarea>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div></div>
|
||||
<p style="padding: 1em 0;">
|
||||
Please keep in mind the data source for this service enforces a daily request limit,
|
||||
so please don't waste it. If no cards are found and you are sure your set codes and
|
||||
card numbers are valid, try again in a few hours or use the raw result URLs.
|
||||
</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span></span>
|
||||
<button type="submit">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
</main>
|
||||
<footer>
|
||||
<p>
|
||||
Version:
|
||||
<?php
|
||||
$stdout=[];
|
||||
exec("git log --format=\"%h|%cd|%d\" --decorate=short --date=short HEAD~1..HEAD", $stdout);
|
||||
$parts = explode("|", $stdout[0]);
|
||||
|
||||
$offset_start = strpos($parts[2], "tag: ");
|
||||
if ($offset_start !== false) {
|
||||
$offset_start += 5;
|
||||
$offset_end = strpos($parts[2], ",", $offset_start) or strpos($parts[1], ")", $offset_start);
|
||||
|
||||
echo substr($parts[2], $offset_start, $offset_end - $offset_start), "; ";
|
||||
}
|
||||
echo $parts[0], " (", $parts[1], ")";
|
||||
?>
|
||||
| <a href="https://git.zom.bi/fanir/mtg-cdc">Source</a>
|
||||
</p>
|
||||
</footer>
|
||||
<script type="text/javascript">updateLineCounter()</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue