From 617e3af5cd8844cd080408e84c82d7d446c42cab Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Tue, 7 Apr 2020 02:02:21 +0100 Subject: [PATCH] [SensitiveContent] Fix plugin settings Also reformatted the code and minor bug fixed it --- plugins/SensitiveContent/README.md | 22 +- .../SensitiveContentPlugin.php | 455 ++++++++++-------- .../actions/sensitivecontentsettings.php | 28 +- .../locale/SensitiveContent.pot | 18 +- .../SensitiveContent/js/sensitivecontent.js | 352 +++++++------- 5 files changed, 460 insertions(+), 415 deletions(-) diff --git a/plugins/SensitiveContent/README.md b/plugins/SensitiveContent/README.md index 1949bd18b9..2000ecfca5 100644 --- a/plugins/SensitiveContent/README.md +++ b/plugins/SensitiveContent/README.md @@ -1,27 +1,21 @@ -# "Sensitive" Content Plugin for GNU Social +# "Sensitive" Content Plugin for GNU social ## About -WARNING: THIS IS ALPHA CODE, IT IS PRERELEASE AND SHOULD ONLY BE INSTALLED TO -HELP TEST OR YOU ARE WILLING TO TAKE RISKS. - -Create user option to allow a user to hide #NSFW-hashtagged notices behind a +Adds a setting to allow a user to hide #NSFW-hashtagged notices behind a 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 -- Add addPlugin('SensitiveContent'); to your config.php +If you want to customize the blocker image, add a line to your config.php: -if you want to customize the blocker image, add a line to your config.php: - - $config['site']['sensitivecontent']['blockerimage'] = "/path/to/image.jpg"; + addPlugin('SensitiveContent', ['blockerimage' => '/path/to/image.jpg']); if you want to activate the nsfw overlay for non-logged-in visitors add: - $config['site']['sensitivecontent']['hideforvisitors'] = true; + addPlugin('SensitiveContent', ['hideforvisitors' => true]); ## Usage @@ -35,7 +29,7 @@ be hidden, it will not apply to notices retroactively unless you clear your brow ## License -GNU Affero License +GNU AGPL v3 or later ## Thanks diff --git a/plugins/SensitiveContent/SensitiveContentPlugin.php b/plugins/SensitiveContent/SensitiveContentPlugin.php index 36a6285aa5..5dce37d414 100644 --- a/plugins/SensitiveContent/SensitiveContentPlugin.php +++ b/plugins/SensitiveContent/SensitiveContentPlugin.php @@ -1,76 +1,258 @@ . -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 { - 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 - { - $versions[] = array('name' => 'Sensitive Content', - 'version' => self::PLUGIN_VERSION, - 'author' => 'MoonMan', - 'homepage' => 'https://gitgud.io/ShitposterClub/SensitiveContent/', - 'description' => - _m('Mark, hide/show sensitive notices like on Twitter.')); - return true; - } + public function onPluginVersion(array &$versions): bool + { + $versions[] = [ + 'name' => 'Sensitive Content', + 'version' => self::PLUGIN_VERSION, + 'author' => 'MoonMan', + 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/SensitiveContent/', + 'description' => _m('Mark, hide/show sensitive notices like on Twitter.'), + ]; + return true; + } - static function settings($setting) - { - $settings['blockerimage'] = Plugin::staticPath('SensitiveContent', '').'img/blocker.png'; - $settings['hideforvisitors'] = false; + /** + * What blocker image to use? + * + * @return string + */ + public function getBlockerImage(): string + { + return Plugin::staticPath('SensitiveContent', '') . $this->blockerimage; + } - $configphpsettings = common_config('site','sensitivecontent') ?: array(); - foreach($configphpsettings as $configphpsetting=>$value) { - $settings[$configphpsetting] = $value; - } + /** + * @param $profile + * @return bool + */ + public function shouldHide($profile): bool + { + if (isset($profile) && $profile instanceof Profile) { + return $this->getHideSensitive($profile); + } + return $this->hideforvisitors; + } - if(isset($settings[$setting])) { - return $settings[$setting]; - } - else FALSE; - } + public function getHideSensitive(Profile $profile): bool + { + $c = Cache::instance(); - function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) - { - $twitter_status['tags'] = $notice->getTags(); - } + // if (!empty($c)) { + // $hidesensitive = $c->get(Cache::key('profile:hide_sensitive:'.$profile->id)); + // if (is_numeric($hidesensitive)) { + // return (bool) $hidesensitive; + // } else { + // return false; + // } + // } - function onTwitterUserArray($profile, &$twitter_user, $scoped) - { - if ($scoped instanceof Profile && $scoped->sameAs($profile)) { - $twitter_user['hide_sensitive'] = $this->getHideSensitive($scoped); - } - } + $hidesensitive = $profile->getPref('MoonMan', 'hide_sensitive', '0'); - public function onRouterInitialized(URLMapper $m) - { - $m->connect('settings/sensitivecontent', - ['action' => 'sensitivecontentsettings']); - } + 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 ); - function onEndAccountSettingsNav($action) - { - $action->menuItem(common_local_url('sensitivecontentsettings'), - _m('MENU', 'Sensitive Content'), - _m('Settings for display of sensitive content.')); + if (is_null($hidesensitive)) { + return false; + } + if (is_numeric($hidesensitive)) { + return (bool)$hidesensitive; + } + return false; + } - return true; - } + /* GNU social EVENTS */ + public function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) + { + $twitter_status['tags'] = $notice->getTags(); + } - public function onQvitterEndShowHeadElements(Action $action) - { - $blocker = static::settings('blockerimage'); - common_log( LOG_DEBUG, "SENSITIVECONTENT " . $blocker ); + public function onTwitterUserArray($profile, &$twitter_user, $scoped) + { + if ($scoped instanceof Profile && $scoped->sameAs($profile)) { + $twitter_user['hide_sensitive'] = $this->getHideSensitive($scoped); + } + } + public function onRouterInitialized(URLMapper $m) + { + $m->connect('settings/sensitivecontent', + ['action' => 'sensitivecontentsettings']); + } - $styles = <<menuItem(common_local_url('sensitivecontentsettings'), + _m('MENU', 'Sensitive Content'), + _m('Settings for display of sensitive content.')); + + return true; + } + + public function onEndShowStyles(Action $action) + { + $blocker = $this->getBlockerImage(); + + $styles = << 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(' '); + $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 = <<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) + { + $blocker = $this->getBlockerImage(); + common_log(LOG_DEBUG, 'SENSITIVECONTENT ' . $blocker); + + $styles = <<style($styles); - } - - function onQvitterEndShowScripts(Action $action) - { - $action->script( Plugin::staticPath('SensitiveContent', '').'js/sensitivecontent.js' ); - } - - function onEndShowStyles(Action $action) - { - $blocker = static::settings('blockerimage'); - - $styles = << 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(' '); - $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 = <<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; - } + $action->style($styles); + } + public function onQvitterEndShowScripts(Action $action) + { + $action->script(Plugin::staticPath('SensitiveContent', '') . 'js/sensitivecontent.js'); + } } diff --git a/plugins/SensitiveContent/actions/sensitivecontentsettings.php b/plugins/SensitiveContent/actions/sensitivecontentsettings.php index 0c7171bc0a..2db5494dbe 100644 --- a/plugins/SensitiveContent/actions/sensitivecontentsettings.php +++ b/plugins/SensitiveContent/actions/sensitivecontentsettings.php @@ -14,8 +14,27 @@ // You should have received a copy of the GNU Affero General Public License // along with GNU social. If not, see . +/** + * 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 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 { public function title() @@ -36,8 +55,8 @@ class SensitiveContentSettingsAction extends SettingsAction 'form', [ 'method' => 'post', - 'id' => 'sensitivecontent', - 'class' => 'form_settings', + 'id' => 'sensitivecontent', + 'class' => 'form_settings', 'action' => common_local_url('sensitivecontentsettings'), ] ); @@ -51,11 +70,10 @@ class SensitiveContentSettingsAction extends SettingsAction 'hidesensitive', _('Hide attachments in posts hashtagged #NSFW'), ($this->arg('hidesensitive') ? - $this->boolean('hidesensitive') : $this->scoped->getPref('MoonMan', 'hide_sensitive', 0)) + $this->boolean('hidesensitive') : $this->scoped->getPref('MoonMan', 'hide_sensitive', 0)) ); $this->elementEnd('li'); - $this->elementEnd('ul'); $this->submit('save', _m('BUTTON', 'Save')); @@ -67,6 +85,6 @@ class SensitiveContentSettingsAction extends SettingsAction { $hidesensitive = $this->boolean('hidesensitive') ? '1' : '0'; $this->scoped->setPref('MoonMan', 'hide_sensitive', $hidesensitive); - return _('Settings saved.'); + return _m('Settings saved.'); } } diff --git a/plugins/SensitiveContent/locale/SensitiveContent.pot b/plugins/SensitiveContent/locale/SensitiveContent.pot index bf19b2ebd0..49fc2e21ac 100644 --- a/plugins/SensitiveContent/locale/SensitiveContent.pot +++ b/plugins/SensitiveContent/locale/SensitiveContent.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,28 +17,32 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: SensitiveContentPlugin.php:18 +#: SensitiveContentPlugin.php:53 msgid "Mark, hide/show sensitive notices like on Twitter." msgstr "" -#: SensitiveContentPlugin.php:59 +#: SensitiveContentPlugin.php:135 msgctxt "MENU" msgid "Sensitive Content" msgstr "" -#: SensitiveContentPlugin.php:60 +#: SensitiveContentPlugin.php:136 msgid "Settings for display of sensitive content." msgstr "" -#: actions/sensitivecontentsettings.php:9 +#: actions/sensitivecontentsettings.php:44 msgid "Sensitive content settings" msgstr "" -#: actions/sensitivecontentsettings.php:14 +#: actions/sensitivecontentsettings.php:49 msgid "Set preferences for display of \"sensitive\" content" msgstr "" -#: actions/sensitivecontentsettings.php:39 +#: actions/sensitivecontentsettings.php:80 msgctxt "BUTTON" msgid "Save" msgstr "" + +#: actions/sensitivecontentsettings.php:90 +msgid "Settings saved." +msgstr "" diff --git a/public/plugins/SensitiveContent/js/sensitivecontent.js b/public/plugins/SensitiveContent/js/sensitivecontent.js index 3c9d6584fd..878c4d25bb 100644 --- a/public/plugins/SensitiveContent/js/sensitivecontent.js +++ b/public/plugins/SensitiveContent/js/sensitivecontent.js @@ -1,41 +1,40 @@ -window.buildAttachmentHTML = function(attachments){ - var attachmentHTML = ''; - var oembedHTML = ''; - var quotedNotices = []; - var attachmentNum = 0; - var oembedNum = 0; - var urlsToHide = []; - if(typeof attachments != "undefined") { - $.each(attachments, function(){ +window.buildAttachmentHTML = function (attachments) { + let attachmentHTML = ''; + let oembedHTML = ''; + const quotedNotices = []; + let attachmentNum = 0; + let oembedNum = 0; + const urlsToHide = []; + if (typeof attachments != "undefined") { + $.each(attachments, function () { - // quoted notices - if(typeof this.quoted_notice != 'undefined') { + // quoted notices + if (typeof this.quoted_notice != 'undefined') { - var quotedContent = this.quoted_notice.content; + let quotedContent = this.quoted_notice.content; - // quoted notice's attachments' thumb urls - var quotedAttachmentsHTML = ''; - var quotedAttachmentsHTMLbefore = ''; - var quotedAttachmentsHTMLafter = ''; - if(typeof this.quoted_notice.attachments != 'undefined' && this.quoted_notice.attachments.length > 0) { - quotedAttachmentsHTML += '
' - $.each(this.quoted_notice.attachments,function(k,qAttach){ - quotedAttachmentsHTML += '
'; - // remove attachment string from content - quotedContent = quotedContent.split(window.siteInstanceURL + 'attachment/' + qAttach.attachment_id).join(''); - }); - quotedAttachmentsHTML += '
'; + // quoted notice's attachments' thumb urls + let quotedAttachmentsHTML = ''; + let quotedAttachmentsHTMLbefore = ''; + let quotedAttachmentsHTMLafter = ''; + if (typeof this.quoted_notice.attachments != 'undefined' && this.quoted_notice.attachments.length > 0) { + quotedAttachmentsHTML += '
'; + $.each(this.quoted_notice.attachments, function (k, qAttach) { + quotedAttachmentsHTML += '
'; + // remove attachment string from content + quotedContent = quotedContent.split(window.siteInstanceURL + 'attachment/' + qAttach.attachment_id).join(''); + }); + quotedAttachmentsHTML += '
'; - // if there is only one attachment, it goes before, otherwise after - if(this.quoted_notice.attachments.length == 1) { - quotedAttachmentsHTMLbefore = quotedAttachmentsHTML; - } - else { - quotedAttachmentsHTMLafter = quotedAttachmentsHTML; - } - } + // if there is only one attachment, it goes before, otherwise after + if (this.quoted_notice.attachments.length == 1) { + quotedAttachmentsHTMLbefore = quotedAttachmentsHTML; + } else { + quotedAttachmentsHTMLafter = quotedAttachmentsHTML; + } + } - var quotedNoticeHTML = quotedAttachmentsHTMLbefore + '\ + const quotedNoticeHTML = quotedAttachmentsHTMLbefore + '\
\ ' + this.quoted_notice.fullname + '\ ' + this.quoted_notice.nickname + '\ @@ -43,20 +42,20 @@ window.buildAttachmentHTML = function(attachments){
' + $.trim(quotedContent) + '
\ ' + quotedAttachmentsHTMLafter; - quotedNotices.push({ - url: this.url, - html: quotedNoticeHTML, - href: window.siteInstanceURL + 'notice/' + this.quoted_notice.id, - class:'quoted-notice' - }); - } + quotedNotices.push({ + url: this.url, + html: quotedNoticeHTML, + href: window.siteInstanceURL + 'notice/' + this.quoted_notice.id, + class: 'quoted-notice' + }); + } - // if we have Twitter oembed data, we add is as quotes - else if(typeof this.oembed != 'undefined' - && this.oembed !== false - && this.oembed.provider == 'Twitter') { + // if we have Twitter oembed data, we add is as quotes + else if (typeof this.oembed != 'undefined' + && this.oembed !== false + && this.oembed.provider == 'Twitter') { - var twitterHTML = '
\ + const twitterHTML = '
\ ' + this.oembed.author_name + '\ ' + this.oembed.title + '\
\ @@ -64,68 +63,67 @@ window.buildAttachmentHTML = function(attachments){ '; - quotedNotices.push({ - url: this.url, - html: twitterHTML, - href: this.url, - class:'oembed-item' - }); - } - // if we have other oembed data (but not for photos and youtube, we handle those later) - else if(typeof this.oembed != 'undefined' - && this.oembed !== false - && this.oembed.title !== null - && this.oembed.provider != 'YouTube' - && this.oembed.provider != 'Vimeo' - && this.oembed.type != 'photo') { + quotedNotices.push({ + url: this.url, + html: twitterHTML, + href: this.url, + class: 'oembed-item' + }); + } + // if we have other oembed data (but not for photos and youtube, we handle those later) + else if (typeof this.oembed != 'undefined' + && this.oembed !== false + && this.oembed.title !== null + && this.oembed.provider != 'YouTube' + && this.oembed.provider != 'Vimeo' + && this.oembed.type != 'photo') { - var oembedImage = ''; - // only local images - if(typeof this.thumb_url != 'undefined' - && this.thumb_url !== null - && isLocalURL(this.thumb_url)) { - oembedImage = '
'; - } + let oembedImage = ''; + // only local images + if (typeof this.thumb_url != 'undefined' + && this.thumb_url !== null + && isLocalURL(this.thumb_url)) { + oembedImage = '
'; + } - var oembedBody = ''; + let oembedBody = ''; - // don't add body if html it's too similar (80%) to the title (wordpress does this..) - if(this.oembed.oembedHTML !== null - && this.oembed.oembedHTML.length > 0) { - if(this.oembed.oembedHTML.length > 200) { - this.oembed.oembedHTML = this.oembed.oembedHTML.substring(0,200) + '…'; - } - if(stringSimilarity(this.oembed.oembedHTML,this.oembed.title.substring(0,200)) < 80) { - oembedBody = this.oembed.oembedHTML; - } - } + // don't add body if html it's too similar (80%) to the title (wordpress does this..) + if (this.oembed.oembedHTML !== null + && this.oembed.oembedHTML.length > 0) { + if (this.oembed.oembedHTML.length > 200) { + this.oembed.oembedHTML = this.oembed.oembedHTML.substring(0, 200) + '…'; + } + if (stringSimilarity(this.oembed.oembedHTML, this.oembed.title.substring(0, 200)) < 80) { + oembedBody = this.oembed.oembedHTML; + } + } - if(this.oembed.provider === null) { - var oembedProvider = this.url; - var oembedProviderURL = ''; - } - else { - var oembedProvider = this.oembed.provider; - var oembedProviderURL = removeProtocolFromUrl(this.oembed.provider_url); - // remove trailing / - if(oembedProviderURL.slice(-1) == '/') { - oembedProviderURL = oembedProviderURL.slice(0,-1); - } - } + if (this.oembed.provider === null) { + var oembedProvider = this.url; + var oembedProviderURL = ''; + } else { + var oembedProvider = this.oembed.provider; + var oembedProviderURL = removeProtocolFromUrl(this.oembed.provider_url); + // remove trailing / + if (oembedProviderURL.slice(-1) == '/') { + oembedProviderURL = oembedProviderURL.slice(0, -1); + } + } - // If the oembed data is generated by Qvitter, we know a better way of showing the title - var oembedTitle = this.oembed.title; - var oembedTitleHTML = '' + oembedTitle + ''; - if(oembedTitle.slice(-10) == ' (Qvitter)') { - var oembedTimePosted = parseTwitterLongDate(oembedTitle.slice(0,-10)); - var 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)); - oembedTitleHTML = '' + oembedGNUsocialFullname + '\ + // If the oembed data is generated by Qvitter, we know a better way of showing the title + const oembedTitle = this.oembed.title; + let oembedTitleHTML = '' + oembedTitle + ''; + if (oembedTitle.slice(-10) == ' (Qvitter)') { + const oembedTimePosted = parseTwitterLongDate(oembedTitle.slice(0, -10)); + const oembedGNUsocialUsername = this.oembed.author_name.substring(this.oembed.author_name.lastIndexOf('(') + 1, this.oembed.author_name.lastIndexOf(')')); + const oembedGNUsocialFullname = this.oembed.author_name.slice(0, -(oembedGNUsocialUsername.length + 3)); + oembedTitleHTML = '' + oembedGNUsocialFullname + '\ @' + oembedGNUsocialUsername + ''; - } + } - oembedHTML += '\ + oembedHTML += '\ ' + oembedImage + '\
\ ' + oembedTitleHTML + '\ @@ -136,93 +134,93 @@ window.buildAttachmentHTML = function(attachments){ ' + oembedProviderURL + '\
\
'; - oembedNum++; - } - // if there's a local thumb_url we assume this is a image or video - else if(typeof this.thumb_url != 'undefined' - && this.thumb_url !== null - && isLocalURL(this.thumb_url)) { - var bigThumbW = 1000; - var bigThumbH = 3000; - if(bigThumbW > window.siteMaxThumbnailSize) { - bigThumbW = window.siteMaxThumbnailSize; - } - if(bigThumbH > window.siteMaxThumbnailSize) { - bigThumbH = window.siteMaxThumbnailSize; - } + oembedNum++; + } + // if there's a local thumb_url we assume this is a image or video + else if (typeof this.thumb_url != 'undefined' + && this.thumb_url !== null + && isLocalURL(this.thumb_url)) { + let bigThumbW = 1000; + let bigThumbH = 3000; + if (bigThumbW > window.siteMaxThumbnailSize) { + bigThumbW = window.siteMaxThumbnailSize; + } + if (bigThumbH > window.siteMaxThumbnailSize) { + bigThumbH = window.siteMaxThumbnailSize; + } - // very long landscape images should not have background-size:cover - var noCoverClass=''; - if(this.width/this.height > 2) { - noCoverClass=' no-cover'; - } + // very long landscape images should not have background-size:cover + let noCoverClass = ''; + if (this.width / this.height > 2) { + noCoverClass = ' no-cover'; + } - // play button for videos and animated gifs - var playButtonClass = ''; - if(typeof this.animated != 'undefined' && this.animated === true - || (this.url.indexOf('://www.youtube.com') > -1 || this.url.indexOf('://youtu.be') > -1) - || this.url.indexOf('://vimeo.com') > -1) { - playButtonClass = ' play-button'; - } + // play button for videos and animated gifs + let playButtonClass = ''; + if (typeof this.animated != 'undefined' && this.animated === true + || (this.url.indexOf('://www.youtube.com') > -1 || this.url.indexOf('://youtu.be') > -1) + || this.url.indexOf('://vimeo.com') > -1) { + playButtonClass = ' play-button'; + } - // gif-class - var animatedGifClass = ''; - if(typeof this.animated != 'undefined' && this.animated === true) { - var animatedGifClass = ' animated-gif'; - } + // gif-class + var animatedGifClass = ''; + if (typeof this.animated != 'undefined' && this.animated === true) { + var animatedGifClass = ' animated-gif'; + } - // animated gifs always get default small non-animated thumbnail - if(this.animated === true) { - var img_url = this.thumb_url; - } - // if no dimensions are set, go with default thumb - else if(this.width === null && this.height === null) { - var img_url = this.thumb_url; - } - // large images get large thumbnail - else if(this.width > 1000) { - var img_url = this.large_thumb_url; - } - // no thumbnails for small local images - else if (this.url.indexOf(window.siteInstanceURL) === 0) { - var img_url = this.url; - } - // small thumbnail for small remote images - else { - var img_url = this.thumb_url; - } + // animated gifs always get default small non-animated thumbnail + if (this.animated === true) { + var img_url = this.thumb_url; + } + // if no dimensions are set, go with default thumb + else if (this.width === null && this.height === null) { + var img_url = this.thumb_url; + } + // large images get large thumbnail + else if (this.width > 1000) { + var img_url = this.large_thumb_url; + } + // no thumbnails for small local images + else if (this.url.indexOf(window.siteInstanceURL) === 0) { + var img_url = this.url; + } + // small thumbnail for small remote images + else { + var img_url = this.thumb_url; + } - var urlToHide = window.siteInstanceURL + 'attachment/' + this.id; + var urlToHide = window.siteInstanceURL + 'attachment/' + this.id; - attachmentHTML += ''; - urlsToHide.push(urlToHide); // hide this attachment url from the queet text - attachmentNum++; - } - else if (this.mimetype == 'image/svg+xml') { - var urlToHide = window.siteInstanceURL + 'attachment/' + this.id; - attachmentHTML += ''; - urlsToHide.push(urlToHide); // hide this attachment url from the queet text - attachmentNum++; - } - }); - } - return { html: '
' + oembedHTML + '
 
' + attachmentHTML + '
', - urlsToHide: urlsToHide, - quotedNotices: quotedNotices - }; - } + attachmentHTML += ''; + urlsToHide.push(urlToHide); // hide this attachment url from the queet text + attachmentNum++; + } else if (this.mimetype == 'image/svg+xml') { + var urlToHide = window.siteInstanceURL + 'attachment/' + this.id; + attachmentHTML += ''; + urlsToHide.push(urlToHide); // hide this attachment url from the queet text + attachmentNum++; + } + }); + } + return { + html: '
' + oembedHTML + '
 
' + attachmentHTML + '
', + urlsToHide: urlsToHide, + quotedNotices: quotedNotices + }; +}; window.sensitiveContentOriginalBuildQueetHtml = window.buildQueetHtml; -window.buildQueetHtml = function(obj, idInStream, extraClasses, requeeted_by, isConversation) { - //add tags to json if they don't exit - if (obj.tags && obj.tags.length > 0) { - for (var tagI = 0; tagI < obj.tags.length; ++tagI) { - extraClasses += (' data-tag-' + obj.tags[tagI]); - if (window.loggedIn.hide_sensitive && obj.tags[tagI] === 'nsfw') extraClasses += ' sensitive-notice'; - } +window.buildQueetHtml = function (obj, idInStream, extraClasses, requeeted_by, isConversation) { + //add tags to json if they don't exit + if (obj.tags && obj.tags.length > 0) { + for (let tagI = 0; tagI < obj.tags.length; ++tagI) { + extraClasses += (' data-tag-' + obj.tags[tagI]); + if (window.loggedIn.hide_sensitive && obj.tags[tagI] === 'nsfw') extraClasses += ' sensitive-notice'; } + } - return window.sensitiveContentOriginalBuildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversation); -} \ No newline at end of file + return window.sensitiveContentOriginalBuildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversation); +}; \ No newline at end of file