-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlockList.php
113 lines (98 loc) · 2.91 KB
/
BlockList.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
/**
* Block List plugin for Craft CMS 3.x
*
* A CP extension for basic ip block-list entries
*
* @link Github.com/Bwilliamson55
* @copyright Benjamin Williamson
*/
namespace bwilliamson\blocklist;
use bwilliamson\blocklist\services\BlockListService as BlockListServiceService;
use bwilliamson\blocklist\variables\BlockListVariable;
use Craft;
use craft\base\Plugin;
use craft\web\UrlManager;
use craft\web\twig\variables\CraftVariable;
use craft\events\RegisterUrlRulesEvent;
use craft\events\RegisterUserPermissionsEvent;
use craft\services\UserPermissions;
use yii\base\Event;
/**
* Class BlockList
*
* @author Benjamin Williamson
* @package BlockList
* @since 1
*
* @property BlockListServiceService $blockListService
*/
class BlockList extends Plugin
{
// Static Properties
// =========================================================================
/**
* @var BlockList
*/
public static BlockList $plugin;
// Public Properties
// =========================================================================
/**
* @var string
*/
public $schemaVersion = '1';
/**
* @var bool
*/
public $hasCpSection = true;
// Public Methods
// =========================================================================
/**
* @inheritdoc
*/
public function init(): void
{
parent::init();
self::$plugin = $this;
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
function (RegisterUrlRulesEvent $event) {
$event->rules['block-list/new'] = 'block-list/block-list/new-license';
$event->rules['block-list/edit/<licenseId:\d+>'] = 'block-list/block-list/edit';
$event->rules['block-list/edit/update-license'] = 'block-list/block-list/update-license';
}
);
Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
function (Event $event) {
/** @var CraftVariable $variable */
$variable = $event->sender;
$variable->set('blockList', BlockListVariable::class);
}
);
Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
function(RegisterUserPermissionsEvent $event) {
$event->permissions['Block List'] = [
'blocklist:read' => [
'label' => 'Block List Read',
],
'blocklist:write' => [
'label' => 'Block List Write',
],
];
}
);
Craft::info(
Craft::t(
'block-list',
'{name} plugin loaded',
['name' => $this->name]
),
__METHOD__
);
}
}