diff --git a/README.md b/README.md
index 1cd07e5..26dbbaa 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,10 @@
+trinkey's fork of [notfire's qna](https://git.notfire.cc/notfire/qna)
+
+has the same functionality but i added custom css support and made the code less messy
+
+---
+
to set up, generally:
- make a database in postgres
- set up config.php based off of the example
-- run `php setup.php` to create the database table
\ No newline at end of file
+- run `php setup.php` to create the database table
diff --git a/TODO.md b/TODO.md
index a751cb8..15b5ed3 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,3 +1,3 @@
- modifying whether a cw is used or not?
- POSSIBLY editing messages / changing their visibility? idk
-- some way to automatically get notified
\ No newline at end of file
+- some way to automatically get notified
diff --git a/admin/all.php b/admin/all.php
index df9de2f..e0ed36e 100644
--- a/admin/all.php
+++ b/admin/all.php
@@ -4,131 +4,75 @@ $query = "
SELECT * FROM data;
";
-$qresp = pg_query($db, $query);
+$queryResponse = pg_query($db, $query);
+$questions = pg_fetch_all($queryResponse);
+asort($questions);
-$rows = pg_fetch_all($qresp);
+$properTitle = "{$pageTitle} — admin";
+$CSSdownDirectory = 1;
+include "../boilerplate/pageStart.php";
+include "../boilerplate/question.php";
+
+echo("
{$pageTitle} — admin ");
+
+if ($_GET["deleted"] == 1) {
+ echo("deleted!
");
+}
+
+if ($_GET["responded"] == 1) {
+ echo("response sent!
");
+}
+
+if ($_GET["read"] == 1) {
+ echo("marked as read!
");
+}
+
+if ($_GET["unread"] == 1) {
+ echo("marked as unread!
");
+}
+
+if ($_GET["migrated"] == 1) {
+ echo("migrations have been run!
");
+}
$totalUnresponded = 0;
$totalPriv = 0;
$totalPrivRead = 0;
$totalRespondedPub = 0;
-foreach (array_reverse($rows) as $i) {
- if ($i["isrespondedto"] === "f" && $i["ispublic"] === "t") {
- $totalUnresponded++;
- } else if ($i["ispublic"] === "f") {
- if ($i["isprivread"] === "t") {
- $totalPrivRead++;
- } else {
- $totalPriv++;
- }
+
+$unresponded = "";
+$private = "";
+$privateRead = "";
+$responded = "";
+
+foreach (array_reverse($questions) as $question) {
+ if ($question["isrespondedto"] === "f" && $question["ispublic"] === "t") {
+ $totalUnresponded++;
+ $unresponded .= getQuestion($question, 0, 1, 0, $adminPassword);
+ } else if ($question["ispublic"] === "f") {
+ if ($question["isprivread"] === "t") {
+ $totalPrivRead++;
+ $privateRead .= getQuestion($question, 0, 1, 0, $adminPassword);
} else {
- $totalRespondedPub++;
+ $totalPriv++;
+ $private .= getQuestion($question, 0, 1, 0, $adminPassword);
}
+ } else {
+ $totalRespondedPub++;
+ $responded .= getQuestion($question, 0, 1, 0, $adminPassword);
+ }
}
-$properTitle = $pageTitle . " – admin";
-
-include '../boilerplate/pageStart.php';
-
-echo(" ");
-
-echo("" . $pageTitle . " – admin ");
-
-if ($_GET["deleted"] == 1) {
- echo("deleted! ");
-}
-
-if ($_GET["responded"] == 1) {
- echo("response sent! ");
-}
-
-if ($_GET["read"] == 1) {
- echo("marked as read! ");
-}
-
-if ($_GET["unread"] == 1) {
- echo("marked as unread! ");
-}
-
-if ($_GET["migrated"] == 1) {
- echo("migrations have been run! ");
-}
-
-asort($rows);
-
-echo("not responded to ({$totalUnresponded}) ");
-foreach (array_reverse($rows) as $i){
- if ($i["isrespondedto"] === "f" && $i["ispublic"] == "t") {
- echo("");
- if ($i["iscwed"] === "t") {
- echo("
cw: " . htmlspecialchars($i["cw"]) . " ");
- }
- echo(htmlspecialchars($i["text"]));
- echo("" . $i["time"] . "
");
- echo("respond / delete ");
- if ($i["iscwed"] === "t") {
- echo(" ");
- } else {
- echo("");
- }
- }
-}
-
-echo("unread private ({$totalPriv}) ");
-foreach (array_reverse($rows) as $i){
- if ($i["ispublic"] === "f" && $i["isprivread"] === "f") {
- echo("");
- if ($i["iscwed"] === "t") {
- echo("
cw: " . htmlspecialchars($i["cw"]) . " ");
- }
- echo(htmlspecialchars($i["text"]));
- echo("" . $i["time"] . "
");
- echo("mark read / delete ");
- if ($i["iscwed"] === "t") {
- echo(" ");
- } else {
- echo("");
- }
- }
-}
-
-echo("public ({$totalRespondedPub}) ");
-foreach (array_reverse($rows) as $i){
- if ($i["ispublic"] === "t" && $i["isrespondedto"] === "t") {
- echo("");
- if ($i["iscwed"] === "t") {
- echo("
cw: " . htmlspecialchars($i["cw"]) . " ");
- }
- echo(htmlspecialchars($i["text"]));
- echo("" . $i["time"] . "
");
- echo("" . htmlspecialchars($i["responsetext"]) . "");
- echo("
" . $i["responsetime"] . "
");
- echo("edit response / delete ");
- if ($i["iscwed"] === "t") {
- echo(" ");
- } else {
- echo("");
- }
- }
-}
-
-echo("read private ({$totalPrivRead}) ");
-foreach (array_reverse($rows) as $i){
- if ($i["ispublic"] === "f" && $i["isprivread"] === "t") {
- echo("");
- if ($i["iscwed"] === "t") {
- echo("
cw: " . htmlspecialchars($i["cw"]) . " ");
- }
- echo(htmlspecialchars($i["text"]));
- echo("" . $i["time"] . "
");
- echo("mark unread / delete ");
- if ($i["iscwed"] === "t") {
- echo(" ");
- } else {
- echo("");
- }
- }
-}
+echo("
+ not responded to ({$totalUnresponded})
+ {$unresponded}
+ unread private ({$totalPriv})
+ {$private}
+ public ({$totalRespondedPub})
+ {$responded}
+ read private ({$totalPrivRead})
+ {$privateRead}
+");
include '../boilerplate/pageEnd.php';
diff --git a/admin/delete.php b/admin/delete.php
index db20957..f86f126 100644
--- a/admin/delete.php
+++ b/admin/delete.php
@@ -3,7 +3,7 @@
$id = (int)$_GET["id"];
if ($id === null) {
- exit();
+ exit();
}
$query = "
@@ -15,4 +15,4 @@ pg_query($db, $query);
header("Location: index.php?deleted=1&pw={$adminPassword}");
-?>
\ No newline at end of file
+?>
diff --git a/admin/fedi.php b/admin/fedi.php
index 58847cd..41e2cfb 100644
--- a/admin/fedi.php
+++ b/admin/fedi.php
@@ -5,51 +5,41 @@ SELECT * FROM data
WHERE id = {$id};
";
-$qresp = pg_query($db, $query);
-$arr = pg_fetch_array($qresp);
+$queryResponse = pg_query($db, $query);
+$question = pg_fetch_array($queryResponse);
+
+$url = "{$pageProto}://" . $_SERVER["HTTP_HOST"] . $pagePath . "/fetch.php?id={$id}";
+
+if (strlen($question["fedipostid"]) == 0) {
+ $method = "POST";
+ $route = $fediAPIRoute;
+} else {
+ $method = "PUT";
+ $route = $fediAPIRoute . "/" . $question["fedipostid"];
+}
+
+$cw = "anonymous question response (automated)";
+if ($question["iscwed"] == "t") {
+ $cw .= "; cw: {$question['cw']}";
+}
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: {$fediAPIToken}"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($ch, CURLOPT_URL, $route);
+curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
+curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
+ "status" => "question: {$question['text']}\n\nresponse: {$question['responsetext']}\n\nlink: {$url}",
+ "visibility" => $fediVisibility,
+ "spoiler_text" => $cw
+)));
-$contentO = $arr["text"];
-$contentR = $arr["responsetext"];
-$url = "{$pageProto}://" . $_SERVER["HTTP_HOST"] . $pagePath . "/fetch.php?id={$id}";
-
-if (strlen($arr["fedipostid"]) == 0) {
- curl_setopt($ch, CURLOPT_URL, $fediAPIRoute);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
-
- if ($arr["iscwed"] == "t") {
- $contentCW = $arr["cw"];
- curl_setopt($ch, CURLOPT_POSTFIELDS,
- http_build_query(array('status' => "question: {$contentO}\n\nresponse: {$contentR}\n\nlink: {$url}", 'visibility' => "{$fediVisibility}", 'spoiler_text' => "anonymous question response (automated); cw: {$contentCW}")));
- } else {
- curl_setopt($ch, CURLOPT_POSTFIELDS,
- http_build_query(array('status' => "question: {$contentO}\n\nresponse: {$contentR}\n\nlink: {$url}", 'visibility' => "{$fediVisibility}", 'spoiler_text' => "anonymous question response (automated)")));
- }
-
- $resp = curl_exec($ch);
- $jsonResp = json_decode($resp, true);
-
- $fediID = $jsonResp["id"];
-
- pg_update($db, "data", array("fedipostid" => $fediID), array("id" => $id));
-} else {
- curl_setopt($ch, CURLOPT_URL, ($fediAPIRoute . "/" . $arr["fedipostid"]));
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
-
- if ($arr["iscwed"] == "t") {
- $contentCW = $arr["cw"];
- curl_setopt($ch, CURLOPT_POSTFIELDS,
- http_build_query(array('status' => "question: {$contentO}\n\nresponse: {$contentR}\n\nlink: {$url}", 'visibility' => "{$fediVisibility}", 'spoiler_text' => "anonymous question response (automated); cw: {$contentCW}")));
- } else {
- curl_setopt($ch, CURLOPT_POSTFIELDS,
- http_build_query(array('status' => "question: {$contentO}\n\nresponse: {$contentR}\n\nlink: {$url}", 'visibility' => "{$fediVisibility}", 'spoiler_text' => "anonymous question response (automated)")));
- }
-
- curl_exec($ch);
+$resp = curl_exec($ch);
+if (strlen($question["fedipostid"]) == 0) {
+ $jsonResp = json_decode($resp, true);
+ $fediID = $jsonResp["id"];
+ pg_update($db, "data", array("fedipostid" => $fediID), array("id" => $id));
}
curl_close($ch);
diff --git a/admin/index.php b/admin/index.php
index 12d9a7e..9b8d82a 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -3,23 +3,24 @@
include '../config.php';
if ($_GET["pw"] === $adminPassword) {
- if ($_GET["page"] === "delete") {
- include 'delete.php';
- } elseif ($_GET["page"] === "respond") {
- include 'respond.php';
- } elseif ($_GET["page"] === "mark") {
- include 'mark.php';
- } elseif ($_GET["page"] === "migrate") {
- include 'migrate.php';
- } else {
- include 'all.php';
- }
+ switch ($_GET["page"]) {
+ case "delete": include "delete.php"; break;
+ case "respond": include "respond.php"; break;
+ case "mark": include "mark.php"; break;
+ case "migrate": include "migrate.php"; break;
+ default: include "all.php";
+ }
} else {
- $properTitle = $pageTitle . " – sign in";
- include 'boilerplate/pageStart.php';
+ $properTitle = $pageTitle . " — sign in";
+ $CSSdownDirectory = 1;
+ include "../boilerplate/pageStart.php";
- echo("enter password ");
- echo("");
+ echo("
+ enter password
+
+ ");
+
+ include "../boilerplate/pageEnd.php";
}
-?>
\ No newline at end of file
+?>
diff --git a/admin/mark.php b/admin/mark.php
index 6e93e73..c5e720c 100644
--- a/admin/mark.php
+++ b/admin/mark.php
@@ -7,23 +7,23 @@ if ($id === null) {
}
if ($_GET["action"] === "unread") {
- $query = "
- UPDATE data
- SET isprivread = False
- WHERE id = {$id};
- ";
- $headerinfo = "Location: index.php?unread=1&pw={$adminPassword}";
-} elseif ($_GET["action"] === "read") {
- $query = "
- UPDATE data
- SET isprivread = True
- WHERE id = {$id};
- ";
- $headerinfo = "Location: index.php?read=1&pw={$adminPassword}";
+ $query = "
+ UPDATE data
+ SET isprivread = False
+ WHERE id = {$id};
+ ";
+ $headerinfo = "Location: index.php?unread=1&pw={$adminPassword}";
+} else if ($_GET["action"] === "read") {
+ $query = "
+ UPDATE data
+ SET isprivread = True
+ WHERE id = {$id};
+ ";
+ $headerinfo = "Location: index.php?read=1&pw={$adminPassword}";
}
pg_query($db, $query);
header($headerinfo);
-?>
\ No newline at end of file
+?>
diff --git a/admin/migrate.php b/admin/migrate.php
index ec16fc8..8904c3d 100644
--- a/admin/migrate.php
+++ b/admin/migrate.php
@@ -4,23 +4,23 @@ $query = "
SELECT * FROM migrations;
";
-$qresp = pg_query($db, $query);
+$queryResponse = pg_query($db, $query);
-$rows = pg_fetch_all($qresp);
+$rows = pg_fetch_all($queryResponse);
$migrations = array(
- "20240218-AddMigrationsTable-40641e8d",
- "20240218-AddMarkReadOption-a7e43358",
- "20240218-AddFalsesToPrivRead-67d82b18",
- "20250310-AddFediIDColumn-64520350"
+ "20240218-AddMigrationsTable-40641e8d",
+ "20240218-AddMarkReadOption-a7e43358",
+ "20240218-AddFalsesToPrivRead-67d82b18",
+ "20250310-AddFediIDColumn-64520350"
);
foreach ($migrations as $mig) {
- if (!in_array($mig, array_column($rows, 'id'))) {
- include "../migrations/{$mig}.php";
- }
+ if (!in_array($mig, array_column($rows, 'id'))) {
+ include "../migrations/{$mig}.php";
+ }
}
header("Location: index.php?migrated=1&pw={$adminPassword}");
-?>
\ No newline at end of file
+?>
diff --git a/admin/respond.php b/admin/respond.php
index 7c208ed..d224621 100644
--- a/admin/respond.php
+++ b/admin/respond.php
@@ -3,27 +3,28 @@
$id = (int)$_GET["id"];
if ($id === null) {
- exit();
+ exit();
}
if ($_GET["text"] !== null) {
- $text = $_GET["text"];
- $cdate = date("Y-m-d H:i:sP");
- $query = "
- UPDATE data
- SET \"responsetime\" = timestamptz'{$cdate}', isrespondedto = True
- WHERE id = {$id};
- ";
+ $text = $_GET["text"];
+ $cdate = date("Y-m-d H:i:sP");
- pg_query($db, $query);
+ $query = "
+ UPDATE data
+ SET \"responsetime\" = timestamptz'{$cdate}', isrespondedto = True
+ WHERE id = {$id};
+ ";
- pg_update($db, "data", array("responsetext" => $text), array("id" => $id));
+ pg_query($db, $query);
+ pg_update($db, "data", array("responsetext" => $text), array("id" => $id));
- if ($fediEnabled) {
- include 'fedi.php';
- }
+ if ($fediEnabled) {
+ include "fedi.php";
+ }
- header("Location: index.php?responded=1&pw={$adminPassword}");
+ header("Location: index.php?responded=1&pw={$adminPassword}");
+ exit();
}
$query = "
@@ -31,37 +32,27 @@ SELECT * FROM data
WHERE id = {$id};
";
-$qresp = pg_query($db, $query);
-$arr = pg_fetch_array($qresp);
+$queryResponse = pg_query($db, $query);
+$question = pg_fetch_array($queryResponse);
-$properTitle = $pageTitle . " – respond to question #" . $id;
-include '../boilerplate/pageStart.php';
+$properTitle = $pageTitle . " — respond to question #" . $id;
+$CSSdownDirectory = 1;
+include "../boilerplate/pageStart.php";
+include "../boilerplate/question.php";
-echo(" ");
-
-if ($arr["ispublic"] === "f") {
- echo("{$pageTitle} – no such question exists ");
- echo("(go back?) ");
- http_response_code(404);
+if ($question["ispublic"] === "f") {
+ echo("
+ {$pageTitle} — no such question exists
+ (go back?)
+ ");
+ http_response_code(404);
} else {
- echo("{$pageTitle} – question number " . $arr["id"] . " ");
-
- echo("(go back?) ");
- echo("");
- if ($arr["iscwed"] === "t") {
- echo("
cw: " . htmlspecialchars($arr["cw"]) . " ");
- }
- echo(htmlspecialchars($arr["text"]));
- echo("
" . $arr["time"] . "
");
- if ($_GET["responded"] == 1) {
- echo("
" . htmlspecialchars($arr["responsetext"]) . "");
- echo("
" . $arr["responsetime"] . "
");
- echo("
enter your edits ");
- } else {
- echo("
enter a response ");
- }
- $respTxt = htmlspecialchars($arr["responsetext"]);
- echo("
");
+ echo("
+
{$pageTitle} — question number {$question['id']}
+
(go back?)
+ ");
+
+ echo(getQuestion($question, 0, 0, 1, $adminPassword));
}
?>
diff --git a/boilerplate/pageEnd.php b/boilerplate/pageEnd.php
index 087b532..308b1d0 100644
--- a/boilerplate/pageEnd.php
+++ b/boilerplate/pageEnd.php
@@ -1,5 +1,2 @@
-
-echo("