Exemple #1
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']));
        }
    }
 function delete_mod($action, $mod_path = '')
 {
     global $template, $user;
     if (!empty($mod_path)) {
         $mod_path = explode('/', str_replace('\\', '/', $mod_path));
         $mod_path = !empty($mod_path[0]) ? $mod_path[0] : $mod_path[1];
     } else {
         $mod_path = request_var('mod_delete', '');
     }
     if (empty($mod_path) || !is_dir($this->mods_dir . '/' . $mod_path)) {
         return false;
         // ERROR
     }
     // get FTP information if we need it
     $hidden_ary = get_connection_info(false);
     $hidden_ary['mod_delete'] = $mod_path;
     if ($action != 'delete_mod') {
         $template->assign_vars(array('S_MOD_DELETE' => true, 'U_DELETE' => $this->u_action . '&action=delete_mod', 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_ary)));
         add_form_key('acp_mods_delete');
         return;
     }
     // end pre_delete_mod
     $write_method = 'editor_' . determine_write_method(false);
     // Force Direct method, in the case of manual - just like above in mod_upload()
     $write_method = $write_method == 'editor_manual' ? 'editor_direct' : $write_method;
     $editor = new $write_method();
     if (!check_form_key('acp_mods_delete')) {
         trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
     }
     $status = $editor->remove("{$this->mods_dir}/{$mod_path}", true);
     if ($status !== true) {
         trigger_error($user->lang['DELETE_ERROR'] . "  {$status}" . adm_back_link($this->u_action), E_USER_WARNING);
     }
     $template->assign_vars(array('S_MOD_SUCCESSBOX' => true, 'MESSAGE' => $user->lang['DELETE_SUCCESS'], 'U_RETURN' => $this->u_action));
 }