[SensitiveContent] Fix plugin settings

Also reformatted the code and minor bug fixed it
This commit is contained in:
Diogo Cordeiro 2020-04-07 02:02:21 +01:00 committed by Diogo Peralta Cordeiro
parent 7ee8751b8e
commit 617e3af5cd
5 changed files with 460 additions and 415 deletions

View File

@ -1,27 +1,21 @@
# "Sensitive" Content Plugin for GNU Social # "Sensitive" Content Plugin for GNU social
## About ## About
WARNING: THIS IS ALPHA CODE, IT IS PRERELEASE AND SHOULD ONLY BE INSTALLED TO Adds a setting to allow a user to hide #NSFW-hashtagged notices behind a
HELP TEST OR YOU ARE WILLING TO TAKE RISKS.
Create user option to allow a user to hide #NSFW-hashtagged notices behind a
blocker image until clicked. blocker image until clicked.
Works for both vanilla GNUSocial and with the Qvitter plugin. Works for both vanilla GNU social and with the Qvitter plugin.
## Install ## Settings
- Move the project directory to ${GNU_SOCIAL}/plugins If you want to customize the blocker image, add a line to your config.php:
- Add addPlugin('SensitiveContent'); to your config.php
if you want to customize the blocker image, add a line to your config.php: addPlugin('SensitiveContent', ['blockerimage' => '/path/to/image.jpg']);
$config['site']['sensitivecontent']['blockerimage'] = "/path/to/image.jpg";
if you want to activate the nsfw overlay for non-logged-in visitors add: if you want to activate the nsfw overlay for non-logged-in visitors add:
$config['site']['sensitivecontent']['hideforvisitors'] = true; addPlugin('SensitiveContent', ['hideforvisitors' => true]);
## Usage ## Usage
@ -35,7 +29,7 @@ be hidden, it will not apply to notices retroactively unless you clear your brow
## License ## License
GNU Affero License GNU AGPL v3 or later
## Thanks ## Thanks

View File

@ -1,46 +1,119 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
if (!defined('GNUSOCIAL')) { /**
exit(1); * Adds a setting to allow a user to hide #NSFW-hashtagged notices behind a
} * blocker image until clicked.
*
* @package GNUsocial
* @author MoonMan
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
/**
* Class SensitiveContentPlugin
* Handles the main UI stuff
*
* @package GNUsocial
* @author MoonMan
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class SensitiveContentPlugin extends Plugin class SensitiveContentPlugin extends Plugin
{ {
const PLUGIN_VERSION = '0.0.1'; public $blockerimage = 'img/blocker.png';
public $hideforvisitors = false;
const PLUGIN_VERSION = '0.1.0';
public function onPluginVersion(array &$versions): bool public function onPluginVersion(array &$versions): bool
{ {
$versions[] = array('name' => 'Sensitive Content', $versions[] = [
'name' => 'Sensitive Content',
'version' => self::PLUGIN_VERSION, 'version' => self::PLUGIN_VERSION,
'author' => 'MoonMan', 'author' => 'MoonMan',
'homepage' => 'https://gitgud.io/ShitposterClub/SensitiveContent/', 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/SensitiveContent/',
'description' => 'description' => _m('Mark, hide/show sensitive notices like on Twitter.'),
_m('Mark, hide/show sensitive notices like on Twitter.')); ];
return true; return true;
} }
static function settings($setting) /**
* What blocker image to use?
*
* @return string
*/
public function getBlockerImage(): string
{ {
$settings['blockerimage'] = Plugin::staticPath('SensitiveContent', '').'img/blocker.png'; return Plugin::staticPath('SensitiveContent', '') . $this->blockerimage;
$settings['hideforvisitors'] = false;
$configphpsettings = common_config('site','sensitivecontent') ?: array();
foreach($configphpsettings as $configphpsetting=>$value) {
$settings[$configphpsetting] = $value;
} }
if(isset($settings[$setting])) { /**
return $settings[$setting]; * @param $profile
* @return bool
*/
public function shouldHide($profile): bool
{
if (isset($profile) && $profile instanceof Profile) {
return $this->getHideSensitive($profile);
} }
else FALSE; return $this->hideforvisitors;
} }
function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) public function getHideSensitive(Profile $profile): bool
{
$c = Cache::instance();
// if (!empty($c)) {
// $hidesensitive = $c->get(Cache::key('profile:hide_sensitive:'.$profile->id));
// if (is_numeric($hidesensitive)) {
// return (bool) $hidesensitive;
// } else {
// return false;
// }
// }
$hidesensitive = $profile->getPref('MoonMan', 'hide_sensitive', '0');
if (!empty($c)) {
//not using it yet.
$c->set(Cache::key('profile:hide_sensitive:' . $profile->id), $hidesensitive);
}
//common_log(LOG_DEBUG, "SENSITIVECONTENT hidesensitive? id " . $profile->id . " value " . (bool) $hidesensitive );
if (is_null($hidesensitive)) {
return false;
}
if (is_numeric($hidesensitive)) {
return (bool)$hidesensitive;
}
return false;
}
/* GNU social EVENTS */
public function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped)
{ {
$twitter_status['tags'] = $notice->getTags(); $twitter_status['tags'] = $notice->getTags();
} }
function onTwitterUserArray($profile, &$twitter_user, $scoped) public function onTwitterUserArray($profile, &$twitter_user, $scoped)
{ {
if ($scoped instanceof Profile && $scoped->sameAs($profile)) { if ($scoped instanceof Profile && $scoped->sameAs($profile)) {
$twitter_user['hide_sensitive'] = $this->getHideSensitive($scoped); $twitter_user['hide_sensitive'] = $this->getHideSensitive($scoped);
@ -53,8 +126,7 @@ class SensitiveContentPlugin extends Plugin
['action' => 'sensitivecontentsettings']); ['action' => 'sensitivecontentsettings']);
} }
public function onEndAccountSettingsNav($action)
function onEndAccountSettingsNav($action)
{ {
$action->menuItem(common_local_url('sensitivecontentsettings'), $action->menuItem(common_local_url('sensitivecontentsettings'),
_m('MENU', 'Sensitive Content'), _m('MENU', 'Sensitive Content'),
@ -63,12 +135,122 @@ class SensitiveContentPlugin extends Plugin
return true; return true;
} }
public function onEndShowStyles(Action $action)
{
$blocker = $this->getBlockerImage();
$styles = <<<EOB
/* default no show */
html .tagcontainer > footer > .attachments > .inline-attachment > .attachment-wrapper > .sensitive-blocker {
display: none;
}
html[data-hidesensitive='true'] .tagcontainer.data-tag-nsfw > footer > .attachments > .inline-attachment > .attachment-wrapper > .sensitive-blocker {
display: block;
width: 100%;
height: 100%;
position: absolute;
z-index: 100;
/*background-color: #d4baba;*/
background-color: black;
background-image: url({$blocker});
background-repeat: no-repeat;
background-position: center center;
background-size: contain;
transition: opacity 1s ease-in-out;
}
html[data-hidesensitive='true'] .tagcontainer.data-tag-nsfw > footer > .attachments > .inline-attachment > .attachment-wrapper > .sensitive-blocker.reveal {
opacity: 0;
}
EOB;
$action->style($styles);
}
public function onStartShowAttachmentRepresentation($out, $file)
{
$classes = 'sensitive-blocker'; //'sensitive-blocker';
$thumbnail = null;
try {
$thumbnail = $file->getThumbnail();
} catch (Exception $e) {
$thumbnail = null;
}
$thumb_width_css = $thumbnail ? $thumbnail->width . 'px' : '100%';
$thumb_height_css = $thumbnail ? $thumbnail->height . 'px' : '100%';
$out->elementStart('div', [
'class' => 'attachment-wrapper',
'style' => "height: {$thumb_height_css}; width: {$thumb_width_css};",
]); // needs height of thumb
$out->elementStart('div', [
'class' => $classes,
'onclick' => 'toggleSpoiler(event)',
'style' => "height: {$thumb_height_css}; width: {$thumb_width_css};",
]);
$out->raw('&nbsp;');
$out->elementEnd('div');
}
public function onEndShowAttachmentRepresentation($out, $file)
{
$out->elementEnd('div');
}
public function onEndShowScripts(Action $action)
{
$profile = $action->getScoped();
$hidesensitive = $this->shouldHide($profile);
$hidesensitive_string = $hidesensitive ? 'true' : 'false';
$inline = <<<EOB
window.hidesensitive = {$hidesensitive_string};
function toggleSpoiler(evt) {
if (window.hidesensitive) evt.target.classList.toggle('reveal');
}
EOB;
$action->inlineScript($inline);
}
public function onEndOpenNoticeListItemElement(NoticeListItem $nli)
{
$rawtags = $nli->getNotice()->getTags();
$classes = 'tagcontainer';
foreach ($rawtags as $tag) {
$classes = $classes . ' data-tag-' . $tag;
}
$nli->elementStart('span', ['class' => $classes]);
//$nli->elementEnd('span');
}
public function onStartCloseNoticeListItemElement(NoticeListItem $nli)
{
$nli->elementEnd('span');
}
public function onStartHtmlElement($action, &$attrs)
{
$profile = Profile::current();
$hidesensitive = $this->shouldHide($profile);
$attrs = array_merge($attrs,
['data-hidesensitive' => ($hidesensitive ? 'true' : 'false')]
);
}
/* Qvitter's EVENTS */
public function onQvitterEndShowHeadElements(Action $action) public function onQvitterEndShowHeadElements(Action $action)
{ {
$blocker = static::settings('blockerimage'); $blocker = $this->getBlockerImage();
common_log( LOG_DEBUG, "SENSITIVECONTENT " . $blocker ); common_log(LOG_DEBUG, 'SENSITIVECONTENT ' . $blocker);
$styles = <<<EOB $styles = <<<EOB
@ -83,7 +265,7 @@ height: 100%;
position: absolute; position: absolute;
z-index: 100; z-index: 100;
background-color: #d4baba; background-color: #d4baba;
background-image: url($blocker); background-image: url({$blocker});
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: center center; background-position: center center;
background-size: contain; background-size: contain;
@ -105,159 +287,8 @@ EOB;
$action->style($styles); $action->style($styles);
} }
function onQvitterEndShowScripts(Action $action) public function onQvitterEndShowScripts(Action $action)
{ {
$action->script(Plugin::staticPath('SensitiveContent', '') . 'js/sensitivecontent.js'); $action->script(Plugin::staticPath('SensitiveContent', '') . 'js/sensitivecontent.js');
} }
function onEndShowStyles(Action $action)
{
$blocker = static::settings('blockerimage');
$styles = <<<EOB
/* default no show */
html .tagcontainer > footer > .attachments > .inline-attachment > .attachment-wrapper > .sensitive-blocker {
display: none;
}
html[data-hidesensitive='true'] .tagcontainer.data-tag-nsfw > footer > .attachments > .inline-attachment > .attachment-wrapper > .sensitive-blocker {
display: block;
width: 100%;
height: 100%;
position: absolute;
z-index: 100;
/*background-color: #d4baba;*/
background-color: black;
background-image: url($blocker);
background-repeat: no-repeat;
background-position: center center;
background-size: contain;
transition: opacity 1s ease-in-out;
}
html[data-hidesensitive='true'] .tagcontainer.data-tag-nsfw > footer > .attachments > .inline-attachment > .attachment-wrapper > .sensitive-blocker.reveal {
opacity: 0;
}
EOB;
$action->style($styles);
}
function onStartShowAttachmentRepresentation($out, $file)
{
$classes = "sensitive-blocker"; //'sensitive-blocker';
$thumbnail = null;
try {
$thumbnail = $file->getThumbnail();
} catch (Exception $e) {
$thumbnail = null;
}
$thumb_width_css = $thumbnail ? $thumbnail->width . 'px' : '100%';
$thumb_height_css = $thumbnail ? $thumbnail->height . 'px' : '100%';
$out->elementStart('div', array(
'class' => 'attachment-wrapper',
'style' => "height: {$thumb_height_css}; width: {$thumb_width_css};",
)); /*needs height of thumb*/
$out->elementStart('div', array(
'class' => $classes,
'onclick' => 'toggleSpoiler(event)',
'style' => "height: {$thumb_height_css}; width: {$thumb_width_css};",
));
$out->raw('&nbsp;');
$out->elementEnd('div');
}
function onEndShowAttachmentRepresentation($out, $file)
{
$out->elementEnd('div');
}
function onEndShowScripts(Action $action)
{
$profile = $action->getScoped();
$hidesensitive = $this->getHideSetting($profile);
$hidesensitive_string = $hidesensitive ? "true" : "false";
$inline = <<<EOB
window.hidesensitive = $hidesensitive_string;
function toggleSpoiler(evt) {
if (window.hidesensitive) evt.target.classList.toggle('reveal');
}
EOB;
$action->inlineScript($inline);
}
function onEndOpenNoticeListItemElement(NoticeListItem $nli)
{
$rawtags = $nli->getNotice()->getTags();
$classes = "tagcontainer";
foreach($rawtags as $tag)
{
$classes = $classes . ' data-tag-' . $tag;
}
$nli->elementStart('span', array('class' => $classes));
//$nli->elementEnd('span');
}
function onStartCloseNoticeListItemElement(NoticeListItem $nli)
{
$nli->elementEnd('span');
}
function onStartHtmlElement($action, &$attrs) {
$profile = Profile::current();
$hidesensitive = $this->getHideSetting($profile);
$attrs = array_merge($attrs,
array('data-hidesensitive' => ($hidesensitive ? "true" : "false"))
);
}
function getHideSetting($profile) {
if (isset($profile) && $profile instanceof Profile) {
return $this->getHideSensitive($profile);
} else {
return static::settings('hideforvisitors');
}
}
function getHideSensitive($profile) {
$c = Cache::instance();
/*
if (!empty($c)) {
$hidesensitive = $c->get(Cache::key('profile:hide_sensitive:'.$profile->id));
if (is_numeric($hidesensitive)) {
return (boolean) $hidesensitive;
}
else return FALSE;
}
*/
$hidesensitive = $profile->getPref('MoonMan', 'hide_sensitive', '0');
if (!empty($c)) {
//not using it yet.
$c->set(Cache::key('profile:hide_sensitive:'.$profile->id), $hidesensitive);
}
//common_log(LOG_DEBUG, "SENSITIVECONTENT hidesensitive? id " . $profile->id . " value " . (boolean)$hidesensitive );
if (is_null($hidesensitive)) {
return FALSE;
} else
if (is_numeric($hidesensitive)) {
return (boolean) $hidesensitive;
}
else return FALSE;
}
} }

View File

@ -14,8 +14,27 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* Adds a setting to allow a user to hide #NSFW-hashtagged notices behind a
* blocker image until clicked.
*
* @package GNUsocial
* @author MoonMan
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die(); defined('GNUSOCIAL') || die();
/**
* Class SensitiveContentSettingsAction
* Handles the settings action for this plugin
*
* @package GNUsocial
* @author MoonMan
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class SensitiveContentSettingsAction extends SettingsAction class SensitiveContentSettingsAction extends SettingsAction
{ {
public function title() public function title()
@ -55,7 +74,6 @@ class SensitiveContentSettingsAction extends SettingsAction
); );
$this->elementEnd('li'); $this->elementEnd('li');
$this->elementEnd('ul'); $this->elementEnd('ul');
$this->submit('save', _m('BUTTON', 'Save')); $this->submit('save', _m('BUTTON', 'Save'));
@ -67,6 +85,6 @@ class SensitiveContentSettingsAction extends SettingsAction
{ {
$hidesensitive = $this->boolean('hidesensitive') ? '1' : '0'; $hidesensitive = $this->boolean('hidesensitive') ? '1' : '0';
$this->scoped->setPref('MoonMan', 'hide_sensitive', $hidesensitive); $this->scoped->setPref('MoonMan', 'hide_sensitive', $hidesensitive);
return _('Settings saved.'); return _m('Settings saved.');
} }
} }

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-14 14:51+0100\n" "POT-Creation-Date: 2020-04-07 01:53+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,28 +17,32 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: SensitiveContentPlugin.php:18 #: SensitiveContentPlugin.php:53
msgid "Mark, hide/show sensitive notices like on Twitter." msgid "Mark, hide/show sensitive notices like on Twitter."
msgstr "" msgstr ""
#: SensitiveContentPlugin.php:59 #: SensitiveContentPlugin.php:135
msgctxt "MENU" msgctxt "MENU"
msgid "Sensitive Content" msgid "Sensitive Content"
msgstr "" msgstr ""
#: SensitiveContentPlugin.php:60 #: SensitiveContentPlugin.php:136
msgid "Settings for display of sensitive content." msgid "Settings for display of sensitive content."
msgstr "" msgstr ""
#: actions/sensitivecontentsettings.php:9 #: actions/sensitivecontentsettings.php:44
msgid "Sensitive content settings" msgid "Sensitive content settings"
msgstr "" msgstr ""
#: actions/sensitivecontentsettings.php:14 #: actions/sensitivecontentsettings.php:49
msgid "Set preferences for display of \"sensitive\" content" msgid "Set preferences for display of \"sensitive\" content"
msgstr "" msgstr ""
#: actions/sensitivecontentsettings.php:39 #: actions/sensitivecontentsettings.php:80
msgctxt "BUTTON" msgctxt "BUTTON"
msgid "Save" msgid "Save"
msgstr "" msgstr ""
#: actions/sensitivecontentsettings.php:90
msgid "Settings saved."
msgstr ""

View File

@ -1,24 +1,24 @@
window.buildAttachmentHTML = function (attachments) { window.buildAttachmentHTML = function (attachments) {
var attachmentHTML = ''; let attachmentHTML = '';
var oembedHTML = ''; let oembedHTML = '';
var quotedNotices = []; const quotedNotices = [];
var attachmentNum = 0; let attachmentNum = 0;
var oembedNum = 0; let oembedNum = 0;
var urlsToHide = []; const urlsToHide = [];
if (typeof attachments != "undefined") { if (typeof attachments != "undefined") {
$.each(attachments, function () { $.each(attachments, function () {
// quoted notices // quoted notices
if (typeof this.quoted_notice != 'undefined') { if (typeof this.quoted_notice != 'undefined') {
var quotedContent = this.quoted_notice.content; let quotedContent = this.quoted_notice.content;
// quoted notice's attachments' thumb urls // quoted notice's attachments' thumb urls
var quotedAttachmentsHTML = ''; let quotedAttachmentsHTML = '';
var quotedAttachmentsHTMLbefore = ''; let quotedAttachmentsHTMLbefore = '';
var quotedAttachmentsHTMLafter = ''; let quotedAttachmentsHTMLafter = '';
if (typeof this.quoted_notice.attachments != 'undefined' && this.quoted_notice.attachments.length > 0) { if (typeof this.quoted_notice.attachments != 'undefined' && this.quoted_notice.attachments.length > 0) {
quotedAttachmentsHTML += '<div class="quoted-notice-attachments quoted-notice-attachments-num-' + this.quoted_notice.attachments.length + '">' quotedAttachmentsHTML += '<div class="quoted-notice-attachments quoted-notice-attachments-num-' + this.quoted_notice.attachments.length + '">';
$.each(this.quoted_notice.attachments, function (k, qAttach) { $.each(this.quoted_notice.attachments, function (k, qAttach) {
quotedAttachmentsHTML += '<div class="quoted-notice-img-container" style="background-image:url(\'' + qAttach.thumb_url + '\')"><img class="quoted-notice-img" src="' + qAttach.thumb_url + '" /></div>'; quotedAttachmentsHTML += '<div class="quoted-notice-img-container" style="background-image:url(\'' + qAttach.thumb_url + '\')"><img class="quoted-notice-img" src="' + qAttach.thumb_url + '" /></div>';
// remove attachment string from content // remove attachment string from content
@ -29,13 +29,12 @@ window.buildAttachmentHTML = function(attachments){
// if there is only one attachment, it goes before, otherwise after // if there is only one attachment, it goes before, otherwise after
if (this.quoted_notice.attachments.length == 1) { if (this.quoted_notice.attachments.length == 1) {
quotedAttachmentsHTMLbefore = quotedAttachmentsHTML; quotedAttachmentsHTMLbefore = quotedAttachmentsHTML;
} } else {
else {
quotedAttachmentsHTMLafter = quotedAttachmentsHTML; quotedAttachmentsHTMLafter = quotedAttachmentsHTML;
} }
} }
var quotedNoticeHTML = quotedAttachmentsHTMLbefore + '\ const quotedNoticeHTML = quotedAttachmentsHTMLbefore + '\
<div class="quoted-notice-header">\ <div class="quoted-notice-header">\
<span class="quoted-notice-author-fullname">' + this.quoted_notice.fullname + '</span>\ <span class="quoted-notice-author-fullname">' + this.quoted_notice.fullname + '</span>\
<span class="quoted-notice-author-nickname">' + this.quoted_notice.nickname + '</span>\ <span class="quoted-notice-author-nickname">' + this.quoted_notice.nickname + '</span>\
@ -56,7 +55,7 @@ window.buildAttachmentHTML = function(attachments){
&& this.oembed !== false && this.oembed !== false
&& this.oembed.provider == 'Twitter') { && this.oembed.provider == 'Twitter') {
var twitterHTML = '<div class="oembed-item-header">\ const twitterHTML = '<div class="oembed-item-header">\
<span class="oembed-item-title">' + this.oembed.author_name + '</span>\ <span class="oembed-item-title">' + this.oembed.author_name + '</span>\
<span class="oembed-username">' + this.oembed.title + '</span>\ <span class="oembed-username">' + this.oembed.title + '</span>\
</div>\ </div>\
@ -79,7 +78,7 @@ window.buildAttachmentHTML = function(attachments){
&& this.oembed.provider != 'Vimeo' && this.oembed.provider != 'Vimeo'
&& this.oembed.type != 'photo') { && this.oembed.type != 'photo') {
var oembedImage = ''; let oembedImage = '';
// only local images // only local images
if (typeof this.thumb_url != 'undefined' if (typeof this.thumb_url != 'undefined'
&& this.thumb_url !== null && this.thumb_url !== null
@ -87,7 +86,7 @@ window.buildAttachmentHTML = function(attachments){
oembedImage = '<div class="oembed-img-container" style="background-image:url(\'' + this.thumb_url + '\')"><img class="oembed-img" src="' + this.thumb_url + '" /></div>'; oembedImage = '<div class="oembed-img-container" style="background-image:url(\'' + this.thumb_url + '\')"><img class="oembed-img" src="' + this.thumb_url + '" /></div>';
} }
var oembedBody = ''; let oembedBody = '';
// don't add body if html it's too similar (80%) to the title (wordpress does this..) // don't add body if html it's too similar (80%) to the title (wordpress does this..)
if (this.oembed.oembedHTML !== null if (this.oembed.oembedHTML !== null
@ -103,8 +102,7 @@ window.buildAttachmentHTML = function(attachments){
if (this.oembed.provider === null) { if (this.oembed.provider === null) {
var oembedProvider = this.url; var oembedProvider = this.url;
var oembedProviderURL = ''; var oembedProviderURL = '';
} } else {
else {
var oembedProvider = this.oembed.provider; var oembedProvider = this.oembed.provider;
var oembedProviderURL = removeProtocolFromUrl(this.oembed.provider_url); var oembedProviderURL = removeProtocolFromUrl(this.oembed.provider_url);
// remove trailing / // remove trailing /
@ -114,12 +112,12 @@ window.buildAttachmentHTML = function(attachments){
} }
// If the oembed data is generated by Qvitter, we know a better way of showing the title // If the oembed data is generated by Qvitter, we know a better way of showing the title
var oembedTitle = this.oembed.title; const oembedTitle = this.oembed.title;
var oembedTitleHTML = '<span class="oembed-item-title">' + oembedTitle + '</span>'; let oembedTitleHTML = '<span class="oembed-item-title">' + oembedTitle + '</span>';
if (oembedTitle.slice(-10) == ' (Qvitter)') { if (oembedTitle.slice(-10) == ' (Qvitter)') {
var oembedTimePosted = parseTwitterLongDate(oembedTitle.slice(0,-10)); const oembedTimePosted = parseTwitterLongDate(oembedTitle.slice(0, -10));
var oembedGNUsocialUsername = this.oembed.author_name.substring(this.oembed.author_name.lastIndexOf('(')+1,this.oembed.author_name.lastIndexOf(')')); const oembedGNUsocialUsername = this.oembed.author_name.substring(this.oembed.author_name.lastIndexOf('(') + 1, this.oembed.author_name.lastIndexOf(')'));
var oembedGNUsocialFullname = this.oembed.author_name.slice(0,-(oembedGNUsocialUsername.length+3)); const oembedGNUsocialFullname = this.oembed.author_name.slice(0, -(oembedGNUsocialUsername.length + 3));
oembedTitleHTML = '<span class="oembed-item-title">' + oembedGNUsocialFullname + '</span>\ oembedTitleHTML = '<span class="oembed-item-title">' + oembedGNUsocialFullname + '</span>\
<span class="oembed-username">@' + oembedGNUsocialUsername + '</span>'; <span class="oembed-username">@' + oembedGNUsocialUsername + '</span>';
} }
@ -142,8 +140,8 @@ window.buildAttachmentHTML = function(attachments){
else if (typeof this.thumb_url != 'undefined' else if (typeof this.thumb_url != 'undefined'
&& this.thumb_url !== null && this.thumb_url !== null
&& isLocalURL(this.thumb_url)) { && isLocalURL(this.thumb_url)) {
var bigThumbW = 1000; let bigThumbW = 1000;
var bigThumbH = 3000; let bigThumbH = 3000;
if (bigThumbW > window.siteMaxThumbnailSize) { if (bigThumbW > window.siteMaxThumbnailSize) {
bigThumbW = window.siteMaxThumbnailSize; bigThumbW = window.siteMaxThumbnailSize;
} }
@ -152,13 +150,13 @@ window.buildAttachmentHTML = function(attachments){
} }
// very long landscape images should not have background-size:cover // very long landscape images should not have background-size:cover
var noCoverClass=''; let noCoverClass = '';
if (this.width / this.height > 2) { if (this.width / this.height > 2) {
noCoverClass = ' no-cover'; noCoverClass = ' no-cover';
} }
// play button for videos and animated gifs // play button for videos and animated gifs
var playButtonClass = ''; let playButtonClass = '';
if (typeof this.animated != 'undefined' && this.animated === true if (typeof this.animated != 'undefined' && this.animated === true
|| (this.url.indexOf('://www.youtube.com') > -1 || this.url.indexOf('://youtu.be') > -1) || (this.url.indexOf('://www.youtube.com') > -1 || this.url.indexOf('://youtu.be') > -1)
|| this.url.indexOf('://vimeo.com') > -1) { || this.url.indexOf('://vimeo.com') > -1) {
@ -197,8 +195,7 @@ window.buildAttachmentHTML = function(attachments){
attachmentHTML += '<a data-local-attachment-url="' + urlToHide + '" style="background-image:url(\'' + img_url + '\')" class="thumb-container' + noCoverClass + playButtonClass + animatedGifClass + ' ' + CSSclassNameByHostFromURL(this.url) + '" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + img_url + '"/ data-width="' + this.width + '" data-height="' + this.height + '" data-full-image-url="' + this.url + '" data-thumb-url="' + img_url + '"></a>'; attachmentHTML += '<a data-local-attachment-url="' + urlToHide + '" style="background-image:url(\'' + img_url + '\')" class="thumb-container' + noCoverClass + playButtonClass + animatedGifClass + ' ' + CSSclassNameByHostFromURL(this.url) + '" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + img_url + '"/ data-width="' + this.width + '" data-height="' + this.height + '" data-full-image-url="' + this.url + '" data-thumb-url="' + img_url + '"></a>';
urlsToHide.push(urlToHide); // hide this attachment url from the queet text urlsToHide.push(urlToHide); // hide this attachment url from the queet text
attachmentNum++; attachmentNum++;
} } else if (this.mimetype == 'image/svg+xml') {
else if (this.mimetype == 'image/svg+xml') {
var urlToHide = window.siteInstanceURL + 'attachment/' + this.id; var urlToHide = window.siteInstanceURL + 'attachment/' + this.id;
attachmentHTML += '<a data-local-attachment-url="' + urlToHide + '" style="background-image:url(\'' + this.url + '\')" class="thumb-container" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + this.url + '"/></a>'; attachmentHTML += '<a data-local-attachment-url="' + urlToHide + '" style="background-image:url(\'' + this.url + '\')" class="thumb-container" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + this.url + '"/></a>';
urlsToHide.push(urlToHide); // hide this attachment url from the queet text urlsToHide.push(urlToHide); // hide this attachment url from the queet text
@ -206,11 +203,12 @@ window.buildAttachmentHTML = function(attachments){
} }
}); });
} }
return { html: '<div class="oembed-data oembed-num-' + oembedNum + '">' + oembedHTML + '</div><div class="queet-thumbs thumb-num-' + attachmentNum + '"><div class="sensitive-blocker">&nbsp;</div>' + attachmentHTML + '</div>', return {
html: '<div class="oembed-data oembed-num-' + oembedNum + '">' + oembedHTML + '</div><div class="queet-thumbs thumb-num-' + attachmentNum + '"><div class="sensitive-blocker">&nbsp;</div>' + attachmentHTML + '</div>',
urlsToHide: urlsToHide, urlsToHide: urlsToHide,
quotedNotices: quotedNotices quotedNotices: quotedNotices
}; };
} };
window.sensitiveContentOriginalBuildQueetHtml = window.buildQueetHtml; window.sensitiveContentOriginalBuildQueetHtml = window.buildQueetHtml;
@ -218,11 +216,11 @@ window.sensitiveContentOriginalBuildQueetHtml = window.buildQueetHtml;
window.buildQueetHtml = function (obj, idInStream, extraClasses, requeeted_by, isConversation) { window.buildQueetHtml = function (obj, idInStream, extraClasses, requeeted_by, isConversation) {
//add tags to json if they don't exit //add tags to json if they don't exit
if (obj.tags && obj.tags.length > 0) { if (obj.tags && obj.tags.length > 0) {
for (var tagI = 0; tagI < obj.tags.length; ++tagI) { for (let tagI = 0; tagI < obj.tags.length; ++tagI) {
extraClasses += (' data-tag-' + obj.tags[tagI]); extraClasses += (' data-tag-' + obj.tags[tagI]);
if (window.loggedIn.hide_sensitive && obj.tags[tagI] === 'nsfw') extraClasses += ' sensitive-notice'; if (window.loggedIn.hide_sensitive && obj.tags[tagI] === 'nsfw') extraClasses += ' sensitive-notice';
} }
} }
return window.sensitiveContentOriginalBuildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversation); return window.sensitiveContentOriginalBuildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversation);
} };