. ************************************************************************** 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 * 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, 'admin_enqueue' ) ); // 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( 'urls', '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['urls'][0]['name'] = $fields['urls'][0]['args']['id'] = 'XML_feed_URL'; $fields['urls'][0]['args']['class'] = 'slushman_adp_text_field'; $fields['urls'][0]['args']['name'] = self::GENSETS_NAME . '[XML_feed_URL]'; $fields['urls'][0]['args']['inputtype'] = 'urls'; $fields['urls'][0]['args']['value'] = $this->gensets['XML_feed_URL']; $fields['urls'][1]['name'] = $fields['urls'][1]['args']['id'] = 'profile_URL'; $fields['urls'][1]['args']['class'] = 'slushman_adp_text_field'; $fields['urls'][1]['args']['name'] = self::GENSETS_NAME . '[profile_URL]'; $fields['urls'][1]['args']['inputtype'] = 'urls'; $fields['urls'][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']['inputtype'] = 'text'; $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']['inputtype'] = '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']['inputtype'] = '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 ( 'urls' ) : $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', 'inputtype', 'label', 'name', 'value' ); foreach ( $check as $field ) { $args[$field] = ( !empty( $params[$field] ) ? $params[$field] : '' ); } // End of $params foreach // Begin no Slushman Toolkit code extract( $args ); if ( $inputtype == 'text' || $inputtype == 'urls' ) { $showsize = ( $inputtype == 'textarea' ? ' cols="50" rows="10"' : '' ); $showvalue = ( !empty( $value ) ? $value : '' ); $name = ( !empty( $name ) ? $name : $id ); $output = ( !empty( $label ) ? '' : '' ); $output .= ''; $output .= ( !empty( $desc ) ? '
' . $desc . '' : '' ); echo $output; } elseif ( $inputtype == 'checkbox' ) { $show_value = ( !empty( $value ) ? ' value="' . $value . '"' : '' ); $checked = ( isset( $check ) ? (bool) $check : false ); $output = ''; $output .= ''; echo $output; } // End of field_type check /* Slushman Toolkit code if ( $inputtype == 'text' || $inputtype == 'urls' ) { Slushman_Toolkit::input_field( $args ); } elseif ( $inputtype == 'checkbox' ) { Slushman_Toolkit::checkbox( $args ); } // End of $inputtype check */ } // 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' => 'layout' ) ); ?>
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_register_style( 'slushman-adp-layout-classic', plugins_url( 'css/classic.css', __FILE__ ) ); wp_register_style( 'slushman-adp-layout-ical', plugins_url( 'css/ical.css', __FILE__ ) ); wp_register_style( 'slushman-adp-layout-classic-widget', plugins_url( 'css/classic_widget.css', __FILE__ ) ); wp_register_style( 'slushman-adp-layout-ical-widget', plugins_url( 'css/ical_widget.css', __FILE__ ) ); wp_enqueue_style( self::PLUGIN_SLUG ); } // End of add_styles() /** * Enqueues the layout styles * * @uses wp_enqueue_style * @uses plugins_url */ function admin_enqueue( $hook ) { wp_enqueue_style( 'slushman-adp-layout-classic', plugins_url( 'css/classic.css', __FILE__ ) ); wp_enqueue_style( 'slushman-adp-layout-ical', plugins_url( 'css/ical.css', __FILE__ ) ); } // End of admin_enqueue /* ========================================================================== 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 * * Fetches the XML feed using wp_remote_get & wp_remote_retrieve_body * then parses the XML into an array using SimpleXML. * * @since 0.5 * * @uses get_option * @uses wp_remote_get * @uses wp_remote_retrieve_body * @uses libxml_use_internal_errors * @uses SimpleXmlElement * @uses libxml_get_errors * * @return array $output An array of data from the ArtistData XML */ function parse_xml( $feedurl ) { $xml = wp_remote_retrieve_body( wp_remote_get( $feedurl ) ); libxml_use_internal_errors( true ); try { $data = new SimpleXMLElement( $xml ); } catch ( Exception $e ) { $error_message = 'SimpleXMLElement threw an exception.'; foreach( libxml_get_errors() as $error_line ) { $error_message .= "\t" . $error_line->message; return $error_message; } // End of libxml_get_errors foreach trigger_error( $error_message ); $error = array( 'Error', 'There seems to be a problem with your feed URL.' ); return $error; } // End of try / catch if ( $data != FALSE ) { $output = ( !empty( $data->show[0]->recordKey ) ? $data : FALSE ); return $output; } // End of $data check } // 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(); $maxshows = ( !empty( $atts['maxshows'] ) ? $atts['maxshows'] : '' ); $feedurl = ( !empty( $atts['feedurl'] ) ? $atts['feedurl'] : '' ); $options = get_option( self::LAYSETS_NAME ); $layout_opt = $options['adp_layout']; $layout = new Layout; $this->get_layout( array( 'layout' => $layout_opt, 'limit' => $maxshows, 'feedurl' => $feedurl ) ); $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, then registers and enqueues the correct CSS 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 layout options page * * @since 0.4 * * @params array $params Includes data: layout, limit, source * * @uses classic_layout * @uses ical_layout */ function get_layout( $params ) { if( !empty( $params ) ) { extract( $params ); } extract( get_option( 'slushman_adp_general_settings' ) ); $style = strtolower( $layout ); wp_enqueue_style( 'slushman-adp-layout-' . $style ); $feedurl = ( isset( $feedurl ) && !empty( $feedurl ) ? $feedurl : $XML_feed_URL ); $feed = $this->parse_xml( $feedurl ); $layout = new Layout; $showfeed = ( $feed[0] == 'Error' && $source == 'layout' || $feed == FALSE && $source == 'layout' ? $layout->get_example_data() : $feed ); $maxshows = ( !empty( $limit ) ? $limit : $how_many_shows ); $count = 0; ?>
' . $no_shows_message . '
'; } elseif ( $showfeed !== FALSE && is_array( $showfeed ) && $showfeed[0] == 'Error' ) { echo '
' . $showfeed[1] . '
'; } elseif ( $showfeed !== FALSE && !is_array( $showfeed ) ) { foreach ( $showfeed->show as $show ) { include( dirname( __FILE__ ) . '/layouts/' . $style . '.php' ); ++$count; if ( $count == $maxshows ) { break; } // End of $maxshows check } // End of $showfeed foreach } // End of $showfeed empty check ?> parse_xml( $feedurl ); $layout = new Layout; $showfeed = ( $feed[0] == 'Error' && $source == 'layout' || $feed == FALSE && $source == 'layout' ? $layout->get_example_data() : $feed ); $count = 0; ?>