From 2cddebe14e58deb22bc3849e55e78eed02e53ec7 Mon Sep 17 00:00:00 2001 From: yehudah Date: Sat, 28 Oct 2017 20:21:02 +0000 Subject: = 1.7.8 - 2017-10-28 * Fixed: IP detection error in some web hosts * Fixed: Link open in new page attribute = _blank * Fixed: Replace deprecated PHP 7 functions. --- .../PostmanEmailLogController.php | 301 ++++++++++----------- 1 file changed, 150 insertions(+), 151 deletions(-) (limited to 'Postman/Postman-Email-Log') diff --git a/Postman/Postman-Email-Log/PostmanEmailLogController.php b/Postman/Postman-Email-Log/PostmanEmailLogController.php index 2aacba6..5df618f 100644 --- a/Postman/Postman-Email-Log/PostmanEmailLogController.php +++ b/Postman/Postman-Email-Log/PostmanEmailLogController.php @@ -5,194 +5,193 @@ require_once 'PostmanEmailLogView.php'; /** * * @author jasonhendriks - * */ class PostmanEmailLogController { const RESEND_MAIL_AJAX_SLUG = 'postman_resend_mail'; private $rootPluginFilenameAndPath; private $logger; - + /** */ - function __construct($rootPluginFilenameAndPath) { + function __construct( $rootPluginFilenameAndPath ) { $this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath; - $this->logger = new PostmanLogger ( get_class ( $this ) ); - if (PostmanOptions::getInstance ()->isMailLoggingEnabled ()) { - add_action ( 'admin_menu', array ( + $this->logger = new PostmanLogger( get_class( $this ) ); + if ( PostmanOptions::getInstance()->isMailLoggingEnabled() ) { + add_action( 'admin_menu', array( $this, - 'postmanAddMenuItem' + 'postmanAddMenuItem', ) ); } else { - $this->logger->trace ( 'not creating PostmanEmailLog admin menu item' ); + $this->logger->trace( 'not creating PostmanEmailLog admin menu item' ); } - if (PostmanUtils::isCurrentPagePostmanAdmin ( 'postman_email_log' )) { - $this->logger->trace ( 'on postman email log page' ); + if ( PostmanUtils::isCurrentPagePostmanAdmin( 'postman_email_log' ) ) { + $this->logger->trace( 'on postman email log page' ); // $this->logger->debug ( 'Registering ' . $actionName . ' Action Post handler' ); - add_action ( 'admin_post_delete', array ( + add_action( 'admin_post_delete', array( $this, - 'delete_log_item' + 'delete_log_item', ) ); - add_action ( 'admin_post_view', array ( + add_action( 'admin_post_view', array( $this, - 'view_log_item' + 'view_log_item', ) ); - add_action ( 'admin_post_transcript', array ( + add_action( 'admin_post_transcript', array( $this, - 'view_transcript_log_item' + 'view_transcript_log_item', ) ); - add_action ( 'admin_init', array ( + add_action( 'admin_init', array( $this, - 'on_admin_init' + 'on_admin_init', ) ); } - if (is_admin ()) { + if ( is_admin() ) { $actionName = self::RESEND_MAIL_AJAX_SLUG; $fullname = 'wp_ajax_' . $actionName; // $this->logger->debug ( 'Registering ' . 'wp_ajax_' . $fullname . ' Ajax handler' ); - add_action ( $fullname, array ( + add_action( $fullname, array( $this, - 'resendMail' + 'resendMail', ) ); } } - + /** */ function on_admin_init() { - $this->handleBulkAction (); + $this->handleBulkAction(); // register the stylesheet and javascript external resources - $pluginData = apply_filters ( 'postman_get_plugin_metadata', null ); - wp_register_script ( 'postman_resend_email_script', plugins_url ( 'script/postman_resend_email_sript.js', $this->rootPluginFilenameAndPath ), array ( + $pluginData = apply_filters( 'postman_get_plugin_metadata', null ); + wp_register_script( 'postman_resend_email_script', plugins_url( 'script/postman_resend_email_sript.js', $this->rootPluginFilenameAndPath ), array( PostmanViewController::JQUERY_SCRIPT, - PostmanViewController::POSTMAN_SCRIPT + PostmanViewController::POSTMAN_SCRIPT, ), $pluginData ['version'] ); } - + /** */ public function resendMail() { // get the email address of the recipient from the HTTP Request - $postid = $this->getRequestParameter ( 'email' ); - if (! empty ( $postid )) { - $post = get_post ( $postid ); - $meta_values = get_post_meta ( $postid ); - - $success = wp_mail ( $meta_values ['original_to'] [0], $meta_values ['original_subject'] [0], $meta_values ['original_message'] [0], $meta_values ['original_headers'] [0] ); - + $postid = $this->getRequestParameter( 'email' ); + if ( ! empty( $postid ) ) { + $post = get_post( $postid ); + $meta_values = get_post_meta( $postid ); + + $success = wp_mail( $meta_values ['original_to'] [0], $meta_values ['original_subject'] [0], $meta_values ['original_message'] [0], $meta_values ['original_headers'] [0] ); + // Postman API: retrieve the result of sending this message from Postman - $result = apply_filters ( 'postman_wp_mail_result', null ); + $result = apply_filters( 'postman_wp_mail_result', null ); $transcript = $result ['transcript']; - + // post-handling - if ($success) { - $this->logger->debug ( 'Email was successfully re-sent' ); + if ( $success ) { + $this->logger->debug( 'Email was successfully re-sent' ); // the message was sent successfully, generate an appropriate message for the user - $statusMessage = sprintf ( __ ( 'Your message was delivered (%d ms) to the SMTP server! Congratulations :)', Postman::TEXT_DOMAIN ), $result ['time'] ); - + $statusMessage = sprintf( __( 'Your message was delivered (%d ms) to the SMTP server! Congratulations :)', Postman::TEXT_DOMAIN ), $result ['time'] ); + // compose the JSON response for the caller - $response = array ( + $response = array( 'message' => $statusMessage, - 'transcript' => $transcript + 'transcript' => $transcript, ); - $this->logger->trace ( 'AJAX response' ); - $this->logger->trace ( $response ); + $this->logger->trace( 'AJAX response' ); + $this->logger->trace( $response ); // send the JSON response - wp_send_json_success ( $response ); + wp_send_json_success( $response ); } else { - $this->logger->error ( 'Email was not successfully re-sent - ' . $result ['exception']->getCode () ); + $this->logger->error( 'Email was not successfully re-sent - ' . $result ['exception']->getCode() ); // the message was NOT sent successfully, generate an appropriate message for the user - $statusMessage = $result ['exception']->getMessage (); - + $statusMessage = $result ['exception']->getMessage(); + // compose the JSON response for the caller - $response = array ( + $response = array( 'message' => $statusMessage, - 'transcript' => $transcript + 'transcript' => $transcript, ); - $this->logger->trace ( 'AJAX response' ); - $this->logger->trace ( $response ); + $this->logger->trace( 'AJAX response' ); + $this->logger->trace( $response ); // send the JSON response - wp_send_json_error ( $response ); + wp_send_json_error( $response ); } } else { // compose the JSON response for the caller - $response = array (); + $response = array(); // send the JSON response - wp_send_json_error ( $response ); + wp_send_json_error( $response ); } } - + /** * TODO move this somewhere reusable * - * @param unknown $parameterName + * @param unknown $parameterName * @return unknown */ - private function getRequestParameter($parameterName) { - if (isset ( $_POST [$parameterName] )) { - $value = filter_var( $_POST [$parameterName], FILTER_SANITIZE_STRING ); - $this->logger->trace ( sprintf ( 'Found parameter "%s"', $parameterName ) ); - $this->logger->trace ( $value ); + private function getRequestParameter( $parameterName ) { + if ( isset( $_POST [ $parameterName ] ) ) { + $value = filter_var( $_POST [ $parameterName ], FILTER_SANITIZE_STRING ); + $this->logger->trace( sprintf( 'Found parameter "%s"', $parameterName ) ); + $this->logger->trace( $value ); return $value; } } - + /** * From https://www.skyverge.com/blog/add-custom-bulk-action/ */ function handleBulkAction() { // only do this for administrators - if (PostmanUtils::isAdmin () && isset ( $_REQUEST ['email_log_entry'] )) { - $this->logger->trace ( 'handling bulk action' ); - if (wp_verify_nonce ( $_REQUEST ['_wpnonce'], 'bulk-email_log_entries' )) { - $this->logger->trace ( sprintf ( 'nonce "%s" passed validation', $_REQUEST ['_wpnonce'] ) ); - if (isset ( $_REQUEST ['action'] ) && ($_REQUEST ['action'] == 'bulk_delete' || $_REQUEST ['action2'] == 'bulk_delete')) { - $this->logger->trace ( sprintf ( 'handling bulk delete' ) ); - $purger = new PostmanEmailLogPurger (); + if ( PostmanUtils::isAdmin() && isset( $_REQUEST ['email_log_entry'] ) ) { + $this->logger->trace( 'handling bulk action' ); + if ( wp_verify_nonce( $_REQUEST ['_wpnonce'], 'bulk-email_log_entries' ) ) { + $this->logger->trace( sprintf( 'nonce "%s" passed validation', $_REQUEST ['_wpnonce'] ) ); + if ( isset( $_REQUEST ['action'] ) && ($_REQUEST ['action'] == 'bulk_delete' || $_REQUEST ['action2'] == 'bulk_delete') ) { + $this->logger->trace( sprintf( 'handling bulk delete' ) ); + $purger = new PostmanEmailLogPurger(); $postids = $_REQUEST ['email_log_entry']; foreach ( $postids as $postid ) { - $purger->verifyLogItemExistsAndRemove ( $postid ); + $purger->verifyLogItemExistsAndRemove( $postid ); } - $mh = new PostmanMessageHandler (); - $mh->addMessage ( __ ( 'Mail Log Entries were deleted.', Postman::TEXT_DOMAIN ) ); + $mh = new PostmanMessageHandler(); + $mh->addMessage( __( 'Mail Log Entries were deleted.', Postman::TEXT_DOMAIN ) ); } else { - $this->logger->warn ( sprintf ( 'action "%s" not recognized', $_REQUEST ['action'] ) ); + $this->logger->warn( sprintf( 'action "%s" not recognized', $_REQUEST ['action'] ) ); } } else { - $this->logger->warn ( sprintf ( 'nonce "%s" failed validation', $_REQUEST ['_wpnonce'] ) ); + $this->logger->warn( sprintf( 'nonce "%s" failed validation', $_REQUEST ['_wpnonce'] ) ); } - $this->redirectToLogPage (); + $this->redirectToLogPage(); } } - + /** */ function delete_log_item() { // only do this for administrators - if (PostmanUtils::isAdmin ()) { - $this->logger->trace ( 'handling delete item' ); + if ( PostmanUtils::isAdmin() ) { + $this->logger->trace( 'handling delete item' ); $postid = $_REQUEST ['email']; - if (wp_verify_nonce ( $_REQUEST ['_wpnonce'], 'delete_email_log_item_' . $postid )) { - $this->logger->trace ( sprintf ( 'nonce "%s" passed validation', $_REQUEST ['_wpnonce'] ) ); - $purger = new PostmanEmailLogPurger (); - $purger->verifyLogItemExistsAndRemove ( $postid ); - $mh = new PostmanMessageHandler (); - $mh->addMessage ( __ ( 'Mail Log Entry was deleted.', Postman::TEXT_DOMAIN ) ); + if ( wp_verify_nonce( $_REQUEST ['_wpnonce'], 'delete_email_log_item_' . $postid ) ) { + $this->logger->trace( sprintf( 'nonce "%s" passed validation', $_REQUEST ['_wpnonce'] ) ); + $purger = new PostmanEmailLogPurger(); + $purger->verifyLogItemExistsAndRemove( $postid ); + $mh = new PostmanMessageHandler(); + $mh->addMessage( __( 'Mail Log Entry was deleted.', Postman::TEXT_DOMAIN ) ); } else { - $this->logger->warn ( sprintf ( 'nonce "%s" failed validation', $_REQUEST ['_wpnonce'] ) ); + $this->logger->warn( sprintf( 'nonce "%s" failed validation', $_REQUEST ['_wpnonce'] ) ); } - $this->redirectToLogPage (); + $this->redirectToLogPage(); } } - + /** */ function view_log_item() { // only do this for administrators - if (PostmanUtils::isAdmin ()) { - $this->logger->trace ( 'handling view item' ); + if ( PostmanUtils::isAdmin() ) { + $this->logger->trace( 'handling view item' ); $postid = $_REQUEST ['email']; - $post = get_post ( $postid ); - $meta_values = get_post_meta ( $postid ); + $post = get_post( $postid ); + $meta_values = get_post_meta( $postid ); // https://css-tricks.com/examples/hrs/ print ''; print ''; - if (! empty ( $meta_values ['from_header'] [0] )) { - printf ( '', _x ( 'From', 'Who is this message From?', Postman::TEXT_DOMAIN ), esc_html ( $meta_values ['from_header'] [0] ) ); + if ( ! empty( $meta_values ['from_header'] [0] ) ) { + printf( '', _x( 'From', 'Who is this message From?', Postman::TEXT_DOMAIN ), esc_html( $meta_values ['from_header'] [0] ) ); } // show the To header (it's optional) - if (! empty ( $meta_values ['to_header'] [0] )) { - printf ( '', _x ( 'To', 'Who is this message To?', Postman::TEXT_DOMAIN ), esc_html ( $meta_values ['to_header'] [0] ) ); + if ( ! empty( $meta_values ['to_header'] [0] ) ) { + printf( '', _x( 'To', 'Who is this message To?', Postman::TEXT_DOMAIN ), esc_html( $meta_values ['to_header'] [0] ) ); } // show the Cc header (it's optional) - if (! empty ( $meta_values ['cc_header'] [0] )) { - printf ( '', _x ( 'Cc', 'Who is this message Cc\'d to?', Postman::TEXT_DOMAIN ), esc_html ( $meta_values ['cc_header'] [0] ) ); + if ( ! empty( $meta_values ['cc_header'] [0] ) ) { + printf( '', _x( 'Cc', 'Who is this message Cc\'d to?', Postman::TEXT_DOMAIN ), esc_html( $meta_values ['cc_header'] [0] ) ); } // show the Bcc header (it's optional) - if (! empty ( $meta_values ['bcc_header'] [0] )) { - printf ( '', _x ( 'Bcc', 'Who is this message Bcc\'d to?', Postman::TEXT_DOMAIN ), esc_html ( $meta_values ['bcc_header'] [0] ) ); + if ( ! empty( $meta_values ['bcc_header'] [0] ) ) { + printf( '', _x( 'Bcc', 'Who is this message Bcc\'d to?', Postman::TEXT_DOMAIN ), esc_html( $meta_values ['bcc_header'] [0] ) ); } // show the Reply-To header (it's optional) - if (! empty ( $meta_values ['reply_to_header'] [0] )) { - printf ( '', __ ( 'Reply-To', Postman::TEXT_DOMAIN ), esc_html ( $meta_values ['reply_to_header'] [0] ) ); + if ( ! empty( $meta_values ['reply_to_header'] [0] ) ) { + printf( '', __( 'Reply-To', Postman::TEXT_DOMAIN ), esc_html( $meta_values ['reply_to_header'] [0] ) ); } - printf ( '', _x ( 'Date', 'What is the date today?', Postman::TEXT_DOMAIN ), $post->post_date ); - printf ( '', _x ( 'Subject', 'What is the subject of this message?', Postman::TEXT_DOMAIN ), esc_html ( $post->post_title ) ); + printf( '', _x( 'Date', 'What is the date today?', Postman::TEXT_DOMAIN ), $post->post_date ); + printf( '', _x( 'Subject', 'What is the subject of this message?', Postman::TEXT_DOMAIN ), esc_html( $post->post_title ) ); // The Transport UI is always there, in more recent versions that is - if (! empty ( $meta_values ['transport_uri'] [0] )) { - printf ( '', _x ( 'Delivery-URI', 'What is the unique URI of the configuration?', Postman::TEXT_DOMAIN ), esc_html ( $meta_values ['transport_uri'] [0] ) ); + if ( ! empty( $meta_values ['transport_uri'] [0] ) ) { + printf( '', _x( 'Delivery-URI', 'What is the unique URI of the configuration?', Postman::TEXT_DOMAIN ), esc_html( $meta_values ['transport_uri'] [0] ) ); } print '
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
%s:%s
'; print '
'; print '
';
-			print esc_html ( $post->post_content );
+			print esc_html( $post->post_content );
 			print '
'; print ''; - die (); + die(); } } - + /** */ function view_transcript_log_item() { // only do this for administrators - if (PostmanUtils::isAdmin ()) { - $this->logger->trace ( 'handling view transcript item' ); + if ( PostmanUtils::isAdmin() ) { + $this->logger->trace( 'handling view transcript item' ); $postid = $_REQUEST ['email']; - $post = get_post ( $postid ); - $meta_values = get_post_meta ( $postid ); + $post = get_post( $postid ); + $meta_values = get_post_meta( $postid ); // https://css-tricks.com/examples/hrs/ print ''; - printf ( '

%s

', __ ( 'This is the conversation between Postman and the mail server. It can be useful for diagnosing problems. DO NOT post it on-line, it may contain your account password.', Postman::TEXT_DOMAIN ) ); + printf( '

%s

', __( 'This is the conversation between Postman and the mail server. It can be useful for diagnosing problems. DO NOT post it on-line, it may contain your account password.', Postman::TEXT_DOMAIN ) ); print '
'; print '
';
-			if (! empty ( $meta_values ['session_transcript'] [0] )) {
-				print esc_html ( $meta_values ['session_transcript'] [0] );
+			if ( ! empty( $meta_values ['session_transcript'] [0] ) ) {
+				print esc_html( $meta_values ['session_transcript'] [0] );
 			} else {
 				/* Translators: Meaning "Not Applicable" */
-				print __ ( 'n/a', Postman::TEXT_DOMAIN );
+				print __( 'n/a', Postman::TEXT_DOMAIN );
 			}
 			print '
'; print ''; - die (); + die(); } } - + /** * For whatever reason, PostmanUtils::get..url doesn't work here? :( */ function redirectToLogPage() { - PostmanUtils::redirect ( PostmanUtils::POSTMAN_EMAIL_LOG_PAGE_RELATIVE_URL ); - die (); + PostmanUtils::redirect( PostmanUtils::POSTMAN_EMAIL_LOG_PAGE_RELATIVE_URL ); + die(); } - + /** * Register the page */ function postmanAddMenuItem() { // only do this for administrators - if (PostmanUtils::isAdmin ()) { - $this->logger->trace ( 'created PostmanEmailLog admin menu item' ); + if ( PostmanUtils::isAdmin() ) { + $this->logger->trace( 'created PostmanEmailLog admin menu item' ); /* Translators where (%s) is the name of the plugin */ - $page = add_management_page ( sprintf ( __ ( '%s Email Log', Postman::TEXT_DOMAIN ), __ ( 'Postman SMTP', Postman::TEXT_DOMAIN ) ), _x ( 'Email Log', 'The log of Emails that have been delivered', Postman::TEXT_DOMAIN ), 'read_private_posts', 'postman_email_log', array ( + $page = add_management_page( sprintf( __( '%s Email Log', Postman::TEXT_DOMAIN ), __( 'Postman SMTP', Postman::TEXT_DOMAIN ) ), _x( 'Email Log', 'The log of Emails that have been delivered', Postman::TEXT_DOMAIN ), 'read_private_posts', 'postman_email_log', array( $this, - 'postman_render_email_page' + 'postman_render_email_page', ) ); // When the plugin options page is loaded, also load the stylesheet - add_action ( 'admin_print_styles-' . $page, array ( + add_action( 'admin_print_styles-' . $page, array( $this, - 'postman_email_log_enqueue_resources' + 'postman_email_log_enqueue_resources', ) ); } } function postman_email_log_enqueue_resources() { - $pluginData = apply_filters ( 'postman_get_plugin_metadata', null ); - wp_register_style ( 'postman_email_log', plugins_url ( 'style/postman-email-log.css', $this->rootPluginFilenameAndPath ), null, $pluginData ['version'] ); - wp_enqueue_style ( 'postman_email_log' ); - wp_enqueue_script ( 'postman_resend_email_script' ); - wp_enqueue_script ( 'sprintf' ); - wp_localize_script ( 'postman_resend_email_script', 'postman_js_email_was_resent', __ ( 'Email was successfully resent (but without attachments)', Postman::TEXT_DOMAIN ) ); + $pluginData = apply_filters( 'postman_get_plugin_metadata', null ); + wp_register_style( 'postman_email_log', plugins_url( 'style/postman-email-log.css', $this->rootPluginFilenameAndPath ), null, $pluginData ['version'] ); + wp_enqueue_style( 'postman_email_log' ); + wp_enqueue_script( 'postman_resend_email_script' ); + wp_enqueue_script( 'sprintf' ); + wp_localize_script( 'postman_resend_email_script', 'postman_js_email_was_resent', __( 'Email was successfully resent (but without attachments)', Postman::TEXT_DOMAIN ) ); /* Translators: Where %s is an error message */ - wp_localize_script ( 'postman_resend_email_script', 'postman_js_email_not_resent', __ ( 'Email could not be resent. Error: %s', Postman::TEXT_DOMAIN ) ); - wp_localize_script ( 'postman_resend_email_script', 'postman_js_resend_label', __ ( 'Resend', Postman::TEXT_DOMAIN ) ); + wp_localize_script( 'postman_resend_email_script', 'postman_js_email_not_resent', __( 'Email could not be resent. Error: %s', Postman::TEXT_DOMAIN ) ); + wp_localize_script( 'postman_resend_email_script', 'postman_js_resend_label', __( 'Resend', Postman::TEXT_DOMAIN ) ); } - + /** * *************************** RENDER TEST PAGE ******************************** * ****************************************************************************** @@ -315,28 +314,28 @@ class PostmanEmailLogController { * it's the way the list tables are used in the WordPress core. */ function postman_render_email_page() { - + // Create an instance of our package class... - $testListTable = new PostmanEmailLogView (); - wp_enqueue_script ( 'postman_resend_email_script' ); + $testListTable = new PostmanEmailLogView(); + wp_enqueue_script( 'postman_resend_email_script' ); // Fetch, prepare, sort, and filter our data... - $testListTable->prepare_items (); - + $testListTable->prepare_items(); + ?>

-

+

+ + echo __( 'This is a record of deliveries made to the mail server. It does not neccessarily indicate sucessful delivery to the recipient.', Postman::TEXT_DOMAIN )?>

@@ -345,10 +344,10 @@ class PostmanEmailLogController { - display()?> - - - + display()?> + + +