function wfu_update_settings()
{
    if (!current_user_can('manage_options')) {
        return;
    }
    if (!check_admin_referer('wfu_edit_admin_settings')) {
        return;
    }
    $plugin_options = wfu_decode_plugin_options(get_option("wordpress_file_upload_options"));
    $new_plugin_options = array();
    //	$enabled = ( isset($_POST['wfu_enabled']) ? ( $_POST['wfu_enabled'] == "on" ? 1 : 0 ) : 0 );
    $hashfiles = isset($_POST['wfu_hashfiles']) ? $_POST['wfu_hashfiles'] == "on" ? 1 : 0 : 0;
    $relaxcss = isset($_POST['wfu_relaxcss']) ? $_POST['wfu_relaxcss'] == "on" ? 1 : 0 : 0;
    $mediacustom = isset($_POST['wfu_mediacustom']) ? $_POST['wfu_mediacustom'] == "on" ? 1 : 0 : 0;
    if (isset($_POST['wfu_basedir']) && isset($_POST['wfu_postmethod']) && isset($_POST['wfu_admindomain']) && isset($_POST['submitform'])) {
        if ($_POST['submitform'] == "Update") {
            $new_plugin_options['version'] = '1.0';
            $new_plugin_options['shortcode'] = $plugin_options['shortcode'];
            $new_plugin_options['hashfiles'] = $hashfiles;
            $new_plugin_options['basedir'] = $_POST['wfu_basedir'];
            $new_plugin_options['postmethod'] = $_POST['wfu_postmethod'];
            $new_plugin_options['relaxcss'] = $relaxcss;
            $new_plugin_options['admindomain'] = $_POST['wfu_admindomain'];
            $new_plugin_options['mediacustom'] = $mediacustom;
            $encoded_options = wfu_encode_plugin_options($new_plugin_options);
            update_option("wordpress_file_upload_options", $encoded_options);
            if ($new_plugin_options['hashfiles'] == '1' && $plugin_options['hashfiles'] != '1') {
                wfu_reassign_hashes();
            }
        }
    }
    return true;
}
function wfu_ajax_action_save_shortcode()
{
    if (!current_user_can('manage_options')) {
        die;
    }
    if (!isset($_POST['shortcode']) || !isset($_POST['shortcode_original']) || !isset($_POST['post_id']) || !isset($_POST['post_hash']) || !isset($_POST['shortcode_position'])) {
        die;
    }
    if ($_POST['post_id'] == "") {
        $plugin_options = wfu_decode_plugin_options(get_option("wordpress_file_upload_options"));
        $new_plugin_options['version'] = '1.0';
        $new_plugin_options['shortcode'] = $plugin_options['shortcode'];
        $new_plugin_options['hashfiles'] = $plugin_options['hashfiles'];
        $new_plugin_options['basedir'] = $plugin_options['basedir'];
        $encoded_options = wfu_encode_plugin_options($new_plugin_options);
        update_option("wordpress_file_upload_options", $encoded_options);
        die("wfu_save_shortcode:success:");
    } else {
        $data['post_id'] = $_POST['post_id'];
        $data['post_hash'] = $_POST['post_hash'];
        $data['shortcode'] = wfu_plugin_decode_string($_POST['shortcode_original']);
        $data['position'] = $_POST['shortcode_position'];
        if (!wfu_check_edit_shortcode($data)) {
            die("wfu_save_shortcode:fail:post_modified");
        } else {
            $new_shortcode = "[wordpress_file_upload " . wfu_plugin_decode_string($_POST['shortcode']) . "]";
            if (wfu_replace_shortcode($data, $new_shortcode)) {
                $post = get_post($_POST['post_id']);
                $hash = hash('md5', $post->post_content);
                die("wfu_save_shortcode:success:" . $hash);
            } else {
                die("wfu_save_shortcode:fail:post_update_failed");
            }
        }
    }
}