Пример #1
0
 public function admin_options()
 {
     $recalculate_images = false;
     if (isset($_REQUEST['save'])) {
         $nonce_verified = wp_verify_nonce($_REQUEST['_catablog_options_nonce'], 'catablog_options');
         if ($nonce_verified) {
             // strip slashes from post values
             $post_vars = array_map('stripslashes_deep', $_POST);
             $post_vars = array_map('trim', $post_vars);
             // transform link target and rel value so it only contains alphanumeric, hyphen, underscore
             // $post_vars['link_target'] = preg_replace('/[^a-z0-9_-]/', '', $post_vars['link_target']);
             // $post_vars['link_relationship'] = preg_replace('/[^a-z0-9_-]/', '', $post_vars['link_relationship']);
             // transform catalog slugs
             if ($this->string_length($post_vars['public_post_slug']) > 0) {
                 $post_vars['public_post_slug'] = sanitize_title_with_dashes($post_vars['public_post_slug']);
             } else {
                 $post_vars['public_post_slug'] = $this->custom_post_name;
             }
             if ($this->string_length($post_vars['public_tax_slug']) > 0) {
                 $post_vars['public_tax_slug'] = sanitize_title_with_dashes($post_vars['public_tax_slug']);
             } else {
                 $post_vars['public_tax_slug'] = $this->custom_tax_name;
             }
             // make sure public post and tax slugs are not the same
             if ($post_vars['public_post_slug'] == $post_vars['public_tax_slug']) {
                 $this->wp_error(__('Form Validation Error. Please make sure that the individual and category public page slugs are not identical.', 'catablog'));
             }
             // flush the rewrite rules for public option updates
             flush_rewrite_rules(false);
             // set default values for post message and image recalculation
             $save_message = __("CataBlog Options Saved", 'catablog');
             $fullsize_dir = new CataBlogDirectory($this->directories['fullsize']);
             // get image size and rendering differences
             $image_width_different = $post_vars['thumbnail_width'] != $this->options['thumbnail-width'];
             $image_height_different = $post_vars['thumbnail_height'] != $this->options['thumbnail-height'];
             $image_size_different = $image_width_different || $image_height_different;
             $bg_color_different = $post_vars['bg_color'] != $this->options['background-color'];
             $keep_ratio_different = isset($post_vars['keep_aspect_ratio']) != $this->options['keep-aspect-ratio'];
             $lightbox_enabled = isset($post_vars['lightbox_enabled']) && isset($post_vars['lightbox_render']) && $fullsize_dir->getCount() < 1;
             $fullsize_different = isset($post_vars['lightbox_enabled']) && $post_vars['lightbox_image_size'] != $this->options['image-size'];
             // set recalculation of thumbnails and update post message
             if ($image_size_different || $bg_color_different || $keep_ratio_different || $lightbox_enabled || $fullsize_different) {
                 $recalculate_images = true;
             }
             // save new plugins options to database
             $this->options['thumbnail-width'] = $post_vars['thumbnail_width'];
             $this->options['thumbnail-height'] = $post_vars['thumbnail_height'];
             $this->options['image-size'] = $post_vars['lightbox_image_size'];
             $this->options['lightbox-enabled'] = isset($post_vars['lightbox_enabled']);
             $this->options['lightbox-navigation'] = isset($post_vars['lightbox_navigation']);
             $this->options['lightbox-render'] = isset($post_vars['lightbox_render']);
             $this->options['lightbox-selector'] = $post_vars['lightbox_selector'];
             $this->options['background-color'] = $post_vars['bg_color'];
             $this->options['keep-aspect-ratio'] = isset($post_vars['keep_aspect_ratio']);
             $this->options['link-target'] = strip_tags($post_vars['link_target']);
             $this->options['link-relationship'] = strip_tags($post_vars['link_relationship']);
             $this->options['filter-description'] = isset($post_vars['wp-filters-enabled']);
             $this->options['nl2br-description'] = isset($post_vars['nl2br-enabled']);
             $this->options['excerpt-length'] = $post_vars['excerpt_length'];
             $this->options['public_posts'] = isset($post_vars['public_posts']);
             $this->options['public_post_slug'] = $post_vars['public_post_slug'];
             $this->options['public_tax_slug'] = $post_vars['public_tax_slug'];
             $this->options['nav-prev-label'] = $post_vars['nav_prev_label'];
             $this->options['nav-next-label'] = $post_vars['nav_next_label'];
             $this->options['nav-location'] = $post_vars['nav_location'];
             $this->options['nav-show-meta'] = isset($post_vars['nav_show_meta']);
             $this->save_wp_options();
             // recalculate thumbnail and fullsize images if necessary
             if ($recalculate_images) {
                 $save_message .= " - ";
                 $link = wp_nonce_url('admin.php?page=catablog-regenerate-images', 'catablog-regenerate-images');
                 $save_message .= sprintf(__("You have changed your image settings, please %sRegenerate All Images Now%s", 'catablog'), '<a href="' . $link . '">', '</a>');
             }
             $this->wp_message($save_message);
         } else {
             $this->wp_error(__('Form Validation Error. Please reload the page and try again.', 'catablog'));
         }
     }
     if (!isset($this->options['thumbnail-width'])) {
         $this->options['thumbnail-width'] = $this->options['thumbnail-size'];
     }
     if (!isset($this->options['thumbnail-height'])) {
         $this->options['thumbnail-height'] = $this->options['thumbnail-size'];
     }
     $thumbnail_width = $this->options['thumbnail-width'];
     $thumbnail_height = $this->options['thumbnail-height'];
     $lightbox_size = $this->options['image-size'];
     $lightbox_enabled = $this->options['lightbox-enabled'];
     $lightbox_navigation = $this->options['lightbox-navigation'];
     $lightbox_render = $this->options['lightbox-render'];
     $lightbox_selector = $this->options['lightbox-selector'];
     $background_color = $this->options['background-color'];
     $keep_aspect_ratio = $this->options['keep-aspect-ratio'];
     $link_target = $this->options['link-target'];
     $link_relationship = $this->options['link-relationship'];
     $wp_filters_enabled = $this->options['filter-description'];
     $nl2br_enabled = $this->options['nl2br-description'];
     $excerpt_length = $this->options['excerpt-length'];
     $public_posts_enabled = $this->options['public_posts'];
     $public_posts_slug = $this->options['public_post_slug'];
     $public_tax_slug = $this->options['public_tax_slug'];
     $nav_prev_label = $this->options['nav-prev-label'];
     $nav_next_label = $this->options['nav-next-label'];
     $nav_location = $this->options['nav-location'];
     $nav_show_meta = $this->options['nav-show-meta'];
     include_once $this->directories['template'] . '/admin-options.php';
 }