Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

functions_acp.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 22.58 KiB


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