Exemplo n.º 1
0
function zn_ajax_callback()
{
    check_ajax_referer('zn_framework', 'zn_ajax_nonce');
    $save_action = $_POST['zn_action'];
    if ($save_action == 'zn_save_options') {
        // DO ACTION FOR SAVED OPTIONS
        do_action('zn_save_theme_options');
        $_POST = array_map('stripslashes_deep', $_POST);
        $data = $_POST;
        $options_field = $data['zn_option_field'];
        /* REMOVE THE HIDDEN FORM DATA */
        unset($data['zn_ajax_nonce']);
        unset($data['zn_option_field']);
        unset($data['action']);
        unset($data['zn_action']);
        // Combine all options
        // Get all saved options
        $saved_options = zget_option('', '', true);
        $saved_options[$options_field] = $data;
        $custom_css = '';
        if (isset($saved_options['advanced']['custom_css'])) {
            $custom_css = $saved_options['advanced']['custom_css'];
            $uploads = wp_upload_dir();
            $zn_uploads_dir = trailingslashit($uploads['basedir']);
            file_put_contents($zn_uploads_dir . 'zn_custom_css.css', $custom_css);
            unset($saved_options['advanced']['custom_css']);
        }
        $result = update_option(ZN()->theme_data['options_prefix'], $saved_options);
        generate_options_css($saved_options);
        //generate static css file
        if ($result == 0 || $result) {
            echo 'Settings successfully save';
            die;
        } else {
            echo 'There was a problem while saving the options';
            die;
        }
    } elseif ($save_action == 'zn_add_element') {
        $data = $_POST;
        if (empty($data['zn_elem_type'])) {
            return;
        }
        $value = json_decode(base64_decode($data['zn_json']), true);
        $value['dynamic'] = true;
        echo ZN()->html->zn_render_single_option($value);
        die;
    } elseif ($save_action == 'zn_add_google_font') {
        $data = $_POST;
        if (empty($data['zn_elem_type'])) {
            return;
        }
        $value = json_decode(base64_decode($data['zn_json']), true);
        if (isset($data['selected_font'])) {
            $value['selected_font'] = $data['selected_font'];
        }
        $value['dynamic'] = true;
        echo ZN()->html->zn_render_single_option($value);
        die;
    } elseif ($save_action == 'zn_import_dummy_data') {
        include FW_PATH . '/importer/zn_importer.php';
        installDummy($_POST['step'], $_POST['data']);
        die;
    } elseif ($save_action == 'zn_refresh_pb') {
        ZN()->pagebuilder->refresh_pb_data();
        die;
    } else {
        die('Are you cheating ?');
    }
}
Exemplo n.º 2
0
function zn_ajax_callback()
{
    $nonce = $_POST['security'];
    if (!wp_verify_nonce($nonce, 'zn_ajax_nonce')) {
        die('-1');
    }
    //get options array from db
    $all = get_option(OPTIONS);
    $save_type = $_POST['type'];
    if ($save_type == 'save') {
        $_POST = array_map('stripslashes_deep', $_POST);
        parse_str($_POST['data'], $data);
        unset($data['security']);
        unset($data['of_save']);
        $args = wp_parse_args($data, $all);
        update_option(OPTIONS, $args);
        generate_options_css($args);
        //generate static css file
        generate_options_js($args);
        //generate static js file
        echo '1';
    } elseif ($save_type == 'zn_restore_options') {
        $saved_backup = get_option($_POST['data']);
        update_option(OPTIONS, $saved_backup);
        generate_options_css($args);
        //generate static css file
        generate_options_js($args);
        //generate static js file
        ob_clean();
        echo '1';
    } elseif ($save_type == 'zn_delete_backup') {
        $saved_backup = delete_option($_POST['data']);
        ob_clean();
        echo '1';
    } elseif ($save_type == 'install_dummy') {
        locate_template(array('admin/dummy_content/zn_importer.php'), true, true);
        installDummy();
    } elseif ($save_type == 'zn_backup_options') {
        $_POST = array_map('stripslashes_deep', $_POST);
        parse_str($_POST['data'], $data);
        unset($data['security']);
        unset($data['of_save']);
        $args = wp_parse_args($data, $all);
        $date = date('Y m d H i s');
        $option_field = THEMENAME . '_backup_from_' . str_replace(' ', '_', $date);
        $option_field = strtolower($option_field);
        add_option($option_field, $args, '', 'no');
        ob_clean();
        echo $option_field;
    } elseif ($save_type == 'add_element') {
        //$what_element = $_POST['data'];
        $html = new zn_html();
        parse_str($_POST['data'], $data);
        // Make a check to see if the element is a subelement
        // All subelements options must be placed in the same array that is passed to zn_get_element_from_id() function in functions-zn-admin.php !!
        $full_id = $data['element_type'];
        if (preg_match('/\\[(\\d+)\\]/', $full_id, $matches)) {
            $split_element_type = preg_split('/\\[(\\d+)\\]/', $full_id);
            $number_of_ids = count($split_element_type) - 1;
            $string = str_replace('[', '', $split_element_type[$number_of_ids]);
            $string = str_replace(']', '', $string);
            $data['element_type'] = $string;
        }
        $option = zn_get_element_from_id($data['element_type']);
        if (isset($option['link'])) {
            $option['is_dynamic'] = true;
        }
        $option['id'] = $full_id;
        if (isset($data['pb_area']) && !empty($data['pb_area'])) {
            $option['pb_area'] = $data['pb_area'];
        }
        echo $html->zn_render_element($option);
        //print_r($option);
        unset($data['security']);
        unset($data['of_save']);
        die(1);
    }
    die;
}