84 lines
1.7 KiB
PHP
84 lines
1.7 KiB
PHP
<?php
|
|
|
|
if (!$emojiEnabled) {
|
|
header("Location: index.php?pw={$adminPassword}");
|
|
exit();
|
|
}
|
|
|
|
include "../boilerplate/question.php";
|
|
|
|
$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 emoji;
|
|
";
|
|
|
|
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, ",") . ";");
|
|
}
|
|
|
|
$query = "
|
|
SELECT * FROM data;
|
|
";
|
|
|
|
$queryResponse = pg_query($db, $query);
|
|
$questions = pg_fetch_all($queryResponse);
|
|
|
|
foreach ($questions as $question) {
|
|
$parsed_text = insertEmoji($question["text"]);
|
|
|
|
$parsed_cw = NULL;
|
|
if ($question["iscwed"] === "t") {
|
|
$parsed_cw = insertEmoji($question["cw"]);
|
|
}
|
|
|
|
$parsed_response = NULL;
|
|
if ($question["isrespondedto"] === "t") {
|
|
$parsed_response = insertEmoji($question["responsetext"]);
|
|
}
|
|
|
|
pg_update(
|
|
$db, "data",
|
|
array(
|
|
"parsedtext" => $parsed_text,
|
|
"parsedcw" => $parsed_cw,
|
|
"parsedresponsetext" => $parsed_response
|
|
),
|
|
array(
|
|
"id" => $question["id"]
|
|
)
|
|
);
|
|
}
|
|
|
|
header("Location: index.php?pw={$adminPassword}&emoji=1");
|
|
|
|
?>
|