Add an option so the blocker can be activated for not-logged-in visitors. Remove redundant setting retrival code.

An example config.php entry to activate the new config:

$config['site']['sensitivecontent']['hideforvisitors'] = true;

Signed-off-by: Moon Man <moonman@shitposter.club>
This commit is contained in:
nee 2018-04-05 22:19:29 +02:00 committed by Moon Man
parent 72bda1fc01
commit cc5f89431a
2 changed files with 20 additions and 33 deletions

View File

@ -19,6 +19,10 @@ if you want to customize the blocker image, add a line to your config.php:
$config['site']['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:
$config['site']['sensitivecontent']['hideforvisitors'] = true;
## Usage ## Usage
Individual users must go to their Settings page. A new sidebar menu item "Sensitive Content" Individual users must go to their Settings page. A new sidebar menu item "Sensitive Content"

View File

@ -22,6 +22,7 @@ class SensitiveContentPlugin extends Plugin
static function settings($setting) static function settings($setting)
{ {
$settings['blockerimage'] = Plugin::staticPath('SensitiveContent', '').'img/blocker.png'; $settings['blockerimage'] = Plugin::staticPath('SensitiveContent', '').'img/blocker.png';
$settings['hideforvisitors'] = false;
$configphpsettings = common_config('site','sensitivecontent') ?: array(); $configphpsettings = common_config('site','sensitivecontent') ?: array();
foreach($configphpsettings as $configphpsetting=>$value) { foreach($configphpsettings as $configphpsetting=>$value) {
@ -146,20 +147,7 @@ EOB;
function onStartShowAttachmentRepresentation($out, $file) 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'; $classes = "sensitive-blocker"; //'sensitive-blocker';
$thumbnail = null; $thumbnail = null;
try { try {
$thumbnail = $file->getThumbnail(); $thumbnail = $file->getThumbnail();
@ -190,18 +178,12 @@ EOB;
function onEndShowScripts(Action $action) function onEndShowScripts(Action $action)
{ {
$profile = $action->getScoped(); $profile = $action->getScoped();
if (!is_null($profile) && $profile instanceof Profile) $hidesensitive = $this->getHideSetting($profile);
{ $hidesensitiveString = $hidesensitive ? "true" : "false";
$hidesensitive = $this->getHideSensitive($profile) ? "true" : "false";
}
else
{
$hidesensitive = "false";
}
$inline = <<<EOB $inline = <<<EOB
window.hidesensitive = $hidesensitive ; window.hidesensitive = $hidesensitiveString ;
function toggleSpoiler(evt) { function toggleSpoiler(evt) {
if (window.hidesensitive) evt.target.classList.toggle('reveal'); if (window.hidesensitive) evt.target.classList.toggle('reveal');
@ -232,22 +214,23 @@ EOB;
function onStartHtmlElement($action, &$attrs) { function onStartHtmlElement($action, &$attrs) {
$profile = Profile::current(); $profile = Profile::current();
$hidesensitive = $this->getHideSetting($profile);
if (!is_null($profile) && $profile instanceof Profile) $attrs = array_merge($attrs,
{
$hidesensitive = $this->getHideSensitive($profile);
}
else
{
$hidesensitive = false;
}
$attrs = array_merge($attrs,
array('data-hidesensitive' => ($hidesensitive ? "true" : "false")) array('data-hidesensitive' => ($hidesensitive ? "true" : "false"))
); );
} }
function getHideSetting($profile) {
if (!is_null($profile) && $profile instanceof Profile)
{
return $this->getHideSensitive($profile);
}
else
{
return static::settings('hideforvisitors');
}
}
function getHideSensitive($profile) { function getHideSensitive($profile) {
$c = Cache::instance(); $c = Cache::instance();