diff options
author | Jim Wigginton <terrafrost@phpbb.com> | 2009-07-12 15:44:43 +0000 |
---|---|---|
committer | Jim Wigginton <terrafrost@phpbb.com> | 2009-07-12 15:44:43 +0000 |
commit | 7909b729bbb1facce975b10da28754eb157723aa (patch) | |
tree | 1301cfee49fa963d06526b430ff1a7b2a572566e | |
parent | 2839f3a964d214b9c2741f047cf69f1f48662462 (diff) | |
download | forums-7909b729bbb1facce975b10da28754eb157723aa.tar forums-7909b729bbb1facce975b10da28754eb157723aa.tar.gz forums-7909b729bbb1facce975b10da28754eb157723aa.tar.bz2 forums-7909b729bbb1facce975b10da28754eb157723aa.tar.xz forums-7909b729bbb1facce975b10da28754eb157723aa.zip |
unified the transfer routines from the updater and from acp_language.php. still needs work..
git-svn-id: file:///svn/phpbb/trunk@9751 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/adm/style/acp_language.html | 48 | ||||
-rw-r--r-- | phpBB/adm/style/install/update.html | 107 | ||||
-rw-r--r-- | phpBB/adm/style/update_options.html | 123 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 264 | ||||
-rw-r--r-- | phpBB/includes/functions_transfer.php | 6 | ||||
-rw-r--r-- | phpBB/install/install_update.php | 287 | ||||
-rw-r--r-- | phpBB/language/en/common.php | 18 | ||||
-rw-r--r-- | phpBB/language/en/install.php | 15 | ||||
-rw-r--r-- | phpBB/modules/acp/acp_language.php | 389 |
9 files changed, 583 insertions, 674 deletions
diff --git a/phpBB/adm/style/acp_language.html b/phpBB/adm/style/acp_language.html index 95ac1d5852..6dbfe9e0f6 100644 --- a/phpBB/adm/style/acp_language.html +++ b/phpBB/adm/style/acp_language.html @@ -142,12 +142,8 @@ </tr> <!-- ENDIF --> <tr> - <td rowspan="2" class="row3"><strong>{PRINT_MESSAGE}<!-- IF S_FROM_STORE --><br /><span style="color: red;">{L_FILE_FROM_STORAGE}</span><!-- ENDIF --></strong></td> - <td class="row3" style="text-align: right;"><input type="submit" name="download_file" class="button2" value="{L_SUBMIT_AND_DOWNLOAD}" /> <input type="submit" name="submit_file" class="button2" value="{L_SUBMIT}" /></td> - </tr> - <tr> - <td class="row3" style="text-align: right;"> - <!-- IF ALLOW_UPLOAD --> {L_UPLOAD_METHOD}: <!-- BEGIN buttons--><input type="radio" class="radio"<!-- IF buttons.S_FIRST_ROW --> id="method" checked="checked"<!-- ENDIF --> value="{buttons.VALUE}" name="method" /> {buttons.VALUE} <!-- END buttons --><input type="submit" name="upload_file" class="button2" value="{L_SUBMIT_AND_UPLOAD}" /><!-- ENDIF --></td> + <td class="row3"><strong>{PRINT_MESSAGE}<!-- IF S_FROM_STORE --><br /><span style="color: red;">{L_FILE_FROM_STORAGE}</span><!-- ENDIF --></strong></td> + <td class="row3" style="text-align: right;"><input type="submit" name="submit_file" class="button2" value="{L_SUBMIT}" /></td> </tr> </thead> <tbody> @@ -165,45 +161,9 @@ </table> </form> -<!-- ELSEIF S_UPLOAD --> - - <a href="{U_BACK}" style="float: {S_CONTENT_FLOW_END};">« {L_BACK}</a> - - <h1>{L_UPLOAD_SETTINGS}</h1> +<!-- ELSEIF S_UPDATE_OPTIONS --> - <form id="upload" method="post" action="{U_ACTION}"> - - <!-- IF S_CONNECTION_SUCCESS --> - <div class="successbox"> - <p>{L_CONNECTION_SUCCESS}</p> - </div> - <!-- ELSEIF S_CONNECTION_FAILED --> - <div class="errorbox"> - <p>{L_CONNECTION_FAILED}</p> - </div> - <!-- ENDIF --> - - <fieldset> - <legend>{L_UPLOAD_SETTINGS}</legend> - <dl> - <dt><label>{L_UPLOAD_METHOD}:</label></dt> - <dd><strong>{NAME}</strong></dd> - </dl> - <!-- BEGIN data --> - <dl> - <dt><label for="{data.DATA}">{data.NAME}:</label><br /><span>{data.EXPLAIN}</span></dt> - <dd><input type="<!-- IF data.DATA == 'password' -->password<!-- ELSE -->text<!-- ENDIF -->" id="{data.DATA}" name="{data.DATA}" value="{data.DEFAULT}" /></dd> - </dl> - <!-- END data --> - </fieldset> - - <fieldset class="quick"> - {HIDDEN} - {S_FORM_TOKEN} - <input class="button1" type="submit" name="update" value="{L_SUBMIT}" /> - <input class="button1" type="submit" name="test_connection" value="{L_TEST_CONNECTION}" /> - </fieldset> - </form> +<!-- INCLUDE update_options.html --> <!-- ELSE --> diff --git a/phpBB/adm/style/install/update.html b/phpBB/adm/style/install/update.html index 3d0ce31ffd..bf60207e46 100644 --- a/phpBB/adm/style/install/update.html +++ b/phpBB/adm/style/install/update.html @@ -55,19 +55,6 @@ </form> -<!-- ELSEIF S_UPLOAD_SUCCESS --> - - <form id="install_update" method="post" action="{U_ACTION}"> - - <h1>{L_UPDATE_SUCCESS}</h1> - <p>{L_UPDATE_SUCCESS_EXPLAIN}</p> - - <fieldset class="submit-buttons"> - <input class="button1" type="submit" name="check_again" value="{L_CHECK_FILES_AGAIN}" /> - </fieldset> - - </form> - <!-- ENDIF --> <!-- IF S_VERSION_CHECK --> @@ -378,99 +365,9 @@ <!-- ENDIF --> -<!-- ELSEIF S_DOWNLOAD_FILES --> - - <h1>{L_DOWNLOAD_UPDATE_METHOD}</h1> - - <p>{L_DOWNLOAD_UPDATE_METHOD_EXPLAIN}</p> - - <form id="install_update" method="post" action="{U_ACTION}"> - - <fieldset> - <legend>{L_SELECT_DOWNLOAD_FORMAT}</legend> - <dl> - <dt><label for="use_method">{L_DOWNLOAD_AS}:</label></dt> - <dd>{RADIO_BUTTONS}</dd> - </dl> - </fieldset> - - <fieldset class="submit-buttons"> - {S_HIDDEN_FIELDS} - <input type="submit" class="button2" value="{L_CHECK_FILES_AGAIN}" name="check_again" /> <input type="submit" class="button1" value="{L_DOWNLOAD}" name="download" /> - </fieldset> - - </form> - - <br /><br /> - - <p>{L_MAPPING_FILE_STRUCTURE}</p> - - <table cellspacing="1"> - <col class="row1" /><col class="row2" /><col class="row1" /> - <thead> - <tr> - <th style="width: 49%">{L_ARCHIVE_FILE}</th> - <th style="width: 2%"> </th> - <th style="width: 49%">{L_DESTINATION}</th> - </tr> - </thead> - <tbody> - <!-- BEGIN location --> - <tr> - <td>{location.SOURCE}</td> - <td><strong>»</strong></td> - <td>{location.DESTINATION}</td> - </tr> - <!-- END location --> - </tbody> - </table> - -<!-- ELSEIF S_FTP_UPLOAD --> - - <h1>{L_SELECT_FTP_SETTINGS}</h1> +<!-- ELSEIF S_UPDATE_OPTIONS --> - <form id="install_update" method="post" action="{U_ACTION}"> - - <!-- IF S_CONNECTION_SUCCESS --> - <div class="successbox"> - <p>{L_CONNECTION_SUCCESS}</p> - </div> - <!-- ELSEIF S_CONNECTION_FAILED --> - <div class="successbox"> - <p>{L_TRY_DOWNLOAD_METHOD}</p> - - <fieldset class="quick"> - <input class="button1" type="submit" name="download" value="{L_TRY_DOWNLOAD_METHOD_BUTTON}" /> - </fieldset> - </div> - - <div class="errorbox"> - <p>{L_CONNECTION_FAILED}<br />{ERROR_MSG}</p> - </div> - <!-- ENDIF --> - - <fieldset> - <legend>{L_FTP_SETTINGS}</legend> - <dl> - <dt><label>{L_UPLOAD_METHOD}:</label></dt> - <dd><strong>{UPLOAD_METHOD}</strong></dd> - </dl> - <!-- BEGIN data --> - <dl> - <dt><label for="{data.DATA}">{data.NAME}:</label><br /><span>{data.EXPLAIN}</span></dt> - <dd><input type="<!-- IF data.DATA == 'password' -->password<!-- ELSE -->text<!-- ENDIF -->" id="{data.DATA}" name="{data.DATA}" value="{data.DEFAULT}" /></dd> - </dl> - <!-- END data --> - </fieldset> - - <fieldset class="submit-buttons"> - {S_HIDDEN_FIELDS} - <input class="button2" type="submit" name="check_again" value="{L_BACK}" /> - <input class="button1" type="submit" name="test_connection" value="{L_TEST_CONNECTION}" /> - <input class="button1" type="submit" name="submit" value="{L_UPDATE_FILES}" /> - </fieldset> - - </form> +<!-- INCLUDE update_options.html --> <!-- ENDIF --> diff --git a/phpBB/adm/style/update_options.html b/phpBB/adm/style/update_options.html new file mode 100644 index 0000000000..e3ef01582c --- /dev/null +++ b/phpBB/adm/style/update_options.html @@ -0,0 +1,123 @@ + +<!-- IF S_DOWNLOAD_FILES --> + + <h1>{L_DOWNLOAD_UPDATE_METHOD}</h1> + + <p>{L_DOWNLOAD_UPDATE_METHOD_EXPLAIN}</p> + + <form id="install_update" method="post" action="{U_ACTION}"> + + <fieldset> + <legend>{L_SELECT_DOWNLOAD_FORMAT}</legend> + <dl> + <dt><label for="use_method">{L_DOWNLOAD_AS}:</label></dt> + <dd>{RADIO_BUTTONS}</dd> + </dl> + </fieldset> + + <fieldset class="submit-buttons"> + {S_HIDDEN_FIELDS}{S_FORM_TOKEN} + <!-- IF S_CHECK_AGAIN --><input type="submit" class="button2" value="{L_CHECK_FILES_AGAIN}" name="check_again" /> <!-- ENDIF --> + <input type="submit" class="button1" value="{L_DOWNLOAD}" name="download" /> + </fieldset> + + </form> + + <br /><br /> + + <p>{L_MAPPING_FILE_STRUCTURE}</p> + + <table cellspacing="1"> + <col class="row1" /><col class="row2" /><col class="row1" /> + <thead> + <tr> + <th style="width: 49%">{L_ARCHIVE_FILE}</th> + <th style="width: 2%"> </th> + <th style="width: 49%">{L_DESTINATION}</th> + </tr> + </thead> + <tbody> + <!-- BEGIN location --> + <tr> + <td>{location.SOURCE}</td> + <td><strong>»</strong></td> + <td>{location.DESTINATION}</td> + </tr> + <!-- END location --> + </tbody> + </table> + +<!-- ELSEIF S_FTP_UPLOAD --> + + <h1>{L_SELECT_FTP_SETTINGS}</h1> + + <form id="update_options" method="post" action="{U_ACTION}"> + + <!-- IF S_CONNECTION_SUCCESS --> + <div class="successbox"> + <p>{L_CONNECTION_SUCCESS}</p> + </div> + <!-- ELSEIF S_CONNECTION_FAILED --> + <div class="successbox"> + <p>{L_TRY_DOWNLOAD_METHOD}</p> + + <fieldset class="quick"> + <input class="button1" type="submit" name="download" value="{L_TRY_DOWNLOAD_METHOD_BUTTON}" /> + </fieldset> + </div> + + <div class="errorbox"> + <p>{L_CONNECTION_FAILED}<br />{ERROR_MSG}</p> + </div> + <!-- ENDIF --> + + <fieldset> + <legend>{L_FTP_SETTINGS}</legend> + <dl> + <dt><label>{L_UPLOAD_METHOD}:</label></dt> + <dd><strong>{UPLOAD_METHOD}</strong></dd> + </dl> + <!-- BEGIN data --> + <dl> + <dt><label for="{data.DATA}">{data.NAME}:</label><br /><span>{data.EXPLAIN}</span></dt> + <dd><input type="<!-- IF data.DATA == 'password' -->password<!-- ELSE -->text<!-- ENDIF -->" id="{data.DATA}" name="{data.DATA}" value="{data.DEFAULT}" /></dd> + </dl> + <!-- END data --> + </fieldset> + + <fieldset class="submit-buttons"> + {S_HIDDEN_FIELDS}{S_FORM_TOKEN} + <input class="button2" type="submit" name="check_again" value="{L_BACK}" /> + <input class="button1" type="submit" name="test_connection" value="{L_TEST_CONNECTION}" /> + <input class="button1" type="submit" name="update" value="{L_UPDATE_FILES}" /> + </fieldset> + + </form> + +<!-- ELSEIF S_UPLOAD_SUCCESS --> + + <form id="update_options" method="post" action="{U_FINAL_ACTION}"> + + <h1>{L_UPDATE_SUCCESS}</h1> + <p>{L_UPDATE_SUCCESS_EXPLAIN}</p> + + <fieldset class="submit-buttons"> + <input class="button1" type="submit" name="clean_up" value="{L_CONTINUE_UPDATE}" /> + </fieldset> + + </form> + +<!-- ELSEIF S_UPDATE_OPTIONS --> + + <form id="update_options" method="post" action="{U_INITIAL_ACTION}"> + + <p>{L_UPDATE_METHOD_EXPLAIN}</p> + + <fieldset class="submit-buttons"> + {S_HIDDEN_FIELDS}{S_FORM_TOKEN} + <input class="button1" type="submit" name="ftp_upload" value="{L_FTP_UPDATE_METHOD}" /> <input class="button1" type="submit" name="download" value="{L_DOWNLOAD_UPDATE_METHOD_BUTTON}" /> + </fieldset> + + </form> + +<!-- ENDIF -->
\ No newline at end of file diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 884c5526c4..dee0f82566 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2984,4 +2984,268 @@ function add_permission_language() return true; } +/** +* Upload files or let the user download them as appropriate +*/ +function process_transfer($module_url, $update_list, $new_location, $download_filename) +{ + // todo: add $s_hidden_fields as a parameter to this function + $s_hidden_fields = ''; + + if (request_var('download', false)) + { + $use_method = request_var('use_method', ''); + $methods = array('.tar'); + + $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); + foreach ($available_methods as $type => $module) + { + if (!@extension_loaded($module)) + { + continue; + } + + $methods[] = $type; + } + + // Let the user decide in which format he wants to have the pack + if (!$use_method) + { + $radio_buttons = ''; + foreach ($methods as $method) + { + $radio_buttons .= '<label><input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>'; + } + + phpbb::$template->assign_vars(array( + 'S_DOWNLOAD_FILES' => true, + 'U_ACTION' => append_sid($module_url), + 'RADIO_BUTTONS' => $radio_buttons, + 'S_HIDDEN_FIELDS' => $s_hidden_fields) + ); + + // To ease the update process create a file location map + $script_path = (phpbb::$config['force_server_vars']) ? ((phpbb::$config['script_path'] == '/') ? '/' : phpbb::$config['script_path'] . '/') : phpbb::$user->page['root_script_path']; + + foreach ($update_list as $status => $files) + { + if ($status == 'up_to_date' || $status == 'no_update' || $status == 'status') + { + continue; + } + + foreach ($files as $file_struct) + { + phpbb::$template->assign_block_vars('location', array( + 'SOURCE' => htmlspecialchars($file_struct['filename']), + 'DESTINATION' => $script_path . htmlspecialchars($file_struct['filename']), + )); + } + } + return 'SELECT_DOWNLOAD_FORMAT'; + } + + if (!in_array($use_method, $methods)) + { + $use_method = '.tar'; + } + + $update_mode = 'download'; + } + else + { + // Choose FTP, if not available use fsock... + $method = basename(request_var('method', '')); + $submit = phpbb_request::is_set_post('update'); + $test_ftp_connection = request_var('test_connection', ''); + + if (!$method || !class_exists($method)) + { + $method = 'ftp'; + $methods = transfer::methods(); + + if (!in_array('ftp', $methods)) + { + $method = $methods[0]; + } + } + + $test_connection = false; + if ($test_ftp_connection || $submit) + { + $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $test_connection = $transfer->open_session(); + + // Make sure that the directory is correct by checking for the existence of common.php + if ($test_connection === true) + { + // Check for common.php file + if (!$transfer->file_exists(PHPBB_ROOT_PATH, 'common.' . PHP_EXT)) + { + $test_connection = 'ERR_WRONG_PATH_TO_PHPBB'; + } + } + + $transfer->close_session(); + + // Make sure the login details are correct before continuing + if ($submit && $test_connection !== true) + { + $submit = false; + $test_ftp_connection = true; + } + } + + $s_hidden_fields .= build_hidden_fields(array('method' => $method)); + + if (!$submit) + { + if (!class_exists($method)) + { + trigger_error('Method does not exist.', E_USER_ERROR); + } + + $requested_data = call_user_func(array($method, 'data')); + foreach ($requested_data as $data => $default) + { + phpbb::$template->assign_block_vars('data', array( + 'DATA' => $data, + 'NAME' => phpbb::$user->lang[strtoupper($method . '_' . $data)], + 'EXPLAIN' => phpbb::$user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], + 'DEFAULT' => (request_var($data, false)) ? request_var($data, '') : $default + )); + } + + phpbb::$template->assign_vars(array( + 'S_CONNECTION_SUCCESS' => ($test_ftp_connection && $test_connection === true) ? true : false, + 'S_CONNECTION_FAILED' => ($test_ftp_connection && $test_connection !== true) ? true : false, + 'ERROR_MSG' => ($test_ftp_connection && $test_connection !== true) ? phpbb::$user->lang[$test_connection] : '', + + 'S_FTP_UPLOAD' => true, + 'UPLOAD_METHOD' => $method, + 'U_ACTION' => $module_url, + 'U_DOWNLOAD_METHOD' => $module_url . '&download=1', + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + )); + + return 'SELECT_FTP_SETTINGS'; + } + + $update_mode = 'upload'; + } + + // Now init the connection + if ($update_mode == 'download') + { + // Now update the installation or download the archive... + $archive_filename = $download_filename . '_' . time() . '_' . unique_id(); + + if ($use_method == '.zip') + { + $compress = new compress_zip('w', PHPBB_ROOT_PATH . 'store/' . $archive_filename . $use_method); + } + else + { + $compress = new compress_tar('w', PHPBB_ROOT_PATH . 'store/' . $archive_filename . $use_method, $use_method); + } + } + else + { + $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer->open_session(); + } + + // Ok, go through the update list and do the operations based on their status + foreach ($update_list as $status => $files) + { + if (!is_array($files)) + { + continue; + } + + foreach ($files as $file_struct) + { + $original_filename = ($file_struct['custom']) ? $file_struct['original'] : $file_struct['filename']; + + switch ($status) + { + case 'new': + case 'new_conflict': + case 'not_modified': + + if ($update_mode == 'download') + { + $compress->add_custom_file($new_location . $original_filename, $file_struct['filename']); + } + else + { + if ($status != 'new') + { + $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); + } + + // New directory too? + $dirname = dirname($file_struct['filename']); + + if ($dirname && !file_exists(PHPBB_ROOT_PATH . $dirname)) + { + $transfer->make_dir($dirname); + } + + $transfer->copy_file($new_location . $original_filename, $file_struct['filename']); + } + break; + + case 'modified': + + $contents = base64_decode($cache->get($file_list[$file_struct['filename']])); + + if ($update_mode == 'download') + { + $compress->add_data($contents, $file_struct['filename']); + } + else + { + // @todo add option to specify if a backup file should be created? + $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); + $transfer->write_file($file_struct['filename'], $contents); + } + break; + + case 'conflict': + + $contents = base64_decode($cache->get($file_list[$file_struct['filename']])); + + if ($update_mode == 'download') + { + $compress->add_data($contents, $file_struct['filename']); + } + else + { + $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); + $transfer->write_file($file_struct['filename'], $contents); + } + break; + } + } + } + + if ($update_mode == 'download') + { + $compress->close(); + + $compress->download($archive_filename, $download_filename); + @unlink(PHPBB_ROOT_PATH . 'store/' . $archive_filename . $use_method); + + exit; + } + else + { + $transfer->close_session(); + + phpbb::$template->assign_var('S_UPLOAD_SUCCESS', true); + return; + } +} + ?>
\ No newline at end of file diff --git a/phpBB/includes/functions_transfer.php b/phpBB/includes/functions_transfer.php index a276bd304a..351f9517c5 100644 --- a/phpBB/includes/functions_transfer.php +++ b/phpBB/includes/functions_transfer.php @@ -16,7 +16,7 @@ if (!defined('IN_PHPBB')) exit; } -require_once PHPBB_ROOT_PATH . 'includes/sftp/sftp.' . PHP_EXT; +require_once PHPBB_ROOT_PATH . 'includes/libraries/sftp/sftp.' . PHP_EXT; /** * Transfer class, wrapper for ftp/sftp/ssh @@ -192,7 +192,7 @@ class transfer $directory = $this->root_path . str_replace(PHPBB_ROOT_PATH, '', $directory); $this->_chdir($directory); - $result = $this->_ls(); + $result = $this->_ls(''); if ($result !== false && is_array($result)) { @@ -455,7 +455,7 @@ class ftp extends transfer $item = str_replace('\\', '/', $item); $dir = str_replace('\\', '/', $dir); - if (strpos($item, $dir) === 0) + if (!empty($dir) && strpos($item, $dir) === 0) { $item = substr($item, strlen($dir)); } diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 383a4d8cca..1cc38c5a94 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -182,7 +182,7 @@ class install_update extends module $this->include_file('includes/diff/renderer.' . PHP_EXT); // Make sure we stay at the file check if checking the files again - if (phpbb_request::variable('check_again', false, false, phpbb_request::POST)) + if (phpbb_request::variable('clean_up', false, false, phpbb_request::POST)) { $sub = $this->p_master->sub = 'file_check'; } @@ -271,7 +271,7 @@ class install_update extends module $action = request_var('action', ''); // We are directly within an update. To make sure our update list is correct we check its status. - $update_list = (phpbb_request::variable('check_again', false, false, phpbb_request::POST)) ? false : phpbb::$acm->get('update_list'); + $update_list = (phpbb_request::variable('clean_up', false, false, phpbb_request::POST)) ? false : phpbb::$acm->get('update_list'); $modified = ($update_list !== false) ? phpbb::$acm->get_modified_date('data', 'update_list') : 0; // Make sure the list is up-to-date @@ -721,284 +721,43 @@ class install_update extends module $file_list['status'] = -1; phpbb::$acm->put('diff_files', $file_list); - if (request_var('download', false)) - { - $this->include_file('includes/functions_compress.' . PHP_EXT); - - $use_method = request_var('use_method', ''); - $methods = array('.tar'); - - $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); - foreach ($available_methods as $type => $module) - { - if (!@extension_loaded($module)) - { - continue; - } - - $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) - { - $radio_buttons .= '<label><input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>'; - } - - phpbb::$template->assign_vars(array( - 'S_DOWNLOAD_FILES' => true, - 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), - 'RADIO_BUTTONS' => $radio_buttons, - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); + $this->include_file('includes/functions_compress.' . $phpEx); + $this->include_file('includes/functions_transfer.' . $phpEx); - // To ease the update process create a file location map - $update_list = phpbb::$acm->get('update_list'); - $script_path = (phpbb::$config['force_server_vars']) ? ((phpbb::$config['script_path'] == '/') ? '/' : phpbb::$config['script_path'] . '/') : phpbb::$user->page['root_script_path']; - - foreach ($update_list as $status => $files) - { - if ($status == 'up_to_date' || $status == 'no_update' || $status == 'status') - { - continue; - } - - foreach ($files as $file_struct) - { - if (in_array($file_struct['filename'], $no_update)) - { - continue; - } - - phpbb::$template->assign_block_vars('location', array( - 'SOURCE' => htmlspecialchars($file_struct['filename']), - 'DESTINATION' => $script_path . htmlspecialchars($file_struct['filename']), - )); - } - } - return; - } - - if (!in_array($use_method, $methods)) - { - $use_method = '.tar'; - } - - $update_mode = 'download'; - } - else - { - $this->include_file('includes/functions_transfer.' . PHP_EXT); - - // Choose FTP, if not available use fsock... - $method = basename(request_var('method', '')); - $submit = phpbb_request::is_set_post('submit'); - $test_ftp_connection = request_var('test_connection', ''); - - if (!$method || !class_exists($method)) - { - $method = 'ftp'; - $methods = transfer::methods(); - - if (!in_array('ftp', $methods)) - { - $method = $methods[0]; - } - } - - $test_connection = false; - if ($test_ftp_connection || $submit) - { - $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); - $test_connection = $transfer->open_session(); - - // Make sure that the directory is correct by checking for the existence of common.php - if ($test_connection === true) - { - // Check for common.php file - if (!$transfer->file_exists(PHPBB_ROOT_PATH, 'common.' . PHP_EXT)) - { - $test_connection = 'ERR_WRONG_PATH_TO_PHPBB'; - } - } - - $transfer->close_session(); - - // Make sure the login details are correct before continuing - if ($submit && $test_connection !== true) - { - $submit = false; - $test_ftp_connection = true; - } - } - - $s_hidden_fields .= build_hidden_fields(array('method' => $method)); - - if (!$submit) - { - $this->page_title = 'SELECT_FTP_SETTINGS'; - - if (!class_exists($method)) - { - trigger_error('Method does not exist.', E_USER_ERROR); - } - - $requested_data = call_user_func(array($method, 'data')); - foreach ($requested_data as $data => $default) - { - phpbb::$template->assign_block_vars('data', array( - 'DATA' => $data, - 'NAME' => phpbb::$user->lang[strtoupper($method . '_' . $data)], - 'EXPLAIN' => phpbb::$user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], - 'DEFAULT' => (request_var($data, false)) ? request_var($data, '') : $default - )); - } - - phpbb::$template->assign_vars(array( - 'S_CONNECTION_SUCCESS' => ($test_ftp_connection && $test_connection === true) ? true : false, - 'S_CONNECTION_FAILED' => ($test_ftp_connection && $test_connection !== true) ? true : false, - 'ERROR_MSG' => ($test_ftp_connection && $test_connection !== true) ? phpbb::$user->lang[$test_connection] : '', - - 'S_FTP_UPLOAD' => true, - 'UPLOAD_METHOD' => $method, - 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), - 'U_DOWNLOAD_METHOD' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files&download=1"), - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); - - return; - } - - $update_mode = 'upload'; - } - - // Now update the installation or download the archive... - $download_filename = 'update_' . $this->update_info['version']['from'] . '_to_' . $this->update_info['version']['to']; - $archive_filename = $download_filename . '_' . time() . '_' . unique_id(); - - // Now init the connection - if ($update_mode == 'download') - { - if ($use_method == '.zip') - { - $compress = new compress_zip('w', PHPBB_ROOT_PATH . 'store/' . $archive_filename . $use_method); - } - else - { - $compress = new compress_tar('w', PHPBB_ROOT_PATH . 'store/' . $archive_filename . $use_method, $use_method); - } - } - else - { - $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); - $transfer->open_session(); - } - - // Ok, go through the update list and do the operations based on their status - foreach ($update_list as $status => $files) + $module_url = append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"); + foreach ($update_list as &$files) { if (!is_array($files)) { continue; } - - foreach ($files as $file_struct) + for ($i = 0, $size = sizeof($files); $i < $size; $i++) { // Skip this file if the user selected to not update it - if (in_array($file_struct['filename'], $no_update)) - { - continue; - } - - $original_filename = ($file_struct['custom']) ? $file_struct['original'] : $file_struct['filename']; - - switch ($status) + if (in_array($files[$i]['filename'], $no_update)) { - case 'new': - case 'new_conflict': - case 'not_modified': - - if ($update_mode == 'download') - { - $compress->add_custom_file($this->new_location . $original_filename, $file_struct['filename']); - } - else - { - if ($status != 'new') - { - $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); - } - - // New directory too? - $dirname = dirname($file_struct['filename']); - - if ($dirname && !file_exists(PHPBB_ROOT_PATH . $dirname)) - { - $transfer->make_dir($dirname); - } - - $transfer->copy_file($this->new_location . $original_filename, $file_struct['filename']); - } - break; - - case 'modified': - - $contents = base64_decode(phpbb::$acm->get($file_list[$file_struct['filename']])); - - if ($update_mode == 'download') - { - $compress->add_data($contents, $file_struct['filename']); - } - else - { - // @todo add option to specify if a backup file should be created? - $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); - $transfer->write_file($file_struct['filename'], $contents); - } - break; - - case 'conflict': - - $contents = base64_decode(phpbb::$acm->get($file_list[$file_struct['filename']])); - - if ($update_mode == 'download') - { - $compress->add_data($contents, $file_struct['filename']); - } - else - { - $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); - $transfer->write_file($file_struct['filename'], $contents); - } - break; + unset($files[$i]['filename']); } } + $files = array_values($files); } + unset($files); + $new_location = $this->new_location; + $download_filename = 'update_' . $this->update_info['version']['from'] . '_to_' . $this->update_info['version']['to']; + $check_params = "mode=$mode&sub=file_check"; - if ($update_mode == 'download') + $temp = process_transfer($module_url, $update_list, $new_location, $download_filename); + if (is_string($temp)) { - $compress->close(); - - $compress->download($archive_filename, $download_filename); - @unlink(PHPBB_ROOT_PATH . 'store/' . $archive_filename . $use_method); - - exit; + $this->page_title = $temp; } - else - { - $transfer->close_session(); - phpbb::$template->assign_vars(array( - 'S_UPLOAD_SUCCESS' => true, - 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"), - )); - return; - } + phpbb::$template->assign_vars(array( + 'S_UPDATE_OPTIONS' => true, + 'S_CHECK_AGAIN' => true, + // 'U_INITIAL_ACTION' isn't set because it's taken care of in the S_FILE_CHECK block of install_update.html + 'U_FINAL_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files")) + ); break; diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index ec9faad8c1..657df9301b 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -131,6 +131,7 @@ $lang = array_merge($lang, array( 'CONGRATULATIONS' => 'Congratulations to', 'CONNECTION_FAILED' => 'Connection failed.', 'CONNECTION_SUCCESS' => 'Connection was successful!', + 'CONTINUE_UPDATE' => 'Back', 'COOKIES_DELETED' => 'All board cookies successfully deleted.', 'CURRENT_TIME' => 'It is currently %s', @@ -162,6 +163,10 @@ $lang = array_merge($lang, array( 2 => 'Viewed %d times', ), + 'DOWNLOAD_UPDATE_METHOD' => 'Download modified files archive', + 'DOWNLOAD_UPDATE_METHOD_BUTTON' => 'Download modified files archive (recommended)', + 'DOWNLOAD_UPDATE_METHOD_EXPLAIN' => 'Once downloaded you should unpack the archive. You will find the modified files you need to upload to your phpBB root directory within it. Please upload the files to their respective locations then. After you have uploaded all files, please check the files again with the other button below.', + 'EDIT_POST' => 'Edit post', 'EMAIL' => 'E-mail', // Short form for EMAIL_ADDRESS 'EMAIL_ADDRESS' => 'E-mail address', @@ -206,6 +211,9 @@ $lang = array_merge($lang, array( 'FROM' => 'from', 'FSOCK_DISABLED' => 'The operation could not be completed because the <var>fsockopen</var> function has been disabled or the server being queried could not be found.', + 'FTP_SETTINGS' => 'FTP settings', + 'FTP_UPDATE_METHOD' => 'FTP upload', + 'FTP_FSOCK_HOST' => 'FTP host', 'FTP_FSOCK_HOST_EXPLAIN' => 'FTP server used to connect your site.', 'FTP_FSOCK_PASSWORD' => 'FTP password', @@ -338,6 +346,7 @@ $lang = array_merge($lang, array( 'LOGOUT_USER' => 'Logout [ %s ]', 'LOG_ME_IN' => 'Log me on automatically each visit', + 'MAPPING_FILE_STRUCTURE' => 'To ease the upload here are the file locations which map your phpBB installation.', 'MARK' => 'Mark', 'MARK_ALL' => 'Mark all', 'MARK_FORUMS_READ' => 'Mark forums read', @@ -550,10 +559,12 @@ $lang = array_merge($lang, array( 'SELECT_ALL_CODE' => 'Select all', 'SELECT_DESTINATION_FORUM' => 'Please select a destination forum', 'SELECT_FORUM' => 'Select a forum', + 'SELECT_FTP_SETTINGS' => 'Select FTP settings', 'SEND_EMAIL' => 'E-mail', // Used for submit buttons 'SEND_EMAIL_USER' => 'E-mail', // Used as: {L_SEND_EMAIL_USER} {USERNAME} -> E-mail UserX 'SEND_PRIVATE_MESSAGE' => 'Send private message', 'SETTINGS' => 'Settings', + 'SIGNATURE' => 'Signature', 'SKIP' => 'Skip to content', 'SMTP_NO_AUTH_SUPPORT' => 'SMTP server does not support authentication.', @@ -655,6 +666,9 @@ $lang = array_merge($lang, array( ), 'TRACKED_PHP_ERROR' => 'Tracked PHP errors: %s', + 'TRY_DOWNLOAD_METHOD' => 'You may want to try the download modified files method.<br />This method always works and is also the recommended update path.', + 'TRY_DOWNLOAD_METHOD_BUTTON'=> 'Try this method now', + 'UNABLE_GET_IMAGE_SIZE' => 'It was not possible to determine the dimensions of the image.', 'UNABLE_TO_DELIVER_FILE'=> 'Unable to deliver file.', 'UNKNOWN_BROWSER' => 'Unknown browser', @@ -669,7 +683,11 @@ $lang = array_merge($lang, array( 'UNWATCHED_TOPICS' => 'You are no longer subscribed to the selected topics.', 'UNWATCHED_FORUMS_TOPICS' => 'You are no longer subscribed to the selected entries.', 'UPDATE' => 'Update', + 'UPDATE_FILES' => 'Update files', + 'UPDATE_METHOD_EXPLAIN' => 'You are now able to choose your preferred update method. Using the FTP upload will present you with a form you need to enter your FTP account details into. With this method the files will be automatically moved to the new location and backups of the old files being created by appending .bak to the filename. If you choose to download the modified files you are able to unpack and upload them to their correct location manually later.', 'UPLOAD_IN_PROGRESS' => 'The upload is currently in progress.', + 'UPDATE_SUCCESS' => 'Update was successful', + 'UPDATE_SUCCESS_EXPLAIN' => 'Successfully updated all files. You should now check to see if everything is working fine.', 'URL_REDIRECT' => 'If your browser does not support meta redirection %splease click HERE to be redirected%s.', 'USERGROUPS' => 'Groups', 'USERNAME' => 'Username', diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php index 087149e5aa..9feed02da6 100644 --- a/phpBB/language/en/install.php +++ b/phpBB/language/en/install.php @@ -384,7 +384,6 @@ $lang = array_merge($lang, array( 'CHANGE_CLEAN_NAMES' => 'The method used to make sure a username is not used by multiple users has been changed. There are some users which have the same name when compared with the new method. You have to delete or rename these users to make sure that each name is only used by one user before you can proceed.', 'CHECK_FILES' => 'Check files', - 'CHECK_FILES_AGAIN' => 'Check files again', 'CHECK_FILES_EXPLAIN' => 'Within the next step all files will be checked against the update files - this can take a while if this is the first file check.', 'CHECK_FILES_UP_TO_DATE' => 'According to your database your version is up to date. You may want to proceed with the file check to make sure all files are really up to date with the latest phpBB version.', 'CHECK_UPDATE_DATABASE' => 'Continue update process', @@ -392,6 +391,7 @@ $lang = array_merge($lang, array( 'COLLECTED_INFORMATION_EXPLAIN' => 'The list below shows information about the files needing an update. Please read the information in front of every status block to see what they mean and what you may need to do to perform a successful update.', 'COLLECTING_FILE_DIFFS' => 'Collecting file differences', 'COMPLETE_LOGIN_TO_BOARD' => 'You should now <a href="../ucp.php?mode=login">login to your board</a> and check if everything is working fine. Do not forget to delete, rename or move your install directory!', + 'CONTINUE_UPDATE' => 'Check files again', 'CONTINUE_UPDATE_NOW' => 'Continue the update process now', 'CURRENT_FILE' => 'Begin of Conflict - Original File code before update', 'CURRENT_VERSION' => 'Current version', @@ -410,11 +410,8 @@ $lang = array_merge($lang, array( 'DONE' => 'Done', 'DOWNLOAD' => 'Download', 'DOWNLOAD_AS' => 'Download as', - 'DOWNLOAD_UPDATE_METHOD_BUTTON' => 'Download modified files archive (recommended)', 'DOWNLOAD_CONFLICTS' => 'Download conflicts for this file', 'DOWNLOAD_CONFLICTS_EXPLAIN' => 'Search for <<< to spot conflicts', - 'DOWNLOAD_UPDATE_METHOD' => 'Download modified files archive', - 'DOWNLOAD_UPDATE_METHOD_EXPLAIN' => 'Once downloaded you should unpack the archive. You will find the modified files you need to upload to your phpBB root directory within it. Please upload the files to their respective locations then. After you have uploaded all files, please check the files again with the other button below.', 'ERROR' => 'Error', 'EDIT_USERNAME' => 'Edit username', @@ -434,8 +431,6 @@ $lang = array_merge($lang, array( 'FILES_NOT_MODIFIED_EXPLAIN' => 'The following files are not modified and represent the original phpBB files from the version you want to update from.', 'FILES_UP_TO_DATE' => 'Already updated files', 'FILES_UP_TO_DATE_EXPLAIN' => 'The following files are already up to date and do not need to be updated.', - 'FTP_SETTINGS' => 'FTP settings', - 'FTP_UPDATE_METHOD' => 'FTP upload', 'INCOMPATIBLE_UPDATE_FILES' => 'The update files found are incompatible with your installed version. Your installed version is %1$s and the update file is for updating phpBB %2$s to %3$s.', 'INCOMPLETE_UPDATE_FILES' => 'The update files are incomplete.', @@ -451,8 +446,6 @@ $lang = array_merge($lang, array( 'LINE_UNMODIFIED' => 'Unmodified', 'LOGIN_UPDATE_EXPLAIN' => 'In order to update your installation you need to login first.', - 'MAPPING_FILE_STRUCTURE' => 'To ease the upload here are the file locations which map your phpBB installation.', - 'MERGE_MODIFICATIONS_OPTION' => 'Merge modifications', 'MERGE_NO_MERGE_NEW_OPTION' => 'Do not merge - use new file', @@ -491,7 +484,6 @@ $lang = array_merge($lang, array( 'SELECT_DIFF_MODE' => 'Select diff mode', 'SELECT_DOWNLOAD_FORMAT' => 'Select download archive format', - 'SELECT_FTP_SETTINGS' => 'Select FTP settings', 'SHOW_DIFF_CONFLICT' => 'Show differences/conflicts', 'SHOW_DIFF_FINAL' => 'Show resulting file', 'SHOW_DIFF_MODIFIED' => 'Show merged differences', @@ -513,14 +505,11 @@ $lang = array_merge($lang, array( 'STATUS_UP_TO_DATE' => 'Already updated file', 'TOGGLE_DISPLAY' => 'View/Hide file list', - 'TRY_DOWNLOAD_METHOD' => 'You may want to try the download modified files method.<br />This method always works and is also the recommended update path.', - 'TRY_DOWNLOAD_METHOD_BUTTON'=> 'Try this method now', 'UPDATE_COMPLETED' => 'Update completed', 'UPDATE_DATABASE' => 'Update database', 'UPDATE_DATABASE_EXPLAIN' => 'Within the next step the database will be updated.', 'UPDATE_DATABASE_SCHEMA' => 'Updating database schema', - 'UPDATE_FILES' => 'Update files', 'UPDATE_FILES_NOTICE' => 'Please make sure you have updated your board files too, this file is only updating your database.', 'UPDATE_INSTALLATION' => 'Update phpBB installation', 'UPDATE_INSTALLATION_EXPLAIN' => 'With this option, it is possible to update your phpBB installation to the latest version.<br />During the process all of your files will be checked for their integrity. You are able to review all differences and files before the update.<br /><br />The file update itself can be done in two different ways.</p><h2>Manual Update</h2><p>With this update you only download your personal set of changed files to make sure you do not lose your file modifications you may have done. After you downloaded this package you need to manually upload the files to their correct position under your phpBB root directory. Once done, you are able to do the file check stage again to see if you moved the files to their correct location.</p><h2>Automatic Update with FTP</h2><p>This method is similar to the first one but without the need to download the changed files and uploading them on your own. This will be done for you. In order to use this method you need to know your FTP login details since you will be asked for them. Once finished you will be redirected to the file check again to make sure everything got updated correctly.<br /><br />', @@ -555,9 +544,7 @@ $lang = array_merge($lang, array( <p>phpBB detected an incomplete automatic update. Please make sure you followed every step within the automatic update tool. Below you will find the link again, or go directly to your install directory.</p> ', 'UPDATE_METHOD' => 'Update method', - 'UPDATE_METHOD_EXPLAIN' => 'You are now able to choose your preferred update method. Using the FTP upload will present you with a form you need to enter your FTP account details into. With this method the files will be automatically moved to the new location and backups of the old files being created by appending .bak to the filename. If you choose to download the modified files you are able to unpack and upload them to their correct location manually later.', 'UPDATE_REQUIRES_FILE' => 'The updater requires that the following file is present: %s', - 'UPDATE_SUCCESS' => 'Update was successful', 'UPDATE_SUCCESS_EXPLAIN' => 'Successfully updated all files. The next step involves checking all files again to make sure the files got updated correctly.', 'UPDATE_VERSION_OPTIMIZE' => 'Updating version and optimising tables', 'UPDATING_DATA' => 'Updating data', diff --git a/phpBB/modules/acp/acp_language.php b/phpBB/modules/acp/acp_language.php index 3b1269c837..6359bdf099 100644 --- a/phpBB/modules/acp/acp_language.php +++ b/phpBB/modules/acp/acp_language.php @@ -47,11 +47,10 @@ class acp_language // Check and set some common vars $action = (phpbb_request::is_set_post('update_details')) ? 'update_details' : ''; - $action = (phpbb_request::is_set_post('download_file')) ? 'download_file' : $action; - $action = (phpbb_request::is_set_post('upload_file')) ? 'upload_file' : $action; - $action = (phpbb_request::is_set_post('upload_data')) ? 'upload_data' : $action; $action = (phpbb_request::is_set_post('submit_file')) ? 'submit_file' : $action; $action = (phpbb_request::is_set_post('remove_store')) ? 'details' : $action; + $action = (phpbb_request::is_set_post('ftp_upload')) ? 'ftp_upload' : $action; + $action = (phpbb_request::is_set_post('download')) ? 'download' : $action; $submit = (empty($action) && !phpbb_request::is_set_post('update') && !phpbb_request::is_set_post('test_connection')) ? false : true; $action = (empty($action)) ? request_var('action', '') : $action; @@ -80,87 +79,8 @@ class acp_language $this->tpl_name = 'acp_language'; $this->page_title = 'ACP_LANGUAGE_PACKS'; - if ($submit && $action == 'upload_data' && request_var('test_connection', '')) - { - $test_connection = false; - $action = 'upload_file'; - $method = request_var('method', ''); - - include_once(PHPBB_ROOT_PATH . 'includes/functions_transfer.' . PHP_EXT); - - 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; - - 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; - - case 'sftp': - $transfer = new sftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); - break; - - default: - trigger_error(phpbb::$user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR); - break; - } - - $test_connection = $transfer->open_session(); - $transfer->close_session(); - } - switch ($action) { - case 'upload_file': - - include_once(PHPBB_ROOT_PATH . 'includes/functions_transfer.' . PHP_EXT); - - $method = request_var('method', ''); - - if (!class_exists($method)) - { - trigger_error('Method does not exist.', E_USER_ERROR); - } - - $requested_data = call_user_func(array($method, 'data')); - foreach ($requested_data as $data => $default) - { - $default_value = request_var($data, ''); - phpbb::$template->assign_block_vars('data', array( - 'DATA' => $data, - 'NAME' => phpbb::$user->lang[strtoupper($method . '_' . $data)], - 'EXPLAIN' => phpbb::$user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], - 'DEFAULT' => (empty($default_value)) ? $default : $default_value, - )); - } - - $hidden_data = build_hidden_fields(array( - 'file' => $this->language_file, - 'dir' => $this->language_directory, - 'language_file' => $selected_lang_file, - 'method' => $method) - ); - - /** - * @todo Do not use $_POST here, but phpbb_request::variable which needs to support more dimensions - */ - $hidden_data .= build_hidden_fields(array('entry' => $_POST['entry']), true, STRIP); - - phpbb::$template->assign_vars(array( - 'S_UPLOAD' => true, - 'NAME' => $method, - 'U_ACTION' => $this->u_action . "&id=$lang_id&action=upload_data", - 'U_BACK' => $this->u_action . "&id=$lang_id&action=details&language_file=" . urlencode($selected_lang_file), - 'HIDDEN' => $hidden_data, - - 'S_CONNECTION_SUCCESS' => (request_var('test_connection', '') && $test_connection === true) ? true : false, - 'S_CONNECTION_FAILED' => (request_var('test_connection', '') && $test_connection !== true) ? true : false, - 'ERROR_MSG' => (request_var('test_connection', '') && $test_connection !== true) ? phpbb::$user->lang[$test_connection] : '', - )); - break; - case 'update_details': if (!$submit || !check_form_key($form_name)) @@ -195,9 +115,8 @@ class acp_language trigger_error(phpbb::$user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action)); break; - case 'submit_file': - case 'download_file': - case 'upload_data': + case 'ftp_upload': + case 'download': if (!$submit || !check_form_key($form_name)) { @@ -231,218 +150,200 @@ class acp_language trigger_error(phpbb::$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) + if (!request_var('test_connection', false)) { - 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(phpbb::$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', PHP_EXT); - $acp_files = $acp_files['acp/']; + // 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, $acp_files)) - { - trigger_error(phpbb::$user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); - } - break; + if (!in_array($this->language_file, $email_files)) + { + trigger_error(phpbb::$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', PHP_EXT); - $mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array(); + case 'acp': + // Get acp files + $acp_files = filelist(PHPBB_ROOT_PATH . 'language/' . $row['lang_iso'], 'acp', PHP_EXT); + $acp_files = $acp_files['acp/']; - if (!in_array($this->language_file, $mods_files)) - { - trigger_error(phpbb::$user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); - } - break; + if (!in_array($this->language_file, $acp_files)) + { + trigger_error(phpbb::$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(phpbb::$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', PHP_EXT); + $mods_files = (isset($mods_files['mods/'])) ? $mods_files['mods/'] : array(); - if (!$safe_mode) - { - $mkdir_ary = array('language', 'language/' . $row['lang_iso']); + if (!in_array($this->language_file, $mods_files)) + { + trigger_error(phpbb::$user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); + } + break; - if ($this->language_directory) - { - $mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory; + default: + if (!in_array($this->language_file, $this->main_files)) + { + trigger_error(phpbb::$user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); + } + break; } - foreach ($mkdir_ary as $dir) + if (!$safe_mode) { - $dir = PHPBB_ROOT_PATH . 'store/' . $dir; + $mkdir_ary = array('language', 'language/' . $row['lang_iso']); - if (!is_dir($dir)) + if ($this->language_directory) { - if (!@mkdir($dir, 0777)) + $mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory; + } + + foreach ($mkdir_ary as $dir) + { + $dir = PHPBB_ROOT_PATH . 'store/' . $dir; + + if (!is_dir($dir)) { - trigger_error("Could not create directory $dir", E_USER_ERROR); + if (!@mkdir($dir, 0777)) + { + trigger_error("Could not create directory $dir", E_USER_ERROR); + } + phpbb::$system->chmod($dir, phpbb::CHMOD_READ | phpbb::CHMOD_WRITE); } - phpbb::$system->chmod($dir, phpbb::CHMOD_READ | phpbb::CHMOD_WRITE); } } - } - // Get target filename for storage folder - $filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true); - $fp = @fopen(PHPBB_ROOT_PATH . $filename, 'wb'); + // Get target filename for storage folder + $filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true); + $fp = @fopen(PHPBB_ROOT_PATH . $filename, 'wb'); - if (!$fp) - { - trigger_error(sprintf(phpbb::$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); - } - - if ($this->language_directory == 'email') - { - // Email Template - $entry = $this->prepare_lang_entry($_POST['entry'], false); - fwrite($fp, $entry); - } - 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 (!$fp) + { + trigger_error(sprintf(phpbb::$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); + } - if (strpos($this->language_file, 'help_') === 0) + if ($this->language_directory == 'email') { - // Help File - $header .= '$help = array(' . "\n"; - fwrite($fp, $header); + // Email Template + $entry = $this->prepare_lang_entry($_POST['entry'], false); + fwrite($fp, $entry); + } + 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); - foreach ($_POST['entry'] as $key => $value) + if (strpos($this->language_file, 'help_') === 0) { - if (!is_array($value)) + // Help File + $header .= '$help = array(' . "\n"; + fwrite($fp, $header); + + foreach ($_POST['entry'] as $key => $value) { - continue; - } + if (!is_array($value)) + { + continue; + } - $entry = "\tarray(\n"; + $entry = "\tarray(\n"; - foreach ($value as $_key => $_value) - { - $entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n"; + foreach ($value as $_key => $_value) + { + $entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n"; + } + + $entry .= "\t),\n"; + fwrite($fp, $entry); } - $entry .= "\t),\n"; - fwrite($fp, $entry); + $footer = ");\n\n?>"; + fwrite($fp, $footer); } + else + { + // Language File + $header .= $this->lang_header; + fwrite($fp, $header); - $footer = ");\n\n?>"; - fwrite($fp, $footer); - } - else - { - // Language File - $header .= $this->lang_header; - fwrite($fp, $header); + foreach ($_POST['entry'] as $key => $value) + { + $entry = $this->format_lang_array($key, $value); + fwrite($fp, $entry); + } - foreach ($_POST['entry'] as $key => $value) - { - $entry = $this->format_lang_array($key, $value); - fwrite($fp, $entry); + $footer = "));\n\n?>"; + fwrite($fp, $footer); } - - $footer = "));\n\n?>"; - fwrite($fp, $footer); } - } - - 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); - $fp = @fopen(PHPBB_ROOT_PATH . $filename, 'rb'); - while ($buffer = fread($fp, 1024)) - { - echo $buffer; - } fclose($fp); - - add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file); - - exit; } - else if ($action == 'upload_data') - { - $sql = 'SELECT lang_iso - FROM ' . LANG_TABLE . " - WHERE lang_id = $lang_id"; - $result = phpbb::$db->sql_query($sql); - $row = phpbb::$db->sql_fetchrow($result); - phpbb::$db->sql_freeresult($result); - $file = request_var('file', ''); - $dir = request_var('dir', ''); + include_once(PHPBB_ROOT_PATH . 'includes/functions_compress.' . PHP_EXT); + include_once(PHPBB_ROOT_PATH . 'includes/functions_transfer.' . PHP_EXT); + + $file = request_var('file', ''); + $dir = request_var('dir', ''); + $lang_path = 'language/' . $row['lang_iso'] . '/' . (($dir) ? $dir . '/' : ''); - $selected_lang_file = $dir . '|' . $file; + $module_url = $this->u_action . "&action=ftp_upload&id=$lang_id"; + $update_list = array('not_modified' => array(array('filename' => $lang_path . $file, 'custom' => false))); + $new_location = PHPBB_ROOT_PATH . 'store/'; + $download_filename = $this->language_file; - $old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true); - $lang_path = 'language/' . $row['lang_iso'] . '/' . (($dir) ? $dir . '/' : ''); + process_transfer($module_url, $update_list, $new_location, $download_filename); - include_once(PHPBB_ROOT_PATH . 'includes/functions_transfer.' . PHP_EXT); - $method = request_var('method', ''); + // bug: if you're downloading the file, the following code will never be called as process_transfer() will exit before it has a chance to be called - if ($method != 'ftp' && $method != 'ftp_fsock' && $method != 'sftp') + if (!request_var('test_connection', false)) + { + // Remove from storage folder + if (file_exists(PHPBB_ROOT_PATH . 'store/' . $lang_path . $file)) { - trigger_error(phpbb::$user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR); + @unlink(PHPBB_ROOT_PATH . 'store/' . $lang_path . $file); } - $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); - - if (($result = $transfer->open_session()) !== true) + if ($action == 'ftp_upload') { - trigger_error(phpbb::$user->lang[$result] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file)), E_USER_WARNING); + add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file); } - $transfer->rename($lang_path . $file, $lang_path . $file . '.bak'); - $result = $transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file); - - if ($result === false) - { - // If failed, try to rename again and print error out... - $transfer->delete_file($lang_path . $file); - $transfer->rename($lang_path . $file . '.bak', $lang_path . $file); + add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file); + } - trigger_error(phpbb::$user->lang['UPLOAD_FAILED'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file)), E_USER_WARNING); - } + // no break; - $transfer->close_session(); + case 'submit_file': - // Remove from storage folder - if (file_exists(PHPBB_ROOT_PATH . 'store/' . $lang_path . $file)) - { - @unlink(PHPBB_ROOT_PATH . 'store/' . $lang_path . $file); - } + $s_hidden_fields = build_hidden_fields(array( + 'file' => $this->language_file, + 'dir' => $this->language_directory, + 'language_file' => $selected_lang_file) + ); - add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file); + /** + * @todo Do not use $_POST here, but phpbb_request::variable which needs to support more dimensions + */ + $s_hidden_fields .= build_hidden_fields(array('entry' => $_POST['entry']), true, STRIP); - trigger_error(phpbb::$user->lang['UPLOAD_COMPLETED'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file))); - } + $module_url = $this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file); - add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file); - $action = 'details'; + phpbb::$template->assign_vars(array( + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_UPDATE_OPTIONS' => true, + 'U_INITIAL_ACTION' => $module_url, + 'U_FINAL_ACTION' => $module_url) + ); - // no break; + break; case 'details': |