-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathsetup.php
More file actions
243 lines (209 loc) · 8.84 KB
/
setup.php
File metadata and controls
243 lines (209 loc) · 8.84 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
/**
* -------------------------------------------------------------------------
* Tag plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Tag.
*
* Tag is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Tag is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tag. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2014-2023 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/tag
* -------------------------------------------------------------------------
*/
use Glpi\Application\ImportMapGenerator;
use Glpi\Form\Destination\AbstractCommonITILFormDestination;
use Glpi\Form\Destination\FormDestinationManager;
use Glpi\Form\Form;
use Glpi\Form\Migration\TypesConversionMapper;
use Glpi\Form\QuestionType\QuestionTypesManager;
use Glpi\Plugin\Hooks;
use GlpiPlugin\Webapplications\Webapplication;
use function Safe\define;
define('PLUGIN_TAG_VERSION', '2.14.3');
// Minimal GLPI version, inclusive
define("PLUGIN_TAG_MIN_GLPI", "11.0.1");
// Maximum GLPI version, exclusive
define("PLUGIN_TAG_MAX_GLPI", "11.0.99");
/**
* Init hooks of the plugin.
* REQUIRED
*
* @return void
*/
function plugin_init_tag()
{
/**
* @var array $PLUGIN_HOOKS
* @var array $UNINSTALL_TYPES
* @var array $CFG_GLPI
*/
global $PLUGIN_HOOKS, $UNINSTALL_TYPES, $CFG_GLPI;
$PLUGIN_HOOKS['csrf_compliant']['tag'] = true;
if (Plugin::isPluginActive("tag")) {
// define list of itemtype which can be associated with tags
$CFG_GLPI['plugin_tag_itemtypes'] = [
__s('Assets') => [
'Computer', 'Monitor', 'Software', 'NetworkEquipment',
'Peripheral', 'Printer', 'CartridgeItem', 'ConsumableItem',
'Phone', 'Enclosure', 'PDU', 'PassiveDCEquipment',
],
__s('Assistance') => [
'Ticket', 'Problem', 'Change', 'TicketRecurrent',
'TicketTemplate', 'PlanningExternalEvent',
],
__s('Management') => [
'Budget', 'Supplier', 'Contact', 'Contract', 'Document',
'Line', 'Certificate', 'Appliance', 'Cluster', 'Domain',
],
__s('Tools') => ['Project', 'Reminder', 'RSSFeed', 'KnowbaseItem', 'ProjectTask'],
__s('Administration') => ['User', 'Group', 'Entity', 'Profile', Form::class],
__s('Setup') => ['SLA', 'SlaLevel', 'Link'],
];
if (class_exists('Webhook')) {
$CFG_GLPI['plugin_tag_itemtypes'][__s('Setup')][] = 'Webhook';
}
if (Plugin::isPluginActive('appliances')) {
$CFG_GLPI['plugin_tag_itemtypes'][__s('Assets')][] = 'PluginAppliancesAppliance';
}
// Plugin Webapplication
if (Plugin::isPluginActive('webapplications') && class_exists(Webapplication::class)) {
$CFG_GLPI['plugin_tag_itemtypes'][__s('Assets')][] = Webapplication::class;
}
// Plugin fusioninventory
if (Plugin::isPluginActive('fusioninventory')) {
$CFG_GLPI['plugin_tag_itemtypes'][__s('FusionInventory')][] = 'PluginFusioninventoryTask';
}
// add link on plugin name in Configuration > Plugin
$PLUGIN_HOOKS['config_page']['tag'] = "front/tag.php";
// Wait all plugins are loaded to find the itemtype matching the current URL
$PLUGIN_HOOKS['post_init']['tag'] = 'plugin_tag_post_init';
// Plugin use specific massive actions
$PLUGIN_HOOKS['use_massive_action']['tag'] = true;
// Plugin uninstall : after uninstall action
if (Plugin::isPluginActive("uninstall")) {
//to prevent null global variable load plugin if needed
if ($UNINSTALL_TYPES == null) {
Plugin::load('uninstall');
}
foreach ($UNINSTALL_TYPES as $u_itemtype) {
$PLUGIN_HOOKS['plugin_uninstall_after']['tag'][$u_itemtype] = 'plugin_uninstall_after_tag';
}
}
// insert tag dropdown into all possible itemtypes
$location = Config::getConfigurationValues('plugin:Tag')['tags_location'] ?? 0;
if ($location === '1') {
$PLUGIN_HOOKS['post_item_form']['tag'] = ['PluginTagTag', 'showForItem'];
} else {
$PLUGIN_HOOKS['pre_item_form']['tag'] = ['PluginTagTag', 'showForItem'];
}
$PLUGIN_HOOKS['pre_kanban_content']['tag'] = ['PluginTagTag', 'preKanbanContent'];
$common_kanban_filters = [
'tag' => [
'description' => _x('filters', 'If the item has a tag', 'tag'),
'supported_prefixes' => ['!'],
],
'tagged' => [
'description' => _x('filters', 'If the item is tagged', 'tag'),
'supported_prefixes' => ['!'],
],
];
$PLUGIN_HOOKS[Hooks::KANBAN_FILTERS]['tag'] = [
'Project' => $common_kanban_filters,
'Ticket' => $common_kanban_filters,
'Problem' => $common_kanban_filters,
'Change' => $common_kanban_filters,
];
$PLUGIN_HOOKS[Hooks::KANBAN_ITEM_METADATA]['tag'] = ['PluginTagTag', 'kanbanItemMetadata'];
// plugin datainjection
$PLUGIN_HOOKS['plugin_datainjection_populate']['tag'] = "plugin_datainjection_populate_tag";
// add needed javascript & css files
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['tag'][] = 'js/common.js';
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['tag'][] = 'js/kanban.js';
$PLUGIN_HOOKS[Hooks::ADD_CSS]['tag'][] = 'css/tag.css';
if (Session::isMultiEntitiesMode()) {
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['tag'][] = 'js/entity.js';
}
ImportMapGenerator::getInstance()->registerModulesPath('tag', '/public/js/modules');
Plugin::registerClass('PluginTagProfile', ['addtabon' => ['Profile']]);
Plugin::registerClass('PluginTagConfig', ['addtabon' => 'Config']);
$PLUGIN_HOOKS['use_rules']['tag'] = ['RuleTicket'];
// Register tag question type
plugin_tag_register_plugin_types();
}
}
/**
* Get the name and the version of the plugin
* REQUIRED
*
* @return array
*/
function plugin_version_tag()
{
return [
'name' => __s('Tag Management', 'tag'),
'version' => PLUGIN_TAG_VERSION,
'author' => '<a href="http://www.teclib.com">Teclib\'</a> - Infotel conseil',
'homepage' => 'https://github.com/pluginsGLPI/tag',
'license' => '<a href="' . plugin_tag_geturl() . '/LICENSE" target="_blank">GPLv2+</a>',
'requirements' => [
'glpi' => [
'min' => PLUGIN_TAG_MIN_GLPI,
'max' => PLUGIN_TAG_MAX_GLPI,
'dev' => true, //Required to allow 9.2-dev
],
],
];
}
function idealTextColor($hexTripletColor)
{
$nThreshold = 105;
$hexTripletColor = str_replace('#', '', $hexTripletColor);
$components = [
'R' => hexdec(substr($hexTripletColor, 0, 2)),
'G' => hexdec(substr($hexTripletColor, 2, 2)),
'B' => hexdec(substr($hexTripletColor, 4, 2)),
];
$bgDelta = ($components['R'] * 0.299)
+ ($components['G'] * 0.587)
+ ($components['B'] * 0.114);
return (((255 - $bgDelta) < $nThreshold) ? "#000000" : "#ffffff");
}
function plugin_tag_geturl(): string
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;
return sprintf('%s/plugins/tag', $CFG_GLPI['url_base']);
}
function plugin_tag_register_plugin_types(): void
{
$types = QuestionTypesManager::getInstance();
$type_mapper = TypesConversionMapper::getInstance();
$destination_manager = FormDestinationManager::getInstance();
// Register question type category
$types->registerPluginCategory(new PluginTagQuestionTypeCategory());
// Register question type
$types->registerPluginQuestionType(new PluginTagQuestionType());
// Register question type itil fields
$destination_manager->registerPluginCommonITILConfigField(
AbstractCommonITILFormDestination::class,
new PluginTagDestinationField(),
);
// Register mapper for legacy question type
$type_mapper->registerPluginQuestionTypeConverter('tag', new PluginTagQuestionType());
}