gnu-social/plugins/SensitiveContent/SensitiveContentPlugin.php
Diogo Cordeiro 46f98b3142 [VersionBump] 1.19.0, fairly late
The core plugins whose version was attached to GS's were reseted to 2.0.0.

2.0.0 was chosen as reset version for plugins because it is higher than
  the one that was set by inheriting GS version. Furthermore, it's a
  major change from prior plugin versioning system thus it also makes
  semantic sense.

Justification for version bump:

== GS ==
9a4ab31f26 1.19.0
c13b935201 1.18.3
c13b935201 1.18.2
18fc39d2cf 1.18.1
c083a8bcc2 1.18.0
e8783d46d0 1.17.1
d9a42550ff 1.17.0
1536d3ef29 1.16.0
c03ed457a6 1.15.0
d2e6519bad 1.14.2
fe411e8138 1.14.1
b17e0b4169 1.14.0
daa5f87fd4 1.13.0
d75b5d2f4a 1.11.7
f6dbf66983 1.11.6
6cf674f8f8 1.11.5
7845a09b34 1.11.4
e4d432295d 1.11.3
339204f1ee 1.11.2
a4e679a118 1.11.1
7967db6ff5 1.11.0
bc030da320 1.10.1
9cc7df51d6 1.10.0
bf7f17474d 1.9.2
8a07edec5f 1.9.1
0042971d74 1.9.0
6b5450b7e6 1.8.0
5dcc98d1c6 1.7.0
e6667db0cd 1.6.0
3290227b50 1.5.0
a59c439b46 1.4.0
496ab8c920 1.3.10
986030060b 1.3.9
1d529c021a 1.3.8
f89c052cf8 1.3.7
38f2ecefac 1.3.6
e473937cb9 1.3.5
9a39ebe66f 1.3.4
ddc3cecfc0 1.3.3
2b43d484eb 1.3.2
e8e487187e 1.3.1

== Plugins ==
XMPP plugin
e0887220b0 bump patch
e186ad57d0 bump patch

OStatus
e186ad57d0 bump patch

Nodeinfo
ceae66a30f bump minor
586fb5a517 bump major
195296846e bump minor
2019-06-07 15:02:08 +01:00

275 lines
6.4 KiB
PHP

<?php
if (!defined('GNUSOCIAL')) {
exit(1);
}
class SensitiveContentPlugin extends Plugin
{
const PLUGIN_VERSION = '0.0.1';
function onPluginVersion(array &$versions)
{
$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;
}
static function settings($setting)
{
$settings['blockerimage'] = Plugin::staticPath('SensitiveContent', '').'img/blocker.png';
$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',
array('action' => 'sensitivecontentsettings'));
}
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)
{
$profile = Profile::current();
if (!is_null($profile) && $profile instanceof Profile)
{
$hidesensitive = $this->getHideSensitive($profile);
}
else
{
$hidesensitive = false;
}
$classes = "sensitive-blocker"; //'sensitive-blocker';
$out->elementStart('div', array(
'class'=>'attachment-wrapper',
'style'=>'height: ' . $file->getThumbnail()->height . 'px; width: ' . $file->getThumbnail()->width . 'px;'
)); /*needs height of thumb*/
$out->elementStart('div', array(
'class'=>$classes,
'onclick'=>'toggleSpoiler(event)',
'style'=>'height: ' . $file->getThumbnail()->height . 'px; width: ' . $file->getThumbnail()->width . 'px;'
));
$out->raw('&nbsp;');
$out->elementEnd('div');
}
function onEndShowAttachmentRepresentation($out, $file)
{
$out->elementEnd('div');
}
function onEndShowScripts(Action $action)
{
$profile = $action->getScoped();
if (!is_null($profile) && $profile instanceof Profile)
{
$hidesensitive = $this->getHideSensitive($profile) ? "true" : "false";
}
else
{
$hidesensitive = "false";
}
$inline = <<<EOB
window.hidesensitive = $hidesensitive ;
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();
if (!is_null($profile) && $profile instanceof Profile)
{
$hidesensitive = $this->getHideSensitive($profile);
}
else
{
$hidesensitive = false;
}
$attrs = array_merge($attrs,
array('data-hidesensitive' => ($hidesensitive ? "true" : "false"))
);
}
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;
}
}