/**
* Gets FTP information if we need it
*
* @param	$preview	bool	true if in pre_(install|uninstall), false otherwise
* @return				array	and array of connection info (currently only ftp)
*/
function get_connection_info($preview = false)
{
    global $config, $ftp_method, $test_ftp_connection, $test_connection;
    $conn_info_ary = array();
    // using $config instead of $editor because write_method is forced to direct
    // when in preview mode
    if ($config['write_method'] == WRITE_FTP) {
        if (!$preview && isset($_POST['password'])) {
            $conn_info_ary['method'] = $config['ftp_method'];
            if (empty($config['ftp_method'])) {
                trigger_error('FTP_METHOD_ERROR');
            }
            $requested_data = call_user_func(array($config['ftp_method'], 'data'));
            foreach ($requested_data as $data => $default) {
                if ($data == 'password') {
                    $config['ftp_password'] = request_var('password', '');
                }
                $default = !empty($config['ftp_' . $data]) ? $config['ftp_' . $data] : $default;
                $conn_info_ary[$data] = $default;
            }
        }
        handle_ftp_details($ftp_method, $test_ftp_connection, $test_connection);
    }
    return $conn_info_ary;
}
Esempio n. 2
0
    /**
     * Uninstall/pre uninstall a mod
     */
    function uninstall($action, $mod_id)
    {
        global $phpbb_root_path, $phpEx, $db, $template, $config, $force_install;
        global $method, $test_ftp_connection, $test_connection, $mod_uninstalled;
        // mod_id blank?
        if (!$mod_id) {
            // ERROR
            return false;
        }
        // set the class parameters to refelect the proper directory
        $sql = 'SELECT mod_path FROM ' . MODS_TABLE . '
			WHERE mod_id = ' . $mod_id;
        $result = $db->sql_query($sql);
        if ($row = $db->sql_fetchrow($result)) {
            $this->mod_root = dirname($row['mod_path']) . '/';
        }
        $execute_edits = $action == 'pre_uninstall' ? false : true;
        $write_method = 'editor_' . determine_write_method(!$execute_edits);
        $editor = new $write_method();
        // get mod install root && make temporary edited folder root
        $this->edited_root = "{$this->mod_root}{$mod_id}_uninst/";
        // get FTP information if we need it
        // using $config instead of $editor because write_method is forced to direct
        // when in preview mode
        if ($config['write_method'] == WRITE_FTP) {
            handle_ftp_details($method, $test_ftp_connection, $test_connection);
        }
        $editor->create_edited_root($this->edited_root);
        $template->assign_vars(array('S_UNINSTALL' => $execute_edits, 'S_PRE_UNINSTALL' => !$execute_edits, 'MOD_ID' => $mod_id, 'U_UNINSTALL' => $this->u_action . '&action=uninstall&mod_id=' . $mod_id, 'U_RETURN' => $this->u_action));
        // grab actions and details
        $details = $this->mod_details($mod_id, false);
        $actions = $this->mod_actions($mod_id);
        $force_install = request_var('force', false);
        // process the actions
        $mod_uninstalled = $this->process_edits($editor, $actions, $details, $execute_edits, true, true);
        if (!$execute_edits) {
            return;
        }
        $force_uninstall = request_var('force', false);
        if ($mod_uninstalled || $force_uninstall) {
            // Move edited files back
            $status = $editor->commit_changes($this->edited_root, '');
            if (is_string($status)) {
                $mod_uninstalled = false;
                $template->assign_block_vars('error', array('ERROR' => $status));
            }
        }
        if ($force_uninstall) {
            $template->assign_var('S_FORCE', true);
        }
        $template->assign_var('S_ERROR', !$mod_uninstalled);
        if ($execute_edits && ($mod_uninstalled || $force_uninstall)) {
            // Delete from DB
            $sql = 'DELETE FROM ' . MODS_TABLE . '
				WHERE mod_id = ' . $mod_id;
            $db->sql_query($sql);
            // Add log
            add_log('admin', 'LOG_MOD_REMOVE', $details['MOD_NAME']);
            $editor->commit_changes_final('mod_' . $editor->install_time, str_replace(' ', '_', $details['MOD_NAME']));
        }
    }