-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathIPtoCompany.php
113 lines (103 loc) · 3.63 KB
/
IPtoCompany.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?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\IPtoCompany;
use Piwik\Db;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Plugin;
use Piwik\SettingsPiwik;
use Piwik\Widget\WidgetsList;
use \Exception;
class IPtoCompany extends \Piwik\Plugin
{
/**
* @see https://developer.matomo.org/guides/extending-database
*/
public function install()
{
try {
$sql = "CREATE TABLE " . Common::prefixTable('ip_to_company') . " (
id INTEGER NOT NULL AUTO_INCREMENT,
ip VARCHAR( 15 ) NOT NULL ,
as_number VARCHAR( 10 ) NULL ,
as_name VARCHAR( 200 ) NULL ,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
PRIMARY KEY ( id )
) DEFAULT CHARSET=utf8 ";
Db::exec($sql);
} catch (Exception $e) {
// ignore error if table already exists (1050 code is for 'table already exists')
if (!Db::get()->isErrNo($e, '1050')) {
throw $e;
}
}
}
/**
* @see https://developer.matomo.org/guides/extending-database
*/
public function activate()
{
try {
$sql = "CREATE TABLE " . Common::prefixTable('ip_to_company') . " (
id INTEGER NOT NULL AUTO_INCREMENT,
ip VARCHAR( 15 ) NOT NULL ,
as_number VARCHAR( 10 ) NULL ,
as_name VARCHAR( 200 ) NULL ,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
PRIMARY KEY ( id )
) DEFAULT CHARSET=utf8 ";
Db::exec($sql);
} catch (Exception $e) {
// ignore error if table already exists (1050 code is for 'table already exists')
if (!Db::get()->isErrNo($e, '1050')) {
throw $e;
}
}
}
/**
* @see https://developer.matomo.org/guides/extending-database
*/
public function uninstall()
{
Db::dropTables(Common::prefixTable('ip_to_company'));
}
/**
* @see \Piwik\Plugin::registerEvents
*/
public function registerEvents()
{
return array(
//'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'Widget.filterWidgets' => 'filterWidgets'
);
}
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "plugins/IPtoCompany/stylesheets/iptocompany.less";
}
/*public function getJsFiles(&$jsFiles)
{
$jsFiles[] = "libs/bower_components/iframe-resizer/js/iframeResizer.min.js";
$jsFiles[] = "plugins/Marketplace/angularjs/plugins/plugin-name.directive.js";
$jsFiles[] = "plugins/Marketplace/angularjs/licensekey/licensekey.controller.js";
$jsFiles[] = "plugins/Marketplace/angularjs/marketplace/marketplace.controller.js";
$jsFiles[] = "plugins/Marketplace/angularjs/marketplace/marketplace.directive.js";
}*/
/**
* @param WidgetsList $list
*/
public function filterWidgets($list)
{
if (!SettingsPiwik::isInternetEnabled()) {
$list->remove('IPtoCompany_Companies');
}
}
}