123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- /*
- Plugin Name: All-in-One Event Calendar Rss
- Plugin URI:
- Description: Produce un rss con gli eventi di All In One Event Calendar
- Version: 0.0.1
- Author: gin(e)
- Author URI:
- License: GPL3
- License URI: http://www.gnu.org/licenses/gpl-3.0.html
- Text Domain: ai1ec_rss
- @author gine
- @category social
- @package Wordpress All-in-One Event Calendar Rss
- @since 0.0.1
- Wordpress All In One Event Calendar Rss. A Plugin for WordPress.
- Copyright (C) 2019 gine -
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
- */
- require_once(ABSPATH .'wp-includes/pluggable.php');
- if ( ! defined( 'ABSPATH' ) ) :
- exit; // Exit if accessed directly
- endif;
- function set_ai1ecrss_join($join, &$wp_query) {
- global $wpdb;
-
- $db_prefix=$wpdb->prefix;
- $join .=" JOIN ".$db_prefix."ai1ec_events
- ON $wpdb->posts.ID = ".$db_prefix."ai1ec_events.post_id";
-
- return $join;
- }
- function set_ai1ecrss_where( $where, &$wp_query ){
- global $wpdb;
-
- $db_prefix=$wpdb->prefix;
- if(! is_admin() && $wp_query->post_type ='ai3ec_event'){
- date_default_timezone_set("Europe/Rome");
-
- $start = time()+ (7 * 24 * 60 * 60);
- $end = time();
- //$where .= ' AND '. $db_prefix.'ai1ec_events.start <= \''.$start.'\'' .' AND '. $db_prefix.'ai1ec_events.end >= \''.$end.'\'';
- $where .= ' AND '. $db_prefix.'ai1ec_events.start <= \''.$start.'\'';
-
- return $where;
- }
- }
- function set_ai1ecrss_orderby($orderby) {
- global $wpdb;
-
- $db_prefix=$wpdb->prefix;
- $orderby = $db_prefix."ai1ec_events.start DESC";
- return $orderby;
- }
- function getEvent($cat){
- $args=Array(
- 'post_type'=> 'ai1ec_event',
- 'no_found_rows' => 1,
- 'showposts' => 10
- );
- if($cat != "all" ) {
- $args['tax_query'] = array(
- Array(
- 'taxonomy' => 'events_categories',
- 'field' => 'slug',
- 'terms' => Array($cat),
- )
- );
- }
- //var_dump($args);
- add_filter( 'posts_join', 'set_ai1ecrss_join',10,2 );
- add_filter( 'posts_where', 'set_ai1ecrss_where', 10, 2 );
- add_filter( 'posts_orderby', 'set_ai1ecrss_orderby' );
- //http://codex.wordpress.org/Class_Reference/WP_Query
- $cat_query = new WP_Query($args);
- remove_filter( 'posts_join', 'set_ai1ecrss_join' );
- remove_filter( 'posts_where', 'set_ai1ecrss_where' );
- remove_filter( 'posts_orderby', 'set_ai1ecrss_orderby' );
- header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
- echo '<?xml version="1.0" encoding="'.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/">
- <channel>
- <title><?php bloginfo_rss('name'); ?> - Events Feed</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 echo get_option('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 if($cat_query->have_posts()): ?>
- <?php while($cat_query->have_posts()) : $cat_query->the_post(); ?>
- <item>
- <title><?php the_title_rss(); ?></title>
- <link><?php the_permalink_rss(); ?></link>
- <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
- <guid isPermaLink="false"><?php the_guid(); ?></guid>
- <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
- <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
- <?php rss_enclosure(); ?>
- <?php do_action('rss2_item'); ?>
- </item>
- <?php endwhile; ?>
- <?php endif; ?>
- </channel>
- </rss>
- <?php
- }
- function debug($args){ ?>
- <html><head></head><body>ciao</body></html><?php
- }
- function wds_ai1ec_rss_restapi_endpoint() {
- add_rewrite_tag( '%ai1ecrss%', '([^&]+)' );
- add_rewrite_rule( '%/wp_ai1ec_rss/([^&]+)/?', 'index.php?ai1ecrss=$matches[1]', 'top' );
- }
- add_action( 'init', 'wds_ai1ec_rss_restapi_endpoint' );
- function wds_ai1ec_rss_restapi_endpoint_call() {
- global $wp_query;
- $category = $wp_query->get( 'ai1ecrss' );
- if ( ! $category)
- return;
- getEvent($category);
- die;
- }
- add_action( 'template_redirect', 'wds_ai1ec_rss_restapi_endpoint_call' );
|