forked from SimpleMachines/SimpleDesk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleDesk-AdminPlugins.php
More file actions
341 lines (295 loc) · 15.9 KB
/
SimpleDesk-AdminPlugins.php
File metadata and controls
341 lines (295 loc) · 15.9 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
/**************************************************************
* Simple Desk Project - www.simpledesk.net *
***************************************************************
* An advanced help desk modification built on SMF *
***************************************************************
* *
* * Copyright 2025 - SimpleDesk.net *
* *
* This file and its contents are subject to the license *
* included with this distribution, license.txt, which *
* states that this software is New BSD Licensed. *
* Any questions, please contact SimpleDesk.net *
* *
***************************************************************
* SimpleDesk Version: 2.1.1 *
* File Info: SimpleDesk-AdminPlugins.php *
**************************************************************/
/**
* This file handles the core of SimpleDesk's plugin system administration.
*
* @package source
* @since 2.0
*/
if (!defined('SMF'))
die('Hacking attempt...');
/**
* The start point for all interaction with the SimpleDesk plugins.
*
* Directed here from the main administration centre, after permission checks and a few dependencies loaded, this deals solely with managing custom fields.
*
* @since 2.0
*/
function shd_admin_plugins()
{
global $context, $scripturl, $sourcedir, $settings, $txt, $modSettings;
loadTemplate('sd_template/SimpleDesk-AdminPlugins');
shd_load_language('ManageSettings');
loadTemplate(false, array('admin', 'helpdesk_admin'));
$context['shd_enabled_plugins'] = !empty($modSettings['shd_enabled_plugins']) ? explode(',', $modSettings['shd_enabled_plugins']) : array();
// 1. Look at the plugin directory and figure out whether or not there are some plugins.
$plugins = array();
$plugindir = $sourcedir . '/sd_plugins_source';
if (is_dir($plugindir))
{
$handle = opendir($plugindir);
while ($dir_entry = readdir($handle))
{
if (is_dir($plugindir . '/' . $dir_entry) && $dir_entry != '.' && $dir_entry != '..' && file_exists($plugindir . '/' . $dir_entry . '/index.php'))
{
include_once($plugindir . '/' . $dir_entry . '/index.php');
$function = 'shdplugin_' . $dir_entry;
if (function_exists($function))
$plugins[$dir_entry] = $function();
}
}
closedir($handle);
}
// 2. Figure out what language stuff is going on
$langtemplates = array();
if (is_dir($settings['default_theme_dir'] . '/languages/sd_plugins_lang/'))
{
$langfilelist = opendir($settings['default_theme_dir'] . '/languages/sd_plugins_lang/');
while ($langfile_entry = readdir($langfilelist))
if (preg_match('~([a-z0-9]+)\.([a-z\-\_]+)\.php$~i', $langfile_entry, $matches))
$langtemplates[$matches[1]][$matches[2]] = true;
closedir($langfilelist);
}
// 3. Figure out what shape the plugins are in
foreach ($plugins as $id => $plugin)
{
// 3.1 Is installable?
if (empty($plugins[$id]['details']['compatibility']))
$plugins[$id]['details']['compatibility'] = array($txt['unknown']);
// Check all compatible versions.
$plugins[$id]['installable'] = (bool) array_reduce($plugin['details']['compatibility'], function($a, $b) {
// Bitwise operator.
return $a | version_compare(SHD_VERSION, $b) == 1;
});
// 3.2 Admin language files? (That also means, let's get a list of known languages for this mod)
$plugins[$id]['languages'] = array();
if (!empty($plugin['includes']['language']['hdadmin']))
{
$include = is_array($plugin['includes']['language']['hdadmin']) ? $plugin['includes']['language']['hdadmin'] : array($plugin['includes']['language']['hdadmin']);
if (!empty($include[0]))
$plugins[$id]['languages'] = array_keys($langtemplates[$include[0]]);
foreach ($include as $langfile)
shd_load_language('sd_plugins_lang/' . $langfile);
}
// 3.3 Sort out some strings - now we've loaded the lang file
if (!empty($txt[$plugin['details']['title']]))
$plugins[$id]['details']['title'] = $txt[$plugin['details']['title']];
if (!empty($plugin['details']['description']) && !empty($txt[$plugin['details']['description']]))
$plugins[$id]['details']['description'] = $txt[$plugin['details']['description']];
if (empty($plugin['details']['author']))
$plugins[$id]['details']['author'] = $txt['unknown'];
// 3.4 Is it enabled?
$plugins[$id]['enabled'] = in_array($id, $context['shd_enabled_plugins']);
$plugins[$id]['details']['acp_url'] = !empty($plugin['details']['acp_url']) && $plugins[$id]['enabled'] ? (strpos($plugin['details']['acp_url'], 'http') === false ? $scripturl . '?' . $plugin['details']['acp_url'] . ';' . $context['session_var'] . '=' . $context['session_id'] : $plugin['details']['acp_url']) : false;
}
// 3. Throw it at the template.
$context['sub_template'] = 'shd_plugin_listing';
$context['plugins'] = $plugins;
$context['page_title'] = $txt['shd_admin_plugins'];
// 4. Are we saving any changes?
if (isset($_POST['save']))
{
checkSession();
$list_of_settings = shd_list_hooks();
$setting_changes = array();
foreach ($list_of_settings as $item)
$setting_changes[$item] = array();
$post_var_prefix = empty($_POST['js_worked']) ? 'feature_plain_' : 'feature_';
foreach ($plugins as $id => $plugin)
{
if (empty($plugin['installable']))
continue; // GET OUT YE WRONGLY VERSIONED SHI--STUFF
// Is it enabled, if so, go do the voodoo that you do so well!!!!
if (!empty($_POST[$post_var_prefix . $id]))
{
$setting_changes['shd_enabled_plugins'][] = $id;
foreach ($plugin['includes']['source'] as $include_point => $include_file)
if (isset($setting_changes['shd_include_' . $include_point]) && file_exists($sourcedir . '/sd_plugins_source/' . $id . '/' . $include_file))
$setting_changes['shd_include_' . $include_point][] = $id . '/' . $include_file;
foreach ($plugin['includes']['language'] as $include_point => $include_file)
if (isset($setting_changes['shd_includelang_' . $include_point]))
$setting_changes['shd_includelang_' . $include_point][] = $include_file;
foreach ($plugin['hooks'] as $include_point => $function)
if (isset($setting_changes['shd_hook_' . $include_point]))
$setting_changes['shd_hook_' . $include_point][] = $function;
}
// Is there a call back for settings?
if (isset($plugin['setting_callback']))
{
$returned_settings = $plugin['setting_callback'](!empty($_POST[$post_var_prefix . $id]));
if (!empty($returned_settings))
$setting_changes = array_merge($setting_changes, $returned_settings);
}
// Standard save callback?
if (isset($plugin['on_save']))
$plugin['on_save']();
}
// OK, so whatever we have at this point, we know we're going to be implode'ing and saving.
foreach ($setting_changes as $setting => $array)
$setting_changes[$setting] = implode(',', $array);
updateSettings($setting_changes);
// Any post save things?
foreach ($plugins as $id => $plugin)
// Standard save callback?
if (isset($plugin['save_callback']))
$plugin['save_callback'](!empty($_POST[$post_var_prefix . $id]));
// We know we did something.
shd_admin_log('admin_plugins', array('action' => 'update'));
redirectexit('action=admin;area=helpdesk_plugins;' . $context['session_var'] . '=' . $context['session_id']);
}
}
/**
* Unregister a plugin, to be called from plugin uninstallers.
*
* Expects $context['uninstall_plugin'] to have been defined, as an array with up to four keys:
* - 'name' as a string of the plugin's name (required)
* - 'sources' as an array of files to be purged from source file loaders (e.g. SDPluginMymod.php)
* - 'languages' as an array of files to be purged from language loaders (e.g. SDPluginMymod)
* - 'functions' as an array of functions to be purged from function calls (e.g. shd_mymod_helpdesk, shd_mymod_adminopts)
*
* @since 2.0
*/
function shd_unregister_plugin()
{
global $context, $modSettings;
// Make sure we're dealing with something sensible
if (empty($context['uninstall_plugin']['sources']))
$context['uninstall_plugin']['sources'] = array();
foreach ($context['uninstall_plugin']['sources'] as $id => $file)
$context['uninstall_plugin']['sources'][$id] = $context['uninstall_plugin']['name'] . '/' . $file;
// Now language files
if (empty($context['uninstall_plugin']['languages']))
$context['uninstall_plugin']['languages'] = array();
// Now functions
if (empty($context['uninstall_plugin']['functions']))
$context['uninstall_plugin']['functions'] = array();
// Get all the hook points
$hooks = shd_list_hooks();
$changes = array();
foreach ($hooks as $hookpoint)
{
$hook = explode('_', $hookpoint);
if (empty($modSettings[$hookpoint]))
continue;
switch ($hook[1])
{
case 'include':
$hooked = explode(',', $modSettings[$hookpoint]);
$hooked = array_diff($hooked, $context['uninstall_plugin']['sources']);
$changes[$hookpoint] = implode(',', $hooked);
break;
case 'includelang':
$hooked = explode(',', $modSettings[$hookpoint]);
$hooked = array_diff($hooked, $context['uninstall_plugin']['languages']);
$changes[$hookpoint] = implode(',', $hooked);
break;
case 'hook':
$hooked = explode(',', $modSettings[$hookpoint]);
$hooked = array_diff($hooked, $context['uninstall_plugin']['functions']);
$changes[$hookpoint] = implode(',', $hooked);
break;
case 'enabled':
$hooked = explode(',', $modSettings[$hookpoint]);
$hooked = array_diff($hooked, array($context['uninstall_plugin']['name']));
$changes[$hookpoint] = implode(',', $hooked);
break;
}
}
// Keep track of this.
shd_admin_log('admin_plugins', array('action' => 'remove'));
updateSettings($changes, true);
}
function shd_list_hooks()
{
global $context;
// This is our master set of hooks and stuff, so FOR THE LOVE OF DEITIES, GET IT RIGHT.
$hooks = array(
'shd_enabled_plugins', // for the list of plugins generally
// File loading - sources
'shd_include_init', // source files to include on SD init, i.e. every page load when the helpdesk is active
'shd_include_helpdesk', // source files to include when going into the helpdesk (action=helpdesk)
'shd_include_hdadmin', // source files to include when going into any part of the helpdesk admin
'shd_include_hdprofile', // source files to include when going into any part of the helpdesk profile
// File loading - lang files
'shd_includelang_init', // language files to include on SD init, i.e. every page load when the helpdesk is active
'shd_includelang_helpdesk', // language files to include when going into the helpdesk (action=helpdesk)
'shd_includelang_hdadmin', // language files to include when going into any part of the helpdesk admin
'shd_includelang_hdprofile', // language files to include when going into any part of the helpdesk profile
'shd_includelang_who', // language files to include when going into Who's Online
// General hooks
'shd_hook_actions', // functions to run when looking at the action array (where action=x is evaluated)
'shd_hook_perms', // functions to add permissions (relevant file probably should be included in the _include_init hook)
'shd_hook_permstemplate', // functions to add permissions to any of the templates (relevant file probably should be included in the _include_init hook)
'shd_hook_prefs', // functions to add preferences (relevant file probably should be included in the _include_init hook)
'shd_hook_newticket', // functions to call when just a new ticket is made
'shd_hook_newreply', // functions to call when a new reply is made
'shd_hook_modpost', // functions to call when a ticket or reply is edited (since all kinds of things might be altered)
'shd_hook_assign', // functions to call when a ticket is assigned to someone
'shd_hook_buffer', // functions to call prior to the final page generation
'shd_hook_after_main', // functions to call after action=helpdesk has been evaluated but before template calls are made
'shd_hook_boardindex_before', // functions to call before setting up the injected boardindex
'shd_hook_boardindex_after', // functions to call after setting up the injected boardindex
'shd_hook_deleteticket', // functions to call just before actually deleting (softly) a ticket
'shd_hook_deletereply', // functions to call just before actually deleting (softly) a reply
'shd_hook_permadeleteticket', // functions to call just before truly deleting a ticket
'shd_hook_permadeletereply', // functions to call just before truly deleting a reply
'shd_hook_restoreticket', // functions to call just before restoring a previously deleted ticket
'shd_hook_restorereply', // functions to call just before restoring a previously deleted reply
'shd_hook_markunread', // functions to call just before marking a ticket unread
'shd_hook_markresolve', // functions to call just before marking a ticket resolved
'shd_hook_markunresolve', // functions to call just before marking a ticket unresolved
'shd_hook_relations', // functions to call just before setting/removing ticket relationships
'shd_hook_movedept', // functions to call just before moving a ticket between departments
'shd_hook_tickettotopic', // functions to call just before moving a ticket into a forum topic
'shd_hook_topictoticket', // functions to call just before moving a forum topic into a ticket
// Admin hooks
'shd_hook_admin_display', // to extend the SD Admin > Options > Display Options
'shd_hook_admin_posting', // to extend the SD Admin > Options > Posting Options
'shd_hook_admin_admin', // to extend the SD Admin > Options > Admin Options
'shd_hook_admin_standalone', // to extend the SD Admin > Options > Standalone Options
'shd_hook_admin_actionlog', // to extend the SD Admin > Options > Action Log Options
'shd_hook_admin_notify', // to extend the SD Admin > Options > Notifications Options
// Template hooks
'shd_hook_tpl_after_tkt_detail', // functions to call after the ticket details (before additional details), in the ticket level left column
'shd_hook_tpl_after_add_detail', // functions to call after the ticket details (after additional details), in the ticket level left column
'shd_hook_tpl_display_lcol', // functions to call for adding into the reply-level left column in a ticket view (it should modify $context['leftcolumn_templates'] to add entries for template_*() to be called)
// Menu hooks - called after the rest of menu configuration is done (meaning menu items may or may not exist depending on permissions)
'shd_hook_mainmenu', // functions to call when looking at the main menu
'shd_hook_profilemenu', // functions to call when specifically modifying the profile menu
'shd_hook_adminmenu', // functions to call when specifically modifying the admin menu
// Area level hooks
'shd_hook_init', // functions to run as soon as main SD initialisation has completed (SD permissions are loaded by here)
'shd_hook_helpdesk', // functions to run when starting the main helpdesk (before going off to subactions)
'shd_hook_hdadmin', // functions to run when starting the main SimpleDesk admin area (probably should include via _include_hdadmin)
'shd_hook_hdadminopts', // functions to run when working in the SimpleDesk options submenu structure (probably should include via _include_hdadmin)
'shd_hook_hdadmininfo', // functions to run when working in the SimpleDesk info submenu structure (probably should include via _include_hdadmin)
'shd_hook_hdadminoptssrch', // functions to run when setting up admin panel search for SimpleDesk options submenu structure (probably should include via _include_hdadmin)
'shd_hook_hdprofile', // functions to call when going into the helpdesk profile area
);
if (!empty($context['master_action_list']))
{
foreach ($context['master_action_list'] as $action)
{
$hooks[] = 'shd_hook_action_' . $action;
$hooks[] = 'shd_include_action_' . $action;
$hooks[] = 'shd_includelang_action_' . $action;
}
}
return $hooks;
}