diff options
Diffstat (limited to 'emotes')
| -rw-r--r-- | emotes/delete.php | 2 | ||||
| -rw-r--r-- | emotes/index.php | 16 | ||||
| -rw-r--r-- | emotes/rate.php | 4 | ||||
| -rw-r--r-- | emotes/setmanip.php | 10 | ||||
| -rw-r--r-- | emotes/upload.php | 596 |
5 files changed, 314 insertions, 314 deletions
diff --git a/emotes/delete.php b/emotes/delete.php index 159e293..03b6dec 100644 --- a/emotes/delete.php +++ b/emotes/delete.php @@ -16,7 +16,7 @@ if (!isset($_POST["id"])) { $emote_id = $_POST["id"]; $user_id = $_SESSION["user_id"]; -$db = new PDO(DB_URL, DB_USER, DB_PASS); +$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['pass']); $stmt = $db->prepare("SELECT uploaded_by, code FROM emotes WHERE id = ?"); $stmt->execute([$emote_id]); diff --git a/emotes/index.php b/emotes/index.php index 80a8c1d..3999d8e 100644 --- a/emotes/index.php +++ b/emotes/index.php @@ -8,7 +8,7 @@ include "{$_SERVER['DOCUMENT_ROOT']}/lib/alert.php"; authorize_user(); -$db = new PDO(DB_URL, DB_USER, DB_PASS); +$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['pass']); $user_id = $_SESSION["user_id"] ?? ""; @@ -126,7 +126,7 @@ if (CLIENT_REQUIRES_JSON) { <head> <title><?php - echo ($emote != null ? "Emote " . $emote->get_code() : "Emotes") . ' - ' . INSTANCE_NAME + echo ($emote != null ? "Emote " . $emote->get_code() : "Emotes") . ' - ' . CONFIG['instance']['name'] ?></title> <link rel="stylesheet" href="/static/style.css"> <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"> @@ -302,9 +302,9 @@ if (CLIENT_REQUIRES_JSON) { if ($row = $stmt->fetch()) { echo 'You gave <img src="/static/img/icons/ratings/' . $row["rate"] . '.png" width="16" height="16"'; - echo 'title="' . RATING_NAMES[$row["rate"]] . '">'; + echo 'title="' . CONFIG['rating']['names'][$row["rate"]] . '">'; } else { - foreach (RATING_NAMES as $key => $value) { + foreach (CONFIG['rating']['names'] as $key => $value) { echo '<form action="/emotes/rate.php" method="POST">'; echo '<input type="text" name="id" value="' . $emote->get_id() . '"style="display: none;">'; echo "<input type=\"text\" name=\"rate\" value=\"$key\" style=\"display:none;\">"; @@ -316,7 +316,7 @@ if (CLIENT_REQUIRES_JSON) { } } } - if (REPORTS_ENABLE && $_SESSION["user_role"]["permission_report"]) { + if (CONFIG['reports']['enable'] && $_SESSION["user_role"]["permission_report"]) { echo "<a class='button red' href='/report?emote_id={$emote->id}'>Report emote</a>"; } } @@ -348,7 +348,7 @@ if (CLIENT_REQUIRES_JSON) { <tr> <th>Uploader</th> <td><?php - $username = ANONYMOUS_DEFAULT_NAME; + $username = CONFIG['anonymous']['defaultname']; $link = "#"; $show_private_badge = false; $badge = null; @@ -411,11 +411,11 @@ if (CLIENT_REQUIRES_JSON) { echo '</span></td></tr>'; } - if (RATING_ENABLE): ?> + if (CONFIG['rating']['enable']): ?> <tr> <th>Rating</th> <?php - if ($emote->get_rating()["total"] < RATING_EMOTE_MIN_VOTES) { + if ($emote->get_rating()["total"] < CONFIG['rating']['minvotes']) { echo '<td>Not rated (' . $emote->get_rating()["total"] . ')</td>'; } else { diff --git a/emotes/rate.php b/emotes/rate.php index fbea404..2e862f9 100644 --- a/emotes/rate.php +++ b/emotes/rate.php @@ -4,7 +4,7 @@ include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/utils.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/config.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/accounts.php"; -if (!RATING_ENABLE) { +if (!CONFIG['rating']['enable']) { generate_alert("/404.php", "Emote ratings are disabled", 403); exit; } @@ -26,7 +26,7 @@ if ($id == 0 || $rate == 0) { exit; } -$db = new PDO(DB_URL, DB_USER, DB_PASS); +$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['pass']); // checking if emote exists $stmt = $db->prepare("SELECT id FROM emotes WHERE id = ?"); diff --git a/emotes/setmanip.php b/emotes/setmanip.php index cf8add6..d6a5f4f 100644 --- a/emotes/setmanip.php +++ b/emotes/setmanip.php @@ -18,7 +18,7 @@ if (!isset($_POST["id"], $_POST["action"], $_POST["emote_set_id"])) { exit; } -$db = new PDO(DB_URL, DB_USER, DB_PASS); +$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['pass']); // checking emote $emote_id = $_POST["id"]; @@ -62,7 +62,7 @@ switch ($action) { $stmt = $db->prepare("INSERT INTO emote_set_contents(emote_set_id, emote_id, added_by) VALUES (?, ?, ?)"); $stmt->execute([$emote_set_id, $emote_id, $user_id]); - if (ACCOUNT_LOG_ACTIONS) { + if (CONFIG['account']['log']) { $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") ->execute([$user_id, "EMOTESET_ADD", json_encode($payload)]); } @@ -82,7 +82,7 @@ switch ($action) { exit; } - if (ACCOUNT_LOG_ACTIONS) { + if (CONFIG['account']['log']) { $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") ->execute([$user_id, "EMOTESET_REMOVE", json_encode($payload)]); } @@ -98,7 +98,7 @@ switch ($action) { exit; } - $value = str_safe($_POST["value"], EMOTE_NAME_MAX_LENGTH); + $value = str_safe($_POST["value"], CONFIG['emote']['maxnamelength']); $stmt = $db->prepare("SELECT esc.code AS alias_code, e.code FROM emote_set_contents esc INNER JOIN emotes e ON e.id = esc.emote_id @@ -121,7 +121,7 @@ switch ($action) { $stmt = $db->prepare("UPDATE emote_set_contents SET code = ? WHERE emote_set_id = ? AND emote_id = ?"); $stmt->execute([$value, $emote_set_id, $emote_id]); - if (ACCOUNT_LOG_ACTIONS) { + if (CONFIG['account']['log']) { $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") ->execute([$user_id, "EMOTESET_ALIAS", json_encode($payload)]); } diff --git a/emotes/upload.php b/emotes/upload.php index 01ae1ee..e509345 100644 --- a/emotes/upload.php +++ b/emotes/upload.php @@ -4,27 +4,27 @@ include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/config.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/alert.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/captcha.php"; -if (!EMOTE_UPLOAD) { +if (!CONFIG['emote']['upload']) { generate_alert("/404.php", "Emote upload is disabled", 403); exit; } authorize_user(); -if (!ANONYMOUS_UPLOAD && isset($_SESSION["user_role"]) && !$_SESSION["user_role"]["permission_upload"]) { +if (!CONFIG['anonymous']['upload'] && isset($_SESSION["user_role"]) && !$_SESSION["user_role"]["permission_upload"]) { generate_alert("/404.php", "Not enough permissions", 403); exit; } $uploaded_by = null; -$uploader_name = ANONYMOUS_DEFAULT_NAME; +$uploader_name = CONFIG['anonymous']['defaultname']; if (isset($_SESSION["user_role"]) && $_SESSION["user_role"]["permission_upload"]) { $uploaded_by = $_SESSION["user_id"] ?? null; - $uploader_name = $_SESSION["user_name"] ?? ANONYMOUS_DEFAULT_NAME; + $uploader_name = $_SESSION["user_name"] ?? CONFIG['anonymous']['defaultname']; } -$db = new PDO(DB_URL, DB_USER, DB_PASS); +$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['pass']); function abort_upload(string $path, PDO $db, string $id) { @@ -39,152 +39,152 @@ function abort_upload(string $path, PDO $db, string $id) include "{$_SERVER['DOCUMENT_ROOT']}/lib/utils.php"; include "{$_SERVER['DOCUMENT_ROOT']}/lib/images.php"; -$max_width = EMOTE_MAX_SIZE[0]; -$max_height = EMOTE_MAX_SIZE[1]; +$max_width = CONFIG['emote']['maxsizex']; +$max_height = CONFIG['emote']['maxsizey']; if ($_SERVER['REQUEST_METHOD'] != "POST") { include "{$_SERVER['DOCUMENT_ROOT']}/lib/partials.php"; echo '' ?> - <html> - - <head> - <title>Upload an emote - <?php echo INSTANCE_NAME ?></title> - <link rel="stylesheet" href="/static/style.css"> - <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"> - </head> - - <body> - <div class="container"> - <div class="wrapper"> - <?php html_navigation_bar() ?> - <?php display_alert() ?> - - <section class="content row"> - <div class="column small-gap"> - <section class="box"> - <div class="box navtab"> - <div> - <b>Upload a new emote</b> - <p style="font-size:8px;">You can just upload, btw. Anything you want.</p> - </div> - </div> - <div class="box content"> - <form action="/emotes/upload.php" method="POST" enctype="multipart/form-data"> - <h3>Image<span style="color:red;">*</span></h3> - - <input type="file" name="file" id="form-file" accept=".gif,.jpg,.jpeg,.png,.webp" - required> - - <div id="form-manual-files" style="display:none;"> - <input type="file" name="file-1x" id="form-file-1x" - accept=".gif,.jpg,.jpeg,.png,.webp"> - <label class="inline" - for="file-1x"><?php echo sprintf("%dx%d", EMOTE_MAX_SIZE[0] / 4, EMOTE_MAX_SIZE[1] / 4) ?></label> - <input type="file" name="file-2x" id="form-file-2x" - accept=".gif,.jpg,.jpeg,.png,.webp"> - <label class="inline" - for="file-2x"><?php echo sprintf("%dx%d", EMOTE_MAX_SIZE[0] / 2, EMOTE_MAX_SIZE[1] / 2) ?></label> - <input type="file" name="file-3x" id="form-file-3x" - accept=".gif,.jpg,.jpeg,.png,.webp"> - <label class="inline" - for="file-3x"><?php echo sprintf("%dx%d", EMOTE_MAX_SIZE[0], EMOTE_MAX_SIZE[1]) ?></label> - </div> - - <div> - <label for="manual" class="inline">Manual resize</label> - <input type="checkbox" name="manual" value="1" onchange="display_manual_resize()"> - </div> - - <h3>Emote name<span style="color:red;">*</span></h3> - <input type="text" name="code" id="code" required> - - <div> - <label for="visibility" class="inline">Emote visibility: </label> - <select name="visibility" id="form-visibility"> - <option value="1">Public</option> - <option value="0">Unlisted</option> - </select><br> - <p id="form-visibility-description" style="font-size: 10px;">test</p> + <html> + + <head> + <title>Upload an emote - <?php echo CONFIG['instance']['name'] ?></title> + <link rel="stylesheet" href="/static/style.css"> + <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"> + </head> + + <body> + <div class="container"> + <div class="wrapper"> + <?php html_navigation_bar() ?> + <?php display_alert() ?> + + <section class="content row"> + <div class="column small-gap"> + <section class="box"> + <div class="box navtab"> + <div> + <b>Upload a new emote</b> + <p style="font-size:8px;">You can just upload, btw. Anything you want.</p> + </div> </div> - - <label for="notes">Approval notes</label> - <textarea name="notes" id="form-notes"></textarea> - - <table class="vertical left font-weight-normal"> - <tr> - <th>Emote source:</th> - <td class="flex"><input class="grow" name="source" id="form-source"></input> - </td> - </tr> - <?php if (TAGS_ENABLE && TAGS_MAX_COUNT != 0): ?> - <tr> - <th>Tags <span class="font-small" style="cursor: help;" title="<?php - echo 'Tags are used for fast search. '; - if (TAGS_MAX_COUNT > 0) { - echo 'You can use ' . TAGS_MAX_COUNT . ' tags. '; - } - echo 'They are space-separated o algo.'; - ?>">[?]</span>: - </th> - <td class="flex"><input class="grow" name="tags" id="form-tags"></input></td> - </tr> - <?php endif; ?> - </table> - - <div> - <label for="tos" class="inline">Do you accept <a href="/rules.php" - target="_BLANK">the - rules</a>?<span style="color:red;">*</span></label> - <input type="checkbox" name="tos" value="1" required> + <div class="box content"> + <form action="/emotes/upload.php" method="POST" enctype="multipart/form-data"> + <h3>Image<span style="color:red;">*</span></h3> + + <input type="file" name="file" id="form-file" accept=".gif,.jpg,.jpeg,.png,.webp" + required> + + <div id="form-manual-files" style="display:none;"> + <input type="file" name="file-1x" id="form-file-1x" + accept=".gif,.jpg,.jpeg,.png,.webp"> + <label class="inline" + for="file-1x"><?php echo sprintf("%dx%d", CONFIG['emote']['maxsizex'] / 4, CONFIG['emote']['maxsizey'] / 4) ?></label> + <input type="file" name="file-2x" id="form-file-2x" + accept=".gif,.jpg,.jpeg,.png,.webp"> + <label class="inline" + for="file-2x"><?php echo sprintf("%dx%d", CONFIG['emote']['maxsizex'] / 2, CONFIG['emote']['maxsizey'] / 2) ?></label> + <input type="file" name="file-3x" id="form-file-3x" + accept=".gif,.jpg,.jpeg,.png,.webp"> + <label class="inline" + for="file-3x"><?php echo sprintf("%dx%d", CONFIG['emote']['maxsizex'], CONFIG['emote']['maxsizey']) ?></label> + </div> + + <div> + <label for="manual" class="inline">Manual resize</label> + <input type="checkbox" name="manual" value="1" onchange="display_manual_resize()"> + </div> + + <h3>Emote name<span style="color:red;">*</span></h3> + <input type="text" name="code" id="code" required> + + <div> + <label for="visibility" class="inline">Emote visibility: </label> + <select name="visibility" id="form-visibility"> + <option value="1">Public</option> + <option value="0">Unlisted</option> + </select><br> + <p id="form-visibility-description" style="font-size: 10px;">test</p> + </div> + + <label for="notes">Approval notes</label> + <textarea name="notes" id="form-notes"></textarea> + + <table class="vertical left font-weight-normal"> + <tr> + <th>Emote source:</th> + <td class="flex"><input class="grow" name="source" id="form-source"></input> + </td> + </tr> + <?php if (CONFIG['tags']['enable'] && CONFIG['tags']['maxcount'] != 0): ?> + <tr> + <th>Tags <span class="font-small" style="cursor: help;" title="<?php + echo 'Tags are used for fast search. '; + if (CONFIG['tags']['maxcount'] > 0) { + echo 'You can use ' . CONFIG['tags']['maxcount'] . ' tags. '; + } + echo 'They are space-separated o algo.'; + ?>">[?]</span>: + </th> + <td class="flex"><input class="grow" name="tags" id="form-tags"></input></td> + </tr> + <?php endif; ?> + </table> + + <div> + <label for="tos" class="inline">Do you accept <a href="/rules.php" + target="_BLANK">the + rules</a>?<span style="color:red;">*</span></label> + <input type="checkbox" name="tos" value="1" required> + </div> + + <button type="submit" id="upload-button">Upload as + <?php echo $uploader_name ?></button> + </form> </div> + </section> - <button type="submit" id="upload-button">Upload as - <?php echo $uploader_name ?></button> - </form> + <?php + if (CONFIG['captcha']['enable'] && (CONFIG['captcha']['force'] || !isset($_SESSION["user_id"]))) { + html_captcha_form(); + } + ?> </div> - </section> - <?php - if (CAPTCHA_ENABLE && (CAPTCHA_FORCE_USERS || !isset($_SESSION["user_id"]))) { - html_captcha_form(); - } - ?> - </div> - - <div class="column small-gap grow" id="emote-showcase" style="display: none;"> - <!-- Emote Preview --> - <section class="box"> - <div class="box navtab"> - Emote Preview - <span id="emote-name"><i>Empty</i></span> - </div> - <div class="box content"> - <div class="emote-showcase items-bottom"> - <div class="emote-image column items-center small-gap"> - <img src="" alt="" class="emote-image-1x"> - <p class="size font-small"></p> + <div class="column small-gap grow" id="emote-showcase" style="display: none;"> + <!-- Emote Preview --> + <section class="box"> + <div class="box navtab"> + Emote Preview - <span id="emote-name"><i>Empty</i></span> </div> - <div class="emote-image column items-center small-gap"> - <img src="" alt="" class="emote-image-2x"> - <p class="size font-small"></p> + <div class="box content"> + <div class="emote-showcase items-bottom"> + <div class="emote-image column items-center small-gap"> + <img src="" alt="" class="emote-image-1x"> + <p class="size font-small"></p> + </div> + <div class="emote-image column items-center small-gap"> + <img src="" alt="" class="emote-image-2x"> + <p class="size font-small"></p> + </div> + <div class="emote-image column items-center small-gap"> + <img src="" alt="" class="emote-image-3x"> + <p class="size font-small"></p> + </div> + </div> + <p style="font-size: 12px;">The result may differ.</p> </div> - <div class="emote-image column items-center small-gap"> - <img src="" alt="" class="emote-image-3x"> - <p class="size font-small"></p> - </div> - </div> - <p style="font-size: 12px;">The result may differ.</p> - </div> - </section> + </section> - <!-- Chat Preview --> - <section class="box"> - <div class="box navtab"> - Chat Preview - </div> - <div class="box content no-gap column chat rounded"> - <?php - $stmt = $db->query("SELECT u.username, + <!-- Chat Preview --> + <section class="box"> + <div class="box navtab"> + Chat Preview + </div> + <div class="box content no-gap column chat rounded"> + <?php + $stmt = $db->query("SELECT u.username, CASE WHEN ub.badge_id IS NOT NULL THEN ub.badge_id WHEN r.badge_id IS NOT NULL THEN r.badge_id @@ -197,194 +197,194 @@ if ($_SERVER['REQUEST_METHOD'] != "POST") { ORDER BY RAND() LIMIT 3 "); - while ($row = $stmt->fetch()) { - echo '<div class="row small-gap items-center chat-message">'; + while ($row = $stmt->fetch()) { + echo '<div class="row small-gap items-center chat-message">'; - if ($row["badge_id"]) { - echo '<img src="/static/userdata/badges/' . $row["badge_id"] . '/1x.webp" alt="" title="" /> '; - } + if ($row["badge_id"]) { + echo '<img src="/static/userdata/badges/' . $row["badge_id"] . '/1x.webp" alt="" title="" /> '; + } - echo '<span style="color: rgb(' . random_int(128, 255) . ', ' . random_int(128, 255) . ', ' . random_int(128, 255) . ')">'; - echo $row["username"]; - echo ': </span>'; + echo '<span style="color: rgb(' . random_int(128, 255) . ', ' . random_int(128, 255) . ', ' . random_int(128, 255) . ')">'; + echo $row["username"]; + echo ': </span>'; - echo '<img src="" alt="" class="emote-image-1x">'; + echo '<img src="" alt="" class="emote-image-1x">'; - echo '</div>'; - } - ?> + echo '</div>'; + } + ?> + </div> + </section> </div> </section> </div> - </section> - </div> - </div> - </body> - - <script> - const max_width = <?php echo EMOTE_MAX_SIZE[0] ?>; - const max_height = <?php echo EMOTE_MAX_SIZE[1] ?>; - - const fileInput = document.getElementById("form-file"); - const showcase = document.getElementById("emote-showcase"); - const reader = new FileReader(); - - let manual = false; - - fileInput.addEventListener("change", (e) => { - if (manual) return; - - showcase.style.display = "flex"; - reader.readAsDataURL(e.target.files[0]); - reader.onload = (e) => { - const image = new Image(); - image.src = e.target.result; - image.onload = () => { - let m = 1; - - for (let i = 3; i > 0; i--) { - place_image(i, m, e, image); - m *= 2; - } - }; - }; - }); + </div> + </body> + + <script> + const max_width = <?php echo CONFIG['emote']['maxsizex'] ?>; + const max_height = <?php echo CONFIG['emote']['maxsizey'] ?>; + + const fileInput = document.getElementById("form-file"); + const showcase = document.getElementById("emote-showcase"); + const reader = new FileReader(); + + let manual = false; + + fileInput.addEventListener("change", (e) => { + if (manual) return; + + showcase.style.display = "flex"; + reader.readAsDataURL(e.target.files[0]); + reader.onload = (e) => { + const image = new Image(); + image.src = e.target.result; + image.onload = () => { + let m = 1; + + for (let i = 3; i > 0; i--) { + place_image(i, m, e, image); + m *= 2; + } + }; + }; + }); - const code = document.getElementById("code"); + const code = document.getElementById("code"); - code.addEventListener("input", (e) => { - const regex = <?php echo EMOTE_NAME_REGEX ?>; + code.addEventListener("input", (e) => { + const regex = <?php echo CONFIG['emote']['nameregex'] ?>; - if (regex.test(e.target.value) && e.target.value.length <= <?php echo EMOTE_NAME_MAX_LENGTH ?>) { - validCode = e.target.value; - } else { - e.target.value = validCode; - } + if (regex.test(e.target.value) && e.target.value.length <= <?php echo CONFIG['emote']['maxnamelength'] ?>) { + validCode = e.target.value; + } else { + e.target.value = validCode; + } - document.getElementById("emote-name").innerHTML = e.target.value ? e.target.value : "<i>Empty</i>"; - }); + document.getElementById("emote-name").innerHTML = e.target.value ? e.target.value : "<i>Empty</i>"; + }); - const visibility = document.getElementById("form-visibility"); - visibility.addEventListener("change", (e) => { - set_form_visibility_description(visibility.value); - }); + const visibility = document.getElementById("form-visibility"); + visibility.addEventListener("change", (e) => { + set_form_visibility_description(visibility.value); + }); - function set_form_visibility_description(visibility) { - const p = document.getElementById("form-visibility-description"); + function set_form_visibility_description(visibility) { + const p = document.getElementById("form-visibility-description"); - if (visibility == 1) { - p.innerHTML = "Emote won't appear on the public list until it passes a moderator's review. It still can be added to chats."; - } else { - p.innerHTML = "Emote doesn't appear on the public list and won't be subject to moderation checks. It still can be added to chats."; - } - } + if (visibility == 1) { + p.innerHTML = "Emote won't appear on the public list until it passes a moderator's review. It still can be added to chats."; + } else { + p.innerHTML = "Emote doesn't appear on the public list and won't be subject to moderation checks. It still can be added to chats."; + } + } - set_form_visibility_description(visibility.value); + set_form_visibility_description(visibility.value); - // Manual resize - function display_manual_resize() { - const manual_files = document.getElementById("form-manual-files"); + // Manual resize + function display_manual_resize() { + const manual_files = document.getElementById("form-manual-files"); - // resetting previous values - const files = document.querySelectorAll("input[type=file]"); + // resetting previous values + const files = document.querySelectorAll("input[type=file]"); - for (let file of files) { - file.value = null; - file.removeAttribute("required"); - } + for (let file of files) { + file.value = null; + file.removeAttribute("required"); + } - const fileImages = document.querySelectorAll(".emote-image img"); + const fileImages = document.querySelectorAll(".emote-image img"); - for (let file of fileImages) { - file.setAttribute("src", ""); - file.setAttribute("width", "0"); - file.setAttribute("height", "0"); - } + for (let file of fileImages) { + file.setAttribute("src", ""); + file.setAttribute("width", "0"); + file.setAttribute("height", "0"); + } - const fileSizes = document.querySelectorAll(".emote-image .size"); + const fileSizes = document.querySelectorAll(".emote-image .size"); - for (let file of fileImages) { - file.innerHTML = ""; - } + for (let file of fileImages) { + file.innerHTML = ""; + } - manual = !manual; + manual = !manual; - if (manual) { - manual_files.style.display = "block"; - fileInput.style.display = "none"; - const elements = document.querySelectorAll("#form-manual-files input[type=file]"); - for (let elem of elements) { - elem.setAttribute("required", "true"); - } - } else { - manual_files.style.display = "none"; - fileInput.style.display = "block"; - fileInput.setAttribute("required", "true"); - } + if (manual) { + manual_files.style.display = "block"; + fileInput.style.display = "none"; + const elements = document.querySelectorAll("#form-manual-files input[type=file]"); + for (let elem of elements) { + elem.setAttribute("required", "true"); + } + } else { + manual_files.style.display = "none"; + fileInput.style.display = "block"; + fileInput.setAttribute("required", "true"); + } - showcase.style.display = "none"; - } + showcase.style.display = "none"; + } - document.getElementById("form-file-1x").addEventListener("change", (e) => { - showcase.style.display = "flex"; - place_image(1, 4, e, null); - }); - - document.getElementById("form-file-2x").addEventListener("change", (e) => { - showcase.style.display = "flex"; - place_image(2, 2, e, null); - }); - - document.getElementById("form-file-3x").addEventListener("change", (e) => { - showcase.style.display = "flex"; - place_image(3, 1, e, null); - }); - - function place_image(image_index, multiplier, e, image) { - let ee = e; - - if (image == null) { - reader.readAsDataURL(e.target.files[0]); - reader.onload = (e) => { - const image = new Image(); - image.src = e.target.result; - image.onload = () => { + document.getElementById("form-file-1x").addEventListener("change", (e) => { + showcase.style.display = "flex"; + place_image(1, 4, e, null); + }); + + document.getElementById("form-file-2x").addEventListener("change", (e) => { + showcase.style.display = "flex"; + place_image(2, 2, e, null); + }); + + document.getElementById("form-file-3x").addEventListener("change", (e) => { + showcase.style.display = "flex"; + place_image(3, 1, e, null); + }); + + function place_image(image_index, multiplier, e, image) { + let ee = e; + + if (image == null) { + reader.readAsDataURL(e.target.files[0]); + reader.onload = (e) => { + const image = new Image(); + image.src = e.target.result; + image.onload = () => { + insert_image(image_index, multiplier, e, image); + }; + } + } else { insert_image(image_index, multiplier, e, image); - }; - } - } else { - insert_image(image_index, multiplier, e, image); - } + } - function insert_image(i, m, e, image) { - const max_w = max_width / multiplier; - const max_h = max_height / multiplier; + function insert_image(i, m, e, image) { + const max_w = max_width / multiplier; + const max_h = max_height / multiplier; - const parentId = `.emote-image-${image_index}x`; - const imgs = document.querySelectorAll(parentId); + const parentId = `.emote-image-${image_index}x`; + const imgs = document.querySelectorAll(parentId); - for (const img of imgs) { - img.setAttribute("src", e.target.result); + for (const img of imgs) { + img.setAttribute("src", e.target.result); - let ratio = Math.min(max_w / image.width, max_h / image.height); + let ratio = Math.min(max_w / image.width, max_h / image.height); - img.setAttribute("width", Math.floor(image.width * ratio)); - img.setAttribute("height", Math.floor(image.height * ratio)); + img.setAttribute("width", Math.floor(image.width * ratio)); + img.setAttribute("height", Math.floor(image.height * ratio)); - const sizeElement = document.querySelector(`.emote-image:has(${parentId}) .size`); - sizeElement.innerHTML = `${img.getAttribute("width")}x${img.getAttribute("height")}`; + const sizeElement = document.querySelector(`.emote-image:has(${parentId}) .size`); + sizeElement.innerHTML = `${img.getAttribute("width")}x${img.getAttribute("height")}`; + } + } } - } - } - </script> + </script> - </html> + </html> - <?php - exit; + <?php + exit; } -if (!CLIENT_REQUIRES_JSON && CAPTCHA_ENABLE && !isset($_SESSION["captcha_solved"])) { +if (!CLIENT_REQUIRES_JSON && CONFIG['captcha']['enable'] && !isset($_SESSION["captcha_solved"])) { generate_alert("/404.php", "You haven't solved captcha yet.", 403); exit; } @@ -401,14 +401,14 @@ if (!$is_manual && !isset($_FILES["file"])) { exit; } -$code = str_safe($_POST["code"] ?? "", EMOTE_NAME_MAX_LENGTH); +$code = str_safe($_POST["code"] ?? "", CONFIG['emote']['maxnamelength']); -if ($code == "" || !preg_match(EMOTE_NAME_REGEX, $code)) { +if ($code == "" || !preg_match(CONFIG['emote']['nameregex'], $code)) { generate_alert("/emotes/upload.php", "Invalid code"); exit; } -$notes = str_safe($_POST["notes"] ?? "", EMOTE_COMMENT_MAX_LENGTH); +$notes = str_safe($_POST["notes"] ?? "", CONFIG['emote']['maxcommentlength']); if (empty($notes)) { $notes = null; } @@ -418,9 +418,9 @@ if (empty($source)) { $source = null; } -$visibility = clamp(intval($_POST["visibility"], EMOTE_VISIBILITY_DEFAULT), 0, 2); +$visibility = clamp(intval($_POST["visibility"], CONFIG['emote']['defaultvisibility']), 0, 2); -if (MOD_EMOTES_APPROVE && $visibility == 1 && EMOTE_VISIBILITY_DEFAULT != 1) { +if (CONFIG['mod']['approve'] && $visibility == 1 && CONFIG['emote']['defaultvisibility'] != 1) { $visibility = 2; } @@ -468,7 +468,7 @@ if ($is_manual) { exit; } - if (EMOTE_STORE_ORIGINAL) { + if (CONFIG['emote']['storeoriginal']) { $ext = get_file_extension($image["tmp_name"]) ?? ""; move_uploaded_file($image["tmp_name"], "$path/original.$ext"); } @@ -477,17 +477,17 @@ if ($is_manual) { $tags = str_safe($_POST["tags"] ?? "", null); $tags_processed = []; -if (!empty($tags) && TAGS_ENABLE) { +if (!empty($tags) && CONFIG['tags']['enable']) { $tags = explode(" ", $tags); $count = 0; foreach ($tags as $tag) { - if (TAGS_MAX_COUNT > 0 && $count >= TAGS_MAX_COUNT) { + if (CONFIG['tags']['maxcount'] > 0 && $count >= CONFIG['tags']['maxcount']) { break; } - if (!preg_match(TAGS_CODE_REGEX, $tag)) { + if (!preg_match(CONFIG['tags']['regex'], $tag)) { continue; } @@ -526,7 +526,7 @@ $emote_data = [ "tags" => $tags_processed ]; -if (ACCOUNT_LOG_ACTIONS && $uploaded_by != null) { +if (CONFIG['account']['log'] && $uploaded_by != null) { $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") ->execute([ $uploaded_by, |
