From 734fe7209da7557738471760296bc427bfa70c50 Mon Sep 17 00:00:00 2001 From: octospacc Date: Mon, 10 Feb 2025 02:32:25 +0100 Subject: [PATCH] Auto-Backup $'Mon Feb 10 2025 01:58:10 GMT+0100 (Central European Standard Time)' --- FrittoMistoSync.php | 145 ++++++++++++++++++++++++++++++++++++++++++++ Proxatore.php | 3 +- 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100755 FrittoMistoSync.php diff --git a/FrittoMistoSync.php b/FrittoMistoSync.php new file mode 100755 index 0000000..800788d --- /dev/null +++ b/FrittoMistoSync.php @@ -0,0 +1,145 @@ +date) === normalize_date($destination->date)) { + return true; + } else { + return false; + } +} + +function post_updated ($source, $destination) { + // if (normalize_date($source->modified) === normalize_date($destination->modified)) { + if (normalize_date($source->modified) < normalize_date($destination->modified)) { + return true; + } else { + return false; + } +} + +function make_content ($content, $link) { + return " +{$content} + + + +

...Leggi il post completo su {$link}.

+ + + +
+{$link} +
+"; +} + +// TODO trim body but include media and embeds +function wporg_to_wpcom ($data, $update) { + $excerpt = $data->excerpt->rendered; + return [ + 'date' => $data->date, + 'title' => ('Post da frittomistocto: ' . $data->title->rendered), + 'content' => make_content(($update ? $excerpt : $data->content->rendered), $data->link), //(/* '

Nuovo post dal fritto misto di octospacc!

' . */ $data->content->rendered . '

...Leggi il post completo su ' . $data->link . '.

'), + 'excerpt' => $excerpt, + 'slug' => $data->slug, + // 'author' => $data->author, + // 'publicize' => true, + // 'publicize_message' => '', + 'status' => $data->status, + 'sticky' => $data->sticky, + //'password' => $data->password, + // 'parent' => , + // 'type' => , + // 'terms' => , + // 'categories' => $data->categories, + // 'tags' => $data->tags, + 'format' => $data->format, + // 'featured_image' => $data->featured_media, + // 'media' => [], + // 'media_urls' => [], + // 'media_attrs' => [], + // 'metadata' => [], + 'discussion' => [ + 'comments_open' => $data->comment_status, + 'pings_open' => $data->ping_status, + ], + // 'likes_enabled' => , + // 'sharing_enabled' => , + // 'menu_order' => 0, + // 'page_template' => '', + ]; +} + +function octomediajournal_post ($data, $id=null) { + //$url = "https://public-api.wordpress.com/rest/v1.1/sites/82974409/posts/{$id}"; + $url = "https://public-api.wordpress.com/wp/v2/sites/240403429/posts" . ($id ? "/${id}" : ''); + //echo json_encode($data); + return json_decode(file_get_contents($url, false, stream_context_create([ + 'http' => [ + 'ignore_errors' => true, + 'method' => 'POST', + 'header' => [ + //('authorization: Bearer ' . OCTOMEDIAJOURNAL_TOKEN), + ('Authorization: '. WPCOM_AUTH), + ('Cookie: '. WPCOM_COOKIE), + //'Content-Type: application/x-www-form-urlencoded', + 'Content-Type: application/json', + ], + 'content' => json_encode($data), //http_build_query($data), + ], + ]))); +} + +require (dirname(__FILE__) . '/../../root-secret/FrittoMistoSync.Config.php'); +header('Content-Type: text/plain'); + +$sources = json_decode(file_get_contents(INPUT_URL)); +$destinations = json_decode(file_get_contents(OUTPUT_URL))->posts; + +// $to_create = []; +// $to_update = []; + +foreach ($sources as $source) { + $destinationid = $result = null; + $created = $updated = false; + + foreach ($destinations as $destination) { + if (post_exists($source, $destination)) { + $created = true; + //$destinationid = $destination->ID; + if (post_updated($source, $destination)) { + $updated = true; + } + break; + } + unset($destination); + } + + //$postdata = wporg_to_wpcom($source); + if (!$created) { + echo "Creating"; + $result = octomediajournal_post(wporg_to_wpcom($source, false)); + } else if (!$updated || $source->content->rendered === $destination->content /* $destination->content !== make_content($source->excerpt->encoded, $source->link) */) { + echo "Updating"; + $result = octomediajournal_post(wporg_to_wpcom($source, true), $destination->ID); + } else { + echo "Skipping"; + } + echo ': ' . $source->id . '->' . ($destination->ID ?? 'new') . ' : ' . json_encode($result) . "\n"; + //echo json_encode($postdata) . "\n"; +} + +echo 'Done!'; + +// foreach ($to_create as $source) { +// echo $source->id . ' '; +// } \ No newline at end of file diff --git a/Proxatore.php b/Proxatore.php index d2e29e5..661096b 100644 --- a/Proxatore.php +++ b/Proxatore.php @@ -2,6 +2,7 @@ const APPNAME = '🎭️ Proxatore'; const PLATFORMS = [ + 'spaccbbs' => ['bbs.spacc.eu.org'], 'facebook' => ['facebook.com', 'm.facebook.com'], 'instagram' => ['instagram.com'], //'juxt' => ['juxt.pretendo.network'], @@ -22,7 +23,7 @@ const PLATFORMS_ALIASES = [ const PLATFORMS_PROXIES = [ 'instagram' => ['ddinstagram.com', 'd.ddinstagram.com'], 'tiktok' => ['vxtiktok.com'], - 'twitter' => ['fxtwitter.com', 'vxtwitter.com'], + 'twitter' => ['fxtwitter.com', 'vxtwitter.com', 'fixvx.com'], 'x' => ['fixupx.com', 'stupidpenisx.com'], ];