add emoji support
This commit is contained in:
parent
6c631c5a66
commit
3f490027d0
13 changed files with 192 additions and 21 deletions
|
@ -35,6 +35,12 @@ if ($_GET["migrated"] == 1) {
|
||||||
echo("<div class=\"sentconf\">migrations have been run!</div>");
|
echo("<div class=\"sentconf\">migrations have been run!</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($_GET["emoji"] == 1) {
|
||||||
|
echo("<div class=\"sentconf\">emojis have been updated!</div>");
|
||||||
|
} else if ($_GET["emoji"]) {
|
||||||
|
echo("<div class=\"warning\">emoji returned non-200 status code {$_GET['emoji']}</div>");
|
||||||
|
}
|
||||||
|
|
||||||
$totalUnresponded = 0;
|
$totalUnresponded = 0;
|
||||||
$totalPriv = 0;
|
$totalPriv = 0;
|
||||||
$totalPrivRead = 0;
|
$totalPrivRead = 0;
|
||||||
|
@ -74,6 +80,24 @@ echo("
|
||||||
{$privateRead}
|
{$privateRead}
|
||||||
");
|
");
|
||||||
|
|
||||||
include '../boilerplate/pageEnd.php';
|
echo("
|
||||||
|
<hr>
|
||||||
|
<div><a href=\"index.php?pw={$adminPassword}&page=migrate\">migrate db</a></div>
|
||||||
|
");
|
||||||
|
|
||||||
|
if ($emojiEnabled) {
|
||||||
|
$query = "
|
||||||
|
SELECT count(*) FROM emoji;
|
||||||
|
";
|
||||||
|
|
||||||
|
$queryResponse = pg_query($db, $query);
|
||||||
|
$count = pg_fetch_array($queryResponse)["count"];
|
||||||
|
|
||||||
|
echo("
|
||||||
|
<div><a href=\"index.php?pw={$adminPassword}&page=emoji\">refresh emojis</a> (currently {$count})</div>
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
include "../boilerplate/pageEnd.php";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
49
admin/emoji.php
Normal file
49
admin/emoji.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?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");
|
||||||
|
|
||||||
|
?>
|
|
@ -8,6 +8,7 @@ if ($_GET["pw"] === $adminPassword) {
|
||||||
case "respond": include "respond.php"; break;
|
case "respond": include "respond.php"; break;
|
||||||
case "mark": include "mark.php"; break;
|
case "mark": include "mark.php"; break;
|
||||||
case "migrate": include "migrate.php"; break;
|
case "migrate": include "migrate.php"; break;
|
||||||
|
case "emoji": include "emoji.php"; break;
|
||||||
default: include "all.php";
|
default: include "all.php";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -12,7 +12,8 @@ $migrations = array(
|
||||||
"20240218-AddMigrationsTable-40641e8d",
|
"20240218-AddMigrationsTable-40641e8d",
|
||||||
"20240218-AddMarkReadOption-a7e43358",
|
"20240218-AddMarkReadOption-a7e43358",
|
||||||
"20240218-AddFalsesToPrivRead-67d82b18",
|
"20240218-AddFalsesToPrivRead-67d82b18",
|
||||||
"20250310-AddFediIDColumn-64520350"
|
"20250310-AddFediIDColumn-64520350",
|
||||||
|
"20250314-AddEmoji"
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($migrations as $mig) {
|
foreach ($migrations as $mig) {
|
||||||
|
|
|
@ -43,13 +43,13 @@ include "../boilerplate/question.php";
|
||||||
if ($question["ispublic"] === "f") {
|
if ($question["ispublic"] === "f") {
|
||||||
echo("
|
echo("
|
||||||
<h2 class=\"title\">{$pageTitle} — no such question exists</h2>
|
<h2 class=\"title\">{$pageTitle} — no such question exists</h2>
|
||||||
<a class=\"go-back\" href=\"index.php\">(go back?)</a>
|
<a href=\"index.php\">(go back?)</a>
|
||||||
");
|
");
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
} else {
|
} else {
|
||||||
echo("
|
echo("
|
||||||
<h2 class=\"title\">{$pageTitle} — question number {$question['id']}</h2>
|
<h2 class=\"title\">{$pageTitle} — question number {$question['id']}</h2>
|
||||||
<a class=\"go-back\" href=\"index.php?pw={$adminPassword}\">(go back?)</a>
|
<a href=\"index.php?pw={$adminPassword}\">(go back?)</a>
|
||||||
");
|
");
|
||||||
|
|
||||||
echo(getQuestion($question, 0, 0, 1, $adminPassword));
|
echo(getQuestion($question, 0, 0, 1, $adminPassword));
|
||||||
|
|
|
@ -1,5 +1,53 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
function insertEmoji($text) {
|
||||||
|
global $emojiEnabled, $db;
|
||||||
|
|
||||||
|
if (!$emojiEnabled) {
|
||||||
|
return htmlspecialchars($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
$out = "";
|
||||||
|
$arr = explode(":", htmlspecialchars($text));
|
||||||
|
$c = 0;
|
||||||
|
$allowNext = false;
|
||||||
|
|
||||||
|
foreach ($arr as $segment) {
|
||||||
|
$c++;
|
||||||
|
|
||||||
|
if (!$allowNext) {
|
||||||
|
$allowNext = true;
|
||||||
|
} else if (sizeof($arr) <= $c) {
|
||||||
|
if ($c !== 1) {
|
||||||
|
$out .= ":";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (preg_match("/^[A-Za-z0-9_-]+$/", $segment) !== false) {
|
||||||
|
$query = "
|
||||||
|
SELECT url FROM emoji WHERE name='{$segment}';
|
||||||
|
";
|
||||||
|
|
||||||
|
$queryResponse = pg_query($db, $query);
|
||||||
|
$url = pg_fetch_array($queryResponse);
|
||||||
|
|
||||||
|
if (pg_num_rows($queryResponse) !== 0) {
|
||||||
|
$out .= "<img class=\"emoji\" src=\"{$url['url']}\" alt=\"${segment}\">";
|
||||||
|
$allowNext = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($c !== 1) {
|
||||||
|
$out .= ":";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$out .= $segment;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
function getQuestion(
|
function getQuestion(
|
||||||
$question,
|
$question,
|
||||||
$includePermalink=1,
|
$includePermalink=1,
|
||||||
|
@ -7,11 +55,11 @@ function getQuestion(
|
||||||
$isResponding=0,
|
$isResponding=0,
|
||||||
$adminPassword=""
|
$adminPassword=""
|
||||||
) {
|
) {
|
||||||
$q = htmlspecialchars($question["text"]);
|
$q = insertEmoji($question["text"]);
|
||||||
$q .= "<div class=\"time\">{$question['time']}</div>";
|
$q .= "<div class=\"time\">{$question['time']}</div>";
|
||||||
|
|
||||||
if ($question["responsetext"]) {
|
if ($question["responsetext"]) {
|
||||||
$q .= "<div class=\"response\">" . htmlspecialchars($question['responsetext']);
|
$q .= "<div class=\"response\">" . insertEmoji($question['responsetext']);
|
||||||
$q .= "<div class=\"time\">{$question['responsetime']}</div></div>";
|
$q .= "<div class=\"time\">{$question['responsetime']}</div></div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +126,7 @@ function getQuestion(
|
||||||
$open = " open";
|
$open = " open";
|
||||||
}
|
}
|
||||||
|
|
||||||
$q = "<details{$open}><summary>cw: " . htmlspecialchars($question["cw"]) . "</summary>{$q}</details>";
|
$q = "<details{$open}><summary>cw: " . insertEmoji($question["cw"]) . "</summary>{$q}</details>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "<div class=\"question\">{$q}</div>";
|
return "<div class=\"question\">{$q}</div>";
|
||||||
|
|
|
@ -9,7 +9,7 @@ $adminPassword = "setAPasswordHere!123";
|
||||||
// page title
|
// page title
|
||||||
$pageTitle = "the cool qna";
|
$pageTitle = "the cool qna";
|
||||||
|
|
||||||
$pageDomainEnabled = True;
|
$pageDomainEnabled = true;
|
||||||
$pageProto = "https";
|
$pageProto = "https";
|
||||||
$pagePath = "/qna";
|
$pagePath = "/qna";
|
||||||
$pageDomain = "example.com";
|
$pageDomain = "example.com";
|
||||||
|
@ -21,11 +21,16 @@ $pageRoot = "/"; // path to go to
|
||||||
$customCSSurl = NULL;
|
$customCSSurl = NULL;
|
||||||
|
|
||||||
// post to fedi?
|
// post to fedi?
|
||||||
$fediEnabled = False;
|
$fediEnabled = false;
|
||||||
$fediAPIRoute = "https://example.com/api/v1/statuses";
|
$fediAPIRoute = "https://example.com/api/v1/statuses";
|
||||||
$fediAPIToken = "Bearer AUTHTOKENGOESHERE";
|
$fediAPIToken = "Bearer AUTHTOKENGOESHERE";
|
||||||
$fediVisibility = "private"; // "direct", "private", "unlisted", "public"
|
$fediVisibility = "private"; // "direct", "private", "unlisted", "public"
|
||||||
|
|
||||||
|
// fedi emojis?
|
||||||
|
$emojiEnabled = false;
|
||||||
|
$emojiAPIRoute = "https://example.com/api/iceshrimp/emoji";
|
||||||
|
$emojiAPIToken = $fediAPIToken;
|
||||||
|
|
||||||
// database setup
|
// database setup
|
||||||
$dbHost = "localhost";
|
$dbHost = "localhost";
|
||||||
$dbName = "postgres";
|
$dbName = "postgres";
|
||||||
|
|
30
css/base.css
30
css/base.css
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
--link-color: #ff0000;
|
--link-color: #ff0000;
|
||||||
--confirmation-color: #00ff00;
|
--confirmation-color: #00ff00;
|
||||||
|
--warning-color: #ffff00;
|
||||||
|
|
||||||
--question-background: #2c2c2c;
|
--question-background: #2c2c2c;
|
||||||
--response-background: #505050;
|
--response-background: #505050;
|
||||||
|
@ -33,13 +34,31 @@ hr {
|
||||||
background-color: var(--hr-color);
|
background-color: var(--hr-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.permalink {
|
a,
|
||||||
|
a:link,
|
||||||
|
a:visited {
|
||||||
color: var(--link-color);
|
color: var(--link-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
img.emoji {
|
||||||
|
height: 1.2em;
|
||||||
|
min-width: 1.2em;
|
||||||
|
max-width: 3em;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.permalink {
|
||||||
font-size: .9em;
|
font-size: .9em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.go-back {
|
.warning {
|
||||||
color: var(--link-color);
|
color: var(--warning-color);
|
||||||
|
margin-bottom: .3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sentconf {
|
||||||
|
color: var(--confirmation-color);
|
||||||
|
margin-bottom: .3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
|
@ -70,11 +89,6 @@ hr {
|
||||||
margin-bottom: .2em;
|
margin-bottom: .2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sentconf {
|
|
||||||
color: var(--confirmation-color);
|
|
||||||
margin-bottom: .3em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sendsum {
|
.sendsum {
|
||||||
font-size: 1.17em;
|
font-size: 1.17em;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
|
|
@ -23,14 +23,14 @@ include "boilerplate/pageStart.php";
|
||||||
if (pg_num_rows($queryResponse) === 0 || $question["ispublic"] === "f" || $question["isrespondedto"] === "f") {
|
if (pg_num_rows($queryResponse) === 0 || $question["ispublic"] === "f" || $question["isrespondedto"] === "f") {
|
||||||
echo("
|
echo("
|
||||||
<h2 class=\"title\">{$pageTitle} — no such question exists</h2>
|
<h2 class=\"title\">{$pageTitle} — no such question exists</h2>
|
||||||
<a class=\"go-back\" href=\"index.php\">(go back?)</a>
|
<a href=\"index.php\">(go back?)</a>
|
||||||
");
|
");
|
||||||
|
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
} else {
|
} else {
|
||||||
echo("
|
echo("
|
||||||
<h2 class=\"title\">{$pageTitle} — question number {$question['id']}</h2>
|
<h2 class=\"title\">{$pageTitle} — question number {$question['id']}</h2>
|
||||||
<a class=\"go-back\" href=\"index.php\">(go back?)</a>
|
<a href=\"index.php\">(go back?)</a>
|
||||||
");
|
");
|
||||||
|
|
||||||
echo(getQuestion($question));
|
echo(getQuestion($question));
|
||||||
|
|
|
@ -19,7 +19,7 @@ include "boilerplate/pageStart.php";
|
||||||
echo("<h2 class=\"title\">" . $pageTitle . "</h2>");
|
echo("<h2 class=\"title\">" . $pageTitle . "</h2>");
|
||||||
|
|
||||||
if ($pageDomainEnabled) {
|
if ($pageDomainEnabled) {
|
||||||
echo("<a class=\"go-back\" href=\"https://{$pageDomainOther}{$pageRoot}\">(go back to " . $pageDomain . "?)</a>");
|
echo("<a href=\"https://{$pageDomainOther}{$pageRoot}\">(go back to " . $pageDomain . "?)</a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["sent"] == 1) {
|
if ($_GET["sent"] == 1) {
|
||||||
|
|
20
migrations/20250314-AddEmoji.php
Normal file
20
migrations/20250314-AddEmoji.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// add emoji table to track emojis and their image urls
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
CREATE TABLE emoji (
|
||||||
|
name TEXT NOT NULL PRIMARY KEY,
|
||||||
|
url TEXT NOT NULL
|
||||||
|
);
|
||||||
|
";
|
||||||
|
|
||||||
|
pg_query($db, $query);
|
||||||
|
|
||||||
|
$dataArray = array(
|
||||||
|
"id" => "20250314-AddEmoji"
|
||||||
|
);
|
||||||
|
|
||||||
|
pg_insert($db, "migrations", $dataArray);
|
||||||
|
|
||||||
|
?>
|
2
send.php
2
send.php
|
@ -12,7 +12,7 @@ $dataArray = array(
|
||||||
"iscwed" => !($_GET["cw"] === null || $_GET["cw"] === ""),
|
"iscwed" => !($_GET["cw"] === null || $_GET["cw"] === ""),
|
||||||
"time" => date("Y-m-d H:i:sP"),
|
"time" => date("Y-m-d H:i:sP"),
|
||||||
"ispublic" => $_GET["public"] == 1,
|
"ispublic" => $_GET["public"] == 1,
|
||||||
"isrespondedto" => False
|
"isrespondedto" => false
|
||||||
);
|
);
|
||||||
|
|
||||||
pg_insert($db, "data", $dataArray);
|
pg_insert($db, "data", $dataArray);
|
||||||
|
|
|
@ -27,6 +27,15 @@ CREATE TABLE migrations (
|
||||||
|
|
||||||
pg_query($db, $query);
|
pg_query($db, $query);
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
CREATE TABLE emoji (
|
||||||
|
name TEXT NOT NULL PRIMARY KEY,
|
||||||
|
url TEXT NOT NULL
|
||||||
|
);
|
||||||
|
";
|
||||||
|
|
||||||
|
pg_query($db, $query);
|
||||||
|
|
||||||
include "admin/migrate.php";
|
include "admin/migrate.php";
|
||||||
|
|
||||||
echo "database set up";
|
echo "database set up";
|
||||||
|
|
Loading…
Reference in a new issue