2005-11-30 17:48:06 +00:00
< ? php
/**
*
* @ package acp
* @ version $Id $
* @ copyright ( c ) 2005 phpBB Group
* @ license http :// opensource . org / licenses / gpl - license . php GNU Public License
*
*/
/**
* @ package acp
*/
class acp_language
{
2006-02-18 13:54:12 +00:00
var $u_action ;
2005-11-30 17:48:06 +00:00
var $main_files ;
var $language_header = '' ;
var $lang_header = '' ;
var $language_file = '' ;
var $language_directory = '' ;
function main ( $id , $mode )
{
global $config , $db , $user , $auth , $template , $cache ;
2006-06-06 20:53:46 +00:00
global $phpbb_root_path , $phpbb_admin_path , $phpEx , $table_prefix ;
2005-11-30 17:48:06 +00:00
global $safe_mode , $file_uploads ;
include_once ( $phpbb_root_path . 'includes/functions_user.' . $phpEx );
$this -> default_variables ();
// Check and set some common vars
2007-10-03 15:05:54 +00:00
$action = ( isset ( $_POST [ 'update_details' ])) ? 'update_details' : '' ;
$action = ( isset ( $_POST [ 'download_file' ])) ? 'download_file' : '' ;
$action = ( isset ( $_POST [ 'upload_file' ])) ? 'upload_file' : '' ;
$action = ( isset ( $_POST [ 'upload_data' ])) ? 'upload_data' : '' ;
$action = ( isset ( $_POST [ 'submit_file' ])) ? 'submit_file' : '' ;
$action = ( isset ( $_POST [ 'remove_store' ])) ? 'details' : '' ;
$submit = ( empty ( $action )) ? false : true ;
$action = ( empty ( $action )) ? request_var ( 'action' , '' ) : $action ;
$form_name = 'acp_lang' ;
add_form_key ( 'acp_lang' );
2005-11-30 17:48:06 +00:00
$lang_id = request_var ( 'id' , 0 );
if ( isset ( $_POST [ 'missing_file' ]))
{
$missing_file = request_var ( 'missing_file' , array ( '' => 0 ));
list ( $_REQUEST [ 'language_file' ], ) = array_keys ( $missing_file );
}
2006-10-19 13:55:48 +00:00
$selected_lang_file = request_var ( 'language_file' , '|common.' . $phpEx );
list ( $this -> language_directory , $this -> language_file ) = explode ( '|' , $selected_lang_file );
2005-11-30 17:48:06 +00:00
$this -> language_directory = basename ( $this -> language_directory );
$this -> language_file = basename ( $this -> language_file );
$user -> add_lang ( 'acp/language' );
$this -> tpl_name = 'acp_language' ;
$this -> page_title = 'ACP_LANGUAGE_PACKS' ;
2007-10-03 15:05:54 +00:00
if ( $submit && $action == 'upload_data' && request_var ( 'test_connection' , '' ))
2006-02-19 14:17:12 +00:00
{
$test_connection = false ;
$action = 'upload_file' ;
$method = request_var ( 'method' , '' );
include_once ( $phpbb_root_path . 'includes/functions_transfer.' . $phpEx );
switch ( $method )
{
case 'ftp' :
$transfer = new ftp ( request_var ( 'host' , '' ), request_var ( 'username' , '' ), request_var ( 'password' , '' ), request_var ( 'root_path' , '' ), request_var ( 'port' , '' ), request_var ( 'timeout' , '' ));
break ;
2006-06-16 16:54:51 +00:00
2006-07-02 21:42:54 +00:00
case 'ftp_fsock' :
$transfer = new ftp_fsock ( request_var ( 'host' , '' ), request_var ( 'username' , '' ), request_var ( 'password' , '' ), request_var ( 'root_path' , '' ), request_var ( 'port' , '' ), request_var ( 'timeout' , '' ));
break ;
2006-02-19 14:17:12 +00:00
default :
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'INVALID_UPLOAD_METHOD' ], E_USER_ERROR );
break ;
2006-02-19 14:17:12 +00:00
}
$test_connection = $transfer -> open_session ();
$transfer -> close_session ();
}
2005-11-30 17:48:06 +00:00
switch ( $action )
{
2006-02-19 14:17:12 +00:00
case 'upload_file' :
2007-10-03 15:05:54 +00:00
2006-02-19 14:17:12 +00:00
include_once ( $phpbb_root_path . 'includes/functions_transfer.' . $phpEx );
$method = request_var ( 'method' , '' );
2007-07-12 07:08:21 +00:00
if ( ! class_exists ( $method ))
{
trigger_error ( 'Method does not exist.' , E_USER_ERROR );
}
2006-02-19 14:17:12 +00:00
$requested_data = call_user_func ( array ( $method , 'data' ));
foreach ( $requested_data as $data => $default )
{
$template -> assign_block_vars ( 'data' , array (
'DATA' => $data ,
'NAME' => $user -> lang [ strtoupper ( $method . '_' . $data )],
'EXPLAIN' => $user -> lang [ strtoupper ( $method . '_' . $data ) . '_EXPLAIN' ],
2006-04-06 17:15:45 +00:00
'DEFAULT' => ( ! empty ( $_REQUEST [ $data ])) ? request_var ( $data , '' ) : $default
2006-02-19 14:17:12 +00:00
));
}
2006-07-02 21:42:54 +00:00
$hidden_data = build_hidden_fields ( array (
2007-03-30 10:49:06 +00:00
'file' => $this -> language_file ,
'dir' => $this -> language_directory ,
'language_file' => $selected_lang_file ,
'method' => $method )
2006-07-02 21:42:54 +00:00
);
2006-02-19 14:17:12 +00:00
2006-11-15 15:35:50 +00:00
$hidden_data .= build_hidden_fields ( array ( 'entry' => $_POST [ 'entry' ]), true , STRIP );
2006-02-19 14:17:12 +00:00
$template -> assign_vars ( array (
'S_UPLOAD' => true ,
'NAME' => $method ,
'U_ACTION' => $this -> u_action . " &id= $lang_id &action=upload_data " ,
2006-12-06 22:13:11 +00:00
'U_BACK' => $this -> u_action . " &id= $lang_id &action=details&language_file= " . urlencode ( $selected_lang_file ),
2006-02-19 14:17:12 +00:00
'HIDDEN' => $hidden_data ,
'S_CONNECTION_SUCCESS' => ( request_var ( 'test_connection' , '' ) && $test_connection === true ) ? true : false ,
2006-06-11 18:13:52 +00:00
'S_CONNECTION_FAILED' => ( request_var ( 'test_connection' , '' ) && $test_connection !== true ) ? true : false
2006-02-19 14:17:12 +00:00
));
2006-03-21 19:23:34 +00:00
break ;
2006-02-19 14:17:12 +00:00
2005-11-30 17:48:06 +00:00
case 'update_details' :
2007-10-03 15:33:31 +00:00
if ( ! $submit || ! check_form_key ( $form_name ))
2007-10-03 15:05:54 +00:00
{
trigger_error ( $user -> lang [ 'FORM_INVALID' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
}
2005-11-30 17:48:06 +00:00
if ( ! $lang_id )
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'NO_LANG_ID' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
2006-07-10 15:55:10 +00:00
$sql = ' SELECT *
FROM ' . LANG_TABLE . "
2005-11-30 17:48:06 +00:00
WHERE lang_id = $lang_id " ;
$result = $db -> sql_query ( $sql );
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
$sql_ary = array (
'lang_english_name' => request_var ( 'lang_english_name' , $row [ 'lang_english_name' ]),
2007-07-22 20:11:45 +00:00
'lang_local_name' => utf8_normalize_nfc ( request_var ( 'lang_local_name' , $row [ 'lang_local_name' ], true )),
'lang_author' => utf8_normalize_nfc ( request_var ( 'lang_author' , $row [ 'lang_author' ], true )),
2005-11-30 17:48:06 +00:00
);
$db -> sql_query ( 'UPDATE ' . LANG_TABLE . '
SET ' . $db->sql_build_array(' UPDATE ', $sql_ary) . '
WHERE lang_id = ' . $lang_id );
2007-02-18 13:42:08 +00:00
2005-11-30 17:48:06 +00:00
add_log ( 'admin' , 'LOG_LANGUAGE_PACK_UPDATED' , $sql_ary [ 'lang_english_name' ]);
2006-02-18 13:54:12 +00:00
trigger_error ( $user -> lang [ 'LANGUAGE_DETAILS_UPDATED' ] . adm_back_link ( $this -> u_action ));
2005-11-30 17:48:06 +00:00
break ;
case 'submit_file' :
case 'download_file' :
2006-04-22 14:40:04 +00:00
case 'upload_data' :
2007-10-03 15:05:54 +00:00
2007-10-03 15:33:31 +00:00
if ( ! $submit || ! check_form_key ( $form_name ))
2007-10-03 15:05:54 +00:00
{
trigger_error ( $user -> lang [ 'FORM_INVALID' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
}
2005-11-30 17:48:06 +00:00
2007-09-02 17:24:56 +00:00
if ( ! $lang_id || empty ( $_POST [ 'entry' ]))
{
trigger_error ( $user -> lang [ 'NO_LANG_ID' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
}
if ( $this -> language_directory != 'email' && ! is_array ( $_POST [ 'entry' ]))
2005-11-30 17:48:06 +00:00
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'NO_LANG_ID' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
if ( ! $this -> language_file || ( ! $this -> language_directory && ! in_array ( $this -> language_file , $this -> main_files )))
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'NO_FILE_SELECTED' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
2006-07-10 15:55:10 +00:00
$sql = ' SELECT *
FROM ' . LANG_TABLE . "
2005-11-30 17:48:06 +00:00
WHERE lang_id = $lang_id " ;
$result = $db -> sql_query ( $sql );
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
2007-10-01 17:46:08 +00:00
if ( ! $row )
{
trigger_error ( $user -> lang [ 'NO_LANG_ID' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
}
// Before we attempt to write anything let's check if the admin really chose a correct filename
switch ( $this -> language_directory )
{
case 'email' :
// Get email templates
$email_files = filelist ( $phpbb_root_path . 'language/' . $row [ 'lang_iso' ], 'email' , 'txt' );
$email_files = $email_files [ 'email/' ];
if ( ! in_array ( $this -> language_file , $email_files ))
{
trigger_error ( $user -> lang [ 'WRONG_LANGUAGE_FILE' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id ), E_USER_WARNING );
}
break ;
case 'acp' :
// Get acp files
$acp_files = filelist ( $phpbb_root_path . 'language/' . $row [ 'lang_iso' ], 'acp' , $phpEx );
$acp_files = $acp_files [ 'acp/' ];
if ( ! in_array ( $this -> language_file , $acp_files ))
{
trigger_error ( $user -> lang [ 'WRONG_LANGUAGE_FILE' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id ), E_USER_WARNING );
}
break ;
case 'mods' :
// Get mod files
$mods_files = filelist ( $phpbb_root_path . 'language/' . $row [ 'lang_iso' ], 'mods' , $phpEx );
$mods_files = ( isset ( $mods_files [ 'mods/' ])) ? $mods_files [ 'mods/' ] : array ();
if ( ! in_array ( $this -> language_file , $mods_files ))
{
trigger_error ( $user -> lang [ 'WRONG_LANGUAGE_FILE' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id ), E_USER_WARNING );
}
break ;
default :
if ( ! in_array ( $this -> language_file , $this -> main_files ))
{
trigger_error ( $user -> lang [ 'WRONG_LANGUAGE_FILE' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id ), E_USER_WARNING );
}
break ;
}
2005-11-30 17:48:06 +00:00
if ( ! $safe_mode )
{
$mkdir_ary = array ( 'language' , 'language/' . $row [ 'lang_iso' ]);
if ( $this -> language_directory )
{
$mkdir_ary [] = 'language/' . $row [ 'lang_iso' ] . '/' . $this -> language_directory ;
}
foreach ( $mkdir_ary as $dir )
{
$dir = $phpbb_root_path . 'store/' . $dir ;
if ( ! is_dir ( $dir ))
{
if ( !@ mkdir ( $dir , 0777 ))
{
2006-08-28 15:50:33 +00:00
trigger_error ( " Could not create directory $dir " , E_USER_ERROR );
2005-11-30 17:48:06 +00:00
}
@ chmod ( $dir , 0777 );
}
}
}
// Get target filename for storage folder
$filename = $this -> get_filename ( $row [ 'lang_iso' ], $this -> language_directory , $this -> language_file , true , true );
2007-07-12 07:08:21 +00:00
$fp = @ fopen ( $phpbb_root_path . $filename , 'wb' );
2005-11-30 17:48:06 +00:00
if ( ! $fp )
{
2006-12-06 22:13:11 +00:00
trigger_error ( sprintf ( $user -> lang [ 'UNABLE_TO_WRITE_FILE' ], $filename ) . adm_back_link ( $this -> u_action . '&id=' . $lang_id . '&action=details&language_file=' . urlencode ( $selected_lang_file )), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
if ( $this -> language_directory == 'email' )
{
// Email Template
2006-07-02 21:42:54 +00:00
$entry = $this -> prepare_lang_entry ( $_POST [ 'entry' ], false );
2006-04-06 17:15:45 +00:00
fwrite ( $fp , $entry );
2005-11-30 17:48:06 +00:00
}
else
{
$name = (( $this -> language_directory ) ? $this -> language_directory . '_' : '' ) . $this -> language_file ;
$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 );
if ( strpos ( $this -> language_file , 'help_' ) === 0 )
{
// Help File
$header .= '$help = array(' . " \n " ;
fwrite ( $fp , $header );
foreach ( $_POST [ 'entry' ] as $key => $value )
{
if ( ! is_array ( $value ))
{
2006-07-02 21:42:54 +00:00
continue ;
2005-11-30 17:48:06 +00:00
}
2006-06-22 15:14:03 +00:00
2006-07-02 21:42:54 +00:00
$entry = " \t array( \n " ;
foreach ( $value as $_key => $_value )
{
$entry .= " \t \t " . ( int ) $_key . " \t => ' " . $this -> prepare_lang_entry ( $_value ) . " ', \n " ;
2005-11-30 17:48:06 +00:00
}
2006-06-22 15:14:03 +00:00
2006-07-02 21:42:54 +00:00
$entry .= " \t ), \n " ;
2005-11-30 17:48:06 +00:00
fwrite ( $fp , $entry );
2006-06-22 15:14:03 +00:00
}
2007-01-10 16:47:16 +00:00
$footer = " ); \n \n ?> " ;
fwrite ( $fp , $footer );
2005-11-30 17:48:06 +00:00
}
else
{
// Language File
$header .= $this -> lang_header ;
fwrite ( $fp , $header );
foreach ( $_POST [ 'entry' ] as $key => $value )
{
2006-07-02 21:42:54 +00:00
$entry = $this -> format_lang_array ( $key , $value );
2005-11-30 17:48:06 +00:00
fwrite ( $fp , $entry );
2006-07-02 21:42:54 +00:00
}
2005-11-30 17:48:06 +00:00
2007-01-10 16:47:16 +00:00
$footer = " )); \n \n ?> " ;
fwrite ( $fp , $footer );
}
2005-11-30 17:48:06 +00:00
}
fclose ( $fp );
if ( $action == 'download_file' )
{
header ( 'Pragma: no-cache' );
header ( 'Content-Type: application/octetstream; name="' . $this -> language_file . '"' );
header ( 'Content-disposition: attachment; filename=' . $this -> language_file );
2007-07-12 07:08:21 +00:00
$fp = @ fopen ( $phpbb_root_path . $filename , 'rb' );
2005-11-30 17:48:06 +00:00
while ( $buffer = fread ( $fp , 1024 ))
{
echo $buffer ;
}
fclose ( $fp );
2007-02-18 13:42:08 +00:00
add_log ( 'admin' , 'LOG_LANGUAGE_FILE_SUBMITTED' , $this -> language_file );
2005-11-30 17:48:06 +00:00
exit ;
}
2006-04-22 14:40:04 +00:00
else if ( $action == 'upload_data' )
{
2006-07-02 21:42:54 +00:00
$sql = ' SELECT lang_iso
FROM ' . LANG_TABLE . "
2006-04-22 14:40:04 +00:00
WHERE lang_id = $lang_id " ;
$result = $db -> sql_query ( $sql );
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
$file = request_var ( 'file' , '' );
$dir = request_var ( 'dir' , '' );
2006-10-19 13:55:48 +00:00
$selected_lang_file = $dir . '|' . $file ;
2006-04-22 14:40:04 +00:00
$old_file = '/' . $this -> get_filename ( $row [ 'lang_iso' ], $dir , $file , false , true );
$lang_path = 'language/' . $row [ 'lang_iso' ] . '/' . (( $dir ) ? $dir . '/' : '' );
include_once ( $phpbb_root_path . 'includes/functions_transfer.' . $phpEx );
$method = request_var ( 'method' , '' );
2007-03-30 10:49:06 +00:00
if ( $method != 'ftp' && $method != 'ftp_fsock' )
2006-04-22 14:40:04 +00:00
{
2007-03-30 10:49:06 +00:00
trigger_error ( $user -> lang [ 'INVALID_UPLOAD_METHOD' ], E_USER_ERROR );
2006-04-22 14:40:04 +00:00
}
2007-03-30 10:49:06 +00:00
$transfer = new $method ( request_var ( 'host' , '' ), request_var ( 'username' , '' ), request_var ( 'password' , '' ), request_var ( 'root_path' , '' ), request_var ( 'port' , '' ), request_var ( 'timeout' , '' ));
2006-06-11 18:13:52 +00:00
if (( $result = $transfer -> open_session ()) !== true )
2006-04-22 14:40:04 +00:00
{
2006-10-19 13:55:48 +00:00
trigger_error ( $user -> lang [ $result ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode ( $selected_lang_file )), E_USER_WARNING );
2006-04-22 14:40:04 +00:00
}
$transfer -> rename ( $lang_path . $file , $lang_path . $file . '.bak' );
2007-01-24 11:29:56 +00:00
$result = $transfer -> copy_file ( 'store/' . $lang_path . $file , $lang_path . $file );
if ( $result === false )
{
// If failed, try to rename again and print error out...
2007-01-26 16:09:51 +00:00
$transfer -> delete_file ( $lang_path . $file );
2007-01-24 11:29:56 +00:00
$transfer -> rename ( $lang_path . $file . '.bak' , $lang_path . $file );
trigger_error ( $user -> lang [ 'UPLOAD_FAILED' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode ( $selected_lang_file )), E_USER_WARNING );
}
2006-04-22 14:40:04 +00:00
$transfer -> close_session ();
2006-07-02 21:42:54 +00:00
// Remove from storage folder
2007-07-12 07:08:21 +00:00
if ( file_exists ( $phpbb_root_path . 'store/' . $lang_path . $file ))
{
@ unlink ( $phpbb_root_path . 'store/' . $lang_path . $file );
}
2006-07-02 21:42:54 +00:00
2006-04-22 14:40:04 +00:00
add_log ( 'admin' , 'LOG_LANGUAGE_FILE_REPLACED' , $file );
2006-10-19 13:55:48 +00:00
trigger_error ( $user -> lang [ 'UPLOAD_COMPLETED' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode ( $selected_lang_file )));
2006-04-22 14:40:04 +00:00
}
2007-02-18 13:42:08 +00:00
add_log ( 'admin' , 'LOG_LANGUAGE_FILE_SUBMITTED' , $this -> language_file );
2005-11-30 17:48:06 +00:00
$action = 'details' ;
// no break;
case 'details' :
if ( ! $lang_id )
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'NO_LANG_ID' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
$this -> page_title = 'LANGUAGE_PACK_DETAILS' ;
2006-07-10 15:55:10 +00:00
$sql = ' SELECT *
FROM ' . LANG_TABLE . '
2005-11-30 17:48:06 +00:00
WHERE lang_id = ' . $lang_id ;
$result = $db -> sql_query ( $sql );
$lang_entries = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
$lang_iso = $lang_entries [ 'lang_iso' ];
$missing_vars = $missing_files = array ();
// Get email templates
$email_files = filelist ( $phpbb_root_path . 'language/' . $config [ 'default_lang' ], 'email' , 'txt' );
$email_files = $email_files [ 'email/' ];
// Get acp files
$acp_files = filelist ( $phpbb_root_path . 'language/' . $config [ 'default_lang' ], 'acp' , $phpEx );
$acp_files = $acp_files [ 'acp/' ];
// Get mod files
$mods_files = filelist ( $phpbb_root_path . 'language/' . $config [ 'default_lang' ], 'mods' , $phpEx );
$mods_files = ( isset ( $mods_files [ 'mods/' ])) ? $mods_files [ 'mods/' ] : array ();
// Check if our current filename matches the files
switch ( $this -> language_directory )
{
case 'email' :
if ( ! in_array ( $this -> language_file , $email_files ))
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'WRONG_LANGUAGE_FILE' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
break ;
case 'acp' :
if ( ! in_array ( $this -> language_file , $acp_files ))
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'WRONG_LANGUAGE_FILE' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
break ;
case 'mods' :
if ( ! in_array ( $this -> language_file , $mods_files ))
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'WRONG_LANGUAGE_FILE' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
break ;
default :
if ( ! in_array ( $this -> language_file , $this -> main_files ))
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'WRONG_LANGUAGE_FILE' ] . adm_back_link ( $this -> u_action . '&action=details&id=' . $lang_id ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
}
if ( isset ( $_POST [ 'remove_store' ]))
{
$store_filename = $this -> get_filename ( $lang_iso , $this -> language_directory , $this -> language_file , true , true );
2007-07-12 07:08:21 +00:00
if ( file_exists ( $phpbb_root_path . $store_filename ))
{
@ unlink ( $phpbb_root_path . $store_filename );
}
2005-11-30 17:48:06 +00:00
}
2006-02-19 14:17:12 +00:00
include_once ( $phpbb_root_path . 'includes/functions_transfer.' . $phpEx );
$methods = transfer :: methods ();
foreach ( $methods as $method )
{
$template -> assign_block_vars ( 'buttons' , array (
'VALUE' => $method
));
}
2005-11-30 17:48:06 +00:00
$template -> assign_vars ( array (
'S_DETAILS' => true ,
2006-02-18 13:54:12 +00:00
'U_ACTION' => $this -> u_action . " &action=details&id= $lang_id " ,
'U_BACK' => $this -> u_action ,
2005-11-30 17:48:06 +00:00
'LANG_LOCAL_NAME' => $lang_entries [ 'lang_local_name' ],
'LANG_ENGLISH_NAME' => $lang_entries [ 'lang_english_name' ],
'LANG_ISO' => $lang_entries [ 'lang_iso' ],
'LANG_AUTHOR' => $lang_entries [ 'lang_author' ],
2006-02-19 14:17:12 +00:00
'ALLOW_UPLOAD' => sizeof ( $methods )
2005-11-30 17:48:06 +00:00
)
);
// If current lang is different from the default lang, then first try to grab missing/additional vars
if ( $lang_iso != $config [ 'default_lang' ])
{
$is_missing_var = false ;
foreach ( $this -> main_files as $file )
{
if ( file_exists ( $phpbb_root_path . $this -> get_filename ( $lang_iso , '' , $file )))
{
$missing_vars [ $file ] = $this -> compare_language_files ( $config [ 'default_lang' ], $lang_iso , '' , $file );
if ( sizeof ( $missing_vars [ $file ]))
{
$is_missing_var = true ;
}
}
else
{
$missing_files [] = $this -> get_filename ( $lang_iso , '' , $file );
}
}
// Now go through acp/mods directories
foreach ( $acp_files as $file )
{
if ( file_exists ( $phpbb_root_path . $this -> get_filename ( $lang_iso , 'acp' , $file )))
{
$missing_vars [ 'acp/' . $file ] = $this -> compare_language_files ( $config [ 'default_lang' ], $lang_iso , 'acp' , $file );
if ( sizeof ( $missing_vars [ 'acp/' . $file ]))
{
$is_missing_var = true ;
}
}
else
{
$missing_files [] = $this -> get_filename ( $lang_iso , 'acp' , $file );
}
}
if ( sizeof ( $mods_files ))
{
foreach ( $mods_files as $file )
{
if ( file_exists ( $phpbb_root_path . $this -> get_filename ( $lang_iso , 'mods' , $file )))
{
$missing_vars [ 'mods/' . $file ] = $this -> compare_language_files ( $config [ 'default_lang' ], $lang_iso , 'mods' , $file );
if ( sizeof ( $missing_vars [ 'mods/' . $file ]))
{
$is_missing_var = true ;
}
}
else
{
$missing_files [] = $this -> get_filename ( $lang_iso , 'mods' , $file );
}
}
}
// More missing files... for example email templates?
foreach ( $email_files as $file )
{
if ( ! file_exists ( $phpbb_root_path . $this -> get_filename ( $lang_iso , 'email' , $file )))
{
$missing_files [] = $this -> get_filename ( $lang_iso , 'email' , $file );
}
}
if ( sizeof ( $missing_files ))
{
$template -> assign_vars ( array (
'S_MISSING_FILES' => true ,
'L_MISSING_FILES' => sprintf ( $user -> lang [ 'THOSE_MISSING_LANG_FILES' ], $lang_entries [ 'lang_local_name' ]),
'MISSING_FILES' => implode ( '<br />' , $missing_files ))
2006-11-03 17:50:39 +00:00
);
2005-11-30 17:48:06 +00:00
}
if ( $is_missing_var )
{
$template -> assign_vars ( array (
'S_MISSING_VARS' => true ,
'L_MISSING_VARS_EXPLAIN' => sprintf ( $user -> lang [ 'THOSE_MISSING_LANG_VARIABLES' ], $lang_entries [ 'lang_local_name' ]),
2006-02-18 13:54:12 +00:00
'U_MISSING_ACTION' => $this -> u_action . " &action= $action &id= $lang_id " )
2006-11-03 17:50:39 +00:00
);
2005-11-30 17:48:06 +00:00
foreach ( $missing_vars as $file => $vars )
{
if ( ! sizeof ( $vars ))
{
continue ;
}
$template -> assign_block_vars ( 'missing' , array (
'FILE' => $file ,
'TPL' => $this -> print_language_entries ( $vars , '' , false ),
'KEY' => ( strpos ( $file , '/' ) === false ) ? '|' . $file : str_replace ( '/' , '|' , $file ))
);
}
}
}
// Main language files
$s_lang_options = '<option value="|common.' . $phpEx . '" class="sep">' . $user -> lang [ 'LANGUAGE_FILES' ] . '</option>' ;
foreach ( $this -> main_files as $file )
{
if ( strpos ( $file , 'help_' ) === 0 )
{
continue ;
}
$prefix = ( file_exists ( $phpbb_root_path . $this -> get_filename ( $lang_iso , '' , $file , true , true ))) ? '* ' : '' ;
$selected = ( ! $this -> language_directory && $this -> language_file == $file ) ? ' selected="selected"' : '' ;
$s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>' ;
}
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
// Help Files
$s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user -> lang [ 'HELP_FILES' ] . '</option>' ;
foreach ( $this -> main_files as $file )
{
if ( strpos ( $file , 'help_' ) !== 0 )
{
continue ;
}
$prefix = ( file_exists ( $phpbb_root_path . $this -> get_filename ( $lang_iso , '' , $file , true , true ))) ? '* ' : '' ;
$selected = ( ! $this -> language_directory && $this -> language_file == $file ) ? ' selected="selected"' : '' ;
$s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>' ;
}
// Now every other language directory
$check_files = array ( 'email' , 'acp' , 'mods' );
foreach ( $check_files as $check )
{
if ( ! sizeof ( $ { $check . '_files' }))
{
continue ;
}
$s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user -> lang [ strtoupper ( $check ) . '_FILES' ] . '</option>' ;
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
foreach ( $ { $check . '_files' } as $file )
{
$prefix = ( file_exists ( $phpbb_root_path . $this -> get_filename ( $lang_iso , $check , $file , true , true ))) ? '* ' : '' ;
$selected = ( $this -> language_directory == $check && $this -> language_file == $file ) ? ' selected="selected"' : '' ;
$s_lang_options .= '<option value="' . $check . '|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>' ;
}
}
// Get Language Entries - if saved within store folder, we take this one (with the option to remove it)
$lang = array ();
$is_email_file = ( $this -> language_directory == 'email' ) ? true : false ;
$is_help_file = ( strpos ( $this -> language_file , 'help_' ) === 0 ) ? true : false ;
$file_from_store = ( file_exists ( $phpbb_root_path . $this -> get_filename ( $lang_iso , $this -> language_directory , $this -> language_file , true , true ))) ? true : false ;
$no_store_filename = $this -> get_filename ( $lang_iso , $this -> language_directory , $this -> language_file );
if ( ! $file_from_store && ! file_exists ( $phpbb_root_path . $no_store_filename ))
{
$print_message = sprintf ( $user -> lang [ 'MISSING_LANGUAGE_FILE' ], $no_store_filename );
}
else
{
if ( $is_email_file )
{
2006-01-04 06:37:17 +00:00
$lang = file_get_contents ( $phpbb_root_path . $this -> get_filename ( $lang_iso , $this -> language_directory , $this -> language_file , $file_from_store ));
2005-11-30 17:48:06 +00:00
}
else
{
2006-03-21 19:23:34 +00:00
$help = array ();
2005-11-30 17:48:06 +00:00
include ( $phpbb_root_path . $this -> get_filename ( $lang_iso , $this -> language_directory , $this -> language_file , $file_from_store ));
if ( $is_help_file )
{
$lang = $help ;
unset ( $help );
}
}
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
$print_message = (( $this -> language_directory ) ? $this -> language_directory . '/' : '' ) . $this -> language_file ;
}
// Normal language pack entries
$template -> assign_vars ( array (
2006-02-18 13:54:12 +00:00
'U_ENTRY_ACTION' => $this -> u_action . " &action=details&id= $lang_id #entries " ,
2005-11-30 17:48:06 +00:00
'S_EMAIL_FILE' => $is_email_file ,
'S_FROM_STORE' => $file_from_store ,
'S_LANG_OPTIONS' => $s_lang_options ,
'PRINT_MESSAGE' => $print_message ,
)
);
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
if ( ! $is_email_file )
{
$tpl = '' ;
$name = (( $this -> language_directory ) ? $this -> language_directory . '/' : '' ) . $this -> language_file ;
if ( isset ( $missing_vars [ $name ]) && sizeof ( $missing_vars [ $name ]))
{
2006-12-28 17:28:28 +00:00
$tpl .= $this -> print_language_entries ( $missing_vars [ $name ], '* ' );
2005-11-30 17:48:06 +00:00
}
2006-11-03 17:50:39 +00:00
2006-12-28 17:28:28 +00:00
$tpl .= $this -> print_language_entries ( $lang );
2005-11-30 17:48:06 +00:00
$template -> assign_var ( 'TPL' , $tpl );
unset ( $tpl );
}
else
{
$template -> assign_vars ( array (
'LANG' => $lang )
);
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
unset ( $lang );
}
return ;
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
break ;
case 'delete' :
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
if ( ! $lang_id )
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'NO_LANG_ID' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
2006-11-03 17:50:39 +00:00
2006-07-10 15:55:10 +00:00
$sql = ' SELECT *
FROM ' . LANG_TABLE . '
2005-11-30 17:48:06 +00:00
WHERE lang_id = ' . $lang_id ;
$result = $db -> sql_query ( $sql );
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
if ( $row [ 'lang_iso' ] == $config [ 'default_lang' ])
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'NO_REMOVE_DEFAULT_LANG' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
$db -> sql_query ( 'DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id );
$sql = 'UPDATE ' . USERS_TABLE . "
2006-11-03 17:50:39 +00:00
SET user_lang = '" . $db->sql_escape($config[' default_lang ']) . "'
WHERE user_lang = '" . $db->sql_escape($row[' lang_iso ']) . "' " ;
2005-11-30 17:48:06 +00:00
$db -> sql_query ( $sql );
2006-11-03 17:50:39 +00:00
2007-01-04 16:07:38 +00:00
// We also need to remove the translated entries for custom profile fields - we want clean tables, don't we?
$sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id ;
$db -> sql_query ( $sql );
$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id ;
$db -> sql_query ( $sql );
2007-04-25 23:59:59 +00:00
$sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_lang = ' " . $db -> sql_escape ( $row [ 'lang_iso' ]) . " ' " ;
$result = $db -> sql_query ( $sql );
$cache -> destroy ( 'sql' , STYLES_IMAGESET_DATA_TABLE );
2005-11-30 17:48:06 +00:00
add_log ( 'admin' , 'LOG_LANGUAGE_PACK_DELETED' , $row [ 'lang_english_name' ]);
2006-11-03 17:50:39 +00:00
2006-02-18 13:54:12 +00:00
trigger_error ( sprintf ( $user -> lang [ 'LANGUAGE_PACK_DELETED' ], $row [ 'lang_english_name' ]) . adm_back_link ( $this -> u_action ));
2005-11-30 17:48:06 +00:00
break ;
case 'install' :
$lang_iso = request_var ( 'iso' , '' );
$lang_iso = basename ( $lang_iso );
if ( ! $lang_iso || ! file_exists ( " { $phpbb_root_path } language/ $lang_iso /iso.txt " ))
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'LANGUAGE_PACK_NOT_EXIST' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
$file = file ( " { $phpbb_root_path } language/ $lang_iso /iso.txt " );
$lang_pack = array (
'iso' => $lang_iso ,
2006-06-06 20:53:46 +00:00
'name' => trim ( htmlspecialchars ( $file [ 0 ])),
2006-11-03 17:50:39 +00:00
'local_name' => trim ( htmlspecialchars ( $file [ 1 ], ENT_COMPAT , 'UTF-8' )),
'author' => trim ( htmlspecialchars ( $file [ 2 ], ENT_COMPAT , 'UTF-8' ))
2005-11-30 17:48:06 +00:00
);
unset ( $file );
2006-07-10 15:55:10 +00:00
$sql = ' SELECT lang_iso
FROM ' . LANG_TABLE . "
2005-11-30 17:48:06 +00:00
WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "' " ;
$result = $db -> sql_query ( $sql );
2006-11-03 17:50:39 +00:00
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
2005-11-30 17:48:06 +00:00
2006-11-10 13:49:52 +00:00
if ( $row )
2005-11-30 17:48:06 +00:00
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'LANGUAGE_PACK_ALREADY_INSTALLED' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
if ( ! $lang_pack [ 'name' ] || ! $lang_pack [ 'local_name' ])
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'INVALID_LANGUAGE_PACK' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
// Add language pack
$sql_ary = array (
'lang_iso' => $lang_pack [ 'iso' ],
'lang_dir' => $lang_pack [ 'iso' ],
'lang_english_name' => $lang_pack [ 'name' ],
'lang_local_name' => $lang_pack [ 'local_name' ],
'lang_author' => $lang_pack [ 'author' ]
);
$db -> sql_query ( 'INSERT INTO ' . LANG_TABLE . ' ' . $db -> sql_build_array ( 'INSERT' , $sql_ary ));
2007-01-04 16:07:38 +00:00
$lang_id = $db -> sql_nextid ();
2007-04-25 23:59:59 +00:00
$valid_localized = array (
'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' ,
);
$sql_ary = array ();
$sql = ' SELECT *
FROM ' . STYLES_IMAGESET_TABLE ;
$result = $db -> sql_query ( $sql );
while ( $imageset_row = $db -> sql_fetchrow ( $result ))
{
if ( @ file_exists ( " { $phpbb_root_path } styles/ { $imageset_row [ 'imageset_path' ] } /imageset/ { $lang_pack [ 'iso' ] } /imageset.cfg " ))
{
$cfg_data_imageset_data = parse_cfg_file ( " { $phpbb_root_path } styles/ { $imageset_row [ 'imageset_path' ] } /imageset/ { $lang_pack [ 'iso' ] } /imageset.cfg " );
foreach ( $cfg_data_imageset_data as $image_name => $value )
{
if ( strpos ( $value , '*' ) !== false )
{
if ( substr ( $value , - 1 , 1 ) === '*' )
{
list ( $image_filename , $image_height ) = explode ( '*' , $value );
$image_width = 0 ;
}
else
{
list ( $image_filename , $image_height , $image_width ) = explode ( '*' , $value );
}
}
else
{
$image_filename = $value ;
$image_height = $image_width = 0 ;
}
if ( strpos ( $image_name , 'img_' ) === 0 && $image_filename )
{
$image_name = substr ( $image_name , 4 );
if ( in_array ( $image_name , $valid_localized ))
{
$sql_ary [] = array (
2007-07-27 17:33:27 +00:00
'image_name' => ( string ) $image_name ,
'image_filename' => ( string ) $image_filename ,
'image_height' => ( int ) $image_height ,
'image_width' => ( int ) $image_width ,
'imageset_id' => ( int ) $imageset_row [ 'imageset_id' ],
'image_lang' => ( string ) $lang_pack [ 'iso' ],
2007-04-25 23:59:59 +00:00
);
}
}
}
}
}
$db -> sql_freeresult ( $result );
if ( sizeof ( $sql_ary ))
{
$db -> sql_multi_insert ( STYLES_IMAGESET_DATA_TABLE , $sql_ary );
$cache -> destroy ( 'sql' , STYLES_IMAGESET_DATA_TABLE );
}
2007-01-04 16:07:38 +00:00
// Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier.
$sql = ' SELECT lang_id
FROM ' . LANG_TABLE . "
WHERE lang_iso = '" . $db->sql_escape($config[' default_lang ']) . "' " ;
$result = $db -> sql_query ( $sql );
$default_lang_id = ( int ) $db -> sql_fetchfield ( 'lang_id' );
$db -> sql_freeresult ( $result );
// From the mysql documentation:
// 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.
// Due to this we stay on the safe side if we do the insertion "the manual way"
$sql = ' SELECT field_id , lang_name , lang_explain , lang_default_value
FROM ' . PROFILE_LANG_TABLE . '
WHERE lang_id = ' . $default_lang_id ;
$result = $db -> sql_query ( $sql );
while ( $row = $db -> sql_fetchrow ( $result ))
{
$row [ 'lang_id' ] = $lang_id ;
$db -> sql_query ( 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db -> sql_build_array ( 'INSERT' , $row ));
}
$db -> sql_freeresult ( $result );
$sql = ' SELECT field_id , option_id , field_type , lang_value
FROM ' . PROFILE_FIELDS_LANG_TABLE . '
WHERE lang_id = ' . $default_lang_id ;
$result = $db -> sql_query ( $sql );
while ( $row = $db -> sql_fetchrow ( $result ))
{
$row [ 'lang_id' ] = $lang_id ;
$db -> sql_query ( 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db -> sql_build_array ( 'INSERT' , $row ));
}
$db -> sql_freeresult ( $result );
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
add_log ( 'admin' , 'LOG_LANGUAGE_PACK_INSTALLED' , $lang_pack [ 'name' ]);
2006-11-03 17:50:39 +00:00
2006-02-18 13:54:12 +00:00
trigger_error ( sprintf ( $user -> lang [ 'LANGUAGE_PACK_INSTALLED' ], $lang_pack [ 'name' ]) . adm_back_link ( $this -> u_action ));
2005-11-30 17:48:06 +00:00
break ;
case 'download' :
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
if ( ! $lang_id )
{
2006-08-28 15:50:33 +00:00
trigger_error ( $user -> lang [ 'NO_LANG_ID' ] . adm_back_link ( $this -> u_action ), E_USER_WARNING );
2005-11-30 17:48:06 +00:00
}
2006-07-10 15:55:10 +00:00
$sql = ' SELECT *
FROM ' . LANG_TABLE . '
2005-11-30 17:48:06 +00:00
WHERE lang_id = ' . $lang_id ;
$result = $db -> sql_query ( $sql );
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
$use_method = request_var ( 'use_method' , '' );
2006-01-04 06:37:17 +00:00
$methods = array ( '.tar' );
2005-11-30 17:48:06 +00:00
2006-01-04 06:37:17 +00:00
$available_methods = array ( '.tar.gz' => 'zlib' , '.tar.bz2' => 'bz2' , '.zip' => 'zlib' );
2005-11-30 17:48:06 +00:00
foreach ( $available_methods as $type => $module )
{
if ( !@ extension_loaded ( $module ))
{
continue ;
}
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
$methods [] = $type ;
}
// Let the user decide in which format he wants to have the pack
if ( ! $use_method )
{
$this -> page_title = 'SELECT_DOWNLOAD_FORMAT' ;
$radio_buttons = '' ;
foreach ( $methods as $method )
{
2007-05-05 10:22:24 +00:00
$radio_buttons .= '<label><input type="radio"' . (( ! $radio_buttons ) ? ' id="use_method"' : '' ) . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>' ;
2005-11-30 17:48:06 +00:00
}
$template -> assign_vars ( array (
'S_SELECT_METHOD' => true ,
2006-02-18 13:54:12 +00:00
'U_BACK' => $this -> u_action ,
'U_ACTION' => $this -> u_action . " &action= $action &id= $lang_id " ,
2005-11-30 17:48:06 +00:00
'RADIO_BUTTONS' => $radio_buttons )
);
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
return ;
}
2006-01-04 06:37:17 +00:00
if ( ! in_array ( $use_method , $methods ))
{
$use_method = '.tar' ;
}
2005-11-30 17:48:06 +00:00
include_once ( $phpbb_root_path . 'includes/functions_compress.' . $phpEx );
2006-08-11 13:21:51 +00:00
if ( $use_method == '.zip' )
2005-11-30 17:48:06 +00:00
{
2006-06-09 19:27:08 +00:00
$compress = new compress_zip ( 'w' , $phpbb_root_path . 'store/lang_' . $row [ 'lang_iso' ] . $use_method );
2005-11-30 17:48:06 +00:00
}
else
{
2006-06-09 19:27:08 +00:00
$compress = new compress_tar ( 'w' , $phpbb_root_path . 'store/lang_' . $row [ 'lang_iso' ] . $use_method , $use_method );
2005-11-30 17:48:06 +00:00
}
// Get email templates
$email_templates = filelist ( $phpbb_root_path . 'language/' . $row [ 'lang_iso' ], 'email' , 'txt' );
$email_templates = $email_templates [ 'email/' ];
// Get acp files
$acp_files = filelist ( $phpbb_root_path . 'language/' . $row [ 'lang_iso' ], 'acp' , $phpEx );
$acp_files = $acp_files [ 'acp/' ];
// Get mod files
$mod_files = filelist ( $phpbb_root_path . 'language/' . $row [ 'lang_iso' ], 'mods' , $phpEx );
$mod_files = ( isset ( $mod_files [ 'mods/' ])) ? $mod_files [ 'mods/' ] : array ();
// Add main files
$this -> add_to_archive ( $compress , $this -> main_files , $row [ 'lang_iso' ]);
2006-08-11 10:09:54 +00:00
// Add search files if they exist...
if ( file_exists ( $phpbb_root_path . 'language/' . $row [ 'lang_iso' ] . '/search_ignore_words.' . $phpEx ))
{
$this -> add_to_archive ( $compress , array ( " search_ignore_words. $phpEx " ), $row [ 'lang_iso' ]);
}
if ( file_exists ( $phpbb_root_path . 'language/' . $row [ 'lang_iso' ] . '/search_synonyms.' . $phpEx ))
{
$this -> add_to_archive ( $compress , array ( " search_synonyms. $phpEx " ), $row [ 'lang_iso' ]);
}
2005-11-30 17:48:06 +00:00
// Write files in folders
$this -> add_to_archive ( $compress , $email_templates , $row [ 'lang_iso' ], 'email' );
$this -> add_to_archive ( $compress , $acp_files , $row [ 'lang_iso' ], 'acp' );
$this -> add_to_archive ( $compress , $mod_files , $row [ 'lang_iso' ], 'mods' );
// Write ISO File
2006-11-03 21:05:25 +00:00
$iso_src = htmlspecialchars_decode ( $row [ 'lang_english_name' ]) . " \n " ;
$iso_src .= htmlspecialchars_decode ( $row [ 'lang_local_name' ]) . " \n " ;
$iso_src .= htmlspecialchars_decode ( $row [ 'lang_author' ]);
2005-11-30 17:48:06 +00:00
$compress -> add_data ( $iso_src , 'language/' . $row [ 'lang_iso' ] . '/iso.txt' );
// index.html files
$compress -> add_data ( '' , 'language/' . $row [ 'lang_iso' ] . '/index.html' );
$compress -> add_data ( '' , 'language/' . $row [ 'lang_iso' ] . '/email/index.html' );
$compress -> add_data ( '' , 'language/' . $row [ 'lang_iso' ] . '/acp/index.html' );
if ( sizeof ( $mod_files ))
{
$compress -> add_data ( '' , 'language/' . $row [ 'lang_iso' ] . '/mods/index.html' );
}
$compress -> close ();
$compress -> download ( 'lang_' . $row [ 'lang_iso' ]);
2006-08-22 21:26:06 +00:00
@ unlink ( $phpbb_root_path . 'store/lang_' . $row [ 'lang_iso' ] . $use_method );
2005-11-30 17:48:06 +00:00
exit ;
break ;
}
$sql = ' SELECT user_lang , COUNT ( user_lang ) AS lang_count
FROM ' . USERS_TABLE . '
GROUP BY user_lang ' ;
$result = $db -> sql_query ( $sql );
$lang_count = array ();
while ( $row = $db -> sql_fetchrow ( $result ))
{
$lang_count [ $row [ 'user_lang' ]] = $row [ 'lang_count' ];
}
$db -> sql_freeresult ( $result );
2007-01-26 16:09:51 +00:00
$sql = ' SELECT *
2006-07-10 15:55:10 +00:00
FROM ' . LANG_TABLE . '
ORDER BY lang_english_name ' ;
2005-11-30 17:48:06 +00:00
$result = $db -> sql_query ( $sql );
$installed = array ();
while ( $row = $db -> sql_fetchrow ( $result ))
{
$installed [] = $row [ 'lang_iso' ];
$tagstyle = ( $row [ 'lang_iso' ] == $config [ 'default_lang' ]) ? '*' : '' ;
$template -> assign_block_vars ( 'lang' , array (
2006-11-03 17:50:39 +00:00
'U_DETAILS' => $this -> u_action . " &action=details&id= { $row [ 'lang_id' ] } " ,
'U_DOWNLOAD' => $this -> u_action . " &action=download&id= { $row [ 'lang_id' ] } " ,
'U_DELETE' => $this -> u_action . " &action=delete&id= { $row [ 'lang_id' ] } " ,
'ENGLISH_NAME' => $row [ 'lang_english_name' ],
'TAG' => $tagstyle ,
'LOCAL_NAME' => $row [ 'lang_local_name' ],
'ISO' => $row [ 'lang_iso' ],
'USED_BY' => ( isset ( $lang_count [ $row [ 'lang_iso' ]])) ? $lang_count [ $row [ 'lang_iso' ]] : 0 ,
));
2005-11-30 17:48:06 +00:00
}
$db -> sql_freeresult ( $result );
$new_ary = $iso = array ();
2007-01-20 17:58:27 +00:00
$dp = @ opendir ( " { $phpbb_root_path } language " );
2005-11-30 17:48:06 +00:00
2007-01-20 17:58:27 +00:00
if ( $dp )
2005-11-30 17:48:06 +00:00
{
2007-01-20 17:58:27 +00:00
while (( $file = readdir ( $dp )) !== false )
2005-11-30 17:48:06 +00:00
{
2007-01-20 17:58:27 +00:00
if ( $file [ 0 ] != '.' && file_exists ( " { $phpbb_root_path } language/ $file /iso.txt " ))
2005-11-30 17:48:06 +00:00
{
2007-01-20 17:58:27 +00:00
if ( ! in_array ( $file , $installed ))
2005-11-30 17:48:06 +00:00
{
2007-01-20 17:58:27 +00:00
if ( $iso = file ( " { $phpbb_root_path } language/ $file /iso.txt " ))
2005-11-30 17:48:06 +00:00
{
2007-01-20 17:58:27 +00:00
if ( sizeof ( $iso ) == 3 )
{
$new_ary [ $file ] = array (
'iso' => $file ,
'name' => trim ( $iso [ 0 ]),
'local_name' => trim ( $iso [ 1 ]),
'author' => trim ( $iso [ 2 ])
);
}
2005-11-30 17:48:06 +00:00
}
}
}
}
2007-01-20 17:58:27 +00:00
closedir ( $dp );
2005-11-30 17:48:06 +00:00
}
2007-01-20 17:58:27 +00:00
2005-11-30 17:48:06 +00:00
unset ( $installed );
if ( sizeof ( $new_ary ))
{
foreach ( $new_ary as $iso => $lang_ary )
{
$template -> assign_block_vars ( 'notinst' , array (
2006-11-03 17:50:39 +00:00
'ISO' => htmlspecialchars ( $lang_ary [ 'iso' ]),
'LOCAL_NAME' => htmlspecialchars ( $lang_ary [ 'local_name' ], ENT_COMPAT , 'UTF-8' ),
'NAME' => htmlspecialchars ( $lang_ary [ 'name' ], ENT_COMPAT , 'UTF-8' ),
2006-02-18 13:54:12 +00:00
'U_INSTALL' => $this -> u_action . '&action=install&iso=' . urlencode ( $lang_ary [ 'iso' ]))
2005-11-30 17:48:06 +00:00
);
}
}
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
unset ( $new_ary );
}
/**
* Set default language variables / header
*/
function default_variables ()
{
global $phpEx ;
$this -> language_file_header = ' < ? php
/**
*
* { FILENAME } [{ LANG_NAME }]
*
* @ package language
2007-02-18 13:42:08 +00:00
* @ version $ ' . ' Id : ' . ' $
2006-12-28 17:28:28 +00:00
* @ copyright ( c ) ' . date(' Y ') . ' phpBB Group
2005-11-30 17:48:06 +00:00
* @ author { CHANGED } - { AUTHOR }
* @ license http :// opensource . org / licenses / gpl - license . php GNU Public License
*
*/
2006-02-19 14:17:12 +00:00
/**
* DO NOT CHANGE
*/
if ( empty ( $lang ) || ! is_array ( $lang ))
{
$lang = array ();
}
2005-11-30 17:48:06 +00:00
// DEVELOPERS PLEASE NOTE
//
2006-10-01 20:49:39 +00:00
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
2005-11-30 17:48:06 +00:00
// Placeholders can now contain order information, e.g. instead of
// \'Page %s of %s\' you can (and should) write \'Page %1$s of %2$s\', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. \'Message %d\' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., \'Click %sHERE%s\' is fine
' ;
$this -> lang_header = '
2006-02-19 14:17:12 +00:00
$lang = array_merge ( $lang , array (
2005-11-30 17:48:06 +00:00
' ;
// Language files in language root directory
2006-08-11 10:09:54 +00:00
$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 " );
2005-11-30 17:48:06 +00:00
}
/**
* Get filename / location of language file
*/
function get_filename ( $lang_iso , $directory , $filename , $check_store = false , $only_return_filename = false )
{
global $phpbb_root_path , $safe_mode ;
$check_filename = " language/ $lang_iso / " . (( $directory ) ? $directory . '/' : '' ) . $filename ;
if ( $check_store )
{
$check_store_filename = ( $safe_mode ) ? " store/langfile_ { $lang_iso } " . (( $directory ) ? '_' . $directory : '' ) . " _ { $filename } " : " store/language/ $lang_iso / " . (( $directory ) ? $directory . '/' : '' ) . $filename ;
if ( ! $only_return_filename && file_exists ( $phpbb_root_path . $check_store_filename ))
{
return $check_store_filename ;
}
else if ( $only_return_filename )
{
return $check_store_filename ;
}
}
return $check_filename ;
}
/**
* Add files to archive
*/
function add_to_archive ( & $compress , $filelist , $lang_iso , $directory = '' )
{
global $phpbb_root_path ;
foreach ( $filelist as $file )
{
// Get source filename
$source = $this -> get_filename ( $lang_iso , $directory , $file , true );
$destination = 'language/' . $lang_iso . '/' . (( $directory ) ? $directory . '/' : '' ) . $file ;
// Add file to archive
$compress -> add_custom_file ( $phpbb_root_path . $source , $destination );
}
}
2006-12-28 17:28:28 +00:00
/**
* Little helper to add some hardcoded template bits
*/
function add_input_field ()
{
$keys = func_get_args ();
$non_static = array_shift ( $keys );
$value = array_shift ( $keys );
if ( ! $non_static )
{
return '<strong>' . htmlspecialchars ( $value , ENT_COMPAT , 'UTF-8' ) . '</strong>' ;
}
// If more then 270 characters, then we present a textarea, else an input field
$textarea = ( utf8_strlen ( $value ) > 270 ) ? true : false ;
$tpl = '' ;
$tpl .= ( $textarea ) ? '<textarea name="' : '<input type="text" name="' ;
$tpl .= 'entry[' . implode ( '][' , array_map ( 'utf8_htmlspecialchars' , $keys )) . ']"' ;
2007-01-21 17:32:26 +00:00
$tpl .= ( $textarea ) ? ' cols="80" rows="5" class="langvalue">' : ' class="langvalue" value="' ;
2006-12-28 17:28:28 +00:00
$tpl .= htmlspecialchars ( $value , ENT_COMPAT , 'UTF-8' );
$tpl .= ( $textarea ) ? '</textarea>' : '" />' ;
return $tpl ;
}
2005-11-30 17:48:06 +00:00
/**
* Print language entries
*/
function print_language_entries ( & $lang_ary , $key_prefix = '' , $input_field = true )
{
$tpl = '' ;
foreach ( $lang_ary as $key => $value )
{
if ( is_array ( $value ))
{
2006-12-28 17:28:28 +00:00
// Write key
2005-11-30 17:48:06 +00:00
$tpl .= '
< tr >
2006-12-28 17:28:28 +00:00
< td class = " row3 " colspan = " 2 " > ' . htmlspecialchars($key_prefix, ENT_COMPAT, ' UTF - 8 ') . ' < strong > ' . htmlspecialchars($key, ENT_COMPAT, ' UTF - 8 ') . ' </ strong ></ td >
2005-11-30 17:48:06 +00:00
</ tr > ' ;
foreach ( $value as $_key => $_value )
{
2006-06-22 15:14:03 +00:00
if ( is_array ( $_value ))
2005-11-30 17:48:06 +00:00
{
2006-12-28 17:28:28 +00:00
// Write key
2006-06-22 15:14:03 +00:00
$tpl .= '
< tr >
2006-12-28 17:28:28 +00:00
< td class = " row3 " colspan = " 2 " > ' . htmlspecialchars($key_prefix, ENT_COMPAT, ' UTF - 8 ') . ' & nbsp ; & nbsp ; < strong > ' . htmlspecialchars($_key, ENT_COMPAT, ' UTF - 8 ') . ' </ strong ></ td >
2006-06-22 15:14:03 +00:00
</ tr > ' ;
foreach ( $_value as $__key => $__value )
{
2006-12-28 17:28:28 +00:00
// Write key
2006-06-22 15:14:03 +00:00
$tpl .= '
< tr >
2006-12-28 17:28:28 +00:00
< td class = " row1 " style = " white-space: nowrap; " > ' . htmlspecialchars($key_prefix, ENT_COMPAT, ' UTF - 8 ') . ' < strong > ' . htmlspecialchars($__key, ENT_COMPAT, ' UTF - 8 ') . ' </ strong ></ td >
2006-06-22 15:14:03 +00:00
< td class = " row2 " > ' ;
2006-12-28 17:28:28 +00:00
$tpl .= $this -> add_input_field ( $input_field , $__value , $key , $_key , $__key );
2006-06-22 15:14:03 +00:00
$tpl .= ' </ td >
</ tr > ' ;
}
2005-11-30 17:48:06 +00:00
}
else
{
2006-12-28 17:28:28 +00:00
// Write key
2006-06-22 15:14:03 +00:00
$tpl .= '
< tr >
2006-12-28 17:28:28 +00:00
< td class = " row1 " style = " white-space: nowrap; " > ' . htmlspecialchars($key_prefix, ENT_COMPAT, ' UTF - 8 ') . ' < strong > ' . htmlspecialchars($_key, ENT_COMPAT, ' UTF - 8 ') . ' </ strong ></ td >
2006-06-22 15:14:03 +00:00
< td class = " row2 " > ' ;
2006-11-03 17:50:39 +00:00
2006-12-28 17:28:28 +00:00
$tpl .= $this -> add_input_field ( $input_field , $_value , $key , $_key );
2006-06-22 15:14:03 +00:00
$tpl .= ' </ td >
</ tr > ' ;
2005-11-30 17:48:06 +00:00
}
}
$tpl .= '
< tr >
< td class = " spacer " colspan = " 2 " >& nbsp ; </ td >
</ tr > ' ;
}
else
{
2006-12-28 17:28:28 +00:00
// Write key
2005-11-30 17:48:06 +00:00
$tpl .= '
< tr >
2006-12-28 17:28:28 +00:00
< td class = " row1 " style = " white-space: nowrap; " > ' . htmlspecialchars($key_prefix, ENT_COMPAT, ' UTF - 8 ') . ' < strong > ' . htmlspecialchars($key, ENT_COMPAT, ' UTF - 8 ') . ' </ strong ></ td >
2005-11-30 17:48:06 +00:00
< td class = " row2 " > ' ;
2006-12-28 17:28:28 +00:00
$tpl .= $this -> add_input_field ( $input_field , $value , $key );
2005-11-30 17:48:06 +00:00
$tpl .= ' </ td >
</ tr > ' ;
}
}
2006-11-03 17:50:39 +00:00
2005-11-30 17:48:06 +00:00
return $tpl ;
}
/**
* Compare two language files
*/
function compare_language_files ( $source_lang , $dest_lang , $directory , $file )
{
global $phpbb_root_path , $phpEx ;
$return_ary = array ();
$lang = array ();
include ( " { $phpbb_root_path } language/ { $source_lang } / " . (( $directory ) ? $directory . '/' : '' ) . $file );
$lang_entry_src = $lang ;
$lang = array ();
if ( ! file_exists ( $phpbb_root_path . $this -> get_filename ( $dest_lang , $directory , $file , true )))
{
return array ();
}
include ( $phpbb_root_path . $this -> get_filename ( $dest_lang , $directory , $file , true ));
$lang_entry_dst = $lang ;
unset ( $lang );
$diff_array_keys = array_diff ( array_keys ( $lang_entry_src ), array_keys ( $lang_entry_dst ));
unset ( $lang_entry_dst );
foreach ( $diff_array_keys as $key )
{
$return_ary [ $key ] = $lang_entry_src [ $key ];
}
unset ( $lang_entry_src );
return $return_ary ;
}
2006-07-02 21:42:54 +00:00
/**
* Return language string value for storage
*/
function prepare_lang_entry ( $text , $store = true )
{
$text = ( STRIP ) ? stripslashes ( $text ) : $text ;
// Adjust for storage...
if ( $store )
{
$text = str_replace ( " ' " , " \\ ' " , str_replace ( '\\' , '\\\\' , $text ));
}
return $text ;
}
/**
* Format language array for storage
*/
function format_lang_array ( $key , $value , $tabs = " \t " )
{
$entry = '' ;
if ( ! is_array ( $value ))
{
2007-07-12 07:08:21 +00:00
$entry .= " { $tabs } ' " . $this -> prepare_lang_entry ( $key ) . " ' \t => ' " . $this -> prepare_lang_entry ( $value ) . " ', \n " ;
2006-07-02 21:42:54 +00:00
}
else
{
$_tabs = $tabs . " \t " ;
2007-07-12 07:08:21 +00:00
$entry .= " \n { $tabs } ' " . $this -> prepare_lang_entry ( $key ) . " ' \t => array( \n " ;
2006-07-02 21:42:54 +00:00
foreach ( $value as $_key => $_value )
{
$entry .= $this -> format_lang_array ( $_key , $_value , $_tabs );
}
$entry .= " { $tabs } ), \n \n " ;
}
return $entry ;
}
2005-11-30 17:48:06 +00:00
}
?>