source: trunk/forum/includes/acp/acp_language.php

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