. ************************************************************************** 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 ); ?>
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_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 '
'; print_r( $array ); echo ''; } // End of print_array() } // End of ArtistDataPress_Plugin } // End of class check new ArtistDataPress_Plugin; ?>