Simple Calendar – Google Calendar Plugin - Version 2.1.0

Version Description

  • Updated to use Google API version 3. Version 2 deprecated deprecated on Nov. 17, 2014.
Download this release

Release Info

Developer pderksen
Plugin Icon 128x128 Simple Calendar – Google Calendar Plugin
Version 2.1.0
Comparing to
See all releases

Code changes from version 2.0.7.1 to 2.1.0

README.txt CHANGED
@@ -87,6 +87,10 @@ There are three ways to install this plugin.
87
 
88
  == Changelog ==
89
 
 
 
 
 
90
  = 2.0.7.1 =
91
 
92
  * As of Nov. 17, 2014 the GCal API v2 is deprecated, which breaks all calendar feed displays. This update will temporarily hide the display while we work on a solution that uses GCal API v3.
@@ -308,7 +312,6 @@ There are three ways to install this plugin.
308
 
309
  == Upgrade Notice ==
310
 
311
- = 2.0.7.1 =
312
-
313
- As of Nov. 17, 2014 the GCal API v2 is deprecated, which breaks all calendar feed displays. v2.0.7.1 will temporarily hide the display while we work on a solution that uses GCal API v3.
314
 
 
87
 
88
  == Changelog ==
89
 
90
+ = 2.1.0 =
91
+
92
+ * Updated to use Google API version 3. Version 2 deprecated deprecated on Nov. 17, 2014.
93
+
94
  = 2.0.7.1 =
95
 
96
  * As of Nov. 17, 2014 the GCal API v2 is deprecated, which breaks all calendar feed displays. This update will temporarily hide the display while we work on a solution that uses GCal API v3.
312
 
313
  == Upgrade Notice ==
314
 
315
+ = 2.1.0 =
 
 
316
 
317
+ Updated to use Google API version 3. Version 2 deprecated deprecated on Nov. 17, 2014.
class-google-calendar-events-admin.php CHANGED
@@ -56,11 +56,69 @@ class Google_Calendar_Events_Admin {
56
  // Add the options page and menu item.
57
  add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ), 2 );
58
 
59
- // Add temporary admin notice for a particular version.
60
- // TODO Remove this after GCal API v3 update, but leave commented out for future admin notices.
61
  if( version_compare( $this->version, '2.1.0', '<' ) ) {
62
  add_action( 'admin_notices', array( $this, 'show_admin_notice' ) );
63
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  }
65
 
66
  public function add_plugin_admin_menu() {
@@ -137,8 +195,8 @@ class Google_Calendar_Events_Admin {
137
 
138
  return array_merge(
139
  array(
 
140
  'feeds' => '<a href="' . admin_url( 'edit.php?post_type=gce_feed' ) . '">' . __( 'Feeds', 'gce' ) . '</a>'
141
- //'settings' => '<a href="' . admin_url( 'edit.php?post_type=gce_feed&page=google-calendar-events_general_settings' ) . '">' . __( 'Settings', 'gce' ) . '</a>',
142
  ),
143
  $links
144
  );
56
  // Add the options page and menu item.
57
  add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ), 2 );
58
 
59
+ // Add admin notice for users upgrading from before 2.1.0.
 
60
  if( version_compare( $this->version, '2.1.0', '<' ) ) {
61
  add_action( 'admin_notices', array( $this, 'show_admin_notice' ) );
62
  }
