[SensitiveContent] Add option to activate 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;
This commit is contained in:
nee 2018-04-05 22:19:29 +02:00 committed by Diogo Peralta Cordeiro
parent 2419d85edf
commit 7ee8751b8e
2 changed files with 17 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";
if you want to activate the nsfw overlay for non-logged-in visitors add:
$config['site']['sensitivecontent']['hideforvisitors'] = true;
## Usage
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)
{
$settings['blockerimage'] = Plugin::staticPath('SensitiveContent', '').'img/blocker.png';
$settings['hideforvisitors'] = false;
$configphpsettings = common_config('site','sensitivecontent') ?: array();
foreach($configphpsettings as $configphpsetting=>$value) {
@ -146,20 +147,7 @@ EOB;
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';
$thumbnail = null;
try {
$thumbnail = $file->getThumbnail();
@ -190,18 +178,12 @@ EOB;
function onEndShowScripts(Action $action)
{
$profile = $action->getScoped();
if (!is_null($profile) && $profile instanceof Profile)
{
$hidesensitive = $this->getHideSensitive($profile) ? "true" : "false";
}
else
{
$hidesensitive = "false";
}
$hidesensitive = $this->getHideSetting($profile);
$hidesensitive_string = $hidesensitive ? "true" : "false";
$inline = <<<EOB
window.hidesensitive = $hidesensitive ;
window.hidesensitive = $hidesensitive_string;
function toggleSpoiler(evt) {
if (window.hidesensitive) evt.target.classList.toggle('reveal');
@ -232,22 +214,20 @@ EOB;
function onStartHtmlElement($action, &$attrs) {
$profile = Profile::current();
$hidesensitive = $this->getHideSetting($profile);
if (!is_null($profile) && $profile instanceof Profile)
{
$hidesensitive = $this->getHideSensitive($profile);
}
else
{
$hidesensitive = false;
}
$attrs = array_merge($attrs,
$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();