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', 'abbreviate_state', 'country', 'abbreviate_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, 'create_settings' ),
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' );
} // 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'
);
} // lay_settings_reg()
/**
* Creates the settings fields
*
* Accepts the $params from settings_reg() and creates a setting field
*
* @since 0.1
*
* @params $params The data specific to this setting field, comes from settings_reg()
*
* @uses checkbox
*/
function create_settings( $params ) {
$defaults = array( 'blank' => '', 'check' => '', 'class' => '', 'desc' => '', 'id' => '', 'label' => '', 'name' => '', 'selections' => '', 'size' => '', 'type' => '', 'value' => '' );
$args = wp_parse_args( $params, $defaults );
switch ( $args['type'] ) {
case ( 'email' ) :
case ( 'number' ) :
case ( 'tel' ) :
case ( 'url' ) :
case ( 'text' ) : echo $this->make_text( $args ); break;
case ( 'checkbox' ) : echo $this->make_checkbox( $args ); break;
case ( 'textarea' ) : echo $this->make_textarea( $args ); break;
case ( 'checkboxes' ) : echo $this->make_checkboxes( $args ); break;
case ( 'radios' ) : echo $this->make_radios( $args ); break;
case ( 'select' ) : echo $this->make_select( $args ); break;
case ( 'file' ) : echo $this->make_file( $args ); break;
case ( 'password' ) : echo $this->make_password( $args ); break;
} // End of $inputtype switch
} // create_settings_fn()
// 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.';
} // urls_section()
/**
* Writes the header for the display section
*/
function display_section() {
echo '
Choose what information you want displayed on your calendar.
';
} // 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.
';
} elseif ( $showfeed && !is_array( $showfeed ) ) {
foreach ( $showfeed->show as $show ) {
include( $this->get_adp_template( $params['layout'] ) );
++$count;
if ( $count == $maxshows ) { break; } // End of $maxshows check
} // End of $showfeed foreach
} // End of $showfeed empty check ?>
gensets['adp_date_format'];
$time = $adp->gensets['adp_time_format'];
$date_format = ( isset( $date ) && !empty( $date ) ? $date : get_option( 'date_format' ) );
$time_format = ( isset( $time ) && !empty( $time ) ? $time : get_option( 'time_format' ) );
$shows = new stdClass;
$shows->show = array( new stdClass, new stdClass, new stdClass );
$shows->show[0]->recordKey = 'NTVD-CJ-3N67231831062008';
$shows->show[0]->name = 'The Vibe Dials CD Release';
$shows->show[0]->city = 'Nashville';
$shows->show[0]->venueName = 'Ryman Auditorium';
$shows->show[0]->venueNameExt = 'Mother Church';
$shows->show[0]->showType = 'Club/Casino/Arena Show';
$shows->show[0]->venueZip = '37219';
$shows->show[0]->venuePhone = '615-889-3060';
$shows->show[0]->venueAddress = '116 5th Ave North';
$shows->show[0]->ticketURI = 'http://thevibedials.com';
$shows->show[0]->description = 'You\'ve made it when you\'re playing the Ryman.';
$shows->show[0]->ageLimit = 'All Ages';
$shows->show[0]->venueURI = 'http://www.ryman.com/';
$shows->show[0]->ticketPrice = '$10';
$shows->show[0]->date = date( $date_format );
$shows->show[0]->timeSet = date( $time_format, time() );
$shows->show[0]->gmtDate = gmdate( $date_format );
$shows->show[0]->showtimeZone = 'America/Chicago';
$shows->show[0]->timeDoors = date( $time_format, time() );
$shows->show[0]->directLink = '';
$shows->show[0]->posterImage = '';
$shows->show[0]->lastUpdate = date( $time_format, time() );
$shows->show[0]->stateAbbreviation = 'TN';
$shows->show[0]->state = 'Tennessee';
$shows->show[0]->countryAbbreviation = 'US';
$shows->show[0]->country = 'United States';
$shows->show[0]->timeZone = 'America/Chicago';
$shows->show[0]->deposit = '$100';
$shows->show[0]->depositReceived = date( $date_format );
$shows->show[0]->otherArtists = new stdClass;
$shows->show[0]->otherArtists->name = '';
$shows->show[0]->otherArtists->uri = '';
$shows->show[0]->otherArtists->timeSet = '';
$shows->show[0]->artistname = 'The Vibe Dials';
$shows->show[0]->artistKey = 'AR-8FAD4948ACC579CB';
$shows->show[1]->recordKey = 'NTVD-CJ-3N67231831062009';
$shows->show[1]->name = 'Bonnaroo Music Festival';
$shows->show[1]->city = 'Manchester';
$shows->show[1]->venueName = 'Bonnaroo Centeroo';
$shows->show[1]->venueNameExt = 'The Other Tent';
$shows->show[1]->showType = 'Festival / Fair';
$shows->show[1]->venueZip = '37355';
$shows->show[1]->venuePhone = '1-800Ð594-8499';
$shows->show[1]->venueAddress = 'New Bushy Branch Road';
$shows->show[1]->ticketURI = 'http://thevibedials.com';
$shows->show[1]->description = 'Bonnaroooooo!';
$shows->show[1]->ageLimit = 'All Ages';
$shows->show[1]->venueURI = 'http://www.bonnaroo.com/';
$shows->show[1]->ticketPrice = '$150';
$shows->show[1]->date = date( $date_format );
$shows->show[1]->timeSet = date( $time_format, time() );
$shows->show[1]->gmtDate = gmdate( $date_format );
$shows->show[1]->showtimeZone = 'America/Chicago';
$shows->show[1]->timeDoors = date( $time_format, time() );
$shows->show[1]->directLink = '';
$shows->show[1]->posterImage = '';
$shows->show[1]->lastUpdate = date( $time_format, time() );
$shows->show[1]->stateAbbreviation = 'TN';
$shows->show[1]->state = 'Tennessee';
$shows->show[1]->countryAbbreviation = 'US';
$shows->show[1]->country = 'United States';
$shows->show[1]->timeZone = 'America/Chicago';
$shows->show[1]->deposit = '$1000';
$shows->show[1]->depositReceived = date( $date_format );
$shows->show[1]->otherArtists = new stdClass;
$shows->show[1]->otherArtists->name = '';
$shows->show[1]->otherArtists->uri = '';
$shows->show[1]->otherArtists->timeSet = '';
$shows->show[1]->artistname = 'The Vibe Dials';
$shows->show[1]->artistKey = 'AR-8FAD4948ACC579CB';
$shows->show[2]->recordKey = 'NTVD-CJ-3N67231831062010';
$shows->show[2]->name = 'South by SouthWest Music Festival';
$shows->show[2]->city = 'Austin';
$shows->show[2]->venueName = 'The White Horse';
$shows->show[2]->venueNameExt = 'Main';
$shows->show[2]->showType = 'Festival / Fair';
$shows->show[2]->venueZip = '78702';
$shows->show[2]->venuePhone = '';
$shows->show[2]->venueAddress = '500 Comal St';
$shows->show[2]->ticketURI = 'http://thevibedials.com';
$shows->show[2]->description = '';
$shows->show[2]->ageLimit = '21+';
$shows->show[2]->venueURI = 'http://www.sxsw.com/';
$shows->show[2]->ticketPrice = '$595';
$shows->show[2]->date = date( $date_format );
$shows->show[2]->timeSet = date( $time_format, time() );
$shows->show[2]->gmtDate = gmdate( $date_format );
$shows->show[2]->showtimeZone = 'America/Chicago';
$shows->show[2]->timeDoors = date( $time_format, time() );
$shows->show[2]->directLink = '';
$shows->show[2]->posterImage = '';
$shows->show[2]->lastUpdate = date( $time_format, time() );
$shows->show[2]->stateAbbreviation = 'TX';
$shows->show[2]->state = 'Texas';
$shows->show[2]->countryAbbreviation = 'US';
$shows->show[2]->country = 'United States';
$shows->show[2]->timeZone = 'America/Chicago';
$shows->show[2]->deposit = '$100';
$shows->show[2]->depositReceived = date( $date_format );
$shows->show[2]->otherArtists = new stdClass;
$shows->show[2]->otherArtists->name = '';
$shows->show[2]->otherArtists->uri = '';
$shows->show[2]->otherArtists->timeSet = '';
$shows->show[2]->artistname = 'The Vibe Dials';
$shows->show[2]->artistKey = 'AR-8FAD4948ACC579CB';
return $shows;
} // get_example_data()
/**
* 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 );
if ( $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 ) {
$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;
} // parse_xml()
/**
* Creates shortcode [artistdatapress]
*
* Shortcode atts:
* maxshows how many shows to display
* feedurl The feed URL to use
*
* @param array $atts The attrbiutes from the shortcode
*
* @uses get_option
* @uses get_layout
*
* @return mixed $output Output of the buffer
*/
function shortcode( $atts ) {
ob_start();
$defaults = array( 'maxshows' => '', 'feedurl' => '' );
$args = wp_parse_args( $atts, $defaults );
$this->get_adp_layout( $args );
$output = ob_get_contents();
ob_end_clean();
return $output;
} // 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
} // widgets_init()
/* ==========================================================================
Slushman Toolkit Functions
========================================================================== */
/**
* Creates a single checkbox field based on the params
*
* @params are:
* check - used in the checked function (example: the plugin's saved option)
* class - used for the class attribute
* id - used for the id and name attributes
* label - the label to use in front of the field
* name - if the name needs to be separated from ID, otherwise its the ID field
*
* @since 0.1
*
* @param array $params An array of the data for the checkbox field
*
* @return mixed $output A properly formatted HTML checkbox with optional label and description
*/
function make_checkbox( $params ) {
$defaults = array( 'class' => '', 'id' => '', 'label' => '', 'name' => $params['id'] );
$params = wp_parse_args( $params, $defaults );
//$checked = checked( $params['check'], 1, FALSE );
$output = sprintf( ' ', $params['name'], $params['id'], $params['class'], $params['label'] );
return $output;
} // make_checkbox()
/**
* Creates a select menu based on the params
*
* @params are:
* blank - false for none, true if you want a blank option, or enter text for the blank selector
* class - used for the class attribute
* desc - description used for the description span
* id - used for the id and name attributes
* label - the label to use in front of the field
* name - the name of the field
* value - used in the selected function
* selections - an array of data to use as the selections in the menu
*
* @since 0.1
*
* @param array $params An array of the data for the select menu
*
* @return mixed $output A properly formatted HTML select menu with optional label and description
*/
function make_select( $params ) {
$defaults = array( 'class' => '', 'desc' => '', 'id' => '', 'label' => '', 'name' => $params['id'], 'value' => '' );
$params = wp_parse_args( $params, $defaults );
$output = ( !empty( $params['label'] ) ? sprintf( '', $params['id'], $params['label'] ) : '' );
$output .= sprintf( '';
$output .= ( !empty( $params['desc'] ) ? sprintf( ' %s', $params['desc'] ) : '' );
return $output;
} // make_select()
/**
* 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
* label - the label to use in front of the field
* name - (optional), can be a separate value from ID
* placeholder - The text that appears in th field before a value is entered.
* type - detemines the particular type of input field to be created
* value - used for the value attribute
*
* Inputtype options:
* email - email address
* text - standard text field (default)
* tel - phone numbers
* url - urls
*
* @since 0.1
*
* @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 make_text( $params ) {
$defaults = array( 'class' => '', 'desc' => '', 'id' => '', 'label' => '', 'name' => $params['id'], 'placeholder' => '', 'type' => 'text', 'value' => '' );
$params = wp_parse_args( $params, $defaults );
$value = ( $params['type'] == 'url' ? esc_url( $params['value'] ) : esc_attr( $params['value'] ) );
$output = ( !empty( $params['label'] ) ? sprintf( '', $params['id'], $params['label'] ) : '' );
$output .= sprintf( '', $params['type'], $params['id'], $params['name'], $value, $params['class'], $params['placeholder'] );
$output .= ( !empty( $params['desc'] ) ? sprintf( ' %s', $params['desc'] ) : '' );
return $output;
} // make_text()
/**
* 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 '
';
} // print_array()
} // class
} // class check
$adp = new ArtistDataPress_Plugin;
?>