. ************************************************************************** To-Do List * Get time and date jquery previews working * * http://core.trac.wordpress.org/browser/trunk/wp-admin/options-general.php - see add_js * Create a templating system so users can create their own layouts * Add additional layouts * Add additional layouts for widgets * Check out admin_notices: http://www.instantshift.com/2012/03/06/21-most-useful-wordpress-admin-page-hacks/ * Auto-blog a post the day of a show with the details of that show * Add support for feeds from Sonicbids and Reverbnation - any others? */ require_once( dirname( __FILE__ ) . '/inc/adp_widget.php' ); if ( !class_exists( "ArtistDataPress_Plugin" ) ) { //Start Class class ArtistDataPress_Plugin { public static $instance; const PLUGIN_NAME = 'ArtistDataPress'; const OPTS_NAME = 'slushman_adp_options'; const GENSETS_NAME = 'slushman_adp_general_settings'; const LAYSETS_NAME = 'slushman_adp_layout_settings'; const PLUGIN_SLUG = 'slushman-adp'; private $settings_tabs = array(); /** * Constructor */ function __construct() { self::$instance = $this; // Runs when plugin is activated register_activation_hook( __FILE__, array( $this, 'create_options' ) ); // Adds the ArtistDataPress option menu to the Settings menu add_action( 'admin_menu', array( $this, 'add_menu' ) ); // Add "Settings" link to plugin page add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ) , array( $this, 'settings_link' ) ); // Create shortcode [artistdatapress] add_shortcode( 'artistdatapress', array( $this, 'shortcode' ) ); // Include other files add_action( 'init', array( $this, 'file_includer' ) ); // Register and define the settings add_action( 'admin_init', array( $this, 'gen_settings_reg' ) ); add_action( 'admin_init', array( $this, 'lay_settings_reg' ) ); // Enqueue stylesheets add_action( 'wp_enqueue_scripts', array( $this, 'add_styles' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'add_styles' ) ); // Enqueue scripts // add_action( 'admin_enqueue_scripts', array( $this, 'example_js' ) ); // Register the widget if its selected add_action( 'widgets_init', array( $this, 'widgets_init' ) ); $this->gensets = (array) get_option( self::GENSETS_NAME ); $this->laysets = (array) get_option( self::LAYSETS_NAME ); $this->widgets = array( 'ArtistDataPress' ); //$this->layouts = array( 'Classic', 'iCal', 'Classic Widget' ); } // End of __construct() /** * Creates the plugin settings * * Creates an array containing each setting and sets the default values to blank. * Then saves the array in the plugin option. * * @since 0.1 * * @uses get_option * @uses delete_option * @uses update_option */ function create_options() { if ( get_option( self::OPTS_NAME ) ) { $options = get_option( self::OPTS_NAME ); $general['XML_feed_URL'] = $options['slushman_adp_xml_url']; $general['profile_URL'] = $options['slushman_adp_adpage_url']; $general['how_many_shows'] = $options['slushman_adp_max_shows']; $general['no_shows_message'] = $options['slushman_adp_no_shows']; $general['show_name'] = $options['slushman_adp_display_name']; $general['show_time'] = $options['slushman_adp_display_time']; $general['ticket_price'] = $options['slushman_adp_display_tickets']; $general['age_limit'] = $options['slushman_adp_display_age']; $general['display_artist'] = $options['slushman_adp_display_artist']; $general['country'] = $options['slushman_adp_display_country']; $general['XML_feed_URL'] = $general['xml_url']; $general['profile_URL'] = $general['adpage_url']; $general['how_many_shows'] = $general['max_shows']; $general['no_shows_message'] = $general['no_shows_msg']; $general['show_name'] = $general['display_name']; $general['venue_stage'] = $general['display_stage']; $general['artist_name'] = $general['display_artist']; $general['ticket_price'] = $general['display_tickets']; $general['age_limit'] = $general['display_age']; $general['country'] = $general['display_country']; $general['show_time'] = $general['display_time']; $general['adp_time_format'] = $general['adp_date_format'] = ''; $layout['adp_layout'] = 'Classic'; delete_option( self::OPTS_NAME ); } else { $general['XML_feed_URL'] = $general['profile_URL'] = $general['how_many_shows'] = $general['show_name'] = $general['show_time'] = $general['show_description'] = $general['venue_phone'] = $general['ticket_price'] = $general['age_limit'] = $general['artist_name'] = $general['country'] = $general['venue_stage'] = $general['adp_time_format'] = $general['adp_date_format'] = ''; $general['no_shows_message'] = 'There are no shows currently scheduled.'; $layout['adp_layout'] = 'Classic'; } // End of previous options check update_option( self::GENSETS_NAME, $general ); update_option( self::LAYSETS_NAME, $layout ); } // End of create_options() /* ========================================================================== Plugin Settigns ========================================================================== */ /** * Adds the plugin settings page to the appropriate admin menu * * @since 0.1 * * @uses add_options_page */ function add_menu() { add_options_page( self::PLUGIN_NAME . 'Options', self::PLUGIN_NAME, 'manage_options', self::PLUGIN_SLUG, array( $this, 'settings_page' ) ); } // End of add_menu() /** * Adds a link to the plugin settings page to the plugin's listing on the plugin page * * @since 0.1 * * @uses admin_url */ function settings_link( $links ) { $slushman_adp_settings_link = sprintf( '%s', admin_url( 'options-general.php?page=' . self::PLUGIN_SLUG ), __( 'Settings' ) ); array_unshift( $links, $slushman_adp_settings_link ); return $links; } // End of settings_link() /** * Creates the settings page * * @since 0.1 * * @uses plugins_url * @uses settings_fields * @uses do_settings_sections * @uses submit_button */ function settings_page() { $tab = ( isset( $_GET['tab'] ) ? $_GET['tab'] : self::GENSETS_NAME ); ?>


