[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

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

   1  <?php
   2  /** 
   3  *
   4  * @package acp
   5  * @version $Id: acp_language.php,v 1.33 2006/11/10 13:49:04 acydburn Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * @package acp
  13  */
  14  class acp_language
  15  {
  16      var $u_action;
  17      var $main_files;
  18      var $language_header = '';
  19      var $lang_header = '';
  20  
  21      var $language_file = '';
  22      var $language_directory = '';
  23  
  24  	function main($id, $mode)
  25      {
  26          global $config, $db, $user, $auth, $template, $cache;
  27          global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
  28          global $safe_mode, $file_uploads;
  29  
  30          include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  31  
  32          $this->default_variables();
  33  
  34          // Check and set some common vars
  35          $action        = request_var('action', '');
  36  
  37          $action        = (isset($_POST['update_details'])) ? 'update_details' : $action;
  38          $action        = (isset($_POST['download_file'])) ? 'download_file' : $action;
  39          $action        = (isset($_POST['upload_file'])) ? 'upload_file' : $action;
  40          $action        = (isset($_POST['upload_data'])) ? 'upload_data' : $action;
  41          $action        = (isset($_POST['submit_file'])) ? 'submit_file' : $action;
  42          $action        = (isset($_POST['remove_store'])) ? 'details' : $action;
  43  
  44          $lang_id = request_var('id', 0);
  45          if (isset($_POST['missing_file']))
  46          {
  47              $missing_file = request_var('missing_file', array('' => 0));
  48              list($_REQUEST['language_file'], ) = array_keys($missing_file);
  49          }
  50  
  51          $selected_lang_file = request_var('language_file', '|common.' . $phpEx);
  52  
  53          list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file);
  54  
  55          $this->language_directory = basename($this->language_directory);
  56          $this->language_file = basename($this->language_file);
  57  
  58          $user->add_lang('acp/language');
  59          $this->tpl_name = 'acp_language';
  60          $this->page_title = 'ACP_LANGUAGE_PACKS';
  61  
  62          if ($action == 'upload_data' && request_var('test_connection', ''))
  63          {
  64              $test_connection = false;
  65              $action = 'upload_file';
  66              $method = request_var('method', '');
  67  
  68              include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
  69  
  70              switch ($method)
  71              {
  72                  case 'ftp':
  73                      $transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
  74                  break;
  75  
  76                  case 'ftp_fsock':
  77                      $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
  78                  break;
  79  
  80                  default:
  81                      trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
  82                  break;
  83              }
  84  
  85              $test_connection = $transfer->open_session();
  86              $transfer->close_session();
  87          }
  88  
  89          switch ($action)
  90          {
  91              case 'upload_file':
  92                  include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
  93  
  94                  $method = request_var('method', '');
  95  
  96                  $requested_data = call_user_func(array($method, 'data'));
  97                  foreach ($requested_data as $data => $default)
  98                  {
  99                      $template->assign_block_vars('data', array(
 100                          'DATA'        => $data,
 101                          'NAME'        => $user->lang[strtoupper($method . '_' . $data)],
 102                          'EXPLAIN'    => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'],
 103                          'DEFAULT'    => (!empty($_REQUEST[$data])) ? request_var($data, '') : $default
 104                      ));
 105                  }
 106  
 107                  $hidden_data = build_hidden_fields(array(
 108                      'file'        => $this->language_file,
 109                      'dir'        => $this->language_directory,
 110                      'method'    => $method,
 111                      'entry'        => $_POST['entry']),
 112                      true
 113                  );
 114  
 115                  $template->assign_vars(array(
 116                      'S_UPLOAD'    => true,
 117                      'NAME'        => $method,
 118                      'U_ACTION'    => $this->u_action . "&amp;id=$lang_id&amp;action=upload_data",
 119                      'HIDDEN'    => $hidden_data,
 120  
 121                      'S_CONNECTION_SUCCESS'        => (request_var('test_connection', '') && $test_connection === true) ? true : false,
 122                      'S_CONNECTION_FAILED'        => (request_var('test_connection', '') && $test_connection !== true) ? true : false
 123                  ));
 124              break;
 125  
 126              case 'update_details':
 127  
 128                  if (!$lang_id)
 129                  {
 130                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
 131                  }
 132  
 133                  $sql = 'SELECT *
 134                      FROM ' . LANG_TABLE . "
 135                      WHERE lang_id = $lang_id";
 136                  $result = $db->sql_query($sql);
 137                  $row = $db->sql_fetchrow($result);
 138                  $db->sql_freeresult($result);
 139  
 140                  $sql_ary    = array(
 141                      'lang_english_name'        => request_var('lang_english_name', $row['lang_english_name']),
 142                      'lang_local_name'        => request_var('lang_local_name', $row['lang_local_name'], true),
 143                      'lang_author'            => request_var('lang_author', $row['lang_author'], true),
 144                  );
 145  
 146                  $db->sql_query('UPDATE ' . LANG_TABLE . ' 
 147                      SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 148                      WHERE lang_id = ' . $lang_id);
 149                      
 150                  add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $sql_ary['lang_english_name']);
 151  
 152                  trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action));
 153              break;
 154  
 155              case 'submit_file':
 156              case 'download_file':
 157              case 'upload_data':
 158  
 159                  if (!$lang_id || empty($_POST['entry']))
 160                  {
 161                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
 162                  }
 163  
 164                  if (!$this->language_file || (!$this->language_directory && !in_array($this->language_file, $this->main_files)))
 165                  {
 166                      trigger_error($user->lang['NO_FILE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
 167                  }
 168  
 169                  $sql = 'SELECT *
 170                      FROM ' . LANG_TABLE . "
 171                      WHERE lang_id = $lang_id";
 172                  $result = $db->sql_query($sql);
 173                  $row = $db->sql_fetchrow($result);
 174                  $db->sql_freeresult($result);
 175  
 176                  if (!$safe_mode)
 177                  {
 178                      $mkdir_ary = array('language', 'language/' . $row['lang_iso']);
 179                      
 180                      if ($this->language_directory)
 181                      {
 182                          $mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory;
 183                      }
 184                  
 185                      foreach ($mkdir_ary as $dir)
 186                      {
 187                          $dir = $phpbb_root_path . 'store/' . $dir;
 188              
 189                          if (!is_dir($dir))
 190                          {
 191                              if (!@mkdir($dir, 0777))
 192                              {
 193                                  trigger_error("Could not create directory $dir", E_USER_ERROR);
 194                              }
 195                              @chmod($dir, 0777);
 196                          }
 197                      }
 198                  }
 199  
 200                  // Get target filename for storage folder
 201                  $filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true);
 202                  $fp = fopen($phpbb_root_path . $filename, 'wb');
 203  
 204                  if (!$fp)
 205                  {
 206                      trigger_error(sprintf($user->lang['UNABLE_TO_WRITE_FILE'], $filename) . adm_back_link($this->u_action . '&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
 207                  }
 208  
 209                  if ($this->language_directory == 'email')
 210                  {
 211                      // Email Template
 212                      $entry = $this->prepare_lang_entry($_POST['entry'], false);
 213                      fwrite($fp, $entry);
 214                  }
 215                  else
 216                  {
 217                      $name = (($this->language_directory) ? $this->language_directory . '_' : '') . $this->language_file;
 218                      $header = str_replace(array('{FILENAME}', '{LANG_NAME}', '{CHANGED}', '{AUTHOR}'), array($name, $row['lang_english_name'], date('Y-m-d', time()), $row['lang_author']), $this->language_file_header);
 219  
 220                      if (strpos($this->language_file, 'help_') === 0)
 221                      {
 222                          // Help File
 223                          $header .= '$help = array(' . "\n";
 224                          fwrite($fp, $header);
 225  
 226                          foreach ($_POST['entry'] as $key => $value)
 227                          {
 228                              if (!is_array($value))
 229                              {
 230                                  continue;
 231                              }
 232  
 233                              $entry = "\tarray(\n";
 234                              
 235                              foreach ($value as $_key => $_value)
 236                              {
 237                                  $entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n";
 238                              }
 239  
 240                              $entry .= "\t),\n";
 241                              fwrite($fp, $entry);
 242                          }
 243                      }
 244                      else
 245                      {
 246                          // Language File
 247                          $header .= $this->lang_header;
 248                          fwrite($fp, $header);
 249  
 250                          foreach ($_POST['entry'] as $key => $value)
 251                          {
 252                              $entry = $this->format_lang_array($key, $value);
 253                              fwrite($fp, $entry);
 254                          }
 255                      }
 256  
 257                      $footer = "));\n\n?>";
 258                      fwrite($fp, $footer);
 259                  }
 260  
 261                  fclose($fp);
 262  
 263                  if ($action == 'download_file')
 264                  {
 265                      header('Pragma: no-cache');
 266                      header('Content-Type: application/octetstream; name="' . $this->language_file . '"');
 267                      header('Content-disposition: attachment; filename=' . $this->language_file);
 268  
 269                      $fp = fopen($phpbb_root_path . $filename, 'rb');
 270                      while ($buffer = fread($fp, 1024))
 271                      {
 272                          echo $buffer;
 273                      }
 274                      fclose($fp);
 275                      
 276                      exit;
 277                  }
 278                  else if ($action == 'upload_data')
 279                  {
 280                      $sql = 'SELECT lang_iso
 281                          FROM ' . LANG_TABLE . "
 282                          WHERE lang_id = $lang_id";
 283                      $result = $db->sql_query($sql);
 284                      $row = $db->sql_fetchrow($result);
 285                      $db->sql_freeresult($result);
 286  
 287                      $file = request_var('file', '');
 288                      $dir = request_var('dir', '');
 289  
 290                      $selected_lang_file = $dir . '|' . $file;
 291  
 292                      $old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true);
 293                      $lang_path = 'language/' . $row['lang_iso'] . '/' . (($dir) ? $dir . '/' : '');
 294  
 295                      include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
 296                      $method = request_var('method', '');
 297  
 298                      switch ($method)
 299                      {
 300                          case 'ftp':
 301                              $transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
 302                          break;
 303  
 304                          case 'ftp_fsock':
 305                              $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
 306                          break;
 307  
 308                          default:
 309                              trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
 310                          break;
 311                      }
 312  
 313                      if (($result = $transfer->open_session()) !== true)
 314                      {
 315                          trigger_error($user->lang[$result] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
 316                      }
 317  
 318                      $transfer->rename($lang_path . $file, $lang_path . $file . '.bak');
 319                      $transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file);
 320                      $transfer->close_session();
 321  
 322                      // Remove from storage folder
 323                      @unlink($phpbb_root_path . 'store/' . $lang_path . $file);
 324  
 325                      add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file);
 326  
 327                      trigger_error($user->lang['UPLOAD_COMPLETED'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)));
 328                  }
 329              
 330                  $action = 'details';
 331  
 332              // no break;
 333  
 334              case 'details':
 335  
 336                  if (!$lang_id)
 337                  {
 338                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
 339                  }
 340                  
 341                  $this->page_title = 'LANGUAGE_PACK_DETAILS';
 342  
 343                  $sql = 'SELECT *
 344                      FROM ' . LANG_TABLE . '
 345                      WHERE lang_id = ' . $lang_id;
 346                  $result = $db->sql_query($sql);
 347                  $lang_entries = $db->sql_fetchrow($result);
 348                  $db->sql_freeresult($result);
 349                  
 350                  $lang_iso = $lang_entries['lang_iso'];
 351                  $missing_vars = $missing_files = array();
 352  
 353                  // Get email templates
 354                  $email_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'email', 'txt');
 355                  $email_files = $email_files['email/'];
 356  
 357                  // Get acp files
 358                  $acp_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'acp', $phpEx);
 359                  $acp_files = $acp_files['acp/'];
 360  
 361                  // Get mod files
 362                  $mods_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'mods', $phpEx);
 363                  $mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();
 364  
 365                  // Check if our current filename matches the files
 366                  switch ($this->language_directory)
 367                  {
 368                      case 'email':
 369                          if (!in_array($this->language_file, $email_files))
 370                          {
 371                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
 372                          }
 373                      break;
 374  
 375                      case 'acp':
 376                          if (!in_array($this->language_file, $acp_files))
 377                          {
 378                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
 379                          }
 380                      break;
 381  
 382                      case 'mods':
 383                          if (!in_array($this->language_file, $mods_files))
 384                          {
 385                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
 386                          }
 387                      break;
 388  
 389                      default:
 390                          if (!in_array($this->language_file, $this->main_files))
 391                          {
 392                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
 393                          }
 394                  }
 395                  
 396                  if (isset($_POST['remove_store']))
 397                  {
 398                      $store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true);
 399                      @unlink($phpbb_root_path . $store_filename);
 400                  }
 401  
 402                  include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
 403  
 404                  $methods = transfer::methods();
 405  
 406                  foreach ($methods as $method)
 407                  {
 408                      $template->assign_block_vars('buttons', array(
 409                          'VALUE' => $method
 410                      ));
 411                  }
 412  
 413                  $template->assign_vars(array(
 414                      'S_DETAILS'            => true,
 415                      'U_ACTION'            => $this->u_action . "&amp;action=details&amp;id=$lang_id",
 416                      'U_BACK'            => $this->u_action,
 417                      'LANG_LOCAL_NAME'    => $lang_entries['lang_local_name'],
 418                      'LANG_ENGLISH_NAME'    => $lang_entries['lang_english_name'],
 419                      'LANG_ISO'            => $lang_entries['lang_iso'],
 420                      'LANG_AUTHOR'        => $lang_entries['lang_author'],
 421                      'ALLOW_UPLOAD'        => sizeof($methods)
 422                      )
 423                  );
 424  
 425                  // If current lang is different from the default lang, then first try to grab missing/additional vars
 426                  if ($lang_iso != $config['default_lang'])
 427                  {
 428                      $is_missing_var = false;
 429  
 430                      foreach ($this->main_files as $file)
 431                      {
 432                          if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file)))
 433                          {
 434                              $missing_vars[$file] = $this->compare_language_files($config['default_lang'], $lang_iso, '', $file);
 435                              
 436                              if (sizeof($missing_vars[$file]))
 437                              {
 438                                  $is_missing_var = true;
 439                              }
 440                          }
 441                          else
 442                          {
 443                              $missing_files[] = $this->get_filename($lang_iso, '', $file);
 444                          }
 445                      }
 446  
 447                      // Now go through acp/mods directories
 448                      foreach ($acp_files as $file)
 449                      {
 450                          if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'acp', $file)))
 451                          {
 452                              $missing_vars['acp/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'acp', $file);
 453                              
 454                              if (sizeof($missing_vars['acp/' . $file]))
 455                              {
 456                                  $is_missing_var = true;
 457                              }
 458                          }
 459                          else
 460                          {
 461                              $missing_files[] = $this->get_filename($lang_iso, 'acp', $file);
 462                          }
 463                      }
 464  
 465                      if (sizeof($mods_files))
 466                      {
 467                          foreach ($mods_files as $file)
 468                          {
 469                              if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'mods', $file)))
 470                              {
 471                                  $missing_vars['mods/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'mods', $file);
 472                                  
 473                                  if (sizeof($missing_vars['mods/' . $file]))
 474                                  {
 475                                      $is_missing_var = true;
 476                                  }
 477                              }
 478                              else
 479                              {
 480                                  $missing_files[] = $this->get_filename($lang_iso, 'mods', $file);
 481                              }
 482                          }
 483                      }
 484                  
 485                      // More missing files... for example email templates?
 486                      foreach ($email_files as $file)
 487                      {
 488                          if (!file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'email', $file)))
 489                          {
 490                              $missing_files[] = $this->get_filename($lang_iso, 'email', $file);
 491                          }
 492                      }
 493  
 494                      if (sizeof($missing_files))
 495                      {
 496                          $template->assign_vars(array(
 497                              'S_MISSING_FILES'        => true,
 498                              'L_MISSING_FILES'        => sprintf($user->lang['THOSE_MISSING_LANG_FILES'], $lang_entries['lang_local_name']),
 499                              'MISSING_FILES'            => implode('<br />', $missing_files))
 500                          );
 501                      }
 502  
 503                      if ($is_missing_var)
 504                      {
 505                          $template->assign_vars(array(
 506                              'S_MISSING_VARS'            => true,
 507                              'L_MISSING_VARS_EXPLAIN'    => sprintf($user->lang['THOSE_MISSING_LANG_VARIABLES'], $lang_entries['lang_local_name']),
 508                              'U_MISSING_ACTION'            => $this->u_action . "&amp;action=$action&amp;id=$lang_id")
 509                          );
 510  
 511                          foreach ($missing_vars as $file => $vars)
 512                          {
 513                              if (!sizeof($vars))
 514                              {
 515                                  continue;
 516                              }
 517  
 518                              $template->assign_block_vars('missing', array(
 519                                  'FILE'            => $file,
 520                                  'TPL'            => $this->print_language_entries($vars, '', false),
 521                                  'KEY'            => (strpos($file, '/') === false) ? '|' . $file : str_replace('/', '|', $file))
 522                              );
 523                          }
 524                      }
 525                  }
 526  
 527                  // Main language files
 528                  $s_lang_options = '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['LANGUAGE_FILES'] . '</option>';
 529                  foreach ($this->main_files as $file)
 530                  {
 531                      if (strpos($file, 'help_') === 0)
 532                      {
 533                          continue;
 534                      }
 535  
 536                      $prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
 537  
 538                      $selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
 539                      $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
 540                  }
 541  
 542                  // Help Files
 543                  $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['HELP_FILES'] . '</option>';
 544                  foreach ($this->main_files as $file)
 545                  {
 546                      if (strpos($file, 'help_') !== 0)
 547                      {
 548                          continue;
 549                      }
 550  
 551                      $prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
 552  
 553                      $selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
 554                      $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
 555                  }
 556  
 557                  // Now every other language directory
 558                  $check_files = array('email', 'acp', 'mods');
 559  
 560                  foreach ($check_files as $check)
 561                  {
 562                      if (!sizeof(${$check . '_files'}))
 563                      {
 564                          continue;
 565                      }
 566  
 567                      $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang[strtoupper($check) . '_FILES'] . '</option>';
 568  
 569                      foreach (${$check . '_files'} as $file)
 570                      {
 571                          $prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $check, $file, true, true))) ? '* ' : '';
 572  
 573                          $selected = ($this->language_directory == $check && $this->language_file == $file) ? ' selected="selected"' : '';
 574                          $s_lang_options .= '<option value="' . $check . '|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
 575                      }
 576                  }
 577  
 578                  // Get Language Entries - if saved within store folder, we take this one (with the option to remove it)
 579                  $lang = array();
 580  
 581                  $is_email_file = ($this->language_directory == 'email') ? true : false;
 582                  $is_help_file = (strpos($this->language_file, 'help_') === 0) ? true : false;
 583  
 584                  $file_from_store = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true))) ? true : false;
 585                  $no_store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file);
 586  
 587                  if (!$file_from_store && !file_exists($phpbb_root_path . $no_store_filename))
 588                  {
 589                      $print_message = sprintf($user->lang['MISSING_LANGUAGE_FILE'], $no_store_filename);
 590                  }
 591                  else
 592                  {
 593                      if ($is_email_file)
 594                      {
 595                          $lang = file_get_contents($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
 596                      }
 597                      else
 598                      {
 599                          $help = array();
 600                          include($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
 601  
 602                          if ($is_help_file)
 603                          {
 604                              $lang = $help;
 605                              unset($help);
 606                          }
 607                      }
 608  
 609                      $print_message = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
 610                  }
 611  
 612                  // Normal language pack entries
 613                  $template->assign_vars(array(
 614                      'U_ENTRY_ACTION'        => $this->u_action . "&amp;action=details&amp;id=$lang_id#entries",
 615                      'S_EMAIL_FILE'            => $is_email_file,
 616                      'S_FROM_STORE'            => $file_from_store,
 617                      'S_LANG_OPTIONS'        => $s_lang_options,
 618                      'PRINT_MESSAGE'            => $print_message,
 619                      )
 620                  );
 621  
 622                  if (!$is_email_file)
 623                  {
 624                      $method = ($is_help_file) ? 'print_help_entries' : 'print_language_entries';
 625                      $tpl = '';
 626                      $name = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
 627  
 628                      if (isset($missing_vars[$name]) && sizeof($missing_vars[$name]))
 629                      {
 630                          $tpl .= $this->$method($missing_vars[$name], '* ');
 631                      }
 632  
 633                      $tpl .= $this->$method($lang);
 634  
 635                      $template->assign_var('TPL', $tpl);
 636                      unset($tpl);
 637                  }
 638                  else
 639                  {
 640                      $template->assign_vars(array(
 641                          'LANG'        => $lang)
 642                      );
 643  
 644                      unset($lang);
 645                  }
 646  
 647                  return;
 648  
 649              break;
 650  
 651              case 'delete':
 652  
 653                  if (!$lang_id)
 654                  {
 655                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
 656                  }
 657  
 658                  $sql = 'SELECT *
 659                      FROM ' . LANG_TABLE . '
 660                      WHERE lang_id = ' . $lang_id;
 661                  $result = $db->sql_query($sql);
 662                  $row = $db->sql_fetchrow($result);
 663                  $db->sql_freeresult($result);
 664  
 665                  if ($row['lang_iso'] == $config['default_lang'])
 666                  {
 667                      trigger_error($user->lang['NO_REMOVE_DEFAULT_LANG'] . adm_back_link($this->u_action), E_USER_WARNING);
 668                  }
 669  
 670                  $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id);
 671  
 672                  $sql = 'UPDATE ' . USERS_TABLE . " 
 673                      SET user_lang = '" . $db->sql_escape($config['default_lang']) . "'
 674                      WHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
 675                  $db->sql_query($sql);
 676  
 677                  add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']);
 678  
 679                  trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action));
 680              break;
 681  
 682              case 'install':
 683                  $lang_iso = request_var('iso', '');
 684                  $lang_iso = basename($lang_iso);
 685  
 686                  if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/iso.txt"))
 687                  {
 688                      trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
 689                  }
 690  
 691                  $file = file("{$phpbb_root_path}language/$lang_iso/iso.txt");
 692  
 693                  $lang_pack = array(
 694                      'iso'        => $lang_iso,
 695                      'name'        => trim(htmlspecialchars($file[0])),
 696                      'local_name'=> trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')),
 697                      'author'    => trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8'))
 698                  );
 699                  unset($file);
 700  
 701                  $sql = 'SELECT lang_iso
 702                      FROM ' . LANG_TABLE . "
 703                      WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'";
 704                  $result = $db->sql_query($sql);
 705                  $row = $db->sql_fetchrow($result);
 706                  $db->sql_freeresult($result);
 707  
 708                  if ($row)
 709                  {
 710                      trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action), E_USER_WARNING);
 711                  }
 712  
 713                  if (!$lang_pack['name'] || !$lang_pack['local_name'])
 714                  {
 715                      trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action), E_USER_WARNING);
 716                  }
 717  
 718                  // Add language pack
 719                  $sql_ary = array(
 720                      'lang_iso'            => $lang_pack['iso'],
 721                      'lang_dir'            => $lang_pack['iso'],
 722                      'lang_english_name'    => $lang_pack['name'],
 723                      'lang_local_name'    => $lang_pack['local_name'],
 724                      'lang_author'        => $lang_pack['author']
 725                  );
 726  
 727                  $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
 728  
 729                  add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']);
 730  
 731                  trigger_error(sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']) . adm_back_link($this->u_action));
 732  
 733              break;
 734  
 735              case 'download':
 736  
 737                  if (!$lang_id)
 738                  {
 739                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
 740                  }
 741  
 742                  $sql = 'SELECT * 
 743                      FROM ' . LANG_TABLE . '
 744                      WHERE lang_id = ' . $lang_id;
 745                  $result = $db->sql_query($sql);
 746                  $row = $db->sql_fetchrow($result);
 747                  $db->sql_freeresult($result);
 748  
 749                  $use_method = request_var('use_method', '');
 750                  $methods = array('.tar');
 751  
 752                  $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
 753                  foreach ($available_methods as $type => $module)
 754                  {
 755                      if (!@extension_loaded($module))
 756                      {
 757                          continue;
 758                      }
 759  
 760                      $methods[] = $type;
 761                  }
 762  
 763                  // Let the user decide in which format he wants to have the pack
 764                  if (!$use_method)
 765                  {
 766                      $this->page_title = 'SELECT_DOWNLOAD_FORMAT';
 767  
 768                      $radio_buttons = '';
 769                      foreach ($methods as $method)
 770                      {
 771                          $radio_buttons .= '<input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" />&nbsp;' . $method . '&nbsp;';
 772                      }
 773  
 774                      $template->assign_vars(array(
 775                          'S_SELECT_METHOD'        => true,
 776                          'U_BACK'                => $this->u_action,
 777                          'U_ACTION'                => $this->u_action . "&amp;action=$action&amp;id=$lang_id",
 778                          'RADIO_BUTTONS'            => $radio_buttons)
 779                      );
 780  
 781                      return;
 782                  }
 783  
 784                  if (!in_array($use_method, $methods))
 785                  {
 786                      $use_method = '.tar';
 787                  }
 788  
 789                  include_once($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
 790  
 791                  if ($use_method == '.zip')
 792                  {
 793                      $compress = new compress_zip('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
 794                  }
 795                  else
 796                  {
 797                      $compress = new compress_tar('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method, $use_method);
 798                  }
 799  
 800                  // Get email templates
 801                  $email_templates = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
 802                  $email_templates = $email_templates['email/'];
 803  
 804                  // Get acp files
 805                  $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
 806                  $acp_files = $acp_files['acp/'];
 807  
 808                  // Get mod files
 809                  $mod_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
 810                  $mod_files = (isset($mod_files['mods/'])) ? $mod_files['mods/'] : array();
 811  
 812                  // Add main files
 813                  $this->add_to_archive($compress, $this->main_files, $row['lang_iso']);
 814  
 815                  // Add search files if they exist...
 816                  if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_ignore_words.' . $phpEx))
 817                  {
 818                      $this->add_to_archive($compress, array("search_ignore_words.$phpEx"), $row['lang_iso']);
 819                  }
 820  
 821                  if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_synonyms.' . $phpEx))
 822                  {
 823                      $this->add_to_archive($compress, array("search_synonyms.$phpEx"), $row['lang_iso']);
 824                  }
 825  
 826                  // Write files in folders
 827                  $this->add_to_archive($compress, $email_templates, $row['lang_iso'], 'email');
 828                  $this->add_to_archive($compress, $acp_files, $row['lang_iso'], 'acp');
 829                  $this->add_to_archive($compress, $mod_files, $row['lang_iso'], 'mods');
 830  
 831                  // Write ISO File
 832                  $iso_src = htmlspecialchars_decode($row['lang_english_name']) . "\n";
 833                  $iso_src .= htmlspecialchars_decode($row['lang_local_name']) . "\n";
 834                  $iso_src .= htmlspecialchars_decode($row['lang_author']);
 835                  $compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt');
 836  
 837                  // index.html files
 838                  $compress->add_data('', 'language/' . $row['lang_iso'] . '/index.html');
 839                  $compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.html');
 840                  $compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.html');
 841                  
 842                  if (sizeof($mod_files))
 843                  {
 844                      $compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.html');
 845                  }
 846  
 847                  $compress->close();
 848  
 849                  $compress->download('lang_' . $row['lang_iso']);
 850                  @unlink($phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
 851  
 852                  exit;
 853  
 854              break;
 855          }
 856  
 857          $sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count
 858              FROM ' . USERS_TABLE . ' 
 859              GROUP BY user_lang';
 860          $result = $db->sql_query($sql);
 861  
 862          $lang_count = array();
 863          while ($row = $db->sql_fetchrow($result))
 864          {
 865              $lang_count[$row['user_lang']] = $row['lang_count'];
 866          }
 867          $db->sql_freeresult($result);
 868  
 869          $sql = 'SELECT *  
 870              FROM ' . LANG_TABLE . '
 871              ORDER BY lang_english_name';
 872          $result = $db->sql_query($sql);
 873  
 874          $installed = array();
 875  
 876          while ($row = $db->sql_fetchrow($result))
 877          {
 878              $installed[] = $row['lang_iso'];
 879              $tagstyle = ($row['lang_iso'] == $config['default_lang']) ? '*' : '';
 880  
 881              $template->assign_block_vars('lang', array(
 882                  'U_DETAILS'            => $this->u_action . "&amp;action=details&amp;id={$row['lang_id']}",
 883                  'U_DOWNLOAD'        => $this->u_action . "&amp;action=download&amp;id={$row['lang_id']}",
 884                  'U_DELETE'            => $this->u_action . "&amp;action=delete&amp;id={$row['lang_id']}",
 885  
 886                  'ENGLISH_NAME'        => $row['lang_english_name'],
 887                  'TAG'                => $tagstyle,
 888                  'LOCAL_NAME'        => $row['lang_local_name'],
 889                  'ISO'                => $row['lang_iso'],
 890                  'USED_BY'            => (isset($lang_count[$row['lang_iso']])) ? $lang_count[$row['lang_iso']] : 0,
 891              ));
 892          }
 893          $db->sql_freeresult($result);
 894  
 895          $new_ary = $iso = array();
 896          $dp = opendir("{$phpbb_root_path}language");
 897  
 898          while (($file = readdir($dp)) !== false)
 899          {
 900              if ($file[0] != '.' && file_exists("{$phpbb_root_path}language/$file/iso.txt"))
 901              {
 902                  if (!in_array($file, $installed))
 903                  {
 904                      if ($iso = file("{$phpbb_root_path}language/$file/iso.txt"))
 905                      {
 906                          if (sizeof($iso) == 3)
 907                          {
 908                              $new_ary[$file] = array(
 909                                  'iso'        => $file,
 910                                  'name'        => trim($iso[0]),
 911                                  'local_name'=> trim($iso[1]),
 912                                  'author'    => trim($iso[2])
 913                              );
 914                          }
 915                      }
 916                  }
 917              }
 918          }
 919          unset($installed);
 920          @closedir($dp);
 921  
 922          if (sizeof($new_ary))
 923          {
 924              foreach ($new_ary as $iso => $lang_ary)
 925              {
 926                  $template->assign_block_vars('notinst', array(
 927                      'ISO'            => htmlspecialchars($lang_ary['iso']),
 928                      'LOCAL_NAME'    => htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'),
 929                      'NAME'            => htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'),
 930                      'U_INSTALL'        => $this->u_action . '&amp;action=install&amp;iso=' . urlencode($lang_ary['iso']))
 931                  );
 932              }
 933          }
 934  
 935          unset($new_ary);
 936      }
 937  
 938  
 939      /**
 940      * Set default language variables/header
 941      */
 942  	function default_variables()
 943      {
 944          global $phpEx;
 945  
 946          $this->language_file_header = '<?php
 947  /** 
 948  *
 949  * {FILENAME} [{LANG_NAME}]
 950  *
 951  * @package language
 952  * @copyright (c) 2006 phpBB Group 
 953  * @author {CHANGED} - {AUTHOR}
 954  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
 955  *
 956  */
 957  
 958  /**
 959  * DO NOT CHANGE
 960  */
 961  if (empty($lang) || !is_array($lang))
 962  {
 963      $lang = array();
 964  }
 965  
 966  // DEVELOPERS PLEASE NOTE
 967  //
 968  // All language files should use UTF-8 as their encoding and the files must not contain a BOM.
 969  //
 970  // Placeholders can now contain order information, e.g. instead of
 971  // \'Page %s of %s\' you can (and should) write \'Page %1$s of %2$s\', this allows
 972  // translators to re-order the output of data while ensuring it remains correct
 973  //
 974  // You do not need this where single placeholders are used, e.g. \'Message %d\' is fine
 975  // equally where a string contains only two placeholders which are used to wrap text
 976  // in a url you again do not need to specify an order e.g., \'Click %sHERE%s\' is fine
 977  ';
 978  
 979          $this->lang_header = '
 980  $lang = array_merge($lang, array(
 981  ';
 982  
 983          // Language files in language root directory
 984          $this->main_files = array("common.$phpEx", "groups.$phpEx", "install.$phpEx", "mcp.$phpEx", "memberlist.$phpEx", "posting.$phpEx", "search.$phpEx", "ucp.$phpEx", "viewforum.$phpEx", "viewtopic.$phpEx", "help_bbcode.$phpEx", "help_faq.$phpEx");
 985      }
 986  
 987      /**
 988      * Get filename/location of language file
 989      */
 990  	function get_filename($lang_iso, $directory, $filename, $check_store = false, $only_return_filename = false)
 991      {
 992          global $phpbb_root_path, $safe_mode;
 993          
 994          $check_filename = "language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
 995  
 996          if ($check_store)
 997          {
 998              $check_store_filename = ($safe_mode) ? "store/langfile_{$lang_iso}" . (($directory) ? '_' . $directory : '') . "_{$filename}" : "store/language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
 999  
1000              if (!$only_return_filename && file_exists($phpbb_root_path . $check_store_filename))
1001              {
1002                  return $check_store_filename;
1003              }
1004              else if ($only_return_filename)
1005              {
1006                  return $check_store_filename;
1007              }
1008          }
1009  
1010          return $check_filename;
1011      }
1012  
1013      /**
1014      * Add files to archive
1015      */
1016  	function add_to_archive(&$compress, $filelist, $lang_iso, $directory = '')
1017      {
1018          global $phpbb_root_path;
1019  
1020          foreach ($filelist as $file)
1021          {
1022              // Get source filename
1023              $source = $this->get_filename($lang_iso, $directory, $file, true);
1024              $destination = 'language/' . $lang_iso . '/' . (($directory) ? $directory . '/' : '') . $file;
1025  
1026              // Add file to archive
1027              $compress->add_custom_file($phpbb_root_path . $source, $destination);
1028          }
1029      }
1030  
1031      /**
1032      * Print language entries
1033      */
1034  	function print_language_entries(&$lang_ary, $key_prefix = '', $input_field = true)
1035      {
1036          $tpl = '';
1037  
1038          foreach ($lang_ary as $key => $value)
1039          {
1040              if (is_array($value))
1041              {
1042                  $tpl .= '
1043                  <tr>
1044                      <td class="row3" colspan="2">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<b>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</b></td>
1045                  </tr>';
1046  
1047                  foreach ($value as $_key => $_value)
1048                  {
1049                      if (is_array($_value))
1050                      {
1051                          $tpl .= '
1052                              <tr>
1053                                  <td class="row3" colspan="2">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '&nbsp; &nbsp;<b>' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '</b></td>
1054                              </tr>';
1055  
1056                          foreach ($_value as $__key => $__value)
1057                          {
1058                              $tpl .= '
1059                                  <tr>
1060                                      <td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<b>' . htmlspecialchars($__key, ENT_COMPAT, 'UTF-8') . '</b></td>
1061                                      <td class="row2">';
1062  
1063                              if ($input_field)
1064                              {
1065                                  $tpl .= '<input type="text" name="entry[' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '][' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '][' . htmlspecialchars($__key, ENT_COMPAT, 'UTF-8') . ']" value="' . htmlspecialchars($__value, ENT_COMPAT, 'UTF-8') . '" size="50" />';
1066                              }
1067                              else
1068                              {
1069                                  $tpl .= '<b>' . htmlspecialchars($__value, ENT_COMPAT, 'UTF-8') . '</b>';
1070                              }
1071                              
1072                              $tpl .= '</td>
1073                                  </tr>';
1074                          }
1075                      }
1076                      else
1077                      {
1078                          $tpl .= '
1079                              <tr>
1080                                  <td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<b>' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '</b></td>
1081                                  <td class="row2">';
1082  
1083                          if ($input_field)
1084                          {
1085                              $tpl .= '<input type="text" name="entry[' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '][' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . ']" value="' . htmlspecialchars($_value, ENT_COMPAT, 'UTF-8') . '" size="50" />';
1086                          }
1087                          else
1088                          {
1089                              $tpl .= '<b>' . htmlspecialchars($_value, ENT_COMPAT, 'UTF-8') . '</b>';
1090                          }
1091                          
1092                          $tpl .= '</td>
1093                              </tr>';
1094                      }
1095                  }
1096  
1097                  $tpl .= '
1098                  <tr>
1099                      <td class="spacer" colspan="2">&nbsp;</td>
1100                  </tr>';
1101              }
1102              else
1103              {
1104                  $tpl .= '
1105                  <tr>
1106                      <td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<b>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</b></td>
1107                      <td class="row2">';
1108  
1109                  if ($input_field)
1110                  {
1111                      $tpl .= '<input type="text" name="entry[' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . ']" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" size="50" />';
1112                  }
1113                  else
1114                  {
1115                      $tpl .= '<b>' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '</b>';
1116                  }
1117                  
1118                  $tpl .= '</td>
1119                      </tr>';
1120              }
1121          }
1122  
1123          return $tpl;
1124      }
1125  
1126      /**
1127      * Print help entries
1128      */
1129  	function print_help_entries(&$lang_ary, $key_prefix = '', $text_field = true)
1130      {
1131          $tpl = '';
1132          
1133          foreach ($lang_ary as $key => $value)
1134          {
1135              if (is_array($value))
1136              {
1137                  $tpl .= '
1138                  <tr>
1139                      <td class="row3" colspan="2">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<b>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</b></td>
1140                  </tr>';
1141  
1142                  foreach ($value as $_key => $_value)
1143                  {
1144                      $tpl .= '
1145                          <tr>
1146                              <td class="row1" style="width: 10%; white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<b>' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '</b></td>
1147                              <td class="row2">';
1148                      
1149                      if ($text_field)
1150                      {
1151                          $tpl .= '<textarea name="entry[' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '][' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . ']" cols="80" rows="5" style="width: 90%;">' . htmlspecialchars($_value, ENT_COMPAT, 'UTF-8') . '</textarea>';
1152                      }
1153                      else
1154                      {
1155                          $tpl .= '<b>' . htmlspecialchars($_value, ENT_COMPAT, 'UTF-8') . '</b>';
1156                      }
1157                      
1158                      $tpl .= '</td>
1159                          </tr>';
1160                  }
1161  
1162                  $tpl .= '
1163                  <tr>
1164                      <td class="spacer" colspan="2">&nbsp;</td>
1165                  </tr>';
1166              }
1167              else
1168              {
1169                  $tpl .= '
1170                  <tr>
1171                      <td class="row1" style="width: 10%; white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<b>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</b></td>
1172                      <td class="row2">';
1173  
1174                  if ($text_field)
1175                  {
1176                      $tpl .= '<textarea name="entry[' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . ']" cols="80" rows="5" style="width: 90%;">' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '</textarea>';
1177                  }
1178                  else
1179                  {
1180                      $tpl .= '<b>' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '</b>';
1181                  }
1182  
1183                  $tpl .= '</td>
1184                      </tr>';
1185              }
1186          }
1187  
1188          return $tpl;
1189      }
1190  
1191      /**
1192      * Compare two language files
1193      */
1194  	function compare_language_files($source_lang, $dest_lang, $directory, $file)
1195      {
1196          global $phpbb_root_path, $phpEx;
1197  
1198          $return_ary = array();
1199  
1200          $lang = array();
1201          include("{$phpbb_root_path}language/{$source_lang}/" . (($directory) ? $directory . '/' : '') . $file);
1202          $lang_entry_src = $lang;
1203  
1204          $lang = array();
1205  
1206          if (!file_exists($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true)))
1207          {
1208              return array();
1209          }
1210  
1211          include($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true));
1212  
1213          $lang_entry_dst = $lang;
1214  
1215          unset($lang);
1216  
1217          $diff_array_keys = array_diff(array_keys($lang_entry_src), array_keys($lang_entry_dst));
1218          unset($lang_entry_dst);
1219  
1220          foreach ($diff_array_keys as $key)
1221          {
1222              $return_ary[$key] = $lang_entry_src[$key];
1223          }
1224  
1225          unset($lang_entry_src);
1226  
1227          return $return_ary;
1228      }
1229  
1230      /**
1231      * Return language string value for storage
1232      */
1233  	function prepare_lang_entry($text, $store = true)
1234      {
1235          $text = (STRIP) ? stripslashes($text) : $text;
1236  
1237          // Adjust for storage...
1238          if ($store)
1239          {
1240              $text = str_replace("'", "\\'", str_replace('\\', '\\\\', $text));
1241          }
1242  
1243          return $text;
1244      }
1245  
1246      /**
1247      * Format language array for storage
1248      */
1249  	function format_lang_array($key, $value, $tabs = "\t")
1250      {
1251          $entry = '';
1252  
1253          if (!is_array($value))
1254          {
1255              $entry .= "{$tabs}'{$key}'\t=> '" . $this->prepare_lang_entry($value) . "',\n";
1256          }
1257          else
1258          {
1259              $_tabs = $tabs . "\t";
1260              $entry .= "\n{$tabs}'{$key}'\t=> array(\n";
1261  
1262              foreach ($value as $_key => $_value)
1263              {
1264                  $entry .= $this->format_lang_array($_key, $_value, $_tabs);
1265              }
1266  
1267              $entry .= "{$tabs}),\n\n";
1268          }
1269  
1270          return $entry;
1271      }
1272  }
1273  
1274  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6