From caa73945f9fe69875171ea2aade2c53e60b21bbe Mon Sep 17 00:00:00 2001 From: yehudah Date: Fri, 13 Sep 2019 11:29:33 +0000 Subject: hooks + sanitize bug --- .../PostmanConfigurationController.php | 20 +++++++++++--------- .../PostmanRegisterConfigurationSettings.php | 15 ++++++++++++--- .../Postman-Configuration/postman_manual_config.js | 3 +++ Postman/Postman-Configuration/postman_wizard.js | 2 ++ Postman/Postman-Email-Log/PostmanEmailLogService.php | 2 ++ Postman/PostmanAdminController.php | 2 ++ Postman/PostmanLogFields.php | 18 +++++++++++------- Postman/PostmanViewController.php | 4 ++++ postman-smtp.php | 5 +++++ 9 files changed, 52 insertions(+), 19 deletions(-) diff --git a/Postman/Postman-Configuration/PostmanConfigurationController.php b/Postman/Postman-Configuration/PostmanConfigurationController.php index ee14ad8..59fbdb8 100644 --- a/Postman/Postman-Configuration/PostmanConfigurationController.php +++ b/Postman/Postman-Configuration/PostmanConfigurationController.php @@ -390,17 +390,19 @@ class PostmanConfigurationController { print '
'; do_settings_sections( PostmanAdminController::NOTIFICATIONS_OPTIONS ); - $currentKey = $this->options->getNotificationService(); - $pushover = $currentKey == 'pushover' ? 'block' : 'none'; - $slack = $currentKey == 'slack' ? 'block' : 'none'; + $currentKey = $this->options->getNotificationService(); + $pushover = $currentKey == 'pushover' ? 'block' : 'none'; + $slack = $currentKey == 'slack' ? 'block' : 'none'; - echo '
'; - do_settings_sections( PostmanAdminController::NOTIFICATIONS_PUSHOVER_CRED ); - echo '
'; + echo '
'; + do_settings_sections( PostmanAdminController::NOTIFICATIONS_PUSHOVER_CRED ); + echo '
'; - echo '
'; - do_settings_sections( PostmanAdminController::NOTIFICATIONS_SLACK_CRED ); - echo '
'; + echo '
'; + do_settings_sections( PostmanAdminController::NOTIFICATIONS_SLACK_CRED ); + echo '
'; + + do_action( 'post_smtp_notification_settings' ); print '
'; diff --git a/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php b/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php index 6ddebd7..705ef23 100644 --- a/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php +++ b/Postman/Postman-Configuration/PostmanRegisterConfigurationSettings.php @@ -234,6 +234,7 @@ class PostmanSettingsRegistry { 'notification_chrome_uid_callback', ), PostmanAdminController::NOTIFICATIONS_OPTIONS, PostmanAdminController::NOTIFICATIONS_SECTION ); + do_action( 'post_smtp_settings' ); } } @@ -443,12 +444,20 @@ class PostmanSettingsRegistry { public function notification_service_callback() { $inputDescription = __( 'Select the notification service you want to recieve alerts about failed emails.' ); + + $options = apply_filters('post_smtp_notification_service', array( + 'default' => __( 'WP Admin Email', 'post-smtp' ), + 'pushover' => __( 'Pushover', 'post-smtp' ), + 'slack' => __( 'Slack', 'post-smtp' ), + )); + printf( '
%s', $inputDescription ); } diff --git a/Postman/Postman-Configuration/postman_manual_config.js b/Postman/Postman-Configuration/postman_manual_config.js index a47df1a..49438fc 100644 --- a/Postman/Postman-Configuration/postman_manual_config.js +++ b/Postman/Postman-Configuration/postman_manual_config.js @@ -40,6 +40,9 @@ jQuery(document).ready( $('#pushover_cred').fadeOut('fast'); $('#slack_cred').fadeIn(); } + + Hook.call( 'post_smtp_notification_change', selected ); + }); diff --git a/Postman/Postman-Configuration/postman_wizard.js b/Postman/Postman-Configuration/postman_wizard.js index d844322..cbd2031 100644 --- a/Postman/Postman-Configuration/postman_wizard.js +++ b/Postman/Postman-Configuration/postman_wizard.js @@ -517,6 +517,8 @@ function handleConfigurationResponse(response) { jQuery('#pushover_cred').fadeOut('fast'); jQuery('#slack_cred').fadeIn(); } + + Hook.call( 'post_smtp_notification_change', selected ); }); // add an event on the user port override field diff --git a/Postman/Postman-Email-Log/PostmanEmailLogService.php b/Postman/Postman-Email-Log/PostmanEmailLogService.php index 1afb4fc..2538700 100644 --- a/Postman/Postman-Email-Log/PostmanEmailLogService.php +++ b/Postman/Postman-Email-Log/PostmanEmailLogService.php @@ -212,6 +212,8 @@ if ( ! class_exists( 'PostmanEmailLogService' ) ) { $notifyer = new PostmanMailNotify; } + $notifyer = apply_filters( 'post_smtp_notifier', $notifyer, $notification_service ); + // Notifications $notify = new PostmanNotify( $notifyer ); $notify->send($message, $log); diff --git a/Postman/PostmanAdminController.php b/Postman/PostmanAdminController.php index 3d0486f..1e43c6d 100644 --- a/Postman/PostmanAdminController.php +++ b/Postman/PostmanAdminController.php @@ -128,11 +128,13 @@ if ( ! class_exists( 'PostmanAdminController' ) ) { $this->logger->debug( 'Looking for grant code' ); if ( isset( $_GET ['code'] ) ) { $this->logger->debug( 'Found authorization grant code' ); + // queue the function that processes the incoming grant code $this->registerInitFunction( 'handleAuthorizationGrant' ); return; } } + do_action('post_smtp_handle_oauth', $this->messageHandler ); // continue to initialize the AdminController add_action( 'init', array( diff --git a/Postman/PostmanLogFields.php b/Postman/PostmanLogFields.php index 84a3121..6e04b8d 100644 --- a/Postman/PostmanLogFields.php +++ b/Postman/PostmanLogFields.php @@ -3,11 +3,11 @@ class PostmanLogFields { private $fields = array( 'success' => 'sanitize_text_field', - 'from_header' => 'sanitize_text_field', - 'to_header' => 'sanitize_text_field', - 'cc_header' => 'sanitize_text_field', - 'bcc_header' => 'sanitize_text_field', - 'reply_to_header' => 'sanitize_text_field', + 'from_header' => '', + 'to_header' => '', + 'cc_header' => '', + 'bcc_header' => '', + 'reply_to_header' => '', 'transport_uri' => 'sanitize_text_field', 'original_to' => 'sanitize_text_field', 'original_subject' => 'sanitize_text_field', @@ -75,7 +75,11 @@ class PostmanLogFields { private function sanitize( $key, $value ) { $callback = is_array( $value ) ? 'array_map' : 'call_user_func'; - return $callback( $this->fields[$key], $value ); + if ( ! empty( $this->fields[$key] ) ) { + return $callback( $this->fields[$key], $value ); + } + + return filter_var( $value, FILTER_SANITIZE_STRING | FILTER_SANITIZE_SPECIAL_CHARS ); } private function sanitize_message( $message ) { @@ -92,4 +96,4 @@ class PostmanLogFields { return $value; } -} +} \ No newline at end of file diff --git a/Postman/PostmanViewController.php b/Postman/PostmanViewController.php index 726880b..050033f 100644 --- a/Postman/PostmanViewController.php +++ b/Postman/PostmanViewController.php @@ -347,7 +347,11 @@ if ( ! class_exists( 'PostmanViewController' ) ) { print '