Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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