-
Notifications
You must be signed in to change notification settings - Fork 14
/
do_hooks.php
166 lines (144 loc) · 3.99 KB
/
do_hooks.php
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
<?php
/**
* @package TinyPortal
* @version 3.0.0
* @author IchBin - http://www.tinyportal.net
* @founder Bloc
* @license MPL 2.0
*
* The contents of this file are subject to the Mozilla Public License Version 2.0
* (the "License"); you may not use this package except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Copyright (C) - The TinyPortal Team
*
*/
global $hooks, $mod_name, $forum_version;
$hooks = [
'integrate_pre_load' => '$boarddir/TinyPortal/Integrate.php|TinyPortal\Integrate::hookPreLoad'
];
$mod_name = 'TinyPortal';
// ---------------------------------------------------------------------------------------------------------------------
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF')) {
require_once dirname(__FILE__) . '/SSI.php';
}
elseif (!defined('SMF')) {
exit('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');
}
if (SMF == 'SSI') {
// Let's start the main job
install_mod();
// and then let's throw out the template! :P
obExit(null, null, true);
}
else {
setup_hooks();
}
function install_mod()
{
global $context, $mod_name;
$context['mod_name'] = $mod_name;
$context['sub_template'] = 'install_script';
$context['page_title_html_safe'] = 'Hook installer for: ' . $mod_name;
if (isset($_GET['action'])) {
$context['uninstalling'] = $_GET['action'] == 'uninstall' ? true : false;
}
$context['html_headers'] .= '
<style type="text/css">
.buttonlist ul {
margin:0 auto;
display:table;
}
</style>';
// Sorry, only logged in admins...
isAllowedTo('admin_forum');
if (isset($context['uninstalling'])) {
setup_hooks();
}
}
function setup_hooks()
{
global $context, $hooks, $forum_version;
$smf21 = true;
if (isset($forum_version) && strpos($forum_version, '2.0') !== false) {
$smf21 = false;
}
elseif (defined('SMF_VERSION') && strpos(SMF_VERSION, '2.0') !== false) {
$smf21 = false;
}
elseif ((SMF == 'SSI') && !function_exists('ssi_version')) {
$smf21 = false;
}
if ($smf21 == false) {
define('SMF_INTEGRATION_SETTINGS', serialize(['integrate_menu_buttons' => 'install_menu_button', ]));
$hooks['integrate_pre_include'] = '$sourcedir/TPCompat.php';
$hooks['integrate_pre_load'] = 'TPHookPreLoad';
}
$integration_function = empty($context['uninstalling']) ? 'add_integration_function' : 'remove_integration_function';
foreach ($hooks as $hook => $function) {
if (strpos($function, ',') === false) {
$integration_function($hook, $function);
}
else {
$tmpFunc = explode(',', $function);
foreach ($tmpFunc as $func) {
$integration_function($hook, $func);
}
}
}
if (!empty($context['uninstalling'])) {
updateSettings(['integrate_default_action' => '']);
}
$context['installation_done'] = true;
}
function install_menu_button(&$buttons)
{
global $boardurl, $context;
$context['sub_template'] = 'install_script';
$context['current_action'] = 'install';
$buttons['install'] = [
'title' => 'Installation script',
'show' => allowedTo('admin_forum'),
'href' => $boardurl . '/do_hooks.php',
'active_button' => true,
'sub_buttons' => [
],
];
}
function template_install_script()
{
global $boardurl, $context, $mod_name;
echo '
<div class="tborder login"">
<div class="cat_bar">
<h3 class="catbg">
Welcome to the install script of the mod: ' . $context['mod_name'] . '
</h3>
</div>
<div class="roundframe centertext">';
if (!isset($context['installation_done'])) {
echo '
<strong>Please select the action you want to perform:</strong>
<div class="buttonlist">
<ul>
<li>
<a class="active" href="' . $boardurl . '/do_hooks.php?action=install">
<span>Install</span>
</a>
</li>
<li>
<a class="active" href="' . $boardurl . '/do_hooks.php?action=uninstall">
<span>Uninstall</span>
</a>
</li>
</ul>
</div>';
}
else {
echo '<strong>Database adaptation successful!</strong>';
}
echo '
</div>
</div>';
}