]> 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)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 14 Jul 2021 02:37:22 +0000 (22:37 -0400)
mod/settings.php
src/Content/Text/Plaintext.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..e635d727e84dfe9958099a068fda33664dfa32e4 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(string $msg, int $limit, int $uid = 0):string
        {
+               $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 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}}