make fedi client edit existing posts; bit of cleanup
This commit is contained in:
parent
0008a59a83
commit
43e18b3d89
4 changed files with 55 additions and 15 deletions
|
@ -10,26 +10,47 @@ $arr = pg_fetch_array($qresp);
|
|||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL,$fediAPIRoute);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER,
|
||||
array("Authorization: {$fediAPIToken}"));
|
||||
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 ($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)")));
|
||||
}
|
||||
if (strlen($arr["fedipostid"]) == 0) {
|
||||
curl_setopt($ch, CURLOPT_URL, $fediAPIRoute);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
|
||||
curl_exec($ch);
|
||||
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);
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ $rows = pg_fetch_all($qresp);
|
|||
$migrations = array(
|
||||
"20240218-AddMigrationsTable-40641e8d",
|
||||
"20240218-AddMarkReadOption-a7e43358",
|
||||
"20240218-AddFalsesToPrivRead-67d82b18"
|
||||
"20240218-AddFalsesToPrivRead-67d82b18",
|
||||
"20250310-AddFediIDColumn-64520350"
|
||||
);
|
||||
|
||||
foreach ($migrations as $mig) {
|
||||
|
|
|
@ -37,7 +37,7 @@ if (pg_num_rows($qresp) === 0 || $arr["ispublic"] === "f" || $arr["isrespondedto
|
|||
echo("<div class=\"time\">" . $arr["time"] . "</div>");
|
||||
echo("<div class=\"response\">" . $arr["responsetext"] . "");
|
||||
echo("<div class=\"time\">" . $arr["responsetime"] . "</div></div>");
|
||||
if ($i["iscwed"] === "t") {
|
||||
if ($arr["iscwed"] === "t") {
|
||||
echo("</details></div>");
|
||||
} else {
|
||||
echo("</div>");
|
||||
|
|
18
migrations/20250310-AddFediIDColumn-64520350.php
Normal file
18
migrations/20250310-AddFediIDColumn-64520350.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
// add "fedipostid" column to data
|
||||
|
||||
$query = "
|
||||
ALTER TABLE data
|
||||
ADD COLUMN fedipostid TEXT;
|
||||
";
|
||||
|
||||
pg_query($db, $query);
|
||||
|
||||
$dataArray = array(
|
||||
"id" => "20250310-AddFediIDColumn-64520350"
|
||||
);
|
||||
|
||||
pg_insert($db, "migrations", $dataArray);
|
||||
|
||||
?>
|
Loading…
Reference in a new issue