Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
functions_acp.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 /**
015 * @ignore
016 */
017 if (!defined('IN_PHPBB'))
018 {
019 exit;
020 }
021
022 /**
023 * Header for acp pages
024 */
025 function adm_page_header($page_title)
026 {
027 global $config, $user, $template;
028 global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
029 global $phpbb_dispatcher, $phpbb_container;
030
031 if (defined('HEADER_INC'))
032 {
033 return;
034 }
035
036 define('HEADER_INC', true);
037
038 // A listener can set this variable to `true` when it overrides this function
039 $adm_page_header_override = false;
040
041 /**
042 * Execute code and/or overwrite adm_page_header()
043 *
044 * @event core.adm_page_header
045 * @var string page_title Page title
046 * @var bool adm_page_header_override Shall we return instead of
047 * running the rest of adm_page_header()
048 * @since 3.1.0-a1
049 */
050 $vars = array('page_title', 'adm_page_header_override');
051 extract($phpbb_dispatcher->trigger_event('core.adm_page_header', compact($vars)));
052
053 if ($adm_page_header_override)
054 {
055 return;
056 }
057
058 $user->update_session_infos();
059
060 // gzip_compression
061 if ($config['gzip_compress'])
062 {
063 if (@extension_loaded('zlib') && !headers_sent())
064 {
065 ob_start('ob_gzhandler');
066 }
067 }
068
069 $template->assign_vars(array(
070 'PAGE_TITLE' => $page_title,
071 'USERNAME' => $user->data['username'],
072
073 'SID' => $SID,
074 '_SID' => $_SID,
075 'SESSION_ID' => $user->session_id,
076 'ROOT_PATH' => $phpbb_root_path,
077 'ADMIN_ROOT_PATH' => $phpbb_admin_path,
078
079 'U_LOGOUT' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout'),
080 'U_ADM_LOGOUT' => append_sid("{$phpbb_admin_path}index.$phpEx", 'action=admlogout'),
081 'U_ADM_INDEX' => append_sid("{$phpbb_admin_path}index.$phpEx"),
082 'U_INDEX' => append_sid("{$phpbb_root_path}index.$phpEx"),
083
084 'T_IMAGES_PATH' => "{$phpbb_root_path}images/",
085 'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/",
086 'T_AVATAR_PATH' => "{$phpbb_root_path}{$config['avatar_path']}/",
087 'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
088 'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/",
089 'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/",
090 'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/",
091
092 'T_FONT_AWESOME_LINK' => !empty($config['allow_cdn']) && !empty($config['load_font_awesome_url']) ? $config['load_font_awesome_url'] : "{$phpbb_root_path}assets/css/font-awesome.min.css?assets_version=" . $config['assets_version'],
093
094 'T_ASSETS_VERSION' => $config['assets_version'],
095
096 'ICON_MOVE_UP' => '<i class="icon acp-icon acp-icon-move-up fa-arrow-circle-up fa-fw" title="' . $user->lang('MOVE_UP') . '"></i>',
097 'ICON_MOVE_UP_DISABLED' => '<i class="icon acp-icon acp-icon-disabled fa-arrow-circle-up fa-fw" title="' . $user->lang('MOVE_UP') . '"></i>',
098 'ICON_MOVE_DOWN' => '<i class="icon acp-icon acp-icon-move-down fa-arrow-circle-down fa-fw" title="' . $user->lang('MOVE_DOWN') . '"></i>',
099 'ICON_MOVE_DOWN_DISABLED' => '<i class="icon acp-icon acp-icon-disabled fa-arrow-circle-down fa-fw" title="' . $user->lang('MOVE_DOWN') . '"></i>',
100 'ICON_EDIT' => '<i class="icon acp-icon acp-icon-settings fa-cog fa-fw" title="' . $user->lang('EDIT') . '"></i>',
101 'ICON_EDIT_DISABLED' => '<i class="icon acp-icon acp-icon-disabled fa-cog fa-fw" title="' . $user->lang('EDIT') . '"></i>',
102 'ICON_DELETE' => '<i class="icon acp-icon acp-icon-delete fa-times-circle fa-fw" title="' . $user->lang('DELETE') . '"></i>',
103 'ICON_DELETE_DISABLED' => '<i class="icon acp-icon acp-icon-disabled fa-times-circle fa-fw" title="' . $user->lang('DELETE') . '"></i>',
104 'ICON_SYNC' => '<i class="icon acp-icon acp-icon-resync fa-refresh fa-fw" title="' . $user->lang('RESYNC') . '"></i>',
105 'ICON_SYNC_DISABLED' => '<i class="icon acp-icon acp-icon-disabled fa-refresh fa-fw" title="' . $user->lang('RESYNC') . '"></i>',
106
107 'S_USER_LANG' => $user->lang['USER_LANG'],
108 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'],
109 'S_CONTENT_ENCODING' => 'UTF-8',
110 'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
111 'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
112
113 'CONTAINER_EXCEPTION' => $phpbb_container->hasParameter('container_exception') ? $phpbb_container->getParameter('container_exception') : false,
114 ));
115
116 // An array of http headers that phpBB will set. The following event may override these.
117 $http_headers = array(
118 // application/xhtml+xml not used because of IE
119 'Content-type' => 'text/html; charset=UTF-8',
120 'Cache-Control' => 'private, no-cache="set-cookie"',
121 'Expires' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
122 'Referrer-Policy' => 'strict-origin-when-cross-origin',
123 );
124
125 /**
126 * Execute code and/or overwrite _common_ template variables after they have been assigned.
127 *
128 * @event core.adm_page_header_after
129 * @var string page_title Page title
130 * @var array http_headers HTTP headers that should be set by phpbb
131 *
132 * @since 3.1.0-RC3
133 */
134 $vars = array('page_title', 'http_headers');
135 extract($phpbb_dispatcher->trigger_event('core.adm_page_header_after', compact($vars)));
136
137 foreach ($http_headers as $hname => $hval)
138 {
139 header((string) $hname . ': ' . (string) $hval);
140 }
141
142 return;
143 }
144
145 /**
146 * Page footer for acp pages
147 */
148 function adm_page_footer($copyright_html = true)
149 {
150 global $db, $config, $template, $user, $auth;
151 global $phpbb_root_path;
152 global $request, $phpbb_dispatcher;
153
154 // A listener can set this variable to `true` when it overrides this function
155 $adm_page_footer_override = false;
156
157 /**
158 * Execute code and/or overwrite adm_page_footer()
159 *
160 * @event core.adm_page_footer
161 * @var bool copyright_html Shall we display the copyright?
162 * @var bool adm_page_footer_override Shall we return instead of
163 * running the rest of adm_page_footer()
164 * @since 3.1.0-a1
165 */
166 $vars = array('copyright_html', 'adm_page_footer_override');
167 extract($phpbb_dispatcher->trigger_event('core.adm_page_footer', compact($vars)));
168
169 if ($adm_page_footer_override)
170 {
171 return;
172 }
173
174 phpbb_check_and_display_sql_report($request, $auth, $db);
175
176 $template->assign_vars(array(
177 'DEBUG_OUTPUT' => phpbb_generate_debug_output($db, $config, $auth, $user, $phpbb_dispatcher),
178 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
179 'S_COPYRIGHT_HTML' => $copyright_html,
180 'CREDIT_LINE' => $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Limited'),
181 'T_JQUERY_LINK' => !empty($config['allow_cdn']) && !empty($config['load_jquery_url']) ? $config['load_jquery_url'] : "{$phpbb_root_path}assets/javascript/jquery-3.7.1.min.js",
182 'S_ALLOW_CDN' => !empty($config['allow_cdn']),
183 'VERSION' => $config['version'])
184 );
185
186 $template->display('body');
187
188 garbage_collection();
189 exit_handler();
190 }
191
192 /**
193 * Generate back link for acp pages
194 */
195 function adm_back_link($u_action)
196 {
197 global $user;
198 return '<br /><br /><a href="' . $u_action . '">« ' . $user->lang['BACK_TO_PREV'] . '</a>';
199 }
200
201 /**
202 * Build select field options in acp pages
203 */
204 function build_select($option_ary, $option_default = false)
205 {
206 global $user;
207
208 $html = '';
209 foreach ($option_ary as $value => $title)
210 {
211 $selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : '';
212 $html .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$title] . '</option>';
213 }
214
215 return $html;
216 }
217
218 /**
219 * Build radio fields in acp pages
220 */
221 function h_radio($name, $input_ary, $input_default = false, $id = false, $key = false, $separator = '')
222 {
223 global $user;
224
225 $html = '';
226 $id_assigned = false;
227 foreach ($input_ary as $value => $title)
228 {
229 $selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : '';
230 $html .= '<label><input type="radio" name="' . $name . '"' . (($id && !$id_assigned) ? ' id="' . $id . '"' : '') . ' value="' . $value . '"' . $selected . (($key) ? ' accesskey="' . $key . '"' : '') . ' class="radio" /> ' . $user->lang[$title] . '</label>' . $separator;
231 $id_assigned = true;
232 }
233
234 return $html;
235 }
236
237 /**
238 * Build configuration template for acp configuration pages
239 */
240 function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars)
241 {
242 global $user, $module, $phpbb_dispatcher;
243
244 $tpl = '';
245 $name = 'config[' . $config_key . ']';
246
247 // Make sure there is no notice printed out for non-existent config options (we simply set them)
248 if (!isset($new_ary[$config_key]))
249 {
250 $new_ary[$config_key] = '';
251 }
252
253 switch ($tpl_type[0])
254 {
255 case 'password':
256 if ($new_ary[$config_key] !== '')
257 {
258 // replace passwords with asterixes
259 $new_ary[$config_key] = '********';
260 }
261 case 'text':
262 case 'url':
263 case 'email':
264 case 'tel':
265 case 'search':
266 // maxlength and size are only valid for these types and will be
267 // ignored for other input types.
268 $size = (int) $tpl_type[1];
269 $maxlength = (int) $tpl_type[2];
270
271 $tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new_ary[$config_key] . '"' . (($tpl_type[0] === 'password') ? ' autocomplete="off"' : '') . ' />';
272 break;
273
274 case 'color':
275 case 'datetime':
276 case 'datetime-local':
277 case 'month':
278 case 'week':
279 $tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '" name="' . $name . '" value="' . $new_ary[$config_key] . '" />';
280 break;
281
282 case 'date':
283 case 'time':
284 case 'number':
285 case 'range':
286 $min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false;
287 $max = isset($tpl_type[2]) ? (int) $tpl_type[2] : false;
288
289 $tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (( $min !== false ) ? ' min="' . $min . '"' : '') . (( $max !== false ) ? ' max="' . $max . '"' : '') . ' name="' . $name . '" value="' . $new_ary[$config_key] . '" />';
290 break;
291
292 case 'dimension':
293 $min = isset($tpl_type[1]) ? (int) $tpl_type[1] : false;
294 $max = isset($tpl_type[2]) ? (int) $tpl_type[2] : false;
295
296 $tpl = '<input id="' . $key . '" type="number"' . (( $min !== false ) ? ' min="' . $min . '"' : '') . (( $max !== false ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_width]" value="' . $new_ary[$config_key . '_width'] . '" /> x <input type="number"' . (( $min !== '' ) ? ' min="' . $min . '"' : '') . (( $max != '' ) ? ' max="' . $max . '"' : '') . ' name="config[' . $config_key . '_height]" value="' . $new_ary[$config_key . '_height'] . '" />';
297 break;
298
299 case 'textarea':
300 $rows = (int) $tpl_type[1];
301 $cols = (int) $tpl_type[2];
302
303 $tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new_ary[$config_key] . '</textarea>';
304 break;
305
306 case 'radio':
307 $key_yes = ($new_ary[$config_key]) ? ' checked="checked"' : '';
308 $key_no = (!$new_ary[$config_key]) ? ' checked="checked"' : '';
309
310 $tpl_type_cond = explode('_', $tpl_type[1]);
311 $type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
312
313 $tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
314 $tpl_yes = '<label><input type="radio" id="' . $key . '" name="' . $name . '" value="1"' . $key_yes . ' class="radio" /> ' . (($type_no) ? $user->lang['YES'] : $user->lang['ENABLED']) . '</label>';
315
316 $tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes;
317 break;
318
319 case 'select':
320 case 'custom':
321
322 if (isset($vars['method']))
323 {
324 $call = array($module->module, $vars['method']);
325 }
326 else if (isset($vars['function']))
327 {
328 $call = $vars['function'];
329 }
330 else
331 {
332 break;
333 }
334
335 if (isset($vars['params']))
336 {
337 $args = array();
338 foreach ($vars['params'] as $value)
339 {
340 switch ($value)
341 {
342 case '{CONFIG_VALUE}':
343 $value = $new_ary[$config_key];
344 break;
345
346 case '{KEY}':
347 $value = $key;
348 break;
349 }
350
351 $args[] = $value;
352 }
353 }
354 else
355 {
356 $args = array($new_ary[$config_key], $key);
357 }
358
359 $return = call_user_func_array($call, $args);
360
361 if ($tpl_type[0] == 'select')
362 {
363 $size = (isset($tpl_type[1])) ? (int) $tpl_type[1] : 1;
364 $data_toggle = (!empty($tpl_type[2])) ? ' data-togglable-settings="true"' : '';
365
366 $tpl = '<select id="' . $key . '" name="' . $name . '"' . (($size > 1) ? ' size="' . $size . '"' : '') . $data_toggle . '>' . $return . '</select>';
367 }
368 else
369 {
370 $tpl = $return;
371 }
372
373 break;
374
375 default:
376 break;
377 }
378
379 if (isset($vars['append']))
380 {
381 $tpl .= $vars['append'];
382 }
383
384 $new = $new_ary;
385 /**
386 * Overwrite the html code we display for the config value
387 *
388 * @event core.build_config_template
389 * @var array tpl_type Config type array:
390 * 0 => data type
391 * 1 [optional] => string: size, int: minimum
392 * 2 [optional] => string: max. length, int: maximum
393 * @var string key Should be used for the id attribute in html
394 * @var array new Array with the config values we display
395 * @var string name Should be used for the name attribute
396 * @var array vars Array with the options for the config
397 * @var string tpl The resulting html code we display
398 * @since 3.1.0-a1
399 */
400 $vars = array('tpl_type', 'key', 'new', 'name', 'vars', 'tpl');
401 extract($phpbb_dispatcher->trigger_event('core.build_config_template', compact($vars)));
402 $new_ary = $new;
403 unset($new);
404
405 return $tpl;
406 }
407
408 /**
409 * Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int.
410 * The first parameter defines the type to be used, the second the lower bound and the third the upper bound. Only the type is required.
411 */
412 function validate_config_vars($config_vars, &$cfg_array, &$error)
413 {
414 global $phpbb_root_path, $user, $phpbb_dispatcher, $phpbb_filesystem, $language;
415
416 $type = 0;
417 $min = 1;
418 $max = 2;
419
420 foreach ($config_vars as $config_name => $config_definition)
421 {
422 if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
423 {
424 continue;
425 }
426
427 if (!isset($config_definition['validate']))
428 {
429 continue;
430 }
431
432 $validator = explode(':', $config_definition['validate']);
433
434 // Validate a bit. ;) (0 = type, 1 = min, 2= max)
435 switch ($validator[$type])
436 {
437 case 'url':
438 case 'csv':
439 if ($validator[$type] == 'url')
440 {
441 $cfg_array[$config_name] = trim($cfg_array[$config_name]);
442
443 if (!empty($cfg_array[$config_name]) && !preg_match('#^' . get_preg_expression('url') . '$#iu', $cfg_array[$config_name]))
444 {
445 $error[] = $language->lang('URL_INVALID', $language->lang($config_definition['lang']));
446 }
447 }
448 else if ($validator[$type] == 'csv')
449 {
450 // Validate comma separated values
451 $unfiltered_array = explode(',', $cfg_array[$config_name]);
452 $filtered_array = array_filter($unfiltered_array);
453 if (!empty($filtered_array) && count($unfiltered_array) !== count($filtered_array))
454 {
455 $error[] = $language->lang('CSV_INVALID', $language->lang($config_definition['lang']));
456 }
457
458 }
459 // no break here
460
461 case 'string':
462 $length = utf8_strlen($cfg_array[$config_name]);
463
464 // the column is a VARCHAR
465 $validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255;
466
467 if (isset($validator[$min]) && $length < $validator[$min])
468 {
469 $error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]);
470 }
471 else if (isset($validator[$max]) && $length > $validator[2])
472 {
473 $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]);
474 }
475 break;
476
477 case 'bool':
478 $cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0;
479 break;
480
481 case 'int':
482 $cfg_array[$config_name] = (int) $cfg_array[$config_name];
483
484 if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min])
485 {
486 $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]);
487 }
488 else if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max])
489 {
490 $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]);
491 }
492
493 if (strpos($config_name, '_max') !== false)
494 {
495 // Min/max pairs of settings should ensure that min <= max
496 // Replace _max with _min to find the name of the minimum
497 // corresponding configuration variable
498 $min_name = str_replace('_max', '_min', $config_name);
499
500 if (isset($cfg_array[$min_name]) && is_numeric($cfg_array[$min_name]) && $cfg_array[$config_name] < $cfg_array[$min_name])
501 {
502 // A minimum value exists and the maximum value is less than it
503 $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], (int) $cfg_array[$min_name]);
504 }
505 }
506 break;
507
508 case 'email':
509 if (!preg_match('/^' . get_preg_expression('email') . '$/i', $cfg_array[$config_name]))
510 {
511 $error[] = $user->lang['EMAIL_INVALID_EMAIL'];
512 }
513 break;
514
515 // Absolute path
516 case 'script_path':
517 if (!$cfg_array[$config_name])
518 {
519 break;
520 }
521
522 $destination = str_replace('\\', '/', $cfg_array[$config_name]);
523
524 if ($destination !== '/')
525 {
526 // Adjust destination path (no trailing slash)
527 if (substr($destination, -1, 1) == '/')
528 {
529 $destination = substr($destination, 0, -1);
530 }
531
532 $destination = str_replace(array('../', './'), '', $destination);
533
534 if ($destination[0] != '/')
535 {
536 $destination = '/' . $destination;
537 }
538 }
539
540 $cfg_array[$config_name] = trim($destination);
541
542 break;
543
544 // Absolute path
545 case 'lang':
546 if (!$cfg_array[$config_name])
547 {
548 break;
549 }
550
551 $cfg_array[$config_name] = basename($cfg_array[$config_name]);
552
553 if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/'))
554 {
555 $error[] = $user->lang['WRONG_DATA_LANG'];
556 }
557 break;
558
559 // Relative path (appended $phpbb_root_path)
560 case 'rpath':
561 case 'rwpath':
562 if (!$cfg_array[$config_name])
563 {
564 break;
565 }
566
567 $destination = $cfg_array[$config_name];
568
569 // Adjust destination path (no trailing slash)
570 if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
571 {
572 $destination = substr($destination, 0, -1);
573 }
574
575 $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
576 if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
577 {
578 $destination = '';
579 }
580
581 $cfg_array[$config_name] = trim($destination);
582
583 // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir...
584 case 'path':
585 case 'wpath':
586
587 if (!$cfg_array[$config_name])
588 {
589 break;
590 }
591
592 $cfg_array[$config_name] = trim($cfg_array[$config_name]);
593
594 // Make sure no NUL byte is present...
595 if (strpos($cfg_array[$config_name], "\0") !== false || strpos($cfg_array[$config_name], '%00') !== false)
596 {
597 $cfg_array[$config_name] = '';
598 break;
599 }
600
601 $path = $phpbb_root_path . $cfg_array[$config_name];
602
603 if (!file_exists($path))
604 {
605 $error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]);
606 }
607
608 if (file_exists($path) && !is_dir($path))
609 {
610 $error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]);
611 }
612
613 // Check if the path is writable
614 if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath')
615 {
616 if (file_exists($path) && !$phpbb_filesystem->is_writable($path))
617 {
618 $error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]);
619 }
620 }
621
622 break;
623
624 default:
625 /**
626 * Validate a config value
627 *
628 * @event core.validate_config_variable
629 * @var array cfg_array Array with config values
630 * @var string config_name Name of the config we validate
631 * @var array config_definition Array with the options for
632 * this config
633 * @var array error Array of errors, the errors should
634 * be strings only, language keys are
635 * not replaced afterwards
636 * @since 3.1.0-a1
637 */
638 $vars = array('cfg_array', 'config_name', 'config_definition', 'error');
639 extract($phpbb_dispatcher->trigger_event('core.validate_config_variable', compact($vars)));
640 break;
641 }
642 }
643
644 return;
645 }
646
647 /**
648 * Checks whatever or not a variable is OK for use in the Database
649 * param mixed $value_ary An array of the form array(array('lang' => ..., 'value' => ..., 'column_type' =>))'
650 * param mixed $error The error array
651 */
652 function validate_range($value_ary, &$error)
653 {
654 global $user;
655
656 $column_types = array(
657 'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1),
658 'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535),
659 'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff),
660 // Do not use (int) 0x80000000 - it evaluates to different
661 // values on 32-bit and 64-bit systems.
662 // Apparently -2147483648 is a float on 32-bit systems,
663 // despite fitting in an int, thus explicit cast is needed.
664 'INT' => array('php_type' => 'int', 'min' => (int) -2147483648, 'max' => (int) 0x7fffffff),
665 'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127),
666
667 'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255),
668 );
669 foreach ($value_ary as $value)
670 {
671 $column = explode(':', $value['column_type']);
672 if (!isset($column_types[$column[0]]))
673 {
674 continue;
675 }
676 else
677 {
678 $type = $column_types[$column[0]];
679 }
680
681 switch ($type['php_type'])
682 {
683 case 'string' :
684 $max = (isset($column[1])) ? min($column[1],$type['max']) : $type['max'];
685 if (utf8_strlen($value['value']) > $max)
686 {
687 $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max);
688 }
689 break;
690
691 case 'int':
692 $min = (isset($column[1])) ? max($column[1],$type['min']) : $type['min'];
693 $max = (isset($column[2])) ? min($column[2],$type['max']) : $type['max'];
694 if ($value['value'] < $min)
695 {
696 $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$value['lang']], $min);
697 }
698 else if ($value['value'] > $max)
699 {
700 $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$value['lang']], $max);
701 }
702 break;
703 }
704 }
705 }
706
707 /**
708 * Inserts new config display_vars into an exisiting display_vars array
709 * at the given position.
710 *
711 * @param array $display_vars An array of existing config display vars
712 * @param array $add_config_vars An array of new config display vars
713 * @param array $where Where to place the new config vars,
714 * before or after an exisiting config, as an array
715 * of the form: array('after' => 'config_name') or
716 * array('before' => 'config_name').
717 * @return array The array of config display vars
718 */
719 function phpbb_insert_config_array($display_vars, $add_config_vars, $where)
720 {
721 if (is_array($where) && array_key_exists(current($where), $display_vars))
722 {
723 $position = array_search(current($where), array_keys($display_vars)) + ((key($where) == 'before') ? 0 : 1);
724 $display_vars = array_merge(
725 array_slice($display_vars, 0, $position),
726 $add_config_vars,
727 array_slice($display_vars, $position)
728 );
729 }
730
731 return $display_vars;
732 }
733