|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* @package phpBB Gallery |
|
6
|
|
|
* @copyright (c) 2014 nickvergessen |
|
7
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace phpbbgallery\core; |
|
12
|
|
|
|
|
13
|
|
|
class url |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Path from the gallery root, back to phpbb's root |
|
17
|
|
|
*/ |
|
18
|
|
|
private $phpbb_root_path = '../'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Path from the phpbb root, into admin's root |
|
22
|
|
|
*/ |
|
23
|
|
|
private $phpbb_admin_path = 'adm/'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Path from the phpbb root, into gallery's file root |
|
27
|
|
|
*/ |
|
28
|
|
|
private $phpbb_gallery_file_path = 'files/phpbbgallery/'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Path from the phpbb root, into gallery's root |
|
32
|
|
|
*/ |
|
33
|
|
|
private $phpbb_gallery_path = 'gallery/'; |
|
34
|
|
|
|
|
35
|
|
|
const IMAGE_PATH = 'images/'; |
|
36
|
|
|
const UPLOAD_PATH = 'core/source/'; |
|
37
|
|
|
const THUMBNAIL_PATH = 'core/mini/'; |
|
38
|
|
|
const MEDIUM_PATH = 'core/medium/'; |
|
39
|
|
|
const IMPORT_PATH = 'import/'; |
|
40
|
|
|
|
|
41
|
|
|
private $phpbb_gallery_relative = ''; |
|
42
|
|
|
private $phpbb_gallery_full_path = ''; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Constructor |
|
46
|
|
|
* |
|
47
|
|
|
* @param \phpbb\template\template $template |
|
48
|
|
|
* @param \phpbb\request\request $request |
|
49
|
|
|
* @param \phpbb\config\config $config |
|
50
|
|
|
* @param $phpbb_root_path |
|
51
|
|
|
* @param $php_ext |
|
52
|
|
|
* @param string $phpbb_admin_path |
|
53
|
|
|
*/ |
|
54
|
105 |
|
public function __construct(\phpbb\template\template $template, \phpbb\request\request $request, \phpbb\config\config $config, $phpbb_root_path, $php_ext, $phpbb_admin_path = 'adm/') |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
105 |
|
$this->template = $template; |
|
|
|
|
|
|
57
|
105 |
|
$this->request = $request; |
|
|
|
|
|
|
58
|
105 |
|
$this->config = $config; |
|
|
|
|
|
|
59
|
105 |
|
$this->phpbb_root_path = $phpbb_root_path; |
|
60
|
105 |
|
$this->phpbb_admin_path = $this->phpbb_root_path . $phpbb_admin_path; |
|
61
|
105 |
|
$this->php_ext = '.' . $php_ext; |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
105 |
|
$this->phpbb_gallery_relative = self::beautiful_path($this->phpbb_root_path . $this->phpbb_gallery_path); |
|
64
|
105 |
|
$this->phpbb_gallery_full_path = self::beautiful_path(generate_board_url() . '/' . $this->phpbb_gallery_path, true); |
|
|
|
|
|
|
65
|
105 |
|
} |
|
66
|
|
|
|
|
67
|
6 |
|
public function path($directory = 'gallery') |
|
68
|
|
|
{ |
|
69
|
6 |
|
switch ($directory) |
|
70
|
|
|
{ |
|
71
|
6 |
|
case 'gallery': |
|
72
|
3 |
|
return $this->phpbb_gallery_relative; |
|
73
|
5 |
|
case 'ext': |
|
74
|
1 |
|
return $this->phpbb_root_path . 'ext/phpbbgallery/core/'; |
|
75
|
5 |
|
case 'phpbb': |
|
76
|
5 |
|
return $this->phpbb_root_path; |
|
77
|
3 |
|
case 'admin': |
|
78
|
1 |
|
return $this->phpbb_admin_path; |
|
79
|
3 |
|
case 'relative': |
|
80
|
1 |
|
return $this->phpbb_gallery_path; |
|
81
|
3 |
|
case 'full': |
|
82
|
3 |
|
return $this->phpbb_gallery_full_path; |
|
83
|
1 |
|
case 'board': |
|
84
|
1 |
|
return generate_board_url() . '/'; |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
1 |
|
case 'images': |
|
87
|
1 |
|
return $this->phpbb_root_path . 'ext/phpbbgallery/core/' . self::IMAGE_PATH; |
|
88
|
1 |
|
case 'upload': |
|
89
|
1 |
|
return $this->phpbb_root_path . $this->phpbb_gallery_file_path . self::UPLOAD_PATH; |
|
90
|
1 |
|
case 'thumbnail': |
|
91
|
1 |
|
return $this->phpbb_root_path . $this->phpbb_gallery_file_path . self::THUMBNAIL_PATH; |
|
92
|
1 |
|
case 'medium': |
|
93
|
1 |
|
return $this->phpbb_root_path . $this->phpbb_gallery_file_path . self::MEDIUM_PATH; |
|
94
|
1 |
|
case 'import': |
|
95
|
1 |
|
return $this->phpbb_root_path . $this->phpbb_gallery_file_path . self::IMPORT_PATH; |
|
96
|
|
|
|
|
97
|
|
|
// stupid phpbb-upload class prepends the rootpath itself. |
|
98
|
1 |
|
case 'upload_noroot': |
|
99
|
1 |
|
return $this->phpbb_gallery_file_path . self::UPLOAD_PATH; |
|
100
|
1 |
|
case 'thumbnail_noroot': |
|
101
|
1 |
|
return $this->phpbb_gallery_file_path . self::THUMBNAIL_PATH; |
|
102
|
1 |
|
case 'medium_noroot': |
|
103
|
1 |
|
return $this->phpbb_gallery_file_path . self::MEDIUM_PATH; |
|
104
|
1 |
|
case 'import_noroot': |
|
105
|
1 |
|
return $this->phpbb_gallery_file_path . self::IMPORT_PATH; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
return false; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
4 |
|
public function append_sid() |
|
112
|
|
|
{ |
|
113
|
4 |
|
$args = func_get_args(); |
|
114
|
4 |
|
if (is_array($args[0])) |
|
115
|
|
|
{ |
|
116
|
|
|
// Little problem from the duplicated call to func_get_args(); |
|
117
|
1 |
|
$args = $args[0]; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
4 |
|
if (in_array($args[0], array('phpbb', 'admin', 'relative', 'full', 'board', 'ext'))) |
|
121
|
|
|
{ |
|
122
|
3 |
|
$mode = array_shift($args); |
|
123
|
3 |
|
$args[0] = $this->path($mode) . $this->phpEx_file($args[0]); |
|
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
else |
|
126
|
|
|
{ |
|
127
|
2 |
|
$args[0] = $this->path() . $this->phpEx_file($args[0]); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
4 |
|
if (isset($args[1])) |
|
131
|
|
|
{ |
|
132
|
4 |
|
$args[1] .= '';//@todo: phpbb_gallery::$display_popup; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
$params = $args + array( |
|
136
|
4 |
|
0 => '', |
|
137
|
|
|
1 => '',//@todo: phpbb_gallery::$display_popup, |
|
138
|
|
|
2 => true, |
|
139
|
|
|
3 => false, |
|
140
|
|
|
); |
|
141
|
|
|
|
|
142
|
4 |
|
return append_sid($params[0], $params[1], $params[2], $params[3]); |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
7 |
|
public function show_image($image_id, $size = 'medium') |
|
146
|
|
|
{ |
|
147
|
7 |
|
return $this->phpbb_gallery_full_path . 'image/' . $image_id . '/' . $size; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
1 |
|
public function show_album($album_id) |
|
151
|
|
|
{ |
|
152
|
1 |
|
return $this->phpbb_gallery_full_path . 'album/' . $album_id; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Removes the sid and replaces & with normal & |
|
157
|
|
|
* @param $path |
|
158
|
|
|
* @param $file |
|
159
|
|
|
* @param bool $params |
|
160
|
|
|
* @param bool $is_amp |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
1 |
|
public function create_link($path, $file, $params = false, $is_amp = true) |
|
164
|
|
|
{ |
|
165
|
1 |
|
if ($is_amp && !is_array($params)) |
|
166
|
|
|
{ |
|
167
|
1 |
|
$params = implode('&', explode('&', $params)); |
|
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
1 |
|
return $this->append_sid($path, $file, $params, false, ''); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function redirect() |
|
174
|
|
|
{ |
|
175
|
|
|
redirect($this->append_sid(func_get_args())); |
|
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
6 |
|
public function phpEx_file($file) |
|
179
|
|
|
{ |
|
180
|
6 |
|
if ((substr($file, -1) == '/') || (strlen($file) == 0)) |
|
181
|
|
|
{ |
|
182
|
|
|
// it's no file, so no .php here. |
|
183
|
1 |
|
return $file; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/*if ($file == 'image_page') |
|
187
|
|
|
{ |
|
188
|
|
|
//@todo |
|
189
|
|
|
$file = 'viewimage'; |
|
190
|
|
|
}*/ |
|
191
|
|
|
|
|
192
|
6 |
|
return $file . $this->php_ext; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
1 |
|
public function _include($file, $path = 'gallery', $sub_directory = 'includes/') |
|
196
|
|
|
{ |
|
197
|
1 |
|
if (!is_array($file)) |
|
198
|
|
|
{ |
|
199
|
1 |
|
include($this->path($path) . $sub_directory . $this->phpEx_file($file)); |
|
|
|
|
|
|
200
|
|
|
} |
|
201
|
|
|
else |
|
202
|
|
|
{ |
|
203
|
|
|
foreach ($file as $real_file) |
|
204
|
|
|
{ |
|
205
|
|
|
$this->_include($real_file, $path, $sub_directory); |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
1 |
|
} |
|
209
|
|
|
|
|
210
|
|
|
public function _file_exists($file, $path = 'gallery', $sub_directory = 'includes/') |
|
211
|
|
|
{ |
|
212
|
|
|
return file_exists($this->path($path) . $sub_directory . $this->phpEx_file($file)); |
|
|
|
|
|
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
public function _is_writable($file, $path = 'gallery', $sub_directory = 'includes/') |
|
216
|
|
|
{ |
|
217
|
|
|
return phpbb_is_writable($this->path($path) . $sub_directory . $this->phpEx_file($file)); |
|
|
|
|
|
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
public function _return_file($file, $path = 'gallery', $sub_directory = 'includes/') |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->path($path) . $sub_directory . $this->phpEx_file($file); |
|
|
|
|
|
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Creates beautiful relative path from ugly relative path |
|
227
|
|
|
* Resolves .. (up directory) |
|
228
|
|
|
* |
|
229
|
|
|
* @author bantu based on phpbb_own_realpath() by Chris Smith |
|
230
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
231
|
|
|
* |
|
232
|
|
|
* @param string ugly path e.g. "../community/../gallery/" |
|
|
|
|
|
|
233
|
|
|
* @param bool is it a full url, so we need to fix teh http:// at the beginning? |
|
|
|
|
|
|
234
|
|
|
* @return string beautiful path e.g. "../gallery/" |
|
235
|
|
|
*/ |
|
236
|
105 |
|
static public function beautiful_path($path, $is_full_url = false) |
|
237
|
|
|
{ |
|
238
|
|
|
// Remove any repeated slashes |
|
239
|
105 |
|
$path = preg_replace('#/{2,}#', '/', $path); |
|
240
|
|
|
|
|
241
|
105 |
|
if ($is_full_url) |
|
242
|
|
|
{ |
|
243
|
|
|
// Fix the double slash, which we just removed. |
|
244
|
105 |
|
if (strpos($path, 'https:/') === 0) |
|
245
|
|
|
{ |
|
246
|
1 |
|
$path = 'https://' . substr($path, 7); |
|
247
|
|
|
} |
|
248
|
105 |
|
else if (strpos($path, 'http:/') === 0) |
|
249
|
|
|
{ |
|
250
|
105 |
|
$path = 'http://' . substr($path, 6); |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
// Break path into pieces |
|
255
|
105 |
|
$bits = explode('/', $path); |
|
256
|
|
|
|
|
257
|
|
|
// Lets get looping, run over and resolve any .. (up directory) |
|
258
|
105 |
|
for ($i = 0, $max = sizeof($bits); $i < $max; $i++) |
|
259
|
|
|
{ |
|
260
|
105 |
|
if ($bits[$i] == '..' && isset($bits[$i - 1]) && $bits[$i - 1][0] != '.') |
|
261
|
|
|
{ |
|
262
|
|
|
// We found a .. and we are able to traverse upwards ... |
|
263
|
1 |
|
unset($bits[$i]); |
|
264
|
1 |
|
unset($bits[$i - 1]); |
|
265
|
|
|
|
|
266
|
1 |
|
$i -= 2; |
|
267
|
1 |
|
$max -= 2; |
|
268
|
|
|
|
|
269
|
1 |
|
$bits = array_values($bits); |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
105 |
|
return implode('/', $bits); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Custom meta_refresh implementation |
|
278
|
|
|
* @param int $time Time in seconds. |
|
279
|
|
|
* @param string $route Route generated by $helper->route |
|
280
|
|
|
*/ |
|
281
|
1 |
|
public function meta_refresh($time, $route) |
|
282
|
|
|
{ |
|
283
|
|
|
// For XHTML compatibility we change back & to & |
|
284
|
1 |
|
$route = str_replace('&', '&', $route); |
|
285
|
1 |
|
$this->template->assign_vars(array( |
|
286
|
1 |
|
'META' => '<meta http-equiv="refresh" content="' . $time . '; url=' . $route . '" />') |
|
287
|
|
|
); |
|
288
|
1 |
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Get URI (prepend domain name to route) |
|
292
|
|
|
* |
|
293
|
|
|
* @param string $route Route generated by $helper->route |
|
294
|
|
|
* return string URI |
|
295
|
|
|
* @return string |
|
296
|
|
|
*/ |
|
297
|
1 |
|
public function get_uri($route) |
|
298
|
|
|
{ |
|
299
|
1 |
|
$url = $this->config['server_name']; |
|
300
|
1 |
|
if ($this->config['force_server_vars'] == 1) |
|
301
|
|
|
{ |
|
302
|
|
|
$url = $this->config['server_protocol'] . $url; |
|
303
|
|
|
} |
|
304
|
|
|
else |
|
305
|
|
|
{ |
|
306
|
1 |
|
$is_secure = $this->request->server('HTTPS', ''); |
|
307
|
1 |
|
if ($is_secure == 'on') |
|
308
|
|
|
{ |
|
309
|
1 |
|
$url = 'https://' . $url; |
|
310
|
|
|
} |
|
311
|
|
|
else |
|
312
|
|
|
{ |
|
313
|
1 |
|
$url = 'http://' . $url; |
|
314
|
|
|
} |
|
315
|
|
|
} |
|
316
|
1 |
|
$split = parse_url($url); |
|
317
|
|
|
|
|
318
|
1 |
|
$uri = $split['scheme'] . '://' . $split['host'] . $route; |
|
319
|
1 |
|
return $uri; |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths