46f98b3142
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.0c13b935201
1.18.3c13b935201
1.18.218fc39d2cf
1.18.1c083a8bcc2
1.18.0e8783d46d0
1.17.1d9a42550ff
1.17.01536d3ef29
1.16.0c03ed457a6
1.15.0d2e6519bad
1.14.2fe411e8138
1.14.1b17e0b4169
1.14.0daa5f87fd4
1.13.0d75b5d2f4a
1.11.7f6dbf66983
1.11.66cf674f8f8
1.11.57845a09b34
1.11.4e4d432295d
1.11.3339204f1ee
1.11.2a4e679a118
1.11.17967db6ff5
1.11.0bc030da320
1.10.19cc7df51d6
1.10.0bf7f17474d
1.9.28a07edec5f
1.9.10042971d74
1.9.06b5450b7e6
1.8.05dcc98d1c6
1.7.0e6667db0cd
1.6.03290227b50
1.5.0a59c439b46
1.4.0496ab8c920
1.3.10986030060b
1.3.91d529c021a
1.3.8f89c052cf8
1.3.738f2ecefac
1.3.6e473937cb9
1.3.59a39ebe66f
1.3.4ddc3cecfc0
1.3.32b43d484eb
1.3.2e8e487187e
1.3.1 == Plugins == XMPP plugine0887220b0
bump patche186ad57d0
bump patch OStatuse186ad57d0
bump patch Nodeinfoceae66a30f
bump minor586fb5a517
bump major195296846e
bump minor
275 lines
6.4 KiB
PHP
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(' ');
|
|
$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;
|
|
}
|
|
|
|
}
|