]> git.mxchange.org Git - friendica-addons.git/commitdiff
Fix handling of the 'private' field / reformatted code
authorMichael <heluecht@pirati.ca>
Sat, 16 Nov 2024 05:42:00 +0000 (05:42 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 16 Nov 2024 05:43:35 +0000 (05:43 +0000)
12 files changed:
bluesky/bluesky.php
diaspora/diaspora.php
dwpost/dwpost.php
ijpost/ijpost.php
libertree/libertree.php
ljpost/ljpost.php
pnut/pnut.php
pumpio/pumpio.php
statusnet/statusnet.php
tumblr/tumblr.php
twitter/twitter.php
wppost/wppost.php

index 4882a263f485636bd3798d1e828dd4d1ab003e65..d719eecb7b3c729a96ce22629168b2bec719bfe3 100644 (file)
@@ -587,13 +587,13 @@ function bluesky_hook_fork(array &$b)
 
        if (DI::pConfig()->get($post['uid'], 'bluesky', 'import')) {
                // Don't post if it isn't a reply to a bluesky post
-               if (($post['parent'] != $post['id']) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::BLUESKY])) {
+               if (($post['gravity'] != Item::GRAVITY_PARENT) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::BLUESKY])) {
                        Logger::notice('No bluesky parent found', ['item' => $post['id']]);
                        $b['execute'] = false;
                        return;
                }
-       } elseif (!strstr($post['postopts'] ?? '', 'bluesky') || ($post['parent'] != $post['id']) || $post['private']) {
-               DI::logger()->info('Activities are never exported when we don\'t import the bluesky timeline', ['uid' => $post['uid']]);
+       } elseif (!strstr($post['postopts'] ?? '', 'bluesky') || ($post['gravity'] != Item::GRAVITY_PARENT) || ($post['private'] == Item::PRIVATE)) {
+               DI::logger()->info('Post will not be exported', ['uid' => $post['uid'], 'postopts' => $post['postopts'], 'gravity' => $post['gravity'], 'private' => $post['private']]);
                $b['execute'] = false;
                return;
        }
@@ -601,15 +601,11 @@ function bluesky_hook_fork(array &$b)
 
 function bluesky_post_local(array &$b)
 {
-       if ($b['edit']) {
-               return;
-       }
-
        if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
-       if ($b['private'] || $b['parent']) {
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
@@ -667,7 +663,7 @@ function bluesky_send(array &$b)
                        bluesky_create_activity($b, $parent);
                }
                return;
-       } elseif ($b['private'] || !strstr($b['postopts'], 'bluesky')) {
+       } elseif (($b['private'] == Item::PRIVATE) || !strstr($b['postopts'], 'bluesky')) {
                return;
        }
 
