diff options
Diffstat (limited to 'pages/toys.inc')
-rw-r--r-- | pages/toys.inc | 697 |
1 files changed, 0 insertions, 697 deletions
diff --git a/pages/toys.inc b/pages/toys.inc deleted file mode 100644 index df34af0..0000000 --- a/pages/toys.inc +++ /dev/null @@ -1,697 +0,0 @@ -<?php - -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; - -if (isset($_POST['deleteAction'])) { - $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true); - - $selected = null; - $selectedIndex = -1; - $id = $_POST['action']; - - foreach ($data as $index => $item) { - if ($item["id"] === $id) { - $selectedIndex = $index; - $selected = $item; - break; - } - } - - if ($selected === null) { - header("Location: /-/toys"); - die(); - } - - unset($data[$selectedIndex]); - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json", utf8_encode(json_encode($data))); - header("Location: /-/toys/?d&id=" . $id); - die(); -} - -if (isset($_POST['updateAction'])) { - $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true); - - $selected = null; - $selectedIndex = -1; - $id = $_POST['action']; - - foreach ($data as $index => $item) { - if ($item["id"] === $id) { - $selectedIndex = $index; - $selected = $item; - break; - } - } - - if ($selected === null) { - header("Location: /-/toys"); - die(); - } - - if (isset($_POST["sexual"])) { - $selected["sexual"] = true; - } else { - $selected["sexual"] = false; - } - - if (isset($_POST["name"])) $selected["name"] = strip_tags(trim($_POST["name"])); - if (isset($_POST["usage"])) $selected["usage"] = strip_tags(trim($_POST["usage"])); - if (isset($_POST["irl"])) $selected["irl"] = strip_tags(trim($_POST["irl"])); - if (isset($_POST["image"])) $selected["image"] = strip_tags(trim($_POST["image"])); - if (isset($_POST["usage_img"])) $selected["usage_img"] = strip_tags(trim($_POST["usage_img"])); - if (isset($_POST["keywords"])) $selected["keywords"] = array_map(function ($i) { - return trim($i); - }, explode(",", strip_tags(trim($_POST["keywords"])))); - if (isset($_POST["description"])) $selected["description"] = strip_tags(trim($_POST["description"])); - if (isset($_POST["water"])) $selected["water"] = match ($_POST["water"]) { - "0" => "out", - "1" => "in", - "2" => "both", - "3" => "playground" - }; - - if (isset($_POST["relations"])) { - $ponies = []; - - foreach ($_POST["relations"] as $relation => $d) { - $ponies[] = [ - "members" => explode("-", $relation), - "deprecated" => isset($d["deprecated"]), - "sexual" => isset($d["sexual"]) - ]; - } - - $selected["ponies"] = $ponies; - } - - global $_PROFILE; - if ($_PROFILE['login'] === "raindrops" && isset($_POST["verified"])) { - $selected["verified"] = true; - } else { - unset($selected["verified"]); - } - - if (isset($_POST["untested"])) { - $selected["untested"] = true; - } else { - unset($selected["untested"]); - } - - $data[$selectedIndex] = $selected; - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json", utf8_encode(json_encode($data))); - - header("Location: /-/toys/" . $id); - die(); -} - -if (isset($_POST['createAction'])) { - require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/random.inc"; - $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true); - - if (!isset($_POST["name"]) || !isset($_POST["water"])) { - header("Location: /-/toys"); - die(); - } - if (trim($_POST["name"]) === "" || !is_numeric($_POST["water"])) { - header("Location: /-/toys"); - die(); - } - - $water = match ($_POST["water"]) { - "0" => "out", - "1" => "in", - "2" => "both", - "3" => "playground" - }; - $name = strip_tags(trim($_POST["name"])); - $id = random(); - - $ponies = []; - - if (isset($_POST["relations"])) { - foreach ($_POST["relations"] as $relation => $_) { - $ponies[] = [ - "members" => explode("-", $relation), - "deprecated" => false - ]; - } - } - - if (isset($_POST["sexual"])) { - $sexual = true; - } else { - $sexual = false; - } - - $data[] = [ - "id" => $id, - "name" => $name, - "water" => $water, - "description" => null, - "ponies" => $ponies, - "usage" => null, - "irl" => null, - "image" => "", - "usage_img" => "", - "keywords" => [], - "sexual" => $sexual - ]; - - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json", utf8_encode(json_encode($data))); - header("Location: /-/toys/" . $id); - die(); -} - -global $pagename; -$parts = explode("/", $pagename); -$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true); - -$selected = null; - -if (isset($parts[1])) { - $id = $parts[1]; - - foreach ($data as $item) { - if ($item["id"] === $id) { - $selected = $item; - break; - } - } - - if ($selected === null) { - header("Location: /-/toys/?nf&id=" . $id); - die(); - } else { - $title = $selected["name"] . " · " . $title; - } -} - -require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; -require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/util/keywords.inc'; - -if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json", "[]"); - -global $_PROFILE; -global $pagename; -$parts = explode("/", $pagename); - -?> - -<script>requestExplicit("back");</script> - -<style> - @media (max-width: 800px) { - #toy-grid-img { - display: block !important; - } - } - - @media (max-width: 900px) { - #toy-grid-img2 { - display: block !important; - } - } -</style> - - <script src="/assets/editor/fuse.js"></script> - - <br> - <div class="container"> - <div id="<?= isset($parts[1]) ? "page-content" : "" ?>"> - <?php if (isset($_GET['nf'])): ?> - <div class="alert alert-danger alert-dismissible"> - <button onclick='window.history.pushState({"html":null,"pageTitle":document.title},"", "/-/toys/");' type="button" class="btn-close" data-bs-dismiss="alert" style="filter: none !important;"></button> - <b>Error: </b> The requested toy (<code><?= strip_tags($_GET['id'] ?? "-") ?></code>) was not found, it may have been deleted or has never existed. - </div> - <?php endif; ?> - - <?php if (isset($_GET['d'])): ?> - <div class="alert alert-success alert-dismissible"> - <button onclick='window.history.pushState({"html":null,"pageTitle":document.title},"", "/-/toys");' type="button" class="btn-close" data-bs-dismiss="alert" style="filter: none !important;"></button> - <b>Success: </b> The toy with ID <code><?= strip_tags($_GET['id'] ?? "-") ?></code> has been successfully deleted. - </div> - <?php endif; ?> - - <?php if (isset($parts[1])): ?> - - <h2> - <span style="vertical-align: middle;"><?= $selected["name"] ?></span> - <a href="/-/toys" class="small btn btn-outline-light" style="float:right;margin-top:5px;vertical-align:middle;opacity:1 !important; color:white;">Back</a> - </h2> - - <p> - <a onclick="event.target.blur();" data-bs-toggle="modal" data-bs-target="#editor" href="#">Edit</a> · - <?php if (!isset($selected["verified"])): ?><span class="badge bg-warning rounded-pill text-black">Unverified</span><?php endif; ?> - <?php if ($selected["water"] === "in"): ?> - <span style="" class="badge rounded-pill bg-primary">Underwater</span> - <?php elseif ($selected["water"] === "out"): ?> - <span style="background-color:#d63384;" class="badge rounded-pill">Outside of water</span> - <?php else: ?> - <span style="" class="badge rounded-pill bg-primary">Underwater</span> - <span style="background-color:#d63384;" class="badge rounded-pill">Outside of water</span> - <?php endif; ?> - </p> - - <div id="toy-grid-img" style="display: grid; grid-template-columns: 1fr <?php if (isset($selected["usage_img"]) && trim($selected["usage_img"]) !== ""): ?>2fr<?php endif; ?> !important; grid-gap: 20px;"> - <?php if (isset($selected["usage_img"]) && trim($selected["usage_img"]) !== ""): ?> - <div> - <img src="<?= $selected["usage_img"] ?>" style="width: 100%; max-height: 100vh;"> - </div> - <?php endif; ?> - <div> - - <?php if (isset($selected["description"]) && trim($selected["description"]) !== ""): ?> - <?= replaceKeyWords(str_replace("\n", "<br>", strip_tags($selected["description"]))); ?> - <?php else: ?> - <p><i>No description provided for this toy. Enter edit mode to add a description to this toy.</i></p> - <?php endif; ?> - - <hr> - - <div style="margin-top:10px;"></div> - - <div id="toy-grid-img2" style="display: grid; grid-template-columns: <?php if (isset($selected["usage_img"]) && $selected["usage_img"] !== ""): ?>3fr <?php if (isset($selected["image"]) && trim($selected["image"]) !== ""): ?>1fr<?php endif; ?><?php else: ?>6fr <?php if (isset($selected["image"]) && trim($selected["image"]) !== ""): ?>1fr<?php endif; ?><?php endif; ?> !important; grid-gap: 20px;"><div> - <b>Usage:</b><br> - <?php if (isset($selected["usage"]) && trim($selected["usage"]) !== ""): ?> - <?php - - $lines = explode("\n", strip_tags($selected["usage"])); - - if (count($lines) > 1) echo("<ul>"); - - foreach ($lines as $line) { - if (count($lines) > 1) echo("<li>"); - - $parts = explode(":", $line); - - if (count($parts) > 1 && strlen($parts[0]) < 30) { - $p0 = $parts[0]; array_shift($parts); - echo(replaceKeyWords("<b>" . $p0 . ":</b>" . implode(":", $parts))); - } else { - echo(replaceKeyWords(implode(":", $parts))); - } - - if (count($lines) > 1) echo("</li>"); - } - - if (count($lines) > 1) echo("</ul>"); - - ?> - <?php else: ?> - <p><i>No usage provided for this toy. Enter edit mode to add usage information to this toy.</i></p> - <?php endif; ?> - <div style="margin-top:10px;"></div> - - <b>Instructions to obtain in real life:</b><br> - <?php if (isset($selected["irl"]) && trim($selected["irl"]) !== ""): ?> - <?= replaceKeyWords(strip_tags($selected["irl"])) ?> - <?php else: ?> - <p><i><?php if (isset($selected["image"]) && $selected["image"] !== ""): ?>This toy is obtainable in real life, but no instructions are provided.<?php else: ?>This toy is not obtainable in real life.<?php endif; ?></i></p> - <?php endif; ?> - - </div> - <?php if (isset($selected["image"]) && trim($selected["image"]) !== ""): ?> - <div> - <img src="<?= $selected["image"] ?>" style="width: 100%; max-height: 100vh;"> - </div> - <?php endif; ?> - </div> - - - <hr> - - <h4>Similar toys</h4> - <div class="row"> - <?php - - $names = []; - $currentName = $selected["name"]; - $namesByDistance = []; - - foreach ($data as $action) { - if ($action["name"] !== $currentName) $names[$action["name"]] = [ - "id" => $action["id"], - "water" => $action["water"], - "ponies" => $action["ponies"], - "sexual" => $action["sexual"], - "description" => $action["description"] - ]; - } - - foreach ($names as $name => $data) { - $namesByDistance[] = [ - "name" => $name, - "distance" => levenshtein($currentName, $name), - "id" => $data["id"], - "description" => $data["description"], - "water" => $data["water"], - "ponies" => $data["ponies"], - "sexual" => $data["sexual"] - ]; - } - - uasort($namesByDistance, function ($a, $b) use ($selected) { - return $a["distance"] - $b["distance"]; - }); - - foreach ($namesByDistance as $item) { - echo("<!-- " . $currentName . " <-> " . $item["name"] . " => " . $item["distance"] . ") -->"); - } - - $index = 0; - foreach ($namesByDistance as $item): if ($index < 3): - ?> - <div class="col-md-4" style="margin-bottom:20px;"> - <a class="linked-card" href="/-/toys/<?= $item["id"] ?>"><div class="card"> - <div class="card-body"> - <h4 class="card-title"><?= $item["name"] ?></h4> - <p class="card-text"> - <?= strlen(strip_tags($item["description"])) > 100 ? substr(strip_tags($item["description"]), 0, 100) . "…" : strip_tags($item["description"]) ?> - </p> - <?php if ($item["water"] === "in"): ?> - <span style="" class="badge rounded-pill bg-primary">Underwater</span> - <?php elseif ($item["water"] === "out"): ?> - <span style="background-color:#d63384;" class="badge rounded-pill">Outside of water</span> - <?php elseif ($item["water"] === "playground"): ?> - <span class="badge rounded-pill" style="background-color:#20c997;">In playground</span> - <?php else: ?> - <span style="" class="badge rounded-pill bg-primary">Underwater</span> - <span style="background-color:#d63384;" class="badge rounded-pill">Outside of water</span> - <?php endif; ?> - </div> - </div></a> - </div> - <?php $index++; endif; endforeach; ?> - </div> - - <div class="modal fade" id="editor"> - <div class="modal-dialog modal-xl"> - <div class="modal-content"> - <div class="modal-header"> - <h4 class="modal-title">Edit toy</h4> - <button type="button" class="btn-close" data-bs-dismiss="modal"></button> - </div> - - <div class="modal-body"> - <form method="post" style="display:inline;"> - <input type="text" placeholder="Toy name" name="name" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;" value="<?= str_replace('"', '"', $selected["name"]) ?>"> - <select name="water" class="form-select" style='color:white;background-color:#111;border-color:#222;background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");'> - <option value="0" <?= $selected["water"] === "out" ? "selected" : "" ?>>Usable outside the water</option> - <option value="1" <?= $selected["water"] === "in" ? "selected" : "" ?>>Usable inside the water</option> - <option value="2" <?= $selected["water"] === "both" ? "selected" : "" ?>>Usable both inside and outside</option> - </select> - - <label style="margin-left:5px; display: none;"> - <input <?= ($selected["sexual"] ?? false) ? "checked" : "" ?> type="checkbox" name="sexual"> - Sexual toy - </label> - - <label style="margin-left:5px; margin-top: 12px;"> - <input class="form-check-input" <?= ($selected["verified"] ?? false) ? "checked" : "" ?> <?= $_PROFILE['login'] !== "raindrops" ? "disabled" : "" ?> type="checkbox" name="verified"> - Mark as verified - </label><br> - - <label style="margin-left:5px; display: none;"> - <input <?= ($selected["untested"] ?? false) ? "checked" : "" ?> type="checkbox" name="untested"> - Mark as untested - </label> - - <hr> - - <textarea rows="5" name="description" class="form-control" style="resize: none;color:white;background:#111;border-color:#222;margin-bottom:10px;" placeholder="Description"><?= strip_tags($selected["description"] ?? "") ?></textarea> - - <textarea rows="5" placeholder="Toy usage" name="usage" class="form-control" style="resize: none;color:white;background:#111;border-color:#222;margin-bottom:10px;"><?= strip_tags($selected["usage"] ?? "") ?></textarea> - - <hr> - - <input type="text" placeholder="Keywords (comma-separated)" name="keywords" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;" value="<?= str_replace('"', '"', implode(",", $selected["keywords"] ?? [])) ?>"> - - <input type="text" placeholder="Instructions to obtain IRL" name="irl" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;" value="<?= str_replace('"', '"', $selected["irl"] ?? "") ?>"> - - <input type="text" placeholder="URL to IRL image" name="image" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;" value="<?= str_replace('"', '"', $selected["image"] ?? "") ?>"> - - <input type="text" placeholder="URL to usage image" name="usage_img" class="form-control" style="color:white;background:#111;border-color:#222;" value="<?= str_replace('"', '"', $selected["usage_img"] ?? "") ?>"> - - <br> - <input type="hidden" name="updateAction"> - <input type="hidden" name="action" value="<?= $selected["id"] ?>"> - <input type="submit" class="btn btn-primary" value="Save"> - </form> - <form method="post" style="display:inline;"> - <input type="hidden" name="deleteAction"> - <input type="hidden" name="action" value="<?= $selected["id"] ?>"> - <input type="submit" class="btn btn-danger" value="Delete"> - </form> - </div> - </div> - </div> - </div> - </div></div> - - <?php else: ?> - - <h2>Toys database</h2> - <?php $complete = count(array_filter($data, function ($i) { - return (isset($i["description"]) && trim($i["description"]) === "") || !isset($i["description"]); - })); ?> - <p><?= count($data) ?> toys<?php if ($complete > 0): ?> (<?= $complete ?> incomplete)<?php endif; ?></p> - - <input type="text" placeholder="Search for a toy..." class="form-control" style="margin-bottom:15px;color:white;background:#111;border-color:#222;" onchange="search();" onkeydown="search();" onkeyup="search();" id="search"> - - <div id="list"> - <div class="list-group"> - <?php - - $init = []; - foreach ($data as $value) { - $init[$value["name"]] = $value; - } - - ksort($init); - - $sorted = array_values($init); - - foreach ($sorted as $item): ?> - <a href="/-/toys/<?= $item["id"] ?>" id="action-<?= $item["id"] ?>" style="display:grid;grid-template-columns: 1fr 0.2fr;" class="list-group-item list-group-item-action action-listing"> - <div> - <span class="<?= trim($item["description"]) === "" ? "text-danger" : "" ?>"><?= $item["name"] ?></span> - <?php if (!isset($item["verified"])): ?><span class="badge bg-warning rounded-pill text-black">Unverified</span><?php endif; ?> - </div> - </a> - <?php endforeach; ?> - </div> - </div> - - <div id="search-results" class="list-group"></div> - - <div id="page-content"> - <hr> - <p>Not finding what you are looking for? <a onclick="event.target.blur(); document.getElementById('creator-title').focus();" href="#" data-bs-toggle="modal" data-bs-target="#creator">Add a toy.</a></p> - </div> - - <script> - window.actions = JSON.parse(atob(`<?= base64_encode(json_encode(array_values(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true)))) ?>`)); - </script> - - <div class="modal fade" id="creator"> - <div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header"> - <h4 class="modal-title">Add a new toy</h4> - <button type="button" class="btn-close" data-bs-dismiss="modal"></button> - </div> - - <div class="modal-body"> - <form method="post"> - <input id="creator-title" type="text" placeholder="Toy name" name="name" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;"> - <select name="water" class="form-select" style='color:white;background-color:#111;border-color:#222;background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");'> - <option value="0" selected>Usable outside of the water</option> - <option value="1">Usable inside of the water</option> - <option value="2">Usable both inside and outside</option> - <option value="3">Usable in a playground</option> - </select> - - <p style="margin-top:10px;">You can add additional data (description, how to use) after adding the toy.</p> - <input type="hidden" name="createAction"> - <input type="submit" class="btn btn-primary" value="Add"> - </form> - </div> - </div> - </div> - </div> - - <?php endif; ?> - </div> - </div> - - <!--suppress JSUnresolvedFunction --> - <script> - Array.from(document.getElementsByClassName("checkbox-input")).forEach((el) => { - el.onchange = () => { - let parent = el.parentElement; - - if (el.checked) { - parent.classList.add("checked"); - } else { - parent.classList.remove("checked"); - } - } - }); - - const fuse = new Fuse(window.actions, { - includeScore: true, - keys: [ - { - name: 'name', - weight: 1 - }, - { - name: 'description', - weight: 1 - }, - { - name: 'example', - weight: 0.7 - }, - { - name: 'irl', - weight: 0.5 - } - ] - }) - - function search() { - let query = document.getElementById("search").value; - let results = fuse.search(query).map((i) => { - return { - id: i.item.id, - score: i.score - }; - }); - - let unfiltered = results; - - results = results.filter((i) => { - return i.score < 0.7; - }); - - console.log("Before:", unfiltered, "After:", results); - - document.getElementById("list").style.display = "none"; - document.getElementById("search-results").style.display = "block"; - document.getElementById("search-results").innerHTML = ""; - - for (let result of results) { - document.getElementById("search-results").innerHTML += document.getElementById("action-" + result.id).outerHTML; - } - - console.log(results); - - if (query.trim() === "") { - document.getElementById("list").style.display = "block"; - document.getElementById("search-results").style.display = "none"; - } - } - - function changeMixed() { - let value = document.getElementById("editor-type").value; - console.log(value); - - if (value === "2") { - Array.from(document.getElementsByClassName("creator-relation")).forEach((el) => { - el.classList.add("mixed"); - }); - } else { - Array.from(document.getElementsByClassName("creator-relation")).forEach((el) => { - el.classList.remove("mixed"); - }); - } - } - </script> - - <style> - .modal-header { - border-bottom: 1px solid #353738; - } - - .modal-content { - border: 1px solid rgba(255, 255, 255, .2); - background-color: #111; - } - - .btn-close { - filter: invert(1); - } - - .creator-relation { - border-radius: 10px; - padding: 5px 10px; - opacity: .5; - } - - .creator-relation.checked { - background-color: rgba(255, 255, 255, .1); - opacity: 1; - } - - .creator-relation:hover { - background-color: rgba(255, 255, 255, .1); - } - - .creator-relation.checked:hover { - background-color: rgba(255, 255, 255, .25) !important; - } - - .creator-relation.checked .deprecated { - display: block !important; - } - - .creator-relation.mixed.checked .sexual { - display: block !important; - } - - .list-group-item { - color: #fff; - background-color: #222; - border: 1px solid rgba(255, 255, 255, .125); - } - - .list-group-item.disabled { - color: #fff; - background-color: #222; - border-color: rgba(255, 255, 255, .125); - opacity: .75; - } - - .list-group-item:hover { - background-color: #252525; - color: #ddd; - } - - .list-group-item:active, .list-group-item:focus { - background-color: #272727; - color: #bbb; - } - - @media (max-width: 991px) { - .action-listing { - grid-template-columns: 1fr !important; - text-align: center !important; - } - - .action-listing > * { - margin-bottom: 10px; - text-align: center !important; - } - - .action-listing > *:nth-last-child(1) { - margin-bottom: 0 !important; - } - - .action-listing img { - width: 32px !important; - } - } - </style> - -<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?>
\ No newline at end of file |