= 0 ) ) ? true : false; if ( 'widgets.php' == $hook || $widgetload ): /* Enqueue Styles */ wp_enqueue_style( 'hoot-font-awesome' ); $style_uri = hoot_locate_style( trailingslashit( HOOT_CSS ) . 'admin-widgets' ); wp_enqueue_style( 'hoot-admin-widgets', $style_uri, array(), HOOT_VERSION ); /* Enqueue Color Picker Styles */ wp_enqueue_style( 'wp-color-picker' ); /* Enqueue Scripts including color-picker */ // Load admin-widgets in footer to maintain script heirarchy $script_uri = hoot_locate_script( trailingslashit( HOOT_JS ) . 'admin-widgets' ); wp_enqueue_script( 'hoot-admin-widgets', $script_uri, array( 'jquery', 'wp-color-picker' ), HOOT_VERSION, true ); /* Enqueues all scripts, styles, settings, and templates necessary to use all media JavaScript APIs. */ wp_enqueue_media(); endif; } add_action( 'admin_enqueue_scripts', 'hoot_enqueue_admin_widget_styles_scripts' ); } /** * Abstract Widgets Class for creating and displaying widgets. This file is only loaded if the theme supports * the 'hoot-core-widgets' feature. * * @credit() Derived from Vantage theme code by Greg Priday http://SiteOrigin.com * Licensed under GPL * * @since 1.0.0 * @access public */ abstract class Hoot_WP_Widget extends WP_Widget { protected $form_options; protected $repeater_html; /** * Register the widget and load the Widget options * * @since 1.0.0 */ function __construct( $id, $name, $widget_options = array(), $control_options = array(), $form_options = array() ) { $this->form_options = $form_options; parent::__construct( $id, $name, $widget_options, $control_options ); $this->initialize(); } /** * Initialize this widget in whatever way we need to. Runs before rendering widget or form. * * @since 1.0.0 */ function initialize(){ } /** * Display the widget. * * @since 1.0.0 * @param array $args * @param array $instance */ function widget( $args, $instance ) { $args = wp_parse_args( $args, array( 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', ) ); $defaults = array(); foreach( $this->form_options as $option ) { if ( isset( $option['id'] ) ) { $defaults[ $option['id'] ] = ( isset( $option['std'] ) ) ? $option['std'] : ''; } } $instance = wp_parse_args( $instance, $defaults ); echo $args['before_widget']; $title = ( !empty( $instance['title'] ) ) ? apply_filters( 'widget_title', $instance['title'] ) : ''; $this->display_widget( $instance, $args['before_title'], $title, $args['after_title'] ); echo $args['after_widget']; } /** * Echo the widget content * Subclasses should over-ride this function to generate their widget code. * Convention: Subclasses should include the template from the theme/widgets folder. * * @since 1.0.0 * @param array $args */ function display_widget( $instance, $before_title = '', $title='', $after_title = '' ) { die('function Hoot_WP_Widget::display_widget() must be over-ridden in a sub-class.'); } /** * Update the widget instance. * * @param array $new_instance * @param array $old_instance * @return array|void */ public function update( $new_instance, $old_instance ) { $new_instance = $this->sanitize( $new_instance, $this->form_options ); return $new_instance; } /** * Display the widget form. * * @since 1.0.0 * @param array $instance * @return string|void */ public function form( $instance ) { $form_id = 'hoot-widget-form-' . md5( uniqid( rand(), true ) ); $class_name = str_replace( '_', '-', strtolower( get_class($this) ) ); ?>
widget_options['help'] ) ) : ?>
widget_options['help']; ?>
form_options as $key => $field ) { $field = wp_parse_args( (array) $field, array( 'name' => '', 'desc' => '', 'id' => '', 'type' => '', 'settings' => array(), 'std' => '', 'options' => array(), 'fields' => array(), ) ); if ( empty( $field['id'] ) || empty( $field['type'] ) ) continue; $value = false; if ( isset( $instance[ $field['id'] ] ) ) $value = $instance[ $field['id'] ]; elseif ( !empty( $field['std'] ) ) $value = $field['std']; $this->render_field( $field, $value, false ); } ?>
/>
$s_title ) { ?>

$i_class ) { $selected = ( $value == $i_class ) ? ' selected' : ''; ?>
>
/>

$v ) { $this->render_group( $k, $v, $fields, $item_name, $repeater ); } } ?>
render_group( 975318642, array(), $fields, $item_name, $repeater ); $html = ob_get_clean(); $this->repeater_html[$id] = $html; ?>
hoot_get_field_id( $id, $repeater ), 'hoot-widget-input', $this->hoot_get_field_name( $id, $repeater ), $value ), $type ); break; } if ( ! empty( $desc ) ) echo '
' . esc_html( $desc ) . '
'; echo '
'; ?>
X