@@ -1481,6 +1477,18 @@ function bluesky_add_media(stdClass $embed, array $item, int $fetch_uid, int $le
 
                case 'app.bsky.embed.record#view':
                        $original_uri = $uri = bluesky_get_uri($embed->record);
+                       $type = '$type';
+                       if (!empty($embed->record->record->$type)) {
+                               $embed_type = $embed->record->record->$type;
+                               if ($embed_type == 'app.bsky.graph.starterpack') {
+                                       Logger::debug('Starterpacks are not fetched like posts', ['original-uri' => $original_uri]);
+                                       if (empty($item['body'])) {
+                                               // @todo process starterpack
+                                               $item['body'] = '[url=' . $embed->record->record->list . ']' . $embed->record->record->name . '[/url]';
+                                       }
+                                       break;
+                               }
+                       }
                        $uri = bluesky_fetch_missing_post($uri, $item['uid'], $fetch_uid, Item::PR_FETCHED, $item['contact-id'], $level, $last_poll);
                        if ($uri) {
                                $shared = Post::selectFirst(['uri-id'], ['uri' => $uri, 'uid' => [$item['uid'], 0]]);
@@ -1603,13 +1611,13 @@ function bluesky_fetch_missing_post(string $uri, int $uid, int $fetch_uid, int $
 
        if (!empty($data->thread->parent)) {
                $parents = bluesky_fetch_parents($data->thread->parent, $uid);
-               
+
                foreach ($parents as $parent) {
                        $uri_id = bluesky_process_post($parent, $uid, $fetch_uid, Item::PR_FETCHED, $causer, $level, $last_poll);
                        Logger::debug('Parent created', ['uri-id' => $uri_id]);
                }
        }
-       
+
        return bluesky_process_thread($data->thread, $uid, $fetch_uid, $post_reason, $causer, $level, $last_poll);
 }
 
@@ -1618,7 +1626,7 @@ function bluesky_fetch_parents(stdClass $parent, int $uid, array $parents = []):
        if (!empty($parent->parent)) {
                $parents = bluesky_fetch_parents($parent->parent, $uid, $parents);
        }
-       
+
        if (!empty($parent->post) && empty(bluesky_fetch_post(bluesky_get_uri($parent->post), $uid))) {
                $parents[] = $parent->post;
        }
index cb2eb9968c743755f13f0bf9454c8d11d437d242..979204baf75fdfedb2dd5c46391cfc19f238a3fb 100644 (file)
@@ -17,6 +17,7 @@ use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\Core\Worker;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Model\Post;
 
 function diaspora_install()
@@ -120,15 +121,15 @@ function diaspora_settings(array &$data)
 function diaspora_settings_post(array &$b)
 {
        if (!empty($_POST['diaspora-submit'])) {
-               DI::pConfig()->set(DI::userSession()->getLocalUserId(),'diaspora', 'post'           , intval($_POST['enabled']));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'diaspora', 'post', intval($_POST['enabled']));
                if (intval($_POST['enabled'])) {
                        if (isset($_POST['handle'])) {
-                               DI::pConfig()->set(DI::userSession()->getLocalUserId(),'diaspora', 'handle'         , trim($_POST['handle']));
-                               DI::pConfig()->set(DI::userSession()->getLocalUserId(),'diaspora', 'password'       , trim($_POST['password']));
+                               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'diaspora', 'handle', trim($_POST['handle']));
+                               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'diaspora', 'password', trim($_POST['password']));
                        }
                        if (!empty($_POST['aspect'])) {
-                               DI::pConfig()->set(DI::userSession()->getLocalUserId(),'diaspora', 'aspect'         , trim($_POST['aspect']));
-                               DI::pConfig()->set(DI::userSession()->getLocalUserId(),'diaspora', 'post_by_default', intval($_POST['post_by_default']));
+                               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'diaspora', 'aspect', trim($_POST['aspect']));
+                               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'diaspora', 'post_by_default', intval($_POST['post_by_default']));
                        }
                } else {
                        DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'diaspora', 'password');
@@ -144,8 +145,10 @@ function diaspora_hook_fork(array &$b)
 
        $post = $b['data'];
 
-       if ($post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
-               !strstr($post['postopts'] ?? '', 'diaspora') || ($post['parent'] != $post['id'])) {
+       if (
+               $post['deleted'] || ($post['private'] == Item::PRIVATE) || ($post['created'] !== $post['edited']) ||
+               !strstr($post['postopts'] ?? '', 'diaspora') || ($post['gravity'] != Item::GRAVITY_PARENT)
+       ) {
                $b['execute'] = false;
                return;
        }
@@ -153,23 +156,19 @@ function diaspora_hook_fork(array &$b)
 
 function diaspora_post_local(array &$b)
 {
-       if ($b['edit']) {
-               return;
-       }
-
        if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
-       if ($b['private'] || $b['parent']) {
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
-       $diaspora_post   = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(),'diaspora','post'));
+       $diaspora_post   = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'diaspora', 'post'));
 
        $diaspora_enable = (($diaspora_post && !empty($_REQUEST['diaspora_enable'])) ? intval($_REQUEST['diaspora_enable']) : 0);
 
-       if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(),'diaspora','post_by_default'))) {
+       if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'diaspora', 'post_by_default'))) {
                $diaspora_enable = 1;
        }
 
@@ -190,11 +189,11 @@ function diaspora_send(array &$b)
 
        Logger::notice('diaspora_send: invoked');
 
-       if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
+       if ($b['deleted'] || ($b['private'] == Item::PRIVATE) || ($b['created'] !== $b['edited'])) {
                return;
        }
 
