diff --git a/classes/Modules/GoogleApi/GoogleScope.php b/classes/Modules/GoogleApi/GoogleScope.php index 0bce92b7..b2096a6a 100644 --- a/classes/Modules/GoogleApi/GoogleScope.php +++ b/classes/Modules/GoogleApi/GoogleScope.php @@ -6,9 +6,6 @@ namespace Xentral\Modules\GoogleApi; final class GoogleScope { - /** @var string CLOUDPRINT */ - public const CLOUDPRINT = 'https://www.googleapis.com/auth/cloudprint'; - /** @var string CALENDAR */ public const CALENDAR = 'https://www.googleapis.com/auth/calendar'; diff --git a/classes/Modules/GoogleApi/Service/GoogleAccountGateway.php b/classes/Modules/GoogleApi/Service/GoogleAccountGateway.php index ea694726..e689cbc9 100644 --- a/classes/Modules/GoogleApi/Service/GoogleAccountGateway.php +++ b/classes/Modules/GoogleApi/Service/GoogleAccountGateway.php @@ -213,25 +213,6 @@ final class GoogleAccountGateway return array_values($pairs); } - /** - * Will be removed after Dec 31. 2020 - * - * @deprecated - * - * @codeCoverageIgnore - * - * @return GoogleAccountData - */ - public function getCloudPrintAccount(): GoogleAccountData - { - $accounts = $this->getAccountsByScope(GoogleScope::CLOUDPRINT); - if (count($accounts) < 1) { - throw new GoogleAccountNotFoundException('No cloud printing account available.'); - } - - return $accounts[0]; - } - /** * @param int $accountId * diff --git a/classes/Modules/GoogleCloudPrint/www/js/PrinterGoogleCloudPrint.js b/classes/Modules/GoogleCloudPrint/www/js/PrinterGoogleCloudPrint.js deleted file mode 100644 index 426f1348..00000000 --- a/classes/Modules/GoogleCloudPrint/www/js/PrinterGoogleCloudPrint.js +++ /dev/null @@ -1,109 +0,0 @@ - -/** - * Für die Bedienung der Modul-Oberfläche - */ -var PrinterGoogleCloudPrint = (function ($) { - 'use strict'; - - var me = { - - isInitialized: false, - $apiSelect: null, - $printerSelect: null, - initApiValue: null, - initPrinterValue: null, - printercache: {}, - - /** - * @return void - */ - init: function () { - if (me.isInitialized === true) { - return; - } - me.$apiSelect = $('select[name="google_api"]'); - me.$printerSelect = $('select[name="google_printer"]'); - me.initApiValue = me.$apiSelect.val(); - me.initPrinterValue = me.$printerSelect.val(); - - var options = {}; - $('select[name="google_printer"] option').each( function () { - options[$(this).attr('value')] = $(this).text(); - }); - me.printercache[me.initApiValue] = options; - - me.registerEvents(); - me.isInitialized = true; - }, - - setPrinterSelectOptions: function(options, selected) { - me.$printerSelect.empty(); // remove old options - $.each(options, function(value, display) { - me.$printerSelect.append($('').attr('value', value).text(display)); - }); - if (selected in options) { - me.$printerSelect.val(selected); - } - }, - - /** - * @return {void} - */ - registerEvents: function () { - me.$apiSelect.change(function () { - me.ajaxLoadPrinterOptions(this.value); - }); - }, - - /** - * @param {number} fieldId - * - * @return {void} - */ - ajaxLoadPrinterOptions: function (apiName) { - if (apiName === '') { - return; - } - - if (apiName in me.printercache) { - me.setPrinterSelectOptions(me.printercache[apiName], me.initPrinterValue); - return; - } - - $.ajax({ - url: 'index.php?module=googleapi&action=ajaxprinters', - data: { - api_name: apiName - }, - method: 'post', - dataType: 'json', - beforeSend: function () { - me.$printerSelect.prop('disabled', true); - me.$apiSelect.prop('disabled', true); - App.loading.open(); - }, - complete: function() { - me.$printerSelect.prop('disabled', false); - me.$apiSelect.prop('disabled', false); - }, - error: function (error) { - App.loading.close(); - }, - success: function (data) { - me.printercache[apiName] = data; - me.setPrinterSelectOptions(data, me.initPrinterValue); - App.loading.close(); - } - }); - }, - }; - - return { - init: me.init, - }; - -})(jQuery); - -$(document).ready(function () { - PrinterGoogleCloudPrint.init(); -}); diff --git a/www/lib/Printer/PrinterGoogleCloudPrint/PrinterGoogleCloudPrint.php b/www/lib/Printer/PrinterGoogleCloudPrint/PrinterGoogleCloudPrint.php deleted file mode 100644 index 31a0bc2f..00000000 --- a/www/lib/Printer/PrinterGoogleCloudPrint/PrinterGoogleCloudPrint.php +++ /dev/null @@ -1,156 +0,0 @@ -getAuthToken(); - $options = new RequestOptions(); - $options->setHeader('Authorization', sprintf('Bearer %s', $token)); - $this->client = new HttpClient($options); - $this->app->ModuleScriptCache->IncludeJavascriptFiles( - 'drucker', - ['./classes/Modules/GoogleCloudPrint/www/js/PrinterGoogleCloudPrint.js'] - ); - } - - /** - * @return string - */ - public static function getName() { - return 'Google Cloud Print'; - } - - /** - * @return array - */ - public function getPrinters() - { - try { - $response = $this->client->request('GET', self::URL_SEARCH); - $result = json_decode($response->getBody()->getContents(), true); - - return $result['printers']; - } catch (Exception $e) { - return []; - } - } - - /** - * @return array - */ - public function SettingsStructure() - { - $googlePrinters = []; - try { - $googlePrinterArr = $this->getPrinters(); - } catch (Exception $e) { - return []; - } - foreach($googlePrinterArr as $item) { - $googlePrinters[$item['id']] = sprintf('%s:%s', $item['displayName'], $item['connectionStatus']); - } - - return [ - 'google_printer' => ['bezeichnung' => 'Drucker:','typ' => 'select', 'optionen' => $googlePrinters], - ]; - } - - /** - * @param string $document - * @param int $count - * - * @return bool - */ - public function printDocument($document, $count = 1) - { - if(empty($this->settings['google_printer'])) { - return false; - } - if($count < 1) { - $count = 1; - } - $title = ''; - $contenttype = 'application/pdf'; - if(is_file($document)) { - $title = basename($document); - $document = file_get_contents($document); - } - $title .= date('YmdHis'); - $titleFirst = $title; - for($i = 1; $i <= $count; $i++) { - if($i > 1) { - $title = $titleFirst.$i; - } - $postFields = array( - 'printerid' => $this->settings['google_printer'], - 'title' => $title, - 'contentTransferEncoding' => 'base64', - 'content' => base64_encode($document), - 'contentType' => $contenttype - ); - try { - $response = $this->client->request('POST', self::URL_PRINT, [], json_encode($postFields)); - $data = json_decode($response->getBody()->getContents(), true); - - return (isset($data['success']) && $data['success'] === true); - } catch (TransferErrorExceptionInterface $e) { - return false; - } - } - return true; - } - - protected function getAuthToken() - { - try { - /** @var GoogleAccountGateway $gateway */ - $gateway = $this->app->Container->get('GoogleAccountGateway'); - $account = $gateway->getCloudPrintAccount(); - $token = $gateway->getAccessToken($account->getId()); - } catch (GoogleAccountNotFoundException $e) { - throw new GoogleAccountNotFoundException($e->getMessage(), $e->getCode(), $e); - } catch (Exception $e) { - $token = null; - } - if ($token === null || $token->getTimeToLive() < 10) { - /** @var GoogleAuthorizationService $auth */ - $auth = $this->app->Container->get('GoogleAuthorizationService'); - $token = $auth->refreshAccessToken($account); - } - - return $token->getToken(); - } -} \ No newline at end of file diff --git a/www/pages/content/googleapi_print.tpl b/www/pages/content/googleapi_print.tpl deleted file mode 100644 index 20d3c495..00000000 --- a/www/pages/content/googleapi_print.tpl +++ /dev/null @@ -1,57 +0,0 @@ - -
- - - diff --git a/www/pages/googleapi.php b/www/pages/googleapi.php index 09cdfab8..5d159f35 100644 --- a/www/pages/googleapi.php +++ b/www/pages/googleapi.php @@ -22,9 +22,6 @@ class GoogleApi /** @var string MODULE_NAME */ public const MODULE_NAME = 'GoogleApi'; - /** @var string GOOGLE_API_TESTURL_PRINT */ - //private const TESTURL_PRINT = 'https://www.google.com/cloudprint/search'; - /** @var string GOOGLE_API_TESTURL_CALENDAR */ //private const TESTURL_CALENDAR = 'https://www.googleapis.com/calendar/v3/users/me/calendarList'; @@ -64,9 +61,7 @@ class GoogleApi // ab hier alle Action Handler definieren die das Modul hat $this->app->ActionHandler('list', 'GoogleApiEdit'); $this->app->ActionHandler('edit', 'GoogleApiEdit'); - $this->app->ActionHandler('print', 'GoogleApiPrint'); $this->app->ActionHandler('redirect', 'GoogleApiRedirect'); - $this->app->ActionHandler('ajaxprinters', 'GoogleApiAjaxPrinters'); $this->app->ActionHandlerListen($app); } @@ -135,7 +130,6 @@ class GoogleApi $sql = "SELECT SQL_CALC_FOUND_ROWS g.id, g.id_name, g.description, (CASE g.type - WHEN 'print' THEN 'Google Cloud Print' WHEN 'mail' THEN 'Google Mail' WHEN 'calendar' THEN 'Google Calendar' ELSE '' @@ -319,41 +313,6 @@ class GoogleApi $this->app->Tpl->Parse('PAGE', 'googleapi_edit.tpl'); } - /** - * @return void - */ - public function GoogleApiPrint(): void - { - /** @var Request $request */ - $request = $this->app->Container->get('Request'); - if ($request->post->has('authorize_cloudprint')) { - /** @var Session $session */ - $session = $this->app->Container->get('Session'); - $redirect = $this->auth->requestScopeAuthorization( - $session, - [GoogleScope::CLOUDPRINT], - 'index.php?module=googleapi&action=print' - ); - SessionHandler::commitSession($session); - $redirect->send(); - $this->app->ExitXentral(); - } - - if ($request->post->has('unauthorize')) { - $this->unauthorize(); - } - - $this->app->Tpl->Add( - 'MESSAGE', - '