Skip to content

Commit

Permalink
Integrate Oauth helper into SC (#562)
Browse files Browse the repository at this point in the history
* Interate Oauth helper into SC

* feedback changes

* Make oauth helper compatible with Appointment

* version, changelog and formatting
  • Loading branch information
Akhill2020 authored Aug 12, 2024
1 parent 890ace5 commit 8415bd0
Show file tree
Hide file tree
Showing 14 changed files with 618 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .bin/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const files = [
},
{ in: 'assets/js/admin.js', out: 'admin.min' },
{ in: 'assets/js/default-calendar.js', out: 'default-calendar.min' },
{ in: 'assets/js/oauth-helper-admin.js', out: 'oauth-helper-admin.min' },
{ in: 'assets/css/admin-add-calendar.css', out: 'admin-add-calendar.min' },
{ in: 'assets/css/oauth-helper-admin.css', out: 'oauth-helper-admin.min' },
{ in: 'assets/css/admin-sett-style.css', out: 'admin-sett-style.min' },
{ in: 'assets/css/admin.css', out: 'admin.min' },
{ in: 'assets/css/default-calendar-grid.css', out: 'default-calendar-grid.min' },
Expand Down
52 changes: 52 additions & 0 deletions assets/css/oauth-helper-admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.simcal-auth-tabs {
width: 600px;
border-radius: 5px 5px 5px 5px;
}
ul#simcal-auth-tabs-nav {
list-style: none;
margin: 0;
padding: 5px;
overflow: auto;
}
ul#simcal-auth-tabs-nav li {
float: left;
font-weight: bold;
margin-right: 2px;
padding: 8px 10px;
border-radius: 5px 5px 5px 5px;
cursor: pointer;
background-color: #d9d9d9;
}
ul#simcal-auth-tabs-nav li:hover,
ul#simcal-auth-tabs-nav li.active {
background-color: #60bc4e;
}
#simcal-auth-tabs-nav li a {
text-decoration: none;
color: #fff;
}
.simcal-auth-tab-content {
padding: 10px;
}
.hide {
display: none;
}
.afterauth-via-xtendify-cta,
.auth-via-xtendify-cta {
text-align: center;
}

.simcal-auth-tabs-content a#oauth_deauthentication:hover,
.simcal-auth-tabs-content .auth-via-xtendify-cta .action_auth_via_xtendify:hover {
color: rgb(96 188 78 1);
background: rgb(255 255 255 1);
border: 1px solid rgb(96 188 78 1);
}
#simcal-settings-page-form .auth-via-xtendify-cta a:active,
#simcal-settings-page-form .auth-via-xtendify-cta a:hover,
#simcal-settings-page-form .afterauth-via-xtendify-cta a:active,
#simcal-settings-page-form .afterauth-via-xtendify-cta a:hover,
#simcal-settings-page-form .afterauth-via-xtendify-cta a:focus,
#simcal-settings-page-form .afterauth-via-xtendify-cta a:focus {
color: #fff;
}
Binary file added assets/images/pages/settings/auth_success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions assets/js/oauth-helper-admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
(function ($) {
'use strict';

/**
* All of the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*/
$(function (e) {
/* ========================= *
* De auth from xtendify*
* ========================= */
$('#oauth_deauthentication').on('click', function (e) {
e.preventDefault();
var spinner = $(this).find('i'),
dialog = $(this).data('dialog'),
reply = confirm(dialog);

if (true !== reply) {
return;
}

$.ajax({
url: oauth_admin.ajax_url,
method: 'POST',
data: {
action: 'oauth_deauthenticate_site',
nonce: $('#oauth_action_deauthentication').val(),
},
beforeSend: function () {
spinner.toggle();
},
success: function (response) {
if (response.data) {
var curUrl = window.location.href;
var newURL = curUrl.replace('status=1', 'status=0');
newURL = newURL.replace('auth_token=', '');
window.location.href = newURL;
} else {
console.log(response);
spinner.fadeToggle();
}
},
error: function (response) {
console.log(response);
spinner.fadeToggle();
},
});
});
});

$(window).load(function () {
/* ========================= *
* Auth Via xtendify Tab*
* ========================= */

$('#simcal-auth-tabs-nav li:first-child').addClass('active');
$('.simcal-auth-tab-content').hide();
$('.simcal-auth-tab-content:first').show();

// Click function
$('#simcal-auth-tabs-nav li').click(function () {
$('#simcal-auth-tabs-nav li').removeClass('active');
$(this).addClass('active');
$('.simcal-auth-tab-content').hide();

var activeTab = $(this).find('a').attr('href');
$(activeTab).fadeIn();
return false;
});
});
})(jQuery);
1 change: 1 addition & 0 deletions google-calendar-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'SIMPLE_CALENDAR_ASSETS' => $this_plugin_dir . 'assets/',
'SIMPLE_CALENDAR_PATH' => $this_plugin_path,
'SIMPLE_CALENDAR_INC' => $this_plugin_path . 'includes/',
'SIMPLE_CALENDAR_OAUTH_HELPER_AUTH_DOMAIN' => 'https://auth.simplecalendar.io/',
];
foreach ($this_plugin_constants as $constant => $value) {
if (!defined($constant)) {
Expand Down
26 changes: 26 additions & 0 deletions includes/admin/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
*/
class Assets
{
/**
* Check for SC setting page.
*
* @since 3.4.1
*/

protected $current_page = '';

/**
* Hook in tabs.
*
Expand All @@ -27,6 +35,8 @@ class Assets
public function __construct()
{
add_action('admin_enqueue_scripts', [$this, 'load']);

$this->current_page = sanitize_text_field(wp_unslash($_GET['page'] ?? ''));
}

/**
Expand Down Expand Up @@ -69,7 +79,19 @@ public function load()
SIMPLE_CALENDAR_VERSION,
true
);
wp_register_script(
'simcal-oauth-helper-admin',
$js_path . 'oauth-helper-admin.min.js',
['jquery'],
SIMPLE_CALENDAR_VERSION,
true
);
$run_oauth_helper = get_option('simple_calendar_run_oauth_helper');

if ($run_oauth_helper && $this->current_page === 'simple-calendar_settings') {
wp_enqueue_script('simcal-oauth-helper-admin');
wp_localize_script('simcal-oauth-helper-admin', 'oauth_admin', simcal_common_scripts_variables());
}
/* ===================== *
* Register Admin Styles *
* ===================== */
Expand Down Expand Up @@ -129,5 +151,9 @@ public function load()
wp_enqueue_style('sc-welcome-style', $css_path . 'sc-welcome-pg-style.min.css', [], SIMPLE_CALENDAR_VERSION);
wp_enqueue_style('sc-tail-style', $css_path . 'tailwind.min.css', [], SIMPLE_CALENDAR_VERSION);
}
$run_oauth_helper = get_option('simple_calendar_run_oauth_helper');
if ($run_oauth_helper && $this->current_page === 'simple-calendar_settings') {
wp_enqueue_style('sc-oauth-helper-style', $css_path . 'oauth-helper-admin.min.css', [], SIMPLE_CALENDAR_VERSION);
}
}
}
2 changes: 1 addition & 1 deletion includes/feeds/google.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public function make_request($id = '', $time_min = 0, $time_max = 0)
$args['orderBy'] = 'startTime';
}

