diff -r 2f6f6f7551ca -r 32102edaa81b web/wp-content/plugins/ajax-calendar/ajax-calendar.php --- a/web/wp-content/plugins/ajax-calendar/ajax-calendar.php Thu Sep 16 15:45:36 2010 +0000 +++ b/web/wp-content/plugins/ajax-calendar/ajax-calendar.php Mon Nov 19 18:26:13 2012 +0100 @@ -1,88 +1,149 @@ -register_plugin ('ajax-calendar', __FILE__); - - if (is_admin ()) - { - $this->add_action ('publish_post', 'cache_remove'); - $this->add_action ('save_post', 'cache_remove'); - $this->add_action ('delete_post', 'cache_remove'); - } - else - $this->add_action ('wp_head'); - - $this->widget = new AJAX_Calendar_Widget ('AJAX Calendar'); - } - - function show ($categories = '') - { - include_once (dirname (__FILE__).'/models/calendar.php'); - - $this->render ('calendar', array ('calendar' => new Calendar ($this->url (), $categories))); - } - - function wp_head () - { - $this->render ('head'); - } - - function cache_remove ($id) - { - $post = wp_get_single_post ($id); - - $postmonth = substr ($post->post_date, 5, 2); - $postyear = substr ($post->post_date, 0, 4); - $modmonth = substr ($post->post_modified, 5, 2); - $modyear = substr ($post->post_modified, 0, 4); - - // Delete the cache files for the two dates, just in case something has changed - for ($x = 0; $x < 2; $x++) - { - wp_cache_delete ($postyear."_".$postmonth."_".$x); - wp_cache_delete ($modyear."_".$modmonth."_".$x); - } - } - - function &get () - { - static $instance; - - if (!isset ($instance)) - { - $c = __CLASS__; - $instance = new $c; - } - - return $instance; - } -} - - -function ajax_calendar ($categories = '') -{ - $calendar = AJAX_Calendar::get (); - $calendar->show ($categories); -} -} - - -$ajax_calendar_plugin = AJAX_Calendar::get (); - -?> \ No newline at end of file + 'ajax_calendar_widget', 'description' => __( 'AJAX Powered Calendar', 'ajax-calendar' ) ); + $control_ops = array( 'width' => 300, 'height' => 300 ); + + $this->WP_Widget( 'ajax-calendar', __( 'AJAX Calendar', 'ajax-calendar' ), $widget_ops, $control_ops ); + + add_action( 'template_redirect', array( &$this, 'template_redirect' ) ); + } + + function template_redirect() { + if ( is_date() && isset( $_GET['ajax'] ) && $_GET['ajax'] == 'true' ) { + $settings = $this->get_settings(); + $settings = $settings[$this->number]; + + $instance = wp_parse_args( $settings, array( 'title' => __( 'AJAX Calendar', 'ajax-calendar' ), 'category_id' => '' ) ); + $this->category_ids = array_filter( explode( ',', $instance['category_id'] ) ); + + echo $this->get_calendar(); + die(); + } + } + + /** + * Display the widget + * + * @param string $args Widget arguments + * @param string $instance Widget instance + * @return void + **/ + function widget( $args, $instance ) { + extract( $args ); + + $instance = wp_parse_args( (array)$instance, array( 'title' => __( 'AJAX Calendar', 'ajax-calendar' ), 'category_id' => '' ) ); + $title = apply_filters( 'widget_title', $instance['title'] ); + $category_id = $instance['category_id']; + + $this->category_ids = array_filter( explode( ',', $category_id ) ); + + echo $before_widget; + + if ( $title ) + echo $before_title . stripslashes( $title ) . $after_title; + + echo $this->get_calendar(); + + // MicroAJAX: http://www.blackmac.de/index.php?/archives/31-Smallest-JavaScript-AJAX-library-ever!.html +?> + +category_ids ) ) { + global $wpdb; + + $query = str_replace( 'WHERE', "LEFT JOIN {$wpdb->prefix}term_relationships ON {$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id INNER JOIN {$wpdb->prefix}term_taxonomy ON ({$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}term_taxonomy.term_taxonomy_id AND {$wpdb->prefix}term_taxonomy.taxonomy='category') WHERE", $query ); + if ( strpos( $query, 'ORDER' ) !== false ) + $query = str_replace( "ORDER", "AND {$wpdb->prefix}term_taxonomy.term_id IN (".implode (',', $this->category_ids ).') ORDER', $query ); + else + $query .= "AND {$wpdb->prefix}term_taxonomy.term_id IN (".implode (',', $this->category_ids ).')'; + } + + return $query; + } + + /** + * Display config interface + * + * @param string $instance Widget instance + * @return void + **/ + function form( $instance ) { + $instance = wp_parse_args( (array)$instance, array( 'title' => __( 'AJAX Calendar', 'ajax-calendar' ), 'category_id' => '' ) ); + + $title = stripslashes( $instance['title'] ); + $category_id = $instance['category_id']; + + ?> +

+

+ __( 'AJAX Calendar', 'ajax-calendar' ), 'category_id' => '' ) ); + + $instance['title'] = wp_filter_nohtml_kses( $new_instance['title'] ); + $instance['category_id'] = implode( ',', array_filter( array_map( 'intval', explode( ',', $new_instance['category_id'] ) ) ) ); + + return $instance; + } +} + +function register_ajax_calendar_widget() { + register_widget( 'AJAX_Calendar_Widget' ); +} + +add_action( 'widgets_init', 'register_ajax_calendar_widget' ); + +function ajax_calendar ($categories = '') { + // $calendar = AJAX_Calendar::get (); + // $calendar->show ( $categories ); +}