spoiler-auto-cw #1

Closed
keith wants to merge 5 commits from spoiler-auto-cw into megamerge
11 changed files with 137 additions and 80 deletions

View file

@ -71,6 +71,7 @@ function settings_post(App $a)
if (!empty($_POST['general-submit'])) {
DI::pConfig()->set(local_user(), 'system', 'accept_only_sharer', intval($_POST['accept_only_sharer']));
DI::pConfig()->set(local_user(), 'system', 'disable_cw', !intval($_POST['enable_cw']));
DI::pConfig()->set(local_user(), 'system', 'enable_cw_self', intval($_POST['enable_cw_self']));
DI::pConfig()->set(local_user(), 'system', 'no_intelligent_shortening', !intval($_POST['enable_smart_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']));
@ -242,6 +243,7 @@ function settings_content(App $a)
if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'connectors')) {
$accept_only_sharer = intval(DI::pConfig()->get(local_user(), 'system', 'accept_only_sharer'));
$enable_cw = !intval(DI::pConfig()->get(local_user(), 'system', 'disable_cw'));
$enable_cw_self = intval(DI::pConfig()->get(local_user(), 'system', 'enable_cw_self'));
$enable_smart_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'));
@ -326,6 +328,7 @@ function settings_content(App $a)
]
],
'$enable_cw' => ['enable_cw', DI::l10n()->t('Enable Content Warning'), $enable_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 enables the automatic collapsing instead of setting the content warning as the post title. Doesn\'t affect any other content filtering you eventually set up.')],
'$enable_cw_self' => ['enable_cw_self', DI::l10n()->t('Show content warnings on own posts'), $enable_cw_self, DI::l10n()->t('Normally Friendica only displays content warnings on posts created by other users. If this option is enabled it will also display content warnings on your own posts.')],
'$enable_smart_shortening' => ['enable_smart_shortening', DI::l10n()->t('Enable intelligent shortening'), $enable_smart_shortening, DI::l10n()->t('Normally the system tries to find the best link to add to shortened posts. If disabled, 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.')],

View file

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

View file

@ -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);
}

View file

