Split feed links and fix parsing issue when no location set
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* @author ThemeBoy
|
||||
* @category Feeds
|
||||
* @package SportsPress/Feeds
|
||||
* @version 1.4
|
||||
* @version 1.5
|
||||
*/
|
||||
|
||||
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.
|
||||
$output =
|
||||
"BEGIN:VCALENDAR\n" .
|
||||
"METHOD:PUBLISH\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" .
|
||||
"X-FROM-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";
|
||||
"REFRESH-INTERVAL;VALUE=DURATION:PT2M\n" .
|
||||
"X-PUBLISHED-TTL:PT2M\n";
|
||||
|
||||
// Loop through each event
|
||||
foreach ( $events as $event):
|
||||
@@ -129,10 +130,13 @@ foreach ( $events as $event):
|
||||
"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";
|
||||
"LAST-MODIFIED:" . mysql2date( $date_format, $event->post_modified_gmt ) . "\n";
|
||||
|
||||
if ( false !== $geo ) {
|
||||
if ( $location ) {
|
||||
$output .= "LOCATION:" . $location . "\n";
|
||||
}
|
||||
|
||||
if ( $geo ) {
|
||||
$output .= "GEO:" . $geo . "\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -25,15 +25,29 @@ class SP_Meta_Box_Calendar_Feeds {
|
||||
$calendar_feeds = $feeds->calendar;
|
||||
?>
|
||||
<div>
|
||||
<?php foreach ( $calendar_feeds as $feed => $name ) { ?>
|
||||
<?php $link = str_replace( array( 'http:', 'https:' ), 'webcal:', add_query_arg( 'feed', 'sp-' . $feed, untrailingslashit( get_post_permalink( $post ) ) ) ); ?>
|
||||
<p>
|
||||
<strong><?php echo $name; ?></strong>
|
||||
<a class="sp-link" href="<?php echo $link; ?>" title="<?php _e( 'Link', 'sportspress' ); ?>"></a>
|
||||
</p>
|
||||
<p>
|
||||
<input type="text" value="<?php echo $link; ?>" readonly="readonly" class="code widefat">
|
||||
</p>
|
||||
<?php foreach ( $calendar_feeds as $slug => $formats ) { ?>
|
||||
<?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>
|
||||
<strong><?php echo sp_array_value( $format, 'name' ); ?></strong>
|
||||
<a class="sp-link" href="<?php echo $feed; ?>" target="_blank" title="<?php _e( 'Link', 'sportspress' ); ?>"></a>
|
||||
</p>
|
||||
<p>
|
||||
<input type="text" value="<?php echo $feed; ?>" readonly="readonly" class="code widefat">
|
||||
</p>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
@@ -22,15 +22,27 @@ class SP_Feeds {
|
||||
public function __construct() {
|
||||
$data = 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 );
|
||||
|
||||
foreach ( $data as $type => $feeds ) {
|
||||
foreach ( $feeds as $slug => $name ) {
|
||||
$this->feed = $slug;
|
||||
foreach ( $data as $post_type => $feeds ) {
|
||||
foreach ( $feeds as $slug => $formats ) {
|
||||
add_feed( 'sp-' . $slug, array( $this, $slug . '_feed' ) );
|
||||
}
|
||||
}
|
||||
@@ -45,7 +57,7 @@ class SP_Feeds {
|
||||
}
|
||||
|
||||
public static function ical_feed() {
|
||||
$feed_template = SP()->plugin_path() . '/feeds/ical.php';
|
||||
$feed_template = SP()->plugin_path() . '/feeds/ical.php';
|
||||
load_template( $feed_template );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user