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

acp_language.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 13.84 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  /**
015  * @ignore
016  */
017  if (!defined('IN_PHPBB'))
018  {
019      exit;
020  }
021   
022  class acp_language
023  {
024      var $u_action;
025      var $main_files;
026      var $language_header = '';
027      var $lang_header = '';
028   
029      var $language_file = '';
030      var $language_directory = '';
031   
032      function main($id, $mode)
033      {
034          global $config, $db, $user, $template, $phpbb_log, $phpbb_container;
035          global $phpbb_root_path, $phpEx, $request;
036   
037          if (!function_exists('validate_language_iso_name'))
038          {
039              include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
040          }
041   
042          // Check and set some common vars
043          $action        = (isset($_POST['update_details'])) ? 'update_details' : '';
044          $action        = (isset($_POST['remove_store'])) ? 'details' : $action;
045   
046          $submit = (empty($action) && !isset($_POST['update']) && !isset($_POST['test_connection'])) ? false : true;
047          $action = (empty($action)) ? $request->variable('action', '') : $action;
048   
049          $form_name = 'acp_lang';
050          add_form_key('acp_lang');
051   
052          $lang_id = $request->variable('id', 0);
053   
054          $selected_lang_file = $request->variable('language_file', '|common.' . $phpEx);
055   
056          list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file);
057   
058          $this->language_directory = basename($this->language_directory);
059          $this->language_file = basename($this->language_file);
060   
061          $user->add_lang('acp/language');
062          $this->tpl_name = 'acp_language';
063          $this->page_title = 'ACP_LANGUAGE_PACKS';
064   
065          switch ($action)
066          {
067              case 'update_details':
068   
069                  if (!$submit || !check_form_key($form_name))
070                  {
071                      trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
072                  }
073   
074                  if (!$lang_id)
075                  {
076                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
077                  }
078   
079                  $sql = 'SELECT *
080                      FROM ' . LANG_TABLE . "
081                      WHERE lang_id = $lang_id";
082                  $result = $db->sql_query($sql);
083                  $row = $db->sql_fetchrow($result);
084                  $db->sql_freeresult($result);
085   
086                  $sql_ary    = array(
087                      'lang_english_name'        => $request->variable('lang_english_name', $row['lang_english_name']),
088                      'lang_local_name'        => $request->variable('lang_local_name', $row['lang_local_name'], true),
089                      'lang_author'            => $request->variable('lang_author', $row['lang_author'], true),
090                  );
091   
092                  $db->sql_query('UPDATE ' . LANG_TABLE . '
093                      SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
094                      WHERE lang_id = ' . $lang_id);
095   
096                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_LANGUAGE_PACK_UPDATED', false, array($sql_ary['lang_english_name']));
097   
098                  trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action));
099              break;
100   
101              case 'details':
102   
103                  if (!$lang_id)
104                  {
105                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
106                  }
107   
108                  $this->page_title = 'LANGUAGE_PACK_DETAILS';
109   
110                  $sql = 'SELECT *
111                      FROM ' . LANG_TABLE . '
112                      WHERE lang_id = ' . $lang_id;
113                  $result = $db->sql_query($sql);
114                  $lang_entries = $db->sql_fetchrow($result);
115                  $db->sql_freeresult($result);
116   
117                  if (!$lang_entries)
118                  {
119                      trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
120                  }
121   
122                  $lang_iso = $lang_entries['lang_iso'];
123   
124                  $template->assign_vars(array(
125                      'S_DETAILS'            => true,
126                      'U_ACTION'            => $this->u_action . "&amp;action=details&amp;id=$lang_id",
127                      'U_BACK'            => $this->u_action,
128   
129                      'LANG_LOCAL_NAME'    => $lang_entries['lang_local_name'],
130                      'LANG_ENGLISH_NAME'    => $lang_entries['lang_english_name'],
131                      'LANG_ISO'            => $lang_iso,
132                      'LANG_AUTHOR'        => $lang_entries['lang_author'],
133                      'L_MISSING_FILES'            => $user->lang('THOSE_MISSING_LANG_FILES', $lang_entries['lang_local_name']),
134                      'L_MISSING_VARS_EXPLAIN'    => $user->lang('THOSE_MISSING_LANG_VARIABLES', $lang_entries['lang_local_name']),
135                  ));
136   
137                  // If current lang is different from the default lang, then highlight missing files and variables
138                  if ($lang_iso != $config['default_lang'])
139                  {
140                      try
141                      {
142                          $iterator = new \RecursiveIteratorIterator(
143                              new \phpbb\recursive_dot_prefix_filter_iterator(
144                                  new \RecursiveDirectoryIterator(
145                                      $phpbb_root_path . 'language/' . $config['default_lang'] . '/',
146                                      \FilesystemIterator::SKIP_DOTS
147                                  )
148                              ),
149                              \RecursiveIteratorIterator::LEAVES_ONLY
150                          );
151                      }
152                      catch (\Exception $e)
153                      {
154                          return array();
155                      }
156   
157                      foreach ($iterator as $file_info)
158                      {
159                          /** @var \RecursiveDirectoryIterator $file_info */
160                          $relative_path = $iterator->getInnerIterator()->getSubPathname();
161                          $relative_path = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path);
162   
163                          if (file_exists($phpbb_root_path . 'language/' . $lang_iso . '/' . $relative_path))
164                          {
165                              if (substr($relative_path, 0 - strlen($phpEx)) === $phpEx)
166                              {
167                                  $missing_vars = $this->compare_language_files($config['default_lang'], $lang_iso, $relative_path);
168   
169                                  if (!empty($missing_vars))
170                                  {
171                                      $template->assign_block_vars('missing_varfile', array(
172                                          'FILE_NAME'            => $relative_path,
173                                      ));
174   
175                                      foreach ($missing_vars as $var)
176                                      {
177                                          $template->assign_block_vars('missing_varfile.variable', array(
178                                                  'VAR_NAME'            => $var,
179                                          ));
180                                      }
181                                  }
182                              }
183                          }
184                          else
185                          {
186                              $template->assign_block_vars('missing_files', array(
187                                  'FILE_NAME' => $relative_path,
188                              ));
189                          }
190                      }
191                  }
192                  return;
193              break;
194   
195              case 'delete':
196   
197                  if (!$lang_id)
198                  {
199                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
200                  }
201   
202                  $sql = 'SELECT *
203                      FROM ' . LANG_TABLE . '
204                      WHERE lang_id = ' . $lang_id;
205                  $result = $db->sql_query($sql);
206                  $row = $db->sql_fetchrow($result);
207                  $db->sql_freeresult($result);
208   
209                  if ($row['lang_iso'] == $config['default_lang'])
210                  {
211                      trigger_error($user->lang['NO_REMOVE_DEFAULT_LANG'] . adm_back_link($this->u_action), E_USER_WARNING);
212                  }
213   
214                  if (confirm_box(true))
215                  {
216                      $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id);
217   
218                      $sql = 'UPDATE ' . USERS_TABLE . "
219                          SET user_lang = '" . $db->sql_escape($config['default_lang']) . "'
220                          WHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
221                      $db->sql_query($sql);
222   
223                      // We also need to remove the translated entries for custom profile fields - we want clean tables, don't we?
224                      $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
225                      $db->sql_query($sql);
226   
227                      $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
228                      $db->sql_query($sql);
229   
230                      $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_LANGUAGE_PACK_DELETED', false, array($row['lang_english_name']));
231   
232                      trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action));
233                  }
234                  else
235                  {
236                      $s_hidden_fields = array(
237                          'i'            => $id,
238                          'mode'        => $mode,
239                          'action'    => $action,
240                          'id'        => $lang_id,
241                      );
242                      confirm_box(false, $user->lang('DELETE_LANGUAGE_CONFIRM', $row['lang_english_name']), build_hidden_fields($s_hidden_fields));
243                  }
244              break;
245   
246              case 'install':
247                  if (!check_link_hash($request->variable('hash', ''), 'acp_language'))
248                  {
249                      trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
250                  }
251   
252                  $lang_iso = $request->variable('iso', '');
253                  $lang_iso = basename($lang_iso);
254   
255                  if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/iso.txt"))
256                  {
257                      trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
258                  }
259   
260                  $file = file("{$phpbb_root_path}language/$lang_iso/iso.txt");
261   
262                  $lang_pack = array(
263                      'iso'        => $lang_iso,
264                      'name'        => trim(htmlspecialchars($file[0])),
265                      'local_name'=> trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')),
266                      'author'    => trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8'))
267                  );
268                  unset($file);
269   
270                  $sql = 'SELECT lang_iso
271                      FROM ' . LANG_TABLE . "
272                      WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'";
273                  $result = $db->sql_query($sql);
274                  $row = $db->sql_fetchrow($result);
275                  $db->sql_freeresult($result);
276   
277                  if ($row)
278                  {
279                      trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action), E_USER_WARNING);
280                  }
281   
282                  if (!$lang_pack['name'] || !$lang_pack['local_name'])
283                  {
284                      trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action), E_USER_WARNING);
285                  }
286   
287                  // Add language pack
288                  $sql_ary = array(
289                      'lang_iso'            => $lang_pack['iso'],
290                      'lang_dir'            => $lang_pack['iso'],
291                      'lang_english_name'    => $lang_pack['name'],
292                      'lang_local_name'    => $lang_pack['local_name'],
293                      'lang_author'        => $lang_pack['author']
294                  );
295   
296                  $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
297                  $lang_id = $db->sql_nextid();
298   
299                  // Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier.
300                  $sql = 'SELECT lang_id
301                      FROM ' . LANG_TABLE . "
302                      WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
303                  $result = $db->sql_query($sql);
304                  $default_lang_id = (int) $db->sql_fetchfield('lang_id');
305                  $db->sql_freeresult($result);
306   
307                  // We want to notify the admin that custom profile fields need to be updated for the new language.
308                  $notify_cpf_update = false;
309   
310                  // From the mysql documentation:
311                  // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
312                  // Due to this we stay on the safe side if we do the insertion "the manual way"
313   
314                  $sql = 'SELECT field_id, lang_name, lang_explain, lang_default_value
315                      FROM ' . PROFILE_LANG_TABLE . '
316                      WHERE lang_id = ' . $default_lang_id;
317                  $result = $db->sql_query($sql);
318   
319                  while ($row = $db->sql_fetchrow($result))
320                  {
321                      $row['lang_id'] = $lang_id;
322                      $db->sql_query('INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
323                      $notify_cpf_update = true;
324                  }
325                  $db->sql_freeresult($result);
326   
327                  $sql = 'SELECT field_id, option_id, field_type, lang_value
328                      FROM ' . PROFILE_FIELDS_LANG_TABLE . '
329                      WHERE lang_id = ' . $default_lang_id;
330                  $result = $db->sql_query($sql);
331   
332                  while ($row = $db->sql_fetchrow($result))
333                  {
334                      $row['lang_id'] = $lang_id;
335                      $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
336                      $notify_cpf_update = true;
337                  }
338                  $db->sql_freeresult($result);
339   
340                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_LANGUAGE_PACK_INSTALLED', false, array($lang_pack['name']));
341   
342                  $message = sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']);
343                  $message .= ($notify_cpf_update) ? '<br /><br />' . $user->lang['LANGUAGE_PACK_CPF_UPDATE'] : '';
344                  trigger_error($message . adm_back_link($this->u_action));
345   
346              break;
347          }
348   
349          $sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count
350              FROM ' . USERS_TABLE . '
351              GROUP BY user_lang';
352          $result = $db->sql_query($sql);
353   
354          $lang_count = array();
355          while ($row = $db->sql_fetchrow($result))
356          {
357              $lang_count[$row['user_lang']] = $row['lang_count'];
358          }
359          $db->sql_freeresult($result);
360   
361          $sql = 'SELECT *
362              FROM ' . LANG_TABLE . '
363              ORDER BY lang_english_name';
364          $result = $db->sql_query($sql);
365   
366          $installed = array();
367   
368          while ($row = $db->sql_fetchrow($result))
369          {
370              $installed[] = $row['lang_iso'];
371              $tagstyle = ($row['lang_iso'] == $config['default_lang']) ? '*' : '';
372   
373              $template->assign_block_vars('lang', array(
374                  'U_DETAILS'            => $this->u_action . "&amp;action=details&amp;id={$row['lang_id']}",
375                  'U_DOWNLOAD'        => $this->u_action . "&amp;action=download&amp;id={$row['lang_id']}",
376                  'U_DELETE'            => $this->u_action . "&amp;action=delete&amp;id={$row['lang_id']}",
377   
378                  'ENGLISH_NAME'        => $row['lang_english_name'],
379                  'TAG'                => $tagstyle,
380                  'LOCAL_NAME'        => $row['lang_local_name'],
381                  'ISO'                => $row['lang_iso'],
382                  'USED_BY'            => (isset($lang_count[$row['lang_iso']])) ? $lang_count[$row['lang_iso']] : 0,
383              ));
384          }
385          $db->sql_freeresult($result);
386   
387          $new_ary = $iso = array();
388   
389          /** @var \phpbb\language\language_file_helper $language_helper */
390          $language_helper = $phpbb_container->get('language.helper.language_file');
391          $iso = $language_helper->get_available_languages();
392   
393          foreach ($iso as $lang_array)
394          {
395              $lang_iso = $lang_array['iso'];
396   
397              if (!in_array($lang_iso, $installed))
398              {
399                  $new_ary[$lang_iso] = $lang_array;
400              }
401          }
402   
403          unset($installed);
404   
405          if (sizeof($new_ary))
406          {
407              foreach ($new_ary as $iso => $lang_ary)
408              {
409                  $template->assign_block_vars('notinst', array(
410                      'ISO'            => htmlspecialchars($lang_ary['iso']),
411                      'LOCAL_NAME'    => htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'),
412                      'NAME'            => htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'),
413                      'U_INSTALL'        => $this->u_action . '&amp;action=install&amp;iso=' . urlencode($lang_ary['iso']) . '&amp;hash=' . generate_link_hash('acp_language'))
414                  );
415              }
416          }
417   
418          unset($new_ary);
419      }
420   
421      /**
422      * Compare two language files
423      */
424      function compare_language_files($source_lang, $dest_lang, $file)
425      {
426          global $phpbb_root_path;
427   
428          $source_file = $phpbb_root_path . 'language/' . $source_lang . '/' . $file;
429          $dest_file = $phpbb_root_path . 'language/' . $dest_lang . '/' . $file;
430   
431          if (!file_exists($dest_file))
432          {
433              return array();
434          }
435   
436          $lang = array();
437          include($source_file);
438          $lang_entry_src = $lang;
439   
440          $lang = array();
441          include($dest_file);
442          $lang_entry_dst = $lang;
443   
444          unset($lang);
445   
446          return array_diff(array_keys($lang_entry_src), array_keys($lang_entry_dst));
447      }
448  }
449