@ -2883,7 +2883,7 @@ class Item
// Compile eventual content filter reasons
$filter_reasons = [];
if (!$is_preview && public_contact() != $item['author-id']) {
if (!$is_preview && (public_contact() != $item['author-id'] || DI::pConfig()->get(local_user(), 'system', 'enable_cw_self', false))) {
if (!empty($item['content-warning']) && (!local_user() || !DI::pConfig()->get(local_user(), 'system', 'disable_cw', false))) {
$filter_reasons[] = DI::l10n()->t('Content warning: %s', $item['content-warning']);
}

View file

@ -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'];
/**

View file

@ -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);

View file

@ -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'];

View file

@ -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') {

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2022.09-dev\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-08-09 13:22-0400\n"
"POT-Creation-Date: 2022-08-13 00:37+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -45,8 +45,8 @@ msgstr ""
#: mod/cal.php:243 mod/events.php:374 src/Content/Nav.php:196
#: src/Content/Nav.php:260 src/Module/BaseProfile.php:84
#: src/Module/BaseProfile.php:95 view/theme/frio/theme.php:224
#: view/theme/frio/theme.php:228
#: src/Module/BaseProfile.php:95 view/theme/frio/theme.php:240
#: view/theme/frio/theme.php:244
msgid "Events"
msgstr ""
@ -122,7 +122,7 @@ msgstr ""
#: mod/item.php:181 mod/item.php:186 mod/item.php:870 mod/message.php:69
#: mod/message.php:111 mod/notes.php:44 mod/ostatus_subscribe.php:33
#: mod/photos.php:160 mod/photos.php:891 mod/repair_ostatus.php:31
#: mod/settings.php:40 mod/settings.php:50 mod/settings.php:156
#: mod/settings.php:40 mod/settings.php:50 mod/settings.php:157
#: mod/suggest.php:34 mod/uimport.php:33 mod/unfollow.php:35
#: mod/unfollow.php:50 mod/unfollow.php:82 mod/wall_attach.php:67
#: mod/wall_attach.php:69 mod/wall_upload.php:89 mod/wall_upload.php:91
@ -436,7 +436,7 @@ msgid "Failed to remove event"
msgstr ""
#: mod/fbrowser.php:61 src/Content/Nav.php:194 src/Module/BaseProfile.php:64
#: view/theme/frio/theme.php:222
#: view/theme/frio/theme.php:238
msgid "Photos"
msgstr ""
@ -717,7 +717,7 @@ msgstr ""
msgid "Discard"
msgstr ""
#: mod/message.php:133 src/Content/Nav.php:285 view/theme/frio/theme.php:229
#: mod/message.php:133 src/Content/Nav.php:285 view/theme/frio/theme.php:245
msgid "Messages"
msgstr ""
@ -1084,7 +1084,7 @@ msgstr ""
msgid "Select"
msgstr ""
#: mod/photos.php:1425 mod/settings.php:350 src/Content/Conversation.php:630
#: mod/photos.php:1425 mod/settings.php:353 src/Content/Conversation.php:630
#: src/Module/Admin/Users/Active.php:139 src/Module/Admin/Users/Blocked.php:140
#: src/Module/Admin/Users/Index.php:153
msgid "Delete"
@ -1175,15 +1175,15 @@ msgid_plural "Errors"
msgstr[0] ""
msgstr[1] ""
#: mod/settings.php:122
#: mod/settings.php:123
msgid "Failed to connect with email account using the settings provided."
msgstr ""
#: mod/settings.php:175
#: mod/settings.php:176
msgid "Connected Apps"
msgstr ""
#: mod/settings.php:176 src/Module/Admin/Blocklist/Contact.php:106
#: mod/settings.php:177 src/Module/Admin/Blocklist/Contact.php:106
#: src/Module/Admin/Users/Active.php:129 src/Module/Admin/Users/Blocked.php:130
#: src/Module/Admin/Users/Create.php:71 src/Module/Admin/Users/Deleted.php:88
#: src/Module/Admin/Users/Index.php:142 src/Module/Admin/Users/Index.php:162
@ -1191,20 +1191,20 @@ msgstr ""
msgid "Name"
msgstr ""
#: mod/settings.php:177 src/Content/Nav.php:214
#: mod/settings.php:178 src/Content/Nav.php:214
msgid "Home Page"
msgstr ""
#: mod/settings.php:178 src/Module/Admin/Queue.php:78
#: mod/settings.php:179 src/Module/Admin/Queue.php:78
msgid "Created"
msgstr ""
#: mod/settings.php:179
#: mod/settings.php:180
msgid "Remove authorization"
msgstr ""
#: mod/settings.php:205 mod/settings.php:237 mod/settings.php:268
#: mod/settings.php:352 src/Module/Admin/Addons/Index.php:69
#: mod/settings.php:206 mod/settings.php:238 mod/settings.php:270
#: mod/settings.php:355 src/Module/Admin/Addons/Index.php:69
#: src/Module/Admin/Features.php:87 src/Module/Admin/Logs/Settings.php:81
#: src/Module/Admin/Site.php:436 src/Module/Admin/Themes/Index.php:113
#: src/Module/Admin/Tos.php:83 src/Module/Settings/Account.php:562
@ -1212,83 +1212,83 @@ msgstr ""
msgid "Save Settings"
msgstr ""
#: mod/settings.php:213
#: mod/settings.php:214
msgid "Addon Settings"
msgstr ""
#: mod/settings.php:214
#: mod/settings.php:215
msgid "No Addon settings configured"
msgstr ""
#: mod/settings.php:235
#: mod/settings.php:236
msgid "Additional Features"
msgstr ""
#: mod/settings.php:273
#: mod/settings.php:275
msgid "Diaspora (Socialhome, Hubzilla)"
msgstr ""
#: mod/settings.php:273 mod/settings.php:274
#: mod/settings.php:275 mod/settings.php:276
msgid "enabled"
msgstr ""
#: mod/settings.php:273 mod/settings.php:274
#: mod/settings.php:275 mod/settings.php:276
msgid "disabled"
msgstr ""
#: mod/settings.php:273 mod/settings.php:274
#: mod/settings.php:275 mod/settings.php:276
#, php-format
msgid "Built-in support for %s connectivity is %s"
msgstr ""
#: mod/settings.php:274
#: mod/settings.php:276
msgid "OStatus (GNU Social)"
msgstr ""
#: mod/settings.php:300
#: mod/settings.php:302
msgid "Email access is disabled on this site."
msgstr ""
#: mod/settings.php:305 mod/settings.php:350
#: mod/settings.php:307 mod/settings.php:353
msgid "None"
msgstr ""
#: mod/settings.php:311 src/Module/BaseSettings.php:78
#: mod/settings.php:313 src/Module/BaseSettings.php:78
msgid "Social Networks"
msgstr ""
#: mod/settings.php:316
#: mod/settings.php:318
msgid "General Social Media Settings"
msgstr ""
#: mod/settings.php:319
#: mod/settings.php:321
msgid "Followed content scope"
msgstr ""
#: mod/settings.php:321
#: mod/settings.php:323
msgid ""
"By default, conversations in which your follows participated but didn't "
"start will be shown in your timeline. You can turn this behavior off, or "
"expand it to the conversations in which your follows liked a post."
msgstr ""
#: mod/settings.php:323
#: mod/settings.php:325
msgid "Only conversations my follows started"
msgstr ""
#: mod/settings.php:324
#: mod/settings.php:326
msgid "Conversations my follows started or commented on (default)"
msgstr ""
#: mod/settings.php:325
#: mod/settings.php:327
msgid "Any conversation my follows interacted with, including likes"
msgstr ""
#: mod/settings.php:328
#: mod/settings.php:330
msgid "Enable Content Warning"
msgstr ""
#: mod/settings.php:328
#: mod/settings.php:330
msgid ""
"Users on networks like Mastodon or Pleroma are able to set a content warning "
"field which collapse their post by default. This enables the automatic "
@ -1296,108 +1296,119 @@ msgid ""
"affect any other content filtering you eventually set up."
msgstr ""
#: mod/settings.php:329
#: mod/settings.php:331
msgid "Show content warnings on own posts"
msgstr ""
#: mod/settings.php:331
msgid ""
"Normally Friendica only displays content warnings on posts created by other "
"users. If this option is enabled it will also display content warnings on "
"your own posts."
msgstr ""
#: mod/settings.php:332
msgid "Enable intelligent shortening"
msgstr ""
#: mod/settings.php:329
#: mod/settings.php:332
msgid ""
"Normally the system tries to find the best link to add to shortened posts. "
"If disabled, every shortened post will always point to the original "
"friendica post."
msgstr ""
#: mod/settings.php:330
#: mod/settings.php:333
msgid "Enable simple text shortening"
msgstr ""
#: mod/settings.php:330
#: mod/settings.php:333
msgid ""
"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."
msgstr ""
#: mod/settings.php:331
#: mod/settings.php:334
msgid "Attach the link title"
msgstr ""
#: mod/settings.php:331
#: mod/settings.php:334
msgid ""
"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."
msgstr ""
#: mod/settings.php:332
#: mod/settings.php:335
msgid "Your legacy ActivityPub/GNU Social account"
msgstr ""
#: mod/settings.php:332
#: mod/settings.php:335
msgid ""
"If you enter your old account name from an ActivityPub based system or your "
"GNU Social/Statusnet account name here (in the format user@domain.tld), your "
"contacts will be added automatically. The field will be emptied when done."
msgstr ""
#: mod/settings.php:335
#: mod/settings.php:338
msgid "Repair OStatus subscriptions"
msgstr ""
#: mod/settings.php:339
#: mod/settings.php:342
msgid "Email/Mailbox Setup"
msgstr ""
#: mod/settings.php:340
#: mod/settings.php:343
msgid ""
"If you wish to communicate with email contacts using this service "
"(optional), please specify how to connect to your mailbox."
msgstr ""
#: mod/settings.php:341
#: mod/settings.php:344
msgid "Last successful email check:"
msgstr ""
#: mod/settings.php:343
#: mod/settings.php:346
msgid "IMAP server name:"
msgstr ""
#: mod/settings.php:344
#: mod/settings.php:347
msgid "IMAP port:"
msgstr ""
#: mod/settings.php:345
#: mod/settings.php:348
msgid "Security:"
msgstr ""
#: mod/settings.php:346
#: mod/settings.php:349
msgid "Email login name:"
msgstr ""
#: mod/settings.php:347
#: mod/settings.php:350
msgid "Email password:"
msgstr ""
#: mod/settings.php:348
#: mod/settings.php:351
msgid "Reply-to address:"
msgstr ""
#: mod/settings.php:349
#: mod/settings.php:352
msgid "Send public posts to all email contacts:"
msgstr ""
#: mod/settings.php:350
#: mod/settings.php:353
msgid "Action after import:"
msgstr ""
#: mod/settings.php:350 src/Content/Nav.php:282
#: mod/settings.php:353 src/Content/Nav.php:282
msgid "Mark as seen"
msgstr ""
#: mod/settings.php:350
#: mod/settings.php:353
msgid "Move to folder"
msgstr ""
#: mod/settings.php:351
#: mod/settings.php:354
msgid "Move to folder:"
msgstr ""
@ -2296,7 +2307,7 @@ msgstr ""
msgid "event"
msgstr ""
#: src/Content/Item.php:380 view/theme/frio/theme.php:250
#: src/Content/Item.php:380 view/theme/frio/theme.php:266
msgid "Follow Thread"
msgstr ""
@ -2382,41 +2393,41 @@ msgstr ""
#: src/Content/Nav.php:192 src/Module/BaseProfile.php:56
#: src/Module/Contact.php:433 src/Module/Contact/Profile.php:380
#: src/Module/Settings/TwoFactor/Index.php:120 view/theme/frio/theme.php:220
#: src/Module/Settings/TwoFactor/Index.php:120 view/theme/frio/theme.php:236
msgid "Status"
msgstr ""
#: src/Content/Nav.php:192 src/Content/Nav.php:275
#: view/theme/frio/theme.php:220
#: view/theme/frio/theme.php:236
msgid "Your posts and conversations"
msgstr ""
#: src/Content/Nav.php:193 src/Module/BaseProfile.php:48
#: src/Module/BaseSettings.php:55 src/Module/Contact.php:457
#: src/Module/Contact/Profile.php:382 src/Module/Profile/Profile.php:241
#: src/Module/Welcome.php:57 view/theme/frio/theme.php:221
#: src/Module/Welcome.php:57 view/theme/frio/theme.php:237
msgid "Profile"
msgstr ""
#: src/Content/Nav.php:193 view/theme/frio/theme.php:221
#: src/Content/Nav.php:193 view/theme/frio/theme.php:237
msgid "Your profile page"
msgstr ""
#: src/Content/Nav.php:194 view/theme/frio/theme.php:222
#: src/Content/Nav.php:194 view/theme/frio/theme.php:238
msgid "Your photos"
msgstr ""
#: src/Content/Nav.php:195 src/Module/BaseProfile.php:72
#: src/Module/BaseProfile.php:75 src/Module/Contact.php:449
#: view/theme/frio/theme.php:223
#: view/theme/frio/theme.php:239
msgid "Media"
msgstr ""
#: src/Content/Nav.php:195 view/theme/frio/theme.php:223
#: src/Content/Nav.php:195 view/theme/frio/theme.php:239
msgid "Your postings with media"
msgstr ""
#: src/Content/Nav.php:196 view/theme/frio/theme.php:224
#: src/Content/Nav.php:196 view/theme/frio/theme.php:240
msgid "Your events"
msgstr ""
@ -2482,7 +2493,7 @@ msgstr ""
#: src/Content/Nav.php:237 src/Content/Nav.php:296
#: src/Content/Text/HTML.php:899 src/Module/BaseProfile.php:125
#: src/Module/BaseProfile.php:128 src/Module/Contact.php:370
#: src/Module/Contact.php:464 view/theme/frio/theme.php:231
#: src/Module/Contact.php:464 view/theme/frio/theme.php:247
msgid "Contacts"
msgstr ""
@ -2495,7 +2506,7 @@ msgid "Conversations on this and other servers"
msgstr ""
#: src/Content/Nav.php:260 src/Module/BaseProfile.php:87
#: src/Module/BaseProfile.php:98 view/theme/frio/theme.php:228
#: src/Module/BaseProfile.php:98 view/theme/frio/theme.php:244
msgid "Events and Calendar"
msgstr ""
@ -2525,11 +2536,11 @@ msgstr ""
msgid "Terms of Service of this Friendica instance"
msgstr ""
#: src/Content/Nav.php:273 view/theme/frio/theme.php:227
#: src/Content/Nav.php:273 view/theme/frio/theme.php:243
msgid "Network"
msgstr ""
#: src/Content/Nav.php:273 view/theme/frio/theme.php:227
#: src/Content/Nav.php:273 view/theme/frio/theme.php:243
msgid "Conversations from your friends"
msgstr ""
@ -2554,7 +2565,7 @@ msgstr ""
msgid "Mark all system notifications as seen"
msgstr ""
#: src/Content/Nav.php:285 view/theme/frio/theme.php:229
#: src/Content/Nav.php:285 view/theme/frio/theme.php:245
msgid "Private mail"
msgstr ""
@ -2576,15 +2587,15 @@ msgstr ""
#: src/Content/Nav.php:294 src/Module/Admin/Addons/Details.php:114
#: src/Module/Admin/Themes/Details.php:93 src/Module/BaseSettings.php:122
#: src/Module/Welcome.php:52 view/theme/frio/theme.php:230
#: src/Module/Welcome.php:52 view/theme/frio/theme.php:246
msgid "Settings"
msgstr ""
#: src/Content/Nav.php:294 view/theme/frio/theme.php:230
#: src/Content/Nav.php:294 view/theme/frio/theme.php:246
msgid "Account settings"
msgstr ""
#: src/Content/Nav.php:296 view/theme/frio/theme.php:231
#: src/Content/Nav.php:296 view/theme/frio/theme.php:247
msgid "Manage/edit friends and contacts"
msgstr ""
@ -11268,11 +11279,11 @@ msgstr ""
msgid "Back to top"
msgstr ""
#: view/theme/frio/theme.php:202
#: view/theme/frio/theme.php:218
msgid "Guest"
msgstr ""
#: view/theme/frio/theme.php:205
#: view/theme/frio/theme.php:221
msgid "Visitor"
msgstr ""

View file

@ -13,6 +13,7 @@
{{include file="field_select.tpl" field=$accept_only_sharer}}
{{include file="field_checkbox.tpl" field=$enable_cw}}
{{include file="field_checkbox.tpl" field=$enable_cw_self}}
{{include file="field_checkbox.tpl" field=$enable_smart_shortening}}
{{include file="field_checkbox.tpl" field=$simple_shortening}}
{{include file="field_checkbox.tpl" field=$attach_link_title}}

View file

@ -22,6 +22,8 @@
{{include file="field_checkbox.tpl" field=$enable_cw}}
{{include file="field_checkbox.tpl" field=$enable_cw_self}}
{{include file="field_checkbox.tpl" field=$enable_smart_shortening}}
{{include file="field_checkbox.tpl" field=$simple_shortening}}