2016-09-02 10:34:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (!defined('GNUSOCIAL')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
class SensitiveContentPlugin extends Plugin
|
|
|
|
{
|
2019-06-03 01:56:52 +01:00
|
|
|
const PLUGIN_VERSION = '0.0.1';
|
2016-09-02 10:34:29 +01:00
|
|
|
|
2019-08-12 15:03:30 +01:00
|
|
|
public function onPluginVersion(array &$versions): bool
|
2016-09-02 10:34:29 +01:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'Sensitive Content',
|
2019-06-03 01:56:52 +01:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2016-09-02 10:34:29 +01:00
|
|
|
'author' => 'MoonMan',
|
|
|
|
'homepage' => 'https://gitgud.io/ShitposterClub/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';
|
2018-04-05 21:19:29 +01:00
|
|
|
$settings['hideforvisitors'] = false;
|
2016-09-02 10:34:29 +01:00
|
|
|
|
|
|
|
$configphpsettings = common_config('site','sensitivecontent') ?: array();
|
|
|
|
foreach($configphpsettings as $configphpsetting=>$value) {
|
|
|
|
$settings[$configphpsetting] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($settings[$setting])) {
|
|
|
|
return $settings[$setting];
|
|
|
|
}
|
|
|
|
else FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped)
|
|
|
|
{
|
|
|
|
$twitter_status['tags'] = $notice->getTags();
|
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2019-07-11 19:14:03 +01:00
|
|
|
['action' => 'sensitivecontentsettings']);
|
2016-09-02 10:34:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onEndAccountSettingsNav($action)
|
|
|
|
{
|
|
|
|
$action->menuItem(common_local_url('sensitivecontentsettings'),
|
|
|
|
_m('MENU', 'Sensitive Content'),
|
|
|
|
_m('Settings for display of sensitive content.'));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function onQvitterEndShowHeadElements(Action $action)
|
|
|
|
{
|
|
|
|
$blocker = static::settings('blockerimage');
|
|
|
|
common_log( LOG_DEBUG, "SENSITIVECONTENT " . $blocker );
|
|
|
|
|
|
|
|
|
|
|
|
$styles = <<<EOB
|
|
|
|
|
|
|
|
.sensitive-blocker {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
div.stream-item.notice.sensitive-notice .sensitive-blocker {
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
position: absolute;
|
|
|
|
z-index: 100;
|
|
|
|
background-color: #d4baba;
|
|
|
|
background-image: url($blocker);
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
background-position: center center;
|
|
|
|
background-size: contain;
|
|
|
|
transition: opacity 1s ease-in-out;
|
|
|
|
}
|
|
|
|
|
|
|
|
.sensitive-blocker:hover {
|
|
|
|
opacity: .5;
|
|
|
|
}
|
|
|
|
|
|
|
|
div.stream-item.notice.expanded.sensitive-notice .sensitive-blocker {
|
|
|
|
display: none;
|
|
|
|
background-color: transparent;
|
|
|
|
background-image: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOB;
|
|
|
|
|
|
|
|
$action->style($styles);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onQvitterEndShowScripts(Action $action)
|
|
|
|
{
|
|
|
|
$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';
|
2018-04-05 21:16:19 +01:00
|
|
|
$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%';
|
|
|
|
|
2016-09-02 10:34:29 +01:00
|
|
|
$out->elementStart('div', array(
|
2018-04-05 21:16:19 +01:00
|
|
|
'class' => 'attachment-wrapper',
|
|
|
|
'style' => "height: {$thumb_height_css}; width: {$thumb_width_css};",
|
2016-09-02 10:34:29 +01:00
|
|
|
)); /*needs height of thumb*/
|
|
|
|
$out->elementStart('div', array(
|
2018-04-05 21:16:19 +01:00
|
|
|
'class' => $classes,
|
|
|
|
'onclick' => 'toggleSpoiler(event)',
|
|
|
|
'style' => "height: {$thumb_height_css}; width: {$thumb_width_css};",
|
2016-09-02 10:34:29 +01:00
|
|
|
));
|
|
|
|
$out->raw(' ');
|
|
|
|
$out->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEndShowAttachmentRepresentation($out, $file)
|
|
|
|
{
|
|
|
|
$out->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEndShowScripts(Action $action)
|
|
|
|
{
|
|
|
|
$profile = $action->getScoped();
|
2018-04-05 21:19:29 +01:00
|
|
|
$hidesensitive = $this->getHideSetting($profile);
|
|
|
|
$hidesensitive_string = $hidesensitive ? "true" : "false";
|
2016-09-02 10:34:29 +01:00
|
|
|
|
|
|
|
$inline = <<<EOB
|
|
|
|
|
2018-04-05 21:19:29 +01:00
|
|
|
window.hidesensitive = $hidesensitive_string;
|
2016-09-02 10:34:29 +01:00
|
|
|
|
|
|
|
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();
|
2018-04-05 21:19:29 +01:00
|
|
|
$hidesensitive = $this->getHideSetting($profile);
|
2016-09-02 10:34:29 +01:00
|
|
|
|
2018-04-05 21:19:29 +01:00
|
|
|
$attrs = array_merge($attrs,
|
2016-09-02 10:34:29 +01:00
|
|
|
array('data-hidesensitive' => ($hidesensitive ? "true" : "false"))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-05 21:19:29 +01:00
|
|
|
function getHideSetting($profile) {
|
|
|
|
if (isset($profile) && $profile instanceof Profile) {
|
|
|
|
return $this->getHideSensitive($profile);
|
|
|
|
} else {
|
|
|
|
return static::settings('hideforvisitors');
|
|
|
|
}
|
|
|
|
}
|
2016-09-02 10:34:29 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|