forked from bombozama/linkcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
134 lines (124 loc) · 4.6 KB
/
Plugin.php
File metadata and controls
134 lines (124 loc) · 4.6 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace Bombozama\LinkCheck;
use Backend;
use Flash;
use Lang;
use System\Classes\PluginBase;
use Bombozama\LinkCheck\Models\Context;
use Bombozama\LinkCheck\Models\Settings;
use Bombozama\LinkCheck\ReportWidgets\BrokenLinks;
/**
* LinkCheck Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'bombozama.linkcheck::lang.details.name',
'description' => 'bombozama.linkcheck::lang.details.description',
'author' => 'Gonzalo Henríquez',
'icon' => 'icon-chain-broken',
'homepage' => 'https://github.com/bombozama/linkcheck',
];
}
public function register()
{
Settings::extend(function ($model) {
$model->bindEvent('model.beforeSave', function () use ($model) {
if (!post('Settings[plugins]')) {
// If no plugin was selected, remove the selected model fields
// by setting modelators to an empty string.
$model->modelators = '';
Flash::info(Lang::get('bombozama.linkcheck::lang.strings.plugins_empty'));
}
});
});
}
public function registerPermissions()
{
return [
'bombozama.linkcheck.manage' => [
'tab' => 'bombozama.linkcheck::lang.plugin.tab',
'label' => 'bombozama.linkcheck::lang.plugin.manage',
],
'bombozama.linkcheck.view' => [
'tab' => 'bombozama.linkcheck::lang.plugin.tab',
'label' => 'bombozama.linkcheck::lang.plugin.view',
],
'bombozama.linkcheck.useragent' => [
'tab' => 'bombozama.linkcheck::lang.plugin.tab',
'label' => 'bombozama.linkcheck::lang.plugin.useragent',
],
];
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'bombozama.linkcheck::lang.menu.settings.label',
'description' => 'bombozama.linkcheck::lang.menu.settings.description',
'category' => 'bombozama.linkcheck::lang.plugin.category',
'icon' => 'icon-chain-broken',
'class' => 'Bombozama\LinkCheck\Models\Settings',
'order' => 410,
'permissions' => ['bombozama.linkcheck.manage'],
],
'brokenlinks' => [
'label' => 'bombozama.linkcheck::lang.menu.brokenlinks.label',
'description' => 'bombozama.linkcheck::lang.menu.brokenlinks.description',
'category' => 'bombozama.linkcheck::lang.plugin.category',
'icon' => 'icon-list',
'url' => Backend::url('bombozama/linkcheck/context'),
'order' => 411,
'permissions' => ['bombozama.linkcheck.view'],
],
'userAgent' => [
'label' => 'bombozama.linkcheck::lang.menu.useragent.label',
'description' => 'bombozama.linkcheck::lang.menu.useragent.description',
'category' => 'bombozama.linkcheck::lang.plugin.category',
'icon' => 'icon-user-secret',
'url' => Backend::url('bombozama/linkcheck/useragent'),
'order' => 412,
'permissions' => ['bombozama.linkcheck.useragent'],
],
];
}
public function registerListColumnTypes()
{
return [
'httpstatus' => [$this, 'httpStatus'],
];
}
public function httpStatus($value, $column, $record)
{
return '<span title="' . Lang::get('bombozama.linkcheck::lang.codes.' . $value) . '">' . $value . '</span>';
}
public function registerReportWidgets()
{
return [
BrokenLinks::class => [
'label' => 'bombozama.linkcheck::lang.details.name',
'context' => 'dashboard',
'permissions' => [
'bombozama.linkcheck.view',
],
],
];
}
// Please do https://octobercms.com/docs/setup/installation#crontab-setup
public function registerSchedule($schedule)
{
$settings = Settings::instance();
if ($settings->time) {
$schedule->call(function() {
Context::processLinks();
})->cron($settings->time);
}
}
}