63
+
64
+ // Add admin notice after plugin activation. Also check if should be hidden.
65
+ add_action( 'admin_notices', array( $this, 'admin_api_settings_notice' ) );
66
+ }
67
+
68
+ /**
69
+ * Show notice after plugin install/activate
70
+ * Also check if user chooses to hide it.
71
+ *
72
+ * @since 2.1.0
73
+ */
74
+ public function admin_api_settings_notice() {
75
+ // Exit all of this is stored value is false/0 or not set.
76
+ if ( false == get_option( 'gce_show_admin_install_notice' ) ) {
77
+ return;
78
+ }
79
+
80
+ $screen = get_current_screen();
81
+
82
+ // Delete stored value if "hide" button click detected (custom querystring value set to 1).
83
+ if ( ! empty( $_REQUEST['gce-dismiss-install-nag'] ) || in_array( $screen->id, $this->plugin_screen_hook_suffix ) ) {
84
+ delete_option( 'gce_show_admin_install_notice' );
85
+ return;
86
+ }
87
+
88
+ // At this point show install notice. Show it only on the plugin screen.
89
+ if( get_current_screen()->id == 'plugins' || $this->viewing_this_plugin() ) {
90
+ include_once( 'views/admin/api-settings-notice.php' );
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Check if viewing one of this plugin's admin pages.
96
+ *
97
+ * @since 2.1.0
98
+ *
99
+ * @return bool
100
+ */
101
+ private function viewing_this_plugin() {
102
+ if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
103
+ return false;
104
+ }
105
+
106
+ $screen = get_current_screen();
107
+
108
+ if ( $screen->id == 'edit-gce_feed' || $screen->id == 'gce_feed' ) {
109
+ return true;
110
+ } else {
111
+ return false;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Fired when the plugin is activated.
117
+ *
118
+ * @since 2.1.0
119
+ */
120
+ public static function activate() {
121
+ update_option( 'gce_show_admin_install_notice', 1 );
122
  }
123
 
124
  public function add_plugin_admin_menu() {
195
 
196
  return array_merge(
197
  array(
198
+ 'settings' => '<a href="' . admin_url( 'edit.php?post_type=gce_feed&page=google-calendar-events_general_settings' ) . '">' . __( 'General Settings', 'gce' ) . '</a>',
199
  'feeds' => '<a href="' . admin_url( 'edit.php?post_type=gce_feed' ) . '">' . __( 'Feeds', 'gce' ) . '</a>'
 
200
  ),
201
  $links
202
  );
class-google-calendar-events.php CHANGED
@@ -18,7 +18,7 @@ class Google_Calendar_Events {
18
  *
19
  * @var string
20
  */
21
- protected $version = '2.0.7.1';
22
 
23
  /**
24
  * Unique identifier for the plugin.
18
  *
19
  * @var string
20
  */
21
+ protected $version = '2.1.0';
22
 
23
  /**
24
  * Unique identifier for the plugin.
google-calendar-events.php CHANGED
@@ -12,7 +12,7 @@
12
  * Plugin Name: Google Calendar Events
13
  * Plugin URI: https://github.com/pderksen/WP-Google-Calendar-Events
14
  * Description: Parses Google Calendar feeds and displays the events as a calendar grid or list on a page, post or widget.
15
- * Version: 2.0.7.1
16
  * Author: Phil Derksen
17
  * Author URI: http://philderksen.com
18
  * License: GPL-2.0+
@@ -56,5 +56,12 @@ add_action( 'plugins_loaded', array( 'Google_Calendar_Events', 'get_instance' )
56
  */
57
  if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
58
  require_once( 'class-google-calendar-events-admin.php' );
 
 
 
 
 
59
  add_action( 'plugins_loaded', array( 'Google_Calendar_Events_Admin', 'get_instance' ) );
60
  }
 
 
12
  * Plugin Name: Google Calendar Events
13
  * Plugin URI: https://github.com/pderksen/WP-Google-Calendar-Events
14
  * Description: Parses Google Calendar feeds and displays the events as a calendar grid or list on a page, post or widget.
15
+ * Version: 2.1.0
16
  * Author: Phil Derksen
17
  * Author URI: http://philderksen.com
18
  * License: GPL-2.0+
56
  */
57
  if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
58
  require_once( 'class-google-calendar-events-admin.php' );
59
+
60
+ // Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
61
+ register_activation_hook( __FILE__, array( 'Google_Calendar_Events_Admin', 'activate' ) );
62
+
63
+ // Get plugin admin class instance
64
  add_action( 'plugins_loaded', array( 'Google_Calendar_Events_Admin', 'get_instance' ) );
65
  }
66
+
67
+
includes/admin/upgrade.php CHANGED
@@ -40,6 +40,10 @@ function gce_upgrade() {
40
  if( version_compare( $version, '2.0.6', '<' ) ) {
41
  gce_v206_upgrade();
42
  }
 
 
 
 
43
  }
44
 
45
  $new_version = Google_Calendar_Events::get_instance()->get_plugin_version();
@@ -48,6 +52,30 @@ function gce_upgrade() {
48
  add_option( 'gce_upgrade_has_run', 1 );
49
  }
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  /*
52
  * Run the upgrade to version 2.0.6
53
  *
40
  if( version_compare( $version, '2.0.6', '<' ) ) {
41
  gce_v206_upgrade();
42
  }
43
+
44
+ if( version_compare( $version, '2.1.0', '<' ) ) {
45
+ gce_v210_upgrade();
46
+ }
47
  }
48
 
49
  $new_version = Google_Calendar_Events::get_instance()->get_plugin_version();
52
  add_option( 'gce_upgrade_has_run', 1 );
53
  }
54
 
55
+ /*
56
+ * Run the upgrade to version 2.1.0
57
+ */
58
+ function gce_v210_upgrade() {
59
+
60
+ $q = new WP_Query( 'post_type=gce_feed' );
61
+
62
+ if( $q->have_posts() ) {
63
+ while( $q->have_posts() ) {
64
+ $q->the_post();
65
+
66
+ $url = get_post_meta( get_the_ID(), 'gce_feed_url', true );
67
+
68
+ // https://www.google.com/calendar/feeds/umsb0ekhivs1a2ubtq6vlqvcjk%40group.calendar.google.com/public/basic
69
+
70
+ $url = str_replace( 'https://www.google.com/calendar/feeds/', '', $url );
71
+ $url = str_replace( '/public/basic', '', $url );
72
+ $url = str_replace( '%40', '@', $url );
73
+
74
+ update_post_meta( get_the_ID(), 'gce_feed_url', $url );
75
+ }
76
+ }
77
+ }
78
+
79
  /*
80
  * Run the upgrade to version 2.0.6
81
  *
includes/class-gce-feed.php CHANGED
@@ -12,6 +12,7 @@
12
  class GCE_Feed {
13
 
14
  public $id,
 
15
  $feed_url,
16
  $date_format,
17
  $time_format,
@@ -24,6 +25,9 @@ class GCE_Feed {
24
 
25
  public $events = array();
26
 
 
 
 
27
  /**
28
  * Class constructor
29
  *
@@ -33,6 +37,8 @@ class GCE_Feed {
33
  // Set the ID
34
  $this->id = $id;
35
 
 
 
36
  // Set up all other data based on the ID
37
  $this->setup_attributes();
38
 
@@ -76,6 +82,8 @@ class GCE_Feed {
76
  private function create_feed() {
77
  //Break the feed URL up into its parts (scheme, host, path, query)
78
 
 
 
79
  if( empty( $this->feed_url ) ) {
80
  if( current_user_can( 'manage_options' ) ) {
81
  echo '<p>' . __( 'The feed URL has not been set. Please make sure to set it correctly in the Feed settings.', 'gce' ) . '</p>';
@@ -84,51 +92,36 @@ class GCE_Feed {
84
  return;
85
  }
86
 
87
- $url_parts = parse_url( $this->feed_url );
88
 
89
- $scheme = ( is_ssl() ? 'https://' : 'http://' );
90
-
91
- $scheme_and_host = $scheme . $url_parts['host'];
92
-
93
- //Remove the exisitng projection from the path, and replace it with '/full-noattendees'
94
- $path = substr( $url_parts['path'], 0, strrpos( $url_parts['path'], '/' ) ) . '/full-noattendees';
95
-
96
- //Add the default parameters to the querystring (retrieving JSON, not XML)
97
- $query = '?alt=json&sortorder=ascending&orderby=starttime';
98
-
99
- $start = $this->get_feed_start();
100
-
101
- $end = $this->get_feed_end();
102
 
103
- $gmt_offset = abs( get_option( 'gmt_offset' ) * 3600 );
104
 
105
- $query .= '&start-min=' . date( 'Y-m-d\TH:i:s', $start - $gmt_offset );
 
106
 
107
- $query .= '&start-max=' . date( 'Y-m-d\TH:i:s', $end - $gmt_offset );
108
 
109
-
110
- // Max results limit for performance.
111
- $query .= '&max-results=10000';
112
 
113
- $ctz = get_option( 'timezone_string' );
114
 
115
- if( ! empty( $ctz ) ) {
116
- $query .= '&ctz=' . $ctz;
117
- }
118
 
119
  if ( ! empty( $this->search_query ) ) {
120
- $query .= '&q=' . rawurlencode( $this->search_query );
121
  }
122
 
123
- if ( $this->expand_recurring ) {
124
- $query .= '&singleevents=true';
125
- }
126
-
127
- //Put the URL back together
128
- $this->display_url = $scheme_and_host . $path . $query;
129
 
130
- // Get all the feed data
131
- $this->get_feed_data( $this->display_url );
 
132
  }
133
 
134
  /**
@@ -146,50 +139,32 @@ class GCE_Feed {
146
  'sslverify' => false, //sslverify is set to false to ensure https URLs work reliably. Data source is Google's servers, so is trustworthy
147
  'timeout' => 10 //Increase timeout from the default 5 seconds to ensure even large feeds are retrieved successfully
148
  ) );
149
-
150
  //If $raw_data is a WP_Error, something went wrong
151
  if ( ! is_wp_error( $raw_data ) ) {
152
- //If response code isn't 200, something went wrong
153
- if ( 200 == $raw_data['response']['code'] ) {
154
  //Attempt to convert the returned JSON into an array
155
  $raw_data = json_decode( $raw_data['body'], true );
156
 
157
  //If decoding was successful
158
  if ( ! empty( $raw_data ) ) {
159
  //If there are some entries (events) to process
160
- if ( isset( $raw_data['feed']['entry'] ) ) {
161
  //Loop through each event, extracting the relevant information
162
- foreach ( $raw_data['feed']['entry'] as $event ) {
163
- $id = ( isset( $event['gCal$uid']['value'] ) ? esc_html( substr( $event['gCal$uid']['value'], 0, strpos( $event['gCal$uid']['value'], '@' ) ) ) : '' );
164
- $title = ( isset( $event['title']['$t'] ) ? esc_html( $event['title']['$t'] ) : '' );
165
- $description = ( isset( $event['content']['$t'] ) ? esc_html( $event['content']['$t'] ) : '' );
166
- $link = ( isset( $event['link'][0]['href'] ) ? esc_url( $event['link'][0]['href'] ) : '' );
167
- $location = ( isset( $event['gd$where'][0]['valueString'] ) ? esc_html( $event['gd$where'][0]['valueString'] ) : '' );
168
- $start_time = ( isset( $event['gd$when'][0]['startTime'] ) ? $this->iso_to_ts( $event['gd$when'][0]['startTime'] ) : null );
169
- $end_time = ( isset( $event['gd$when'][0]['endTime'] ) ? $this->iso_to_ts( $event['gd$when'][0]['endTime'] ) : null );
170
-
171
  //Create a GCE_Event using the above data. Add it to the array of events
172
  $this->events[] = new GCE_Event( $this, $id, $title, $description, $location, $start_time, $end_time, $link );
173
  }
174
- }
175
  } else {
176
  //json_decode failed
177
- $this->error = __( 'Some data was retrieved, but could not be parsed successfully. Please ensure your feed URL is correct.', 'gce' );
178
- }
179
- } else {
180
- //The response code wasn't 200, so generate a helpful(ish) error message depending on error code
181
- switch ( $raw_data['response']['code'] ) {
182
- case 404:
183
- $this->error = __( 'The feed could not be found (404). Please ensure your feed URL is correct.', 'gce' );
184
- break;
185
- case 403:
186
- $this->error = __( 'Access to this feed was denied (403). Please ensure you have public sharing enabled for your calendar.', 'gce' );
187
- break;
188
- default:
189
- $this->error = sprintf( __( 'The feed data could not be retrieved. Error code: %s. Please ensure your feed URL is correct.', 'gce' ), $raw_data['response']['code'] );
190
  }
191
- }
192
- }else{
193
  //Generate an error message from the returned WP_Error
194
  $this->error = $raw_data->get_error_message() . __( ' Please ensure your feed URL is correct.', 'gce' );
195
  }
@@ -224,15 +199,15 @@ class GCE_Feed {
224
 
225
  switch( $interval ) {
226
  case 'days':
227
- return time() - ( $start * 86400 );
228
  case 'months':
229
- return time() - ( $start * 2629743 );
230
  case 'years':
231
- return time() - ( $start * 31556926 );
232
  }
233
 
234
  // fall back just in case. Falls back to 1 year ago
235
- return time() - 31556926;
236
  }
237
 
238
  private function get_feed_end() {
@@ -242,15 +217,15 @@ class GCE_Feed {
242
 
243
  switch( $interval ) {
244
  case 'days':
245
- return time() + ( $end * 86400 );
246
  case 'months':
247
- return time() + ( $end * 2629743 );
248
  case 'years':
249
- return time() + ( $end * 31556926 );
250
  }
251
 
252
  // Falls back to 1 year ahead just in case
253
- return time() + 31556926;
254
  }
255
 
256
  function get_builder() {
12
  class GCE_Feed {
13
 
14
  public $id,
15
+ $calendar_id,
16
  $feed_url,
17
  $date_format,
18
  $time_format,
25
 
26
  public $events = array();
27
 
28
+ // Google API Key
29
+ private $api_key = 'AIzaSyAssdKVved1mPVY0UJCrx96OUOF9u17AuY';
30
+
31
  /**
32
  * Class constructor
33
  *
37
  // Set the ID
38
  $this->id = $id;
39
 
40
+ $this->calendar_id = get_post_meta( $this->id, 'gce_feed_url', true );
41
+
42
  // Set up all other data based on the ID
43
  $this->setup_attributes();
44
 
82
  private function create_feed() {
83
  //Break the feed URL up into its parts (scheme, host, path, query)
84
 
85
+ global $gce_options;
86
+
87
  if( empty( $this->feed_url ) ) {
88
  if( current_user_can( 'manage_options' ) ) {
89
  echo '<p>' . __( 'The feed URL has not been set. Please make sure to set it correctly in the Feed settings.', 'gce' ) . '</p>';
92
  return;
93
  }
94
 
95
+ $args = array();
96
 
97
+ if( ! empty( $gce_options['api_key'] ) ) {
98
+ $api_key = $gce_options['api_key'];
99
+ } else {
100
+ $api_key = $this->api_key;
101
+ }
 
 
 
 
 
 
 
 
102
 
103
+ $query = 'https://www.googleapis.com/calendar/v3/calendars/' . $this->calendar_id . '/events';
104
 
105
+ // Set API key
106
+ $query .= '?key=' . $api_key;
107
 
108
+ $args['orderBy'] = 'startTime';
109
 
110
+ $args['timeMin'] = urlencode( $this->get_feed_start() );
 
 
111
 
112
+ $args['timeMax'] = urlencode( $this->get_feed_end() );
113
 
114
+ $args['maxResults'] = 10000;
 
 
115
 
116
  if ( ! empty( $this->search_query ) ) {
117
+ $args['q'] = rawurlencode( $this->search_query );
118
  }
119
 
120
+ $args['singleEvents'] = 'true';
 
 
 
 
 
121
 
122
+ $query = add_query_arg( $args, $query );
123
+
124
+ $this->get_feed_data( $query );
125
  }
126
 
127
  /**
139
  'sslverify' => false, //sslverify is set to false to ensure https URLs work reliably. Data source is Google's servers, so is trustworthy
140
  'timeout' => 10 //Increase timeout from the default 5 seconds to ensure even large feeds are retrieved successfully
141
  ) );
 
142
  //If $raw_data is a WP_Error, something went wrong
143
  if ( ! is_wp_error( $raw_data ) ) {
 
 
144
  //Attempt to convert the returned JSON into an array
145
  $raw_data = json_decode( $raw_data['body'], true );
146
 
147
  //If decoding was successful
148
  if ( ! empty( $raw_data ) ) {
149
  //If there are some entries (events) to process
150
+ //if ( isset( $raw_data['feed']['entry'] ) ) {
151
  //Loop through each event, extracting the relevant information
152
+ foreach ( $raw_data['items'] as $event ) {
153
+ $id = ( isset( $event['id'] ) ? esc_html( $event['id'] ) : '' );
154
+ $title = ( isset( $event['summary'] ) ? esc_html( $event['summary'] ) : '' );
155
+ $description = ( isset( $event['description'] ) ? esc_html( $event['description'] ) : '' );
156
+ $link = ( isset( $event['htmlLink'] ) ? esc_url( $event['htmlLink'] ) : '' );
157
+ $location = ( isset( $event['location'] ) ? esc_html( $event['location'] ) : '' );
158
+ $start_time = ( isset( $event['start']['dateTime'] ) ? $this->iso_to_ts( $event['start']['dateTime'] ) : null );
159
+ $end_time = ( isset( $event['end']['dateTime'] ) ? $this->iso_to_ts( $event['end']['dateTime'] ) : null );
 
160
  //Create a GCE_Event using the above data. Add it to the array of events
161
  $this->events[] = new GCE_Event( $this, $id, $title, $description, $location, $start_time, $end_time, $link );
162
  }
 
163
  } else {
164
  //json_decode failed
165
+ $this->error = __( 'Some data was retrieved, but could not be parsed successfully. Please ensure your feed settings are correct.', 'gce' );
 
 
 
 
 
 
 
 
 
 
 
 
166
  }
167
+ } else{
 
168
  //Generate an error message from the returned WP_Error
169
  $this->error = $raw_data->get_error_message() . __( ' Please ensure your feed URL is correct.', 'gce' );
170
  }
199
 
200
  switch( $interval ) {
201
  case 'days':
202
+ return date( 'c', time() - ( $start * 86400 ) );
203
  case 'months':
204
+ return date( 'c', time() - ( $start * 2629743 ) );
205
  case 'years':
206
+ return date( 'c', time() - ( $start * 31556926 ) );
207
  }
208
 
209
  // fall back just in case. Falls back to 1 year ago
210
+ return date( 'c', time() - 31556926 );
211
  }
212
 
213
  private function get_feed_end() {
217
 
218
  switch( $interval ) {
219
  case 'days':
220
+ return date( 'c', time() + ( $end * 86400 ) );
221
  case 'months':
222
+ return date( 'c', time() + ( $end * 2629743 ) );
223
  case 'years':
224
+ return date( 'c', time() + ( $end * 31556926 ) );
225
  }
226
 
227
  // Falls back to 1 year ahead just in case
228
+ return date( 'c', time() + 31556926 );
229
  }
230
 
231
  function get_builder() {
includes/gce-feed-cpt.php CHANGED
@@ -182,7 +182,15 @@ function gce_save_meta( $post_id ) {
182
  foreach ( $post_meta_fields as $pmf ) {
183
  if ( isset( $_POST[$pmf] ) && ! empty( $_POST[$pmf] ) ) {
184
  if( $pmf == 'gce_feed_url' ) {
185
- update_post_meta( $post_id, $pmf, esc_url( $_POST[$pmf] ) );
 
 
 
 
 
 
 
 
186
  } else {
187
  update_post_meta( $post_id, $pmf, stripslashes( $_POST[$pmf] ) );
188
  }
182
  foreach ( $post_meta_fields as $pmf ) {
183
  if ( isset( $_POST[$pmf] ) && ! empty( $_POST[$pmf] ) ) {
184
  if( $pmf == 'gce_feed_url' ) {
185
+
186
+ $str = $_POST[$pmf];
187
+
188
+ // convert from URL if user enters a URL link (like the old versions required)
189
+ $id = str_replace( 'https://www.google.com/calendar/feeds/', '', $str );
190
+ $id = str_replace( '/public/basic', '', $id );
191
+ $id = str_replace( '%40', '@', $id );
192
+
193
+ update_post_meta( $post_id, $pmf, $id );
194
  } else {
195
  update_post_meta( $post_id, $pmf, stripslashes( $_POST[$pmf] ) );
196
  }
includes/misc-functions.php CHANGED
@@ -7,11 +7,7 @@
7
  */
8
  function gce_print_calendar( $feed_ids, $display = 'grid', $args = array(), $widget = false ) {
9
 
10
- // Temporarily hide all shortcode output.
11
- // TODO Remove this after GCal API v3 update..
12
- return '';
13
-
14
- $defaults = array(
15
  'title_text' => '',
16
  'sort' => 'asc',
17
  'grouped' => 0,
@@ -241,3 +237,4 @@ function gce_ga_campaign_url( $base_url, $source, $medium, $campaign ) {
241
 
242
  return $url;
243
  }
 
7
  */
8
  function gce_print_calendar( $feed_ids, $display = 'grid', $args = array(), $widget = false ) {
9
 
10
+ $defaults = array(
 
 
 
 
11
  'title_text' => '',
12
  'sort' => 'asc',
13
  'grouped' => 0,
237
 
238
  return $url;
239
  }
240
+
includes/register-settings.php CHANGED
@@ -24,6 +24,16 @@ function gce_register_settings() {
24
 
25
  /* General Settings */
26
  'general' => array(
 
 
 
 
 
 
 
 
 
 
27
  'save_settings' => array(
28
  'id' => 'save_settings',
29
  'name' => __( 'Save Settings', 'gce' ),
@@ -111,6 +121,33 @@ function gce_checkbox_callback( $args ) {
111
  echo $html;
112
  }
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  /*
115
  * Function we can use to sanitize the input data and return it when saving options
116
  *
@@ -154,4 +191,4 @@ function gce_get_settings() {
154
  $general_settings = is_array( get_option( 'gce_settings_general' ) ) ? get_option( 'gce_settings_general' ) : array();
155
 
156
  return $general_settings;
157
- }
24
 
25
  /* General Settings */
26
  'general' => array(
27
+ 'api_key' => array(
28
+ 'id' => 'api_key',
29
+ 'name' => __( 'Google API Key', 'gce' ),
30
+ 'desc' => __( 'If left blank all displayed Google calendars will use a public Google API key shared across all plugin users.', 'gce' ) . ' ' .
31
+ __( 'Currently the shared key is limited to 500,000 requests per day and 5 requests per second.', 'gce' ) . '<br/>' .
32
+ sprintf( __( 'To avoid these limits <a href="%s" target="_blank">click here for instructions on how to generate and use your own Google API key.</a>', 'gce' ),
33
+ gce_ga_campaign_url( 'http://wpdocs.philderksen.com/google-calendar-events/getting-started/api-key-settings/', 'gce_lite', 'settings_link', 'docs' ) ),
34
+ 'size' => 'regular-text',
35
+ 'type' => 'text'
36
+ ),
37
  'save_settings' => array(
38
  'id' => 'save_settings',
39
  'name' => __( 'Save Settings', 'gce' ),
121
  echo $html;
122
  }
123
 
124
+ /**
125
+ * Textbox callback function
126
+ * Valid built-in size CSS class values:
127
+ * small-text, regular-text, large-text
128
+ *
129
+ * @since 2.1.0
130
+ *
131
+ */
132
+ function gce_text_callback( $args ) {
133
+ global $gce_options;
134
+
135
+ if ( isset( $gce_options[ $args['id'] ] ) )
136
+ $value = $gce_options[ $args['id'] ];
137
+ else
138
+ $value = isset( $args['std'] ) ? $args['std'] : '';
139
+
140
+ $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : '';
141
+ $html = "\n" . '<input type="text" class="' . $size . '" id="gce_settings_' . $args['section'] . '[' . $args['id'] . ']" name="gce_settings_' . $args['section'] . '[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>' . "\n";
142
+
143
+ // Render and style description text underneath if it exists.
144
+ if ( ! empty( $args['desc'] ) ) {
145
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
146
+ }
147
+
148
+ echo $html;
149
+ }
150
+
151
  /*
152
  * Function we can use to sanitize the input data and return it when saving options
153
  *
191
  $general_settings = is_array( get_option( 'gce_settings_general' ) ) ? get_option( 'gce_settings_general' ) : array();
192
 
193
  return $general_settings;
194
+ }
languages/gce.pot CHANGED
@@ -1,8 +1,8 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Google Calendar Events\n"
4
- "POT-Creation-Date: 2014-10-28 10:39-0700\n"
5
- "PO-Revision-Date: 2014-10-28 10:39-0700\n"
6
  "Last-Translator: \n"
7
  "Language-Team: \n"
8
  "Language: en\n"
@@ -15,18 +15,19 @@ msgstr ""
15
  "X-Poedit-KeywordsList: __;_e\n"
16
  "X-Poedit-SearchPath-0: google-calendar-events\n"
17
 
18
- #: google-calendar-events/class-google-calendar-events-admin.php:64
19
- #: google-calendar-events/class-google-calendar-events-admin.php:65
20
- #: google-calendar-events/includes/register-settings.php:44
 
21
  msgid "General Settings"
22
  msgstr ""
23
 
24
- #: google-calendar-events/class-google-calendar-events-admin.php:122
25
  #: google-calendar-events/views/widgets.php:27
26
  msgid "Google Calendar Events"
27
  msgstr ""
28
 
29
- #: google-calendar-events/class-google-calendar-events-admin.php:134
30
  msgid "Feeds"
31
  msgstr ""
32
 
@@ -67,7 +68,7 @@ msgid "More Details"
67
  msgstr ""
68
 
69
  #: google-calendar-events/includes/admin/admin-functions.php:78
70
- #: google-calendar-events/includes/gce-feed-cpt.php:256
71
  msgid "Clear Cache"
72
  msgstr ""
73
 
@@ -147,37 +148,19 @@ msgstr ""
147
  msgid "%s mins"
148
  msgstr ""
149
 
150
- #: google-calendar-events/includes/class-gce-feed.php:81
151
  msgid ""
152
  "The feed URL has not been set. Please make sure to set it correctly in the "
153
  "Feed settings."
154
  msgstr ""
155
 
156
- #: google-calendar-events/includes/class-gce-feed.php:177
157
  msgid ""
158
  "Some data was retrieved, but could not be parsed successfully. Please ensure "
159
- "your feed URL is correct."
160
  msgstr ""
161
 
162
- #: google-calendar-events/includes/class-gce-feed.php:183
163
- msgid ""
164
- "The feed could not be found (404). Please ensure your feed URL is correct."
165
- msgstr ""
166
-
167
- #: google-calendar-events/includes/class-gce-feed.php:186
168
- msgid ""
169
- "Access to this feed was denied (403). Please ensure you have public sharing "
170
- "enabled for your calendar."
171
- msgstr ""
172
-
173
- #: google-calendar-events/includes/class-gce-feed.php:189
174
- #, php-format
175
- msgid ""
176
- "The feed data could not be retrieved. Error code: %s. Please ensure your "
177
- "feed URL is correct."
178
- msgstr ""
179
-
180
- #: google-calendar-events/includes/class-gce-feed.php:194
181
  msgid " Please ensure your feed URL is correct."
182
  msgstr ""
183
 
@@ -265,53 +248,104 @@ msgstr ""
265
  msgid "Helpful Links"
266
  msgstr ""
267
 
268
- #: google-calendar-events/includes/gce-feed-cpt.php:209
269
  msgid "Feed ID"
270
  msgstr ""
271
 
272
- #: google-calendar-events/includes/gce-feed-cpt.php:210
273
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:73
274
  msgid "Feed Shortcode"
275
  msgstr ""
276
 
277
- #: google-calendar-events/includes/gce-feed-cpt.php:211
278
  msgid "Display Type"
279
  msgstr ""
280
 
281
- #: google-calendar-events/includes/gce-feed-cpt.php:238
282
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:152
283
  #: google-calendar-events/views/widgets.php:218
284
  msgid "Grid"
285
  msgstr ""
286
 
287
- #: google-calendar-events/includes/gce-feed-cpt.php:240
288
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:153
289
  #: google-calendar-events/views/widgets.php:219
290
  msgid "List"
291
  msgstr ""
292
 
293
- #: google-calendar-events/includes/gce-feed-cpt.php:242
294
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:154
295
  #: google-calendar-events/views/widgets.php:220
296
  msgid "Grouped List"
297
  msgstr ""
298
 
299
  #: google-calendar-events/includes/register-settings.php:29
300
- msgid "Save Settings"
301
  msgstr ""
302
 
303
  #: google-calendar-events/includes/register-settings.php:30
304
  msgid ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  "Save your settings when uninstalling this plugin. Useful when upgrading or "
306
  "re-installing."
307
  msgstr ""
308
 
309
- #: google-calendar-events/includes/register-settings.php:132
310
  #, php-format
311
  msgid ""
312
  "The callback function used for the <strong>%s</strong> setting is missing."
313
  msgstr ""
314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  #: google-calendar-events/views/admin/display-options-meta.php:39
316
  msgid ""
317
  "Check this box to use the simple display options below instead of the Event "
@@ -467,11 +501,11 @@ msgid ""
467
  msgstr ""
468
 
469
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:83
470
- msgid "GCal Feed URL"
471
  msgstr ""
472
 
473
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:87
474
- msgid "The Google Calendar feed URL."
475
  msgstr ""
476
 
477
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:87
@@ -479,7 +513,7 @@ msgid "Example"
479
  msgstr ""
480
 
481
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:89
482
- msgid "How to find your GCal feed URL"
483
  msgstr ""
484
 
485
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:95
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Google Calendar Events\n"
4
+ "POT-Creation-Date: 2014-11-19 00:09-0700\n"
5
+ "PO-Revision-Date: 2014-11-19 00:10-0700\n"
6
  "Last-Translator: \n"
7
  "Language-Team: \n"
8
  "Language: en\n"
15
  "X-Poedit-KeywordsList: __;_e\n"
16
  "X-Poedit-SearchPath-0: google-calendar-events\n"
17
 
18
+ #: google-calendar-events/class-google-calendar-events-admin.php:128
19
+ #: google-calendar-events/class-google-calendar-events-admin.php:129
20
+ #: google-calendar-events/class-google-calendar-events-admin.php:198
21
+ #: google-calendar-events/includes/register-settings.php:54
22
  msgid "General Settings"
23
  msgstr ""
24
 
25
+ #: google-calendar-events/class-google-calendar-events-admin.php:186
26
  #: google-calendar-events/views/widgets.php:27
27
  msgid "Google Calendar Events"
28
  msgstr ""
29
 
30
+ #: google-calendar-events/class-google-calendar-events-admin.php:199
31
  msgid "Feeds"
32
  msgstr ""
33
 
68
  msgstr ""
69
 
70
  #: google-calendar-events/includes/admin/admin-functions.php:78
71
+ #: google-calendar-events/includes/gce-feed-cpt.php:264
72
  msgid "Clear Cache"
73
  msgstr ""
74
 
148
  msgid "%s mins"
149
  msgstr ""
150
 
151
+ #: google-calendar-events/includes/class-gce-feed.php:89
152
  msgid ""
153
  "The feed URL has not been set. Please make sure to set it correctly in the "
154
  "Feed settings."
155
  msgstr ""
156
 
157
+ #: google-calendar-events/includes/class-gce-feed.php:165
158
  msgid ""
159
  "Some data was retrieved, but could not be parsed successfully. Please ensure "
160
+ "your feed settings are correct."
161
  msgstr ""
162
 
163
+ #: google-calendar-events/includes/class-gce-feed.php:169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  msgid " Please ensure your feed URL is correct."
165
  msgstr ""
166
 
248
  msgid "Helpful Links"
249
  msgstr ""
250
 
251
+ #: google-calendar-events/includes/gce-feed-cpt.php:217
252
  msgid "Feed ID"
253
  msgstr ""
254
 
255
+ #: google-calendar-events/includes/gce-feed-cpt.php:218
256
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:73
257
  msgid "Feed Shortcode"
258
  msgstr ""
259
 
260
+ #: google-calendar-events/includes/gce-feed-cpt.php:219
261
  msgid "Display Type"
262
  msgstr ""
263
 
264
+ #: google-calendar-events/includes/gce-feed-cpt.php:246
265
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:152
266
  #: google-calendar-events/views/widgets.php:218
267
  msgid "Grid"
268
  msgstr ""
269
 
270
+ #: google-calendar-events/includes/gce-feed-cpt.php:248
271
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:153
272
  #: google-calendar-events/views/widgets.php:219
273
  msgid "List"
274
  msgstr ""
275
 
276
+ #: google-calendar-events/includes/gce-feed-cpt.php:250
277
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:154
278
  #: google-calendar-events/views/widgets.php:220
279
  msgid "Grouped List"
280
  msgstr ""
281
 
282
  #: google-calendar-events/includes/register-settings.php:29
283
+ msgid "Google API Key"
284
  msgstr ""
285
 
286
  #: google-calendar-events/includes/register-settings.php:30
287
  msgid ""
288
+ "If left blank all displayed Google calendars will use a public Google API "
289
+ "key shared across all plugin users."
290
+ msgstr ""
291
+
292
+ #: google-calendar-events/includes/register-settings.php:31
293
+ msgid ""
294
+ "Currently the shared key is limited to 500,000 requests per day and 5 "
295
+ "requests per second."
296
+ msgstr ""
297
+
298
+ #: google-calendar-events/includes/register-settings.php:32
299
+ #, php-format
300
+ msgid ""
301
+ "To avoid these limits <a href=\"%s\" target=\"_blank\">click here for "
302
+ "instructions on how to generate and use your own Google API key.</a>"
303
+ msgstr ""
304
+
305
+ #: google-calendar-events/includes/register-settings.php:39
306
+ msgid "Save Settings"
307
+ msgstr ""
308
+
309
+ #: google-calendar-events/includes/register-settings.php:40
310
+ msgid ""
311
  "Save your settings when uninstalling this plugin. Useful when upgrading or "
312
  "re-installing."
313
  msgstr ""
314
 
315
+ #: google-calendar-events/includes/register-settings.php:169
316
  #, php-format
317
  msgid ""
318
  "The callback function used for the <strong>%s</strong> setting is missing."
319
  msgstr ""
320
 
321
+ #: google-calendar-events/views/admin/api-settings-notice.php:27
322
+ msgid "GCal Events Important Update (Nov. 19, 2014):"
323
+ msgstr ""
324
+
325
+ #: google-calendar-events/views/admin/api-settings-notice.php:28
326
+ msgid ""
327
+ "GCal Events now uses the Google API version 3, which requires use of a "
328
+ "public key."
329
+ msgstr ""
330
+
331
+ #: google-calendar-events/views/admin/api-settings-notice.php:29
332
+ msgid ""
333
+ "By default a shared key is used across all plugin users, which is limited to "
334
+ "500,000 requests per day and 5 requests per second."
335
+ msgstr ""
336
+
337
+ #: google-calendar-events/views/admin/api-settings-notice.php:30
338
+ msgid "To avoid these limits you can use your own Google API key."
339
+ msgstr ""
340
+
341
+ #: google-calendar-events/views/admin/api-settings-notice.php:33
342
+ msgid "Update your API settings now"
343
+ msgstr ""
344
+
345
+ #: google-calendar-events/views/admin/api-settings-notice.php:34
346
+ msgid "Hide this"
347
+ msgstr ""
348
+
349
  #: google-calendar-events/views/admin/display-options-meta.php:39
350
  msgid ""
351
  "Check this box to use the simple display options below instead of the Event "
501
  msgstr ""
502
 
503
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:83
504
+ msgid "Google Calendar ID"
505
  msgstr ""
506
 
507
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:87
508
+ msgid "The Google Calendar ID."
509
  msgstr ""
510
 
511
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:87
513
  msgstr ""
514
 
515
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:89
516
+ msgid "How to find your GCal calendar ID"
517
  msgstr ""
518
 
519
  #: google-calendar-events/views/admin/gce-feed-meta-display.php:95
views/admin/api-settings-notice.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Show notice for API Settings
5
+ *
6
+ * @package GCE
7
+ * @subpackage admin/views
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ ?>
17
+
18
+ <style>
19
+ /* #gce-install-notice .button-primary, */
20
+ #gce-install-notice .button-secondary {
21
+ margin-left: 15px;
22
+ }
23
+ </style>
24
+
25
+ <div id="gce-install-notice" class="updated">
26
+ <p>
27
+ <strong><?php echo __( 'GCal Events Important Update (Nov. 19, 2014):', 'gce' ); ?></strong><br/>
28
+ <?php echo __( 'GCal Events now uses the Google API version 3, which requires use of a public key.', 'gce' ); ?>
29
+ <?php echo __( 'By default a shared key is used across all plugin users, which is limited to 500,000 requests per day and 5 requests per second.', 'gce' ); ?>
30
+ <?php echo __( 'To avoid these limits you can use your own Google API key.', 'gce' ); ?>
31
+ </p>
32
+ <p>
33
+ <a href="<?php echo admin_url( 'edit.php?post_type=gce_feed&page=google-calendar-events_general_settings' ); ?>" class="button-primary"><?php _e( 'Update your API settings now', 'gce' ); ?></a>
34
+ <a href="<?php echo add_query_arg( 'gce-dismiss-install-nag', 1 ); ?>" class="button-secondary"><?php _e( 'Hide this', 'gce' ); ?></a>
35
+ </p>
36
+ </div>
views/admin/gce-feed-meta-display.php CHANGED
@@ -80,13 +80,13 @@
80
  </td>
81
  </tr>
82
  <tr>
83
- <th scope="row"><label for="gce_feed_url"><?php _e( 'GCal Feed URL', 'gce' ); ?></label></th>
84
  <td>
85
- <input type="text" class="large-text" name="gce_feed_url" id="gce_feed_url" value="<?php echo $gce_feed_url; ?>" />
86
  <p class="description">
87
- <?php _e( 'The Google Calendar feed URL.', 'gce' ); ?> <?php _e( 'Example', 'gce' ); ?>:<br/>
88
- <code>https://www.google.com/calendar/feeds/em3luo1919fjcjum4j874j5ejg%40group.calendar.google.com/public/basic</code><br/>
89
- <a href="http://wpdocs.philderksen.com/google-calendar-events/getting-started/find-feed-url/" target="_blank"><?php _e( 'How to find your GCal feed URL', 'gce' ); ?></a>
90
  </p>
91
  </td>
92
  </tr>
80
  </td>
81
  </tr>
82
  <tr>
83
+ <th scope="row"><label for="gce_feed_url"><?php _e( 'Google Calendar ID', 'gce' ); ?></label></th>
84
  <td>
85
+ <input type="text" class="regular-text" style="width: 30em;" name="gce_feed_url" id="gce_feed_url" value="<?php echo $gce_feed_url; ?>" />
86
  <p class="description">
87
+ <?php _e( 'The Google Calendar ID.', 'gce' ); ?> <?php _e( 'Example', 'gce' ); ?>:<br/>
88
+ <code>umsb0ekhivs1a2ubtq6vlqvcjk@group.calendar.google.com</code><br/>
89
+ <a href="<?php echo gce_ga_campaign_url( 'http://wpdocs.philderksen.com/google-calendar-events/getting-started/find-calendar-id/', 'gce_lite', 'settings_link', 'docs' ); ?>" target="_blank"><?php _e( 'How to find your GCal calendar ID', 'gce' ); ?></a>
90
  </p>
91
  </td>
92
  </tr>