Support and Improve ADP

Like this plugin? Want to help improve it? All donations will go towards improving ArtistDataPress, so donate $5, $10, or $20 now!

settings_tabs[self::GENSETS_NAME] = self::PLUGIN_NAME . 'Settings'; register_setting( self::GENSETS_NAME, self::GENSETS_NAME, array( $this, 'validate_options' ) ); $sections = array( 'URL', 'display', 'time_and_date' ); foreach ( $sections as $section ) { $secname = ( str_replace( '_', ' ', $section ) ); add_settings_section( 'slushman_adp_' . $section, 'ArtistDataPress ' . ucwords( $secname ) . ' Options', array( $this, $section . '_section' ), self::GENSETS_NAME ); } // End of $sections foreach $fields['URL'][0]['name'] = $fields['URL'][0]['args']['id'] = 'XML_feed_URL'; $fields['URL'][0]['args']['class'] = 'slushman_adp_text_field'; $fields['URL'][0]['args']['name'] = self::GENSETS_NAME . '[XML_feed_URL]'; $fields['URL'][0]['args']['type'] = 'url'; $fields['URL'][0]['args']['value'] = $this->gensets['XML_feed_URL']; $fields['URL'][1]['name'] = $fields['URL'][1]['args']['id'] = 'profile_URL'; $fields['URL'][1]['args']['class'] = 'slushman_adp_text_field'; $fields['URL'][1]['args']['name'] = self::GENSETS_NAME . '[profile_URL]'; $fields['URL'][1]['args']['type'] = 'url'; $fields['URL'][1]['args']['value'] = $this->gensets['profile_URL']; $fields['display'][0]['name'] = $fields['display'][0]['args']['id'] = 'how_many_shows'; $fields['display'][0]['args']['name'] = self::GENSETS_NAME . '[how_many_shows]'; $fields['display'][0]['args']['type'] = 'number'; $fields['display'][0]['args']['value'] = ( empty( $this->gensets['how_many_shows'] ) ? 'All' : $this->gensets['how_many_shows'] );; $checkboxes = array( 'age_limit', 'artist_name', 'country', 'show_description', 'show_name', 'show_time', 'ticket_price', 'venue_phone', 'venue_stage' ); $count = 1; foreach ( $checkboxes as $checkbox ) { $fields['display'][$count]['name'] = $fields['display'][$count]['args']['id'] = $checkbox; $fields['display'][$count]['args']['name'] = self::GENSETS_NAME . '[' . $checkbox . ']'; $fields['display'][$count]['args']['type'] = 'checkbox'; $fields['display'][$count]['args']['check'] = $this->gensets[$checkbox]; $count++; } // End of $checkboxes foreach $fields['display'][$count]['name'] = $fields['display'][$count]['args']['id'] = 'no_shows_message'; $fields['display'][$count]['args']['class'] = 'slushman_adp_text_field'; $fields['display'][$count]['args']['name'] = self::GENSETS_NAME . '[no_shows_message]'; $fields['display'][$count]['args']['type'] = 'text'; $fields['display'][$count]['args']['value'] = $this->gensets['no_shows_message']; foreach ( $fields as $section => $field ) { foreach ( $field as $data ) { extract( $data ); $plain = str_replace( '_', ' ', $name ); $fieldname = 'slushman_adp_' . $name . '_field'; switch ( $section ) { case ( 'URL' ) : $title = 'ArtistData ' . ucwords( $plain ); break; case ( 'display' ) : $title = 'Display ' . ucwords( $plain ) . '?'; break; case ( 'time_and_date' ) : $title = ucwords( $plain ) . ' Format'; break; } // End of $section switch add_settings_field( $fieldname, $title, array( $this, 'make_settings_field' ), self::GENSETS_NAME, 'slushman_adp_' . $section, $args ); } // End of $field foreach } // End of $fields foreach add_settings_field( 'slushman_adp_time_format_field', 'Time format:', array( $this, 'display_time_format_field' ), self::GENSETS_NAME, 'slushman_adp_time_and_date' ); add_settings_field( 'slushman_adp_date_format_field', 'Date format:', array( $this, 'display_date_format_field' ), self::GENSETS_NAME, 'slushman_adp_time_and_date' ); } // End of gen_settings_reg() /** * Registers the layout tab plugin option, settings, and sections * * Instead of writing the registration for each field, I used a foreach loop to write them all. * add_settings_field has an argument that can pass data to the callback, which I used to send the specifics * of each setting field to the callback that actually creates the setting field. * * @since 0.42 * * @uses register_setting * @uses add_settings_section * @uses add_settings_field */ function lay_settings_reg() { $this->settings_tabs[self::LAYSETS_NAME] = self::PLUGIN_NAME . ' Layouts'; register_setting( self::LAYSETS_NAME, self::LAYSETS_NAME ); add_settings_section( 'slushman_adp_layout', 'Choose the Layout', array( $this, 'layout_section' ), self::LAYSETS_NAME ); add_settings_field( 'slushman_adp_layout_field', 'Choose the layout for your events.', array( $this, 'layout_preference_field' ), self::LAYSETS_NAME, 'slushman_adp_layout' ); } // End of lay_settings_reg() /** * Creates the settings fields * * Accepts the $params from settings_reg() and creates a setting field * * @since 0.42 * * @params array $params The data specific to this setting field, comes from settings_reg() * * @uses checked * @uses Slushman_Toolkit::checkbox * @uses Slushman_Toolkit::input_type */ function make_settings_field( $params ) { $check = array( 'check', 'class', 'desc', 'id', 'label', 'name', 'type', 'value' ); foreach ( $check as $field ) { $args[$field] = ( !empty( $params[$field] ) ? $params[$field] : '' ); } // End of $params foreach $args['selections'] = ( isset( $params['selections'] ) ? $params['selections'] : '' ); switch ( $args['type'] ) { case ( 'email' ) : case ( 'file' ) : case ( 'number' ) : case ( 'tel' ) : case ( 'url' ) : case ( 'text' ) : echo $this->input_field( $args ); break; case ( 'checkbox' ) : echo $this->checkbox( $args ); break; case ( 'textarea' ) : echo $this->textarea( $args ); break; case ( 'checkgroup' ) : echo $this->make_checkboxes( $args ); break; case ( 'radios' ) : echo $this->make_radios( $args ); break; case ( 'select' ) : echo $this->make_select( $args ); break; } // End of $inputtype switch } // End of make_settings_field() // Settings Fields /** * Writes the HTML for the time_format field */ function display_time_format_field() { ?>
gensets['adp_time_format'] ); ?>
  • Examples...
  • =
