__construct(); } //PHP 5 constructor function __construct(){ add_action('activate_google-calendar-events/google-calendar-events.php', array($this, 'init_plugin')); add_action('admin_menu', array($this, 'setup_admin')); add_action('admin_init', array($this, 'init_admin')); add_action('widgets_init', create_function('', 'return register_widget("GCE_Widget");')); add_shortcode('google-calendar-events', array($this, 'shortcode_handler')); add_action('wp_print_styles', array($this, 'add_styles')); add_action('wp_print_scripts', array($this, 'add_scripts')); } function init_plugin(){ add_option(GCE_OPTIONS_NAME); } //Setup admin settings page function setup_admin(){ if(function_exists('add_options_page')) add_options_page('Google Calendar Events', 'Google Calendar Events', 'manage_options', basename(__FILE__), array($this, 'admin_page')); } //Prints admin settings page function admin_page(){ //Add correct updated message (added / edited / deleted) if(isset($_GET['updated'])){ switch($_GET['updated']){ case 'added': ?>

New Feed Added Successfully.

Feed Details Updated Successfully.

Feed Deleted Successfully.


Google Calendar Events

Cancel

Cancel

Cancel

$id, 'title' => $title, 'url' => $url, 'show_past_events' => $show_past_events, 'max_events' => $max_events, 'date_format' => $date_format, 'time_format' => $time_format, 'cache_duration' => $cache_duration ); } return $options; } //Handles the shortcode stuff function shortcode_handler($atts){ $options = get_option(GCE_OPTIONS_NAME); //Check that any feeds have been added if(is_array($options) && !empty($options)){ extract(shortcode_atts(array( 'id' => '1', 'type' => 'grid' ), $atts)); switch($type){ case 'grid': return gce_print_grid($id); break; case 'ajax': return gce_print_grid($id, true); break; case 'list': return gce_print_list($id); break; } }else{ return 'No feeds have been added yet. You can add a feed in the Google Calendar Events settings.'; } } //Adds the required CSS function add_styles(){ //Don't add styles if on admin screens if(!is_admin()){ //If user has entered a URL to a custom stylesheet, use it. Otherwise use the default if((get_option('gce_stylesheet') != false) && (get_option('gce_stylesheet') != '')){ wp_enqueue_style('gce_styles', get_option('gce_stylesheet')); }else{ wp_enqueue_style('gce_styles', WP_PLUGIN_URL . '/' . GCE_PLUGIN_NAME . '/css/gce-style.css'); } } } //Adds the required scripts function add_scripts(){ //Don't add scripts if on admin screens if(!is_admin()){ wp_enqueue_script('jquery'); wp_enqueue_script('gce_scripts', WP_PLUGIN_URL . '/' . GCE_PLUGIN_NAME . '/js/gce-tooltip-script.js'); } } } } function gce_print_list($feed_id){ //Get saved feed options $options = get_option(GCE_OPTIONS_NAME); //Set time and date formats to WordPress defaults if not set by user $df = $options[$feed_id]['date_format']; $tf = $options[$feed_id]['time_format']; if($df == '') $df = get_option('date_format'); if($tf == '') $tf = get_option('time_format'); //Creates a new GCE_Parser object for $feed_id $feed_data = new GCE_Parser( $options[$feed_id]['url'], $options[$feed_id]['show_past_events'], $options[$feed_id]['max_events'], $options[$feed_id]['cache_duration'], $df, $tf, get_option('start_of_week') ); //If the feed parsed ok if($feed_data->parsed_ok()){ $markup = '
' . $feed_data->get_list() . '
'; return $markup; }else{ return 'The Google Calendar feed was not parsed successfully, please check that the feed URL is correct.'; } } function gce_print_grid($feed_id, $ajaxified = false, $month = null, $year = null){ //Get saved feed options $options = get_option(GCE_OPTIONS_NAME); //Set time and date formats to WordPress defaults if not set by user $df = $options[$feed_id]['date_format']; $tf = $options[$feed_id]['time_format']; if($df == '') $df = get_option('date_format'); if($tf == '') $tf = get_option('time_format'); //Creates a new GCE_Parser object for $feed_id $feed_data = new GCE_Parser( $options[$feed_id]['url'], $options[$feed_id]['show_past_events'], $options[$feed_id]['max_events'], $options[$feed_id]['cache_duration'], $df, $tf, get_option('start_of_week') ); //If the feed parsed ok if($feed_data->parsed_ok()){ $markup = '
'; //Add AJAX script if required if($ajaxified){ $markup .= ''; } $markup .= $feed_data->get_grid($year, $month, $ajaxified); $markup .= '
'; return $markup; }else{ return 'The Google Calendar feed was not parsed successfully, please check that the feed URL is correct.'; } } function gce_handle_ajax($feed_id, $month = null, $year = null){ echo gce_print_grid($feed_id, true, $month, $year); } if(isset($_GET['gce_type']) && $_GET['gce_type'] == 'page'){ if(isset($_GET['gce_feed_id'])){ gce_handle_ajax($_GET['gce_feed_id'], $_GET['gce_month'], $_GET['gce_year']); die(); } } $gce = new Google_Calendar_Events(); ?>