49 lines
1 KiB
PHP
49 lines
1 KiB
PHP
<?php
|
|
|
|
if (!$emojiEnabled) {
|
|
header("Location: index.php?pw={$adminPassword}");
|
|
exit();
|
|
}
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: {$emojiAPIToken}"));
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_URL, $emojiAPIRoute);
|
|
|
|
$resp = curl_exec($ch);
|
|
|
|
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
if ($responseCode !== 200) {
|
|
header("Location: index.php?pw={$adminPassword}&emoji={$responseCode}");
|
|
exit();
|
|
}
|
|
|
|
$query = "
|
|
TRUNCATE TABLE qna;
|
|
";
|
|
|
|
pg_query($db, $query);
|
|
|
|
$jsonResp = json_decode($resp, true);
|
|
if (count($jsonResp)) {
|
|
$query = "
|
|
INSERT INTO emoji (name, url) VALUES
|
|
";
|
|
|
|
foreach ($jsonResp as $emoji) {
|
|
if (str_contains($emoji["name"], "'") || str_contains($emoji["publicUrl"], "'")) {
|
|
continue;
|
|
}
|
|
|
|
$query .= "('{$emoji['name']}', '{$emoji['publicUrl']}'),";
|
|
}
|
|
|
|
pg_query($db, rtrim($query, ",") . ";");
|
|
}
|
|
|
|
header("Location: index.php?pw={$adminPassword}&emoji=1");
|
|
|
|
?>
|