Last active
December 12, 2015 05:48
-
-
Save DerekMarcinyshyn/4724477 to your computer and use it in GitHub Desktop.
All-in-one-Calendar RSS feed with additional items for simple API use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* RSS2 Feed Template for displaying RSS2 Posts feed. | |
* | |
* @package WordPress | |
*/ | |
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . Ai1ec_Meta::get_option( 'blog_charset' ), true); | |
echo '<?xml version="1.0" encoding="', | |
Ai1ec_Meta::get_option( 'blog_charset' ), | |
'"?'.'>'; ?> | |
<rss version="2.0" | |
xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
xmlns:wfw="http://wellformedweb.org/CommentAPI/" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:atom="http://www.w3.org/2005/Atom" | |
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" | |
xmlns:slash="http://purl.org/rss/1.0/modules/slash/" | |
<?php do_action('rss2_ns'); ?> | |
> | |
<channel> | |
<title><?php bloginfo_rss('name'); wp_title_rss(); ?></title> | |
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" /> | |
<link><?php bloginfo_rss('url') ?></link> | |
<description><?php bloginfo_rss("description") ?></description> | |
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate> | |
<language><?php bloginfo_rss( 'language' ); ?></language> | |
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod> | |
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency> | |
<?php | |
foreach ( $event_results['events'] as $event ){ | |
$title = htmlspecialchars( $event->post->post_title ); | |
$permalink = htmlspecialchars( get_permalink( $event->post_id ) ); | |
$date = date('d M Y H:i:s', $event->start ); | |
$user_info = get_userdata( $event->post->post_author ); | |
$location = str_replace( "\n", ', ', rtrim( $event->get_location() ) ); | |
$use_excerpt = Ai1ec_Meta::get_option( 'rss_use_excerpt' ); | |
$description = $event->post->post_content; | |
if( $use_excerpt ) { | |
$description = Ai1ec_String_Utility::truncate_string_if_longer_than_x_words( | |
$event->post->post_content, | |
50, | |
" <a href='$permalink' >" . __( 'Read more...', AI1EC_PLUGIN_NAME ) . "</a>" | |
); | |
} | |
$args = array( | |
"timespan" => $event->get_timespan_html(), | |
"location" => $location, | |
"permalink" => $permalink, | |
"description" => wpautop( $description ) | |
); | |
// Load the RSS specific template | |
ob_start(); | |
$ai1ec_view_helper->display_theme( 'event-feed-description.php', $args ); | |
$content = ob_get_contents(); | |
ob_end_clean(); | |
$user = $user_info->user_login; | |
$guid = htmlspecialchars( get_the_guid( $event->post_id ) ); | |
$comments = esc_url( get_post_comments_feed_link( $event->post_id, 'rss2' ) ); | |
$comments_number = get_comments_number( $event->post_id ); | |
// rmedia events | |
// @author Derek Marcinyshyn <derek.marcinyshyn.com> | |
date_default_timezone_set('America/Los_Angeles'); | |
$timespan = date( 'g:i a', $event->start) . ' - ' .date( 'g:i a', $event->end); | |
$event_month = date( 'M', $event->start ); | |
$event_day = date( 'd', $event->start ); | |
$no_img_desc = preg_replace("/<img[^>]+\>/i", "", $description ); | |
echo <<<FEED | |
<item> | |
<title>$title</title> | |
<link>{$permalink}{$event->instance_id}</link> | |
<pubDate>$date</pubDate> | |
<dc:creator>$user</dc:creator> | |
<guid isPermaLink="false">$guid</guid> | |
<description><![CDATA[$content]]></description> | |
<timespan><![CDATA[$timespan]]></timespan> | |
<event_month><![CDATA[$event_month]]></event_month> | |
<event_day><![CDATA[$event_day]]></event_day> | |
<location><![CDATA[$location]]></location> | |
<event><![CDATA[$no_img_desc]]></event> | |
<wfw:commentRss>$comments</wfw:commentRss> | |
<slash:comments>$comments_number</slash:comments> | |
</item> | |
FEED; | |
} | |
?> | |
</channel> | |
</rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment