Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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: 09.10.2024, 12:54 - Dateigröße: 10.69 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 \phpbb\language\language
 044       */
 045      protected $language;
 046   
 047      /**
 048       * @var bool|string
 049       */
 050      protected $language_cookie;
 051   
 052      /**
 053       * @var \phpbb\language\language_file_helper
 054       */
 055      protected $lang_helper;
 056   
 057      /**
 058       * @var \phpbb\install\helper\navigation\navigation_provider
 059       */
 060      protected $navigation_provider;
 061   
 062      /**
 063       * @var \phpbb\template\template
 064       */
 065      protected $template;
 066   
 067      /**
 068       * @var \phpbb\path_helper
 069       */
 070      protected $path_helper;
 071   
 072      /**
 073       * @var \phpbb\request\request
 074       */
 075      protected $phpbb_request;
 076   
 077      /**
 078       * @var \phpbb\symfony_request
 079       */
 080      protected $request;
 081   
 082      /**
 083       * @var \phpbb\routing\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       * Process navigation data to reflect active/completed stages
 209       *
 210       * @param \phpbb\install\helper\iohandler\iohandler_interface|null    $iohandler
 211       */
 212      public function handle_navigation($iohandler = null)
 213      {
 214          $nav_data = $this->installer_config->get_navigation_data();
 215   
 216          // Set active navigation stage
 217          if (isset($nav_data['active']) && is_array($nav_data['active']))
 218          {
 219              if ($iohandler !== null)
 220              {
 221                  $iohandler->set_active_stage_menu($nav_data['active']);
 222              }
 223   
 224              $this->navigation_provider->set_nav_property($nav_data['active'], array(
 225                  'selected'    => true,
 226                  'completed'    => false,
 227              ));
 228          }
 229   
 230          // Set finished navigation stages
 231          if (isset($nav_data['finished']) && is_array($nav_data['finished']))
 232          {
 233              foreach ($nav_data['finished'] as $finished_stage)
 234              {
 235                  if ($iohandler !== null)
 236                  {
 237                      $iohandler->set_finished_stage_menu($finished_stage);
 238                  }
 239   
 240                  $this->navigation_provider->set_nav_property($finished_stage, array(
 241                      'selected'    => false,
 242                      'completed'    => true,
 243                  ));
 244              }
 245          }
 246      }
 247   
 248      /**
 249       * Set default template variables
 250       *
 251       * @param string    $page_title            Title of the page
 252       * @param bool        $selected_language    True to enable language selector it, false otherwise
 253       */
 254      protected function page_header($page_title, $selected_language = false)
 255      {
 256          // Path to templates
 257          $paths = array($this->phpbb_root_path . 'install/update/new/adm/', $this->phpbb_admin_path);
 258          $paths = array_filter($paths, 'is_dir');
 259          $path = array_shift($paths);
 260          $path = substr($path, strlen($this->phpbb_root_path));
 261   
 262          $this->template->assign_vars(array(
 263              'L_CHANGE'                => $this->language->lang('CHANGE'),
 264              'L_COLON'                => $this->language->lang('COLON'),
 265              'L_INSTALL_PANEL'        => $this->language->lang('INSTALL_PANEL'),
 266              'L_SELECT_LANG'            => $this->language->lang('SELECT_LANG'),
 267              'L_SKIP'                => $this->language->lang('SKIP'),
 268              'PAGE_TITLE'            => $this->language->lang($page_title),
 269              'T_IMAGE_PATH'            => $this->path_helper->get_web_root_path() . $path . 'images',
 270              'T_JQUERY_LINK'            => $this->path_helper->get_web_root_path() . $path . '../assets/javascript/jquery.min.js',
 271              'T_TEMPLATE_PATH'        => $this->path_helper->get_web_root_path() . $path . 'style',
 272              'T_ASSETS_PATH'            => $this->path_helper->get_web_root_path() . $path . '../assets',
 273   
 274              'S_CONTENT_DIRECTION'     => $this->language->lang('DIRECTION'),
 275              'S_CONTENT_FLOW_BEGIN'    => ($this->language->lang('DIRECTION') === 'ltr') ? 'left' : 'right',
 276              'S_CONTENT_FLOW_END'    => ($this->language->lang('DIRECTION') === 'ltr') ? 'right' : 'left',
 277              'S_CONTENT_ENCODING'     => 'UTF-8',
 278              'S_LANG_SELECT'            => $selected_language,
 279   
 280              'S_USER_LANG'            => $this->language->lang('USER_LANG'),
 281          ));
 282   
 283          $this->render_navigation();
 284      }
 285   
 286      /**
 287       * Render navigation
 288       */
 289      protected function render_navigation()
 290      {
 291          // Get navigation items
 292          $nav_array = $this->navigation_provider->get();
 293          $nav_array = $this->sort_navigation_level($nav_array);
 294   
 295          $active_main_menu = $this->get_active_main_menu($nav_array);
 296   
 297          // Pass navigation to template
 298          foreach ($nav_array as $key => $entry)
 299          {
 300              $this->template->assign_block_vars('t_block1', array(
 301                  'L_TITLE' => $this->language->lang($entry['label']),
 302                  'S_SELECTED' => ($active_main_menu === $key),
 303                  'U_TITLE' => $this->route($entry['route']),
 304              ));
 305   
 306              if (is_array($entry[0]) && $active_main_menu === $key)
 307              {
 308                  $entry[0] = $this->sort_navigation_level($entry[0]);
 309   
 310                  foreach ($entry[0] as $name => $sub_entry)
 311                  {
 312                      if (isset($sub_entry['stage']) && $sub_entry['stage'] === true)
 313                      {
 314                          $this->template->assign_block_vars('l_block2', array(
 315                              'L_TITLE' => $this->language->lang($sub_entry['label']),
 316                              'S_SELECTED' => (isset($sub_entry['selected']) && $sub_entry['selected'] === true),
 317                              'S_COMPLETE' => (isset($sub_entry['completed']) && $sub_entry['completed'] === true),
 318                              'STAGE_NAME' => $name,
 319                          ));
 320                      }
 321                      else
 322                      {
 323                          $this->template->assign_block_vars('l_block1', array(
 324                              'L_TITLE' => $this->language->lang($sub_entry['label']),
 325                              'S_SELECTED' => (isset($sub_entry['route']) && $sub_entry['route'] === $this->request->get('_route')),
 326                              'U_TITLE' => $this->route($sub_entry['route']),
 327                          ));
 328                      }
 329                  }
 330              }
 331          }
 332      }
 333   
 334      /**
 335       * Render language select form
 336       *
 337       * @param string    $selected_language
 338       */
 339      protected function render_language_select($selected_language = null)
 340      {
 341          $langs = $this->lang_helper->get_available_languages();
 342          foreach ($langs as $lang)
 343          {
 344              $this->template->assign_block_vars('language_select_item', array(
 345                  'VALUE' => $lang['iso'],
 346                  'NAME' => $lang['local_name'],
 347                  'SELECTED' => ($lang['iso'] === $selected_language),
 348              ));
 349          }
 350      }
 351   
 352      /**
 353       * Returns the name of the active main menu item
 354       *
 355       * @param array    $nav_array
 356       *
 357       * @return string|bool    Returns the name of the active main menu element, if the element not found, returns false
 358       */
 359      protected function get_active_main_menu($nav_array)
 360      {
 361          $active_route = $this->request->get('_route');
 362   
 363          foreach ($nav_array as $nav_name => $nav_options)
 364          {
 365              $current_menu = $nav_name;
 366   
 367              if (isset($nav_options['route']) && $nav_options['route'] === $active_route)
 368              {
 369                  return $nav_name;
 370              }
 371   
 372              if (is_array($nav_options[0]))
 373              {
 374                  foreach ($nav_options[0] as $sub_menus)
 375                  {
 376                      if (isset($sub_menus['route']) && $sub_menus['route'] === $active_route)
 377                      {
 378                          return $current_menu;
 379                      }
 380                  }
 381              }
 382          }
 383   
 384          return false;
 385      }
 386   
 387      /**
 388       * Sorts the top level of navigation array
 389       *
 390       * @param array    $nav_array    Navigation array
 391       *
 392       * @return array
 393       */
 394      protected function sort_navigation_level($nav_array)
 395      {
 396          $sorted = array();
 397          foreach ($nav_array as $key => $nav)
 398          {
 399              $order = (isset($nav['order'])) ? $nav['order'] : 0;
 400              $sorted[$order][$key] = $nav;
 401          }
 402   
 403          // Linearization of navigation array
 404          $nav_array = array();
 405          ksort($sorted);
 406          foreach ($sorted as $nav)
 407          {
 408              $nav_array = array_merge($nav_array, $nav);
 409          }
 410   
 411          return $nav_array;
 412      }
 413  }
 414