From 44b8dc0fe047950edd5ab85e725259c174e74f8e Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Wed, 17 Apr 2024 16:42:57 +0200 Subject: [PATCH] Remove Google Cloud Print --- classes/Modules/GoogleApi/GoogleScope.php | 3 - .../Service/GoogleAccountGateway.php | 19 --- .../www/js/PrinterGoogleCloudPrint.js | 109 ------------ .../PrinterGoogleCloudPrint.php | 156 ------------------ www/pages/content/googleapi_print.tpl | 57 ------- www/pages/googleapi.php | 104 ------------ 6 files changed, 448 deletions(-) delete mode 100644 classes/Modules/GoogleCloudPrint/www/js/PrinterGoogleCloudPrint.js delete mode 100644 www/lib/Printer/PrinterGoogleCloudPrint/PrinterGoogleCloudPrint.php delete mode 100644 www/pages/content/googleapi_print.tpl 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 @@ - -
- - - - -
- [MESSAGE] - -
-
-
-
- {|Google Cloud Print verwenden|} - -
- - - - - - - - - - - - - - - -
- -
Google Cloud Print: - - Um Google Cloud Print zu verwenden klicke auf Verbinden und wähle im nächsten Schritt, das Google - Konto aus, das für Cloud Printing verwendet werden soll. - -
- - -
-
-
-
-
- - [TAB1NEXT] -
- - -
- - - 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', - '
- Hinweis: Google wird den Cloud Print Dienst am 31.12.2020 abschalten.
' - ); - - $this->app->erp->Headlines('Google Cloud Print'); - $this->createMenu(); - $this->app->Tpl->Parse('PAGE', 'googleapi_print.tpl'); - } - /** * After user confirmed access to Google API manually, Google API * redirects user to this action sending authentication code and API scope @@ -382,47 +341,6 @@ class GoogleApi } - /** - * Action for the printer setup gui to get printer options from api connection - * - * @return void - */ - public function GoogleApiAjaxPrinters() - { - $data = []; - $apiName = $this->app->DB->real_escape_string(trim($this->app->Secure->GetPOST('api_name'))); - if(!empty($apiName)) { - $id = $this->getGoogleApiByName($apiName); - $token = $this->getAccessToken($id); - $authHeader = sprintf('Authorization: Bearer %s', $token); - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_HTTPHEADER, [$authHeader]); - curl_setopt( $ch, CURLOPT_FOLLOWLOCATION,true); - curl_setopt( $ch, CURLOPT_HEADER,false); - curl_setopt( $ch, CURLOPT_RETURNTRANSFER,true); - curl_setopt( $ch, CURLOPT_HTTPAUTH,CURLAUTH_ANY); - curl_setopt( $ch, CURLOPT_URL, 'https://www.google.com/cloudprint/search'); - curl_setopt( $ch, CURLOPT_POST, true ); - curl_setopt ( $ch, CURLOPT_POSTFIELDS, ['printerid' => $id]); - - $response = curl_exec($ch); - $result = json_decode($response, true); - - $printers = $result['printers']; - if(!empty($printers)) { - foreach ($printers as $item) { - $data[$item['id']] = sprintf('%s:%s', $item['displayName'], $item['connectionStatus']); - } - } - } - - $responseData = json_encode($data); - header('Content-Type: application/json'); - echo $responseData; - $this->app->ExitXentral(); - } - /** * Automatically calls getAccessTokenByRederect if needed. * @@ -682,11 +600,6 @@ class GoogleApi } switch ($type) { - case 'print': - $scope = self::GOOGLE_API_SCOPE_PRINT; - - break; - case 'mail': $scope = self::GOOGLE_API_SCOPE_MAIL; @@ -855,10 +768,6 @@ class GoogleApi $type = $this->app->DB->Select(sprintf("SELECT g.type FROM googleapi AS g WHERE g.id = '%s';", $id)); switch ($type) { - case 'print': - $testurl = self::GOOGLE_API_TESTURL_PRINT; - break; - case 'mail': $this->app->Tpl->Add( $messageTarget, @@ -893,18 +802,6 @@ class GoogleApi return false; } - if ($type === 'print' && - (!isset($info['content_type']) || explode(';', $info['content_type'])[0] !== 'text/plain') - ) { - $error = 'Test fehlgeschlagen: Fehlerhafte Antwort vom Server'; - $this->app->Tpl->Add( - $messageTarget, - sprintf('
%s
', $error) - ); - - return false; - } - if ($type === 'mail' && (!isset($info['content_type']) || explode(';', $info['content_type'])[0] !== 'text/plain') ) { @@ -977,6 +874,5 @@ class GoogleApi $this->app->erp->MenuEintrag('index.php?module=googleapi&action=list', 'Zurück zur Übersicht'); $this->app->erp->MenuEintrag('index.php?module=googleapi&action=list', 'Übersicht'); - $this->app->erp->MenuEintrag('index.php?module=googleapi&action=print', 'Google Cloud Print'); } }