Skip to content

Commit 41c28f4

Browse files
authored
Merge pull request #7717 from sbulen/temp_hook_enhancements
Improve temporary hook handling
2 parents 8c6916e + 5c7aa65 commit 41c28f4

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

Sources/ManageMaintenance.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,12 +1977,24 @@ function($accumulator, $functions)
19771977
'data' => array(
19781978
'function' => function($data) use ($txt, $scripturl, $context, $filter_url)
19791979
{
1980-
$change_status = array('before' => '', 'after' => '');
1981-
1982-
$change_status['before'] = '<a href="' . $scripturl . '?action=admin;area=maintain;sa=hooks;do=' . ($data['enabled'] ? 'disable' : 'enable') . ';hook=' . $data['hook_name'] . ';function=' . urlencode($data['function_name']) . $filter_url . ';' . $context['admin-hook_token_var'] . '=' . $context['admin-hook_token'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['quickmod_confirm'] . '" class="you_sure">';
1983-
$change_status['after'] = '</a>';
1984-
1985-
return $change_status['before'] . '<span class="main_icons post_moderation_' . $data['status'] . '" title="' . $data['img_text'] . '"></span>' . $change_status['after'];
1980+
// Cannot update temp hooks in any way, really. Just show the appropriate icon.
1981+
if ($data['status'] == 'temp')
1982+
{
1983+
return '<span class="main_icons ' . ($data['hook_exists'] ? 'posts' : 'error') . '" title="' . $data['img_text'] . '"></span>';
1984+
}
1985+
else
1986+
{
1987+
$change_status = array('before' => '', 'after' => '');
1988+
1989+
// Can only enable/disable if it exists...
1990+
if ($data['hook_exists'])
1991+
{
1992+
$change_status['before'] = '<a href="' . $scripturl . '?action=admin;area=maintain;sa=hooks;do=' . ($data['enabled'] ? 'disable' : 'enable') . ';hook=' . $data['hook_name'] . ';function=' . urlencode($data['function_name']) . $filter_url . ';' . $context['admin-hook_token_var'] . '=' . $context['admin-hook_token'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['quickmod_confirm'] . '" class="you_sure">';
1993+
$change_status['after'] = '</a>';
1994+
}
1995+
1996+
return $change_status['before'] . '<span class="main_icons post_moderation_' . $data['status'] . '" title="' . $data['img_text'] . '"></span>' . $change_status['after'];
1997+
}
19861998
},
19871999
'class' => 'centertext',
19882000
),
@@ -2001,6 +2013,8 @@ function($accumulator, $functions)
20012013
<li><span class="main_icons post_moderation_allow"></span> ' . $txt['hooks_disable_legend_exists'] . '</li>
20022014
<li><span class="main_icons post_moderation_moderate"></span> ' . $txt['hooks_disable_legend_disabled'] . '</li>
20032015
<li><span class="main_icons post_moderation_deny"></span> ' . $txt['hooks_disable_legend_missing'] . '</li>
2016+
<li><span class="main_icons posts"></span> ' . $txt['hooks_disable_legend_temp'] . '</li>
2017+
<li><span class="main_icons error"></span> ' . $txt['hooks_disable_legend_temp_missing'] . '</li>
20042018
</ul>'
20052019
),
20062020
),
@@ -2014,7 +2028,8 @@ function($accumulator, $functions)
20142028
'data' => array(
20152029
'function' => function($data) use ($txt, $scripturl, $context, $filter_url)
20162030
{
2017-
if (!$data['hook_exists'])
2031+
// Note: Cannot remove temp hooks via the UI...
2032+
if (!$data['hook_exists'] && $data['status'] != 'temp')
20182033
return '
20192034
<a href="' . $scripturl . '?action=admin;area=maintain;sa=hooks;do=remove;hook=' . $data['hook_name'] . ';function=' . urlencode($data['function_name']) . $filter_url . ';' . $context['admin-hook_token_var'] . '=' . $context['admin-hook_token'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['quickmod_confirm'] . '" class="you_sure">
20202035
<span class="main_icons delete" title="' . $txt['hooks_button_remove'] . '"></span>
@@ -2100,6 +2115,7 @@ function get_integration_hooks_data($start, $per_page, $sort, $filtered_hooks, $
21002115
$function_list += get_defined_functions_in_file($absPath_clean);
21012116

21022117
$hook_exists = isset($function_list[$hookParsedData['call']]) || (substr($hook, -8) === '_include' && isset($files[$absPath_clean]));
2118+
$hook_temp = !empty($context['integration_hooks_temporary'][$hook][$hookParsedData['rawData']]);
21032119
$temp = array(
21042120
'hook_name' => $hook,
21052121
'function_name' => $hookParsedData['rawData'],
@@ -2108,8 +2124,8 @@ function get_integration_hooks_data($start, $per_page, $sort, $filtered_hooks, $
21082124
'file_name' => strtr($hookParsedData['absPath'] ?: ($function_list[$hookParsedData['call']] ?? ''), [$normalized_boarddir => '.']),
21092125
'instance' => $hookParsedData['object'],
21102126
'hook_exists' => $hook_exists,
2111-
'status' => $hook_exists ? ($hookParsedData['enabled'] ? 'allow' : 'moderate') : 'deny',
2112-
'img_text' => $txt['hooks_' . ($hook_exists ? ($hookParsedData['enabled'] ? 'active' : 'disabled') : 'missing')],
2127+
'status' => ($hook_temp ? 'temp' : ($hook_exists ? ($hookParsedData['enabled'] ? 'allow' : 'moderate') : 'deny')),
2128+
'img_text' => $txt['hooks_' . ($hook_exists ? ($hook_temp ? 'temp' : ($hookParsedData['enabled'] ? 'active' : 'disabled')) : 'missing')],
21132129
'enabled' => $hookParsedData['enabled'],
21142130
);
21152131
$sort_array[] = $temp[$sort_types[$sort][0]];

Sources/Subs.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5801,7 +5801,7 @@ function call_integration_hook($hook, $parameters = array())
58015801
*/
58025802
function add_integration_function($hook, $function, $permanent = true, $file = '', $object = false)
58035803
{
5804-
global $smcFunc, $modSettings;
5804+
global $smcFunc, $modSettings, $context;
58055805

58065806
// Any objects?
58075807
if ($object)
@@ -5853,6 +5853,14 @@ function add_integration_function($hook, $function, $permanent = true, $file = '
58535853

58545854
$functions = array_unique(array_merge($functions, array($integration_call)));
58555855
$modSettings[$hook] = implode(',', $functions);
5856+
5857+
// It is handy to be able to know which hooks are temporary...
5858+
if ($permanent !== true)
5859+
{
5860+
if (!isset($context['integration_hooks_temporary']))
5861+
$context['integration_hooks_temporary'] = array();
5862+
$context['integration_hooks_temporary'][$hook][$function] = true;
5863+
}
58565864
}
58575865

58585866
/**

Themes/default/languages/Admin.english.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,16 @@
727727
$txt['hooks_active'] = 'Exists';
728728
$txt['hooks_disabled'] = 'Disabled';
729729
$txt['hooks_missing'] = 'Not found';
730+
$txt['hooks_temp'] = 'Temporary';
730731
$txt['hooks_no_hooks'] = 'There are currently no hooks in the system.';
731732
$txt['hooks_button_remove'] = 'Remove';
732733
$txt['hooks_disable_instructions'] = 'Click on the status icon to enable or disable the hook';
733734
$txt['hooks_disable_legend'] = 'Legend';
734735
$txt['hooks_disable_legend_exists'] = 'the hook exists and is active';
735736
$txt['hooks_disable_legend_disabled'] = 'the hook exists but has been disabled';
736737
$txt['hooks_disable_legend_missing'] = 'the hook has not been found';
738+
$txt['hooks_disable_legend_temp'] = 'the hook is temporary';
739+
$txt['hooks_disable_legend_temp_missing'] = 'temporary hook not found';
737740
$txt['hooks_reset_filter'] = 'No filter';
738741

739742
$txt['board_perms_allow'] = 'Allow';

0 commit comments

Comments
 (0)