Advertisement
gregrickaby

jFlow Settings

Jan 12th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.15 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Radio Theme for Genesis
  4.  * Requires Genesis 1.8 or later
  5.  *
  6.  * This file is the engine for the Radio Theme. It defines required parameters, registers
  7.  * all of this child theme's specific Theme Settings, accessible from Genesis > Radio Settings,
  8.  * and executes required functions.
  9.  *
  10.  * @package     Radio
  11.  * @author      Greg Rickaby <greg@gregrickaby.com>
  12.  * @copyright   Copyright (c) 2012
  13.  * @license     http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
  14.  * @link        http://radio.gregrickaby.com
  15.  * @thanks      Bill Erickson for BE-Genesis-Child
  16.  */
  17.  
  18. /** Child theme (do not remove) */
  19. define( 'CHILD_THEME_NAME', 'Radio Theme for Genesis' );
  20. define( 'CHILD_THEME_URL', 'http://radio.gregrickaby.com' );
  21.  
  22. /**
  23.  * Registers a new admin page, providing content and corresponding menu item
  24.  * for the Radio Settings page.
  25.  *
  26.  * @package Radio
  27.  * @subpackage Admin
  28.  *
  29.  * @since 1.0.0
  30.  */
  31. class Child_Theme_Settings extends Genesis_Admin_Boxes {
  32.  
  33.     /**
  34.      * Create an admin menu item and settings page.
  35.      *
  36.      * @since 1.0.0
  37.      */
  38.     function __construct() {
  39.  
  40.         // Specify a unique page ID.
  41.         $page_id = 'child';
  42.  
  43.         // Set it as a child to genesis, and define the menu and page titles
  44.         $menu_ops = array(
  45.             'submenu' => array(
  46.                 'parent_slug' => 'genesis',
  47.                 'page_title'  => 'Radio Theme for Genesis',
  48.                 'menu_title'  => 'Radio Settings',
  49.             )
  50.         );
  51.  
  52.         // Set up page options. These are optional, so only uncomment if you want to change the defaults
  53.         $page_ops = array(
  54.         //  'screen_icon'       => 'options-general',
  55.         //  'save_button_text'  => 'Save Settings',
  56.         //  'reset_button_text' => 'Reset Settings',
  57.         //  'save_notice_text'  => 'Settings saved.',
  58.         //  'reset_notice_text' => 'Settings reset.',
  59.         );     
  60.  
  61.         // Give it a unique settings field.
  62.         // You'll access them from genesis_get_option( 'option_name', 'child-settings' );
  63.         $settings_field = 'child-settings';
  64.  
  65.         // Set the default values
  66.         $default_settings = array(
  67.             'jflow_speed'   => '400',
  68.            
  69.         );
  70.  
  71.         // Create the Admin Page
  72.         $this->create( $page_id, $menu_ops, $page_ops, $settings_field, $default_settings );
  73.  
  74.         // Initialize the Sanitization Filter
  75.         add_action( 'genesis_settings_sanitizer_init', array( $this, 'sanitization_filters' ) );
  76.  
  77.     }
  78.  
  79.     /**
  80.      * Set up Sanitization Filters
  81.      *
  82.      * See /lib/classes/sanitization.php for all available filters.
  83.      *
  84.      * @since 1.0.0
  85.      */
  86.     function sanitization_filters() {
  87.  
  88.         genesis_add_option_filter( 'no_html', $this->settings_field,
  89.             array(
  90.                 'style_box',
  91.                 'custom_stylesheet',
  92.                 'jflow_category',
  93.                 'jflow_limit',
  94.                 'jflow_sort',
  95.                 'jflow_order',
  96.                 'jflow_speed',
  97.             ) );
  98.     }
  99.  
  100.     /**
  101.      * Register metaboxes on Child Theme Settings page
  102.      *
  103.      * @since 1.0.0
  104.      *
  105.      * @see Child_Theme_Settings::contact_information() Callback for contact information
  106.      */
  107.     function metaboxes() {
  108.  
  109.         add_meta_box( 'style-box', 'Color Style', array ($this, 'style_box' ), $this->pagehook, 'main', 'high' );
  110.         add_meta_box( 'custom-stylesheet', 'Custom Stylesheet', array( $this, 'custom_stylesheet' ), $this->pagehook, 'main', 'high' );
  111.         add_meta_box( 'jflow-settings', 'Featured Content Slider', array( $this, 'jflow_settings' ), $this->pagehook, 'main', 'high' );
  112.  
  113.     }
  114.  
  115.  
  116.     /**
  117.      * Callback for setting(s) metaboxes
  118.      *
  119.      * @since 1.0.0
  120.      *
  121.      * @see Child_Theme_Settings::metaboxes()
  122.      */
  123.     function style_box() {
  124.  
  125.         $current_style = $this->get_field_value( 'style_selection' );
  126.         $styles  = get_theme_support( 'child-style-selector' );
  127.        
  128.         echo '<p><label for="' . $this->get_field_id( 'style_selection' ) . '">Color Style: </label>';
  129.         echo '<select name="' . $this->get_field_name( 'style_selection' ) . '" id="' . $this->get_field_id( 'style_selection' ) . '">';
  130.         echo '<option value="">Default</option>';
  131.             if ( ! empty( $styles ) ) {
  132.                 $styles = array_shift( $styles );
  133.                 foreach ( (array) $styles as $style => $title ) {
  134.                     echo '<option value="' . esc_attr( $style ) . '"' . selected( $current_style, $style ) . '>' . esc_html( $title ) . '</option>';
  135.                 }
  136.             }
  137.         echo '</select></p>';
  138.         echo '<p><span class="description">Please select the color style from the drop down list and save your settings.</span></p>';
  139.     }  
  140.    
  141.     function custom_stylesheet() {
  142.        
  143.         echo '<input type="checkbox" name="' . $this->get_field_name( 'custom_stylesheet' ) . '" value="checked" '. esc_attr( $this->get_field_value( 'custom_stylesheet' ) ) . ' />';
  144.         echo '<label> Load <span class="description"><code>custom.css</code></span>?</label>';
  145.         echo '<p><span class="description">The use of this stylesheet will prevent your customizations from disappearing after a theme update.</span></p>';
  146.     }
  147.  
  148.     function jflow_settings() {
  149.  
  150.         $jflow_category = get_categories( 'type=post&orderby=name&hide_empty=0' );
  151.         $jflow_current_category = $this->get_field_value( 'jflow_category' );
  152.         $jflow_current_limit = $this->get_field_value( 'jflow_limit' );
  153.         $jflow_current_sort = $this->get_field_value( 'jflow_sort' );
  154.         $jflow_current_order = $this->get_field_value( 'jflow_order' );
  155.  
  156.         $jflow_post_limit = array(
  157.             '10'    => '10',
  158.             '9'     => '9',
  159.             '8'     => '8',
  160.             '7'     => '7',
  161.             '6'     => '6',
  162.             '5'     => '5',
  163.             '4'     => '4',
  164.             '3'     => '3',
  165.             '2'     => '2',
  166.             '1'     => '1',
  167.         );
  168.  
  169.         $jflow_display_sort = apply_filters( 'child_display_sort', array(
  170.             'date'          => __( 'Date', 'child' ),
  171.             'title'         => __( 'Title', 'child' ),
  172.             'author'        => __( 'Author', 'child' ),
  173.             'ID'            => __( 'Post ID', 'child' ),
  174.             'rand'          => __( 'Random', 'child' ),
  175.             'parent'        => __( 'Parent ID', 'child' ),
  176.             'menu_order'        => __( 'Menu Order', 'child' ),
  177.             'modified'      => __( 'Date Modified', 'child' ),
  178.             'comment_count'     => __( 'Comment Count', 'child' ),
  179.         ));
  180.  
  181.         $jflow_display_order = apply_filters( 'child_display_order', array(
  182.             'DESC'      => __( 'Oldest', 'child' ),
  183.             'ASC'       => __( 'Newest', 'child' ),
  184.            
  185.         ));
  186.  
  187.  
  188.         echo '<label>Featured Category: </label>';
  189.         echo '<select name="' . $this->get_field_name( 'jflow_category' ) . '" id="' . $this->get_field_id( 'jflow_category' ) . '">';
  190.                 foreach( $jflow_category as $jflow_cat ) {
  191.                     echo '<option value="' . $jflow_cat->cat_ID . '"' . selected( $jflow_current_category, $jflow_cat->cat_ID )  . '>' . $jflow_cat->cat_name. '</option>';
  192.                 }
  193.         echo '</select></p>';
  194.         echo '<p><span class="description">Selected the featured category.</span></p>';
  195.  
  196.         echo '<label>Story Count: </label>';
  197.         echo '<select name="' . $this->get_field_name( 'jflow_limit' ) . '" id="' . $this->get_field_id( 'jflow_limit' ) . '">';
  198.                 foreach ( $jflow_post_limit as $jflow_limit ) {
  199.                     echo '<option value="' . esc_attr( $jflow_limit ) . '"' . selected( $jflow_current_limit, $jflow_limit ) . '>' . esc_html( $jflow_limit ) . '</option>';
  200.                 }
  201.         echo '</select>';
  202.         echo '<p><span class="description">Select the number of stories to be displayed.</p>';
  203.  
  204.         echo '<label>Sort Stories: </label>';
  205.         echo '<select name="' . $this->get_field_name( 'jflow_sort' ) . '" id="' . $this->get_field_id( 'jflow_sort' ) . '">';
  206.                 foreach ( $jflow_display_sort as $jflow_d_sort => $sort_label ) {
  207.                     printf( '<option value="%s" %s>%s</option>', $jflow_d_sort, selected( $jflow_d_sort, genesis_get_option( 'jflow_sort' ), 0 ), $sort_label );
  208.                 }
  209.         echo '</select>';
  210.         echo '<p><span class="description">Select how to sort stories.</span></p>';
  211.  
  212.         echo '<label>Order Stories: </label>';
  213.         echo '<select name="' . $this->get_field_name( 'jflow_order' ) . '" id="' . $this->get_field_id( 'jflow_order' ) . '">';
  214.                 foreach ( $jflow_display_order as $jflow_d_order => $order_label ) {
  215.                     printf( '<option value="%s" %s>%s</option>', $jflow_d_order, selected( $jflow_d_order, genesis_get_option( 'jflow_order' ), 0 ), $order_label );
  216.                 }
  217.         echo '</select>';
  218.         echo '<p><span class="description">Select the story order.</span></p>';
  219.        
  220.  
  221.         echo '<label>Speed: </label><input type="text" name="' . $this->get_field_name( 'jflow_speed' ) . '" id="' . $this->get_field_id( 'jflow_speed' ) . '" value="' . esc_attr( $this->get_field_value( 'jflow_speed' ) ) . '" class="small-text" />';
  222.         echo '<label> Default: <code class="description">400</code></label>';
  223.         echo '<p><span class="description">This sets the transition speed of the featured content slider in milliseconds.</span></p>';
  224.     }
  225.    
  226. }
  227.  
  228. add_action( 'admin_menu', 'child_add_child_theme_settings', 2 );
  229. /**
  230.  * Add the Theme Settings Page
  231.  *
  232.  * @since 1.0.0
  233.  * @required Genesis
  234.  */
  235. function child_add_child_theme_settings() {
  236.     global $_child_theme_settings;
  237.     $_child_theme_settings = new Child_Theme_Settings;     
  238. }
  239.  
  240. add_action( 'genesis_meta', 'child_viewport_meta_tag' );
  241. /**
  242.  * Add viewport meta-tag to <head> for responsive design in mobile browsers.
  243.  *
  244.  * @author Greg Rickaby
  245.  * @since 1.0.0
  246.  * @required Genesis
  247.  */
  248. function child_viewport_meta_tag() {
  249.  
  250.         echo '<meta name="viewport" content="width=device-width, initial-scale=1.0"/>' . "\n";
  251.  
  252. }
  253.  
  254. add_action( 'wp_enqueue_scripts', 'child_scripts' );
  255. /**
  256.  * Load theme scripts and move jQuery to Google CDN.
  257.  *
  258.  * @author Greg Rickaby
  259.  * @since 1.0.0
  260.  */
  261. function child_scripts() {
  262.    
  263.     wp_deregister_script( 'jquery' );
  264.     wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' );
  265.     wp_enqueue_script( 'jflow', CHILD_URL . '/lib/js/jflow.plus.min.js', array('jquery'), '1.0', true );
  266.    
  267. }
  268.  
  269. add_action( 'wp_head', 'child_custom_stylesheet', 99 );
  270. /**
  271.  * Check for and load custom.css immediately before the </head> tag.
  272.  *
  273.  * @author Greg Rickaby
  274.  * @since 1.0.0
  275.  */
  276. function child_custom_stylesheet() {
  277.  
  278.     if ( genesis_get_option( 'custom_stylesheet', 'child-settings' ) )
  279.         echo '<link rel="stylesheet" href="'. CHILD_URL.'/custom/custom.css" type="text/css" media="screen" />' . "\n";
  280.        
  281. }
  282.  
  283. add_filter( 'body_class', 'child_style_body_class' );
  284. /**
  285.  * Filters the <body> class to add "custom".
  286.  *
  287.  * @since 1.0.0
  288.  */
  289. function child_style_body_class( $classes ) {
  290.  
  291.     if ( $style = genesis_get_option( 'style_selection', 'child-settings' ) ) {
  292.             $classes[] = esc_attr( sanitize_html_class( $style ) );
  293.     }  
  294.  
  295.     if ( genesis_get_option( 'custom_stylesheet', 'child-settings' ) ) {
  296.             $classes[] = 'custom';
  297.     }  
  298.  
  299.     return $classes;
  300. }
  301.  
  302. add_action( 'genesis_after', 'child_jflow_script', 99 );
  303. /**
  304.      * Check if homepage, then add jFlow javascript to footer.
  305.      *
  306.      * @author Greg Rickaby
  307.      * @since 1.0.0
  308.      * @requires jFlow script -> jflow.plus.min.js
  309.      * @requires jQuery 1.7 or later
  310.     */
  311. function child_jflow_script() {
  312.  
  313.     if ( is_front_page() ) {
  314.  
  315.     echo '<script type="text/javascript">';
  316.     echo '$(document).ready(function(){';
  317.         echo '$("#myController").jFlow({';
  318.             echo 'controller: ".jFlowControl",';
  319.             echo 'slideWrapper : "#jFlowSlider",';
  320.             echo 'slides: "#mySlides",';
  321.             echo 'selectedWrapper: "jFlowSelected",';
  322.             echo 'effect: "flow",';
  323.             echo 'width: "970px",';
  324.             echo 'height: "300px",';
  325.             echo 'pause: 5000,';
  326.             echo 'prev: ".jFlowPrev",';
  327.             echo 'next: ".jFlowNext",';
  328.             echo 'auto: true,';
  329.             $jflow = genesis_get_option( 'jflow_speed', 'child-settings' );
  330.             echo 'duration: '. $jflow . '';
  331.         echo '});';
  332.     echo '});';
  333.     echo '</script>';
  334. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement