Advertisement
rcain

index - v3.1.4 - bug fixes

Dec 13th, 2011
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 27.38 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Promotion Slider
  4. Plugin URI: http://www.orderofbusiness.net/plugins/promotion-slider/
  5. Description: This plugin creates a special post type called 'Promotions' that it uses to populate the carousel.  Just use the shortcode [promoslider] to display the slider on your site.  Be sure to check the <a href="http://wordpress.org/extend/plugins/promotion-slider/faq/" target="_blank">user guide</a> for more information on what this plugin can really do!
  6. Version: 3.3.1
  7. Author: Micah Wood
  8. Author URI: http://www.orderofbusiness.net/micah-wood/
  9. License: GPL3
  10.  
  11. Copyright 2010  Micah Wood  (email : micah.wood@orderofbusiness.net)
  12.  
  13.     This program is free software; you can redistribute it and/or modify
  14.     it under the terms of the GNU General Public License, version 3, as
  15.     published by the Free Software Foundation.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software
  24.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  25. */
  26.  
  27.  
  28. //mod jrc 131211: systemcore.co.uk - recommended bug fixes, various. see mod marks 'mod jrc ...'
  29. //based on code: http://wordpress.org/extend/plugins/promotion-slider/
  30. //based on version: V3.1.4
  31. //based on file: index.php
  32. //problem reference: http://wordpress.org/support/topic/plugin-promotion-slider-browser-scroll-bug-using-image-width-auto-suggested-fix  
  33.  
  34.  
  35. // Check for PHP 5+ and return error before getting to code that will throw errors
  36. if( phpversion() < 5 )
  37.     die( printf(__('Sorry, this plugin requires PHP version %s or later. You are currently running version %s.', 'promotion-slider'), 5, phpversion()) );
  38.  
  39. // DEFINE CONSTANTS
  40. if( !defined('PROMOSLIDER_VER') ) define( 'PROMOSLIDER_VER', '3.3.1' );
  41.  
  42. // INCLUDE FILES
  43. include( dirname(__FILE__).'/classes/post_type.php' );
  44. include( dirname(__FILE__).'/classes/register_tax.php' );
  45. include( dirname(__FILE__).'/classes/legacy.php' );
  46. include( dirname(__FILE__).'/includes/functions.php' );
  47.  
  48. // BEGIN MAIN CLASS
  49. if( !class_exists('promo_slider') ){
  50.    
  51.     class promo_slider{
  52.      
  53.         // Define post type and taxonomy name
  54.         private $post_type = 'ps_promotion',
  55.                 $taxonomy = 'promotion-categories',
  56.                 $options,
  57.                 $options_page;
  58.      
  59.         function __construct(){
  60.             // Set global plugin defaults
  61.             $this->options = array( 'version' => PROMOSLIDER_VER,
  62.                                     'start_on' => 'first',              // VALUES: first, random
  63.                                     'auto_advance' => 'auto_advance',   // VALUES: auto_advance, no_auto_advance
  64.                                     'time_delay' => 6,                  // VALUES: any integer between 3 and 15
  65.                                     'display_nav' => 'fancy',           // VALUES: none, default, fancy, links, thumb
  66.                                     'display_title' => 'none',          // VALUES: none, default, fancy
  67.                                     'display_excerpt' => 'none',        // VALUES: none, excerpt
  68.                                     'pause_on_hover' => 'no_pause',     // VALUES: pause, no_pause
  69.                                     'load_js_in' => 'header',           // VALUES: header, footer
  70.                                     'default_img_size' => 'full',       // VALUES: thumbnail, medium, large, full
  71.                                     'show_title' => false,              // DEPRECIATED: replaced by display_title, VALUES: true, false
  72.                                     'show_excerpt' => false,            // DEPRECIATED: replaced by display_excerpt, VALUES: true, false
  73.                                     'nav_option' => 'default',          // DEPRECIATED: replaced by display_nav, VALUES: none, default, links, thumb
  74.                                     'disable_fancy_title' => false,     // DEPRECIATED: replaced by display_title, VALUES: true, false
  75.                                     'disable_fancy_nav' => false        // DEPRECIATED: replaced by display_nav, VALUES: true, false
  76.                                     );
  77.          
  78.             // Create the post type that we will pull from
  79.             new wordpress_custom_post_type($this->post_type,
  80.                                            array('singular' => __('Promotion', 'promotion-slider'),
  81.                                                  'plural' => __('Promotions', 'promotion-slider'),
  82.                                                  'slug' => 'promotion',
  83.                                                  'args' => array('supports' => array('title', 'editor', 'author', 'excerpt', 'thumbnail'))));
  84.  
  85.             // Register the taxonomy for our post type
  86.             new wordpress_custom_taxonomy($this->taxonomy,
  87.                                           $this->post_type,
  88.                                           array('singular' => __('Category', 'promotion-slider'),
  89.                                                 'plural' => __('Categories', 'promotion-slider'),
  90.                                                 'slug' => 'promotions',
  91.                                                 'args' => array('hierarchical' => TRUE)) );
  92.  
  93.             // Perform some maintenance activities on activation
  94.             register_activation_hook( __FILE__, array($this, 'activate') );
  95.            
  96.             // Check if plugin has been updated, if so run activation function
  97.             if( $this->get_options()->version != PROMOSLIDER_VER )
  98.                 $this->activate();
  99.          
  100.             // Initiate key components
  101.             add_action( 'after_setup_theme', array($this, 'after_setup_theme') );
  102.             add_action( 'init', array($this, 'init') );
  103.             add_action( 'admin_init', array($this, 'admin_init') );
  104.             add_action( 'admin_menu', array($this, 'admin_menu') );
  105.             add_action( 'admin_print_styles', array($this, 'load_css_for_options_page') );
  106.          
  107.             // Load this plugin last to ensure other plugins don't overwrite theme support
  108.             add_action( 'activated_plugin', array($this, 'load_last') );
  109.            
  110.             // Add contextual help
  111.             add_filter( 'contextual_help', array($this, 'slider_options_help'), 10, 3 );
  112.            
  113.             // Add menu items to the WordPress admin bar
  114.             add_action( 'wp_before_admin_bar_render', array($this, 'wp_admin_bar') );
  115.  
  116.         }
  117.        
  118.         function wp_admin_bar() {
  119.             global $wp_admin_bar;
  120.             $wp_admin_bar->add_menu( array( 'parent' => 'appearance',
  121.                                             'id' => 'promoslider_settings',
  122.                                             'title' => __('Promotion Slider Options', 'promotion-slider'),
  123.                                             'href' => admin_url( 'edit.php?post_type='.$this->post_type.'&page=options' )) );
  124.         }
  125.        
  126.         function load_css_for_options_page(){
  127.             if( @$_GET['post_type'] == $this->post_type && @$_GET['page'] == 'options' )
  128.                 wp_enqueue_style('options_page_css', plugins_url('/css/admin.css', __FILE__) );
  129.         }
  130.        
  131.         function slider_options_help( $contextual_help, $screen_id, $screen ){
  132.             if( $screen_id == 'edit-'.$this->post_type ):
  133.                 // Promotions
  134.                 $contextual_help = $this->get_include_contents( dirname(__FILE__).'/includes/help.promotions.php' );
  135.             elseif( $screen_id == $this->post_type ):
  136.                 // Add New Promotion
  137.                 $contextual_help = $this->get_include_contents( dirname(__FILE__).'/includes/help.add_new_promotion.php' );
  138.             elseif( $screen_id == 'edit-'.$this->taxonomy ):
  139.                 // Categories
  140.                 $contextual_help = $this->get_include_contents( dirname(__FILE__).'/includes/help.categories.php' );
  141.             elseif( $screen_id == $this->options_page ):
  142.                 // Slider Options
  143.                 $contextual_help = $this->get_include_contents( dirname(__FILE__).'/includes/help.slider_options.php' );
  144.             endif;
  145.             return $contextual_help;
  146.         }
  147.        
  148.         function get_include_contents( $filename ) {
  149.             if( is_file($filename) ) {
  150.                 ob_start();
  151.                 include $filename;
  152.                 return ob_get_clean();
  153.             }
  154.             return false;
  155.         }
  156.      
  157.         function activate() {
  158.             // Make sure user is using WordPress 3.0+
  159.             $this->requires_wordpress_version();
  160.             // Change post type, if necessary
  161.             ps_legacy::change_legacy_post_type();
  162.             // Ensure all options are up-to-date when upgrading
  163.             $this->option_management();
  164.             // One time flush of rewrite rules
  165.             flush_rewrite_rules();
  166.         }
  167.        
  168.         function requires_wordpress_version( $ver = 3 ){
  169.             global $wp_version;
  170.             if( $wp_version < $ver )
  171.                 die( printf(__('Sorry, this plugin requires WordPress version %d or later. You are currently running version %s.', 'promotion-slider'), $ver, $wp_version) );
  172.         }
  173.      
  174.         function after_setup_theme(){
  175.             // Adds support for featured images, which is where the slider gets its images
  176.             add_theme_support( 'post-thumbnails' );
  177.         }
  178.      
  179.         function init(){
  180.             // Add support for translations
  181.             load_plugin_textdomain( 'promotion-slider', FALSE, dirname(plugin_basename(__FILE__)).'/lang/' );
  182.             // Load our js and css files
  183.             add_action( 'wp_print_styles', array($this, 'enqueue_styles') );
  184.             add_action( 'wp_print_scripts', array($this, 'enqueue_scripts') );
  185.             // Create [promoslider] shortcode
  186.             add_shortcode( 'promoslider', array($this, 'show_slider') );
  187.             // Enable use of the shortcode in text widgets
  188.             add_filter( 'widget_text', 'do_shortcode' );
  189.             // Add our custom column to the promotions listing page
  190.             add_filter( 'manage_edit-ps_promotion_columns', array($this, 'add_promotion_columns') );
  191.             add_action( 'manage_posts_custom_column',  array($this, 'show_promotion_columns') );
  192.             // Add our custom filters to the promotions listing page
  193.             add_action( 'restrict_manage_posts', array($this, 'manage_posts_by_category') );
  194.         }
  195.        
  196.         function enqueue_styles(){
  197.             // Loads our styles, only on the front end of the site
  198.             if( !is_admin() ){
  199.                 wp_enqueue_style( 'promoslider_main', plugins_url('/css/slide.css', __FILE__) );
  200.             }
  201.         }
  202.        
  203.         function enqueue_scripts(){
  204.             // Loads our scripts, only on the front end of the site
  205.             if( !is_admin() ){
  206.                 // Get plugin options
  207.                 $options = $this->get_options();
  208.  
  209.                 // Load javascript
  210.                 $load_js_in_footer = ( $options->load_js_in == 'footer' ) ? TRUE : FALSE;
  211.                 wp_enqueue_script( 'promoslider_main', plugins_url('/js/promo_slider.js', __FILE__), array('jquery'), FALSE, $load_js_in_footer );
  212.                 // Localize plugin options
  213.  
  214. //mod jrc 121211 - fix options not passed bug
  215. //orig::                $data = array('version' => PROMOSLIDER_VER);
  216.                 $data = get_object_vars($options);
  217.                 $data['version'] = PROMOSLIDER_VER;
  218. //end mod jrc 121211
  219.                 wp_localize_script('promoslider_main', 'promo_slider_options', $data);
  220.             }
  221.         }
  222.      
  223.         function admin_init(){
  224.             // Register plugin options
  225.             register_setting( 'promoslider-settings-group', 'promotion_slider_options', array($this, 'update_options') );
  226.             // Add meta boxes to our post type
  227.             add_meta_box( 'promo_slider_meta_box', __('Promotion Slider Options', 'promotion-slider'), array($this, 'meta_box_content'), $this->post_type );
  228.             // Save meta data when saving our post type
  229.             add_action( 'save_post', array($this, 'save_meta_data') );
  230.         }
  231.      
  232.         function admin_menu(){
  233.             // Create options page
  234.             $this->options_page = add_submenu_page( 'edit.php?post_type='.$this->post_type,
  235.                                                     __('Promotion Slider Options', 'promotion-slider'),
  236.                                                     __('Slider Options', 'promotion-slider'),
  237.                                                     'manage_options',
  238.                                                     'options',
  239.                                                     array($this, 'options_page') );
  240.         }
  241.      
  242.         function load_last(){
  243.             // Get array of active plugins
  244.             if( !$active_plugins = get_option('active_plugins') ) return;
  245.             // Set this plugin as variable
  246.             $my_plugin = 'promotion-slider/'.basename(__FILE__);
  247.             // See if my plugin is in the array
  248.             $key = array_search( $my_plugin, $active_plugins );
  249.             // If my plugin was found
  250.             if( $key !== FALSE ){
  251.                 // Remove it from the array
  252.                 unset( $active_plugins[$key] );
  253.                 // Reset keys in the array
  254.                 $active_plugins = array_values( $active_plugins );
  255.                 // Add my plugin to the end
  256.                 array_push( $active_plugins, $my_plugin );
  257.                 // Resave the array of active plugins
  258.                 update_option( 'active_plugins', $active_plugins );
  259.             }
  260.         }
  261.      
  262.         function options_page(){
  263.             // Load options page
  264.             include( dirname(__FILE__).'/includes/options_page.php' );
  265.         }
  266.      
  267.         function meta_box_content() {
  268.             include( dirname(__FILE__).'/includes/meta_box.php' );
  269.         }
  270.            
  271.         function save_meta_data( $post_id ) {
  272.             // If this is an auto save, our form has not been submitted, so we don't want to do anything
  273.             if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
  274.             // Is the post type correct?
  275.             if ( isset($_POST['post_type']) && $this->post_type != $_POST['post_type'] ) return $post_id;
  276.             // Verify this came from our screen and with proper authorization, because save_post can be triggered at other times
  277.             if ( !isset($_POST['promo_slider_noncename']) || !wp_verify_nonce( $_POST['promo_slider_noncename'], 'ps_update_promotion' )) { return $post_id; }
  278.             // Can user edit this post?
  279.             if ( !current_user_can('edit_post', $post_id) ) return $post_id;
  280.             // Setup array for the data we are saving  
  281.             $data = array('_promo_slider_target', '_promo_slider_url', '_promo_slider_disable_links', '_promo_slider_show_ad_code', '_promo_slider_ad_code', '_promo_slider_cdn_image_url');
  282.             // Use this filter to add postmeta to save for the default post type
  283.             $data = apply_filters('promoslider_add_meta_to_save', $data);
  284.             // Save meta data
  285.             foreach($data as $meta){
  286.                 // Get current meta
  287.                 $current = get_post_meta($post_id, $meta, TRUE);
  288.                 // Get new meta
  289.                 $new = $_POST[$meta];
  290.                 // If the new meta is empty, delete the current meta
  291.                 if( empty($new) ) delete_post_meta($post_id, $meta);
  292.                 // Otherwise, update the current meta
  293.                 else update_post_meta($post_id, $meta, $new);
  294.             }
  295.         }
  296.      
  297.         function show_slider( $atts ){
  298.             global $post;
  299.             // Get plugin options
  300.             $options = $this->get_options();
  301.             // Get combined and filtered attribute list
  302.             $options = shortcode_atts(array('id' => NULL,
  303.                                             'width' => NULL,
  304.                                             'height' => NULL,
  305.                                             'post_type' => $this->post_type,
  306.                                             'category' => NULL,
  307.                                             'numberposts' => -1,
  308.                                             'start_on' => $options->start_on,
  309.                                             'auto_advance' => $options->auto_advance,
  310.                                             'time_delay' => $options->time_delay,
  311.                                             'display_nav' => $options->display_nav,
  312.                                             'display_title' => $options->display_title,
  313.                                             'display_excerpt' => $options->display_excerpt,
  314.                                             'pause_on_hover' => $options->pause_on_hover), $atts);
  315.             // Validate options
  316.             foreach( $options as $option => $value )
  317.                 $options[$option] = $this->validate_options( $option, $value );
  318.            
  319.             // Extract shortcode attributes
  320.             extract( $options );
  321.            
  322.             // Create an array with default values that we can use to build our query
  323.             $query = array('numberposts' => $numberposts, 'post_type' => $post_type);
  324.            
  325.             // If the post type is post or the default, set the category based on taxonomy.
  326.             if( $category ){
  327.                 if( $query['post_type'] == $this->post_type ) $query[$this->taxonomy] = $category;
  328.                 elseif( $query['post_type'] == 'post' ) $query['category_name'] = $category;
  329.             }
  330.            
  331.             // Use the promoslider_query filter to customize the results returned.
  332.             $query = apply_filters('promoslider_query', $query);
  333.            
  334.             // Use the promoslider_query_by_id filter to customize a query for a particular slider.
  335.             $query_by_id = apply_filters('promoslider_query_by_id', array('query' => $query, 'id' => $id));
  336.             $query = $query_by_id['query'];
  337.        
  338.             // Use the promoslider_custom_query_results to run your own query and return the results object to the slider
  339.             $promo_posts = apply_filters('promoslider_custom_query_results', $promo_posts);
  340.        
  341.             // Run query and get posts
  342.             if( !has_filter('promoslider_custom_query_results') )
  343.                 $promo_posts = get_posts( $query );
  344.        
  345.             // If there are results, build slider.  Otherwise, don't show anything.
  346.             if( $promo_posts ){
  347.            
  348.                 // Initiate iteration counter
  349.                 $i = 1;
  350.                
  351.                 // Setup thumbnail array if thumbnail nav is being used
  352.                 if( $display_nav == 'thumb' ) $thumb_collection = array();
  353.                
  354.                 // Setup attributes for wrapper element
  355.                 $wrapper_classes = 'promo_slider_wrapper '.$start_on;
  356.                 if( $display_nav != 'none' ) $wrapper_classes .= ' '.$display_nav.'_nav';
  357.                 $wrapper_classes .= ' '.$pause_on_hover;
  358.                 $wrapper_atts = ' class="'.$wrapper_classes.'"';
  359.                
  360.                 // Setup attributes for main slider element
  361.                 $slider_id = ( $id ) ? ' id="'.$id.'"' : '';
  362.                 $slider_classes = 'promo_slider '.$auto_advance;
  363.                 $width = ( $width ) ? 'width:'.$width.';' : '';
  364.                 $height = ( $height ) ? 'height:'.$height.';' : '';
  365.                 $style = ( $width || $height ) ? ' style="'.$width.' '.$height.'"' : '';
  366.                 $slider_atts = $slider_id.' class="'.$slider_classes.'"'.$style;
  367.            
  368.                 // Begin Output
  369.                 ob_start(); ?>
  370.  
  371.                 <div<?php echo $wrapper_atts; ?>>
  372.                     <?php do_action('before_promoslider', $id); ?>
  373.                    
  374.                     <div<?php echo $slider_atts; ?>>
  375.                         <?php if($time_delay) echo '<span class="promo_slider_time_delay" style="display:none;">'.$time_delay.'</span>'; ?>
  376.                
  377.                         <?php foreach($promo_posts as $post): setup_postdata($post);
  378.                             // Setup values to be passed to the promoslider_content action hook //
  379.                            
  380.                             // Get the title
  381.                             $title = get_the_title();
  382.                             // Get the excerpt
  383.                             $excerpt = get_the_excerpt();
  384.                             // Fetch image for slider
  385.                             $image = $this->get_slider_image( $id );
  386.                             // Fetch thumbnails for slider nav, if thumbnail nav is being used
  387.                             if( $display_nav == 'thumb' ) $thumb_collection[] = $this->get_slider_thumb( $title );
  388.                             // Fetch link settings
  389.                             extract( $this->fetch_link_settings() );
  390.                            
  391.                             // Store all the values in an array and pass it to the promoslider_content action
  392.                             $values = compact('id', 'title', 'excerpt', 'image', 'destination_url', 'target', 'disable_links', 'display_title', 'display_excerpt'); ?>
  393.                                    
  394.                             <div class="panel panel-<?php echo $i; ?>">
  395.                                 <span class="panel-title" style="display:none;"><?php echo $title; ?></span>
  396.                                 <?php // Use the promoslider_content action to populate the contents for panel
  397.                                 do_action('promoslider_content', $values); ?>
  398.                             </div>
  399.                        
  400.                             <?php $i++; ?>
  401.                         <?php endforeach;
  402.                    
  403.                         if( $i > 2 && $display_nav != 'thumb' ):
  404.                             // Use promoslider_nav action to generate the nav options
  405.                             do_action('promoslider_nav', $display_nav);
  406.                         endif; ?>
  407.                    
  408.                         <div class="clear"></div>
  409.                    
  410.                     </div><?php
  411.                    
  412.                     if( $i > 2 && $display_nav == 'thumb' )
  413.                         do_action('promoslider_thumbnail_nav', array('id' => $id, 'title' => $title, 'thumbs' => $thumb_collection, 'width' => $width) );
  414.                     do_action('after_promoslider', $id); ?>
  415.                    
  416.                 </div><?php
  417.                
  418.                 // Reset query so that comment forms work properly
  419.                 wp_reset_query();
  420.          
  421.                 // End Output        
  422.                 return ob_get_clean();
  423.        
  424.             }
  425.         }
  426.        
  427.         function get_slider_image( $slider_id = NULL ){
  428.             global $post;
  429.             $options = $this->get_options();
  430.             // If functionality or image doesn't exist, go ahead and terminate
  431.             if( !function_exists('has_post_thumbnail') || !has_post_thumbnail($post->ID) ) return FALSE;
  432.             // Filters allow for use of particular image sizes in the slider
  433.             $image_size = apply_filters('promoslider_image_size', $options->default_img_size);
  434.             // Filters allow for use of particular image sizes in specific sliders
  435.             $image_size = apply_filters('promoslider_image_size_by_id', array('id' => $slider_id, 'image_size' => $image_size) );
  436.             $image_size = $image_size['image_size'];
  437.             // Return the appropriate sized image
  438.             return get_the_post_thumbnail($post->ID, $image_size);
  439.         }
  440.        
  441.         function get_slider_thumb( $title ){
  442.             global $post;
  443.             // If functionality or image doesn't exist, go ahead and terminate
  444.             if( !function_exists('has_post_thumbnail') || !has_post_thumbnail($post->ID) ) return FALSE;
  445.             // Filter allows for use of particular thumbnail size in the slider
  446.             $thumb_size = apply_filters('promoslider_thumb_size', 'thumbnail');
  447.             // Return the appropriate sized image with corrected title attribute
  448.             return preg_replace('/title="[^"]*"/', 'title="'.$title.'"', get_the_post_thumbnail($post->ID, $thumb_size) );
  449.         }
  450.        
  451.         function fetch_link_settings(){
  452.             global $post;
  453.             // If the destination url is set by the user, use that.  Otherwise, use the permalink
  454.             $destination_url = get_post_meta($post->ID, '_promo_slider_url', TRUE);
  455.             if( !$destination_url ) $destination_url = get_permalink($post->ID);
  456.             // If the target attribute is set the user, use that.  Otherwise, set it to _self
  457.             $target = get_post_meta($post->ID, '_promo_slider_target', TRUE);
  458.             if( !$target ) $target = '_self';
  459.             // Setup the disable links variable
  460.             $disable_links = get_post_meta($post->ID, '_promo_slider_disable_links', TRUE);
  461.             return compact('destination_url', 'target', 'disable_links');
  462.         }
  463.        
  464.         function add_promotion_columns( $columns ){
  465.             // Create a new array so we can put columns in the order we want
  466.             $new_columns = array();
  467.             // Transfer columns to new array and append ours after the desired elements
  468.             foreach($columns as $key => $value){
  469.                 $new_columns[$key] = $value;
  470.                 if($key == 'title')
  471.                     $new_columns[$this->taxonomy] = __('Categories', 'promotion-slider');
  472.             }
  473.             // Return the new column configuration
  474.             return $new_columns;
  475.         }
  476.  
  477.         function show_promotion_columns( $name ) {
  478.             global $post;
  479.             // Display our categories on the promotions listing page
  480.             switch ( $name ) {
  481.                 case $this->taxonomy:
  482.                     $terms = get_the_terms( $post->ID, $this->taxonomy );
  483.                     if( $terms ){
  484.                         $links = array();
  485.                         foreach( $terms as $term ){
  486.                             $links[] = '<a href="edit.php?post_type='.$this->post_type.'&'.$this->taxonomy.'='.$term->slug.'">'.$term->name.'</a>';
  487.                         }
  488.                         echo implode(', ', $links);
  489.                     }
  490.                     else
  491.                         _e('No Categories', 'promotion-slider');
  492.                     break;
  493.             }
  494.         }
  495.        
  496.         function manage_posts_by_category(){
  497.             global $typenow;
  498.             // If we are on our custom post type screen, add our custom taxonomy as a filter
  499.             if( $typenow == $this->post_type ){
  500.                 $taxonomy = get_terms($this->taxonomy);
  501.                 if( $taxonomy ): //print_r($taxonomy); ?>
  502.                     <select name="<?php echo $this->taxonomy; ?>" id="<?php echo $this->taxonomy; ?>" class="postform">
  503.                         <option value="">Show All Categories</option><?php
  504.                         foreach( $taxonomy as $terms ): ?>
  505.                             <option value="<?php echo $terms->slug; ?>"<?php if( isset($_GET[$this->taxonomy]) && $terms->slug == $_GET[$this->taxonomy] ) echo ' selected="selected"'; ?>><?php echo $terms->name; ?></option><?php
  506.                         endforeach; ?>
  507.                     </select><?php
  508.                 endif;
  509.             }
  510.         }
  511.        
  512.         function get_options(){
  513.             // Get options from database
  514.             $options = get_option('promotion_slider_options');
  515.             // If nothing, return false
  516.             if( !$options ) return FALSE;
  517.             // Otherwise, return the options as an object (my personal preference)
  518.             return (object) $options;
  519.         }
  520.        
  521.         function update_options( $options = array() ){
  522.             // Get plugin default options as an array
  523.             $defaults = (array) $this->options;
  524.             // Get new options as an array
  525.             $options = (array) $options;
  526.             // Merge the arrays allowing the new options to override defaults
  527.             $options = wp_parse_args( $options, $defaults );
  528.             // Validate options
  529.             foreach( $options as $option => $value ){
  530.                 $options[$option] = $this->validate_options( $option, $value );
  531.                 if( $value === FALSE ) unset($options[$option]);
  532.             }
  533.             // Return new options array
  534.             return $options;
  535.         }
  536.        
  537.         function validate_options( $option_name, $option_value ){
  538.             switch( $option_name ){
  539.                 case 'version':
  540.                     return PROMOSLIDER_VER;
  541.                 case 'start_on':
  542.                     if( in_array($option_value, array('first', 'random')) )
  543.                         return $option_value;
  544.                     break;
  545.                 case 'auto_advance':
  546.                     if( in_array($option_value, array('auto_advance', 'no_auto_advance')) )
  547.                         return $option_value;
  548.                     break;
  549.                 case 'time_delay':
  550.                     $option_value = (int) $option_value;
  551.                     if( is_int($option_value) && $option_value >= 3 && $option_value <= 15 )
  552.                         return $option_value;
  553.                     break;
  554.                 case 'display_nav':
  555.                     if( in_array($option_value, array('none', 'default', 'fancy', 'links', 'thumb')) )
  556.                         return $option_value;
  557.                     break;
  558.                 case 'display_title':
  559.                     if( in_array($option_value, array('none', 'default', 'fancy')) )
  560.                         return $option_value;
  561.                     break;
  562.                 case 'display_excerpt':
  563.                     if( in_array($option_value, array('none', 'excerpt')) )
  564.                         return $option_value;
  565.                     break;
  566.                 case 'pause_on_hover':
  567.                     if( in_array($option_value, array('pause', 'no_pause')) )
  568.                         return $option_value;
  569.                     break;
  570.                 case 'load_js_in':
  571.                     if( in_array($option_value, array('head', 'footer')) )
  572.                         return $option_value;
  573.                     break;
  574.                 case 'post_type':
  575.                     if( $option_value != $this->post_type && post_type_exists($option_value) )
  576.                         return $option_value;
  577.                     return $this->post_type;
  578.                     break;
  579.                 case 'category':
  580.                     if( term_exists($option_value) )
  581.                         return $option_value;
  582.                     return FALSE;
  583.                 case 'id':
  584.                     return $option_value;
  585.                     break;
  586.                 case 'width':
  587.                     return $option_value;
  588.                     break;
  589.                 case 'height':
  590.                     return $option_value;
  591.                     break;
  592.                 case 'numberposts':
  593.                     $option_value = (int) $option_value;
  594.                     if( is_int($option_value) )
  595.                         return $option_value;
  596.                     return -1;
  597.                     break;
  598.                 case 'default_img_size':
  599.                     if( in_array($option_value, array('thumbnail', 'medium', 'large', 'full')) )
  600.                         return $option_value;
  601.                     break;
  602.                 default:
  603.                     return FALSE;
  604.             }
  605.             return $this->options[$option_name];
  606.         }
  607.        
  608.         function save_options( $options ){
  609.             // Takes an array or object and saves the options to the database after validating
  610.             update_option('promotion_slider_options', $this->update_options($options));
  611.         }
  612.        
  613.         function option_management(){
  614.             // Get existing options array, if available
  615.             $options = (array) $this->get_options();
  616.             // If unavailable, create an empty array
  617.             if( !$options ) $options = array();
  618.             // Original options were stored individually, transfer these to our array
  619.             if( get_option('time_delay') ) $options['time_delay'] = get_option('time_delay');
  620.             if( get_option('auto_advance') ) $options['auto_advance'] = get_option('auto_advance');
  621.             if( get_option('show_title') ) $options['show_title'] = get_option('show_title');
  622.             if( get_option('show_excerpt') ) $options['show_excerpt'] = get_option('show_excerpt');
  623.             if( get_option('nav_option') ) $options['nav_option'] = get_option('nav_option');
  624.             if( get_option('disable_fancy_title') ) $options['disable_fancy_title'] = get_option('disable_fancy_title');
  625.             if( get_option('disable_fancy_nav') ) $options['disable_fancy_nav'] = get_option('disable_fancy_nav');
  626.             // Update auto_advance option due to change in values
  627.             if( $options['auto_advance'] == true ) $options['auto_advance'] = 'auto_advance';
  628.             elseif( $options['auto_advance'] == false ) $options['auto_advance'] = 'no_auto_advance';
  629.             else $options['auto_advance'] = 'auto_advance';
  630.             // Update depreciated options
  631.             if( isset($options['nav_option']) ) $options['display_nav'] = $options['nav_option'];
  632.             if( isset($options['disable_fancy_nav']) && $options['disable_fancy_nav'] != true ) $options['nav_option'] = 'fancy';
  633.             if( isset($options['show_title']) && $options['show_title'] != true ) $options['display_title'] = 'none';
  634.             elseif( isset($options['disable_fancy_title']) && $options['disable_fancy_title'] == true ) $options['display_title'] = 'default';
  635.             elseif( isset($options['disable_fancy_title']) && $options['disable_fancy_title'] == false ) $options['display_title'] = 'fancy';
  636.             if( $options['show_excerpt'] == true ) $options['display_excerpt'] = 'excerpt';
  637.             else $options['display_excerpt'] = 'none';
  638.             // Properly saves options and updates plugin version
  639.             $this->save_options( $options );
  640.             // Remove legacy options, if needed
  641.             ps_legacy::remove_legacy_options();
  642.         }
  643.  
  644.     }
  645.  
  646. }
  647.  
  648. if( class_exists('promo_slider') ){
  649.     new promo_slider();
  650. }
  651.  
  652. ?>
  653.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement