mirror of
https://github.com/Findus23/plugin-QuickExcludeVisitorIP.git
synced 2024-09-08 03:03:46 +02:00
initial commit
This commit is contained in:
commit
40d1e7bbd9
9 changed files with 147 additions and 0 deletions
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
## Changelog
|
||||
|
||||
# 0.1.0
|
||||
|
||||
first beta version
|
47
Controller.php
Normal file
47
Controller.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link https://matomo.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\QuickExcludeVisitorIP;
|
||||
|
||||
use Piwik\Common;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugins\SitesManager\API as APISitesManager;
|
||||
|
||||
class Controller extends \Piwik\Plugin\Controller
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
private function response($message, $type)
|
||||
{
|
||||
return json_encode(["message" => $message, "options" => ["title" => "QuickExcludeVisitorIP", "context" => $type]]);
|
||||
}
|
||||
|
||||
public function ignoreIP()
|
||||
{
|
||||
Piwik::checkUserHasSuperUserAccess();
|
||||
@header('Content-Type: application/json; charset=utf-8');
|
||||
$ip = Common::getRequestVar('ip', null, 'string');
|
||||
$ignoredIPstr = APISitesManager::getInstance()->getExcludedIpsGlobal();
|
||||
$ignoredIPs = explode(",", $ignoredIPstr);
|
||||
if (in_array($ip, $ignoredIPs)) {
|
||||
return $this->response("IP was already on ignore list", "warning");
|
||||
}
|
||||
|
||||
$ignoredIPs[] = $ip;
|
||||
|
||||
$ignoredIPstr = implode(",", $ignoredIPs);
|
||||
|
||||
APISitesManager::getInstance()->setGlobalExcludedIps($ignoredIPstr);
|
||||
|
||||
return $this->response("successfully added \"$ip\" to ignore list", "success");
|
||||
}
|
||||
}
|
37
QuickExcludeVisitorIP.php
Normal file
37
QuickExcludeVisitorIP.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link https://matomo.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\QuickExcludeVisitorIP;
|
||||
|
||||
use Piwik\Access;
|
||||
use Piwik\DataTable\Row;
|
||||
use Piwik\Plugin;
|
||||
|
||||
class QuickExcludeVisitorIP extends Plugin
|
||||
{
|
||||
public function registerEvents()
|
||||
{
|
||||
return array(
|
||||
'Live.renderVisitorIcons' => 'handleMyEventInATemplate',
|
||||
'AssetManager.getJavaScriptFiles' => 'getJavaScriptFiles',
|
||||
);
|
||||
}
|
||||
|
||||
public function handleMyEventInATemplate(&$outString, Row $visit)
|
||||
{
|
||||
if (Access::getInstance()->hasSuperUserAccess()) {
|
||||
$ip = $visit->getColumn("visitIp");
|
||||
$outString .= "<a class='quickExcludeButton' data-ip='$ip'>ignore</a>";
|
||||
}
|
||||
}
|
||||
|
||||
public function getJavaScriptFiles(&$files)
|
||||
{
|
||||
$files[] = "plugins/QuickExcludeVisitorIP/javascripts/main.js";
|
||||
}
|
||||
}
|
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Matomo QuickExcludeVisitorIP Plugin
|
||||
|
||||
## Description
|
||||
|
||||
|
2
config/config.php
Normal file
2
config/config.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
return array();
|
2
config/tracker.php
Normal file
2
config/tracker.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
return array();
|
21
javascripts/main.js
Normal file
21
javascripts/main.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
(function ($, require) {
|
||||
$(document).ready(function () {
|
||||
var ajaxHelper = require('ajaxHelper');
|
||||
var UI = require('piwik/UI');
|
||||
var notification = new UI.Notification();
|
||||
$("body").on("click", "a.quickExcludeButton", function () {
|
||||
var ip = $(this).data("ip");
|
||||
var ajax = new ajaxHelper();
|
||||
ajax.addParams({
|
||||
module: 'QuickExcludeVisitorIP',
|
||||
action: 'ignoreIP',
|
||||
ip: ip
|
||||
}, 'post');
|
||||
ajax.setCallback(function (response) {
|
||||
notification.show(response.message, response.options);
|
||||
});
|
||||
ajax.setFormat('json');
|
||||
ajax.send(false);
|
||||
});
|
||||
});
|
||||
})(jQuery, require);
|
28
plugin.json
Normal file
28
plugin.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "QuickExcludeVisitorIP",
|
||||
"description": "Adds a button to Visitor Profile to quickly add them to the list of ignored IPs",
|
||||
"version": "0.1.0",
|
||||
"theme": false,
|
||||
"require": {
|
||||
"piwik": ">=3.10.0,<5.0.0-b1"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Lukas Winkler",
|
||||
"email": "lukas@matomo.org",
|
||||
"homepage": "https://lw1.at"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"email": "lukas@matomo.org",
|
||||
"issues": "https://github.com/Findus23/plugin-QuickExcludeVisitorIP/issues",
|
||||
"forum": "https://forum.matomo.org",
|
||||
"source": "https://github.com/Findus23/plugin-QuickExcludeVisitorIP"
|
||||
},
|
||||
"homepage": "https://lw1.at",
|
||||
"license": "GPL v3+",
|
||||
"keywords": [
|
||||
"IP",
|
||||
"ignore"
|
||||
]
|
||||
}
|
0
screenshots/.gitkeep
Normal file
0
screenshots/.gitkeep
Normal file
Loading…
Reference in a new issue