Issue 10491: Possibility for simple shortening added
This commit is contained in:
parent
07ef1edfd6
commit
e5c312a066
6 changed files with 57 additions and 3 deletions
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue