PluginProbe
WP GoToWebinar / trunk
WP GoToWebinar vtrunk
15.20 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 8.0 All 112 releases
wp-gotowebinar / wp-gotowebinar.php

wp-gotowebinar.php in WP GoToWebinar trunk, at wp-gotowebinar.php

1,828 lines 61.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: WP GoToWebinar
4 * Plugin URI: https://plugins.northernbeacheswebsites.com.au
5 * Description: Show upcoming GoToWebinars on any post or page or in a widget and register users on your website.
6 * Version: 15.20
7 * Author: Martin Gibson
8 * Author URI: https://plugins.northernbeacheswebsites.com.au
9 * Text Domain: wp-gotowebinar
10 * Support: https://plugins.northernbeacheswebsites.com.au/contact
11 * Licence: GPL2
12 */
13
14 use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
15
16 // Assign global variables
17 global $gotowebinar_is_pro;
18
19 if(file_exists(dirname( __FILE__ ).'/inc/pro/pro.php')){
20 $gotowebinar_is_pro = "YES";
21 } else {
22 $gotowebinar_is_pro = "NO";
23 }
24
25
26 //the first YES/NO in the array is if the feature is pro, the second YES/NO in the array is if a save settings button is necessary
27 global $gotowebinar_pro_features;
28 $gotowebinar_pro_features = array('General Options' => array('NO','YES'), 'Translation' => array('NO','YES'), 'Clear Cache' => array('NO','NO'), 'FAQ' => array('NO','NO'), 'Support' => array('NO','NO'), 'Log' => array('NO','NO'), 'Webinar Product Manager' => array('YES','NO'), 'Create a Webinar' => array('YES','NO'), 'Integration' => array('YES','YES'), 'Pro Options' => array('YES','YES'), 'Performance' => array('YES','NO'), 'Toolbar Countdown' => array('YES','YES'), 'Licence Activation' => array('YES','YES'));
29
30 global $time_zone_list;
31 $time_zone_list = array("Pacific/Tongatapu"=>13, "Pacific/Fiji"=>12, "Pacific/Auckland"=>12, "Asia/Magadan"=>11, "Asia/Vladivostok"=>10, "Australia/Hobart"=>10, "Pacific/Guam"=>10, "Australia/Sydney"=>10, "Australia/Brisbane"=>10, "Australia/Darwin"=>9.5, "Australia/Adelaide"=>9.5, "Asia/Yakutsk"=>9, "Asia/Seoul"=>9, "Asia/Tokyo"=>9, "Asia/Taipei"=>8, "Australia/Perth"=>8, "Asia/Singapore"=>8, "Asia/Irkutsk"=>8, "Asia/Shanghai"=>8, "Asia/Krasnoyarsk"=>7, "Asia/Bangkok"=>7, "Asia/Jakarta"=>7, "Asia/Rangoon"=>6.5, "Asia/Colombo"=>6, "Asia/Dhaka"=>6, "Asia/Novosibirsk"=>6, "Asia/Katmandu"=>5.75, "Asia/Calcutta"=>5.5, "Asia/Karachi"=>5, "Asia/Yekaterinburg"=>5, "Asia/Kabul"=>4.5, "Asia/Tbilisi"=>4, "Asia/Muscat"=>4, "Asia/Tehran"=>3.5, "Africa/Nairobi"=>3, "Europe/Moscow"=>3, "Asia/Kuwait"=>3, "Asia/Baghdad"=>3, "Asia/Jerusalem"=>2, "Europe/Helsinki"=>2, "Africa/Harare"=>2, "Africa/Cairo"=>2, "Europe/Bucharest"=>2, "Europe/Athens"=>2, "Africa/Malabo"=>1, "Europe/Warsaw"=>1, "Europe/Brussels"=>1, "Europe/Prague"=>1, "Europe/Amsterdam"=>1, "GMT"=>0, "Europe/London"=>0, "Africa/Casablanca"=>0, "Atlantic/Cape_Verde"=>-1, "Atlantic/Azores"=>-1, "America/Buenos_Aires"=>-3, "America/Sao_Paulo"=>-3, "America/St_Johns"=>-3, "America/Santiago"=>-4, "America/Caracas"=>-4, "America/Halifax"=>-4, "America/Indianapolis"=>-5, "America/New_York"=>-5, "America/Bogota"=>-5, "America/Mexico_City"=>-6, "America/Chicago"=>-6, "America/Denver"=>-7, "America/Phoenix"=>-7, "America/Los_Angeles"=>-8, "America/Anchorage"=>-9, "Pacific/Honolulu"=>-10, "MIT"=>-11);
32
33 //get plugin version number
34 function wpgotowebinar_plugin_get_version() {
35 if ( ! function_exists( 'get_plugins' ) )
36 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
37 $plugin_folder = get_plugins( '/' . plugin_basename( dirname( __FILE__ ) ) );
38 $plugin_file = basename( ( __FILE__ ) );
39 return $plugin_folder[$plugin_file]['Version'];
40 }
41
42 //gotowebinar api base
43 function wpgotowebinar_api_base() {
44 return 'https://api.getgo.com/G2W/rest/v2';
45 }
46
47
48 // Add a link to our plugin in the admin menu under Settings > GoToWebinar
49 function wp_gotowebinar_wp_menu() {
50 global $gotowebinar_wp_settings_page;
51 $gotowebinar_wp_settings_page = add_options_page(
52 'WP GoToWebinar Options',
53 'WP GoToWebinar',
54 'manage_options',
55 'wp-gotowebinar',
56 'wp_gotowebinar_options_page'
57 );
58 }
59 add_action('admin_menu','wp_gotowebinar_wp_menu');
60 add_action( 'admin_init', 'wp_gotowebinar_settings_init' );
61
62
63 //add a settings link on the plugin page
64 function plugin_add_settings_link( $links ) {
65 $settings_link = '<a href="options-general.php?page=wp-gotowebinar">' . __( 'Settings' ) . '</a>';
66 array_unshift( $links, $settings_link );
67 return $links;
68 }
69 $plugin = plugin_basename( __FILE__ );
70 add_filter( "plugin_action_links_$plugin", 'plugin_add_settings_link' );
71
72 //add custom links to plugin on plugins page
73 function wp_gotowebinar_custom_plugin_row_meta( $links, $file ) {
74 if ( strpos( $file, 'wp-gotowebinar.php' ) !== false ) {
75 $new_links = array(
76 '<a href="https://plugins.northernbeacheswebsites.com.au/product/donate-to-northern-beaches-websites/" target="_blank">' . __('Donate') . '</a>',
77 '<a href="https://plugins.northernbeacheswebsites.com.au/wp-gotowebinar-pro/" target="_blank">' . __('Pro Version') . '</a>',
78 '<a href="http://wordpress.org/support/plugin/wp-gotowebinar" target="_blank">' . __('Support Forum') . '</a>',
79 );
80 $links = array_merge( $links, $new_links );
81 }
82 return $links;
83 }
84 add_filter( 'plugin_row_meta', 'wp_gotowebinar_custom_plugin_row_meta', 10, 2 );
85
86 //Gets, sets and renders options
87 require('inc/options-output.php');
88
89 // Create our main options page
90 function wp_gotowebinar_options_page(){
91 require('inc/options-page-wrapper.php');
92 }
93
94
95 //get translations from plugin folder
96 add_action('plugins_loaded', 'wp_gotowebinar_translations');
97 function wp_gotowebinar_translations() {
98 load_plugin_textdomain( 'wp-gotowebinar', false, dirname( plugin_basename(__FILE__) ) . '/inc/lang/' );
99 }
100
101
102 //common function to get upcoming webinars
103 function wp_gotowebinar_upcoming_webinars($transientName, $transientDuration){
104 //get options
105 $options = get_option('gotowebinar_settings');
106 //get transient
107 $getTransient = get_transient($transientName);
108 //if transient doesn't exist or caching disabled do this
109 if ($getTransient != false){
110
111 $jsondata = $getTransient;
112 $json_response = 200;
113 return array($jsondata,$json_response);
114
115 } else {
116
117 //otherwise do this
118 list($access_token,$organizer_key) = wp_gotowebinar_get_access_and_refresh_token();
119
120 $currentTime = current_time('Y-m-d\TH:i:s\Z');
121 $currentTimePlusYear = date('Y-m-d\TH:i:s\Z', strtotime('+364 days', strtotime($currentTime)));
122 $currentTimeMinusDay = date('Y-m-d\TH:i:s\Z', strtotime('-1 day', strtotime($currentTime)));
123
124 $url = wpgotowebinar_api_base().'/organizers/'.$organizer_key.'/webinars?fromTime='.$currentTimeMinusDay.'&toTime='.$currentTimePlusYear.'&page=0&size=200';
125
126 $json_feed = wp_remote_get($url , array(
127 'headers' => array(
128 'Authorization' => $access_token,
129 ),
130 ));
131
132 $json_response = wp_remote_retrieve_response_code($json_feed);
133
134 //if response is successful set the transient
135 if($json_response == 200){
136
137 //store the data and response in a variable
138 $jsondata = json_decode(preg_replace('/("\w+"):(\d+(\.\d+)?)/', '\\1:"\\2"', wp_remote_retrieve_body( $json_feed )), true);
139
140 $jsondata = $jsondata['_embedded']['webinars'];
141
142
143 if(is_array($jsondata) && is_countable($jsondata) && count($jsondata)>0){
144 $webinarsToSort = array();
145
146 //cycle through the webinars
147 foreach($jsondata as $key1 => $webinar){
148
149 //get the key
150 $webinarKey = $webinar['webinarKey'];
151
152 //cycle through the times
153 foreach($webinar['times'] as $key2 => $time){
154
155 $startTime = $time['startTime'];
156 $endTime = $time['endTime'];
157
158 //this is not good enough, we also need to account for timezone
159 $time_zone = $webinar['timeZone'];
160
161 // Create DateTime object from UTC time
162 $startTimeCompare = new DateTime($startTime, new DateTimeZone('UTC'));
163
164 // Set timezone to Australia/Sydney
165 $startTimeCompare->setTimezone(new DateTimeZone($time_zone));
166
167 $start_time_compare = $startTimeCompare->getTimestamp();
168
169 // Output the new time with timezone adjustment
170 $startTimeCompare = $startTimeCompare->format('Y-m-d H:i:s T');
171
172 // Get the current timestamp
173 $current_timestamp = new DateTime();
174
175 $current_timestamp = $current_timestamp->getTimestamp();
176
177 //we only want to put stuff in the array which is in the future
178 if($start_time_compare > $current_timestamp ){
179 $webinarsToSort[$webinarKey.'-'.$key1.'-'.$key2] = $startTime;
180 }
181 }
182 }
183
184 //sort the array by value i.e. time
185 asort($webinarsToSort);
186
187 //create holding array
188 $jsondatareturn = array();
189
190 //loop through sorted array
191 foreach($webinarsToSort as $key => $value){
192
193 $explodeTheKey = explode('-',$key);
194
195 $webinarPosition = $explodeTheKey[1];
196 $timePosition = $explodeTheKey[2];
197
198 $webinarInstance = $jsondata[$webinarPosition];
199 $timeInstance = $webinarInstance['times'][$timePosition];
200
201 //now we want to remove the times from the array and then plug in the actual time of this part in the sequence
202 unset($webinarInstance['times']);
203
204 //now add the time back in with just the key
205 $webinarInstance['times'] = array($timeInstance);
206
207 //now add the webinar instance to the array
208 array_push($jsondatareturn,$webinarInstance);
209
210 }
211
212 set_transient($transientName,$jsondatareturn, $transientDuration);
213
214 //return the data and response
215 return array($jsondatareturn,$json_response);
216 } else {
217 return false;
218 }
219 } else {
220 return false;
221 }
222
223
224 } //end else
225 } //end function
226
227
228 //function to check authentication status
229 function wp_gotowebinar_authentication_check(){
230
231 //get options
232 $options = get_option('gotowebinar_settings');
233
234 list($access_token,$organizer_key) = wp_gotowebinar_get_access_and_refresh_token();
235
236 $currentTime = current_time('Y-m-d\TH:i:s\Z');
237 $currentTimePlusYear = date('Y-m-d\TH:i:s\Z', strtotime('+1 year', strtotime($currentTime)));
238
239 $json_feed = wp_remote_get( wpgotowebinar_api_base().'/organizers/'.$organizer_key.'/webinars?fromTime='.$currentTime.'&toTime='.$currentTimePlusYear.'&page=0&size=200', array(
240 'headers' => array(
241 'Authorization' => $access_token,
242 ),
243 ));
244
245 $json_response = wp_remote_retrieve_response_code($json_feed);
246
247 //return the data and response
248 return $json_response;
249
250
251 } //end function
252
253
254 // Add shortcode
255 if(file_exists(get_stylesheet_directory().'/wp-gotowebinar/shortcode.php')) {
256 require(get_stylesheet_directory().'/wp-gotowebinar/shortcode.php');
257 } else {
258 require('inc/shortcode.php');
259 }
260
261 // Add registration shortcode
262 if(file_exists(get_stylesheet_directory().'/wp-gotowebinar/shortcode-registration.php')) {
263 require(get_stylesheet_directory().'/wp-gotowebinar/shortcode-registration.php');
264 } else {
265 require('inc/shortcode-registration.php');
266 }
267
268 // Add calendar shortcode
269 if(file_exists(get_stylesheet_directory().'/wp-gotowebinar/shortcode-calendar.php')) {
270 require(get_stylesheet_directory().'/wp-gotowebinar/shortcode-calendar.php');
271 } else {
272 require('inc/shortcode-calendar.php');
273 }
274
275 // Add widget
276 require('inc/widget.php');
277
278
279 // Load front end style and scripts
280 function wp_gotowebinar_register_frontend() {
281
282 //register styles
283 wp_register_style( 'full-calendar-style', plugins_url('/inc/external/fullcalendar.min.css', __FILE__ ) );
284 wp_register_style( 'font-awesome-icons', plugins_url('/inc/external/all.min.css', __FILE__ ) );
285 wp_register_style( 'custom-style', plugins_url( '/inc/style.css', __FILE__ ),array(),wpgotowebinar_plugin_get_version());
286
287 //register scripts
288 wp_register_script( 'moment-gotowebinar', plugins_url('/inc/external/moment.js', __FILE__ ), array( 'jquery' ));
289 wp_register_script( 'moment-timezone', plugins_url('/inc/external/moment-timezone-with-data.js', __FILE__ ), array( 'jquery' ));
290 wp_register_script( 'full-calendar', plugins_url('/inc/external/fullcalendar.min.js', __FILE__ ), array( 'jquery' ));
291 wp_register_script( 'full-calendar-locale', plugins_url('/inc/external/locale-all.js', __FILE__ ), array( 'jquery' ));
292 wp_register_script( 'jquery-ui', plugins_url('/inc/external/jquery-ui.min.js', __FILE__ ), array( 'jquery'), '1.12.1');
293 wp_register_script( 'custom-script', plugins_url( '/inc/script.js', __FILE__ ), array( 'jquery' ),wpgotowebinar_plugin_get_version(),true);
294 wp_localize_script( 'custom-script', 'registration_form_submit', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
295 wp_localize_script( 'custom-script', 'integration_post', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
296 wp_register_script( 'timezone-detection', plugins_url('/inc/external/jstz.min.js', __FILE__ ), array( 'jquery' ));
297 wp_register_script( 'google-recaptcha-gotowebinar', 'https://www.google.com/recaptcha/api.js');
298
299
300 //need to load flipclock stuff on every page if enabled
301 $options = get_option('gotowebinar_settings');
302
303 if(isset($options['gotowebinar_toolbar_activate'])){
304 wp_enqueue_style( 'gotowebinar-flipclockstyle', plugins_url( '/inc/external/flipclock.css', __FILE__ ));
305 wp_enqueue_style( 'custom-style-everywhere', plugins_url( '/inc/style-everywhere.css', __FILE__ ),array(),wpgotowebinar_plugin_get_version());
306 wp_enqueue_script( 'gotowebinar-flipclock', plugins_url( '/inc/external/flipclock.min.js', __FILE__ ), array('jquery'));
307 wp_enqueue_script( 'gotowebinar-jquerycookie', plugins_url( '/inc/external/jquery.cookie.js', __FILE__ ), array('jquery'));
308 wp_enqueue_script( 'custom-script-everywhere', plugins_url( '/inc/script-everywhere.js', __FILE__ ), array( 'jquery' ),wpgotowebinar_plugin_get_version(),true);
309 }
310
311 //only output on checkout page
312 //check if woocommerce is active
313 if(class_exists('woocommerce')){
314 if(is_checkout()){
315 wp_enqueue_script( 'custom-script-woocommerce-checkout', plugins_url( '/inc/woocommerce-checkout.js', __FILE__ ), array( 'jquery' ),wpgotowebinar_plugin_get_version(),true);
316 }
317 }
318
319 }
320 add_action( 'wp_enqueue_scripts', 'wp_gotowebinar_register_frontend' );
321
322
323
324 // Load admin style and scripts
325 function wp_gotowebinar_register_admin($hook)
326 {
327 wp_enqueue_style( 'visual-composer-style', plugins_url( '/inc/vc-adminstyle.css', __FILE__ ));
328 global $gotowebinar_wp_settings_page;
329
330 global $post;
331 if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
332 if ( 'product' === $post->post_type ) {
333 wp_enqueue_script( 'custom-admin-script-pro', plugins_url( '/inc/pro/adminscriptpro.js', __FILE__ ), array( 'jquery'),wpgotowebinar_plugin_get_version());
334 }
335 if ( 'shop_order' === $post->post_type ) {
336 wp_enqueue_style( 'custom-admin-style-pro', plugins_url( '/inc/pro/adminstylepro.css', __FILE__ ),array(),wpgotowebinar_plugin_get_version());
337 }
338
339 }
340
341 if($hook != $gotowebinar_wp_settings_page)
342 return;
343
344
345 wp_enqueue_script('time-picker', plugins_url('/inc/external/jquery.timepicker.min.js', __FILE__ ), array('jquery'));
346
347 wp_enqueue_style( 'wp-color-picker' );
348 wp_enqueue_script( 'custom-admin-script', plugins_url( '/inc/adminscript.js', __FILE__ ), array( 'jquery','wp-color-picker' ),wpgotowebinar_plugin_get_version());
349 wp_enqueue_script('jquery-ui', plugins_url('/inc/external/jquery-ui.min.js', __FILE__ ), array( 'jquery'), '1.12.1');
350 wp_enqueue_script('jquery-form');
351 wp_enqueue_script('jquery-effects-shake');
352 wp_enqueue_script('chart','https://www.gstatic.com/charts/loader.js');
353 wp_enqueue_style( 'custom-admin-style', plugins_url( '/inc/adminstyle.css', __FILE__ ),array(),wpgotowebinar_plugin_get_version());
354 wp_register_style( 'font-awesome-icons', plugins_url('/inc/external/all.min.css', __FILE__ ) );
355 wp_register_style( 'time-picker-style', plugins_url('/inc/external/jquery.timepicker.min.css', __FILE__ ) );
356 wp_enqueue_style( array('font-awesome-icons','time-picker-style') );
357
358 wp_enqueue_script( 'moment-gotowebinar', plugins_url('/inc/external/moment.js', __FILE__ ), array( 'jquery' ));
359 wp_enqueue_script( 'moment-timezone', plugins_url('/inc/external/moment-timezone-with-data.js', __FILE__ ), array( 'jquery' ));
360
361 }
362 add_action( 'admin_enqueue_scripts', 'wp_gotowebinar_register_admin' );
363
364
365 // Include pro functions
366 if ($gotowebinar_is_pro == "YES"){
367 include('inc/pro/pro.php');
368 include('inc/pro/options-output-pro.php');
369 }
370 //clear cache and deactivation tasks
371 require('inc/clear-cache.php');
372 // add visual composer functionality
373 require('inc/visual-composer.php');
374 // add registration function
375 require('inc/registration.php');
376
377 //function to save dismiss welcome notice
378
379 function wp_gotowebinar_disable_welcome_message_callback() {
380
381 $gotowebinar_options = get_option('gotowebinar_settings');
382 $gotowebinar_options['gotowebinar_welcome_message'] = 1;
383
384 update_option('gotowebinar_settings', $gotowebinar_options);
385 wp_die();
386
387 }
388 add_action( 'wp_ajax_disable_welcome_message', 'wp_gotowebinar_disable_welcome_message_callback' );
389
390
391
392
393
394 //functions to register tinymce features
395 function wp_gotowebinar_register_plugin( $plugin_array ) {
396 $plugin_array['wpgotowebinar_button'] = plugins_url('/inc/tinymce.js', __FILE__ );
397 return $plugin_array;
398 }
399
400 function wp_gotowebinar_register_buttons($button) {
401 array_push($button, 'wpgotowebinar_button');
402 return $button;
403 }
404
405 function wp_gotowebinar_mce() {
406 if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
407 return;
408 }
409
410 if ('true' == get_user_option( 'rich_editing')){
411 add_filter( "mce_external_plugins", "wp_gotowebinar_register_plugin" );
412 add_filter( 'mce_buttons', 'wp_gotowebinar_register_buttons' );
413 }
414 }
415 add_action('init','wp_gotowebinar_mce');
416
417
418
419
420
421
422 //get timezones
423 function wp_gotowebinar_get_timezones() {
424 global $time_zone_list;
425
426 $list = array();
427
428 $list[] = array(
429 'text' => '',
430 'value' => ''
431 );
432
433 foreach($time_zone_list as $key => $value) {
434 $list[] = array(
435 'text' => $key,
436 'value' => $key
437 );
438 }
439
440 wp_send_json($list);
441 wp_die();
442 }
443
444 function wp_gotowebinar_get_timezones_ajax() {
445 // check for nonce
446 check_ajax_referer( 'wpgotowebinar-nonce', 'security' );
447 return wp_gotowebinar_get_timezones();
448 }
449 add_action( 'wp_ajax_get_timezones_list', 'wp_gotowebinar_get_timezones_ajax' );
450
451
452
453 //get upcoming webinars
454 function wp_gotowebinar_get_webinars() {
455
456 $options = get_option('gotowebinar_settings');
457
458 list($jsondata,$json_response) = wp_gotowebinar_upcoming_webinars('gtw_key', 86400);
459
460 $list = array();
461
462 $list[] = array(
463 'text' => 'Use most upcoming webinar',
464 'value' => 'upcoming'
465 );
466
467 if($json_response == 200){
468 foreach ($jsondata as $data) {
469
470 foreach($data['times'] as $mytimes) {
471 $date = new DateTime($mytimes['startTime']);
472 $startTime = $date->format(wp_gotowebinar_date_format());
473 }
474
475 $list[] = array(
476 'text' => $data['subject'].' ('.$startTime.')',
477 'value' => $data['webinarKey']
478 );
479 }
480 }
481
482 wp_send_json($list);
483 wp_die();
484
485 }
486
487 function wp_gotowebinar_get_webinars_ajax() {
488 // check for nonce
489 check_ajax_referer( 'wpgotowebinar-nonce', 'security' );
490 return wp_gotowebinar_get_webinars();
491 }
492 add_action( 'wp_ajax_get_webinars_list', 'wp_gotowebinar_get_webinars_ajax' );
493
494
495
496
497
498 //get mailchimp lists
499 function wp_gotowebinar_get_mailchimp() {
500
501 $options = get_option('gotowebinar_settings');
502
503 if(isset($options['gotowebinar_mailchimp_api']) && strlen($options['gotowebinar_mailchimp_api'])>0){
504
505 list($jsondata,$json_response) = wp_gotowebinar_mailchimp_list_hint();
506
507 if (200 == $json_response) {
508
509 $lists = array();
510
511 foreach($jsondata['lists'] as $list){
512
513 $lists[] = array(
514 'text' => $list['name'],
515 'value' => $list['id']
516 );
517 }
518
519 wp_send_json($lists);
520 wp_die();
521
522 }
523 }
524 }
525
526 function wp_gotowebinar_get_mailchimp_ajax() {
527 // check for nonce
528 check_ajax_referer( 'wpgotowebinar-nonce', 'security' );
529 return wp_gotowebinar_get_mailchimp();
530 }
531 add_action( 'wp_ajax_get_mailchimp_list', 'wp_gotowebinar_get_mailchimp_ajax');
532
533
534
535
536
537 //get constantcontact lists
538 function wp_gotowebinar_get_constantcontact() {
539
540 $options = get_option('gotowebinar_settings');
541
542 if(isset($options['gotowebinar_constantcontact_token']) && strlen($options['gotowebinar_constantcontact_token'])>0){
543
544 list($jsondata,$json_response) = wp_gotowebinar_constantcontact_list_hint();
545
546 if (200 == $json_response) {
547
548 $lists = array();
549
550 foreach($jsondata as $list){
551
552 $lists[] = array(
553 'text' => $list['name'],
554 'value' => $list['id']
555 );
556 }
557
558 wp_send_json($lists);
559 wp_die();
560
561 }
562 }
563 }
564
565 function wp_gotowebinar_get_constantcontact_ajax() {
566 // check for nonce
567 check_ajax_referer( 'wpgotowebinar-nonce', 'security' );
568 return wp_gotowebinar_get_constantcontact();
569 }
570 add_action( 'wp_ajax_get_constantcontact_list', 'wp_gotowebinar_get_constantcontact_ajax');
571
572
573
574
575
576 //get activecampaign lists
577 function wp_gotowebinar_get_activecampaign() {
578
579 $options = get_option('gotowebinar_settings');
580
581 if(isset($options['gotowebinar_activecampaign_account']) && strlen($options['gotowebinar_activecampaign_account'])>0){
582
583 list($jsondata,$json_response) = wp_gotowebinar_activecampaign_list_hint();
584
585 if (200 == $json_response) {
586
587 $lists = array();
588
589 foreach($jsondata as $list){
590 if (is_array($list) && isset($list['name'])) {
591 $lists[] = array(
592 'text' => $list['name'],
593 'value' => $list['id']
594 );
595 }
596 }
597
598 wp_send_json($lists);
599 wp_die();
600
601 }
602 }
603 }
604
605 function wp_gotowebinar_get_activecampaign_ajax() {
606 // check for nonce
607 check_ajax_referer( 'wpgotowebinar-nonce', 'security' );
608 return wp_gotowebinar_get_activecampaign();
609 }
610 add_action( 'wp_ajax_get_activecampaign_list', 'wp_gotowebinar_get_activecampaign_ajax');
611
612
613
614
615
616
617
618 //get campaignmonitor lists
619 function wp_gotowebinar_get_campaignmonitor() {
620
621 $options = get_option('gotowebinar_settings');
622
623 if(isset($options['gotowebinar_campaignmonitor_client_id']) && strlen($options['gotowebinar_campaignmonitor_client_id'])>0){
624
625 list($jsondata,$json_response) = wp_gotowebinar_campaignmonitor_list_hint();
626
627 if (200 == $json_response) {
628
629 $lists = array();
630
631 foreach($jsondata as $list){
632 if (is_array($list) && isset($list['Name'])) {
633 $lists[] = array(
634 'text' => $list['Name'],
635 'value' => $list['ListID']
636 );
637 }
638 }
639
640 wp_send_json($lists);
641 wp_die();
642
643 }
644 }
645 }
646
647 function wp_gotowebinar_get_campaignmonitor_ajax() {
648 // check for nonce
649 check_ajax_referer( 'wpgotowebinar-nonce', 'security' );
650 return wp_gotowebinar_get_campaignmonitor();
651 }
652 add_action( 'wp_ajax_get_campaignmonitor_list', 'wp_gotowebinar_get_campaignmonitor_ajax');
653
654
655
656
657
658
659
660
661
662 //get aweber lists
663 function wp_gotowebinar_get_aweber() {
664
665 $options = get_option('gotowebinar_settings');
666
667 if(isset($options['gotowebinar_aweber_token']) && strlen($options['gotowebinar_aweber_token'])>0){
668
669 list($jsondata,$json_response) = wp_gotowebinar_aweber_list_hint();
670
671 if (200 == $json_response) {
672
673 $lists = array();
674
675 foreach($jsondata['entries'] as $key => $list){
676
677 $lists[] = array(
678 'text' => $list['name'],
679 'value' => $list['id']
680 );
681
682 }
683
684 wp_send_json($lists);
685 wp_die();
686
687 }
688 }
689 }
690
691 function wp_gotowebinar_get_aweber_ajax() {
692 // check for nonce
693 check_ajax_referer( 'wpgotowebinar-nonce', 'security' );
694 return wp_gotowebinar_get_aweber();
695 }
696 add_action( 'wp_ajax_get_aweber_list', 'wp_gotowebinar_get_aweber_ajax');
697
698
699
700
701
702
703
704 function wp_gotowebinar_send_tinymce_data() {
705 // create nonce
706 global $pagenow;
707 if( $pagenow != 'admin.php' ){
708 $nonce = wp_create_nonce( 'wpgotowebinar-nonce' );
709 ?><script type="text/javascript">
710 jQuery( document ).ready( function( $ ) {
711 var data = {
712 'action' : 'get_timezones_list', // wp ajax action
713 'security' : '<?php echo $nonce; ?>' // nonce value created earlier
714 };
715 // fire ajax
716 jQuery.post(ajaxurl, data, function(response) {
717 // if nonce fails then not authorized else settings saved
718 if( response === '-1' ){
719 } else {
720 if (typeof(tinyMCE) != 'undefined') {
721 if (tinyMCE.activeEditor != null) {
722 tinyMCE.activeEditor.settings.timezoneList = response;
723 }
724 }
725 }
726 });
727 var data = {
728 'action' : 'get_webinars_list', // wp ajax action
729 'security' : '<?php echo $nonce; ?>' // nonce value created earlier
730 };
731 // fire ajax
732 jQuery.post(ajaxurl, data, function(response) {
733 // if nonce fails then not authorized else settings saved
734 if( response === '-1' ){
735 } else {
736 if (typeof(tinyMCE) != 'undefined') {
737 if (tinyMCE.activeEditor != null) {
738 tinyMCE.activeEditor.settings.webinarList = response;
739 }
740 }
741 }
742 });
743 var data = {
744 'action' : 'get_mailchimp_list', // wp ajax action
745 'security' : '<?php echo $nonce; ?>' // nonce value created earlier
746 };
747 // fire ajax
748 jQuery.post(ajaxurl, data, function(response) {
749 // if nonce fails then not authorized else settings saved
750 if( response === '-1' ){
751 } else {
752 if (typeof(tinyMCE) != 'undefined') {
753 if (tinyMCE.activeEditor != null) {
754 tinyMCE.activeEditor.settings.mailchimpList = response;
755 }
756 }
757 }
758 });
759 var data = {
760 'action' : 'get_constantcontact_list', // wp ajax action
761 'security' : '<?php echo $nonce; ?>' // nonce value created earlier
762 };
763 // fire ajax
764 jQuery.post(ajaxurl, data, function(response) {
765 // if nonce fails then not authorized else settings saved
766 if( response === '-1' ){
767 } else {
768 if (typeof(tinyMCE) != 'undefined') {
769 if (tinyMCE.activeEditor != null) {
770 tinyMCE.activeEditor.settings.constantcontactList = response;
771 }
772 }
773 }
774 });
775 var data = {
776 'action' : 'get_activecampaign_list', // wp ajax action
777 'security' : '<?php echo $nonce; ?>' // nonce value created earlier
778 };
779 // fire ajax
780 jQuery.post(ajaxurl, data, function(response) {
781 // if nonce fails then not authorized else settings saved
782 if( response === '-1' ){
783 } else {
784 if (typeof(tinyMCE) != 'undefined') {
785 if (tinyMCE.activeEditor != null) {
786 tinyMCE.activeEditor.settings.activecampaignList = response;
787 }
788 }
789 }
790 });
791 var data = {
792 'action' : 'get_campaignmonitor_list', // wp ajax action
793 'security' : '<?php echo $nonce; ?>' // nonce value created earlier
794 };
795 // fire ajax
796 jQuery.post(ajaxurl, data, function(response) {
797 // if nonce fails then not authorized else settings saved
798 if( response === '-1' ){
799 } else {
800 if (typeof(tinyMCE) != 'undefined') {
801 if (tinyMCE.activeEditor != null) {
802 tinyMCE.activeEditor.settings.campaignmonitorList = response;
803 }
804 }
805 }
806 });
807 var data = {
808 'action' : 'get_aweber_list', // wp ajax action
809 'security' : '<?php echo $nonce; ?>' // nonce value created earlier
810 };
811 // fire ajax
812 jQuery.post(ajaxurl, data, function(response) {
813 // if nonce fails then not authorized else settings saved
814 if( response === '-1' ){
815 } else {
816 if (typeof(tinyMCE) != 'undefined') {
817 if (tinyMCE.activeEditor != null) {
818 tinyMCE.activeEditor.settings.aweberList = response;
819 }
820 }
821 }
822 });
823
824 });
825 </script>
826 <?php
827 }
828 }
829 add_action('admin_footer','wp_gotowebinar_send_tinymce_data');
830
831
832
833
834
835
836
837
838
839
840
841 //get email service list hints for use in tinymce and visual composer shortcode builder and also in pro settings
842 function wp_gotowebinar_mailchimp_list_hint() {
843
844 $options = get_option('gotowebinar_settings');
845
846 if(isset($options['gotowebinar_mailchimp_api']) && strlen($options['gotowebinar_mailchimp_api'])>0){
847
848 $serverCenter = substr($options['gotowebinar_mailchimp_api'], strpos($options['gotowebinar_mailchimp_api'],'-')+1);
849
850 $response = wp_remote_get( 'https://'.$serverCenter.'.api.mailchimp.com/3.0/lists', array(
851 'headers' => array(
852 'Authorization' => 'Basic '. base64_encode('anystring:'.$options['gotowebinar_mailchimp_api']),
853 ),
854 ));
855
856 $jsondata = json_decode(preg_replace('/("\w+"):(\d+(\.\d+)?)/', '\\1:"\\2"', wp_remote_retrieve_body( $response )), true);
857 $json_response = wp_remote_retrieve_response_code($response);
858
859 return array($jsondata,$json_response);
860
861 }
862 }
863
864 function wp_gotowebinar_constantcontact_list_hint() {
865
866 $options = get_option('gotowebinar_settings');
867
868 if(isset($options['gotowebinar_constantcontact_token']) && strlen($options['gotowebinar_constantcontact_token'])>0){
869
870 $response = wp_remote_get('https://api.constantcontact.com/v2/lists?api_key=me68vunsy43cw654ydm2tucf', array(
871 'headers' => array(
872 'Authorization' => 'Bearer '.$options['gotowebinar_constantcontact_token'],
873 ),
874 ));
875
876 $jsondata = json_decode(preg_replace('/("\w+"):(\d+(\.\d+)?)/', '\\1:"\\2"', wp_remote_retrieve_body( $response )), true);
877 $json_response = wp_remote_retrieve_response_code($response);
878
879 return array($jsondata,$json_response);
880
881 }
882 }
883
884 function wp_gotowebinar_activecampaign_list_hint() {
885
886 $options = get_option('gotowebinar_settings');
887
888 if(isset($options['gotowebinar_activecampaign_account']) && strlen($options['gotowebinar_activecampaign_account'])>0){
889
890 $response = wp_remote_get($options['gotowebinar_activecampaign_account'].'/admin/api.php?api_action=list_list&api_key='.$options['gotowebinar_activecampaign_api'].'&ids=all&api_output=json', array(
891 'headers' => array(
892 'Content-Type' => 'application/json',
893 'Content-Type' => 'application/json; charset=utf-8',
894 )
895 ));
896
897 $jsondata = json_decode(preg_replace('/("\w+"):(\d+(\.\d+)?)/', '\\1:"\\2"', wp_remote_retrieve_body( $response )), true);
898 $json_response = wp_remote_retrieve_response_code($response);
899
900 return array($jsondata,$json_response);
901
902 }
903 }
904
905
906 function wp_gotowebinar_campaignmonitor_list_hint() {
907
908 $options = get_option('gotowebinar_settings');
909
910 if(isset($options['gotowebinar_campaignmonitor_client_id']) && strlen($options['gotowebinar_campaignmonitor_client_id'])>0){
911
912 $response = wp_remote_get('https://api.createsend.com/api/v3.1/clients/'.$options['gotowebinar_campaignmonitor_client_id'].'/lists.json?pretty=true', array(
913 'headers' => array(
914 'Authorization' => 'Basic '. base64_encode($options['gotowebinar_campaignmonitor_api']),
915 ),
916 ));
917
918 $jsondata = json_decode(preg_replace('/("\w+"):(\d+(\.\d+)?)/', '\\1:"\\2"', wp_remote_retrieve_body( $response )), true);
919 $json_response = wp_remote_retrieve_response_code($response);
920
921 return array($jsondata,$json_response);
922
923 }
924 }
925
926
927
928
929
930
931
932
933
934 function wp_gotowebinar_aweber_account_hint() {
935
936 $options = get_option('gotowebinar_settings');
937
938 if(isset($options['gotowebinar_aweber_token']) && strlen($options['gotowebinar_aweber_token'])>0){
939
940 //lets first get the account id
941
942 //get authorization code from settings
943 $authorizationCode = $options['gotowebinar_aweber_authorization_code'];
944 $separateData = explode("|",$authorizationCode);
945 $applicationKey = $separateData[0];
946 $applicationSecret = $separateData[1];
947 $nonce = wp_create_nonce('aweber');
948 $unixTimestamp = time();
949
950 $url = 'https://api.aweber.com/1.0/accounts';
951
952 //start building a string which will be encoded and turned into the oauth1 signature
953 $signatureBaseString = 'oauth_consumer_key=';
954 $signatureBaseString .= $applicationKey;
955 $signatureBaseString .= '&oauth_nonce=';
956 $signatureBaseString .= $nonce;
957 $signatureBaseString .= '&oauth_signature_method=HMAC-SHA1&oauth_timestamp=';
958 $signatureBaseString .= $unixTimestamp;
959 $signatureBaseString .= '&oauth_token=';
960 $signatureBaseString .= $options['gotowebinar_aweber_token'];
961 $signatureBaseString .= '&oauth_version=1.0';
962
963 //encode the signature
964 $signatureBaseString = 'GET&'.urlencode($url).'&'.urlencode($signatureBaseString);
965
966 //the key of the signature
967 $sigKey = $applicationSecret.'&'.$options['gotowebinar_aweber_token_secret'];
968
969 //the final signature woohoo!
970 $signature = base64_encode(hash_hmac('sha1', $signatureBaseString, $sigKey, true));
971
972 $response = wp_remote_get($url, array(
973 'headers' => array(
974 'Authorization' => 'OAuth oauth_consumer_key="'.$applicationKey.'", oauth_nonce="'.$nonce.'", oauth_signature="'.$signature.'", oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.$unixTimestamp.'", oauth_token="'.$options['gotowebinar_aweber_token'].'", oauth_version="1.0"',
975 ),
976 ));
977
978 $jsondata = json_decode(preg_replace('/("\w+"):(\d+(\.\d+)?)/', '\\1:"\\2"', wp_remote_retrieve_body( $response )), true);
979 $json_response = wp_remote_retrieve_response_code($response);
980
981 return array($jsondata,$json_response);
982
983 }
984 }
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005 function wp_gotowebinar_aweber_list_hint() {
1006
1007 $options = get_option('gotowebinar_settings');
1008
1009 if(isset($options['gotowebinar_aweber_accounts']) && strlen($options['gotowebinar_aweber_token'])>0){
1010
1011 //get authorization code from settings
1012 $authorizationCode = $options['gotowebinar_aweber_authorization_code'];
1013 $separateData = explode("|",$authorizationCode);
1014 $applicationKey = $separateData[0];
1015 $applicationSecret = $separateData[1];
1016 $nonce = wp_create_nonce('aweber');
1017 $unixTimestamp = time();
1018
1019 //start building a string which will be encoded and turned into the oauth1 signature
1020 $signatureBaseString = 'oauth_consumer_key=';
1021 $signatureBaseString .= $applicationKey;
1022 $signatureBaseString .= '&oauth_nonce=';
1023 $signatureBaseString .= $nonce;
1024 $signatureBaseString .= '&oauth_signature_method=HMAC-SHA1&oauth_timestamp=';
1025 $signatureBaseString .= $unixTimestamp;
1026 $signatureBaseString .= '&oauth_token=';
1027 $signatureBaseString .= $options['gotowebinar_aweber_token'];
1028 $signatureBaseString .= '&oauth_version=1.0';
1029
1030 //get the new url for lists with the accountid placed inside
1031 $url = 'https://api.aweber.com/1.0/accounts/'.$options['gotowebinar_aweber_accounts'].'/lists';
1032
1033 //encode the signature
1034 $signatureBaseString = 'GET&'.urlencode($url).'&'.urlencode($signatureBaseString);
1035
1036 //the key of the signature
1037 $sigKey = $applicationSecret.'&'.$options['gotowebinar_aweber_token_secret'];
1038
1039 //the final signature woohoo!
1040 $signature = base64_encode(hash_hmac('sha1', $signatureBaseString, $sigKey, true));
1041
1042 $response = wp_remote_get($url, array(
1043 'headers' => array(
1044 'Authorization' => 'OAuth oauth_consumer_key="'.$applicationKey.'", oauth_nonce="'.$nonce.'", oauth_signature="'.$signature.'", oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.$unixTimestamp.'", oauth_token="'.$options['gotowebinar_aweber_token'].'", oauth_version="1.0"',
1045 ),
1046 ));
1047
1048 $jsondata = json_decode(preg_replace('/("\w+"):(\d+(\.\d+)?)/', '\\1:"\\2"', wp_remote_retrieve_body( $response )), true);
1049 $json_response = wp_remote_retrieve_response_code($response);
1050
1051 return array($jsondata,$json_response);
1052
1053 }
1054 }
1055
1056
1057
1058
1059 //add item to log
1060 function wp_gotowebinar_add_log_item($type,$message,$user) {
1061
1062 include(ABSPATH . "wp-includes/pluggable.php");
1063 $options = get_option('gotowebinar_settings');
1064
1065
1066 if(get_option('gotowebinar_log')===false){
1067 add_option( 'gotowebinar_log',array(), '', 'yes' );
1068 }
1069
1070 $currentOption = get_option('gotowebinar_log');
1071
1072 //get the current user name
1073 $current_user = wp_get_current_user();
1074 $userFullName = $current_user->user_firstname.' '.$current_user->user_lastname;
1075
1076 if(strlen($userFullName)<2) {
1077 $name = $current_user->user_login;
1078 } else {
1079 $name = $userFullName;
1080 }
1081
1082 //get the time
1083 $currentDate = date_i18n(wp_gotowebinar_date_format(), current_time('timestamp'),true);
1084 $currentTime = date_i18n(str_replace(" T","",wp_gotowebinar_time_format()), current_time('timestamp'),true);
1085 $fullDateTime = $currentDate.' '.$currentTime;
1086
1087 if($user == true){
1088 $newLogItem = array($type,$fullDateTime,$message,$name);
1089 } else {
1090 $newLogItem = array($type,$fullDateTime,$message,'');
1091 }
1092
1093
1094
1095 //if there are more than 200 log entries lets start removing the earlier log entrie
1096 if(count($currentOption)>=200){
1097 array_shift($currentOption);
1098 }
1099
1100 //add the new item to the array
1101 array_push($currentOption,$newLogItem);
1102
1103 //update the option
1104 update_option('gotowebinar_log',$currentOption,'yes');
1105
1106 }
1107
1108
1109 function wp_gotowebinar_add_create_webinar_log_item(){
1110
1111 $nonce = $_POST['nonce'];
1112
1113 if ( current_user_can( 'manage_options' ) && wp_verify_nonce($nonce, 'create_product_log') ) {
1114
1115 $type = sanitize_text_field($_POST['type']);
1116 $message = sanitize_text_field($_POST['message']);
1117 $user = true;
1118
1119 wp_gotowebinar_add_log_item($type,$message,$user);
1120
1121 }
1122 wp_die();
1123 }
1124 add_action( 'wp_ajax_create_product_log', 'wp_gotowebinar_add_create_webinar_log_item' );
1125
1126
1127 //Function to run upon ajax request to delete log
1128 function wp_gotowebinar_delete_log_callback() {
1129
1130 $nonce = $_POST['nonce'];
1131
1132 if( wp_verify_nonce($nonce, 'delete_log') && current_user_can('administrator') ){
1133 delete_option('gotowebinar_log');
1134 }
1135
1136 wp_die();
1137 }
1138 add_action( 'wp_ajax_delete_log', 'wp_gotowebinar_delete_log_callback' );
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168 if($gotowebinar_is_pro == "YES"){
1169
1170 //initialise the update check
1171 require 'inc/pro/plugin-update-checker/plugin-update-checker.php';
1172
1173 global $plugin_update_checker_wp_gotowebinar;
1174
1175 $plugin_update_checker_wp_gotowebinar = PucFactory::buildUpdateChecker(
1176 'https://plugins.northernbeacheswebsites.com.au/?update_action=get_metadata&update_slug=wp-gotowebinar', //Metadata URL.
1177 __FILE__, //Full path to the main plugin file.
1178 'wp-gotowebinar' //Plugin slug. Usually it's the same as the name of the directory.
1179 );
1180
1181
1182 //add queries to the update call
1183 $plugin_update_checker_wp_gotowebinar->addQueryArgFilter('filter_update_checks_wp_gotowebinar');
1184 function filter_update_checks_wp_gotowebinar($queryArgs) {
1185
1186
1187 $pluginSettings = get_option('gotowebinar_settings');
1188
1189
1190 if(isset($pluginSettings['gotowebinar_licence_activation_purchase_email']) && isset($pluginSettings['gotowebinar_licence_activation_order_id'])){
1191
1192 $purchaseEmailAddress = $pluginSettings['gotowebinar_licence_activation_purchase_email'];
1193 $orderId = $pluginSettings['gotowebinar_licence_activation_order_id'];
1194 $siteUrl = get_site_url();
1195 $siteUrl = parse_url($siteUrl);
1196 $siteUrl = $siteUrl['host'];
1197
1198 if (!empty($purchaseEmailAddress) && !empty($orderId)) {
1199 $queryArgs['purchaseEmailAddress'] = $purchaseEmailAddress;
1200 $queryArgs['orderId'] = $orderId;
1201 $queryArgs['siteUrl'] = $siteUrl;
1202 $queryArgs['productId'] = '8018';
1203 }
1204
1205 }
1206
1207 return $queryArgs;
1208 }
1209
1210
1211
1212 // define the puc_request_info_result-<slug> callback
1213 $plugin_update_checker_wp_gotowebinar->addFilter(
1214 'request_info_result', 'filter_puc_request_info_result_slug_wp_gotowebinar', 10, 2
1215 );
1216 function filter_puc_request_info_result_slug_wp_gotowebinar( $plugininfo, $result ) {
1217 //get the message from the server and set as transient
1218 set_transient('wp-gotowebinar-update',$plugininfo->{'message'},YEAR_IN_SECONDS * 1);
1219
1220 return $plugininfo;
1221 };
1222
1223
1224
1225
1226
1227
1228 $path = plugin_basename( __FILE__ );
1229
1230 add_action("after_plugin_row_{$path}", function( $plugin_file, $plugin_data, $status ) {
1231
1232 //get plugin settings
1233 $pluginSettings = get_option('gotowebinar_settings');
1234
1235
1236 if (!empty($pluginSettings['gotowebinar_licence_activation_purchase_email']) && !empty($pluginSettings['gotowebinar_licence_activation_order_id'])) {
1237
1238 $order_id = $pluginSettings['gotowebinar_licence_activation_order_id'];
1239
1240 //get transient
1241 $message = get_transient('wp-gotowebinar-update');
1242
1243 if($message !== 'Yes' && $message !== false){
1244
1245 $purchaseLink = 'https://plugins.northernbeacheswebsites.com.au/wp-gotowebinar-pro/';
1246
1247 if($message == 'Incorrect Details'){
1248 $displayMessage = 'The Order ID and Purchase ID you entered is not correct. Please double check the details you entered to receive product updates.';
1249 } elseif ($message == 'Licence Expired'){
1250 $displayMessage = 'Your licence has expired. Please <a href="'.$purchaseLink.'" target="_blank">purchase a new licence</a> to receive further updates for this plugin.';
1251 } elseif ($message == 'Website Mismatch') {
1252 $displayMessage = 'This plugin has already been registered on another website using your details. Under the licence terms this plugin can only be used on one website. Please <a href="'.$purchaseLink.'" target="_blank">click here</a> to purchase an additional licence. To change the website assigned to your licence, please click <a href="https://plugins.northernbeacheswebsites.com.au/my-account/view-order/'.$order_id.'/" target="_blank">here</a>.';
1253 } else {
1254 $displayMessage = '';
1255 }
1256
1257 echo '<tr class="plugin-update-tr active"><td colspan="3" class="plugin-update colspanchange"><div class="update-message notice inline notice-error notice-alt"><p class="installer-q-icon">'.$displayMessage.'</p></div></td></tr>';
1258
1259 }
1260
1261 } else {
1262
1263 echo '<tr class="plugin-update-tr active"><td colspan="3" class="plugin-update colspanchange"><div class="update-message notice inline notice-error notice-alt"><p class="installer-q-icon">Please enter your Order ID and Purchase ID in the plugin settings to receive automatics updates.</p></div></td></tr>';
1264
1265 }
1266
1267
1268 }, 10, 3 );
1269
1270 /**
1271 *
1272 *
1273 *
1274 * Force check for updates
1275 */
1276 function wp_gotowebinar_force_check_for_updates(){
1277 global $plugin_update_checker_wp_gotowebinar;
1278
1279 $plugin_update_checker_wp_gotowebinar->checkForUpdates();
1280 }
1281
1282 }
1283
1284
1285 //this common function checks whether to include or exclude the webinar in the shortcode and returns true or false
1286 //its a pretty boring function with a whole bunch of if conditions
1287 function wp_gotowebinar_include_exclude_check($shortcodeData,$webinarTitle,$includeExclude){
1288
1289
1290
1291 //first if the short data is blank lets return true
1292 if($shortcodeData==''){
1293
1294 return true;
1295 }
1296
1297 //lets check if the shortcode data contains AND or OR statements
1298 if(strpos($shortcodeData, 'AND') !== false){
1299
1300 $andArray = explode('AND',$shortcodeData);
1301 $countOfItemsInArray = count($andArray);
1302 $countOfConditionsMet = 0;
1303
1304 foreach($andArray as $condition){
1305 if(strpos($webinarTitle,$condition) !== false){
1306 $countOfConditionsMet++;
1307 }
1308 }
1309
1310 if($includeExclude == 'include'){
1311 //do include condition
1312 if($countOfItemsInArray == $countOfConditionsMet){
1313 return true;
1314 } else {
1315 return false;
1316 }
1317 } else {
1318 //do exclude condition
1319 if($countOfItemsInArray == $countOfConditionsMet){
1320 return false;
1321 } else {
1322 return true;
1323 }
1324 }
1325
1326 } elseif (strpos($shortcodeData, 'OR') !== false){
1327
1328 $orArray = explode('OR',$shortcodeData);
1329
1330 $countOfConditionsMet = 0;
1331
1332 foreach($orArray as $condition){
1333 if(strpos($webinarTitle,$condition) !== false){
1334 $countOfConditionsMet++;
1335 }
1336 }
1337
1338 if($includeExclude == 'include'){
1339 //do include condition
1340 if($countOfConditionsMet > 0){
1341
1342 return true;
1343 } else {
1344
1345 return false;
1346 }
1347 } else {
1348 //do exclude condition
1349 if($countOfConditionsMet > 0){
1350 return false;
1351 } else {
1352 return true;
1353 }
1354 }
1355 } else {
1356
1357
1358
1359 if($includeExclude == 'include'){
1360 //include condition
1361 if(strpos($webinarTitle,$shortcodeData) !== false){
1362 return true;
1363 } else {
1364 return false;
1365 }
1366
1367 } else {
1368 //exclude condition
1369 if(strpos($webinarTitle,$shortcodeData) !== false){
1370 return false;
1371 } else {
1372
1373
1374 return true;
1375
1376
1377 }
1378 }
1379 }
1380
1381 }
1382
1383
1384 //common function to check timezone
1385 function wp_gotowebinar_timezone_check($shortcodeData,$webinarTimezone){
1386
1387 //if the shortcode is blank return true
1388 if($shortcodeData == '' || $shortcodeData == 'Show All'){
1389 return true;
1390 }
1391
1392 if(strpos($webinarTimezone,$shortcodeData) !== false){
1393 return true;
1394 } else {
1395 return false;
1396 }
1397
1398
1399 }
1400
1401
1402 //common function hide parts of the title of a webinar
1403 function wp_gotowebinar_hide_from_title($hideData,$webinarTitle){
1404
1405 if($hideData == ''){
1406 return $webinarTitle;
1407 }
1408
1409 if(strpos($hideData, 'AND') !== false) {
1410 $andArray = explode('AND',$hideData);
1411
1412 foreach($andArray as $condition){
1413 $webinarTitle = str_replace($condition,"",$webinarTitle);
1414 }
1415
1416 return $webinarTitle;
1417
1418 } else {
1419 //theres no and so do a simple replace
1420 return str_replace($hideData,"",$webinarTitle);
1421 }
1422
1423
1424 }
1425
1426
1427
1428
1429 //common function to get access token and update the refresh token in the settings with the new refresh token
1430 function wp_gotowebinar_get_access_and_refresh_token() {
1431
1432
1433 //first we need to get the transient, if the transient exists use that for the authorisation and organiser key
1434 $getTransient = get_transient('gotowebinar_auth_settings');
1435
1436 //if the transient exists
1437 if ($getTransient != false){
1438
1439 //if transient exists get the current transient
1440
1441 //explode the transient
1442 $explodedTransient = explode("|", $getTransient);
1443
1444 return array($explodedTransient[0],$explodedTransient[1]);
1445
1446 } else {
1447
1448
1449 //the transient doesn't exist therefore do api call
1450
1451 $pluginSettings = get_option('gotowebinar_auth_settings');
1452
1453 //current refresh token
1454 $currentRefreshToken = $pluginSettings['refresh_token'];
1455
1456 //do response
1457 $response = wp_remote_post( 'https://authentication.logmeininc.com/oauth/token', array(
1458 'headers' => array(
1459 'Authorization' => 'Basic '.wp_gotowebinar_get_authorization(),
1460 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
1461 ),
1462 'body' => array(
1463 'refresh_token' => $currentRefreshToken,
1464 'grant_type' => 'refresh_token',
1465 ),
1466 ));
1467
1468 if ( ! is_wp_error( $response ) ) {
1469 // The request went through successfully, check the response code against
1470 // what we're expecting
1471 if ( 200 == wp_remote_retrieve_response_code( $response ) ) {
1472
1473
1474 //get new acess token and refresh token
1475
1476 $jsondata = json_decode($response['body'],true);
1477
1478 $newAccessToken = $jsondata['access_token'];
1479
1480 if( array_key_exists('refresh_token',$jsondata) ){
1481 $newRefreshToken = $jsondata['refresh_token'];
1482 } else {
1483 $newRefreshToken = $currentRefreshToken;
1484 }
1485
1486
1487 //we need to get this information
1488 $response = wp_remote_get( 'https://api.getgo.com/identity/v1/Users/me', array(
1489 'headers' => array(
1490 'Authorization' => 'Bearer '.$newAccessToken,
1491 ),
1492 ));
1493
1494 $status = wp_remote_retrieve_response_code( $response );
1495
1496 if($status == 200){
1497
1498 $data = json_decode($response['body'] ,true);
1499
1500 $organizerKey = $data['id'];
1501
1502 $accountKey = $data['urn:scim:schemas:extension:getgo:1.0']['accounts'][0]['value'];
1503
1504 }
1505
1506 // $organizerKey = $jsondata['organizer_key'];
1507 // $accountKey = $jsondata['account_key'];
1508
1509 //now we need to update the settings
1510 //set the new values from the existing array
1511 $pluginSettings['access_token'] = $newAccessToken;
1512 $pluginSettings['refresh_token'] = $newRefreshToken;
1513 $pluginSettings['organizer_key'] = $organizerKey;
1514 $pluginSettings['account_key'] = $accountKey;
1515
1516 //update the option
1517 update_option('gotowebinar_auth_settings', $pluginSettings);
1518
1519 //set the transient
1520 //we will make this transient expire just before 60 minutes
1521 set_transient( 'gotowebinar_auth_settings',$newAccessToken.'|'.$organizerKey,60*50);
1522
1523 //add to connection log
1524 wp_gotowebinar_connection_log(wp_remote_retrieve_response_code($response).' Success');
1525
1526 //return the array
1527 return array($newAccessToken,$organizerKey);
1528
1529
1530 } else {
1531 //we can put some diagnostic info here if we wanted to
1532 //add to connection log
1533 // $error_message = wp_remote_retrieve_response_message( $response );
1534
1535 //the below code gives us a heaps better description as it's from the GoToWebinar server
1536 $jsondata = json_decode($response['body'],true);
1537 $errorTitle = $jsondata['error'];
1538 $errorDescription = $jsondata['error_description'];
1539
1540 wp_gotowebinar_connection_log(wp_remote_retrieve_response_code($response).' '.$errorTitle.' - '.$errorDescription);
1541 }
1542 } else {
1543 //we can put some diagnostic info here if we wanted to
1544 //add to connection log
1545 $error_message = $response->get_error_message();
1546 wp_gotowebinar_connection_log(wp_remote_retrieve_response_code($response).' '.$error_message);
1547 }
1548
1549
1550
1551 } //end else
1552
1553 } //end function
1554
1555
1556
1557 function wp_gotowebinar_connection_log($message){
1558
1559 //add item to log
1560 $currentTime = current_time('timestamp');
1561 $currentTimeInNiceFormat = date('d/m/Y H:i',$currentTime);
1562
1563
1564 //get current log
1565 $existingLog = get_option('gotowebinar_connection_log');
1566
1567 if($existingLog == false){
1568 $existingLog = array();
1569 }
1570
1571 //if the array length is greater than 200 then lets remove the first item
1572 if(count($existingLog) > 200){
1573 array_shift($existingLog);
1574 }
1575
1576 //now lets add our new item to the log
1577 array_push($existingLog,array($currentTimeInNiceFormat,$message));
1578
1579 //update the setting
1580 update_option('gotowebinar_connection_log',$existingLog);
1581
1582
1583 }
1584
1585
1586
1587
1588
1589 function wp_gotowebinar_get_access_and_refresh_token_call(){
1590
1591 if( current_user_can( 'manage_options' ) ){
1592
1593 $implodeResult = implode('|',wp_gotowebinar_get_access_and_refresh_token());
1594
1595 echo $implodeResult;
1596 }
1597
1598 wp_die();
1599 }
1600
1601 add_action( 'wp_ajax_get_access_and_refresh_token', 'wp_gotowebinar_get_access_and_refresh_token_call' );
1602
1603
1604
1605 //function used to get different authentication depending on pro vs free
1606 function wp_gotowebinar_get_authorization(){
1607
1608 //first lets check if they have created a custom application, if they have let create that authrisation
1609 $options = get_option('gotowebinar_settings');
1610 $consumerKey = trim($options['gotowebinar_consumer_key']);
1611 $consumerSecret = trim($options['gotowebinar_consumer_secret']);
1612
1613 if( isset($consumerKey) && isset($consumerSecret) && strlen($consumerKey)> 0 && strlen($consumerSecret)> 0 ){
1614
1615 return base64_encode($consumerKey.':'.$consumerSecret );
1616
1617 } else {
1618
1619 global $gotowebinar_is_pro;
1620
1621 if($gotowebinar_is_pro == 'YES'){
1622 return 'V2lPUERtSXB0RFdudVRBZUtLbm9hUXpSQ2VxdHlwZjE6dmdYWEROb2RvQkJ6ZWNYUw==';
1623 } else {
1624 return 'bVhnZEFtelZzOWxHVmJFQ0dyVVQyaWVaZVBvVm1oNHo6VXVncUd5b1U0U3JBc3V5SA==';
1625 }
1626 }
1627
1628 }
1629
1630
1631
1632
1633 //Function to run upon ajax request to get the access token and store it in the plugin settings and to set a transient
1634 function wp_gotowebinar_save_authentication_details() {
1635
1636 $nonce = sanitize_text_field($_POST['nonce']);
1637
1638 if( current_user_can( 'manage_options' ) && wp_verify_nonce( $nonce, 'save_authentication_details_gotowebinar' ) ){
1639
1640 //get the code field
1641 $code = sanitize_text_field($_POST['code']);
1642
1643
1644 // echo wp_gotowebinar_get_authorization();
1645
1646 $response = wp_remote_post( 'https://authentication.logmeininc.com/oauth/token', array(
1647 'headers' => array(
1648 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
1649 'Authorization' => 'Basic '.wp_gotowebinar_get_authorization(),
1650 'Accept' => 'application/json',
1651 ),
1652 'body' => array(
1653 'code' => $code,
1654 'grant_type' => 'authorization_code',
1655 ),
1656 ) );
1657
1658 if ( ! is_wp_error( $response ) ) {
1659 // The request went through successfully, check the response code against
1660 // what we're expecting
1661 if ( 200 == wp_remote_retrieve_response_code( $response ) ) {
1662
1663 //lets get the response and decode it
1664 $jsondata = json_decode($response['body'],true);
1665
1666 //lets pull our key variables from the response
1667 $access_token = $jsondata['access_token'];
1668 $refresh_token = $jsondata['refresh_token'];
1669
1670 //we need to get this information
1671 $response = wp_remote_get( 'https://api.getgo.com/identity/v1/Users/me', array(
1672 'headers' => array(
1673 'Authorization' => 'Bearer '.$access_token,
1674 ),
1675 ));
1676
1677 $status = wp_remote_retrieve_response_code( $response );
1678
1679 if($status == 200){
1680
1681 $data = json_decode($response['body'] ,true);
1682
1683 $organizer_key = $data['id'];
1684
1685 $accountKey = $data['urn:scim:schemas:extension:getgo:1.0']['accounts'][0]['value'];
1686
1687 }
1688
1689 // $organizer_key = $jsondata['organizer_key'];
1690 // $accountKey = $jsondata['account_key'];
1691
1692 //lets create an array which will store our updated settings
1693 $newPluginSettings = array();
1694
1695 //lets add our fields to the array
1696 $newPluginSettings['organizer_key'] = $organizer_key;
1697 $newPluginSettings['access_token'] = $access_token;
1698 $newPluginSettings['refresh_token'] = $refresh_token;
1699 $newPluginSettings['account_key'] = $accountKey;
1700
1701
1702 //update the options
1703 update_option('gotowebinar_auth_settings', $newPluginSettings);
1704
1705 //set the transient
1706 set_transient( 'gotowebinar_auth_settings',$access_token.'|'.$organizer_key,60*50);
1707
1708 wp_gotowebinar_connection_log(wp_remote_retrieve_response_code($response).' Success');
1709
1710
1711 echo 'SUCCESS';
1712 wp_die();
1713
1714 } else {
1715 // The response code was not what we were expecting, record the message
1716
1717 $jsondata = json_decode($response['body'],true);
1718 $errorTitle = $jsondata['error'];
1719 $errorDescription = $jsondata['error_description'];
1720
1721 wp_gotowebinar_connection_log(wp_remote_retrieve_response_code($response).' '.$errorTitle.' - '.$errorDescription);
1722
1723 $error_message = wp_remote_retrieve_response_message( $response );
1724
1725 echo wp_remote_retrieve_response_code( $response ).' - '.$error_message.' - '.$errorTitle.' - '.$errorDescription;
1726
1727
1728 wp_die();
1729
1730 }
1731 } else {
1732 // There was an error making the request
1733 $error_message = $response->get_error_message();
1734
1735 wp_gotowebinar_connection_log(wp_remote_retrieve_response_code($response).' '.$error_message);
1736
1737 echo wp_remote_retrieve_response_code($response).' '.$error_message;
1738 wp_die();
1739 }
1740
1741 } else {
1742 wp_die();
1743 }
1744
1745
1746 }
1747 add_action( 'wp_ajax_save_authentication_details_gotowebinar', 'wp_gotowebinar_save_authentication_details' );
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760 //add notice about the update
1761 function wp_gotowebinar_display_important_update_warning() {
1762
1763 //check plugin options to see if it exists and keep displaying option until new option is saved
1764 if(get_option('gotowebinar_auth_settings') == false){
1765 $pluginSettingsPage = admin_url( 'options-general.php?page=wp-gotowebinar');
1766
1767 ?>
1768 <div data-dismissible="wp-gotowebinar-notice-forever" class="notice notice-error is-dismissible">
1769
1770 <h2><?php _e( 'IMPORTANT INFORMATION ABOUT THE WP GOTOWEBINAR PLUGIN UPDATE - PLEASE READ!', 'wp-gotowebinar' ); ?></h2>
1771
1772 <p><?php _e( 'Thanks for updating WP GoToWebinar. Due to the GoToWebinar API upgrade the authentication process for this plugin has needed to be re-written. It is critical that you now reauthenticate the plugin immidiately by going to the <a href="'.$pluginSettingsPage.'">plugin settings</a> and clicking on the new "CLICK HERE TO CONNECT WITH GOTOWEBINAR" button, otherwise plugin features will be broken and potentially front end pages may not display correctly. If you should experience issues due to the uprade please try re-authenticating again and if this does not work please create a post on the <a target="_blank" href="https://wordpress.org/support/plugin/wp-gotowebinar">forum</a>.', 'wp-gotowebinar' ); ?></p>
1773 </div>
1774 <?php
1775
1776 }
1777
1778 }
1779
1780
1781
1782 //standard date and time display functions
1783 function wp_gotowebinar_date_format() {
1784
1785 $options = get_option('gotowebinar_settings');
1786
1787 if(isset($options['gotowebinar_date_format'])){
1788
1789 if($options['gotowebinar_date_format'] == 'wordpress'){
1790 $date_format = get_option('date_format');
1791 } else {
1792 $date_format = $options['gotowebinar_date_format'];
1793 }
1794
1795 } else {
1796 $date_format = "j/n/Y";
1797 }
1798
1799 return $date_format;
1800
1801 }
1802
1803 function wp_gotowebinar_time_format() {
1804
1805 $options = get_option('gotowebinar_settings');
1806
1807 if(isset($options['gotowebinar_time_format'])){
1808
1809 if($options['gotowebinar_time_format'] == 'wordpress'){
1810 $time_format = get_option('time_format');
1811 } else {
1812 $time_format = $options['gotowebinar_time_format'];
1813 }
1814
1815 } else {
1816 $time_format = "g:ia T";
1817 }
1818
1819 return $time_format;
1820
1821 }
1822
1823
1824
1825
1826
1827
1828 ?>