gensets['adp_date_format'] ); ?>
  • Examples...
  • =
Please note: These settings do not apply to the iCal layout.
Please see the documentation on date and time formatting for additional formats.' ); ?>
The ArtistData XML feed URL can be found on your ArtistData account by going to Tools > Data Feeds.

'; } // End of urls_section() /** * Writes the header for the display section */ function display_section() { echo '

Choose what information you want displayed on your calendar.

'; } // End of display_section() /** * Writes the header for the time_and_date section */ function time_and_date_section() { echo '

Choose how you want to format your times and dates.

'; } // End of time_and_date_section() /** * Writes the header for the layout section */ function layout_section() { echo ''; } // End of layout_section() /** * Writes the HTML for the time_format field */ /* function example_js() { ?>


get_layout( array( 'layout' => $choice, 'limit' => 3, 'source' => 'plugsets' ) ); ?>
gensets[$check] : $input[$check] ); $valid[$check] = ( isset( $input[$check] ) && $input[$check] ? true : false ); } // End of $checks foreach return $valid; } // End of validate_options() /* ========================================================================== Styles and Scripts ========================================================================== */ /** * Registers all the styles and enqueues the public-facing style * * @uses wp_register_style * @uses plugins_url * @uses wp_enqueue_style */ function add_styles() { wp_register_style( self::PLUGIN_SLUG, plugins_url( 'css/artistdatapress.css', __FILE__ ) ); wp_enqueue_style( self::PLUGIN_SLUG ); } // End of add_styles() /* ========================================================================== Plugin Functions ========================================================================== */ /** * Include other files * * Includes all files containing functions outside the class. * * @since 0.37 */ function file_includer() { require( 'inc/layout.php' ); } // End of file_includer() /** * Processes and outputs the raw ArtistData XML feed * * Gets the transient, if there isn't one already, fetches the XML feed * using wp_remote_get & wp_remote_retrieve_body then parses the XML * into an array using SimpleXML. * * The transient is saved for one hour. * * @since 0.6 * * @uses md5 * @uses get_transient * @uses wp_remote_get * @uses is_wp_error * @uses wp_remote_retrieve_body * @uses set_transient * @uses simplexml_load_string * * @return array $xml An array of data from the ArtistData XML */ function parse_xml( $url ) { $key = md5( $url ); $xml = get_transient( 'adp_' . $key ); if ( !$xml && $url ) { $response = wp_remote_get( $url, array( 'timeout' => 15 ) ); if ( !is_wp_error( $response ) ) { $xml = wp_remote_retrieve_body( $response ); } // End of wp_error check } // End of $output && $url checks if ( $xml ) { set_transient( 'adp_' . $key, $xml, HOUR_IN_SECONDS ); $output = @simplexml_load_string( $xml ); } else { $output = array( 'Error', 'There seems to be a problem with your feed URL.' ); } // End of $xml check return $output; } // End of parse_xml() /** * Creates shortcode [artistdatapress] * * @uses get_option * @uses get_layout * * @return mixed $output Output of the buffer */ function shortcode( $atts ) { ob_start(); $layset = get_option( self::LAYSETS_NAME ); $layargs['layout'] = $layset['adp_layout']; $layargs['limit'] = ( !empty( $atts['maxshows'] ) ? $atts['maxshows'] : '' ); $layargs['feedurl'] = ( !empty( $atts['feedurl'] ) ? $atts['feedurl'] : '' ); $layout = new Layout; $this->get_layout( $layargs ); $output = ob_get_contents(); ob_end_clean(); return $output; } // End of shortcode() /** * Registers widgets with WordPress * * @since 0.5 * * @uses register_widget */ function widgets_init() { foreach ( $this->widgets as $field ) { $widget = str_replace( ' ', '_', strtolower( $field ) ) . '_widget'; register_widget( $widget ); } // End of $fields foreach } // End of widgets_init() /* ========================================================================== Get Layouts ========================================================================== */ /** * Displays the user's chosen layout * * Gets the options and calls the correct function to display that layout's HTML. * * Limit is for only showing x-many on the layout options page * * Source is for specifying that the request is from the plugin settings page * * @since 0.4 * * @params array $params Includes data: layout, limit, source * * @uses classic_layout * @uses ical_layout */ function get_layout( $params ) { $layout = new Layout; $genset = get_option( self::GENSETS_NAME ); $url = ( isset( $params['feedurl'] ) && !empty( $params['feedurl'] ) ? $params['feedurl'] : $genset['XML_feed_URL'] ); $feed = $this->parse_xml( $url ); $showfeed = ( ( $feed[0] == 'Error' || !$feed ) && $params['source'] == 'plugsets' ? $layout->get_example_data() : $feed ); $maxshows = ( !empty( $params['limit'] ) ? $params['limit'] : $genset['how_many_shows'] ); $count = 0; echo '
'; if ( !$showfeed && $params['source'] != 'plugsets' ) { echo '
' . $genset['no_shows_message'] . '
'; } elseif ( $showfeed && is_array( $showfeed ) && $showfeed[0] == 'Error' ) { echo '
' . $showfeed[1] . '
'; } elseif ( $showfeed && !is_array( $showfeed ) ) { foreach ( $showfeed->show as $show ) { include( dirname( __FILE__ ) . '/layouts/' . $params['layout'] . '.php' ); ++$count; if ( $count == $maxshows ) { break; } // End of $maxshows check } // End of $showfeed foreach } // End of $showfeed empty check ?>
parse_xml( $feed ); $count = 0; echo ' '; return $output; } // End of checkbox() /** * Creates an input field based on the params * * Creates an input field based on the params * * @params are: * class - used for the class attribute * desc - description used for the description span * id - used for the id and name attributes * type - detemines the particular type of input field to be created * label - the label to use in front of the field * name - (optional), can be a separate value from ID * placeholder - The that appears in th field before a value is entered. * value - used for the value attribute * * Inputtype options: * email - email address * file - file upload * number - number field * text - standard text field * search - search field * tel - phone numbers * url - url * * @since 0.6 * * @param array $params An array of the data for the text field * * @return mixed $output A properly formatted HTML input field with optional label and description */ function input_field( $params ) { extract( $params ); $showid = ( !empty( $id ) ? ' id="' . $id . '" name="' . ( !empty( $name ) ? $name : $id ) . '"' : '' ); $showclass = ( !empty( $class ) ? ' class="' . $class . '"' : '' ); $showtype = ( !empty( $type ) ? ' type="' . $type . '"' : '' ); $showvalue = ( !empty( $value ) ? ' value="' . $value . '"' : 'value=""' ); $showph = ( !empty( $placeholder ) ? ' placeholder="' . $placeholder . '"' : '' ); $output = ( !empty( $label ) ? '' : '' ); $output .= ''; $output .= ( !empty( $desc ) ? '
' . $desc . '' : '' ); return $output; } // End of input_field() /** * Display an array in a nice format * * @param array The array you wish to view */ public function print_array( $array ) { echo '
';
		  
		  print_r( $array );
		  
		  echo '
'; } // End of print_array() } // End of ArtistDataPress_Plugin } // End of class check new ArtistDataPress_Plugin; ?>