[ Index ]

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


Generated: Sun Feb 19 19:47:08 2017 Cross-referenced by PHPXref 0.7.1