/
hooks.php
executable file
·238 lines (229 loc) · 7.4 KB
/
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
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
<?php
/**
*
* PHP version 5
*
* @category JFusion
* @package JFusionPlugins
* @subpackage phpBB3
* @author JFusion Team <webmaster@jfusion.org>
* @copyright 2008 JFusion. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.jfusion.org
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
/**
* Function that registers the JFusion phpBB3 hooks
*
* @category JFusion
* @package JFusionPlugins
* @subpackage phpBB3
* @author JFusion Team <webmaster@jfusion.org>
* @copyright 2008 JFusion. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.jfusion.org
*
* @param phpbb_hook &$hook
*/
function phpbb_hook_register(&$hook)
{
global $phpbb_root_path, $phpEx, $db, $config, $user;
//Register the hooks
foreach ($hook->hooks as $definition => $hooks) {
foreach ($hooks as $function => $data) {
$callback = $definition == '__global' ? $function : $definition . '_' . $function;
$hook->register(array($definition, $function), array('JFusionHook', $callback));
}
}
}
/**
* JFusion Hooks for phpBB3
*
* @category JFusion
* @package JFusionPlugins
* @subpackage phpBB3
* @author JFusion Team <webmaster@jfusion.org>
* @copyright 2008 JFusion. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.jfusion.org
*/
class JFusionHook {
/**
* Throws an exception at the end of the phpBB3 execution to return to JFusion
*
* @param mixed $hook
*
* @throws RuntimeException
*/
public static function exit_handler($hook) {
//throw an exception to allow Joomla to continue
throw new RuntimeException('phpBB exited.');
}
/**
* @static
* @param $hook
* @param $url
* @param bool|array $params
* @param bool $is_amp
* @param bool $session_id
* @return string
*/
public static function append_sid($hook, $url, $params = false, $is_amp = true, $session_id = false) {
global $_SID, $_EXTRA_URL, $phpbb_hook;
$params_is_array = is_array($params);
// Get anchor
$anchor = '';
$url = str_replace('../', '' , $url);
if (strpos($url, '#') !== false) {
list($url, $anchor) = explode('#', $url, 2);
$anchor = '#' . $anchor;
} else if (!$params_is_array && strpos($params, '#') !== false) {
list($params, $anchor) = explode('#', $params, 2);
$anchor = '#' . $anchor;
}
// Handle really simple cases quickly
if ($_SID == '' && $session_id === false && empty($_EXTRA_URL) && !$params_is_array && !$anchor) {
if ($params === false) {
return $url;
}
$url_delim = (strpos($url, '?') === false) ? '?' : (($is_amp) ? '&' : '&');
return $url . ($params !== false ? $url_delim . $params : '');
}
// Assign sid if session id is not specified
if ($session_id === false) {
$session_id = $_SID;
}
$amp_delim = ($is_amp) ? '&' : '&';
$url_delim = (strpos($url, '?') === false) ? '?' : $amp_delim;
// Appending custom url parameter?
$append_url = (!empty($_EXTRA_URL)) ? implode($amp_delim, $_EXTRA_URL) : '';
// Use the short variant if possible ;)
if ($params === false) {
// Append session id
if (!$session_id) {
return $url . (($append_url) ? $url_delim . $append_url : '') . $anchor;
} else {
return $url . (($append_url) ? $url_delim . $append_url . $amp_delim : $url_delim) . 'sid=' . $session_id . $anchor;
}
}
// Build string if parameters are specified as array
if (is_array($params)) {
$output = array();
foreach ($params as $key => $item) {
if ($item === null) {
continue;
}
if ($key == '#') {
$anchor = '#' . $item;
continue;
}
$output[] = $key . '=' . $item;
}
$params = implode($amp_delim, $output);
}
// Append session id and parameters (even if they are empty)
// If parameters are empty, the developer can still append his/her parameters without caring about the delimiter
return $url . (($append_url) ? $url_delim . $append_url . $amp_delim : $url_delim) . $params . ((!$session_id) ? '' : $amp_delim . 'sid=' . $session_id) . $anchor;
}
/**
* Function that allows for the user object to contain the correct url
*
* @param $hook
*/
public static function phpbb_user_session_handler($hook) {
/**
* @var $request \phpbb\request\request
* @var $user \phpbb\user
*/
//we need to change the $user->page array as it does not detect some POST values
global $user, $request;
//set our current phpBB3 filename
$mainframe = JFusionFactory::getApplication();
$jfile = $mainframe->input->get('jfile');
if (empty($jfile)) {
$jfile = 'index.php';
}
$user->page['page_name'] = $jfile;
//parse our GET variables
$list = $request->variable_names(\phpbb\request\request_interface::GET);
$get_vars = array();
foreach ($list as $var) {
$get_vars[$var] = $request->variable($var, null, false, \phpbb\request\request_interface::GET);
}
//Some params where changed to POST therefore we need to include some of those
$post_include = array('i', 'mode');
foreach ($post_include as $value) {
if ($request->is_set_post($value) && empty($get_vars[$value])) {
$get_vars[$value] = $request->variable($value, null, false, \phpbb\request\request_interface::POST);
}
}
//unset Joomla vars
unset($get_vars['option'], $get_vars['Itemid'], $get_vars['jFusion_Route'], $get_vars['jfile']);
$safeHtmlFilter = JFilterInput::getInstance(array(), array(), 1, 1);
$query_array = array();
foreach ($get_vars as $key => $value) {
$query_array[] = $safeHtmlFilter->clean($key, gettype($key)) . '=' . $safeHtmlFilter->clean($value, gettype($value));
}
$query_string = implode('&', $query_array);
$user->page['query_string'] = $query_string;
if (empty($query_string)) {
$user->page['page'] = $jfile;
} else {
$user->page['page'] = $jfile . '?' . $query_string;
}
//set the script path to allow for email notifications with correct URLs
$Itemid = $mainframe->input->getInt('Itemid');
//Get the base URL to the specific JFusion plugin
$baseURL = JFusionFunction::getPluginURL($Itemid, false);
if (substr($baseURL, -1) != '/') {
//non-SEF mode
global $source_url;
$uri = new JURI($source_url);
$path = $uri->getPath();
if (substr($path, -1) != '/') {
$path.= '/';
}
$user->page['script_path'] = $path;
$user->page['root_script_path'] = $path;
$user->host = $uri->getHost();
} else {
//SEF mode
$uri = new JURI($baseURL);
$path = $uri->getPath();
$user->page['script_path'] = $path;
$user->page['root_script_path'] = $path;
$uri = new JURI(JURI::base());
$user->host = $uri->getHost();
}
}
/**
* @static
* @param $hook
* @param $handle
* @param bool $include_once
*/
public static function template_display($hook, $handle, $include_once = true) {
global $template, $jname;
$params = JFusionFactory::getParams($jname);
$lostpassword_url = $params->get('lostpassword_url');
$register_url = $params->get('register_url');
if (!empty($lostpassword_url)) {
$template->_tpldata['.'][0]['U_SEND_PASSWORD'] = $lostpassword_url;
}
if (!empty($register_url)) {
$template->_tpldata['.'][0]['U_REGISTER'] = $register_url;
}
}
/**
* Function not implemented
*
* @param string $errno
* @param string $msg_text
* @param string $errfile
* @param string $errline
*/
public static function msg_handler($errno, $msg_text, $errfile, $errline) {
msg_handler($errno, $msg_text, $errfile, $errline);
}
}