Split feed links and fix parsing issue when no location set
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @category Feeds
|
* @category Feeds
|
||||||
* @package SportsPress/Feeds
|
* @package SportsPress/Feeds
|
||||||
* @version 1.4
|
* @version 1.5
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -27,17 +27,18 @@ $main_result = get_option( 'sportspress_primary_result', null );
|
|||||||
// Initialize output. Max line length is 75 chars.
|
// Initialize output. Max line length is 75 chars.
|
||||||
$output =
|
$output =
|
||||||
"BEGIN:VCALENDAR\n" .
|
"BEGIN:VCALENDAR\n" .
|
||||||
"METHOD:PUBLISH\n" .
|
|
||||||
"VERSION:2.0\n" .
|
"VERSION:2.0\n" .
|
||||||
|
"PRODID:-//ThemeBoy//SportsPress//" . strtoupper( $locale ) . "\n" .
|
||||||
|
"CALSCALE:GREGORIAN\n" .
|
||||||
|
"METHOD:PUBLISH\n" .
|
||||||
"URL:" . add_query_arg( 'feed', 'sp-calendar-ical', get_post_permalink( $post ) ) . "\n" .
|
"URL:" . add_query_arg( 'feed', 'sp-calendar-ical', get_post_permalink( $post ) ) . "\n" .
|
||||||
|
"X-FROM-URL:" . add_query_arg( 'feed', 'sp-calendar-ical', get_post_permalink( $post ) ) . "\n" .
|
||||||
"NAME:" . $post->post_title . "\n" .
|
"NAME:" . $post->post_title . "\n" .
|
||||||
"X-WR-CALNAME:" . $post->post_title . "\n" .
|
"X-WR-CALNAME:" . $post->post_title . "\n" .
|
||||||
"DESCRIPTION:" . $post->post_title . "\n" .
|
"DESCRIPTION:" . $post->post_title . "\n" .
|
||||||
"DESCRIPTION:" . $post->post_title . "\n" .
|
|
||||||
"X-WR-CALDESC:" . $post->post_title . "\n" .
|
"X-WR-CALDESC:" . $post->post_title . "\n" .
|
||||||
"REFRESH-INTERVAL;VALUE=DURATION:PT1H\n" .
|
"REFRESH-INTERVAL;VALUE=DURATION:PT2M\n" .
|
||||||
"X-PUBLISHED-TTL:PT1H\n" .
|
"X-PUBLISHED-TTL:PT2M\n";
|
||||||
"PRODID:-//ThemeBoy//SportsPress//" . strtoupper( $locale ) . "\n";
|
|
||||||
|
|
||||||
// Loop through each event
|
// Loop through each event
|
||||||
foreach ( $events as $event):
|
foreach ( $events as $event):
|
||||||
@@ -129,10 +130,13 @@ foreach ( $events as $event):
|
|||||||
"STATUS:CONFIRMED\n" .
|
"STATUS:CONFIRMED\n" .
|
||||||
"DTSTART:" . mysql2date( $date_format, $event->post_date_gmt ) . "\n" .
|
"DTSTART:" . mysql2date( $date_format, $event->post_date_gmt ) . "\n" .
|
||||||
"DTEND:" . $end->format( $date_format ) . "\n" .
|
"DTEND:" . $end->format( $date_format ) . "\n" .
|
||||||
"LAST-MODIFIED:" . mysql2date( $date_format, $event->post_modified_gmt ) . "\n" .
|
"LAST-MODIFIED:" . mysql2date( $date_format, $event->post_modified_gmt ) . "\n";
|
||||||
"LOCATION:" . $location . "\n";
|
|
||||||
|
|
||||||
if ( false !== $geo ) {
|
if ( $location ) {
|
||||||
|
$output .= "LOCATION:" . $location . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $geo ) {
|
||||||
$output .= "GEO:" . $geo . "\n";
|
$output .= "GEO:" . $geo . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,16 +25,30 @@ class SP_Meta_Box_Calendar_Feeds {
|
|||||||
$calendar_feeds = $feeds->calendar;
|
$calendar_feeds = $feeds->calendar;
|
||||||
?>
|
?>
|
||||||
<div>
|
<div>
|
||||||
<?php foreach ( $calendar_feeds as $feed => $name ) { ?>
|
<?php foreach ( $calendar_feeds as $slug => $formats ) { ?>
|
||||||
<?php $link = str_replace( array( 'http:', 'https:' ), 'webcal:', add_query_arg( 'feed', 'sp-' . $feed, untrailingslashit( get_post_permalink( $post ) ) ) ); ?>
|
<?php $link = add_query_arg( 'feed', 'sp-' . $slug, untrailingslashit( get_post_permalink( $post ) ) ); ?>
|
||||||
|
<?php foreach ( $formats as $format ) { ?>
|
||||||
|
<?php
|
||||||
|
$protocol = sp_array_value( $format, 'protocol' );
|
||||||
|
if ( $protocol ) {
|
||||||
|
$feed = str_replace( array( 'http:', 'https:' ), 'webcal:', $link );
|
||||||
|
} else {
|
||||||
|
$feed = $link;
|
||||||
|
}
|
||||||
|
$prefix = sp_array_value( $format, 'prefix' );
|
||||||
|
if ( $prefix ) {
|
||||||
|
$feed = $prefix . urlencode( $feed );
|
||||||
|
}
|
||||||
|
?>
|
||||||
<p>
|
<p>
|
||||||
<strong><?php echo $name; ?></strong>
|
<strong><?php echo sp_array_value( $format, 'name' ); ?></strong>
|
||||||
<a class="sp-link" href="<?php echo $link; ?>" title="<?php _e( 'Link', 'sportspress' ); ?>"></a>
|
<a class="sp-link" href="<?php echo $feed; ?>" target="_blank" title="<?php _e( 'Link', 'sportspress' ); ?>"></a>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<input type="text" value="<?php echo $link; ?>" readonly="readonly" class="code widefat">
|
<input type="text" value="<?php echo $feed; ?>" readonly="readonly" class="code widefat">
|
||||||
</p>
|
</p>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,27 @@ class SP_Feeds {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
$data = array(
|
$data = array(
|
||||||
'calendar' => array(
|
'calendar' => array(
|
||||||
'ical' => __( 'iCal', 'sportspress' ),
|
'ical' => array(
|
||||||
|
'apple' => array(
|
||||||
|
'name' => __( 'Apple Calendar', 'sportspress' ),
|
||||||
|
'protocol' => 'webcal',
|
||||||
|
),
|
||||||
|
'outlook' => array(
|
||||||
|
'name' => __( 'Outlook', 'sportspress' ),
|
||||||
|
'protocol' => 'webcal',
|
||||||
|
),
|
||||||
|
'google' => array(
|
||||||
|
'name' => __( 'Google', 'sportspress' ),
|
||||||
|
'prefix' => 'http://www.google.com/calendar/render?cid=',
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->data = apply_filters( 'sportspress_feeds', $data );
|
$this->data = apply_filters( 'sportspress_feeds', $data );
|
||||||
|
|
||||||
foreach ( $data as $type => $feeds ) {
|
foreach ( $data as $post_type => $feeds ) {
|
||||||
foreach ( $feeds as $slug => $name ) {
|
foreach ( $feeds as $slug => $formats ) {
|
||||||
$this->feed = $slug;
|
|
||||||
add_feed( 'sp-' . $slug, array( $this, $slug . '_feed' ) );
|
add_feed( 'sp-' . $slug, array( $this, $slug . '_feed' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user