57 lines
2.1 KiB
PHP
57 lines
2.1 KiB
PHP
<?php
|
|
|
|
$query = "
|
|
SELECT * FROM data
|
|
WHERE id = {$id};
|
|
";
|
|
|
|
$qresp = pg_query($db, $query);
|
|
$arr = pg_fetch_array($qresp);
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: {$fediAPIToken}"));
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$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);
|
|
}
|
|
|
|
curl_close($ch);
|
|
|
|
?>
|