-       if (!strstr($b['postopts'],'diaspora')) {
+       if (!strstr($b['postopts'], 'diaspora')) {
                return;
        }
 
@@ -214,9 +213,9 @@ function diaspora_send(array &$b)
 
        Logger::info('diaspora_send: prepare posting');
 
-       $handle = DI::pConfig()->get($b['uid'],'diaspora','handle');
-       $password = DI::pConfig()->get($b['uid'],'diaspora','password');
-       $aspect = DI::pConfig()->get($b['uid'],'diaspora','aspect');
+       $handle = DI::pConfig()->get($b['uid'], 'diaspora', 'handle');
+       $password = DI::pConfig()->get($b['uid'], 'diaspora', 'password');
+       $aspect = DI::pConfig()->get($b['uid'], 'diaspora', 'aspect');
 
        if ($handle && $password) {
                Logger::info('diaspora_send: all values seem to be okay');
@@ -230,7 +229,7 @@ function diaspora_send(array &$b)
                // Removal of tags and mentions
                // #-tags
                $body = preg_replace('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $body);
-               // @-mentions
+               // @-mentions
                $body = preg_replace('/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $body);
 
                // remove multiple newlines
@@ -244,7 +243,7 @@ function diaspora_send(array &$b)
 
                // Adding the title
                if (strlen($title)) {
-                       $body = "## ".html_entity_decode($title)."\n\n".$body;
+                       $body = "## " . html_entity_decode($title) . "\n\n" . $body;
                }
 
                require_once "addon/diaspora/diasphp.php";
@@ -252,9 +251,9 @@ function diaspora_send(array &$b)
                try {
                        Logger::info('diaspora_send: prepare');
                        $conn = new Diaspora_Connection($handle, $password);
-                       Logger::info('diaspora_send: try to log in '.$handle);
+                       Logger::info('diaspora_send: try to log in ' . $handle);
                        $conn->logIn();
-                       Logger::info('diaspora_send: try to send '.$body);
+                       Logger::info('diaspora_send: try to send ' . $body);
 
                        $conn->provider = $hostname;
                        $conn->postStatusMessage($body, $aspect);
@@ -263,7 +262,7 @@ function diaspora_send(array &$b)
                } catch (Exception $e) {
                        Logger::notice("diaspora_send: Error submitting the post: " . $e->getMessage());
 
-                       Logger::info('diaspora_send: requeueing '.$b['uid']);
+                       Logger::info('diaspora_send: requeueing ' . $b['uid']);
 
                        Worker::defer();
                }
index 4ad5021f7f85a3327d684d02d4f72b0118b6bc85..1ecd9764be4dea38aacb4f11add03507240423c7 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
@@ -88,24 +89,20 @@ function dwpost_settings_post(array &$b)
 
 function dwpost_post_local(array &$b)
 {
-       // This can probably be changed to allow editing by pointing to a different API endpoint
-       if ($b['edit']) {
-               return;
-       }
-
        if ((!DI::userSession()->getLocalUserId()) || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
-       if ($b['private'] || $b['parent']) {
+       // This can probably be changed to allow editing by pointing to a different API endpoint
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
-       $dw_post = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(),'dwpost','post'));
+       $dw_post = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'dwpost', 'post'));
 
        $dw_enable = (($dw_post && !empty($_REQUEST['dwpost_enable'])) ? intval($_REQUEST['dwpost_enable']) : 0);
 
-       if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(),'dwpost','post_by_default'))) {
+       if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'dwpost', 'post_by_default'))) {
                $dw_enable = 1;
        }
 
