Hide banned visitors too

This commit is contained in:
Dmitriy Simushev 2014-10-22 13:50:37 +00:00
parent f2619bb105
commit 860aa5b82c
3 changed files with 25 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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

View File

@ -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"