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

language_file_loader.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 5.46 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\language;
 015   
 016  use \phpbb\language\exception\language_file_not_found;
 017   
 018  /**
 019   * Language file loader
 020   */
 021  class language_file_loader
 022  {
 023      /**
 024       * @var string    Path to phpBB's root
 025       */
 026      protected $phpbb_root_path;
 027   
 028      /**
 029       * @var string    Extension of PHP files
 030       */
 031      protected $php_ext;
 032   
 033      /**
 034       * @var \phpbb\extension\manager    Extension manager
 035       */
 036      protected $extension_manager;
 037   
 038      /**
 039       * Constructor
 040       *
 041       * @param string    $phpbb_root_path    Path to phpBB's root
 042       * @param string    $php_ext            Extension of PHP files
 043       */
 044      public function __construct($phpbb_root_path, $php_ext)
 045      {
 046          $this->phpbb_root_path    = $phpbb_root_path;
 047          $this->php_ext            = $php_ext;
 048   
 049          $this->extension_manager = null;
 050      }
 051   
 052      /**
 053       * Extension manager setter
 054       *
 055       * @param \phpbb\extension\manager    $extension_manager    Extension manager
 056       */
 057      public function set_extension_manager(\phpbb\extension\manager $extension_manager)
 058      {
 059          $this->extension_manager = $extension_manager;
 060      }
 061   
 062      /**
 063       * Loads language array for the given component
 064       *
 065       * @param string        $component    Name of the language component
 066       * @param string|array    $locale        ISO code of the language to load, or array of ISO codes if you want to
 067       *                                     specify additional language fallback steps
 068       * @param array            $lang        Array reference containing language strings
 069       */
 070      public function load($component, $locale, &$lang)
 071      {
 072          $locale = (array) $locale;
 073   
 074          // Determine path to language directory
 075          $path = $this->phpbb_root_path . 'language/';
 076   
 077          $this->load_file($path, $component, $locale, $lang);
 078      }
 079   
 080      /**
 081       * Loads language array for the given extension component
 082       *
 083       * @param string        $extension    Name of the extension
 084       * @param string        $component    Name of the language component
 085       * @param string|array    $locale        ISO code of the language to load, or array of ISO codes if you want to
 086       *                                     specify additional language fallback steps
 087       * @param array            $lang        Array reference containing language strings
 088       */
 089      public function load_extension($extension, $component, $locale, &$lang)
 090      {
 091          // Check if extension manager was loaded
 092          if ($this->extension_manager === null)
 093          {
 094              // If not, let's return
 095              return;
 096          }
 097   
 098          $locale = (array) $locale;
 099   
 100          // Determine path to language directory
 101          $path = $this->extension_manager->get_extension_path($extension, true) . 'language/';
 102   
 103          $this->load_file($path, $component, $locale, $lang);
 104      }
 105   
 106      /**
 107       * Prepares language file loading
 108       *
 109       * @param string    $path        Path to search for file in
 110       * @param string    $component    Name of the language component
 111       * @param array        $locale        Array containing language fallback options
 112       * @param array        $lang        Array reference of language strings
 113       */
 114      protected function load_file($path, $component, $locale, &$lang)
 115      {
 116          // This is BC stuff and not the best idea as it makes language fallback
 117          // implementation quite hard like below.
 118          if (strpos($this->phpbb_root_path . $component, $path) === 0)
 119          {
 120              // Filter out the path
 121              $path_diff = str_replace($path, '', dirname($this->phpbb_root_path . $component));
 122              $language_file = basename($component, '.' . $this->php_ext);
 123              $component = '';
 124   
 125              // This step is needed to resolve language/en/subdir style $component
 126              // $path already points to the language base directory so we need to eliminate
 127              // the first directory from the path (that should be the language directory)
 128              $path_diff_parts = explode('/', $path_diff);
 129   
 130              if (sizeof($path_diff_parts) > 1)
 131              {
 132                  array_shift($path_diff_parts);
 133                  $component = implode('/', $path_diff_parts) . '/';
 134              }
 135   
 136              $component .= $language_file;
 137          }
 138   
 139          // Determine filename
 140          $filename = $component . '.' . $this->php_ext;
 141   
 142          // Determine path to file
 143          $file_path = $this->get_language_file_path($path, $filename, $locale);
 144   
 145          // Load language array
 146          $this->load_language_file($file_path, $lang);
 147      }
 148   
 149      /**
 150       * This function implements language fallback logic
 151       *
 152       * @param string    $path        Path to language directory
 153       * @param string    $filename    Filename to load language strings from
 154       *
 155       * @return string    Relative path to language file
 156       *
 157       * @throws language_file_not_found    When the path to the file cannot be resolved
 158       */
 159      protected function get_language_file_path($path, $filename, $locales)
 160      {
 161          $language_file_path = $filename;
 162   
 163          // Language fallback logic
 164          foreach ($locales as $locale)
 165          {
 166              $language_file_path = $path . $locale . '/' . $filename;
 167   
 168              // If we are in install, try to use the updated version, when available
 169              if (defined('IN_INSTALL'))
 170              {
 171                  $install_language_path = str_replace('language/', 'install/update/new/language/', $language_file_path);
 172                  if (file_exists($install_language_path))
 173                  {
 174                      return $install_language_path;
 175                  }
 176              }
 177   
 178              if (file_exists($language_file_path))
 179              {
 180                  return $language_file_path;
 181              }
 182          }
 183   
 184          // The language file is not exist
 185          throw new language_file_not_found('Language file ' . $language_file_path . ' couldn\'t be opened.');
 186      }
 187   
 188      /**
 189       * Loads language file
 190       *
 191       * @param string    $path    Path to language file to load
 192       * @param array        $lang    Reference of the array of language strings
 193       */
 194      protected function load_language_file($path, &$lang)
 195      {
 196          // Do not suppress error if in DEBUG mode
 197          if (defined('DEBUG'))
 198          {
 199              include $path;
 200          }
 201          else
 202          {
 203              @include $path;
 204          }
 205      }
 206  }
 207