1
0
Fork 0

Issue 10491: Possibility for simple shortening added

This commit is contained in:
Michael 2021-07-12 14:11:51 +00:00
parent 07ef1edfd6
commit e5c312a066
6 changed files with 57 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($msg, $limit, $uid = 0)
{
$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

@ -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
*

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

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