| Current Path : /var/www/consult-e-syn/public_html/plugins/ats/mailfetch/library/ |
| Current File : /var/www/consult-e-syn/public_html/plugins/ats/mailfetch/library/atsgmailbutton.php |
<?php
/**
* @package ats
* @copyright Copyright (c)2011-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
defined('_JEXEC') or die;
use FOF40\Container\Container;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Uri\Uri;
/**
* @package ats
* @copyright Copyright (c)2011-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
class JFormFieldAtsgmailbutton extends FormField
{
static $loadedJS = false;
public function getInput()
{
// Load the necessary JavaScript
if (!self::$loadedJS)
{
self::$loadedJS = true;
/** @var CMSApplication $app */
try
{
$app = Factory::getApplication();
}
catch (Exception $e)
{
return sprintf("Internal Joomla error: %s.", $e->getMessage());
}
$app->getDocument()->addScriptDeclaration($this->getJavascript());
$app->getDocument()->addStyleDeclaration($this->getCSS());
}
$jsEvent = 'ats_mailfetch_gmail_authenticate()';
return <<< HTML
<button class="plgAtsMailFetchGmailButton" type="button"></button>
HTML;
}
private function getJavascript()
{
$container = Container::getInstance('com_ats');
// Get the Google OAuth2 login URL
$authOpenUrl = Uri::base() . 'index.php?option=com_ajax&group=ats&plugin=AtsMailfetchGmailConsent&format=raw';
$token = $container->platform->getToken();
return <<< JS
window.jQuery(document).ready(function() {
akeeba.System.iterateNodes('.plgAtsMailFetchGmailButton', function (elButton) {
akeeba.System.addEventListener(elButton, 'click', function (event) {
event.preventDefault();
ats_mailfetch_gmail_authenticate();
return false;
})
});
});
if (typeof ats_mailfetch_gmail_authenticate === 'undefined')
{
var ats_mailfetch_gmail_authenticate = function() {
var clientId = document.getElementById('jform_params_gmail_client_id').value;
var apiSecret = document.getElementById('jform_params_gmail_api_secret').value;
var token = '$token';
var url = '$authOpenUrl' +
'&client_id=' + encodeURIComponent(clientId) +
'&api_secret=' + encodeURIComponent(apiSecret) +
'&' + encodeURIComponent(token) + '=1';
window.open(url, 'ats_mailfetch_auth_window', 'width=1010, height=500');
};
}
if (typeof ats_mailfetch_token_callback === 'undefined')
{
var ats_mailfetch_token_callback = function(data)
{
document.getElementById('jform_params_access_token').value = data.access_token;
document.getElementById('jform_params_refresh_token').value = data.refresh_token;
myWindow = window.open("", "ats_mailfetch_auth_window");
myWindow.close();
};
}
JS;
}
private function getCSS()
{
return <<< CSS
button.plgAtsMailFetchGmailButton {
display :block!important;
width: 191px !important;
height: 46px !important;
background-color: transparent;
border: none;
background-image: url(../media/plg_ats_mailfetch/images/gmail_normal.png);
}
button.plgAtsMailFetchGmailButton:focus {
background-image: url(../media/plg_ats_mailfetch/images/gmail_focus.png);
}
button.plgAtsMailFetchGmailButton:active {
background-image: url(../media/plg_ats_mailfetch/images/gmail_pressed.png);
}
button.plgAtsMailFetchGmailButton:disabled {
background-image: url(../media/plg_ats_mailfetch/images/gmail_disabled.png);
}
@media only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min--moz-device-pixel-ratio: 2),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 2dppx) {
button.plgAtsMailFetchGmailButton {
background-image: url(../media/plg_ats_mailfetch/images/gmail_normal@2x.png);
}
button.plgAtsMailFetchGmailButton:focus {
background-image: url(../media/plg_ats_mailfetch/images/gmail_focus@2x.png);
}
button.plgAtsMailFetchGmailButton:active {
background-image: url(../media/plg_ats_mailfetch/images/gmail_pressed@2x.png);
}
button.plgAtsMailFetchGmailButton:disabled {
background-image: url(../media/plg_ats_mailfetch/images/gmail_disabled@2x.png);
}
}
CSS;
}
}