diff --git a/admin/fedi.php b/admin/fedi.php index 41e2cfb..1e80e95 100644 --- a/admin/fedi.php +++ b/admin/fedi.php @@ -8,8 +8,6 @@ WHERE id = {$id}; $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; @@ -18,9 +16,22 @@ if (strlen($question["fedipostid"]) == 0) { $route = $fediAPIRoute . "/" . $question["fedipostid"]; } -$cw = "anonymous question response (automated)"; +$cw = $fediCWFormat; +$msg = $fediMessageFormat; if ($question["iscwed"] == "t") { - $cw .= "; cw: {$question['cw']}"; + $cw = str_replace("%c", $question["cw"], $fediCWFormatWithCW); + $msg = str_replace("%c", $question["cw"], $fediMessageFormatWithCW); +} + +$url = "{$pageProto}://" . $_SERVER["HTTP_HOST"] . $pagePath . "/fetch.php?id={$id}"; + +foreach (array( + "%q" => $question["text"], + "%r" => $question["responsetext"], + "%u" => $url +) as $replace => $text) { + $cw = str_replace($replace, $text, $cw); + $msg = str_replace($replace, $text, $msg); } $ch = curl_init(); @@ -30,7 +41,7 @@ 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}", + "status" => $msg, "visibility" => $fediVisibility, "spoiler_text" => $cw ))); diff --git a/config.example.php b/config.example.php index 7811cf1..ddef1ee 100644 --- a/config.example.php +++ b/config.example.php @@ -30,6 +30,15 @@ $fediAPIRoute = "https://example.com/api/v1/statuses"; $fediAPIToken = "Bearer AUTHTOKENGOESHERE"; $fediVisibility = "private"; // "direct", "private", "unlisted", "public" +// %c: content warning (only on WithCW variables) +// %q: question +// %r: response +// %u: url to question +$fediCWFormat = "anonymous question response"; // set to NULL to disable the content warning on the post +$fediCWFormatWithCW = $fediCWFormat . "; cw: %c"; +$fediMessageFormat = "question: %q\n\nresponse: %r\n\nlink: %u"; +$fediMessageFormatWithCW = $fediMessageFormat; + // fedi emojis? $emojiEnabled = false; $emojiAPIRoute = "https://example.com/api/iceshrimp/emoji";