[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

/adm/ -> index.php (source)

   1  <?php
   2  /** 
   3  *
   4  * @package acp
   5  * @version $Id: index.php,v 1.55 2006/10/08 13:42:23 grahamje Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  */
  13  define('IN_PHPBB', 1);
  14  define('ADMIN_START', 1);
  15  define('NEED_SID', true);
  16  
  17  // Include files
  18  $phpbb_root_path = './../';
  19  $phpEx = substr(strrchr(__FILE__, '.'), 1);
  20  require($phpbb_root_path . 'common.' . $phpEx);
  21  require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  22  require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
  23  
  24  // Start session management
  25  $user->session_begin();
  26  $auth->acl($user->data);
  27  $user->setup('acp/common');
  28  // End session management
  29  
  30  // Did user forget to login? Give 'em a chance to here ...
  31  if ($user->data['user_id'] == ANONYMOUS)
  32  {
  33      login_box('', $user->lang['LOGIN_ADMIN'], $user->lang['LOGIN_ADMIN_SUCCESS'], true);
  34  }
  35  
  36  // Have they authenticated (again) as an admin for this session?
  37  if (!isset($user->data['session_admin']) || !$user->data['session_admin'])
  38  {
  39      login_box('', $user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], true, false);
  40  }
  41  
  42  // Is user any type of admin? No, then stop here, each script needs to
  43  // check specific permissions but this is a catchall
  44  if (!$auth->acl_get('a_'))
  45  {
  46      trigger_error($user->lang['NO_ADMIN']);
  47  }
  48  
  49  // We define the admin variables now, because the user is now able to use the admin related features...
  50  define('IN_ADMIN', true);
  51  $phpbb_admin_path = './';
  52  
  53  // Some oft used variables
  54  $safe_mode        = (@ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on') ? true : false;
  55  $file_uploads     = (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false;
  56  $module_id        = request_var('i', '');
  57  $mode            = request_var('mode', '');
  58  
  59  // Set custom template for admin area
  60  $template->set_custom_template($phpbb_admin_path . 'style', 'admin');
  61  $template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
  62  
  63  // the acp template is never stored in the database
  64  $user->theme['template_storedb'] = false;
  65  
  66  // Force pagination seperation for admin style
  67  $user->theme['pagination_sep'] = '';
  68  
  69  // Instantiate new module
  70  $module = new p_master();
  71  
  72  // Instantiate module system and generate list of available modules
  73  $module->list_modules('acp');
  74  
  75  // Select the active module
  76  $module->set_active($module_id, $mode);
  77  
  78  // Assign data to the template engine for the list of modules
  79  // We do this before loading the active module for correct menu display in trigger_error
  80  $module->assign_tpl_vars(append_sid("{$phpbb_admin_path}index.$phpEx"));
  81  
  82  // Load and execute the relevant module
  83  $module->load_active();
  84  
  85  // Generate the page
  86  adm_page_header($module->get_page_title());
  87  
  88  $template->set_filenames(array(
  89      'body' => $module->get_tpl_name())
  90  );
  91  
  92  adm_page_footer();
  93  
  94  /**
  95  * Header for acp pages
  96  */
  97  function adm_page_header($page_title)
  98  {
  99      global $config, $db, $user, $template;
 100      global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
 101  
 102      if (defined('HEADER_INC'))
 103      {
 104          return;
 105      }
 106  
 107      define('HEADER_INC', true);
 108  
 109      // gzip_compression
 110      if ($config['gzip_compress'])
 111      {
 112          if (@extension_loaded('zlib') && !headers_sent())
 113          {
 114              ob_start('ob_gzhandler');
 115          }
 116      }
 117  
 118      $template->assign_vars(array(
 119          'PAGE_TITLE'            => $page_title,
 120          'USERNAME'                => $user->data['username'],
 121  
 122          'SID'                    => $SID,
 123          '_SID'                    => $_SID,
 124          'SESSION_ID'            => $user->session_id,
 125          'ROOT_PATH'                => $phpbb_admin_path,
 126  
 127          'U_LOGOUT'                => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout'),
 128          'U_ADM_INDEX'            => append_sid("{$phpbb_admin_path}index.$phpEx"),
 129          'U_INDEX'                => append_sid("{$phpbb_root_path}index.$phpEx"),
 130  
 131          'T_IMAGES_PATH'            => "{$phpbb_root_path}images/",
 132          'T_SMILIES_PATH'        => "{$phpbb_root_path}{$config['smilies_path']}/",
 133          'T_AVATAR_PATH'            => "{$phpbb_root_path}{$config['avatar_path']}/",
 134          'T_AVATAR_GALLERY_PATH'    => "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
 135          'T_ICONS_PATH'            => "{$phpbb_root_path}{$config['icons_path']}/",
 136          'T_RANKS_PATH'            => "{$phpbb_root_path}{$config['ranks_path']}/",
 137          'T_UPLOAD_PATH'            => "{$phpbb_root_path}{$config['upload_path']}/",
 138  
 139          'ICON_MOVE_UP'                => '<img src="' . $phpbb_admin_path . 'images/icon_up.gif" alt="' . $user->lang['MOVE_UP'] . '" title="' . $user->lang['MOVE_UP'] . '" />',
 140          'ICON_MOVE_UP_DISABLED'        => '<img src="' . $phpbb_admin_path . 'images/icon_up_disabled.gif" alt="' . $user->lang['MOVE_UP'] . '" title="' . $user->lang['MOVE_UP'] . '" />',
 141          'ICON_MOVE_DOWN'            => '<img src="' . $phpbb_admin_path . 'images/icon_down.gif" alt="' . $user->lang['MOVE_DOWN'] . '" title="' . $user->lang['MOVE_DOWN'] . '" />',
 142          'ICON_MOVE_DOWN_DISABLED'    => '<img src="' . $phpbb_admin_path . 'images/icon_down_disabled.gif" alt="' . $user->lang['MOVE_DOWN'] . '" title="' . $user->lang['MOVE_DOWN'] . '" />',        
 143          'ICON_EDIT'                    => '<img src="' . $phpbb_admin_path . 'images/icon_edit.gif" alt="' . $user->lang['EDIT'] . '" title="' . $user->lang['EDIT'] . '" />',
 144          'ICON_EDIT_DISABLED'        => '<img src="' . $phpbb_admin_path . 'images/icon_edit_disabled.gif" alt="' . $user->lang['EDIT'] . '" title="' . $user->lang['EDIT'] . '" />',
 145          'ICON_DELETE'                => '<img src="' . $phpbb_admin_path . 'images/icon_delete.gif" alt="' . $user->lang['DELETE'] . '" title="' . $user->lang['DELETE'] . '" />',
 146          'ICON_DELETE_DISABLED'        => '<img src="' . $phpbb_admin_path . 'images/icon_delete_disabled.gif" alt="' . $user->lang['DELETE'] . '" title="' . $user->lang['DELETE'] . '" />',
 147          'ICON_SYNC'                    => '<img src="' . $phpbb_admin_path . 'images/icon_sync.gif" alt="' . $user->lang['RESYNC'] . '" title="' . $user->lang['RESYNC'] . '" />',
 148          'ICON_SYNC_DISABLED'        => '<img src="' . $phpbb_admin_path . 'images/icon_sync_disabled.gif" alt="' . $user->lang['RESYNC'] . '" title="' . $user->lang['RESYNC'] . '" />',
 149  
 150          'S_USER_LANG'            => $user->lang['USER_LANG'],
 151          'S_CONTENT_DIRECTION'    => $user->lang['DIRECTION'],
 152          'S_CONTENT_ENCODING'    => 'UTF-8',
 153          'S_CONTENT_DIR_LEFT'    => $user->lang['LEFT'],
 154          'S_CONTENT_DIR_RIGHT'    => $user->lang['RIGHT'])
 155      );
 156  
 157      if ($config['send_encoding'])
 158      {
 159          header('Content-type: text/html; charset=UTF-8');
 160      }
 161      header('Cache-Control: private, no-cache="set-cookie"');
 162      header('Expires: 0');
 163      header('Pragma: no-cache');
 164  
 165      return;
 166  }
 167  
 168  /**
 169  * Page footer for acp pages
 170  */
 171  function adm_page_footer($copyright_html = true)
 172  {
 173      global $db, $config, $template, $user, $auth, $cache;
 174      global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx;
 175  
 176      // Output page creation time
 177      if (defined('DEBUG'))
 178      {
 179          $mtime = explode(' ', microtime());
 180          $totaltime = $mtime[0] + $mtime[1] - $starttime;
 181  
 182          if (!empty($_REQUEST['explain']) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report'))
 183          {
 184              $db->sql_report('display');
 185          }
 186  
 187          $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' .  (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
 188  
 189          if ($auth->acl_get('a_') && defined('DEBUG_EXTRA'))
 190          {
 191              if (function_exists('memory_get_usage'))
 192              {
 193                  if ($memory_usage = memory_get_usage())
 194                  {
 195                      global $base_memory_usage;
 196                      $memory_usage -= $base_memory_usage;
 197                      $memory_usage = ($memory_usage >= 1048576) ? round((round($memory_usage / 1048576 * 100) / 100), 2) . ' ' . $user->lang['MB'] : (($memory_usage >= 1024) ? round((round($memory_usage / 1024 * 100) / 100), 2) . ' ' . $user->lang['KB'] : $memory_usage . ' ' . $user->lang['BYTES']);
 198  
 199                      $debug_output .= ' | Memory Usage: ' . $memory_usage;
 200                  }
 201              }
 202  
 203              $debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
 204          }
 205      }
 206  
 207      $template->assign_vars(array(
 208          'DEBUG_OUTPUT'        => (defined('DEBUG')) ? $debug_output : '',
 209          'S_COPYRIGHT_HTML'    => $copyright_html,
 210          'VERSION'            => $config['version'])
 211      );
 212  
 213      $template->display('body');
 214  
 215      garbage_collection();
 216  
 217      exit;
 218  }
 219  
 220  /**
 221  * Generate back link for acp pages
 222  */
 223  function adm_back_link($u_action)
 224  {
 225      global $user;
 226      return '<br /><br /><a href="' . $u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>';
 227  }
 228  
 229  /**
 230  * Build select field options in acp pages
 231  */
 232  function build_select($option_ary, $option_default = false)
 233  {
 234      global $user;
 235  
 236      $html = '';
 237      foreach ($option_ary as $value => $title)
 238      {
 239          $selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : '';
 240          $html .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$title] . '</option>';
 241      }
 242  
 243      return $html;
 244  }
 245  
 246  /**
 247  * Build radio fields in acp pages
 248  */
 249  function h_radio($name, &$input_ary, $input_default = false, $id = false, $key = false)
 250  {
 251      global $user;
 252  
 253      $html = '';
 254      $id_assigned = false;
 255      foreach ($input_ary as $value => $title)
 256      {
 257          $selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : '';
 258          $html .= ($html) ? ' &nbsp; ' : '';
 259          $html .= '<input type="radio" name="' . $name . '"' . (($id && !$id_assigned) ? ' id="' . $id . '"' : '') . ' value="' . $value . '"' . $selected . (($key) ? ' accesskey="' . $key . '"' : '') . ' class="radio" /> ' . $user->lang[$title];
 260          $id_assigned = true;
 261      }
 262  
 263      return $html;
 264  }
 265  
 266  /**
 267  * Build configuration template for acp configuration pages
 268  */
 269  function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
 270  {
 271      global $user, $module;
 272  
 273      $tpl = '';
 274      $name = 'config[' . $config_key . ']';
 275  
 276      switch ($tpl_type[0])
 277      {
 278          case 'text':
 279          case 'password':
 280              $size = (int) $tpl_type[1];
 281              $maxlength = (int) $tpl_type[2];
 282  
 283              $tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new[$config_key] . '" />';
 284          break;
 285  
 286          case 'dimension':
 287              $size = (int) $tpl_type[1];
 288              $maxlength = (int) $tpl_type[2];
 289  
 290              $tpl = '<input id="' . $key . '" type="text"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="config[' . $config_key . '_height]" value="' . $new[$config_key . '_height'] . '" /> x <input type="text"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="config[' . $config_key . '_width]" value="' . $new[$config_key . '_width'] . '" />';
 291          break;
 292  
 293          case 'textarea':
 294              $rows = (int) $tpl_type[1];
 295              $cols = (int) $tpl_type[2];
 296  
 297              $tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new[$config_key] . '</textarea>';
 298          break;
 299  
 300          case 'radio':
 301              $key_yes    = ($new[$config_key]) ? ' checked="checked"' : '';
 302              $key_no        = (!$new[$config_key]) ? ' checked="checked"' : '';
 303  
 304              $tpl_type_cond = explode('_', $tpl_type[1]);
 305              $type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
 306  
 307              $tpl_no = '<input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" />&nbsp;' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']);
 308              $tpl_yes = '<input type="radio" id="' . $key . '" name="' . $name . '" value="1"' . $key_yes . ' class="radio" />&nbsp;' . (($type_no) ? $user->lang['YES'] : $user->lang['ENABLED']);
 309  
 310              $tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . '&nbsp;&nbsp;' . $tpl_no : $tpl_no . '&nbsp;&nbsp;' . $tpl_yes;
 311          break;
 312  
 313          case 'select':
 314          case 'custom':
 315              
 316              $return = '';
 317  
 318              if (isset($vars['method']))
 319              {
 320                  $call = array($module->module, $vars['method']);
 321              }
 322              else if (isset($vars['function']))
 323              {
 324                  $call = $vars['function'];
 325              }
 326              else
 327              {
 328                  break;
 329              }
 330  
 331              if (isset($vars['params']))
 332              {
 333                  $args = array();
 334                  foreach ($vars['params'] as $value)
 335                  {
 336                      switch ($value)
 337                      {
 338                          case '{CONFIG_VALUE}':
 339                              $value = $new[$config_key];
 340                          break;
 341  
 342                          case '{KEY}':
 343                              $value = $key;
 344                          break;
 345                      }
 346  
 347                      $args[] = $value;
 348                  }
 349              }
 350              else
 351              {
 352                  $args = array($new[$config_key], $key);
 353              }
 354              
 355              $return = call_user_func_array($call, $args);
 356  
 357              if ($tpl_type[0] == 'select')
 358              {
 359                  $tpl = '<select id="' . $key . '" name="' . $name . '">' . $return . '</select>';
 360              }
 361              else
 362              {
 363                  $tpl = $return;
 364              }
 365  
 366          break;
 367  
 368          default:
 369          break;
 370      }
 371  
 372      if (isset($vars['append']))
 373      {
 374          $tpl .= $vars['append'];
 375      }
 376  
 377      return $tpl;
 378  }
 379  
 380  /**
 381  * Going through a config array and validate values, writing errors to $error.
 382  */
 383  function validate_config_vars($config_vars, &$cfg_array, &$error)
 384  {
 385      global $phpbb_root_path, $user;
 386  
 387      foreach ($config_vars as $config_name => $config_definition)
 388      {
 389          if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
 390          {
 391              continue;
 392          }
 393  
 394          if (!isset($config_definition['validate']))
 395          {
 396              continue;
 397          }
 398  
 399          // Validate a bit. ;) String is already checked through request_var(), therefore we do not check this again
 400          switch ($config_definition['validate'])
 401          {
 402              case 'bool':
 403                  $cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0;
 404              break;
 405  
 406              case 'int':
 407                  $cfg_array[$config_name] = (int) $cfg_array[$config_name];
 408              break;
 409  
 410              // Relative path (appended $phpbb_root_path)
 411              case 'rpath':
 412              case 'rwpath':
 413                  if (!$cfg_array[$config_name])
 414                  {
 415                      break;
 416                  }
 417  
 418                  $destination = $cfg_array[$config_name];
 419  
 420                  // Adjust destination path (no trailing slash)
 421                  if ($destination{(sizeof($destination)-1)} == '/' || $destination{(sizeof($destination)-1)} == '\\')
 422                  {
 423                      $destination = substr($destination, 0, sizeof($destination)-2);
 424                  }
 425  
 426                  $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
 427                  if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
 428                  {
 429                      $destination = '';
 430                  }
 431  
 432                  $cfg_array[$config_name] = trim($destination);
 433  
 434              // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir...
 435              case 'path':
 436              case 'wpath':
 437  
 438                  if (!$cfg_array[$config_name])
 439                  {
 440                      break;
 441                  }
 442  
 443                  $cfg_array[$config_name] = trim($cfg_array[$config_name]);
 444  
 445                  // Make sure no NUL byte is present...
 446                  if (strpos($cfg_array[$config_name], '\0') !== false || strpos($cfg_array[$config_name], '%00') !== false)
 447                  {
 448                      $cfg_array[$config_name] = '';
 449                      break;
 450                  }
 451  
 452                  if (!file_exists($phpbb_root_path . $cfg_array[$config_name]))
 453                  {
 454                      $error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]);
 455                  }
 456  
 457                  if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name]))
 458                  {
 459                      $error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]);
 460                  }
 461  
 462                  // Check if the path is writeable
 463                  if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath')
 464                  {
 465                      if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_writeable($phpbb_root_path . $cfg_array[$config_name]))
 466                      {
 467                          $error[] = sprintf($user->lang['DIRECTORY_NOT_WRITEABLE'], $cfg_array[$config_name]);
 468                      }
 469                  }
 470  
 471              break;
 472          }
 473      }
 474  
 475      return;
 476  }
 477  
 478  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6