Repository navigation
Expand file tree
/
Copy pathsetup.php
More file actions
199 lines (168 loc) · 7.05 KB
/
Copy pathsetup.php
File metadata and controls
199 lines (168 loc) · 7.05 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
<?php
/*
-------------------------------------------------------------------------
Tag plugin for GLPI
Copyright (C) 2003-2017 by the Tag Development Team.
https://github.com/pluginsGLPI/tag
-------------------------------------------------------------------------
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/>.
--------------------------------------------------------------------------
*/
define ('PLUGIN_TAG_VERSION', '2.6.0');
// Minimal GLPI version, inclusive
define("PLUGIN_TAG_MIN_GLPI", "9.4");
// Maximum GLPI version, exclusive
define("PLUGIN_TAG_MAX_GLPI", "9.5");
/**
* Check configuration process
*
* @param boolean $verbose Whether to display message on failure. Defaults to false
*
* @return boolean
*/
function plugin_tag_check_config($verbose = false) {
return true;
}
/**
* Init hooks of the plugin.
* REQUIRED
*
* @return void
*/
function plugin_init_tag() {
global $PLUGIN_HOOKS, $UNINSTALL_TYPES, $CFG_GLPI;
$PLUGIN_HOOKS['csrf_compliant']['tag'] = true;
$plugin = new Plugin();
if ($plugin->isInstalled("tag") && $plugin->isActivated("tag")) {
// define list of itemtype which can be associated with tags
$CFG_GLPI['plugin_tag_itemtypes'] = [
__('Assets') => ['Computer', 'Monitor', 'Software', 'NetworkEquipment',
'Peripheral', 'Printer', 'CartridgeItem', 'ConsumableItem',
'Phone'],
__('Assistance') => ['Ticket', 'Problem', 'Change', 'TicketRecurrent',
'TicketTemplate'],
__('Management') => ['Budget', 'Supplier', 'Contact', 'Contract', 'Document'],
__('Tools') => ['Project', 'Reminder', 'RSSFeed', 'KnowbaseItem'],
__('Administration') => ['User', 'Group', 'Entity', 'Profile'],
__('Setup') => ['SLA', 'SlaLevel', 'Link'],
];
if ($plugin->isInstalled('appliances') && $plugin->isActivated('appliances')) {
$CFG_GLPI['plugin_tag_itemtypes'][__('Assets')][] = 'PluginAppliancesAppliance';
}
// Plugin Webapplication
if ($plugin->isInstalled('webapplications') && $plugin->isActivated('webapplications')) {
$CFG_GLPI['plugin_tag_itemtypes'][__('Assets')][] = 'PluginWebapplicationsWebapplication';
}
// Plugin fusioninventory
if ($plugin->isInstalled('fusioninventory') && $plugin->isActivated('fusioninventory')) {
$CFG_GLPI['plugin_tag_itemtypes'][__('FusionInventory')][] = 'PluginFusioninventoryTask';
}
// add link on plugin name in Configuration > Plugin
$PLUGIN_HOOKS['config_page']['tag'] = "front/tag.php";
// require spectrum (for glpi >= 9.2)
$CFG_GLPI['javascript']['config']['commondropdown']['PluginTagTag'] = ['colorpicker'];
// Plugin use specific massive actions
$PLUGIN_HOOKS['use_massive_action']['tag'] = true;
// Plugin uninstall : after uninstall action
if ($plugin->isInstalled("uninstall") && $plugin->isActivated("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
$PLUGIN_HOOKS['pre_item_form']['tag'] = ['PluginTagTag', 'preItemForm'];
$PLUGIN_HOOKS['pre_kanban_content']['tag'] = ['PluginTagTag', 'preKanbanContent'];
// plugin datainjection
$PLUGIN_HOOKS['plugin_datainjection_populate']['tag'] = "plugin_datainjection_populate_tag";
// add needed javascript & css files
$PLUGIN_HOOKS['add_javascript']['tag'][] = 'js/common.js';
$PLUGIN_HOOKS['add_css']['tag'][] = 'css/tag.css';
if (Session::isMultiEntitiesMode()) {
$PLUGIN_HOOKS['add_javascript']['tag'][] = 'js/entity.js';
}
// hook on object changes
if ($itemtype = PluginTagTag::getCurrentItemtype()) {
if (PluginTagTag::canItemtype($itemtype)) {
$PLUGIN_HOOKS['item_add']['tag'][$itemtype] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS['pre_item_update']['tag'][$itemtype] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS['pre_item_purge']['tag'][$itemtype] = ['PluginTagTagItem', 'purgeItem'];
}
}
Plugin::registerClass('PluginTagProfile', ['addtabon' => ['Profile']]);
}
}
/**
* Get the name and the version of the plugin
* REQUIRED
*
* @return array
*/
function plugin_version_tag() {
return [
'name' => __('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="../plugins/tag/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
]
]
];
}
/**
* Check pre-requisites before install
* OPTIONNAL, but recommanded
*
* @return boolean
*/
function plugin_tag_check_prerequisites() {
//Version check is not done by core in GLPI < 9.2 but has to be delegated to core in GLPI >= 9.2.
if (!method_exists('Plugin', 'checkGlpiVersion')) {
$version = preg_replace('/^((\d+\.?)+).*$/', '$1', GLPI_VERSION);
$matchMinGlpiReq = version_compare($version, PLUGIN_TAG_MIN_GLPI, '>=');
$matchMaxGlpiReq = version_compare($version, PLUGIN_TAG_MAX_GLPI, '<');
if (!$matchMinGlpiReq || !$matchMaxGlpiReq) {
echo vsprintf(
'This plugin requires GLPI >= %1$s and < %2$s.',
[
PLUGIN_TAG_MIN_GLPI,
PLUGIN_TAG_MAX_GLPI,
]
);
return false;
}
}
return true;
}
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");
}