Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

acp_language.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 44.31 KiB


0001  <?php
0002  /**
0003  *
0004  * @package acp
0005  * @version $Id$
0006  * @copyright (c) 2005 phpBB Group
0007  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
0008  *
0009  */
0010   
0011  /**
0012  * @ignore
0013  */
0014  if (!defined('IN_PHPBB'))
0015  {
0016      exit;
0017  }
0018   
0019  /**
0020  * @package acp
0021  */
0022  class acp_language
0023  {
0024      var $u_action;
0025      var $main_files;
0026      var $language_header = '';
0027      var $lang_header = '';
0028   
0029      var $language_file = '';
0030      var $language_directory = '';
0031   
0032      function main($id, $mode)
0033      {
0034          global $config, $db, $user, $auth, $template, $cache;
0035          global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
0036          global $safe_mode, $file_uploads;
0037   
0038          include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
0039   
0040          $this->default_variables();
0041   
0042          // Check and set some common vars
0043   
0044          $action        = (isset($_POST['update_details'])) ? 'update_details' : '';
0045          $action        = (isset($_POST['download_file'])) ? 'download_file' : $action;
0046          $action        = (isset($_POST['upload_file'])) ? 'upload_file' : $action;
0047          $action        = (isset($_POST['upload_data'])) ? 'upload_data' : $action;
0048          $action        = (isset($_POST['submit_file'])) ? 'submit_file' : $action;
0049          $action        = (isset($_POST['remove_store'])) ? 'details' : $action;
0050   
0051          $submit = (empty($action) && !isset($_POST['update']) && !isset($_POST['test_connection'])) ? false : true;
0052          $action = (empty($action)) ? request_var('action', '') : $action;
0053   
0054          $form_name = 'acp_lang';
0055          add_form_key('acp_lang');
0056   
0057          $lang_id = request_var('id', 0);
0058          if (isset($_POST['missing_file']))
0059          {
0060              $missing_file = request_var('missing_file', array('' => 0));
0061              list($_REQUEST['language_file'], ) = array_keys($missing_file);
0062          }
0063   
0064          $selected_lang_file = request_var('language_file', '|common.' . $phpEx);
0065   
0066          list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file);
0067   
0068          $this->language_directory = basename($this->language_directory);
0069          $this->language_file = basename($this->language_file);
0070   
0071          $user->add_lang('acp/language');
0072          $this->tpl_name = 'acp_language';
0073          $this->page_title = 'ACP_LANGUAGE_PACKS';
0074   
0075          if ($submit && $action == 'upload_data' && request_var('test_connection', ''))
0076          {
0077              $test_connection = false;
0078              $action = 'upload_file';
0079              $method = request_var('method', '');
0080   
0081              include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
0082   
0083              switch ($method)
0084              {
0085                  case 'ftp':
0086                      $transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
0087                  break;
0088   
0089                  case 'ftp_fsock':
0090                      $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
0091                  break;
0092   
0093                  default:
0094                      trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
0095                  break;
0096              }
0097   
0098              $test_connection = $transfer->open_session();
0099              $transfer->close_session();
0100          }
0101   
0102          switch ($action)
0103          {
0104              case 'upload_file':
0105   
0106                  include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
0107   
0108                  $method = request_var('method', '');
0109   
0110                  if (!class_exists($method))
0111                  {
0112                      trigger_error('Method does not exist.', E_USER_ERROR);
0113                  }
0114   
0115                  $requested_data = call_user_func(array($method, 'data'));
0116                  foreach ($requested_data as $data => $default)
0117                  {
0118                      $template->assign_block_vars('data', array(
0119                          'DATA'        => $data,
0120                          'NAME'        => $user->lang[strtoupper($method . '_' . $data)],
0121                          'EXPLAIN'    => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'],
0122                          'DEFAULT'    => (!empty($_REQUEST[$data])) ? request_var($data, '') : $default
0123                      ));
0124                  }
0125   
0126                  $hidden_data = build_hidden_fields(array(
0127                      'file'            => $this->language_file,
0128                      'dir'            => $this->language_directory,
0129                      'language_file'    => $selected_lang_file,
0130                      'method'        => $method)
0131                  );
0132   
0133                  $hidden_data .= build_hidden_fields(array('entry' => $_POST['entry']), true, STRIP);
0134   
0135                  $template->assign_vars(array(
0136                      'S_UPLOAD'    => true,
0137                      'NAME'        => $method,
0138                      'U_ACTION'    => $this->u_action . "&amp;id=$lang_id&amp;action=upload_data",
0139                      'U_BACK'    => $this->u_action . "&amp;id=$lang_id&amp;action=details&amp;language_file=" . urlencode($selected_lang_file),
0140                      'HIDDEN'    => $hidden_data,
0141   
0142                      'S_CONNECTION_SUCCESS'        => (request_var('test_connection', '') && $test_connection === true) ? true : false,
0143                      'S_CONNECTION_FAILED'        => (request_var('test_connection', '') && $test_connection !== true) ? true : false
0144                  ));
0145              break;
0146   
0147              case 'update_details':
0148   
0149                  if (!$submit || !check_form_key($form_name))
0150                  {
0151                      trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
0152                  }
0153   
0154                  if (!$lang_id)
0155                  {
0156                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
0157                  }
0158   
0159                  $sql = 'SELECT *
0160                      FROM ' . LANG_TABLE . "
0161                      WHERE lang_id = $lang_id";
0162                  $result = $db->sql_query($sql);
0163                  $row = $db->sql_fetchrow($result);
0164                  $db->sql_freeresult($result);
0165   
0166                  $sql_ary    = array(
0167                      'lang_english_name'        => request_var('lang_english_name', $row['lang_english_name']),
0168                      'lang_local_name'        => utf8_normalize_nfc(request_var('lang_local_name', $row['lang_local_name'], true)),
0169                      'lang_author'            => utf8_normalize_nfc(request_var('lang_author', $row['lang_author'], true)),
0170                  );
0171   
0172                  $db->sql_query('UPDATE ' . LANG_TABLE . '
0173                      SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
0174                      WHERE lang_id = ' . $lang_id);
0175   
0176                  add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $sql_ary['lang_english_name']);
0177   
0178                  trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action));
0179              break;
0180   
0181              case 'submit_file':
0182              case 'download_file':
0183              case 'upload_data':
0184                  
0185                  if (!$submit || !check_form_key($form_name))
0186                  {
0187                      trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
0188                  }
0189   
0190                  if (!$lang_id || empty($_POST['entry']))
0191                  {
0192                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
0193                  }
0194   
0195                  if ($this->language_directory != 'email' && !is_array($_POST['entry']))
0196                  {
0197                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
0198                  }
0199   
0200                  if (!$this->language_file || (!$this->language_directory && !in_array($this->language_file, $this->main_files)))
0201                  {
0202                      trigger_error($user->lang['NO_FILE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
0203                  }
0204   
0205                  $sql = 'SELECT *
0206                      FROM ' . LANG_TABLE . "
0207                      WHERE lang_id = $lang_id";
0208                  $result = $db->sql_query($sql);
0209                  $row = $db->sql_fetchrow($result);
0210                  $db->sql_freeresult($result);
0211   
0212                  if (!$row)
0213                  {
0214                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
0215                  }
0216   
0217                  // Before we attempt to write anything let's check if the admin really chose a correct filename
0218                  switch ($this->language_directory)
0219                  {
0220                      case 'email':
0221                          // Get email templates
0222                          $email_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
0223                          $email_files = $email_files['email/'];
0224   
0225                          if (!in_array($this->language_file, $email_files))
0226                          {
0227                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
0228                          }
0229                      break;
0230   
0231                      case 'acp':
0232                          // Get acp files
0233                          $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
0234                          $acp_files = $acp_files['acp/'];
0235   
0236                          if (!in_array($this->language_file, $acp_files))
0237                          {
0238                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
0239                          }
0240                      break;
0241   
0242                      case 'mods':
0243                          // Get mod files
0244                          $mods_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
0245                          $mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();
0246   
0247                          if (!in_array($this->language_file, $mods_files))
0248                          {
0249                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
0250                          }
0251                      break;
0252   
0253                      default:
0254                          if (!in_array($this->language_file, $this->main_files))
0255                          {
0256                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
0257                          }
0258                      break;
0259                  }
0260   
0261                  if (!$safe_mode)
0262                  {
0263                      $mkdir_ary = array('language', 'language/' . $row['lang_iso']);
0264                      
0265                      if ($this->language_directory)
0266                      {
0267                          $mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory;
0268                      }
0269                  
0270                      foreach ($mkdir_ary as $dir)
0271                      {
0272                          $dir = $phpbb_root_path . 'store/' . $dir;
0273              
0274                          if (!is_dir($dir))
0275                          {
0276                              if (!@mkdir($dir, 0777))
0277                              {
0278                                  trigger_error("Could not create directory $dir", E_USER_ERROR);
0279                              }
0280                              @chmod($dir, 0777);
0281                          }
0282                      }
0283                  }
0284   
0285                  // Get target filename for storage folder
0286                  $filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true);
0287                  $fp = @fopen($phpbb_root_path . $filename, 'wb');
0288   
0289                  if (!$fp)
0290                  {
0291                      trigger_error(sprintf($user->lang['UNABLE_TO_WRITE_FILE'], $filename) . adm_back_link($this->u_action . '&amp;id=' . $lang_id . '&amp;action=details&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
0292                  }
0293   
0294                  if ($this->language_directory == 'email')
0295                  {
0296                      // Email Template
0297                      $entry = $this->prepare_lang_entry($_POST['entry'], false);
0298                      fwrite($fp, $entry);
0299                  }
0300                  else
0301                  {
0302                      $name = (($this->language_directory) ? $this->language_directory . '_' : '') . $this->language_file;
0303                      $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);
0304   
0305                      if (strpos($this->language_file, 'help_') === 0)
0306                      {
0307                          // Help File
0308                          $header .= '$help = array(' . "\n";
0309                          fwrite($fp, $header);
0310   
0311                          foreach ($_POST['entry'] as $key => $value)
0312                          {
0313                              if (!is_array($value))
0314                              {
0315                                  continue;
0316                              }
0317   
0318                              $entry = "\tarray(\n";
0319                              
0320                              foreach ($value as $_key => $_value)
0321                              {
0322                                  $entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n";
0323                              }
0324   
0325                              $entry .= "\t),\n";
0326                              fwrite($fp, $entry);
0327                          }
0328   
0329                          $footer = ");\n\n?>";
0330                          fwrite($fp, $footer);
0331                      }
0332                      else
0333                      {
0334                          // Language File
0335                          $header .= $this->lang_header;
0336                          fwrite($fp, $header);
0337   
0338                          foreach ($_POST['entry'] as $key => $value)
0339                          {
0340                              $entry = $this->format_lang_array($key, $value);
0341                              fwrite($fp, $entry);
0342                          }
0343   
0344                          $footer = "));\n\n?>";
0345                          fwrite($fp, $footer);
0346                      }
0347                  }
0348   
0349                  fclose($fp);
0350   
0351                  if ($action == 'download_file')
0352                  {
0353                      header('Pragma: no-cache');
0354                      header('Content-Type: application/octetstream; name="' . $this->language_file . '"');
0355                      header('Content-disposition: attachment; filename=' . $this->language_file);
0356   
0357                      $fp = @fopen($phpbb_root_path . $filename, 'rb');
0358                      while ($buffer = fread($fp, 1024))
0359                      {
0360                          echo $buffer;
0361                      }
0362                      fclose($fp);
0363   
0364                      add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
0365   
0366                      exit;
0367                  }
0368                  else if ($action == 'upload_data')
0369                  {
0370                      $sql = 'SELECT lang_iso
0371                          FROM ' . LANG_TABLE . "
0372                          WHERE lang_id = $lang_id";
0373                      $result = $db->sql_query($sql);
0374                      $row = $db->sql_fetchrow($result);
0375                      $db->sql_freeresult($result);
0376   
0377                      $file = request_var('file', '');
0378                      $dir = request_var('dir', '');
0379   
0380                      $selected_lang_file = $dir . '|' . $file;
0381   
0382                      $old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true);
0383                      $lang_path = 'language/' . $row['lang_iso'] . '/' . (($dir) ? $dir . '/' : '');
0384   
0385                      include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
0386                      $method = request_var('method', '');
0387   
0388                      if ($method != 'ftp' && $method != 'ftp_fsock')
0389                      {
0390                          trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
0391                      }
0392   
0393                      $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
0394   
0395                      if (($result = $transfer->open_session()) !== true)
0396                      {
0397                          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);
0398                      }
0399   
0400                      $transfer->rename($lang_path . $file, $lang_path . $file . '.bak');
0401                      $result = $transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file);
0402   
0403                      if ($result === false)
0404                      {
0405                          // If failed, try to rename again and print error out...
0406                          $transfer->delete_file($lang_path . $file);
0407                          $transfer->rename($lang_path . $file . '.bak', $lang_path . $file);
0408   
0409                          trigger_error($user->lang['UPLOAD_FAILED'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
0410                      }
0411   
0412                      $transfer->close_session();
0413   
0414                      // Remove from storage folder
0415                      if (file_exists($phpbb_root_path . 'store/' . $lang_path . $file))
0416                      {
0417                          @unlink($phpbb_root_path . 'store/' . $lang_path . $file);
0418                      }
0419   
0420                      add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file);
0421   
0422                      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)));
0423                  }
0424   
0425                  add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
0426                  $action = 'details';
0427   
0428              // no break;
0429   
0430              case 'details':
0431   
0432                  if (!$lang_id)
0433                  {
0434                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
0435                  }
0436                  
0437                  $this->page_title = 'LANGUAGE_PACK_DETAILS';
0438   
0439                  $sql = 'SELECT *
0440                      FROM ' . LANG_TABLE . '
0441                      WHERE lang_id = ' . $lang_id;
0442                  $result = $db->sql_query($sql);
0443                  $lang_entries = $db->sql_fetchrow($result);
0444                  $db->sql_freeresult($result);
0445                  
0446                  $lang_iso = $lang_entries['lang_iso'];
0447                  $missing_vars = $missing_files = array();
0448   
0449                  // Get email templates
0450                  $email_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'email', 'txt');
0451                  $email_files = $email_files['email/'];
0452   
0453                  // Get acp files
0454                  $acp_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'acp', $phpEx);
0455                  $acp_files = $acp_files['acp/'];
0456   
0457                  // Get mod files
0458                  $mods_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'mods', $phpEx);
0459                  $mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array();
0460   
0461                  // Check if our current filename matches the files
0462                  switch ($this->language_directory)
0463                  {
0464                      case 'email':
0465                          if (!in_array($this->language_file, $email_files))
0466                          {
0467                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
0468                          }
0469                      break;
0470   
0471                      case 'acp':
0472                          if (!in_array($this->language_file, $acp_files))
0473                          {
0474                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
0475                          }
0476                      break;
0477   
0478                      case 'mods':
0479                          if (!in_array($this->language_file, $mods_files))
0480                          {
0481                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
0482                          }
0483                      break;
0484   
0485                      default:
0486                          if (!in_array($this->language_file, $this->main_files))
0487                          {
0488                              trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
0489                          }
0490                  }
0491                  
0492                  if (isset($_POST['remove_store']))
0493                  {
0494                      $store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true);
0495   
0496                      if (file_exists($phpbb_root_path . $store_filename))
0497                      {
0498                          @unlink($phpbb_root_path . $store_filename);
0499                      }
0500                  }
0501   
0502                  include_once($phpbb_root_path . 'includes/functions_transfer.' . $phpEx);
0503   
0504                  $methods = transfer::methods();
0505   
0506                  foreach ($methods as $method)
0507                  {
0508                      $template->assign_block_vars('buttons', array(
0509                          'VALUE' => $method
0510                      ));
0511                  }
0512   
0513                  $template->assign_vars(array(
0514                      'S_DETAILS'            => true,
0515                      'U_ACTION'            => $this->u_action . "&amp;action=details&amp;id=$lang_id",
0516                      'U_BACK'            => $this->u_action,
0517                      'LANG_LOCAL_NAME'    => $lang_entries['lang_local_name'],
0518                      'LANG_ENGLISH_NAME'    => $lang_entries['lang_english_name'],
0519                      'LANG_ISO'            => $lang_entries['lang_iso'],
0520                      'LANG_AUTHOR'        => $lang_entries['lang_author'],
0521                      'ALLOW_UPLOAD'        => sizeof($methods)
0522                      )
0523                  );
0524   
0525                  // If current lang is different from the default lang, then first try to grab missing/additional vars
0526                  if ($lang_iso != $config['default_lang'])
0527                  {
0528                      $is_missing_var = false;
0529   
0530                      foreach ($this->main_files as $file)
0531                      {
0532                          if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file)))
0533                          {
0534                              $missing_vars[$file] = $this->compare_language_files($config['default_lang'], $lang_iso, '', $file);
0535                              
0536                              if (sizeof($missing_vars[$file]))
0537                              {
0538                                  $is_missing_var = true;
0539                              }
0540                          }
0541                          else
0542                          {
0543                              $missing_files[] = $this->get_filename($lang_iso, '', $file);
0544                          }
0545                      }
0546   
0547                      // Now go through acp/mods directories
0548                      foreach ($acp_files as $file)
0549                      {
0550                          if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'acp', $file)))
0551                          {
0552                              $missing_vars['acp/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'acp', $file);
0553                              
0554                              if (sizeof($missing_vars['acp/' . $file]))
0555                              {
0556                                  $is_missing_var = true;
0557                              }
0558                          }
0559                          else
0560                          {
0561                              $missing_files[] = $this->get_filename($lang_iso, 'acp', $file);
0562                          }
0563                      }
0564   
0565                      if (sizeof($mods_files))
0566                      {
0567                          foreach ($mods_files as $file)
0568                          {
0569                              if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'mods', $file)))
0570                              {
0571                                  $missing_vars['mods/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'mods', $file);
0572                                  
0573                                  if (sizeof($missing_vars['mods/' . $file]))
0574                                  {
0575                                      $is_missing_var = true;
0576                                  }
0577                              }
0578                              else
0579                              {
0580                                  $missing_files[] = $this->get_filename($lang_iso, 'mods', $file);
0581                              }
0582                          }
0583                      }
0584                  
0585                      // More missing files... for example email templates?
0586                      foreach ($email_files as $file)
0587                      {
0588                          if (!file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'email', $file)))
0589                          {
0590                              $missing_files[] = $this->get_filename($lang_iso, 'email', $file);
0591                          }
0592                      }
0593   
0594                      if (sizeof($missing_files))
0595                      {
0596                          $template->assign_vars(array(
0597                              'S_MISSING_FILES'        => true,
0598                              'L_MISSING_FILES'        => sprintf($user->lang['THOSE_MISSING_LANG_FILES'], $lang_entries['lang_local_name']),
0599                              'MISSING_FILES'            => implode('<br />', $missing_files))
0600                          );
0601                      }
0602   
0603                      if ($is_missing_var)
0604                      {
0605                          $template->assign_vars(array(
0606                              'S_MISSING_VARS'            => true,
0607                              'L_MISSING_VARS_EXPLAIN'    => sprintf($user->lang['THOSE_MISSING_LANG_VARIABLES'], $lang_entries['lang_local_name']),
0608                              'U_MISSING_ACTION'            => $this->u_action . "&amp;action=$action&amp;id=$lang_id")
0609                          );
0610   
0611                          foreach ($missing_vars as $file => $vars)
0612                          {
0613                              if (!sizeof($vars))
0614                              {
0615                                  continue;
0616                              }
0617   
0618                              $template->assign_block_vars('missing', array(
0619                                  'FILE'            => $file,
0620                                  'TPL'            => $this->print_language_entries($vars, '', false),
0621                                  'KEY'            => (strpos($file, '/') === false) ? '|' . $file : str_replace('/', '|', $file))
0622                              );
0623                          }
0624                      }
0625                  }
0626   
0627                  // Main language files
0628                  $s_lang_options = '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['LANGUAGE_FILES'] . '</option>';
0629                  foreach ($this->main_files as $file)
0630                  {
0631                      if (strpos($file, 'help_') === 0)
0632                      {
0633                          continue;
0634                      }
0635   
0636                      $prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
0637   
0638                      $selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
0639                      $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
0640                  }
0641   
0642                  // Help Files
0643                  $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['HELP_FILES'] . '</option>';
0644                  foreach ($this->main_files as $file)
0645                  {
0646                      if (strpos($file, 'help_') !== 0)
0647                      {
0648                          continue;
0649                      }
0650   
0651                      $prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true))) ? '* ' : '';
0652   
0653                      $selected = (!$this->language_directory && $this->language_file == $file) ? ' selected="selected"' : '';
0654                      $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
0655                  }
0656   
0657                  // Now every other language directory
0658                  $check_files = array('email', 'acp', 'mods');
0659   
0660                  foreach ($check_files as $check)
0661                  {
0662                      if (!sizeof(${$check . '_files'}))
0663                      {
0664                          continue;
0665                      }
0666   
0667                      $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang[strtoupper($check) . '_FILES'] . '</option>';
0668   
0669                      foreach (${$check . '_files'} as $file)
0670                      {
0671                          $prefix = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $check, $file, true, true))) ? '* ' : '';
0672   
0673                          $selected = ($this->language_directory == $check && $this->language_file == $file) ? ' selected="selected"' : '';
0674                          $s_lang_options .= '<option value="' . $check . '|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
0675                      }
0676                  }
0677   
0678                  // Get Language Entries - if saved within store folder, we take this one (with the option to remove it)
0679                  $lang = array();
0680   
0681                  $is_email_file = ($this->language_directory == 'email') ? true : false;
0682                  $is_help_file = (strpos($this->language_file, 'help_') === 0) ? true : false;
0683   
0684                  $file_from_store = (file_exists($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true))) ? true : false;
0685                  $no_store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file);
0686   
0687                  if (!$file_from_store && !file_exists($phpbb_root_path . $no_store_filename))
0688                  {
0689                      $print_message = sprintf($user->lang['MISSING_LANGUAGE_FILE'], $no_store_filename);
0690                  }
0691                  else
0692                  {
0693                      if ($is_email_file)
0694                      {
0695                          $lang = file_get_contents($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
0696                      }
0697                      else
0698                      {
0699                          $help = array();
0700                          include($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
0701   
0702                          if ($is_help_file)
0703                          {
0704                              $lang = $help;
0705                              unset($help);
0706                          }
0707                      }
0708   
0709                      $print_message = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
0710                  }
0711   
0712                  // Normal language pack entries
0713                  $template->assign_vars(array(
0714                      'U_ENTRY_ACTION'        => $this->u_action . "&amp;action=details&amp;id=$lang_id#entries",
0715                      'S_EMAIL_FILE'            => $is_email_file,
0716                      'S_FROM_STORE'            => $file_from_store,
0717                      'S_LANG_OPTIONS'        => $s_lang_options,
0718                      'PRINT_MESSAGE'            => $print_message,
0719                      )
0720                  );
0721   
0722                  if (!$is_email_file)
0723                  {
0724                      $tpl = '';
0725                      $name = (($this->language_directory) ? $this->language_directory . '/' : '') . $this->language_file;
0726   
0727                      if (isset($missing_vars[$name]) && sizeof($missing_vars[$name]))
0728                      {
0729                          $tpl .= $this->print_language_entries($missing_vars[$name], '* ');
0730                      }
0731   
0732                      $tpl .= $this->print_language_entries($lang);
0733   
0734                      $template->assign_var('TPL', $tpl);
0735                      unset($tpl);
0736                  }
0737                  else
0738                  {
0739                      $template->assign_vars(array(
0740                          'LANG'        => $lang)
0741                      );
0742   
0743                      unset($lang);
0744                  }
0745   
0746                  return;
0747   
0748              break;
0749   
0750              case 'delete':
0751   
0752                  if (!$lang_id)
0753                  {
0754                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
0755                  }
0756   
0757                  $sql = 'SELECT *
0758                      FROM ' . LANG_TABLE . '
0759                      WHERE lang_id = ' . $lang_id;
0760                  $result = $db->sql_query($sql);
0761                  $row = $db->sql_fetchrow($result);
0762                  $db->sql_freeresult($result);
0763   
0764                  if ($row['lang_iso'] == $config['default_lang'])
0765                  {
0766                      trigger_error($user->lang['NO_REMOVE_DEFAULT_LANG'] . adm_back_link($this->u_action), E_USER_WARNING);
0767                  }
0768   
0769                  $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id);
0770   
0771                  $sql = 'UPDATE ' . USERS_TABLE . "
0772                      SET user_lang = '" . $db->sql_escape($config['default_lang']) . "'
0773                      WHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
0774                  $db->sql_query($sql);
0775   
0776                  // We also need to remove the translated entries for custom profile fields - we want clean tables, don't we?
0777                  $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
0778                  $db->sql_query($sql);
0779   
0780                  $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
0781                  $db->sql_query($sql);
0782   
0783                  $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
0784                  $result = $db->sql_query($sql);
0785   
0786                  $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
0787   
0788                  add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']);
0789   
0790                  trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action));
0791              break;
0792   
0793              case 'install':
0794                  $lang_iso = request_var('iso', '');
0795                  $lang_iso = basename($lang_iso);
0796   
0797                  if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/iso.txt"))
0798                  {
0799                      trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
0800                  }
0801   
0802                  $file = file("{$phpbb_root_path}language/$lang_iso/iso.txt");
0803   
0804                  $lang_pack = array(
0805                      'iso'        => $lang_iso,
0806                      'name'        => trim(htmlspecialchars($file[0])),
0807                      'local_name'=> trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')),
0808                      'author'    => trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8'))
0809                  );
0810                  unset($file);
0811   
0812                  $sql = 'SELECT lang_iso
0813                      FROM ' . LANG_TABLE . "
0814                      WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'";
0815                  $result = $db->sql_query($sql);
0816                  $row = $db->sql_fetchrow($result);
0817                  $db->sql_freeresult($result);
0818   
0819                  if ($row)
0820                  {
0821                      trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action), E_USER_WARNING);
0822                  }
0823   
0824                  if (!$lang_pack['name'] || !$lang_pack['local_name'])
0825                  {
0826                      trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action), E_USER_WARNING);
0827                  }
0828   
0829                  // Add language pack
0830                  $sql_ary = array(
0831                      'lang_iso'            => $lang_pack['iso'],
0832                      'lang_dir'            => $lang_pack['iso'],
0833                      'lang_english_name'    => $lang_pack['name'],
0834                      'lang_local_name'    => $lang_pack['local_name'],
0835                      'lang_author'        => $lang_pack['author']
0836                  );
0837   
0838                  $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
0839                  $lang_id = $db->sql_nextid();
0840   
0841                  $valid_localized = array(
0842                      'icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply',
0843                  );
0844   
0845                  $sql_ary = array();
0846   
0847                  $sql = 'SELECT *
0848                      FROM ' . STYLES_IMAGESET_TABLE;
0849                  $result = $db->sql_query($sql);
0850                  while ($imageset_row = $db->sql_fetchrow($result))
0851                  {
0852                      if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg"))
0853                      {
0854                          $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg");
0855                          foreach ($cfg_data_imageset_data as $image_name => $value)
0856                          {
0857                              if (strpos($value, '*') !== false)
0858                              {
0859                                  if (substr($value, -1, 1) === '*')
0860                                  {
0861                                      list($image_filename, $image_height) = explode('*', $value);
0862                                      $image_width = 0;
0863                                  }
0864                                  else
0865                                  {
0866                                      list($image_filename, $image_height, $image_width) = explode('*', $value);
0867                                  }
0868                              }
0869                              else
0870                              {
0871                                  $image_filename = $value;
0872                                  $image_height = $image_width = 0;
0873                              }
0874   
0875                              if (strpos($image_name, 'img_') === 0 && $image_filename)
0876                              {
0877                                  $image_name = substr($image_name, 4);
0878                                  if (in_array($image_name, $valid_localized))
0879                                  {
0880                                      $sql_ary[] = array(
0881                                          'image_name'        => (string) $image_name,
0882                                          'image_filename'    => (string) $image_filename,
0883                                          'image_height'        => (int) $image_height,
0884                                          'image_width'        => (int) $image_width,
0885                                          'imageset_id'        => (int) $imageset_row['imageset_id'],
0886                                          'image_lang'        => (string) $lang_pack['iso'],
0887                                      );
0888                                  }
0889                              }
0890                          }
0891                      }
0892                  }
0893                  $db->sql_freeresult($result);
0894   
0895                  if (sizeof($sql_ary))
0896                  {
0897                      $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
0898                      $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
0899                  }
0900   
0901                  // Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier.
0902                  $sql = 'SELECT lang_id
0903                      FROM ' . LANG_TABLE . "
0904                      WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
0905                  $result = $db->sql_query($sql);
0906                  $default_lang_id = (int) $db->sql_fetchfield('lang_id');
0907                  $db->sql_freeresult($result);
0908   
0909                  // From the mysql documentation:
0910                  // 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.
0911                  // Due to this we stay on the safe side if we do the insertion "the manual way"
0912   
0913                  $sql = 'SELECT field_id, lang_name, lang_explain, lang_default_value
0914                      FROM ' . PROFILE_LANG_TABLE . '
0915                      WHERE lang_id = ' . $default_lang_id;
0916                  $result = $db->sql_query($sql);
0917   
0918                  while ($row = $db->sql_fetchrow($result))
0919                  {
0920                      $row['lang_id'] = $lang_id;
0921                      $db->sql_query('INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
0922                  }
0923                  $db->sql_freeresult($result);
0924   
0925                  $sql = 'SELECT field_id, option_id, field_type, lang_value
0926                      FROM ' . PROFILE_FIELDS_LANG_TABLE . '
0927                      WHERE lang_id = ' . $default_lang_id;
0928                  $result = $db->sql_query($sql);
0929   
0930                  while ($row = $db->sql_fetchrow($result))
0931                  {
0932                      $row['lang_id'] = $lang_id;
0933                      $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
0934                  }
0935                  $db->sql_freeresult($result);
0936   
0937                  add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']);
0938   
0939                  trigger_error(sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']) . adm_back_link($this->u_action));
0940   
0941              break;
0942   
0943              case 'download':
0944   
0945                  if (!$lang_id)
0946                  {
0947                      trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
0948                  }
0949   
0950                  $sql = 'SELECT *
0951                      FROM ' . LANG_TABLE . '
0952                      WHERE lang_id = ' . $lang_id;
0953                  $result = $db->sql_query($sql);
0954                  $row = $db->sql_fetchrow($result);
0955                  $db->sql_freeresult($result);
0956   
0957                  $use_method = request_var('use_method', '');
0958                  $methods = array('.tar');
0959   
0960                  $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
0961                  foreach ($available_methods as $type => $module)
0962                  {
0963                      if (!@extension_loaded($module))
0964                      {
0965                          continue;
0966                      }
0967   
0968                      $methods[] = $type;
0969                  }
0970   
0971                  // Let the user decide in which format he wants to have the pack
0972                  if (!$use_method)
0973                  {
0974                      $this->page_title = 'SELECT_DOWNLOAD_FORMAT';
0975   
0976                      $radio_buttons = '';
0977                      foreach ($methods as $method)
0978                      {
0979                          $radio_buttons .= '<label><input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>';
0980                      }
0981   
0982                      $template->assign_vars(array(
0983                          'S_SELECT_METHOD'        => true,
0984                          'U_BACK'                => $this->u_action,
0985                          'U_ACTION'                => $this->u_action . "&amp;action=$action&amp;id=$lang_id",
0986                          'RADIO_BUTTONS'            => $radio_buttons)
0987                      );
0988   
0989                      return;
0990                  }
0991   
0992                  if (!in_array($use_method, $methods))
0993                  {
0994                      $use_method = '.tar';
0995                  }
0996   
0997                  include_once($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
0998   
0999                  if ($use_method == '.zip')
1000                  {
1001                      $compress = new compress_zip('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
1002                  }
1003                  else
1004                  {
1005                      $compress = new compress_tar('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method, $use_method);
1006                  }
1007   
1008                  // Get email templates
1009                  $email_templates = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
1010                  $email_templates = $email_templates['email/'];
1011   
1012                  // Get acp files
1013                  $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
1014                  $acp_files = $acp_files['acp/'];
1015   
1016                  // Get mod files
1017                  $mod_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
1018                  $mod_files = (isset($mod_files['mods/'])) ? $mod_files['mods/'] : array();
1019   
1020                  // Add main files
1021                  $this->add_to_archive($compress, $this->main_files, $row['lang_iso']);
1022   
1023                  // Add search files if they exist...
1024                  if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_ignore_words.' . $phpEx))
1025                  {
1026                      $this->add_to_archive($compress, array("search_ignore_words.$phpEx"), $row['lang_iso']);
1027                  }
1028   
1029                  if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_synonyms.' . $phpEx))
1030                  {
1031                      $this->add_to_archive($compress, array("search_synonyms.$phpEx"), $row['lang_iso']);
1032                  }
1033   
1034                  // Write files in folders
1035                  $this->add_to_archive($compress, $email_templates, $row['lang_iso'], 'email');
1036                  $this->add_to_archive($compress, $acp_files, $row['lang_iso'], 'acp');
1037                  $this->add_to_archive($compress, $mod_files, $row['lang_iso'], 'mods');
1038   
1039                  // Write ISO File
1040                  $iso_src = htmlspecialchars_decode($row['lang_english_name']) . "\n";
1041                  $iso_src .= htmlspecialchars_decode($row['lang_local_name']) . "\n";
1042                  $iso_src .= htmlspecialchars_decode($row['lang_author']);
1043                  $compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt');
1044   
1045                  // index.html files
1046                  $compress->add_data('', 'language/' . $row['lang_iso'] . '/index.html');
1047                  $compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.html');
1048                  $compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.html');
1049                  
1050                  if (sizeof($mod_files))
1051                  {
1052                      $compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.html');
1053                  }
1054   
1055                  $compress->close();
1056   
1057                  $compress->download('lang_' . $row['lang_iso']);
1058                  @unlink($phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
1059   
1060                  exit;
1061   
1062              break;
1063          }
1064   
1065          $sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count
1066              FROM ' . USERS_TABLE . '
1067              GROUP BY user_lang';
1068          $result = $db->sql_query($sql);
1069   
1070          $lang_count = array();
1071          while ($row = $db->sql_fetchrow($result))
1072          {
1073              $lang_count[$row['user_lang']] = $row['lang_count'];
1074          }
1075          $db->sql_freeresult($result);
1076   
1077          $sql = 'SELECT *
1078              FROM ' . LANG_TABLE . '
1079              ORDER BY lang_english_name';
1080          $result = $db->sql_query($sql);
1081   
1082          $installed = array();
1083   
1084          while ($row = $db->sql_fetchrow($result))
1085          {
1086              $installed[] = $row['lang_iso'];
1087              $tagstyle = ($row['lang_iso'] == $config['default_lang']) ? '*' : '';
1088   
1089              $template->assign_block_vars('lang', array(
1090                  'U_DETAILS'            => $this->u_action . "&amp;action=details&amp;id={$row['lang_id']}",
1091                  'U_DOWNLOAD'        => $this->u_action . "&amp;action=download&amp;id={$row['lang_id']}",
1092                  'U_DELETE'            => $this->u_action . "&amp;action=delete&amp;id={$row['lang_id']}",
1093   
1094                  'ENGLISH_NAME'        => $row['lang_english_name'],
1095                  'TAG'                => $tagstyle,
1096                  'LOCAL_NAME'        => $row['lang_local_name'],
1097                  'ISO'                => $row['lang_iso'],
1098                  'USED_BY'            => (isset($lang_count[$row['lang_iso']])) ? $lang_count[$row['lang_iso']] : 0,
1099              ));
1100          }
1101          $db->sql_freeresult($result);
1102   
1103          $new_ary = $iso = array();
1104          $dp = @opendir("{$phpbb_root_path}language");
1105   
1106          if ($dp)
1107          {
1108              while (($file = readdir($dp)) !== false)
1109              {
1110                  if ($file[0] != '.' && file_exists("{$phpbb_root_path}language/$file/iso.txt"))
1111                  {
1112                      if (!in_array($file, $installed))
1113                      {
1114                          if ($iso = file("{$phpbb_root_path}language/$file/iso.txt"))
1115                          {
1116                              if (sizeof($iso) == 3)
1117                              {
1118                                  $new_ary[$file] = array(
1119                                      'iso'        => $file,
1120                                      'name'        => trim($iso[0]),
1121                                      'local_name'=> trim($iso[1]),
1122                                      'author'    => trim($iso[2])
1123                                  );
1124                              }
1125                          }
1126                      }
1127                  }
1128              }
1129              closedir($dp);
1130          }
1131   
1132          unset($installed);
1133   
1134          if (sizeof($new_ary))
1135          {
1136              foreach ($new_ary as $iso => $lang_ary)
1137              {
1138                  $template->assign_block_vars('notinst', array(
1139                      'ISO'            => htmlspecialchars($lang_ary['iso']),
1140                      'LOCAL_NAME'    => htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'),
1141                      'NAME'            => htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'),
1142                      'U_INSTALL'        => $this->u_action . '&amp;action=install&amp;iso=' . urlencode($lang_ary['iso']))
1143                  );
1144              }
1145          }
1146   
1147          unset($new_ary);
1148      }
1149   
1150   
1151      /**
1152      * Set default language variables/header
1153      */
1154      function default_variables()
1155      {
1156          global $phpEx;
1157   
1158          $this->language_file_header = '<?php
1159  /**
1160  *
1161  * {FILENAME} [{LANG_NAME}]
1162  *
1163  * @package language
1164  * @version $' . 'Id: ' . '$
1165  * @copyright (c) ' . date('Y') . ' phpBB Group
1166  * @author {CHANGED} - {AUTHOR}
1167  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
1168  *
1169  */
1170   
1171  /**
1172  * DO NOT CHANGE
1173  */
1174  if (!defined(\'IN_PHPBB\'))
1175  {
1176      exit;
1177  }
1178   
1179  if (empty($lang) || !is_array($lang))
1180  {
1181      $lang = array();
1182  }
1183   
1184  // DEVELOPERS PLEASE NOTE
1185  //
1186  // All language files should use UTF-8 as their encoding and the files must not contain a BOM.
1187  //
1188  // Placeholders can now contain order information, e.g. instead of
1189  // \'Page %s of %s\' you can (and should) write \'Page %1$s of %2$s\', this allows
1190  // translators to re-order the output of data while ensuring it remains correct
1191  //
1192  // You do not need this where single placeholders are used, e.g. \'Message %d\' is fine
1193  // equally where a string contains only two placeholders which are used to wrap text
1194  // in a url you again do not need to specify an order e.g., \'Click %sHERE%s\' is fine
1195  ';
1196   
1197          $this->lang_header = '
1198  $lang = array_merge($lang, array(
1199  ';
1200   
1201          // Language files in language root directory
1202          $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");
1203      }
1204   
1205      /**
1206      * Get filename/location of language file
1207      */
1208      function get_filename($lang_iso, $directory, $filename, $check_store = false, $only_return_filename = false)
1209      {
1210          global $phpbb_root_path, $safe_mode;
1211          
1212          $check_filename = "language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
1213   
1214          if ($check_store)
1215          {
1216              $check_store_filename = ($safe_mode) ? "store/langfile_{$lang_iso}" . (($directory) ? '_' . $directory : '') . "_{$filename}" : "store/language/$lang_iso/" . (($directory) ? $directory . '/' : '') . $filename;
1217   
1218              if (!$only_return_filename && file_exists($phpbb_root_path . $check_store_filename))
1219              {
1220                  return $check_store_filename;
1221              }
1222              else if ($only_return_filename)
1223              {
1224                  return $check_store_filename;
1225              }
1226          }
1227   
1228          return $check_filename;
1229      }
1230   
1231      /**
1232      * Add files to archive
1233      */
1234      function add_to_archive(&$compress, $filelist, $lang_iso, $directory = '')
1235      {
1236          global $phpbb_root_path;
1237   
1238          foreach ($filelist as $file)
1239          {
1240              // Get source filename
1241              $source = $this->get_filename($lang_iso, $directory, $file, true);
1242              $destination = 'language/' . $lang_iso . '/' . (($directory) ? $directory . '/' : '') . $file;
1243   
1244              // Add file to archive
1245              $compress->add_custom_file($phpbb_root_path . $source, $destination);
1246          }
1247      }
1248   
1249      /**
1250      * Little helper to add some hardcoded template bits
1251      */
1252      function add_input_field()
1253      {
1254          $keys = func_get_args();
1255   
1256          $non_static        = array_shift($keys);
1257          $value            = array_shift($keys);
1258   
1259          if (!$non_static)
1260          {
1261              return '<strong>' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '</strong>';
1262          }
1263   
1264          // If more then 270 characters, then we present a textarea, else an input field
1265          $textarea = (utf8_strlen($value) > 270) ? true : false;
1266          $tpl = '';
1267   
1268          $tpl .= ($textarea) ? '<textarea name="' : '<input type="text" name="';
1269          $tpl .= 'entry[' . implode('][', array_map('utf8_htmlspecialchars', $keys)) . ']"';
1270   
1271          $tpl .= ($textarea) ? ' cols="80" rows="5" class="langvalue">' : ' class="langvalue" value="';
1272          $tpl .= htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
1273          $tpl .= ($textarea) ? '</textarea>' : '" />';
1274   
1275          return $tpl;
1276      }
1277   
1278      /**
1279      * Print language entries
1280      */
1281      function print_language_entries(&$lang_ary, $key_prefix = '', $input_field = true)
1282      {
1283          $tpl = '';
1284   
1285          foreach ($lang_ary as $key => $value)
1286          {
1287              if (is_array($value))
1288              {
1289                  // Write key
1290                  $tpl .= '
1291                  <tr>
1292                      <td class="row3" colspan="2">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1293                  </tr>';
1294   
1295                  foreach ($value as $_key => $_value)
1296                  {
1297                      if (is_array($_value))
1298                      {
1299                          // Write key
1300                          $tpl .= '
1301                              <tr>
1302                                  <td class="row3" colspan="2">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '&nbsp; &nbsp;<strong>' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1303                              </tr>';
1304   
1305                          foreach ($_value as $__key => $__value)
1306                          {
1307                              // Write key
1308                              $tpl .= '
1309                                  <tr>
1310                                      <td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($__key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1311                                      <td class="row2">';
1312   
1313                              $tpl .= $this->add_input_field($input_field, $__value, $key, $_key, $__key);
1314   
1315                              $tpl .= '</td>
1316                                  </tr>';
1317                          }
1318                      }
1319                      else
1320                      {
1321                          // Write key
1322                          $tpl .= '
1323                              <tr>
1324                                  <td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($_key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1325                                  <td class="row2">';
1326   
1327                          $tpl .= $this->add_input_field($input_field, $_value, $key, $_key);
1328   
1329                          $tpl .= '</td>
1330                              </tr>';
1331                      }
1332                  }
1333   
1334                  $tpl .= '
1335                  <tr>
1336                      <td class="spacer" colspan="2">&nbsp;</td>
1337                  </tr>';
1338              }
1339              else
1340              {
1341                  // Write key
1342                  $tpl .= '
1343                  <tr>
1344                      <td class="row1" style="white-space: nowrap;">' . htmlspecialchars($key_prefix, ENT_COMPAT, 'UTF-8') . '<strong>' . htmlspecialchars($key, ENT_COMPAT, 'UTF-8') . '</strong></td>
1345                      <td class="row2">';
1346   
1347                  $tpl .= $this->add_input_field($input_field, $value, $key);
1348   
1349                  $tpl .= '</td>
1350                      </tr>';
1351              }
1352          }
1353   
1354          return $tpl;
1355      }
1356   
1357      /**
1358      * Compare two language files
1359      */
1360      function compare_language_files($source_lang, $dest_lang, $directory, $file)
1361      {
1362          global $phpbb_root_path, $phpEx;
1363   
1364          $return_ary = array();
1365   
1366          $lang = array();
1367          include("{$phpbb_root_path}language/{$source_lang}/" . (($directory) ? $directory . '/' : '') . $file);
1368          $lang_entry_src = $lang;
1369   
1370          $lang = array();
1371   
1372          if (!file_exists($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true)))
1373          {
1374              return array();
1375          }
1376   
1377          include($phpbb_root_path . $this->get_filename($dest_lang, $directory, $file, true));
1378   
1379          $lang_entry_dst = $lang;
1380   
1381          unset($lang);
1382   
1383          $diff_array_keys = array_diff(array_keys($lang_entry_src), array_keys($lang_entry_dst));
1384          unset($lang_entry_dst);
1385   
1386          foreach ($diff_array_keys as $key)
1387          {
1388              $return_ary[$key] = $lang_entry_src[$key];
1389          }
1390   
1391          unset($lang_entry_src);
1392   
1393          return $return_ary;
1394      }
1395   
1396      /**
1397      * Return language string value for storage
1398      */
1399      function prepare_lang_entry($text, $store = true)
1400      {
1401          $text = (STRIP) ? stripslashes($text) : $text;
1402   
1403          // Adjust for storage...
1404          if ($store)
1405          {
1406              $text = str_replace("'", "\\'", str_replace('\\', '\\\\', $text));
1407          }
1408   
1409          return $text;
1410      }
1411   
1412      /**
1413      * Format language array for storage
1414      */
1415      function format_lang_array($key, $value, $tabs = "\t")
1416      {
1417          $entry = '';
1418   
1419          if (!is_array($value))
1420          {
1421              $entry .= "{$tabs}'" . $this->prepare_lang_entry($key) . "'\t=> '" . $this->prepare_lang_entry($value) . "',\n";
1422          }
1423          else
1424          {
1425              $_tabs = $tabs . "\t";
1426              $entry .= "\n{$tabs}'" . $this->prepare_lang_entry($key) . "'\t=> array(\n";
1427   
1428              foreach ($value as $_key => $_value)
1429              {
1430                  $entry .= $this->format_lang_array($_key, $_value, $_tabs);
1431              }
1432   
1433              $entry .= "{$tabs}),\n\n";
1434          }
1435   
1436          return $entry;
1437      }
1438  }
1439   
1440  ?>