From 860aa5b82ca04199034ca315d2d85d8504ba035d Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 22 Oct 2014 13:50:37 +0000 Subject: [PATCH] Hide banned visitors too --- Plugin.php | 23 +++++++++++++++++++++++ README.md | 2 +- package.json | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Plugin.php b/Plugin.php index 6e7d2ba..caa8d2e 100644 --- a/Plugin.php +++ b/Plugin.php @@ -23,6 +23,7 @@ namespace Mibew\Mibew\Plugin\RealBan; +use Mibew\Ban; use Mibew\EventDispatcher\EventDispatcher; use Mibew\EventDispatcher\Events; use Mibew\Plugin\AbstractPlugin; @@ -53,6 +54,7 @@ class Plugin extends AbstractPlugin implements PluginInterface { $dispatcher = EventDispatcher::getInstance(); $dispatcher->attachListener(Events::USERS_UPDATE_THREADS_ALTER, $this, 'alterThreads'); + $dispatcher->attachListener(Events::USERS_UPDATE_VISITORS_ALTER, $this, 'alterVisitors'); } /** @@ -85,4 +87,25 @@ class Plugin extends AbstractPlugin implements PluginInterface $args['threads'] = $threads; } + + /** + * A handler for + * {@link \Mibew\EventDispatcher\Events::USERS_UPDATE_VISITORS_ALTER} event. + * + * @param array $args Event arguments. + */ + public function alterVisitors(&$args) + { + $visitors = array(); + foreach ($args['visitors'] as $visitor) { + $ban = Ban::loadByAddress($visitor['userIp']); + if ($ban && !$ban->isExpired()) { + // Skip banned visitors + continue; + } + $visitors[] = $visitor; + } + + $args['visitors'] = $visitors; + } } diff --git a/README.md b/README.md index 3f679bb..8d80221 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mibew Real Ban plugin -It hides banned users from the awaiting page. +It hides banned threads and visitors on the awaiting page. ## Installation diff --git a/package.json b/package.json index 67714bf..a02a7d7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "real-ban-plugin", "version": "0.1.0", - "description": "A plugin for Mibew that hides banned users from the threads list.", + "description": "A plugin for Mibew that hides banned threads and visitors on the awaiting page.", "private": true, "bugs": { "url": "https://github.com/mibew/real-ban-plugin/issues"