Issue 10491: Possibility for simple shortening added

This commit is contained in:
Michael 2021-07-12 14:11:51 +00:00 committed by Hypolite Petovan
parent 999a394b4d
commit 5526421607
4 changed files with 15 additions and 3 deletions

View 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")),

View 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("…", 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("♲ ", ENT_QUOTES, 'UTF-8');
$ellipsis = html_entity_decode("…", 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']);
}
}

View 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}}

View 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}}