@@ -122,7 +119,7 @@ function dwpost_post_local(array &$b)
 
 function dwpost_send(array &$b)
 {
-       if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
+       if ($b['deleted'] || ($b['private'] == Item::PRIVATE) || ($b['created'] !== $b['edited'])) {
                return;
        }
 
@@ -145,8 +142,8 @@ function dwpost_send(array &$b)
        $user = User::getById($b['uid']);
        $tz = $user['timezone'] ?: 'UTC';
 
-       $dw_username = DI::pConfig()->get($b['uid'],'dwpost','dw_username');
-       $dw_password = DI::pConfig()->get($b['uid'],'dwpost','dw_password');
+       $dw_username = DI::pConfig()->get($b['uid'], 'dwpost', 'dw_username');
+       $dw_password = DI::pConfig()->get($b['uid'], 'dwpost', 'dw_password');
        $dw_blog = 'http://www.dreamwidth.org/interface/xmlrpc';
 
        if ($dw_username && $dw_password && $dw_blog) {
@@ -156,11 +153,11 @@ function dwpost_send(array &$b)
                $tags = Tag::getCSVByURIId($b['uri-id'], [Tag::HASHTAG]);
 
                $date = DateTimeFormat::convert($b['created'], $tz);
-               $year = intval(substr($date,0,4));
-               $mon  = intval(substr($date,5,2));
-               $day  = intval(substr($date,8,2));
-               $hour = intval(substr($date,11,2));
-               $min  = intval(substr($date,14,2));
+               $year = intval(substr($date, 0, 4));
+               $mon  = intval(substr($date, 5, 2));
+               $day  = intval(substr($date, 8, 2));
+               $hour = intval(substr($date, 11, 2));
+               $min  = intval(substr($date, 14, 2));
 
                $xml = <<< EOT
 <?xml version="1.0" encoding="utf-8"?>
index 885bc289ceb498502ce53b2932b9f4f8582a59a2..f22dfff29346c1bb68e55e63cd522b5f7f62e347 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
@@ -85,17 +86,12 @@ function ijpost_settings_post(array &$b)
 
 function ijpost_post_local(array &$b)
 {
-       // This can probably be changed to allow editing by pointing to a different API endpoint
-
-       if ($b['edit']) {
-               return;
-       }
-
        if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
-       if ($b['private'] || $b['parent']) {
+       // This can probably be changed to allow editing by pointing to a different API endpoint
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
@@ -120,7 +116,7 @@ function ijpost_post_local(array &$b)
 
 function ijpost_send(array &$b)
 {
-       if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
+       if ($b['deleted'] || ($b['private'] == Item::PRIVATE) || ($b['created'] !== $b['edited'])) {
                return;
        }
 
@@ -150,11 +146,11 @@ function ijpost_send(array &$b)
                $tags = Tag::getCSVByURIId($b['uri-id'], [Tag::HASHTAG]);
 
                $date = DateTimeFormat::convert($b['created'], $tz);
-               $year = intval(substr($date,0,4));
-               $mon  = intval(substr($date,5,2));
-               $day  = intval(substr($date,8,2));
-               $hour = intval(substr($date,11,2));
-               $min  = intval(substr($date,14,2));
+               $year = intval(substr($date, 0, 4));
+               $mon  = intval(substr($date, 5, 2));
+               $day  = intval(substr($date, 8, 2));
+               $hour = intval(substr($date, 11, 2));
+               $min  = intval(substr($date, 14, 2));
 
                $xml = <<< EOT
 <?xml version="1.0" encoding="utf-8"?>
index f69c0aabb027164386598cadb0f041218bc4add9..1d997123a3007d97ab57f5c52a7f0ca14d4c7b8f 100644 (file)
@@ -13,6 +13,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Model\Post;
 
 function libertree_install()
@@ -74,13 +75,11 @@ function libertree_settings(array &$data)
 function libertree_settings_post(array &$b)
 {
        if (!empty($_POST['libertree-submit'])) {
-               DI::pConfig()->set(DI::userSession()->getLocalUserId(),'libertree','post',intval($_POST['libertree']));
-               DI::pConfig()->set(DI::userSession()->getLocalUserId(),'libertree','post_by_default',intval($_POST['libertree_bydefault']));
-               DI::pConfig()->set(DI::userSession()->getLocalUserId(),'libertree','libertree_api_token',trim($_POST['libertree_api_token']));
-               DI::pConfig()->set(DI::userSession()->getLocalUserId(),'libertree','libertree_url',trim($_POST['libertree_url']));
-
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'libertree', 'post', intval($_POST['libertree']));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'libertree', 'post_by_default', intval($_POST['libertree_bydefault']));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'libertree', 'libertree_api_token', trim($_POST['libertree_api_token']));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'libertree', 'libertree_url', trim($_POST['libertree_url']));
        }
-
 }
 
 function libertree_hook_fork(array &$b)
@@ -91,8 +90,10 @@ function libertree_hook_fork(array &$b)
 
        $post = $b['data'];
 
-       if ($post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
-               !strstr($post['postopts'], 'libertree') || ($post['parent'] != $post['id'])) {
+       if (
+               $post['deleted'] || ($post['private'] == Item::PRIVATE) || ($post['created'] !== $post['edited']) ||
+               !strstr($post['postopts'], 'libertree') || ($post['gravity'] != Item::GRAVITY_PARENT)
+       ) {
                $b['execute'] = false;
                return;
        }
@@ -100,26 +101,20 @@ function libertree_hook_fork(array &$b)
 
 function libertree_post_local(array &$b)
 {
-
-       // This can probably be changed to allow editing by pointing to a different API endpoint
-
-       if ($b['edit']) {
-               return;
-       }
-
        if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
-       if ($b['private'] || $b['parent']) {
+       // This can probably be changed to allow editing by pointing to a different API endpoint
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
-       $ltree_post   = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(),'libertree','post'));
+       $ltree_post   = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'libertree', 'post'));
 
        $ltree_enable = (($ltree_post && !empty($_REQUEST['libertree_enable'])) ? intval($_REQUEST['libertree_enable']) : 0);
 
-       if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(),'libertree','post_by_default'))) {
+       if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'libertree', 'post_by_default'))) {
                $ltree_enable = 1;
        }
 
@@ -138,11 +133,11 @@ function libertree_send(array &$b)
 {
        Logger::notice('libertree_send: invoked');
 
-       if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
+       if ($b['deleted'] || ($b['private'] == Item::PRIVATE) || ($b['created'] !== $b['edited'])) {
                return;
        }
 
-       if (! strstr($b['postopts'],'libertree')) {
+       if (! strstr($b['postopts'], 'libertree')) {
                return;
        }
 
@@ -159,15 +154,15 @@ function libertree_send(array &$b)
 
        $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], DI::contentItem()->addSharedPost($b));
 
-       $ltree_api_token = DI::pConfig()->get($b['uid'],'libertree','libertree_api_token');
-       $ltree_url = DI::pConfig()->get($b['uid'],'libertree','libertree_url');
+       $ltree_api_token = DI::pConfig()->get($b['uid'], 'libertree', 'libertree_api_token');
+       $ltree_url = DI::pConfig()->get($b['uid'], 'libertree', 'libertree_url');
        $ltree_blog = "$ltree_url/api/v1/posts/create/?token=$ltree_api_token";
        $ltree_source = DI::baseUrl()->getHost();
 
        if ($b['app'] != "")
-               $ltree_source .= " (".$b['app'].")";
+               $ltree_source .= " (" . $b['app'] . ")";
 
