Skip to content

Commit

Permalink
Hide links displayed by 'Summaries' extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jslirola committed Aug 19, 2020
1 parent d4e0eaf commit 8a016a6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Listeners/LoadSettingsFromDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace JSLirola\Login2SeePlus\Listeners;

use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Api\Serializer\BasicPostSerializer;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Api\Event\Serializing;
use Flarum\Settings\SettingsRepositoryInterface;
Expand Down Expand Up @@ -80,8 +81,10 @@ public function handle(Serializing $event)
$newHTML = $event->attributes['contentHtml'];

// truncate
if ($s_post != -1 && function_exists('mb_substr') && function_exists('mb_strlen'))
if ($s_post != -1 && function_exists('mb_substr') && function_exists('mb_strlen')) {
$newHTML = $this->truncate_html($newHTML, $s_post);
$newHTML = preg_replace('/(<p>)([^<]*)<\/p>$/is', '$1$2...$3', $newHTML);
}

// links
if ($s_link == 1) {
Expand Down Expand Up @@ -111,6 +114,19 @@ public function handle(Serializing $event)
)) . '</div>';

$event->attributes['contentHtml'] = $newHTML;

}
else if ($event->isSerializer(BasicPostSerializer::class) && !is_null($event->attributes["contentHtml"]))
{
if (!$event->actor->isGuest())
return;

$s_summary_links = $this->settings->get('jslirola.login2seeplus.link', false);

if ($s_summary_links == 1)
$event->attributes['contentHtml'] = preg_replace('/(<a((?!PostMention).)*?>)[^<]*<\/a>/is',
'[' . $this->get_link('jslirola-login2seeplus.forum.link') . ']', $event->attributes['contentHtml']);

}
}
}

0 comments on commit 8a016a6

Please sign in to comment.