Advertisement
gregrickaby

For Gary

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