]> git.mxchange.org Git - friendica.git/commitdiff
Issue 10491: Possibility for simple shortening added
authorMichael <heluecht@pirati.ca>
Mon, 12 Jul 2021 14:11:51 +0000 (14:11 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 12 Jul 2021 14:11:51 +0000 (14:11 +0000)
mod/settings.php
src/Content/Text/Plaintext.php
src/Model/Item.php
src/Protocol/Diaspora.php
view/templates/settings/connectors.tpl
view/theme/frio/templates/settings/connectors.tpl

index e042ed8e85d3e442d66c9d1a7bc029d420fc5396..c9350e68e8b7d8ead6cd654b42828e1f821fee9c 100644 (file)
@@ -137,6 +137,7 @@ function settings_post(App $a)
                        DI::pConfig()->set(local_user(), 'system', 'accept_only_sharer', intval($_POST['accept_only_sharer']));
                        DI::pConfig()->set(local_user(), 'system', 'disable_cw', intval($_POST['disable_cw']));
                        DI::pConfig()->set(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening']));
+                       DI::pConfig()->set(local_user(), 'system', 'simple_shortening', intval($_POST['simple_shortening']));
                        DI::pConfig()->set(local_user(), 'system', 'attach_link_title', intval($_POST['attach_link_title']));
                        DI::pConfig()->set(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow']));
                        DI::pConfig()->set(local_user(), 'ostatus', 'default_group', $_POST['group-selection']);
@@ -546,6 +547,7 @@ function settings_content(App $a)
                $accept_only_sharer        = intval(DI::pConfig()->get(local_user(), 'system', 'accept_only_sharer'));
                $disable_cw                = intval(DI::pConfig()->get(local_user(), 'system', 'disable_cw'));
                $no_intelligent_shortening = intval(DI::pConfig()->get(local_user(), 'system', 'no_intelligent_shortening'));
+               $simple_shortening         = intval(DI::pConfig()->get(local_user(), 'system', 'simple_shortening'));
                $attach_link_title         = intval(DI::pConfig()->get(local_user(), 'system', 'attach_link_title'));
                $ostatus_autofriend        = intval(DI::pConfig()->get(local_user(), 'system', 'ostatus_autofriend'));
                $default_group             = DI::pConfig()->get(local_user(), 'ostatus', 'default_group');
@@ -612,6 +614,7 @@ function settings_content(App $a)
                        '$accept_only_sharer' => ['accept_only_sharer', DI::l10n()->t('Accept only top level posts by contacts you follow'), $accept_only_sharer, DI::l10n()->t('The system does an auto completion of threads when a comment arrives. This has got the side effect that you can receive posts that had been started by a non-follower but had been commented by someone you follow. This setting deactivates this behaviour. When activated, you strictly only will receive posts from people you really do follow.')],
                        '$disable_cw' => ['disable_cw', DI::l10n()->t('Disable Content Warning'), $disable_cw, DI::l10n()->t('Users on networks like Mastodon or Pleroma are able to set a content warning field which collapse their post by default. This disables the automatic collapsing and sets the content warning as the post title. Doesn\'t affect any other content filtering you eventually set up.')],
                        '$no_intelligent_shortening' => ['no_intelligent_shortening', DI::l10n()->t('Disable intelligent shortening'), $no_intelligent_shortening, DI::l10n()->t('Normally the system tries to find the best link to add to shortened posts. If this option is enabled then every shortened post will always point to the original friendica post.')],
+                       '$simple_shortening' => ['simple_shortening', DI::l10n()->t('Enable simple text shortening'), $simple_shortening, DI::l10n()->t('Normally the system shortens posts at the next line feed. If this option is enabled then the system will shorten the text at the maximum character limit.')],
                        '$attach_link_title' => ['attach_link_title', DI::l10n()->t('Attach the link title'), $attach_link_title, DI::l10n()->t('When activated, the title of the attached link will be added as a title on posts to Diaspora. This is mostly helpful with "remote-self" contacts that share feed content.')],
                        '$ostatus_autofriend' => ['snautofollow', DI::l10n()->t("Automatically follow any GNU Social \x28OStatus\x29 followers/mentioners"), $ostatus_autofriend, DI::l10n()->t('If you receive a message from an unknown OStatus user, this option decides what to do. If it is checked, a new contact will be created for every unknown user.')],
                        '$default_group' => Group::displayGroupSelection(local_user(), $default_group, DI::l10n()->t("Default group for OStatus contacts")),
index 1c602b2bf867c732b6e0a33ea63601d58fdbd223..45c35cb172c9e4c7410f258f0d2d17ca89fb15c3 100644 (file)
@@ -31,16 +31,22 @@ class Plaintext
         *
         * @param  string $msg
         * @param  int    $limit
+        * @param  int    $uid
         * @return string
         *
         * @todo For Twitter URLs aren't shortened, but they have to be calculated as if.
         */
-       public static function shorten($msg, $limit)
+       public static function shorten($msg, $limit, $uid = 0)
        {
+               $ellipsis = html_entity_decode("&#x2026;", ENT_QUOTES, 'UTF-8');
+
+               if (!empty($uid) && DI::pConfig()->get($uid, 'system', 'simple_shortening')) {
+                       return iconv_substr(iconv_substr(trim($msg), 0, $limit, "UTF-8"), 0, -3, "UTF-8") . $ellipsis;
+               }
+
                $lines = explode("\n", $msg);
                $msg = "";
                $recycle = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8');
-               $ellipsis = html_entity_decode("&#x2026;", ENT_QUOTES, 'UTF-8');
                foreach ($lines as $row => $line) {
                        if (iconv_strlen(trim($msg . "\n" . $line), "UTF-8") <= $limit) {
                                $msg = trim($msg . "\n" . $line);
@@ -241,7 +247,7 @@ class Plaintext
                                } elseif (DI::pConfig()->get($item['uid'], 'system', 'no_intelligent_shortening')) {
                                        $post['url'] = $item['plink'];
                                }
-                               $msg = self::shorten($msg, $limit);
+                               $msg = self::shorten($msg, $limit, $item['uid']);
                        }
                }
 
index 86b9270fe9e899c55f7e6bf4cd2c129f1d515619..990232fc4bd33b321ebfd2e3e28aff8a9ce1f270 100644 (file)
@@ -38,6 +38,8 @@ use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\Diaspora;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\HTTPSignature;
+use Friendica\Util\LDSignature;
 use Friendica\Util\Map;
 use Friendica\Util\Network;
 use Friendica\Util\Proxy;
@@ -542,25 +544,30 @@ class Item
 
                if (!empty($item['author-id']) && Contact::isBlocked($item['author-id'])) {
                        Logger::notice('Author is blocked node-wide', ['author-link' => $item['author-link'], 'item-uri' => $item['uri']]);
+                       self::remoteDelete($item);
                        return false;
                }
 
                if (!empty($item['author-link']) && Network::isUrlBlocked($item['author-link'])) {
                        Logger::notice('Author server is blocked', ['author-link' => $item['author-link'], 'item-uri' => $item['uri']]);
+                       self::remoteDelete($item);
                        return false;
                }
 
                if (!empty($item['owner-id']) && Contact::isBlocked($item['owner-id'])) {
                        Logger::notice('Owner is blocked node-wide', ['owner-link' => $item['owner-link'], 'item-uri' => $item['uri']]);
+                       self::remoteDelete($item);
                        return false;
                }
 
                if (!empty($item['owner-link']) && Network::isUrlBlocked($item['owner-link'])) {
                        Logger::notice('Owner server is blocked', ['owner-link' => $item['owner-link'], 'item-uri' => $item['uri']]);
+                       self::remoteDelete($item);
                        return false;
                }
 
                if (!empty($item['uid']) && !self::isAllowedByUser($item, $item['uid'])) {
+                       self::remoteDelete($item);
                        return false;
                }
 
@@ -583,6 +590,40 @@ class Item
                return true;
        }
 
+       /**
+        * Try to delete the remote (unwanted) item
+        *
+        * @param array $item 
+        */
+       private static function remoteDelete(array $item)
+       {
+               if ($item['gravity'] == GRAVITY_PARENT) {
+                       return;
+               }
+               return;
+
+               $owner   = User::getOwnerDataById($item['uid']);
+               $contact = Contact::getById($item['contact-id']);
+
+               if (FContact::getByURL($contact['addr'], false)) {
+                       Logger::info('Send Diaspora retraction for post', ['addr' => $contact['addr'], 'item' => $item]);
+                       Diaspora::sendRetraction($item, $owner, $contact, in_array($item['private'], [self::UNLISTED, self::PUBLIC]));
+               } elseif ($profile = APContact::getByURL($contact['url'], false)) {
+                       Logger::info('Send ActivityPub deletion for post', ['url' => $contact['url'], 'item' => $item]);
+                       $data = ['@context' => ActivityPub::CONTEXT,
+                               'id' => $item['uri'] . '/Delete',
+                               'type' => 'Delete',
+                               'actor' => $owner['url'],
+                               'object' => ['type' => 'Tombstone', 'id' => $item['uri']],
+                               'to' => [$profile['url']]];
+
+                       $signed = LDSignature::sign($data, $owner);
+                       return HTTPSignature::transmit($signed, $profile['inbox'], $item['uid']);
+               } else {
+                       Logger::info('Unsupported protocol for deletion', ['network' => $contact['network']]);
+               }
+       }
+
        /**
         * Check if the item array is too old
         *
index 586b6e9ec282e8b425adfbf42adff5a71d995bcc..862bbca9996e6d4b1c05a58ebc6c766175f97081 100644 (file)
@@ -1495,6 +1495,7 @@ class Diaspora
 
                $contact = self::allowedContactByHandle($importer, $sender, true);
                if (!$contact) {
+                       //self::sendRetraction($item, $owner, $contact, in_array($item['private'], [self::UNLISTED, self::PUBLIC]));
                        return false;
                }
 
index 08452b124fedd1f5c4cfa5b6388ae6b42208de0b..ef9cc2b95bb297fefbffae57328053d015fd6239 100644 (file)
@@ -14,6 +14,7 @@
                {{include file="field_checkbox.tpl" field=$accept_only_sharer}}
                {{include file="field_checkbox.tpl" field=$disable_cw}}
                {{include file="field_checkbox.tpl" field=$no_intelligent_shortening}}
+               {{include file="field_checkbox.tpl" field=$simple_shortening}}
                {{include file="field_checkbox.tpl" field=$attach_link_title}}
                {{include file="field_checkbox.tpl" field=$ostatus_autofriend}}
                {{$default_group nofilter}}
index 6818c66bd5bac50c60ec6112d7b3988a72335e77..88e4977e149ecaafee58362da1505c7cbe7ff120 100644 (file)
@@ -24,6 +24,8 @@
 
                                                {{include file="field_checkbox.tpl" field=$no_intelligent_shortening}}
 
+                                               {{include file="field_checkbox.tpl" field=$simple_shortening}}
+
                                                {{include file="field_checkbox.tpl" field=$attach_link_title}}
 
                                                {{include file="field_checkbox.tpl" field=$ostatus_autofriend}}