Merge branch 'spoiler-auto-cw' into megamerge

Reviewed-on: #1
~keith 1 year ago
commit 014e9aeb21
Signed by: keith
GPG Key ID: 5BEBEEAB2C73D520

@ -2179,6 +2179,30 @@ class BBCode
DI::profiler()->stopRecording();
return $abstract;
}
/**
* Returns a list of the headings of "spoiler" elements
*
* @param string $text The text containing spoiler elements
* @return string The list of spoiler headings
*/
public static function getSpoilerHeadings(string $text): string
{
DI::profiler()->startRecording('rendering');
$headings = BBCode::performWithEscapedTags($text, ['code', 'noparse', 'nobb', 'pre'], function ($text) {
$headings = [];
if (preg_match_all('/\[spoiler=[\"\']*(.*?)[\"\']*\]/ism', $text, $matches)) {
foreach ($matches[1] as $item) {
$headings[] = BBCode::toPlaintext($item);
}
}
return implode(', ', $headings);
});
DI::profiler()->stopRecording();
return $headings;
}
/**
* Callback function to replace a Friendica style mention in a mention for Diaspora

@ -114,7 +114,7 @@ class HTML
/** @var \DOMNode $child */
foreach ($node->childNodes as $key => $child) {
/* Remove empty text nodes at the start or at the end of the children list */
if ($key > 0 && $key < $node->childNodes->length - 1 || $child->nodeName != '#text' || trim($child->nodeValue)) {
if ($key > 0 && $key < $node->childNodes->length - 1 || $child->nodeName != '#text' || trim($child->nodeValue) !== '') {
$newNode = $child->cloneNode(true);
$node->parentNode->insertBefore($newNode, $node);
}

@ -76,6 +76,7 @@ class ActivityPub
'discoverable' => 'toot:discoverable',
'PropertyValue' => 'schema:PropertyValue',
'value' => 'schema:value',
'keithext' => 'http://bytes.keithhacks.cyou/keith/friendica/',
]];
const ACCOUNT_TYPES = ['Person', 'Organization', 'Service', 'Group', 'Application', 'Tombstone'];
/**

@ -1835,6 +1835,12 @@ class Receiver
$object_data['sensitive'] = JsonLD::fetchElement($object, 'as:sensitive');
$object_data['name'] = JsonLD::fetchElement($object, 'as:name', '@value');
$object_data['summary'] = JsonLD::fetchElement($object, 'as:summary', '@value');
// HACK Don't know exactly where I should be checking keithext:summaryFromSpoilers to prevent
// auto-generated spoiler CWs from showing up on Friendica, but it's definitely not here.
// However, this should work for now.
// TODO @keith clean this up or else
if (JsonLD::fetchElement($object, 'keithext:summaryFromSpoilers', '@value'))
$object_data['summary'] = null;
$object_data['content'] = JsonLD::fetchElement($object, 'as:content', '@value');
$object_data['mediatype'] = JsonLD::fetchElement($object, 'as:mediaType', '@value');
$object_data = self::getSource($object, $object_data);

@ -1599,7 +1599,16 @@ class Transmitter
return $data;
}
$data['summary'] = BBCode::toPlaintext(BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB));
$abstract = BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB);
if (!empty($abstract)) {
$data['summary'] = BBCode::toPlaintext($abstract);
} else {
$warnings = BBCode::getSpoilerHeadings($item['body']);
if ($warnings) {
$data['summary'] = $warnings;
$data['keithext:summaryFromSpoilers'] = true;
}
}
if ($item['uri'] != $item['thr-parent']) {
$data['inReplyTo'] = $item['thr-parent'];

@ -780,7 +780,7 @@ class DFRN
}
// Remove the abstract element. It is only locally important.
$body = BBCode::stripAbstract($body);
// $body = BBCode::stripAbstract($body);
$htmlbody = '';
if ($type == 'html') {

Loading…
Cancel
Save