Add iCal feeds to calendars close #62
This commit is contained in:
@@ -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' );
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Calendar Feeds
|
||||
*
|
||||
* Based on a tutorial by Steve Thomas.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 1.4
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Calendar_Feeds
|
||||
*/
|
||||
class SP_Meta_Box_Calendar_Feeds {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
$feeds = new SP_Feeds();
|
||||
$calendar_feeds = $feeds->calendar;
|
||||
?>
|
||||
<div>
|
||||
<?php foreach ( $calendar_feeds as $slug => $name ) { ?>
|
||||
<?php $link = add_query_arg( 'feed', 'sp-calendar-' . $slug, get_post_permalink( $post ) ); ?>
|
||||
<p>
|
||||
<strong><?php echo $name; ?></strong>
|
||||
<a class="sp-link" href="<?php echo $link; ?>" target="_blank" title="<?php _e( 'Link', 'sportspress' ); ?>"></a>
|
||||
</p>
|
||||
<p>
|
||||
<input type="text" value="<?php echo $link; ?>" readonly="readonly" class="code widefat">
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
52
includes/class-sp-feeds.php
Normal file
52
includes/class-sp-feeds.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Feeds Class
|
||||
*
|
||||
* @class SP_Feeds
|
||||
* @version 1.4
|
||||
* @package SportsPress/Classes
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
*/
|
||||
class SP_Feeds {
|
||||
|
||||
/** @var array Array of feeds */
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* Constructor for the feeds class - defines all preset feeds.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$data = array(
|
||||
'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 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user