[ Index ]

PHP Cross Reference of phpBB-3.1.12-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;
  35          global $phpbb_root_path, $phpEx, $request;
  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_var('action', '') : $action;
  48  
  49          $form_name = 'acp_lang';
  50          add_form_key('acp_lang');
  51  
  52          $lang_id = request_var('id', 0);
  53  
  54          $selected_lang_file = request_var('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_var('lang_english_name', $row['lang_english_name']),
  88                      'lang_local_name'        => utf8_normalize_nfc(request_var('lang_local_name', $row['lang_local_name'], true)),
  89                      'lang_author'            => utf8_normalize_nfc(request_var('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                  add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $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                      add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $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_var('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                  add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $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          $dp = @opendir("{$phpbb_root_path}language");
 389  
 390          if ($dp)
 391          {
 392              while (($file = readdir($dp)) !== false)
 393              {
 394                  if ($file[0] == '.' || !is_dir($phpbb_root_path . 'language/' . $file))
 395                  {
 396                      continue;
 397                  }
 398  
 399                  if (file_exists("{$phpbb_root_path}language/$file/iso.txt"))
 400                  {
 401                      if (!in_array($file, $installed))
 402                      {
 403                          if ($iso = file("{$phpbb_root_path}language/$file/iso.txt"))
 404                          {
 405                              if (sizeof($iso) == 3)
 406                              {
 407                                  $new_ary[$file] = array(
 408                                      'iso'        => $file,
 409                                      'name'        => trim($iso[0]),
 410                                      'local_name'=> trim($iso[1]),
 411                                      'author'    => trim($iso[2])
 412                                  );
 413                              }
 414                          }
 415                      }
 416                  }
 417              }
 418              closedir($dp);
 419          }
 420  
 421          unset($installed);
 422  
 423          if (sizeof($new_ary))
 424          {
 425              foreach ($new_ary as $iso => $lang_ary)
 426              {
 427                  $template->assign_block_vars('notinst', array(
 428                      'ISO'            => htmlspecialchars($lang_ary['iso']),
 429                      'LOCAL_NAME'    => htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'),
 430                      'NAME'            => htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'),
 431                      'U_INSTALL'        => $this->u_action . '&amp;action=install&amp;iso=' . urlencode($lang_ary['iso']) . '&amp;hash=' . generate_link_hash('acp_language'))
 432                  );
 433              }
 434          }
 435  
 436          unset($new_ary);
 437      }
 438  
 439      /**
 440      * Compare two language files
 441      */
 442  	function compare_language_files($source_lang, $dest_lang, $file)
 443      {
 444          global $phpbb_root_path;
 445  
 446          $source_file = $phpbb_root_path . 'language/' . $source_lang . '/' . $file;
 447          $dest_file = $phpbb_root_path . 'language/' . $dest_lang . '/' . $file;
 448  
 449          if (!file_exists($dest_file))
 450          {
 451              return array();
 452          }
 453  
 454          $lang = array();
 455          include($source_file);
 456          $lang_entry_src = $lang;
 457  
 458          $lang = array();
 459          include($dest_file);
 460          $lang_entry_dst = $lang;
 461  
 462          unset($lang);
 463  
 464          return array_diff(array_keys($lang_entry_src), array_keys($lang_entry_dst));
 465      }
 466  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1