From 8d02a1dbf8a51d9e2396b5b431fede557ea2fedd Mon Sep 17 00:00:00 2001 From: yehudah Date: Mon, 28 Jan 2019 15:23:06 +0000 Subject: Chrome Extension Notification --- .../PostmanConfigurationController.php | 23 ++++++++++++++++++++++ .../PostmanRegisterConfigurationSettings.php | 19 ++++++++++++++++++ .../Postman-Email-Log/PostmanEmailLogService.php | 1 + Postman/PostmanInputSanitizer.php | 3 +++ Postman/PostmanOptions.php | 14 +++++++++++++ Postman/notifications/PostmanNotify.php | 22 +++++++++++++++++++++ 6 files changed, 82 insertions(+) diff --git a/Postman/Postman-Configuration/PostmanConfigurationController.php b/Postman/Postman-Configuration/PostmanConfigurationController.php index 6abb5e2..a74ae04 100644 --- a/Postman/Postman-Configuration/PostmanConfigurationController.php +++ b/Postman/Postman-Configuration/PostmanConfigurationController.php @@ -428,6 +428,29 @@ class PostmanConfigurationController { +
+

+ + + + + + + + + + + +
+ + + + +
+ +
+
+ '; diff --git a/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php b/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php index ecd7ec3..6102d10 100644 --- a/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php +++ b/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php @@ -213,6 +213,16 @@ class PostmanSettingsRegistry { 'slack_token_callback', ), PostmanAdminController::NOTIFICATIONS_SLACK_CRED, 'slack_credentials' ); + add_settings_field( PostmanOptions::NOTIFICATION_USE_CHROME, _x( 'Push to chrome extension', 'Configuration Input Field', Postman::TEXT_DOMAIN ), array( + $this, + 'notification_use_chrome_callback', + ), PostmanAdminController::NOTIFICATIONS_OPTIONS, PostmanAdminController::NOTIFICATIONS_SECTION ); + + add_settings_field( PostmanOptions::NOTIFICATION_CHROME_UID, _x( 'Chrome Extension UID', 'Configuration Input Field', Postman::TEXT_DOMAIN ), array( + $this, + 'notification_chrome_uid_callback', + ), PostmanAdminController::NOTIFICATIONS_OPTIONS, PostmanAdminController::NOTIFICATIONS_SECTION ); + } } @@ -415,6 +425,15 @@ class PostmanSettingsRegistry { printf( '
%s', $inputDescription ); } + public function notification_use_chrome_callback() { + $value = $this->options->useChromeExtension(); + printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::NOTIFICATION_USE_CHROME, $value ? 'checked="checked"' : '' ); + } + + public function notification_chrome_uid_callback() { + printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::NOTIFICATION_CHROME_UID, $this->options->getNotificationChromeUid() ); + } + public function pushover_user_callback() { printf( '', PostmanOptions::POSTMAN_OPTIONS, PostmanOptions::PUSHOVER_USER, $this->options->getPushoverUser() ); } diff --git a/Postman/Postman-Email-Log/PostmanEmailLogService.php b/Postman/Postman-Email-Log/PostmanEmailLogService.php index ebb2e54..103dcc1 100644 --- a/Postman/Postman-Email-Log/PostmanEmailLogService.php +++ b/Postman/Postman-Email-Log/PostmanEmailLogService.php @@ -182,6 +182,7 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { $notify = new PostmanNotify( $notifyer, $message ); $notify->send($message, $log); + $notify->push_to_chrome($log->statusMessage); } /** diff --git a/Postman/PostmanInputSanitizer.php b/Postman/PostmanInputSanitizer.php index b17df30..9e1fa52 100644 --- a/Postman/PostmanInputSanitizer.php +++ b/Postman/PostmanInputSanitizer.php @@ -74,6 +74,9 @@ if ( ! class_exists( 'PostmanInputSanitizer' ) ) { $this->sanitizePassword( 'Pushover Token', PostmanOptions::PUSHOVER_TOKEN, $input, $new_input, $this->options->getPushoverToken() ); $this->sanitizePassword( 'Slack Token', PostmanOptions::SLACK_TOKEN, $input, $new_input, $this->options->getSlackToken() ); + $this->sanitizeString( 'Push Chrome Extension', PostmanOptions::NOTIFICATION_USE_CHROME, $input, $new_input ); + $this->sanitizePassword( 'Push Chrome Extension UID', PostmanOptions::NOTIFICATION_CHROME_UID, $input, $new_input, $this->options->getNotificationChromeUid() ); + if ( $new_input [ PostmanOptions::CLIENT_ID ] != $this->options->getClientId() || $new_input [ PostmanOptions::CLIENT_SECRET ] != $this->options->getClientSecret() || $new_input [ PostmanOptions::HOSTNAME ] != $this->options->getHostname() ) { $this->logger->debug( 'Recognized new Client ID' ); // the user entered a new client id and we should destroy the stored auth token diff --git a/Postman/PostmanOptions.php b/Postman/PostmanOptions.php index 9c244bd..29ddbc6 100644 --- a/Postman/PostmanOptions.php +++ b/Postman/PostmanOptions.php @@ -106,6 +106,8 @@ if ( ! class_exists( 'PostmanOptions' ) ) { const TEMPORARY_DIRECTORY = 'tmp_dir'; const DISABLE_EMAIL_VALIDAITON = 'disable_email_validation'; const NOTIFICATION_SERVICE = 'notification_service'; + const NOTIFICATION_USE_CHROME = 'notification_use_chrome'; + const NOTIFICATION_CHROME_UID = 'notification_chrome_uid'; const PUSHOVER_USER = 'pushover_user'; const PUSHOVER_TOKEN = 'pushover_token'; const SLACK_TOKEN = 'slack_token'; @@ -341,6 +343,18 @@ if ( ! class_exists( 'PostmanOptions' ) ) { return base64_decode( $this->options [ PostmanOptions::SLACK_TOKEN ] ); } } + + public function useChromeExtension() { + if ( isset( $this->options [ PostmanOptions::NOTIFICATION_USE_CHROME ] ) ) { + return $this->options [ PostmanOptions::NOTIFICATION_USE_CHROME ]; + } + } + + public function getNotificationChromeUid() { + if ( isset( $this->options [ PostmanOptions::NOTIFICATION_CHROME_UID ] ) ) { + return base64_decode( $this->options [ PostmanOptions::NOTIFICATION_CHROME_UID ] ); + } + } public function getReplyTo() { if ( isset( $this->options [ PostmanOptions::REPLY_TO ] ) ) { diff --git a/Postman/notifications/PostmanNotify.php b/Postman/notifications/PostmanNotify.php index 22ca56f..365d708 100644 --- a/Postman/notifications/PostmanNotify.php +++ b/Postman/notifications/PostmanNotify.php @@ -14,4 +14,26 @@ class PostmanNotify { public function send( $message, $log ) { $this->notify->send_message( $message ); } + + public function push_to_chrome($message) { + $push_chrome = PostmanOptions::getInstance()->useChromeExtension(); + + if ( $push_chrome ) { + $uid = PostmanOptions::getInstance()->getNotificationChromeUid(); + + if ( empty( $uid ) ) { + return; + } + + $url = 'https://postmansmtp.com/chrome/' . $uid; + + $args = array( + 'body' => array( + 'message' => $message + ) + ); + + $response = wp_remote_post( $url , $args ); + } + } } \ No newline at end of file -- cgit v1.2.3