[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/includes/acp/ -> acp_language.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  class acp_language
  23  {
  24      var $u_action;
  25      var $main_files;
  26      var $language_header = '';
  27      var $lang_header = '';
  28  
  29      var $language_file = '';
  30      var $language_directory = '';
  31  
  32  	function main($id, $mode)
  33      {
  34          global $config, $db, $user, $template, $phpbb_log, $phpbb_container;
  35          global $phpbb_root_path, $phpEx, $request, $phpbb_dispatcher;
  36  
  37          if (!function_exists('validate_language_iso_name'))
  38          {
  39              include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  40          }
  41  
  42          // Check and set some common vars
  43          $action        = (isset($_POST['update_details'])) ? 'update_details' : '';
  44          $action        = (isset($_POST['remove_store'])) ? 'details' : $action;
  45  
  46          $submit = (empty($action) && !isset($_POST['update']) && !isset($_POST['test_connection'])) ? false : true;
  47          $action = (empty($action)) ? $request->variable('action', '') : $action;
  48  
  49          $form_name = 'acp_lang';
  50          add_form_key('acp_lang');
  51  
  52          $lang_id = $request->variable('id', 0);
  53  
  54          $selected_lang_file = $request->variable('language_file', '|common.' . $phpEx);
  55  
  56          list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file);
  57  
  58          $this->language_directory = basename($this->language_directory);
  59          $this->language_file = basename($this->language_file);
  60  
  61          $user->add_lang('acp/language');
  62          $this->tpl_name = 'acp_language';
  63          $this->page_title = 'ACP_LANGUAGE_PACKS';
  64  
  65          switch ($action)
  66          {
  67              case 'update_details':
  68  
  69                  if (!$submit || !check_form_key($form_name))
  70                  {
  71                      trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
  72                  }
  73  
  74                  if (!$lang_id)
  75                  {
  76                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
  77                  }
  78  
  79                  $sql = 'SELECT *
  80                      FROM ' . LANG_TABLE . "
  81                      WHERE lang_id = $lang_id";
  82                  $result = $db->sql_query($sql);
  83                  $row = $db->sql_fetchrow($result);
  84                  $db->sql_freeresult($result);
  85  
  86                  $sql_ary    = array(
  87                      'lang_english_name'        => $request->variable('lang_english_name', $row['lang_english_name']),
  88                      'lang_local_name'        => $request->variable('lang_local_name', $row['lang_local_name'], true),
  89                      'lang_author'            => $request->variable('lang_author', $row['lang_author'], true),
  90                  );
  91  
  92                  $db->sql_query('UPDATE ' . LANG_TABLE . '
  93                      SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  94                      WHERE lang_id = ' . $lang_id);
  95  
  96                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_LANGUAGE_PACK_UPDATED', false, array($sql_ary['lang_english_name']));
  97  
  98                  trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action));
  99              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                      $delete_message = sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']);
 233                      $lang_iso = $row['lang_iso'];
 234                      /**
 235                       * Run code after language deleted
 236                       *
 237                       * @event core.acp_language_after_delete
 238                       * @var    string     lang_iso         Language ISO code
 239                       * @var    string  delete_message  Delete message appear to user
 240                       * @since 3.2.2-RC1
 241                       */
 242                      $vars = array('lang_iso', 'delete_message');
 243                      extract($phpbb_dispatcher->trigger_event('core.acp_language_after_delete', compact($vars)));
 244  
 245                      trigger_error($delete_message . adm_back_link($this->u_action));
 246                  }
 247                  else
 248                  {
 249                      $s_hidden_fields = array(
 250                          'i'            => $id,
 251                          'mode'        => $mode,
 252                          'action'    => $action,
 253                          'id'        => $lang_id,
 254                      );
 255                      confirm_box(false, $user->lang('DELETE_LANGUAGE_CONFIRM', $row['lang_english_name']), build_hidden_fields($s_hidden_fields));
 256                  }
 257              break;
 258  
 259              case 'install':
 260                  if (!check_link_hash($request->variable('hash', ''), 'acp_language'))
 261                  {
 262                      trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 263                  }
 264  
 265                  $lang_iso = $request->variable('iso', '');
 266                  $lang_iso = basename($lang_iso);
 267  
 268                  if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/iso.txt"))
 269                  {
 270                      trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
 271                  }
 272  
 273                  $file = file("{$phpbb_root_path}language/$lang_iso/iso.txt");
 274  
 275                  $lang_pack = array(
 276                      'iso'        => $lang_iso,
 277                      'name'        => trim(htmlspecialchars($file[0])),
 278                      'local_name'=> trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')),
 279                      'author'    => trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8'))
 280                  );
 281                  unset($file);
 282  
 283                  $sql = 'SELECT lang_iso
 284                      FROM ' . LANG_TABLE . "
 285                      WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'";
 286                  $result = $db->sql_query($sql);
 287                  $row = $db->sql_fetchrow($result);
 288                  $db->sql_freeresult($result);
 289  
 290                  if ($row)
 291                  {
 292                      trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action), E_USER_WARNING);
 293                  }
 294  
 295                  if (!$lang_pack['name'] || !$lang_pack['local_name'])
 296                  {
 297                      trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action), E_USER_WARNING);
 298                  }
 299  
 300                  // Add language pack
 301                  $sql_ary = array(
 302                      'lang_iso'            => $lang_pack['iso'],
 303                      'lang_dir'            => $lang_pack['iso'],
 304                      'lang_english_name'    => $lang_pack['name'],
 305                      'lang_local_name'    => $lang_pack['local_name'],
 306                      'lang_author'        => $lang_pack['author']
 307                  );
 308  
 309                  $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
 310                  $lang_id = $db->sql_nextid();
 311  
 312                  // Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier.
 313                  $sql = 'SELECT lang_id
 314                      FROM ' . LANG_TABLE . "
 315                      WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
 316                  $result = $db->sql_query($sql);
 317                  $default_lang_id = (int) $db->sql_fetchfield('lang_id');
 318                  $db->sql_freeresult($result);
 319  
 320                  // We want to notify the admin that custom profile fields need to be updated for the new language.
 321                  $notify_cpf_update = false;
 322  
 323                  // From the mysql documentation:
 324                  // 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.
 325                  // Due to this we stay on the safe side if we do the insertion "the manual way"
 326  
 327                  $sql = 'SELECT field_id, lang_name, lang_explain, lang_default_value
 328                      FROM ' . PROFILE_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_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
 336                      $notify_cpf_update = true;
 337                  }
 338                  $db->sql_freeresult($result);
 339  
 340                  $sql = 'SELECT field_id, option_id, field_type, lang_value
 341                      FROM ' . PROFILE_FIELDS_LANG_TABLE . '
 342                      WHERE lang_id = ' . $default_lang_id;
 343                  $result = $db->sql_query($sql);
 344  
 345                  while ($row = $db->sql_fetchrow($result))
 346                  {
 347                      $row['lang_id'] = $lang_id;
 348                      $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
 349                      $notify_cpf_update = true;
 350                  }
 351                  $db->sql_freeresult($result);
 352  
 353                  $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_LANGUAGE_PACK_INSTALLED', false, array($lang_pack['name']));
 354  
 355                  $message = sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']);
 356                  $message .= ($notify_cpf_update) ? '<br /><br />' . $user->lang['LANGUAGE_PACK_CPF_UPDATE'] : '';
 357                  trigger_error($message . adm_back_link($this->u_action));
 358  
 359              break;
 360          }
 361  
 362          $sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count
 363              FROM ' . USERS_TABLE . '
 364              GROUP BY user_lang';
 365          $result = $db->sql_query($sql);
 366  
 367          $lang_count = array();
 368          while ($row = $db->sql_fetchrow($result))
 369          {
 370              $lang_count[$row['user_lang']] = $row['lang_count'];
 371          }
 372          $db->sql_freeresult($result);
 373  
 374          $sql = 'SELECT *
 375              FROM ' . LANG_TABLE . '
 376              ORDER BY lang_english_name';
 377          $result = $db->sql_query($sql);
 378  
 379          $installed = array();
 380  
 381          while ($row = $db->sql_fetchrow($result))
 382          {
 383              $installed[] = $row['lang_iso'];
 384              $tagstyle = ($row['lang_iso'] == $config['default_lang']) ? '*' : '';
 385  
 386              $template->assign_block_vars('lang', array(
 387                  'U_DETAILS'            => $this->u_action . "&amp;action=details&amp;id={$row['lang_id']}",
 388                  'U_DOWNLOAD'        => $this->u_action . "&amp;action=download&amp;id={$row['lang_id']}",
 389                  'U_DELETE'            => $this->u_action . "&amp;action=delete&amp;id={$row['lang_id']}",
 390  
 391                  'ENGLISH_NAME'        => $row['lang_english_name'],
 392                  'TAG'                => $tagstyle,
 393                  'LOCAL_NAME'        => $row['lang_local_name'],
 394                  'ISO'                => $row['lang_iso'],
 395                  'USED_BY'            => (isset($lang_count[$row['lang_iso']])) ? $lang_count[$row['lang_iso']] : 0,
 396              ));
 397          }
 398          $db->sql_freeresult($result);
 399  
 400          $new_ary = $iso = array();
 401  
 402          /** @var \phpbb\language\language_file_helper $language_helper */
 403          $language_helper = $phpbb_container->get('language.helper.language_file');
 404          $iso = $language_helper->get_available_languages();
 405  
 406          foreach ($iso as $lang_array)
 407          {
 408              $lang_iso = $lang_array['iso'];
 409  
 410              if (!in_array($lang_iso, $installed))
 411              {
 412                  $new_ary[$lang_iso] = $lang_array;
 413              }
 414          }
 415  
 416          unset($installed);
 417  
 418          if (count($new_ary))
 419          {
 420              foreach ($new_ary as $iso => $lang_ary)
 421              {
 422                  $template->assign_block_vars('notinst', array(
 423                      'ISO'            => htmlspecialchars($lang_ary['iso']),
 424                      'LOCAL_NAME'    => htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'),
 425                      'NAME'            => htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'),
 426                      'U_INSTALL'        => $this->u_action . '&amp;action=install&amp;iso=' . urlencode($lang_ary['iso']) . '&amp;hash=' . generate_link_hash('acp_language'))
 427                  );
 428              }
 429          }
 430  
 431          unset($new_ary);
 432      }
 433  
 434      /**
 435      * Compare two language files
 436      */
 437  	function compare_language_files($source_lang, $dest_lang, $file)
 438      {
 439          global $phpbb_root_path;
 440  
 441          $source_file = $phpbb_root_path . 'language/' . $source_lang . '/' . $file;
 442          $dest_file = $phpbb_root_path . 'language/' . $dest_lang . '/' . $file;
 443  
 444          if (!file_exists($dest_file))
 445          {
 446              return array();
 447          }
 448  
 449          $lang = array();
 450          include($source_file);
 451          $lang_entry_src = $lang;
 452  
 453          $lang = array();
 454          include($dest_file);
 455          $lang_entry_dst = $lang;
 456  
 457          unset($lang);
 458  
 459          return array_diff(array_keys($lang_entry_src), array_keys($lang_entry_dst));
 460      }
 461  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1