Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

helper.php

Zuletzt modifiziert: 01.05.2026, 11:25 - Dateigröße: 11.25 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  namespace phpbb\install\controller;
 015   
 016  use phpbb\install\helper\config;
 017  use phpbb\install\helper\navigation\navigation_provider;
 018  use phpbb\language\language;
 019  use phpbb\language\language_file_helper;
 020  use phpbb\path_helper;
 021  use phpbb\request\request;
 022  use phpbb\request\request_interface;
 023  use phpbb\routing\router;
 024  use phpbb\symfony_request;
 025  use phpbb\template\template;
 026  use Symfony\Component\HttpFoundation\Response;
 027  use Symfony\Component\HttpFoundation\Cookie;
 028   
 029  /**
 030   * A duplicate of \phpbb\controller\helper
 031   *
 032   * This class is necessary because of controller\helper's legacy function calls
 033   * to page_header() page_footer() functions which has unavailable dependencies.
 034   */
 035  class helper
 036  {
 037      /**
 038       * @var config
 039       */
 040      protected $installer_config;
 041   
 042      /**
 043       * @var language
 044       */
 045      protected $language;
 046   
 047      /**
 048       * @var bool|string
 049       */
 050      protected $language_cookie;
 051   
 052      /**
 053       * @var language_file_helper
 054       */
 055      protected $lang_helper;
 056   
 057      /**
 058       * @var navigation_provider
 059       */
 060      protected $navigation_provider;
 061   
 062      /**
 063       * @var template
 064       */
 065      protected $template;
 066   
 067      /**
 068       * @var path_helper
 069       */
 070      protected $path_helper;
 071   
 072      /**
 073       * @var request
 074       */
 075      protected $phpbb_request;
 076   
 077      /**
 078       * @var symfony_request
 079       */
 080      protected $request;
 081   
 082      /**
 083       * @var router
 084       */
 085      protected $router;
 086   
 087      /**
 088       * @var string
 089       */
 090      protected $phpbb_admin_path;
 091   
 092      /**
 093       * @var string
 094       */
 095      protected $phpbb_root_path;
 096   
 097      /**
 098       * Constructor
 099       *
 100       * @param config                $config
 101       * @param language                $language
 102       * @param language_file_helper    $lang_helper
 103       * @param navigation_provider    $nav
 104       * @param template                $template
 105       * @param path_helper            $path_helper
 106       * @param request                $phpbb_request
 107       * @param symfony_request        $request
 108       * @param router                $router
 109       * @param string                $phpbb_root_path
 110       */
 111      public function __construct(config $config, language $language, language_file_helper $lang_helper, navigation_provider $nav, template $template, path_helper $path_helper, request $phpbb_request, symfony_request $request, router $router, $phpbb_root_path)
 112      {
 113          $this->installer_config = $config;
 114          $this->language = $language;
 115          $this->language_cookie = false;
 116          $this->lang_helper = $lang_helper;
 117          $this->navigation_provider = $nav;
 118          $this->template = $template;
 119          $this->path_helper = $path_helper;
 120          $this->phpbb_request = $phpbb_request;
 121          $this->request = $request;
 122          $this->router = $router;
 123          $this->phpbb_root_path = $phpbb_root_path;
 124          $this->phpbb_admin_path = $phpbb_root_path . 'adm/';
 125      }
 126   
 127      /**
 128       * Automate setting up the page and creating the response object.
 129       *
 130       * @param string    $template_file        The template handle to render
 131       * @param string    $page_title            The title of the page to output
 132       * @param bool        $selected_language    True to enable language selector it, false otherwise
 133       * @param int        $status_code        The status code to be sent to the page header
 134       *
 135       * @return Response object containing rendered page
 136       */
 137      public function render($template_file, $page_title = '', $selected_language = false, $status_code = 200)
 138      {
 139          $this->page_header($page_title, $selected_language);
 140   
 141          $this->template->set_filenames(array(
 142              'body'    => $template_file,
 143          ));
 144   
 145          $response = new Response($this->template->assign_display('body'), $status_code);
 146   
 147          // Set language cookie
 148          if ($this->language_cookie !== false)
 149          {
 150              $cookie = new Cookie('lang', $this->language_cookie, time() + 3600);
 151              $response->headers->setCookie($cookie);
 152   
 153              $this->language_cookie = false;
 154          }
 155   
 156          return $response;
 157      }
 158   
 159      /**
 160       * Returns path from route name
 161       *
 162       * @param string    $route_name
 163       * @param array        $parameters
 164       *
 165       * @return string
 166       */
 167      public function route($route_name, $parameters = array())
 168      {
 169          $url = $this->router->generate($route_name, $parameters);
 170   
 171          return $url;
 172      }
 173   
 174      /**
 175       * Handles language selector form
 176       */
 177      public function handle_language_select()
 178      {
 179          $lang = null;
 180   
 181          // Check if language form has been submited
 182          $submit = $this->phpbb_request->variable('change_lang', '');
 183          if (!empty($submit))
 184          {
 185              $lang = $this->phpbb_request->variable('language', '');
 186          }
 187   
 188          // Retrieve language from cookie
 189          $lang_cookie = $this->phpbb_request->variable('lang', '', false, request_interface::COOKIE);
 190          if (empty($lang) && !empty($lang_cookie))
 191          {
 192              $lang = $lang_cookie;
 193          }
 194   
 195          $lang = (!empty($lang) && strpos($lang, '/') === false) ? $lang : null;
 196          $this->language_cookie = $lang;
 197   
 198          $this->render_language_select($lang);
 199   
 200          if ($lang !== null)
 201          {
 202              $this->language->set_user_language($lang, true);
 203              $this->installer_config->set('user_language', $lang);
 204          }
 205      }
 206   
 207      /**
 208       * Handle installer restart
 209       */
 210      public function handle_installer_restart(): void
 211      {
 212          $restart = $this->phpbb_request->variable('install_restart', false);
 213          if ($restart)
 214          {
 215              // Clean up config file to restart installer
 216              $this->installer_config->clean_up_config_file();
 217          }
 218          else if ($this->installer_config->exists())
 219          {
 220              $this->template->assign_var('SHOW_RESTART_BUTTON', true);
 221          }
 222      }
 223   
 224      /**
 225       * Process navigation data to reflect active/completed stages
 226       *
 227       * @param \phpbb\install\helper\iohandler\iohandler_interface|null    $iohandler
 228       */
 229      public function handle_navigation($iohandler = null)
 230      {
 231          $nav_data = $this->installer_config->get_navigation_data();
 232   
 233          // Set active navigation stage
 234          if (isset($nav_data['active']) && is_array($nav_data['active']))
 235          {
 236              if ($iohandler !== null)
 237              {
 238                  $iohandler->set_active_stage_menu($nav_data['active']);
 239              }
 240   
 241              $this->navigation_provider->set_nav_property($nav_data['active'], array(
 242                  'selected'    => true,
 243                  'completed'    => false,
 244              ));
 245          }
 246   
 247          // Set finished navigation stages
 248          if (isset($nav_data['finished']) && is_array($nav_data['finished']))
 249          {
 250              foreach ($nav_data['finished'] as $finished_stage)
 251              {
 252                  if ($iohandler !== null)
 253                  {
 254                      $iohandler->set_finished_stage_menu($finished_stage);
 255                  }
 256   
 257                  $this->navigation_provider->set_nav_property($finished_stage, array(
 258                      'selected'    => false,
 259                      'completed'    => true,
 260                  ));
 261              }
 262          }
 263      }
 264   
 265      /**
 266       * Set default template variables
 267       *
 268       * @param string    $page_title            Title of the page
 269       * @param bool        $selected_language    True to enable language selector it, false otherwise
 270       */
 271      protected function page_header($page_title, $selected_language = false)
 272      {
 273          // Path to templates
 274          $paths = array($this->phpbb_root_path . 'install/update/new/adm/', $this->phpbb_admin_path);
 275          $paths = array_filter($paths, 'is_dir');
 276          $path = array_shift($paths);
 277          $path = substr($path, strlen($this->phpbb_root_path));
 278   
 279          $this->template->assign_vars(array(
 280              'L_CHANGE'                => $this->language->lang('CHANGE'),
 281              'L_COLON'                => $this->language->lang('COLON'),
 282              'L_INSTALL_PANEL'        => $this->language->lang('INSTALL_PANEL'),
 283              'L_SELECT_LANG'            => $this->language->lang('SELECT_LANG'),
 284              'L_SKIP'                => $this->language->lang('SKIP'),
 285              'PAGE_TITLE'            => $this->language->lang($page_title),
 286              'T_IMAGE_PATH'            => $this->path_helper->get_web_root_path() . $path . 'images',
 287              'T_JQUERY_LINK'            => $this->path_helper->get_web_root_path() . $path . '../assets/javascript/jquery-3.7.1.min.js',
 288              'T_TEMPLATE_PATH'        => $this->path_helper->get_web_root_path() . $path . 'style',
 289              'T_ASSETS_PATH'            => $this->path_helper->get_web_root_path() . $path . '../assets',
 290   
 291              'S_CONTENT_DIRECTION'     => $this->language->lang('DIRECTION'),
 292              'S_CONTENT_FLOW_BEGIN'    => ($this->language->lang('DIRECTION') === 'ltr') ? 'left' : 'right',
 293              'S_CONTENT_FLOW_END'    => ($this->language->lang('DIRECTION') === 'ltr') ? 'right' : 'left',
 294              'S_CONTENT_ENCODING'     => 'UTF-8',
 295              'S_LANG_SELECT'            => $selected_language,
 296   
 297              'S_USER_LANG'            => $this->language->lang('USER_LANG'),
 298          ));
 299   
 300          $this->render_navigation();
 301      }
 302   
 303      /**
 304       * Render navigation
 305       */
 306      protected function render_navigation()
 307      {
 308          // Get navigation items
 309          $nav_array = $this->navigation_provider->get();
 310          $nav_array = $this->sort_navigation_level($nav_array);
 311   
 312          $active_main_menu = $this->get_active_main_menu($nav_array);
 313   
 314          // Pass navigation to template
 315          foreach ($nav_array as $key => $entry)
 316          {
 317              $this->template->assign_block_vars('t_block1', array(
 318                  'L_TITLE' => $this->language->lang($entry['label']),
 319                  'S_SELECTED' => ($active_main_menu === $key),
 320                  'U_TITLE' => $this->route($entry['route']),
 321              ));
 322   
 323              if (is_array($entry[0]) && $active_main_menu === $key)
 324              {
 325                  $entry[0] = $this->sort_navigation_level($entry[0]);
 326   
 327                  foreach ($entry[0] as $name => $sub_entry)
 328                  {
 329                      if (isset($sub_entry['stage']) && $sub_entry['stage'] === true)
 330                      {
 331                          $this->template->assign_block_vars('l_block2', array(
 332                              'L_TITLE' => $this->language->lang($sub_entry['label']),
 333                              'S_SELECTED' => (isset($sub_entry['selected']) && $sub_entry['selected'] === true),
 334                              'S_COMPLETE' => (isset($sub_entry['completed']) && $sub_entry['completed'] === true),
 335                              'STAGE_NAME' => $name,
 336                          ));
 337                      }
 338                      else
 339                      {
 340                          $this->template->assign_block_vars('l_block1', array(
 341                              'L_TITLE' => $this->language->lang($sub_entry['label']),
 342                              'S_SELECTED' => (isset($sub_entry['route']) && $sub_entry['route'] === $this->request->get('_route')),
 343                              'U_TITLE' => $this->route($sub_entry['route']),
 344                          ));
 345                      }
 346                  }
 347              }
 348          }
 349      }
 350   
 351      /**
 352       * Render language select form
 353       *
 354       * @param string    $selected_language
 355       */
 356      protected function render_language_select($selected_language = null)
 357      {
 358          $langs = $this->lang_helper->get_available_languages();
 359   
 360          // The first language will be selected by default. Unless a user has consciously included
 361          // other languages in the installation process, it will be British English anyway.
 362          if ($selected_language === null && count($langs))
 363          {
 364              $selected_language = $langs[0]['iso'];
 365          }
 366   
 367          foreach ($langs as $lang)
 368          {
 369              $this->template->assign_block_vars('language_select_item', array(
 370                  'VALUE' => $lang['iso'],
 371                  'NAME' => $lang['local_name'],
 372                  'SELECTED' => ($lang['iso'] === $selected_language),
 373              ));
 374          }
 375      }
 376   
 377      /**
 378       * Returns the name of the active main menu item
 379       *
 380       * @param array    $nav_array
 381       *
 382       * @return string|bool    Returns the name of the active main menu element, if the element not found, returns false
 383       */
 384      protected function get_active_main_menu($nav_array)
 385      {
 386          $active_route = $this->request->get('_route');
 387   
 388          foreach ($nav_array as $nav_name => $nav_options)
 389          {
 390              $current_menu = $nav_name;
 391   
 392              if (isset($nav_options['route']) && $nav_options['route'] === $active_route)
 393              {
 394                  return $nav_name;
 395              }
 396   
 397              if (is_array($nav_options[0]))
 398              {
 399                  foreach ($nav_options[0] as $sub_menus)
 400                  {
 401                      if (isset($sub_menus['route']) && $sub_menus['route'] === $active_route)
 402                      {
 403                          return $current_menu;
 404                      }
 405                  }
 406              }
 407          }
 408   
 409          return false;
 410      }
 411   
 412      /**
 413       * Sorts the top level of navigation array
 414       *
 415       * @param array    $nav_array    Navigation array
 416       *
 417       * @return array
 418       */
 419      protected function sort_navigation_level($nav_array)
 420      {
 421          $sorted = array();
 422          foreach ($nav_array as $key => $nav)
 423          {
 424              $order = (isset($nav['order'])) ? $nav['order'] : 0;
 425              $sorted[$order][$key] = $nav;
 426          }
 427   
 428          // Linearization of navigation array
 429          $nav_array = array();
 430          ksort($sorted);
 431          foreach ($sorted as $nav)
 432          {
 433              $nav_array = array_merge($nav_array, $nav);
 434          }
 435   
 436          return $nav_array;
 437      }
 438  }
 439