public function options_save()
 {
     $option_keys = $this->option_keys();
     $this->options = $this->get_option();
     $iv = new InputValidator('POST');
     $iv->set_rules(self::NONCE_NAME, 'required');
     // Update options
     if (!is_wp_error($iv->input(self::NONCE_NAME)) && check_admin_referer(self::NONCE_ACTION, self::NONCE_NAME)) {
         // Get posted options
         $fields = array_keys($option_keys);
         foreach ($fields as $field) {
             switch ($field) {
                 case 'access_key':
                 case 'secret_key':
                     $iv->set_rules($field, array('trim', 'esc_html', 'required'));
                     break;
                 default:
                     $iv->set_rules($field, array('trim', 'esc_html'));
                     break;
             }
         }
         $options = $iv->input($fields);
         $err_message = '';
         foreach ($option_keys as $key => $field) {
             if (is_wp_error($options[$key])) {
                 $error_data = $options[$key];
                 $err = '';
                 foreach ($error_data->errors as $errors) {
                     foreach ($errors as $error) {
                         $err .= (!empty($err) ? '<br />' : '') . __('Error! : ', self::TEXT_DOMAIN);
                         $err .= sprintf(__(str_replace($key, '%s', $error), self::TEXT_DOMAIN), $field);
                     }
                 }
                 $err_message .= (!empty($err_message) ? '<br />' : '') . $err;
             }
             if (!isset($options[$key]) || is_wp_error($options[$key])) {
                 $options[$key] = '';
             }
         }
         if (self::$debug_mode && function_exists('dbgx_trace_var')) {
             dbgx_trace_var($options);
         }
         // Update options
         if ($this->options !== $options) {
             update_option(self::OPTION_KEY, $options);
             printf('<div id="message" class="updated fade"><p><strong>%s</strong></p></div>' . "\n", empty($err_message) ? __('Done!', self::TEXT_DOMAIN) : $err_message);
             $this->options = $options;
         }
         unset($options);
     }
 }
    public function options_page()
    {
        $nonce_action = 'update_options';
        $nonce_name = '_wpnonce_update_options';
        $title = __($this->plugin_name . ' Options', self::TEXT_DOMAIN);
        $iv = new InputValidator('POST');
        $iv->set_rules($nonce_name, 'required');
        $iv->set_rules('static_url', array('trim', 'esc_html'));
        $iv->set_rules('static_dir', array('trim', 'esc_html'));
        $iv->set_rules('basic_usr', array('trim', 'esc_html'));
        $iv->set_rules('basic_pwd', array('trim', 'esc_html'));
        $iv->set_rules('timeout', 'numeric');
        // Update options
        if (!is_wp_error($iv->input($nonce_name)) && check_admin_referer($nonce_action, $nonce_name)) {
            // Get posted options
            $static_url = $iv->input('static_url');
            $static_dir = $iv->input('static_dir');
            $basic_usr = $iv->input('basic_usr');
            $basic_pwd = $iv->input('basic_pwd');
            $timeout = $iv->input('timeout');
            $basic_auth = $basic_usr && $basic_pwd ? base64_encode("{$basic_usr}:{$basic_pwd}") : false;
            // Update options
            update_option(self::OPTION_STATIC_URL, $static_url);
            update_option(self::OPTION_STATIC_DIR, $static_dir);
            update_option(self::OPTION_STATIC_BASIC, $basic_auth);
            update_option(self::OPTION_STATIC_TIMEOUT, $timeout);
            printf('<div id="message" class="updated fade"><p><strong>%s</strong></p></div>' . "\n", empty($err_message) ? __('Done!', self::TEXT_DOMAIN) : $err_message);
            $this->static_url = $static_url;
            $this->static_dir = $static_dir;
            $this->basic_auth = $basic_auth;
            $this->timeout = $timeout;
        }
        do_action('StaticPress::options_save');
        $basic_usr = $basic_pwd = '';
        if ($this->basic_auth) {
            list($basic_usr, $basic_pwd) = explode(':', base64_decode($this->basic_auth));
        }
        ?>
		<div class="wrap" id="<?php 
        echo self::OPTION_PAGE;
        ?>
-options">
		<?php 
        screen_icon(self::OPTION_PAGE . '-options');
        ?>
		<h2><?php 
        echo esc_html($title);
        ?>
</h2>
		<form method="post" action="<?php 
        echo $this->admin_action;
        ?>
">
		<?php 
        echo wp_nonce_field($nonce_action, $nonce_name, true, false) . "\n";
        ?>
		<table class="wp-list-table fixed"><tbody>
		<?php 
        $this->input_field('static_url', __('Static URL', self::TEXT_DOMAIN), $this->static_url);
        ?>
		<?php 
        $this->input_field('static_dir', __('Save DIR (Document root)', self::TEXT_DOMAIN), $this->static_dir);
        ?>
		<?php 
        $this->input_field('basic_usr', __('(OPTION) BASIC Auth User', self::TEXT_DOMAIN), $basic_usr);
        ?>
		<?php 
        $this->input_field('basic_pwd', __('(OPTION) BASIC Auth Password', self::TEXT_DOMAIN), $basic_pwd, 'password');
        ?>
		<?php 
        $this->input_field('timeout', __('(OPTION) Request Timeout', self::TEXT_DOMAIN), $this->timeout);
        ?>
		</tbody></table>
		<?php 
        submit_button();
        ?>
		</form>
		</div>
<?php 
        do_action('StaticPress::options_page');
    }
    public function options_page()
    {
        $nonce_action = 'update_options';
        $nonce_name = '_wpnonce_update_options';
        $option_keys = $this->option_keys();
        $option_keys = apply_filters('nephila_clavata_option_keys', $option_keys);
        self::$options = $this->get_option();
        $title = __('Nephila clavata', NephilaClavata::TEXT_DOMAIN);
        $iv = new InputValidator('POST');
        $iv->set_rules($nonce_name, 'required');
        // Update options
        if (!is_wp_error($iv->input($nonce_name)) && check_admin_referer($nonce_action, $nonce_name)) {
            // Get posted options
            $fields = array_keys($option_keys);
            foreach ($fields as $field) {
                switch ($field) {
                    case 'access_key':
                    case 'secret_key':
                        $iv->set_rules($field, array('trim', 'esc_html', 'required'));
                        break;
                    default:
                        $iv->set_rules($field, array('trim', 'esc_html'));
                        break;
                }
            }
            $options = $iv->input($fields);
            $err_message = '';
            foreach ($option_keys as $key => $field) {
                if (is_wp_error($options[$key])) {
                    $error_data = $options[$key];
                    $err = '';
                    foreach ($error_data->errors as $errors) {
                        foreach ($errors as $error) {
                            $err .= (!empty($err) ? '<br />' : '') . __('Error! : ', NephilaClavata::TEXT_DOMAIN);
                            $err .= sprintf(__(str_replace($key, '%s', $error), NephilaClavata::TEXT_DOMAIN), $field);
                        }
                    }
                    $err_message .= (!empty($err_message) ? '<br />' : '') . $err;
                }
                if (!isset($options[$key]) || is_wp_error($options[$key])) {
                    $options[$key] = '';
                }
            }
            if (empty($options['s3_url']) && !empty($options['bucket'])) {
                $options['s3_url'] = sprintf('http://%1$s.s3-website-%2$s.amazonaws.com', strtolower($options['bucket']), strtolower(str_replace('_', '-', $options['region'])));
            }
            if (!empty($options['s3_url']) && !preg_match('#^https?://#i', $options['s3_url'])) {
                $options['s3_url'] = 'http://' . preg_replace('#^//?#', '', $options['s3_url']);
            }
            $options['s3_url'] = untrailingslashit($options['s3_url']);
            if (NephilaClavata::DEBUG_MODE && function_exists('dbgx_trace_var')) {
                dbgx_trace_var($options);
            }
            // Update options
            if (self::$options !== $options) {
                update_option(self::OPTION_KEY, $options);
                if (self::$options['s3_url'] !== $options['s3_url']) {
                    global $wpdb;
                    $sql = $wpdb->prepare("delete from {$wpdb->postmeta} where meta_key in (%s, %s)", NephilaClavata::META_KEY, NephilaClavata::META_KEY . '-replace');
                    $wpdb->query($sql);
                }
                printf('<div id="message" class="updated fade"><p><strong>%s</strong></p></div>' . "\n", empty($err_message) ? __('Done!', NephilaClavata::TEXT_DOMAIN) : $err_message);
                self::$options = $options;
            }
            unset($options);
        }
        // Get S3 Object
        $s3 = S3_helper::get_instance();
        $s3->init(isset(self::$options['access_key']) ? self::$options['access_key'] : null, isset(self::$options['secret_key']) ? self::$options['secret_key'] : null, isset(self::$options['region']) ? self::$options['region'] : null);
        $regions = $this->regions;
        $buckets = false;
        if ($s3) {
            $regions = $s3->get_regions();
            $buckets = $s3->list_buckets();
        }
        if (!$buckets) {
            unset($option_keys['bucket']);
            unset($option_keys['s3_url']);
        }
        $storage_classes = $this->storage_classes;
        ?>
		<div class="wrap">
		<?php 
        screen_icon();
        ?>
		<h2><?php 
        echo esc_html($title);
        ?>
</h2>
		<form method="post" action="<?php 
        echo $this->admin_action;
        ?>
">
		<?php 
        echo wp_nonce_field($nonce_action, $nonce_name, true, false) . "\n";
        ?>
		<table class="wp-list-table fixed"><tbody>
		<?php 
        foreach ($option_keys as $field => $label) {
            $this->input_field($field, $label, array('regions' => $regions, 'buckets' => $buckets, 'storage_classes' => $storage_classes));
        }
        ?>
		</tbody></table>
		<?php 
        submit_button();
        ?>
		</form>
		</div>
<?php 
    }
 private function _options_update($recv_param)
 {
     $fields = array('head_js', 'remove_js', 'head_filters', 'head_remove', 'foot_filters', 'foot_remove', 'xml_declaration', 'ie_conditional', 'canonical_tag', 'add_ogp_tag', 'ogp_default_image', 'og_type_top', 'og_locale', 'fb_admins', 'fb_app_id', 'add_last_modified', 'foot_js', 'dynamic', 'js_move_foot', 'cache_enabled', 'combined_css', 'css_optimise', 'default_media', 'img_base64', 'combined_js', 'js_minify', 'paranoia_mode', 'gzip_on', 'use_ajax_libs', 'debug_mode', 'wp_generator', 'rsd_link', 'wlwmanifest_link');
     $iv = new InputValidator($recv_param);
     foreach ($fields as $field) {
         switch ($field) {
             case 'head_js':
             case 'remove_js':
             case 'head_filters':
             case 'head_remove':
             case 'foot_filters':
             case 'foot_remove':
                 $iv->set_rules($field, array('trim', 'esc_html', 'required'));
                 break;
             case 'ogp_default_image':
                 //	$iv->set_rules($field, array('trim','esc_html','url'));
                 //	break;
             //	$iv->set_rules($field, array('trim','esc_html','url'));
             //	break;
             case 'og_type_top':
             case 'og_locale':
             case 'fb_admins':
             case 'fb_app_id':
                 $iv->set_rules($field, array('trim', 'esc_html'));
                 break;
             case 'default_media':
                 $iv->set_rules($field, array('trim', 'esc_html'));
                 break;
             default:
                 $iv->set_rules($field, 'bool');
         }
     }
     $options = $iv->input($fields);
     $options['remove_js'] = is_wp_error($options['remove_js']) ? array() : (array) $options['remove_js'];
     unset($iv);
     // head js
     $head_js = is_wp_error($options['head_js']) ? array() : (array) $options['head_js'];
     unset($options['head_js']);
     if (function_exists('dbgx_trace_var')) {
         dbgx_trace_var($head_js);
     }
     foreach ((array) $this->options['head_js'] as $javascript => $value) {
         if (array_search($javascript, $head_js) !== false) {
             $this->options['head_js'][$javascript] = false;
         } else {
             $this->options['head_js'][$javascript] = true;
         }
     }
     unset($head_js);
     // wp_head
     $tag = 'wp_head';
     $all_filters = array_merge((array) $this->options['filters'][$tag], array('wp_generator' => 10, 'rsd_link' => 10, 'wlwmanifest_link' => 10));
     $head_filters = is_wp_error($options['head_filters']) ? array() : (array) $options['head_filters'];
     $head_remove = is_wp_error($options['head_remove']) ? array() : (array) $options['head_remove'];
     unset($options['head_filters']);
     unset($options['head_remove']);
     if (function_exists('dbgx_trace_var')) {
         dbgx_trace_var($head_filters);
         dbgx_trace_var($head_remove);
     }
     foreach ($all_filters as $function_name => $priority) {
         switch ($function_name) {
             case 'wp_generator':
             case 'rsd_link':
             case 'wlwmanifest_link':
                 if ($options[$function_name]) {
                     $this->options['priority'][$tag][$function_name] = -1;
                 } elseif (isset($this->options['priority'][$tag][$function_name])) {
                     unset($this->options['priority'][$tag][$function_name]);
                 }
                 break;
             default:
                 if (array_search($function_name, $head_filters) !== false) {
                     $this->options['priority'][$tag][$function_name] = self::PRIORITY + 1;
                 } elseif (array_search($function_name, $head_remove) !== false) {
                     $this->options['priority'][$tag][$function_name] = -1;
                 } elseif (isset($this->options['priority'][$tag][$function_name])) {
                     unset($this->options['priority'][$tag][$function_name]);
                 }
         }
         if (!$this->function_enabled($function_name) && isset($this->options['filters'][$tag][$function_name])) {
             unset($this->options['filters'][$tag][$function_name]);
         }
     }
     unset($all_filters);
     unset($head_filters);
     unset($head_remove);
     // wp_footer
     $tag = 'wp_footer';
     $all_filters = (array) $this->options['filters'][$tag];
     $foot_filters = is_wp_error($options['foot_filters']) ? array() : (array) $options['foot_filters'];
     $foot_remove = is_wp_error($options['foot_remove']) ? array() : (array) $options['foot_remove'];
     unset($options['foot_filters']);
     unset($options['foot_remove']);
     if (function_exists('dbgx_trace_var')) {
         dbgx_trace_var($foot_filters);
         dbgx_trace_var($foot_remove);
     }
     foreach ($all_filters as $function_name => $priority) {
         if (array_search($function_name, $foot_filters) !== false) {
             $this->options['priority'][$tag][$function_name] = self::PRIORITY + 1;
         } elseif (array_search($function_name, $foot_remove) !== false) {
             $this->options['priority'][$tag][$function_name] = -1;
         } elseif (isset($this->options['priority'][$tag][$function_name])) {
             unset($this->options['priority'][$tag][$function_name]);
         }
         if (!$this->function_enabled($function_name) && isset($this->options['filters'][$tag][$function_name])) {
             unset($this->options['filters'][$tag][$function_name]);
         }
     }
     unset($all_filters);
     unset($foot_filters);
     unset($foot_remove);
     $options_org = $this->options;
     foreach ($options_org as $key => $option) {
         if (isset($options[$key]) && !is_wp_error($options[$key]) && $option !== $options[$key]) {
             $this->options[$key] = $options[$key];
         }
         switch ($key) {
             case 'ogp_default_image':
                 if (is_wp_error($option)) {
                     $this->options[$key] = '';
                 }
                 break;
         }
     }
     if (function_exists('dbgx_trace_var')) {
         dbgx_trace_var($this->options);
     }
     unset($options);
     // options update
     $this->updateOptions();
     // create .htaccess file
     $cache_dir = $this->_create_cache_dir();
     if ($cache_dir !== false) {
         $this->_create_htaccess($cache_dir);
     }
     return $this->options;
 }