[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/includes/ -> functions_acp.php (source)

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


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1