-       if($ltree_url && $ltree_api_token && $ltree_blog && $ltree_source) {
+       if ($ltree_url && $ltree_api_token && $ltree_blog && $ltree_source) {
                $title = $b['title'];
                $body = $b['body'];
                // Insert a newline before and after a quote
@@ -177,7 +172,7 @@ function libertree_send(array &$b)
                // Removal of tags and mentions
                // #-tags
                $body = preg_replace('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $body);
-               // @-mentions
+               // @-mentions
                $body = preg_replace('/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $body);
 
                // remove multiple newlines
@@ -198,7 +193,7 @@ function libertree_send(array &$b)
                $params = [
                        'text' => $body,
                        'source' => $ltree_source
-               //      'token' => $ltree_api_token
+                       //      'token' => $ltree_api_token
                ];
 
                $result = DI::httpClient()->post($ltree_blog, $params)->getBodyString();
index fac447677d104b3225ef07fd23666eefa2cac5fc..7acc65898b1bff77b0b1cf514019f38ded7960de 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
@@ -35,7 +36,7 @@ function ljpost_jot_nets(array &$jotnets_fields)
                return;
        }
 
-       if (DI::pConfig()->get(DI::userSession()->getLocalUserId(),'ljpost','post')) {
+       if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'ljpost', 'post')) {
                $jotnets_fields[] = [
                        'type' => 'checkbox',
                        'field' => [
@@ -57,7 +58,7 @@ function ljpost_settings(array &$data)
        $ij_username = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'ljpost', 'ij_username');
        $def_enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'ljpost', 'post_by_default');
 
-       $t= Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/ljpost/');
+       $t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/ljpost/');
        $html = Renderer::replaceMacros($t, [
                '$enabled'   => ['ljpost', DI::l10n()->t('Enable LiveJournal Post Addon'), $enabled],
                '$username'  => ['ij_username', DI::l10n()->t('LiveJournal username'), $ij_username],
@@ -86,20 +87,16 @@ function ljpost_settings_post(array &$b)
 
 function ljpost_post_local(array &$b)
 {
-       // This can probably be changed to allow editing by pointing to a different API endpoint
-       if ($b['edit']) {
-               return;
-       }
-
        if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
-       if ($b['private'] || $b['parent']) {
+       // This can probably be changed to allow editing by pointing to a different API endpoint
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
-       $lj_post   = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(),'ljpost','post'));
+       $lj_post   = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'ljpost', 'post'));
        $lj_enable = (($lj_post && !empty($_REQUEST['ljpost_enable'])) ? intval($_REQUEST['ljpost_enable']) : 0);
 
        if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'ljpost', 'post_by_default'))) {
@@ -118,11 +115,11 @@ function ljpost_post_local(array &$b)
 
 function ljpost_send(array &$b)
 {
-       if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
+       if ($b['deleted'] || ($b['private'] == Item::PRIVATE) || ($b['created'] !== $b['edited'])) {
                return;
        }
 
-       if (!strstr($b['postopts'],'ljpost')) {
+       if (!strstr($b['postopts'], 'ljpost')) {
                return;
        }
 
@@ -139,13 +136,13 @@ function ljpost_send(array &$b)
        $user = User::getById($b['uid']);
        $tz = $user['timezone'] ?: 'UTC';
 
-       $lj_username = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_username'));
-       $lj_password = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_password'));
-       $lj_journal = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_journal'));
-//     if(! $lj_journal)
-//             $lj_journal = $lj_username;
+       $lj_username = XML::escape(DI::pConfig()->get($b['uid'], 'ljpost', 'lj_username'));
+       $lj_password = XML::escape(DI::pConfig()->get($b['uid'], 'ljpost', 'lj_password'));
+       $lj_journal = XML::escape(DI::pConfig()->get($b['uid'], 'ljpost', 'lj_journal'));
+       //      if(! $lj_journal)
+       //              $lj_journal = $lj_username;
 
-       $lj_blog = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_blog'));
+       $lj_blog = XML::escape(DI::pConfig()->get($b['uid'], 'ljpost', 'lj_blog'));
        if (!strlen($lj_blog)) {
                $lj_blog = XML::escape('http://www.livejournal.com/interface/xmlrpc');
        }
@@ -157,11 +154,11 @@ function ljpost_send(array &$b)
                $tags = Tag::getCSVByURIId($b['uri-id'], [Tag::HASHTAG]);
 
                $date = DateTimeFormat::convert($b['created'], $tz);
-               $year = intval(substr($date,0,4));
-               $mon  = intval(substr($date,5,2));
-               $day  = intval(substr($date,8,2));
-               $hour = intval(substr($date,11,2));
-               $min  = intval(substr($date,14,2));
+               $year = intval(substr($date, 0, 4));
+               $mon  = intval(substr($date, 5, 2));
+               $day  = intval(substr($date, 8, 2));
+               $hour = intval(substr($date, 11, 2));
+               $min  = intval(substr($date, 14, 2));
 
                $xml = <<< EOT
 <?xml version="1.0" encoding="utf-8"?>
index e84f208bc25d610ff30618ed5e99365d76db8353..32f60f6d507188ea43d498aaafc2da83ba6bc2cc 100644 (file)
@@ -18,6 +18,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Model\Photo;
 use phpnut\phpnutException;
 
@@ -82,7 +83,7 @@ function pnut_connect()
                $o = DI::l10n()->t('Error fetching token. Please try again.', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
        }
 
-       $o .= '<br /><a href="' . DI::baseUrl() . '/settings/connectors">' . DI::l10n()->t("return to the connector page").'</a>';
+       $o .= '<br /><a href="' . DI::baseUrl() . '/settings/connectors">' . DI::l10n()->t("return to the connector page") . '</a>';
 
        return $o;
 }
@@ -119,14 +120,14 @@ function pnut_settings(array &$data)
        }
 
        $redirectUri  = DI::baseUrl() . '/pnut/connect';
-       $scope        = ['write_post','files'];
+       $scope        = ['write_post', 'files'];
 
        $enabled       = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'pnut', 'post') ?? false;
        $def_enabled   = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'pnut', 'post_by_default') ?? false;
        $client_id     = DI::config()->get('pnut', 'client_id');
        $client_secret = DI::config()->get('pnut', 'client_secret');
        $token         = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'pnut', 'access_token');
-       
+
        $user_client = empty($client_id) || empty($client_secret);
        if ($user_client) {
                $client_id     = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'pnut', 'client_id');
@@ -221,7 +222,7 @@ function pnut_hook_fork(array &$b)
                return;
        }
 
-       if (!strstr($post['postopts'] ?? '', 'pnut') || ($post['parent'] != $post['id']) || $post['private']) {
+       if (!strstr($post['postopts'] ?? '', 'pnut') || ($post['gravity'] != Item::GRAVITY_PARENT) || ($post['private'] == Item::PRIVATE)) {
                $b['execute'] = false;
                return;
        }
@@ -229,15 +230,11 @@ function pnut_hook_fork(array &$b)
 
 function pnut_post_local(array &$b)
 {
-       if ($b['edit']) {
-               return;
-       }
-
        if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
-       if ($b['private'] || $b['parent']) {
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
@@ -265,7 +262,7 @@ function pnut_post_hook(array &$b)
        /**
         * Post to pnut.io
         */
-       if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
+       if ($b['deleted'] || ($b['private'] == Item::PRIVATE) || ($b['created'] !== $b['edited'])) {
                return;
        }
 
index 6600696ec93a29714939f6ad82929003e8ab9250..2a8a530e0f45a0de4ae01044dc3448b04b02d387 100644 (file)
@@ -345,14 +345,14 @@ function pumpio_hook_fork(array &$b)
 
        if (DI::pConfig()->get($post['uid'], 'pumpio', 'import')) {
                // Don't fork if it isn't a reply to a pump.io post
-               if (($post['parent'] != $post['id']) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::PUMPIO])) {
+               if (($post['gravity'] != Item::GRAVITY_PARENT) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::PUMPIO])) {
                        Logger::notice('No pump.io parent found for item ' . $post['id']);
                        $b['execute'] = false;
                        return;
                }
        } else {
                // Comments are never exported when we don't import the pumpio timeline
-               if (!strstr($post['postopts'], 'pumpio') || ($post['parent'] != $post['id']) || $post['private']) {
+               if (!strstr($post['postopts'], 'pumpio') || ($post['gravity'] != Item::GRAVITY_PARENT)|| ($post['private'] == Item::PRIVATE)) {
                        $b['execute'] = false;
                        return;
                }
@@ -412,7 +412,7 @@ function pumpio_send(array &$b)
 
                Logger::notice('pumpio_send: receiver ', $receiver);
 
-               if (!count($receiver) && ($b['private'] || !strstr($b['postopts'], 'pumpio'))) {
+               if (!count($receiver) && ($b['private'] == Item::PRIVATE) || !strstr($b['postopts'], 'pumpio'))) {
                        return;
                }
 
@@ -1319,7 +1319,7 @@ function pumpio_getreceiver(array $b)
 {
        $receiver = [];
 
-       if (!$b['private']) {
+       if ($b['private'] != Item::PRIVATE)) {
                if (!strstr($b['postopts'], 'pumpio')) {
                        return $receiver;
                }
index f0372852af07eb6ba242812a50f019465a86711e..4bc32050fb0d8e2547a457af6ccb6e253ece929f 100644 (file)
@@ -296,7 +296,7 @@ function statusnet_hook_fork(array &$b)
 
        $post = $b['data'];
 
-       if ($post['deleted'] || ($post['created'] !== $post['edited']) || strpos($post['postopts'] ?? '', 'statusnet') === false || ($post['parent'] != $post['id']) || $post['private']) {
+       if ($post['deleted'] || ($post['created'] !== $post['edited']) || strpos($post['postopts'] ?? '', 'statusnet') === false || ($post['gravity'] != Item::GRAVITY_PARENT) || ($post['private'] == Item::PRIVATE)) {
                $b['execute'] = false;
                return;
        }
@@ -336,7 +336,7 @@ function statusnet_post_hook(array &$b)
        /**
         * Post to GNU Social
         */
-       if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
+       if ($b['deleted'] || ($b['private'] == Item::PRIVATE) || ($b['created'] !== $b['edited'])) {
                return;
        }
 
@@ -439,11 +439,13 @@ function statusnet_addon_admin_post()
                $secret = trim($_POST['secret'][$id]);
                $key = trim($_POST['key'][$id]);
                //$applicationname = (!empty($_POST['applicationname']) ? Strings::escapeTags(trim($_POST['applicationname'][$id])):'');
-               if ($sitename != '' &&
+               if (
+                       $sitename != '' &&
                        $apiurl != '' &&
                        $secret != '' &&
                        $key != '' &&
-                       empty($_POST['delete'][$id])) {
+                       empty($_POST['delete'][$id])
+               ) {
 
                        $sites[] = [
                                'sitename' => $sitename,
index 390c3c6c2d983c6b6dfeb3a292ec9da768779f8d..1e9f5c7fa843866cb22ee31ff167131d62ef7bf9 100644 (file)
@@ -477,13 +477,13 @@ function tumblr_hook_fork(array &$b)
 
        if (DI::pConfig()->get($post['uid'], 'tumblr', 'import')) {
                // Don't post if it isn't a reply to a tumblr post
-               if (($post['parent'] != $post['id']) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::TUMBLR])) {
+               if (($post['gravity'] != Item::GRAVITY_PARENT) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::TUMBLR])) {
                        Logger::notice('No tumblr parent found', ['item' => $post['id']]);
                        $b['execute'] = false;
                        return;
                }
-       } elseif (!strstr($post['postopts'] ?? '', 'tumblr') || ($post['parent'] != $post['id']) || $post['private']) {
-               DI::logger()->info('Activities are never exported when we don\'t import the tumblr timeline', ['uid' => $post['uid']]);
+       } elseif (!strstr($post['postopts'] ?? '', 'tumblr') || ($post['gravity'] != Item::GRAVITY_PARENT) || ($post['private'] == Item::PRIVATE)) {
+               DI::logger()->info('Post will not be exported', ['uid' => $post['uid'], 'postopts' => $post['postopts'], 'gravity' => $post['gravity'], 'private' => $post['private']]);
                $b['execute'] = false;
                return;
        }
@@ -491,15 +491,11 @@ function tumblr_hook_fork(array &$b)
 
 function tumblr_post_local(array &$b)
 {
-       if ($b['edit']) {
-               return;
-       }
-
        if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
-       if ($b['private'] || $b['parent']) {
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
@@ -575,7 +571,7 @@ function tumblr_send(array &$b)
                        }
                }
                return;
-       } elseif ($b['private'] || !strstr($b['postopts'], 'tumblr')) {
+       } elseif (($b['private'] == Item::PRIVATE) || !strstr($b['postopts'], 'tumblr')) {
                return;
        }
 
index 11c163efc9a50025b2ce17b139488c4936df0da7..10f8a2fb3aed8de774ab9f9fe10adcd7f1f67989 100644 (file)
@@ -170,7 +170,7 @@ function twitter_hook_fork(array &$b)
        $post = $b['data'];
 
        if (
-               $post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
+               $post['deleted'] || ($post['private'] == Item::PRIVATE) || ($post['created'] !== $post['edited']) ||
                !strstr($post['postopts'], 'twitter') || ($post['gravity'] != Item::GRAVITY_PARENT)
        ) {
                $b['execute'] = false;
@@ -184,7 +184,7 @@ function twitter_post_local(array &$b)
                return;
        }
 
-       if ($b['edit'] || $b['private'] || $b['parent']) {
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
@@ -211,7 +211,7 @@ function twitter_post_hook(array &$b)
 {
        DI::logger()->debug('Invoke post hook', $b);
 
-       if (($b['gravity'] != Item::GRAVITY_PARENT) || !strstr($b['postopts'], 'twitter') || $b['private'] || $b['deleted'] || ($b['created'] !== $b['edited'])) {
+       if (($b['gravity'] != Item::GRAVITY_PARENT) || !strstr($b['postopts'], 'twitter') || ($b['private'] == Item::PRIVATE) || $b['deleted'] || ($b['created'] !== $b['edited'])) {
                return;
        }
 
index e27079aa304905813398ca951a06ccf5cc03faa3..dba738de4830f7e3fc00bbd88405812e91081249 100644 (file)
@@ -108,8 +108,8 @@ function wppost_hook_fork(array &$b)
        $post = $b['data'];
 
        if (
-               $post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
-               !strstr($post['postopts'] ?? '', 'wppost') || ($post['parent'] != $post['id'])
+               $post['deleted'] || ($post['private'] == Item::PRIVATE) || ($post['created'] !== $post['edited']) ||
+               !strstr($post['postopts'] ?? '', 'wppost') || ($post['gravity'] != Item::GRAVITY_PARENT)
        ) {
                $b['execute'] = false;
                return;
@@ -118,18 +118,12 @@ function wppost_hook_fork(array &$b)
 
 function wppost_post_local(array &$b)
 {
-
-       // This can probably be changed to allow editing by pointing to a different API endpoint
-
-       if ($b['edit']) {
-               return;
-       }
-
        if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
                return;
        }
 
-       if ($b['private'] || $b['parent']) {
+       // This can probably be changed to allow editing by pointing to a different API endpoint
+       if ($b['edit'] || ($b['private'] == Item::PRIVATE) || ($b['gravity'] != Item::GRAVITY_PARENT)) {
                return;
        }
 
@@ -152,12 +146,9 @@ function wppost_post_local(array &$b)
        $b['postopts'] .= 'wppost';
 }
 
-
-
-
 function wppost_send(array &$b)
 {
-       if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
+       if ($b['deleted'] || ($b['private'] == Item::PRIVATE) || ($b['created'] !== $b['edited'])) {
                return;
        }