Merge pull request #14162 from annando/sensitive

Respect the "sensitive" flag for posts
This commit is contained in:
Hypolite Petovan 2024-05-16 11:12:28 -04:00 committed by GitHub
commit c81ee0d1c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 638 additions and 672 deletions

View file

@ -1514,14 +1514,6 @@ class Conversation
[$categories, $folders] = $this->item->determineCategoriesTerms($item, $this->session->getLocalUserId());
if (!empty($item['title'])) {
$title = $item['title'];
} elseif (!empty($item['content-warning']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'disable_cw', false)) {
$title = ucfirst($item['content-warning']);
} else {
$title = '';
}
if (!empty($item['featured'])) {
$pinned = $this->l10n->t('Pinned item');
} else {
@ -1547,7 +1539,8 @@ class Conversation
'sparkle' => $sparkle,
'lock' => false,
'thumb' => $this->baseURL->remove($this->item->getAuthorAvatar($item)),
'title' => $title,
'title' => $item['title'],
'summary' => $item['content-warning'],
'body_html' => $body_html,
'tags' => $tags['tags'],
'hashtags' => $tags['hashtags'],

View file

@ -3347,7 +3347,6 @@ class Item
$item['tags'] = $tags['tags'];
$item['hashtags'] = $tags['hashtags'];
$item['mentions'] = $tags['mentions'];
$sensitive = $item['sensitive'] && !DI::pConfig()->get($uid, 'system', 'display_sensitive', false);
if (!$is_preview) {
$item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']);
@ -3415,11 +3414,11 @@ class Item
$shared_links = array_merge($shared_links, $sharedSplitAttachments['visual']->column('url'));
$shared_links = array_merge($shared_links, $sharedSplitAttachments['link']->column('url'));
$shared_links = array_merge($shared_links, $sharedSplitAttachments['additional']->column('url'));
$item['body'] = self::replaceVisualAttachments($sharedSplitAttachments['visual'], $item['body'], $sensitive);
$item['body'] = self::replaceVisualAttachments($sharedSplitAttachments['visual'], $item['body']);
}
$itemSplitAttachments = DI::postMediaRepository()->splitAttachments($item['uri-id'], $shared_links, $item['has-media'] ?? false);
$item['body'] = self::replaceVisualAttachments($itemSplitAttachments['visual'], $item['body'] ?? '', $sensitive);
$item['body'] = self::replaceVisualAttachments($itemSplitAttachments['visual'], $item['body'] ?? '');
self::putInCache($item);
$item['body'] = $body;
@ -3440,8 +3439,8 @@ class Item
$filter_reasons[] = DI::l10n()->t('Content from %s is collapsed', $item['author-name']);
}
if (!empty($item['content-warning']) && (!$uid || !DI::pConfig()->get($uid, 'system', 'disable_cw', false))) {
$filter_reasons[] = DI::l10n()->t('Content warning: %s', $item['content-warning']);
if ($item['sensitive'] && (!$uid || !DI::pConfig()->get($uid, 'system', 'disable_cw', false))) {
$filter_reasons[] = DI::l10n()->t('Sensitive content');
}
$item['attachments'] = $itemSplitAttachments;
@ -3474,9 +3473,9 @@ class Item
}
if (!empty($sharedSplitAttachments)) {
$s = self::addGallery($s, $sharedSplitAttachments['visual'], $sensitive);
$s = self::addVisualAttachments($sharedSplitAttachments['visual'], $shared_item, $s, true, $sensitive);
$s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $sharedSplitAttachments, $body, $s, true, $quote_shared_links, $sensitive);
$s = self::addGallery($s, $sharedSplitAttachments['visual']);
$s = self::addVisualAttachments($sharedSplitAttachments['visual'], $shared_item, $s, true);
$s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $sharedSplitAttachments, $body, $s, true, $quote_shared_links);
$s = self::addNonVisualAttachments($sharedSplitAttachments['additional'], $item, $s, true);
$body = BBCode::removeSharedData($body);
}
@ -3487,9 +3486,9 @@ class Item
$s = substr($s, 0, $pos);
}
$s = self::addGallery($s, $itemSplitAttachments['visual'], $sensitive);
$s = self::addVisualAttachments($itemSplitAttachments['visual'], $item, $s, false, $sensitive);
$s = self::addLinkAttachment($item['uri-id'], $itemSplitAttachments, $body, $s, false, $shared_links, $sensitive);
$s = self::addGallery($s, $itemSplitAttachments['visual']);
$s = self::addVisualAttachments($itemSplitAttachments['visual'], $item, $s, false);
$s = self::addLinkAttachment($item['uri-id'], $itemSplitAttachments, $body, $s, false, $shared_links);
$s = self::addNonVisualAttachments($itemSplitAttachments['additional'], $item, $s, false);
$s = self::addQuestions($item, $s);
@ -3523,10 +3522,9 @@ class Item
*
* @param string $s
* @param PostMedias $PostMedias
* @param bool $sensitive
* @return string
*/
private static function addGallery(string $s, PostMedias $PostMedias, bool $sensitive): string
private static function addGallery(string $s, PostMedias $PostMedias): string
{
foreach ($PostMedias as $PostMedia) {
if (!$PostMedia->preview || ($PostMedia->type !== Post\Media::IMAGE)) {
@ -3536,10 +3534,9 @@ class Item
if ($PostMedia->hasDimensions()) {
$pattern = '#<a href="' . preg_quote($PostMedia->url) . '">(.*?)"></a>#';
$s = preg_replace_callback($pattern, function () use ($PostMedia, $sensitive) {
$s = preg_replace_callback($pattern, function () use ($PostMedia) {
return Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image/single_with_height_allocation.tpl'), [
'$image' => $PostMedia,
'$sensitive' => $sensitive,
'$allocated_height' => $PostMedia->getAllocatedHeight(),
'$allocated_max_width' => ($PostMedia->previewWidth ?? $PostMedia->width) . 'px',
]);
@ -3608,10 +3605,9 @@ class Item
*
* @param PostMedias $PostMedias
* @param string $body
* @param bool $sensitive
* @return string modified body
*/
private static function replaceVisualAttachments(PostMedias $PostMedias, string $body, bool $sensitive): string
private static function replaceVisualAttachments(PostMedias $PostMedias, string $body): string
{
DI::profiler()->startRecording('rendering');
@ -3620,7 +3616,7 @@ class Item
if (DI::baseUrl()->isLocalUri($PostMedia->preview)) {
continue;
}
$proxy = DI::baseUrl() . $PostMedia->getPreviewPath(Proxy::SIZE_LARGE, $sensitive);
$proxy = DI::baseUrl() . $PostMedia->getPreviewPath(Proxy::SIZE_LARGE);
$search = ['[img=' . $PostMedia->preview . ']', ']' . $PostMedia->preview . '[/img]'];
$replace = ['[img=' . $proxy . ']', ']' . $proxy . '[/img]'];
@ -3629,7 +3625,7 @@ class Item
if (DI::baseUrl()->isLocalUri($PostMedia->url)) {
continue;
}
$proxy = DI::baseUrl() . $PostMedia->getPreviewPath(Proxy::SIZE_LARGE, $sensitive);
$proxy = DI::baseUrl() . $PostMedia->getPreviewPath(Proxy::SIZE_LARGE);
$search = ['[img=' . $PostMedia->url . ']', ']' . $PostMedia->url . '[/img]'];
$replace = ['[img=' . $proxy . ']', ']' . $proxy . '[/img]'];
@ -3647,11 +3643,10 @@ class Item
* @param array $item
* @param string $content
* @param bool $shared
* @param bool $sensitive
* @return string modified content
* @throws ServiceUnavailableException
*/
private static function addVisualAttachments(PostMedias $PostMedias, array $item, string $content, bool $shared, bool $sensitive): string
private static function addVisualAttachments(PostMedias $PostMedias, array $item, string $content, bool $shared): string
{
DI::profiler()->startRecording('rendering');
$leading = '';
@ -3666,7 +3661,7 @@ class Item
if ($PostMedia->mimetype->type == 'image' || $PostMedia->preview) {
$preview_size = Proxy::SIZE_MEDIUM;
$preview_url = DI::baseUrl() . $PostMedia->getPreviewPath($preview_size, $sensitive);
$preview_url = DI::baseUrl() . $PostMedia->getPreviewPath($preview_size);
} else {
$preview_size = 0;
$preview_url = '';
@ -3761,12 +3756,11 @@ class Item
* @param string $content
* @param bool $shared
* @param array $ignore_links A list of URLs to ignore
* @param bool $sensitive
* @return string modified content
* @throws InternalServerErrorException
* @throws ServiceUnavailableException
*/
private static function addLinkAttachment(int $uriid, array $attachments, string $body, string $content, bool $shared, array $ignore_links, bool $sensitive): string
private static function addLinkAttachment(int $uriid, array $attachments, string $body, string $content, bool $shared, array $ignore_links): string
{
DI::profiler()->startRecording('rendering');
// Don't show a preview when there is a visual attachment (audio or video)
@ -3809,9 +3803,9 @@ class Item
if ($preview && $attachment->preview) {
if ($attachment->previewWidth >= 500) {
$data['image'] = DI::baseUrl() . $attachment->getPreviewPath(Proxy::SIZE_MEDIUM, $sensitive);
$data['image'] = DI::baseUrl() . $attachment->getPreviewPath(Proxy::SIZE_MEDIUM);
} else {
$data['preview'] = DI::baseUrl() . $attachment->getPreviewPath(Proxy::SIZE_MEDIUM, $sensitive);
$data['preview'] = DI::baseUrl() . $attachment->getPreviewPath(Proxy::SIZE_MEDIUM);
}
}
@ -3836,11 +3830,6 @@ class Item
$data = BBCode::getAttachmentData($match[1]);
}
if ($sensitive) {
$data['image'] = '';
$data['preview'] = '';
}
DI::profiler()->stopRecording();
if (isset($data['url']) && !in_array(strtolower($data['url']), $ignore_links)) {

View file

@ -218,7 +218,7 @@ class Connectors extends BaseSettings
Item::COMPLETION_LIKE => $this->t('Any conversation my follows interacted with, including likes'),
]
],
'$enable_cw' => ['enable_cw', $this->t('Enable Content Warning'), $enable_cw, $this->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' => ['enable_cw', $this->t("Collapse sensitive posts"), $enable_cw, $this->t('If a post is marked as "sensitive", it will be displayed in a collapsed state, if this option is enabled.')],
'$enable_smart_shortening' => ['enable_smart_shortening', $this->t('Enable intelligent shortening'), $enable_smart_shortening, $this->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', $this->t('Enable simple text shortening'), $simple_shortening, $this->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', $this->t('Attach the link title'), $attach_link_title, $this->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

@ -106,7 +106,6 @@ class Display extends BaseSettings
$enable_smart_threading = (bool)$request['enable_smart_threading'];
$enable_dislike = (bool)$request['enable_dislike'];
$display_resharer = (bool)$request['display_resharer'];
$display_sensitive = (bool)$request['display_sensitive'];
$stay_local = (bool)$request['stay_local'];
$show_page_drop = (bool)$request['show_page_drop'];
$display_eventlist = (bool)$request['display_eventlist'];
@ -158,7 +157,6 @@ class Display extends BaseSettings
$this->pConfig->set($uid, 'system', 'no_smart_threading' , !$enable_smart_threading);
$this->pConfig->set($uid, 'system', 'hide_dislike' , !$enable_dislike);
$this->pConfig->set($uid, 'system', 'display_resharer' , $display_resharer);
$this->pConfig->set($uid, 'system', 'display_sensitive' , $display_sensitive);
$this->pConfig->set($uid, 'system', 'stay_local' , $stay_local);
$this->pConfig->set($uid, 'system', 'show_page_drop' , $show_page_drop);
$this->pConfig->set($uid, 'system', 'display_eventlist' , $display_eventlist);
@ -253,7 +251,6 @@ class Display extends BaseSettings
$enable_smart_threading = !$this->pConfig->get($uid, 'system', 'no_smart_threading', false);
$enable_dislike = !$this->pConfig->get($uid, 'system', 'hide_dislike', false);
$display_resharer = $this->pConfig->get($uid, 'system', 'display_resharer', false);
$display_sensitive = $this->pConfig->get($uid, 'system', 'display_sensitive', false);
$stay_local = $this->pConfig->get($uid, 'system', 'stay_local', false);
$show_page_drop = $this->pConfig->get($uid, 'system', 'show_page_drop', true);
$display_eventlist = $this->pConfig->get($uid, 'system', 'display_eventlist', true);
@ -333,7 +330,6 @@ class Display extends BaseSettings
'$enable_smart_threading' => ['enable_smart_threading' , $this->t('Enable Smart Threading'), $enable_smart_threading, $this->t('Enable the automatic suppression of extraneous thread indentation.')],
'$enable_dislike' => ['enable_dislike' , $this->t('Display the Dislike feature'), $enable_dislike, $this->t('Display the Dislike button and dislike reactions on posts and comments.')],
'$display_resharer' => ['display_resharer' , $this->t('Display the resharer'), $display_resharer, $this->t('Display the first resharer as icon and text on a reshared item.')],
'$display_sensitive' => ['display_sensitive' , $this->t('Display sensitive content'), $display_sensitive, $this->t('If enabled, pictures in posts marked as "sensitive" will not be blurred.')],
'$stay_local' => ['stay_local' , $this->t('Stay local'), $stay_local, $this->t("Don't go to a remote system when following a contact link.")],
'$show_page_drop' => ['show_page_drop' , $this->t('Show the post deletion checkbox'), $show_page_drop, $this->t("Display the checkbox for the post deletion on the network page.")],
'$display_eventlist' => ['display_eventlist' , $this->t('DIsplay the event list'), $display_eventlist, $this->t("Display the birthday reminder and event list on the network page.")],

View file

@ -465,14 +465,6 @@ class Post
list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item, DI::userSession()->getLocalUserId());
if (!empty($item['title'])) {
$title = $item['title'];
} elseif (!empty($item['content-warning']) && DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'disable_cw', false)) {
$title = ucfirst($item['content-warning']);
} else {
$title = '';
}
$hide_dislike = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'hide_dislike');
if ($hide_dislike) {
$buttons['dislike'] = false;
@ -572,7 +564,8 @@ class Post
'thumb' => DI::baseUrl()->remove(DI::contentItem()->getAuthorAvatar($item)),
'osparkle' => $osparkle,
'sparkle' => $sparkle,
'title' => $title,
'title' => $item['title'],
'summary' => $item['content-warning'],
'localtime' => DateTimeFormat::local($item['created'], 'r'),
'ago' => $item['app'] ? DI::l10n()->t('%s from %s', $ago, $item['app']) : $ago,
'app' => $item['app'],

View file

@ -783,3 +783,9 @@ figure.img-allocated-height img{
font-weight: bold;
font-style: italic;
}
summary.wall-item-summary {
font-weight: bold;
font-style: oblique;
padding-bottom: 5px;
}

File diff suppressed because it is too large Load diff

View file

@ -18,7 +18,6 @@
{{include file="field_checkbox.tpl" field=$enable_smart_threading}}
{{include file="field_checkbox.tpl" field=$enable_dislike}}
{{include file="field_checkbox.tpl" field=$display_resharer}}
{{include file="field_checkbox.tpl" field=$display_sensitive}}
{{include file="field_checkbox.tpl" field=$stay_local}}
{{include file="field_checkbox.tpl" field=$show_page_drop}}
{{include file="field_checkbox.tpl" field=$display_eventlist}}

View file

@ -74,6 +74,7 @@
<div itemprop="description" class="wall-item-content">
{{if $item.title}}<h2 dir="auto"><a href="{{$item.plink.href}}" class="{{$item.sparkle}} p-name" dir="auto">{{$item.title}}</a></h2>{{/if}}
{{if $item.summary}}<summary class="wall-item-summary" id="wall-item-summary-{{$item.id}}">{{$item.summary}}</summary>{{/if}}
<div class="wall-item-body e-content {{if !$item.title}}p-name{{/if}}" dir="auto">{{$item.body_html nofilter}}</div>
</div>
</div>

View file

@ -65,7 +65,6 @@
{{include file="field_checkbox.tpl" field=$enable_smart_threading}}
{{include file="field_checkbox.tpl" field=$enable_dislike}}
{{include file="field_checkbox.tpl" field=$display_resharer}}
{{include file="field_checkbox.tpl" field=$display_sensitive}}
{{include file="field_checkbox.tpl" field=$stay_local}}
{{include file="field_checkbox.tpl" field=$show_page_drop}}
{{include file="field_checkbox.tpl" field=$display_eventlist}}

View file

@ -266,7 +266,9 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.title}}
<span class="wall-item-title" id="wall-item-title-{{$item.id}}"><h4 class="media-heading" dir="auto"><a href="{{$item.plink.href}}" class="{{$item.sparkle}} p-name" target="_blank">{{$item.title}}</a></h4><br /></span>
{{/if}}
{{if $item.summary}}
<summary class="wall-item-summary" id="wall-item-summary-{{$item.id}}">{{$item.summary}}</summary>
{{/if}}
<div class="wall-item-body e-content {{if !$item.title}}p-name{{/if}}" id="wall-item-body-{{$item.id}}" dir="auto">{{$item.body_html nofilter}}</div>
</div>