. ************************************************************************** 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 ); ?>
Like this plugin? Want to help improve it? All donations will go towards improving ArtistDataPress, so donate $5, $10, or $20 now!
gensets['adp_time_format'] ); ?>
|
|
gensets['adp_date_format'] ); ?>
|
|
Please note: These settings do not apply to the iCal layout. |
| Please see the documentation on date and time formatting for additional formats.' ); ?> | ||
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() { ?> 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; ?>