$is_authhelper = simcal_check_helper_addon();
$is_authhelper = get_option('simple_calendar_run_oauth_helper');
// Query events in calendar.
$simple_calendar_auth_site_token = get_option('simple_calendar_auth_site_token');
$response = '';
Expand Down
15 changes: 14 additions & 1 deletion includes/functions/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
}

use SimpleCalendar\Admin\Notice;

use SimpleCalendar\Add_On_Google_Pro;
use SimpleCalendar\Simple_Calendar_Appointment;
/**
* Get settings pages and tabs.
*
Expand Down Expand Up @@ -432,6 +433,7 @@ function simcal_notice_to_update_pro_addon()
$all_plugins = get_plugins();
$notices = get_option('simple-calendar_admin_notices', []);
$pro_plugin_path = 'simple-calendar-google-calendar-pro/simple-calendar-google-calendar-pro.php';
$appointment_plugin_path = 'simple-calendar-appointment/simple-calendar-appointment.php';
$fullcalendar_plugin_path = 'simple-calendar-fullcalendar/simple-calendar-fullcalendar.php';
$pro_plugin_latest_version = get_option('simple-calendar-google-calendar-pro_latest_version', '');
$fullcalendar_plugin_latest_version = get_option('simple-calendar-fullcalendar_latest_version', '');
Expand Down Expand Up @@ -477,5 +479,16 @@ function simcal_notice_to_update_pro_addon()
unset($notices[$notice_id]);
update_option('simple-calendar_admin_notices', $notices);
}

/*
* Check if Pro/Appointment is actiated, run oauth functionality.
* Update option if pro/appointment plugin is activated.
*/

if (class_exists('SimpleCalendar\Add_On_Google_Pro') || class_exists('SimpleCalendar\Simple_Calendar_Appointment')) {
update_option('simple_calendar_run_oauth_helper', true);
} else {
update_option('simple_calendar_run_oauth_helper', false);
}
}
add_action('admin_init', 'simcal_notice_to_update_pro_addon');
11 changes: 0 additions & 11 deletions includes/functions/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,3 @@ function simcal_delete_feed_transients($id = '')

return delete_transient('_simple-calendar_feed_ids');
}

/**
* Check if helper plugin install and activate
* @since 3.2.9
*
* @return bool
*/
function simcal_check_helper_addon()
{
return defined('OAUTH_HELPER_AUTH_DOMAIN') ? OAUTH_HELPER_AUTH_DOMAIN : false;
}
29 changes: 29 additions & 0 deletions includes/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public function __construct()
add_action('init', [$this, 'init'], 5);
add_action('admin_init', [$this, 'register_settings'], 5);

//Oauth Helper init
add_action('admin_init', [$this, 'oauth_helper_init'], 5);

// Upon plugin loaded action hook.
do_action('simcal_loaded');
}
Expand Down Expand Up @@ -236,6 +239,32 @@ public function register_settings()
}
}

/**
* Register plugin settings.
*
* @since 3.4.1
*/
public function oauth_helper_init()
{
if (defined('SIMPLE_CALENDAR_GOOGLE_PRO_VERSION') || defined('SIMPLE_CALENDAR_APPOINTMENT_VERSION')) {
if (defined('SC_OAUTH_HELPER_VERSION')) {
add_action('admin_notices', function () {
echo '<div class="error"><p>' .
sprintf(
__(
'The Simple Calendar plugin now includes the features previously provided by the Google Calendar OAuth Helper add-on. Please deactivate and remove the OAuth Helper add-on to avoid redundancy.',
'google-calendar-events'
),
simcal_ga_campaign_url(simcal_get_url('addons'), 'core-plugin', 'admin-notice')
) .
'</p></div>';
});
} else {
require plugin_dir_path(__FILE__) . 'oauthhelper/oauth-service-actions.php';
require plugin_dir_path(__FILE__) . 'oauthhelper/class-oauth-service.php';
}
}
}
/**
* Get Ajax URL.
*
Expand Down
Loading

0 comments on commit 8415bd0

Please sign in to comment.