'', 'desc' => '', 'id' => '', 'type' => '', 'settings' => array(), 'std' => '', 'options' => array(), 'fields' => array(), ) ); $this->render_field( $field, isset( $value[ $field['id'] ] ) ? $value[ $field['id'] ] : false, $repeater ); } ?>
get_field_name( $id ); else { $repeater_extras = ''; foreach( $repeater as $r ) $repeater_extras .= '[' . $r . ']'; $repeater_extras .= '[' . esc_attr( $id ) . ']'; $name = $this->get_field_name('{{{FIELD_NAME}}}'); $name = str_replace( '[{{{FIELD_NAME}}}]', $repeater_extras, $name ); return $name; } } /** * Get the ID of this field. * * @since 1.0.0 * @param $id * @param array $repeater * @return string */ public function hoot_get_field_id( $id, $repeater = array() ) { if ( empty( $repeater ) ) return $this->get_field_id( $id ); else { $ids = $repeater; $ids[] = $id; return $this->get_field_id( implode( '-', $ids ) ); } } /** * Sanitize field values to store in database * * @since 1.1.7 * @param $instance * @param $fields */ public function sanitize( $instance, $fields ) { foreach ( $fields as $field ) { /* Skip if the field does not have an id/type */ if ( !isset( $field['id'] ) || !isset( $field['type'] ) ) continue; /* Skip if instance value is not set */ $id = $field['id']; if ( !isset( $instance[ $id ] ) ) continue; /* Sanitize field values */ switch ( $field['type'] ) { case 'textarea': global $allowedposttags; $instance[ $id ] = wp_kses( $instance[ $id ], $allowedposttags); break; case 'checkbox': $instance[ $id ] = ( !empty( $instance[ $id ] ) ) ? 1 : 0; break; case 'select': case 'radio': case 'images': $instance[ $id ] = ( isset( $field['options'][ $instance[ $id ] ] ) ) ? $instance[ $id ] : ''; break; case 'icon': $icons = hoot_enum_icons(); $instance[ $id ] = ( in_array( $instance[ $id ], $icons ) ) ? $instance[ $id ] : ''; break; case 'group': foreach ( $instance[ $id ] as $i => $subinstance ) { $instance[ $id ][ $i ] = $this->sanitize( $subinstance, $field['fields'] ); } break; } /* Custom sanitizations for specific field. Example, a text input has a url */ if ( isset( $field['sanitize'] ) ) { switch( $field['sanitize'] ) { case 'url': $instance[ $id ] = esc_url_raw( $instance[ $id ] ); break; case 'integer': $instance[ $id ] = intval( $instance[ $id ] ); $instance[ $id ] = ( !empty( $instance[ $id ] ) ) ? $instance[ $id ] : ''; break; case 'absint': $instance[ $id ] = absint( $instance[ $id ] ); $instance[ $id ] = ( !empty( $instance[ $id ] ) ) ? $instance[ $id ] : ''; break; case 'email': $instance[ $id ] = is_email( $instance[ $id ] ); break; // Allow custom sanitization functions default: $instance[ $id ] = apply_filters( 'widget_admin_sanitize_field', $instance[ $id ], $field['sanitize'], $instance ); } } } return $instance; } /** * Helper function to get a list for option values * * @since 1.0.0 * @param $post_type * @param $number Set to -1 to show all * @see: http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters * @return array */ // @todo more post types and taxonomies static function get_wp_list( $post_type = 'page', $number = false ) { $number = intval( $number ); if ( false === $number || empty( $number ) ) { $number = HOOT_ADMIN_LIST_ITEM_COUNT; if ( $post_type == 'page' ) { static $options_pages = array(); // cache if ( empty( $options_pages ) ) $options_pages = self::get_pages( $number ); return $options_pages; } } else { if ( $post_type == 'page' ) { $pages = self::get_pages( $number ); return $pages; } } } /** * Helper function to get a list of taxonomies * * @since 1.1.1 * @param $taxonomy * @return array */ static function get_tax_list( $taxonomy = 'category' ) { static $options_tax = array(); // cache if ( empty( $options_tax[ $taxonomy ] ) ) $options_tax[ $taxonomy ] = get_terms( $taxonomy, array( 'fields' => 'id=>name' ) ); return $options_tax[ $taxonomy ]; } /** * Get pages array * * @since 1.0.0 * @param int $number Set to -1 for all pages * @param string $post_type for custom post types * @return array */ static function get_pages( $number, $post_type = 'page' ){ // Doesnt allow -1 as $number // $options_pages_obj = get_pages("sort_column=post_parent,menu_order&number=$number"); // $options_pages[''] = __( 'Select a page:', 'chromatic' ); $options_pages = array(); $number = intval( $number ); global $post; $static = $post; // $post could be null $the_query = new WP_Query( array( 'post_type' => $post_type, 'posts_per_page' => $number, 'orderby' => 'post_title', 'order' => 'ASC' ) ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $options_pages[ get_the_ID() ] = get_the_title(); endwhile; wp_reset_postdata(); if ( empty( $static ) ) $post = $static; // Prcetabe plug endif; return $options_pages; } } /* Loads all available widget classes for the theme. */ hoot_load_widgets();