diff --git a/feeds/ical.php b/feeds/ical.php new file mode 100644 index 00000000..4b8ec5e8 --- /dev/null +++ b/feeds/ical.php @@ -0,0 +1,105 @@ + 404 ) ); +} + +// Get events in calendar +$calendar = new SP_Calendar( $post ); +$events = $calendar->data(); + +// Get blog locale +$locale = substr( get_locale(), 0, 2 ); + +// Initialize output. Max line length is 75 chars. +$output = +"BEGIN:VCALENDAR\n" . +"METHOD:PUBLISH\n" . +"VERSION:2.0\n" . +"URL:" . add_query_arg( 'feed', 'sp-calendar-ical', get_post_permalink( $post ) ) . "\n" . +"NAME:" . $post->post_title . "\n" . +"X-WR-CALNAME:" . $post->post_title . "\n" . +"DESCRIPTION:" . $post->post_title . "\n" . +"DESCRIPTION:" . $post->post_title . "\n" . +"X-WR-CALDESC:" . $post->post_title . "\n" . +"REFRESH-INTERVAL;VALUE=DURATION:PT1H\n" . +"X-PUBLISHED-TTL:PT1H\n" . +"PRODID:-//ThemeBoy//SportsPress//" . strtoupper( $locale ) . "\n"; + +// Loop through each event +foreach ( $events as $event): + + // Define date format + $date_format = 'Ymd\THis\Z'; + + // Initialize end time + $end = new DateTime( $event->post_date_gmt ); + + // Get full time minutes + $minutes = get_post_meta( $event->post_id, 'sp_minutes', true ); + if ( false === $minutes ) $minutes = get_option( 'sportspress_event_minutes', 90 ); + + // Add full time minutes to end time + $end->add( new DateInterval( 'PT' . $minutes . 'M' ) ); + + // Initialize location + $location = ''; + + // Get venue information + $venues = get_the_terms( $event->ID, 'sp_venue' ); + if ( $venues ) { + $venue = reset( $venues ); + $location .= $venue->name; + + // Get venue term meta + $t_id = $venue->term_id; + $meta = get_option( "taxonomy_$t_id" ); + + // Add details to location + $address = sp_array_value( $meta, 'sp_address', false ); + if ( false !== $address ) { + $location = $address; + } + + // Generate geo tag + $latitude = sp_array_value( $meta, 'sp_latitude', false ); + $longitude = sp_array_value( $meta, 'sp_longitude', false ); + if ( false !== $latitude && false !== $longitude ) { + $geo = $latitude . ';' . $longitude; + } else { + $geo = false; + } + } + + // Append to output string + $output .= + "BEGIN:VEVENT\n" . + "SUMMARY:$event->post_title\n" . + "UID:$event->ID\n" . + "STATUS:CONFIRMED\n" . + "DTSTART:" . mysql2date( $date_format, $event->post_date_gmt ) . "\n" . + "DTEND:" . $end->format( $date_format ) . "\n" . + "LAST-MODIFIED:" . mysql2date( $date_format, $event->post_modified_gmt ) . "\n" . + "LOCATION:" . $location . "\n"; + + if ( false !== $geo ) { + $output .= "GEO:" . $geo . "\n"; + } + + $output .= "END:VEVENT\n"; +endforeach; + +// End output +$output .= "END:VCALENDAR"; + +echo $output; diff --git a/includes/admin/post-types/class-sp-admin-meta-boxes.php b/includes/admin/post-types/class-sp-admin-meta-boxes.php index e8566fc5..6bc6367f 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -131,6 +131,9 @@ class SP_Admin_Meta_Boxes { // Calendars add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_Calendar_Shortcode::output', 'sp_calendar', 'side', 'default' ); + if ( isset( $post ) && 'publish' == $post->post_status ): + add_meta_box( 'sp_feedsdiv', __( 'Feeds', 'sportspress' ), 'SP_Meta_Box_Calendar_Feeds::output', 'sp_calendar', 'side', 'default' ); + endif; add_meta_box( 'sp_formatdiv', __( 'Layout', 'sportspress' ), 'SP_Meta_Box_Calendar_Format::output', 'sp_calendar', 'side', 'default' ); add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Calendar_Details::output', 'sp_calendar', 'side', 'default' ); add_meta_box( 'sp_datadiv', __( 'Events', 'sportspress' ), 'SP_Meta_Box_Calendar_Data::output', 'sp_calendar', 'normal', 'high' ); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-feeds.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-feeds.php new file mode 100644 index 00000000..dd34bb0f --- /dev/null +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-feeds.php @@ -0,0 +1,41 @@ +calendar; + ?> +
+ array( + 'ical' => __( 'iCal', 'sportspress' ), + ), + ); + + $this->data = apply_filters( 'sportspress_feeds', $data ); + + foreach ( $data as $type => $feeds ) { + foreach ( $feeds as $slug => $name ) { + $this->feed = $slug; + add_feed( 'sp-' . $type . '-' . $slug, array( $this, 'load_' . $type . '_' . $slug . '_feed' ) ); + } + } + } + + public function __get( $key ) { + return ( array_key_exists( $key, $this->data ) ? $this->data[ $key ] : null ); + } + + public function __set( $key, $value ){ + $this->data[ $key ] = $value; + } + + public static function load_calendar_ical_feed() { + $feed_template = SP()->plugin_path() . '/feeds/ical.php'; + load_template( $feed_template ); + } +} + diff --git a/sportspress.php b/sportspress.php index 6504e410..378c4aa0 100644 --- a/sportspress.php +++ b/sportspress.php @@ -214,6 +214,7 @@ final class SportsPress { // Classes (used on all pages) include_once( 'includes/class-sp-countries.php' ); // Defines continents and countries include_once( 'includes/class-sp-formats.php' ); // Defines custom post type formats + include_once( 'includes/class-sp-feeds.php' ); // Adds feeds // Include template functions making them pluggable by plugins and themes. include_once( 'includes/sp-template-functions.php' ); @@ -269,6 +270,7 @@ final class SportsPress { // Load class instances $this->countries = new SP_Countries(); // Countries class $this->formats = new SP_Formats(); // Formats class + $this->feeds = new SP_Feeds(); // Feeds class // Load string options $this->text = get_option( 'sportspress_text', array() ); @@ -297,7 +299,7 @@ final class SportsPress { add_theme_support( 'post-thumbnails' ); // Add image sizes - add_image_size( 'sportspress-fit-thumbnail', 320, 320, false ); + add_image_size( 'sportspress-fit-medium', 300, 300, false ); add_image_size( 'sportspress-fit-icon', 128, 128, false ); add_image_size( 'sportspress-fit-mini', 32, 32, false ); }