From 82f78770cb8c6058bf506db617ed95c21e3c7b0a Mon Sep 17 00:00:00 2001 From: yehudah Date: Tue, 5 Dec 2017 21:53:16 +0000 Subject: * Welcome on activation * email log records per page * email logs trash all * remove gmail hosts for non gmail host --- .../PostmanWelcomeController.php | 219 +++++++++++++++++++++ .../PostmanEmailLogController.php | 20 +- .../Postman-Email-Log/PostmanEmailLogService.php | 10 +- Postman/Postman-Email-Log/PostmanEmailLogView.php | 16 +- Postman/Postman-Mail/PostmanMessage.php | 4 +- Postman/Postman-Mail/PostmanTransportRegistry.php | 191 +++++++++--------- Postman/Postman.php | 2 + Postman/PostmanInstaller.php | 201 ++++++++++--------- Postman/PostmanPluginFeedback.php | 8 +- Postman/PostmanViewController.php | 31 ++- 10 files changed, 490 insertions(+), 212 deletions(-) create mode 100644 Postman/Postman-Controller/PostmanWelcomeController.php (limited to 'Postman') diff --git a/Postman/Postman-Controller/PostmanWelcomeController.php b/Postman/Postman-Controller/PostmanWelcomeController.php new file mode 100644 index 0000000..b43e969 --- /dev/null +++ b/Postman/Postman-Controller/PostmanWelcomeController.php @@ -0,0 +1,219 @@ +rootPluginFilenameAndPath = $rootPluginFilenameAndPath; + $this->pluginUrl = plugins_url( 'style', $rootPluginFilenameAndPath ); + $this->version = PostmanState::getInstance()->getVersion(); + + add_action( 'admin_menu', array( $this, 'add_menus' ) ); + add_action( 'admin_head', array( $this, 'admin_head' ) ); + } + + public function add_menus() { + + if ( current_user_can( 'manage_options' ) ) { + + // About + add_dashboard_page( + __( 'Welcome', Postman::TEXT_DOMAIN ), + __( 'Welcome', Postman::TEXT_DOMAIN ), + 'manage_options', + 'post-about', + array( $this, 'about_screen' ) + ); + + // Credits + add_dashboard_page( + __( 'Credits', Postman::TEXT_DOMAIN ), + __( 'Credits', Postman::TEXT_DOMAIN ), + 'manage_options', + 'post-credits', + array( $this, 'credits_screen' ) + ); + + // add_action( 'admin_print_styles-' . $page, array( $this, 'postman_about_enqueue_resources' ) ); + } + } + + public function admin_head() { + remove_submenu_page( 'index.php', 'post-about' ); + remove_submenu_page( 'index.php', 'post-credits' ); + } + + public function postman_about_enqueue_resources() { + // wp_enqueue_style( 'font-awsome', '' ); + } + + + public function about_screen() { + ?> + +
+

version ); ?>

+
version ); ?>
+ %s','Post SMTP support every SMTP service: Gmail/G-suite, SendGrid, Mandrill, Office365, and more...' ); ?> +
+
version ); ?>
+ + + +
+

+ +
+
+

+

+ + +

+
+ +
+

+

+ + +

+
+
+
+ +
+

+ +
+
+

+
+
+ +
+
+

+

+
+ +
+

+

+
+ +
+

+

+
+
+
+ +
+ +
+ +
+ + + +
+

version ); ?>

+
version ); ?>
+
version ); ?>
+ + + +

+ +

+ + +

+
+

+ diegocanal, + Johan Yourstone, + bodhirayo, + Neil Murray , + A place waiting for you? :-) +

+ +
+ +
+ +
+ +
-
+
@@ -378,11 +378,21 @@ class PostmanEmailLogController {
+
+
+
+
+ + + +
- -
- -
Please notice: when you select a date for example 11/20/2017, behind the scene the query select 11/20/2017 00:00:00.
So if you searching for an email arrived that day at any hour you need to select 11/20/2017 as the From Date and 11/21/2017 as the To Date.
diff --git a/Postman/Postman-Email-Log/PostmanEmailLogService.php b/Postman/Postman-Email-Log/PostmanEmailLogService.php index 5f57ed8..6c0784b 100644 --- a/Postman/Postman-Email-Log/PostmanEmailLogService.php +++ b/Postman/Postman-Email-Log/PostmanEmailLogService.php @@ -234,10 +234,10 @@ if ( ! class_exists( 'PostmanEmailLogPurger' ) ) { * * @return unknown */ - function __construct() { + function __construct( $args = array() ) { $this->logger = new PostmanLogger( get_class( $this ) ); - $args = array( - 'posts_per_page' => 1000, + $defaults = array( + 'posts_per_page' => -1, 'offset' => 0, 'category' => '', 'category_name' => '', @@ -253,7 +253,9 @@ if ( ! class_exists( 'PostmanEmailLogPurger' ) ) { 'post_status' => 'private', 'suppress_filters' => true, ); - $this->posts = get_posts( $args ); + $args = wp_parse_args( $args, $defaults ); + $query = new WP_Query( $args ); + $this->posts = $query->posts; } /** diff --git a/Postman/Postman-Email-Log/PostmanEmailLogView.php b/Postman/Postman-Email-Log/PostmanEmailLogView.php index fe0fdfe..1d8c4b1 100644 --- a/Postman/Postman-Email-Log/PostmanEmailLogView.php +++ b/Postman/Postman-Email-Log/PostmanEmailLogView.php @@ -305,8 +305,10 @@ class PostmanEmailLogView extends WP_List_Table { * be able to use your precisely-queried data immediately. */ $data = array(); + $posts_per_page = absint( $_POST['postman_page_records'] ); + $args = array( - 'posts_per_page' => 1000, + 'posts_per_page' => $posts_per_page, 'offset' => 0, 'orderby' => 'date', 'order' => 'DESC', @@ -339,7 +341,19 @@ class PostmanEmailLogView extends WP_List_Table { $args['s'] = sanitize_text_field( $_POST['search'] ); } + if ( isset( $_POST['postman_trash_all'] ) ) { + $args['posts_per_page'] = -1; + } $posts = new WP_query( $args ); + + if ( isset( $_POST['postman_trash_all'] ) ) { + foreach ( $posts->posts as $post ) { + wp_delete_post( $post->ID, true ); + } + + $posts->posts = array(); + } + $date_format = get_option( 'date_format' ); $time_format = get_option( 'time_format' ); diff --git a/Postman/Postman-Mail/PostmanMessage.php b/Postman/Postman-Mail/PostmanMessage.php index f9b7dd3..93cb11d 100644 --- a/Postman/Postman-Mail/PostmanMessage.php +++ b/Postman/Postman-Mail/PostmanMessage.php @@ -35,7 +35,7 @@ if ( ! class_exists( 'PostmanMessage' ) ) { // determined by the send() method private $isTextHtml; - private $contentType; + private $contentType = 'text/plain'; private $charset; private $boundary; @@ -81,7 +81,7 @@ if ( ! class_exists( 'PostmanMessage' ) ) { $this->contentType = sprintf( "%s;\r\n\t boundary=\"%s\"", $this->contentType, $this->getBoundary() ); } - $body = $this->getBody(); + $body = $this->getBody(); $contentType = $this->getContentType(); // add the message content as either text or html if ( empty( $contentType ) || substr( $contentType, 0, 10 ) === 'text/plain' ) { diff --git a/Postman/Postman-Mail/PostmanTransportRegistry.php b/Postman/Postman-Mail/PostmanTransportRegistry.php index 01a60bd..77654eb 100644 --- a/Postman/Postman-Mail/PostmanTransportRegistry.php +++ b/Postman/Postman-Mail/PostmanTransportRegistry.php @@ -5,34 +5,33 @@ require_once 'PostmanZendMailTransportConfigurationFactory.php'; /** * * @author jasonhendriks - * */ class PostmanTransportRegistry { private $transports; private $logger; - + /** */ private function __construct() { - $this->logger = new PostmanLogger ( get_class ( $this ) ); + $this->logger = new PostmanLogger( get_class( $this ) ); } - + // singleton instance public static function getInstance() { static $inst = null; - if ($inst === null) { - $inst = new PostmanTransportRegistry (); + if ( $inst === null ) { + $inst = new PostmanTransportRegistry(); } return $inst; } - public function registerTransport(PostmanModuleTransport $instance) { - $this->transports [$instance->getSlug ()] = $instance; + public function registerTransport( PostmanModuleTransport $instance ) { + $this->transports [ $instance->getSlug() ] = $instance; $instance->init(); } public function getTransports() { return $this->transports; } - + /** * Retrieve a Transport by slug * Look up a specific Transport use: @@ -40,85 +39,84 @@ class PostmanTransportRegistry { * B) when querying what a theoretical scenario involving this transport is like * (ie.for ajax in config screen) * - * @param unknown $slug + * @param unknown $slug */ - public function getTransport($slug) { - $transports = $this->getTransports (); - if (isset ( $transports [$slug] )) { - return $transports [$slug]; + public function getTransport( $slug ) { + $transports = $this->getTransports(); + if ( isset( $transports [ $slug ] ) ) { + return $transports [ $slug ]; } } - + /** * A short-hand way of showing the complete delivery method * - * @param PostmanModuleTransport $transport + * @param PostmanModuleTransport $transport * @return string */ - public function getPublicTransportUri(PostmanModuleTransport $transport) { - return $transport->getPublicTransportUri (); + public function getPublicTransportUri( PostmanModuleTransport $transport ) { + return $transport->getPublicTransportUri(); } - + /** * Determine if a specific transport is registered in the directory. * - * @param unknown $slug + * @param unknown $slug */ - public function isRegistered($slug) { - $transports = $this->getTransports (); - return isset ( $transports [$slug] ); + public function isRegistered( $slug ) { + $transports = $this->getTransports(); + return isset( $transports [ $slug ] ); } - + /** * Retrieve the transport Postman is currently configured with. * * @return PostmanDummyTransport|PostmanModuleTransport * @deprecated - * */ public function getCurrentTransport() { - $selectedTransport = PostmanOptions::getInstance ()->getTransportType (); - $transports = $this->getTransports (); - if (! isset ( $transports [$selectedTransport] )) { + $selectedTransport = PostmanOptions::getInstance()->getTransportType(); + $transports = $this->getTransports(); + if ( ! isset( $transports [ $selectedTransport ] ) ) { return $transports ['default']; } else { - return $transports [$selectedTransport]; + return $transports [ $selectedTransport ]; } } - + /** * - * @param PostmanOptions $options - * @param PostmanOAuthToken $token + * @param PostmanOptions $options + * @param PostmanOAuthToken $token * @return boolean */ public function getActiveTransport() { - $selectedTransport = PostmanOptions::getInstance ()->getTransportType (); - $transports = $this->getTransports (); - if (isset ( $transports [$selectedTransport] )) { - $transport = $transports [$selectedTransport]; - if ($transport->getSlug () == $selectedTransport && $transport->isConfiguredAndReady ()) { + $selectedTransport = PostmanOptions::getInstance()->getTransportType(); + $transports = $this->getTransports(); + if ( isset( $transports [ $selectedTransport ] ) ) { + $transport = $transports [ $selectedTransport ]; + if ( $transport->getSlug() == $selectedTransport && $transport->isConfiguredAndReady() ) { return $transport; } } return $transports ['default']; } - + /** * Retrieve the transport Postman is currently configured with. * * @return PostmanDummyTransport|PostmanModuleTransport */ public function getSelectedTransport() { - $selectedTransport = PostmanOptions::getInstance ()->getTransportType (); - $transports = $this->getTransports (); - if (isset ( $transports [$selectedTransport] )) { - return $transports [$selectedTransport]; + $selectedTransport = PostmanOptions::getInstance()->getTransportType(); + $transports = $this->getTransports(); + if ( isset( $transports [ $selectedTransport ] ) ) { + return $transports [ $selectedTransport ]; } else { return $transports ['default']; } } - + /** * Determine whether to show the Request Permission link on the main menu * @@ -127,47 +125,52 @@ class PostmanTransportRegistry { * 2. the transport is properly configured * 3. we have a valid Client ID and Client Secret without an Auth Token * - * @param PostmanOptions $options + * @param PostmanOptions $options * @return boolean */ - public function isRequestOAuthPermissionAllowed(PostmanOptions $options, PostmanOAuthToken $authToken) { + public function isRequestOAuthPermissionAllowed( PostmanOptions $options, PostmanOAuthToken $authToken ) { // does the current transport use OAuth 2.0 - $oauthUsed = self::getSelectedTransport ()->isOAuthUsed ( $options->getAuthenticationType () ); - + $oauthUsed = self::getSelectedTransport()->isOAuthUsed( $options->getAuthenticationType() ); + // is the transport configured - if ($oauthUsed) { - $configured = self::getSelectedTransport ()->isConfiguredAndReady (); + if ( $oauthUsed ) { + $configured = self::getSelectedTransport()->isConfiguredAndReady(); } - + return $oauthUsed && $configured; } - + /** * Polls all the installed transports to get a complete list of sockets to probe for connectivity * - * @param unknown $hostname - * @param unknown $isGmail + * @param unknown $hostname + * @param unknown $isGmail * @return multitype: */ - public function getSocketsForSetupWizardToProbe($hostname = 'localhost', $smtpServerGuess = null) { - $hosts = array (); - if ($this->logger->isDebug ()) { - $this->logger->debug ( sprintf ( 'Getting sockets for Port Test given hostname %s and smtpServerGuess %s', $hostname, $smtpServerGuess ) ); + public function getSocketsForSetupWizardToProbe( $hostname = 'localhost', $smtpServerGuess = null ) { + $hosts = array(); + if ( $this->logger->isDebug() ) { + $this->logger->debug( sprintf( 'Getting sockets for Port Test given hostname %s and smtpServerGuess %s', $hostname, $smtpServerGuess ) ); + } + + $transports = $this->getTransports(); + if ( $hostname !== 'smtp.gmail.com' ) { + unset( $transports['gmail_api'] ); } - foreach ( $this->getTransports () as $transport ) { - $socketsToTest = $transport->getSocketsForSetupWizardToProbe ( $hostname, $smtpServerGuess ); - if ($this->logger->isTrace ()) { - $this->logger->trace ( 'sockets to test:' ); - $this->logger->trace ( $socketsToTest ); + foreach ( $transports as $transport ) { + $socketsToTest = $transport->getSocketsForSetupWizardToProbe( $hostname, $smtpServerGuess ); + if ( $this->logger->isTrace() ) { + $this->logger->trace( 'sockets to test:' ); + $this->logger->trace( $socketsToTest ); } - $hosts = array_merge ( $hosts, $socketsToTest ); - if ($this->logger->isDebug ()) { - $this->logger->debug ( sprintf ( 'Transport %s returns %d sockets ', $transport->getName (), sizeof ( $socketsToTest ) ) ); + $hosts = array_merge( $hosts, $socketsToTest ); + if ( $this->logger->isDebug() ) { + $this->logger->debug( sprintf( 'Transport %s returns %d sockets ', $transport->getName(), sizeof( $socketsToTest ) ) ); } } return $hosts; } - + /** * If the host port is a possible configuration option, recommend it * @@ -175,63 +178,63 @@ class PostmanTransportRegistry { * * response should include ['success'], ['message'], ['priority'] * - * @param unknown $hostData + * @param unknown $hostData */ - public function getRecommendation(PostmanWizardSocket $hostData, $userAuthOverride, $originalSmtpServer) { - $scrubbedUserAuthOverride = $this->scrubUserOverride ( $hostData, $userAuthOverride ); - $transport = $this->getTransport ( $hostData->transport ); - $recommendation = $transport->getConfigurationBid ( $hostData, $scrubbedUserAuthOverride, $originalSmtpServer ); - if ($this->logger->isDebug ()) { - $this->logger->debug ( sprintf ( 'Transport %s bid %s', $transport->getName (), $recommendation ['priority'] ) ); + public function getRecommendation( PostmanWizardSocket $hostData, $userAuthOverride, $originalSmtpServer ) { + $scrubbedUserAuthOverride = $this->scrubUserOverride( $hostData, $userAuthOverride ); + $transport = $this->getTransport( $hostData->transport ); + $recommendation = $transport->getConfigurationBid( $hostData, $scrubbedUserAuthOverride, $originalSmtpServer ); + if ( $this->logger->isDebug() ) { + $this->logger->debug( sprintf( 'Transport %s bid %s', $transport->getName(), $recommendation ['priority'] ) ); } return $recommendation; } - + /** * - * @param PostmanWizardSocket $hostData - * @param unknown $userAuthOverride + * @param PostmanWizardSocket $hostData + * @param unknown $userAuthOverride * @return NULL */ - private function scrubUserOverride(PostmanWizardSocket $hostData, $userAuthOverride) { - $this->logger->trace ( 'before scrubbing userAuthOverride: ' . $userAuthOverride ); - + private function scrubUserOverride( PostmanWizardSocket $hostData, $userAuthOverride ) { + $this->logger->trace( 'before scrubbing userAuthOverride: ' . $userAuthOverride ); + // validate userAuthOverride - if (! ($userAuthOverride == 'oauth2' || $userAuthOverride == 'password' || $userAuthOverride == 'none')) { + if ( ! ($userAuthOverride == 'oauth2' || $userAuthOverride == 'password' || $userAuthOverride == 'none') ) { $userAuthOverride = null; } - + // validate the userAuthOverride - if (! $hostData->auth_xoauth) { - if ($userAuthOverride == 'oauth2') { + if ( ! $hostData->auth_xoauth ) { + if ( $userAuthOverride == 'oauth2' ) { $userAuthOverride = null; } } - if (! $hostData->auth_crammd5 && ! $hostData->authPlain && ! $hostData->auth_login) { - if ($userAuthOverride == 'password') { + if ( ! $hostData->auth_crammd5 && ! $hostData->authPlain && ! $hostData->auth_login ) { + if ( $userAuthOverride == 'password' ) { $userAuthOverride = null; } } - if (! $hostData->auth_none) { - if ($userAuthOverride == 'none') { + if ( ! $hostData->auth_none ) { + if ( $userAuthOverride == 'none' ) { $userAuthOverride = null; } } - $this->logger->trace ( 'after scrubbing userAuthOverride: ' . $userAuthOverride ); + $this->logger->trace( 'after scrubbing userAuthOverride: ' . $userAuthOverride ); return $userAuthOverride; } - + /** */ public function getReadyMessage() { - if ($this->getCurrentTransport ()->isConfiguredAndReady ()) { - if (PostmanOptions::getInstance ()->getRunMode () != PostmanOptions::RUN_MODE_PRODUCTION) { - return __ ( 'Postman is in non-Production mode and is dumping all emails.', Postman::TEXT_DOMAIN ); + if ( $this->getCurrentTransport()->isConfiguredAndReady() ) { + if ( PostmanOptions::getInstance()->getRunMode() != PostmanOptions::RUN_MODE_PRODUCTION ) { + return __( 'Postman is in non-Production mode and is dumping all emails.', Postman::TEXT_DOMAIN ); } else { - return __ ( 'Postman is configured.', Postman::TEXT_DOMAIN ); + return __( 'Postman is configured.', Postman::TEXT_DOMAIN ); } } else { - return __ ( 'Postman is not configured and is mimicking out-of-the-box WordPress email delivery.', Postman::TEXT_DOMAIN ); + return __( 'Postman is not configured and is mimicking out-of-the-box WordPress email delivery.', Postman::TEXT_DOMAIN ); } } } diff --git a/Postman/Postman.php b/Postman/Postman.php index 23351e7..69c23b8 100644 --- a/Postman/Postman.php +++ b/Postman/Postman.php @@ -203,6 +203,7 @@ class Postman { // load the dependencies require_once 'PostmanMessageHandler.php'; require_once 'PostmanAdminController.php'; + require_once 'Postman-Controller/PostmanWelcomeController.php'; require_once 'Postman-Controller/PostmanDashboardWidgetController.php'; require_once 'Postman-Controller/PostmanAdminPointer.php'; require_once 'Postman-Email-Log/PostmanEmailLogController.php'; @@ -215,6 +216,7 @@ class Postman { $this->messageHandler = new PostmanMessageHandler(); // create the Admin Controllers + new PostmanWelcomeController( $rootPluginFilenameAndPath ); new PostmanDashboardWidgetController( $rootPluginFilenameAndPath, $options, $authToken, $this->wpMailBinder ); new PostmanAdminController( $rootPluginFilenameAndPath, $options, $authToken, $this->messageHandler, $this->wpMailBinder ); new PostmanEmailLogController( $rootPluginFilenameAndPath ); diff --git a/Postman/PostmanInstaller.php b/Postman/PostmanInstaller.php index 170ccf1..812f122 100644 --- a/Postman/PostmanInstaller.php +++ b/Postman/PostmanInstaller.php @@ -1,6 +1,6 @@ logger = new PostmanLogger ( get_class ( $this ) ); + $this->logger = new PostmanLogger( get_class( $this ) ); } - + /** * Handle activation of the plugin */ public function activatePostman() { - if (function_exists ( 'is_multisite' ) && is_multisite ()) { + if ( function_exists( 'is_multisite' ) && is_multisite() ) { // handle network activation // from https://wordpress.org/support/topic/new-function-wp_get_sites?replies=11 - // run the activation function for each blog id - $old_blog = get_current_blog_id (); + $old_blog = get_current_blog_id(); // Get all blog ids - $subsites = wp_get_sites (); + $subsites = wp_get_sites(); foreach ( $subsites as $subsite ) { - $this->logger->trace ( 'multisite: switching to blog ' . $subsite ['blog_id'] ); - switch_to_blog ( $subsite ['blog_id'] ); - $this->handleOptionUpdates (); - $this->addCapability (); + $this->logger->trace( 'multisite: switching to blog ' . $subsite ['blog_id'] ); + switch_to_blog( $subsite ['blog_id'] ); + $this->handleOptionUpdates(); + $this->addCapability(); } - switch_to_blog ( $old_blog ); + switch_to_blog( $old_blog ); } else { // handle single-site activation - $this->handleOptionUpdates (); - $this->addCapability (); + $this->handleOptionUpdates(); + $this->addCapability(); } + + $this->add_activation_redirect(); + } + + function add_activation_redirect() { + + // Bail if activating from network, or bulk + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { + return; } + + // Add the transient to redirect + set_transient( '_post_activation_redirect', true, 30 ); } - + /** * Handle deactivation of the plugin */ public function deactivatePostman() { - if (function_exists ( 'is_multisite' ) && is_multisite ()) { + if ( function_exists( 'is_multisite' ) && is_multisite() ) { // handle network deactivation // from https://wordpress.org/support/topic/new-function-wp_get_sites?replies=11 - // run the deactivation function for each blog id - $old_blog = get_current_blog_id (); + $old_blog = get_current_blog_id(); // Get all blog ids - $subsites = wp_get_sites (); + $subsites = wp_get_sites(); foreach ( $subsites as $subsite ) { - $this->logger->trace ( 'multisite: switching to blog ' . $subsite ['blog_id'] ); - switch_to_blog ( $subsite ['blog_id'] ); - $this->removeCapability (); + $this->logger->trace( 'multisite: switching to blog ' . $subsite ['blog_id'] ); + switch_to_blog( $subsite ['blog_id'] ); + $this->removeCapability(); } - switch_to_blog ( $old_blog ); + switch_to_blog( $old_blog ); } else { // handle single-site deactivation - $this->removeCapability (); + $this->removeCapability(); } } - + /** * Add the capability to manage postman */ public function addCapability() { - if ($this->logger->isDebug ()) { - $this->logger->debug ( 'Adding admin capability' ); + if ( $this->logger->isDebug() ) { + $this->logger->debug( 'Adding admin capability' ); } // ref: https://codex.wordpress.org/Function_Reference/add_cap // NB: This setting is saved to the database, so it might be better to run this on theme/plugin activation - // add the custom capability to the administrator role - $role = get_role ( Postman::ADMINISTRATOR_ROLE_NAME ); - $role->add_cap ( Postman::MANAGE_POSTMAN_CAPABILITY_NAME ); + $role = get_role( Postman::ADMINISTRATOR_ROLE_NAME ); + $role->add_cap( Postman::MANAGE_POSTMAN_CAPABILITY_NAME ); } - + /** * Remove the capability to manage postman */ public function removeCapability() { - if ($this->logger->isDebug ()) { - $this->logger->debug ( 'Removing admin capability' ); + if ( $this->logger->isDebug() ) { + $this->logger->debug( 'Removing admin capability' ); } // ref: https://codex.wordpress.org/Function_Reference/add_cap // NB: This setting is saved to the database, so it might be better to run this on theme/plugin activation - // remove the custom capability from the administrator role - $role = get_role ( Postman::ADMINISTRATOR_ROLE_NAME ); - $role->remove_cap ( Postman::MANAGE_POSTMAN_CAPABILITY_NAME ); + $role = get_role( Postman::ADMINISTRATOR_ROLE_NAME ); + $role->remove_cap( Postman::MANAGE_POSTMAN_CAPABILITY_NAME ); } - + /** * Handle activation of plugin */ private function handleOptionUpdates() { - $this->logger->debug ( "Activating plugin" ); + $this->logger->debug( 'Activating plugin' ); // prior to version 0.2.5, $authOptions did not exist - $authOptions = get_option ( 'postman_auth_token' ); - $options = get_option ( 'postman_options' ); - $postmanState = get_option ( 'postman_state' ); - if (empty ( $authOptions ) && ! (empty ( $options )) && ! empty ( $options ['access_token'] )) { - $this->logger->debug ( "Upgrading database: copying Authorization token from postman_options to postman_auth_token" ); + $authOptions = get_option( 'postman_auth_token' ); + $options = get_option( 'postman_options' ); + $postmanState = get_option( 'postman_state' ); + if ( empty( $authOptions ) && ! (empty( $options )) && ! empty( $options ['access_token'] ) ) { + $this->logger->debug( 'Upgrading database: copying Authorization token from postman_options to postman_auth_token' ); // copy the variables from $options to $authToken $authOptions ['access_token'] = $options ['access_token']; $authOptions ['refresh_token'] = $options ['refresh_token']; // there was a bug where we weren't setting the expiry time - if (! empty ( $options ['auth_token_expires'] )) { + if ( ! empty( $options ['auth_token_expires'] ) ) { $authOptions ['auth_token_expires'] = $options ['auth_token_expires']; } - update_option ( 'postman_auth_token', $authOptions ); + update_option( 'postman_auth_token', $authOptions ); } - if (! isset ( $options ['authorization_type'] ) && ! isset ( $options ['auth_type'] )) { + if ( ! isset( $options ['authorization_type'] ) && ! isset( $options ['auth_type'] ) ) { // prior to 1.0.0, access tokens were saved in authOptions without an auth type // prior to 0.2.5, access tokens were save in options without an auth type // either way, only oauth2 was supported - if (isset ( $authOptions ['access_token'] ) || isset ( $options ['access_token'] )) { - $this->logger->debug ( "Upgrading database: setting authorization_type to 'oauth2'" ); + if ( isset( $authOptions ['access_token'] ) || isset( $options ['access_token'] ) ) { + $this->logger->debug( "Upgrading database: setting authorization_type to 'oauth2'" ); $options ['authorization_type'] = 'oauth2'; - update_option ( 'postman_options', $options ); + update_option( 'postman_options', $options ); } } - if (! isset ( $options ['enc_type'] )) { + if ( ! isset( $options ['enc_type'] ) ) { // prior to 1.3, encryption type was combined with authentication type - if (isset ( $options ['authorization_type'] )) { - $this->logger->debug ( "Upgrading database: creating auth_type and enc_type from authorization_type" ); + if ( isset( $options ['authorization_type'] ) ) { + $this->logger->debug( 'Upgrading database: creating auth_type and enc_type from authorization_type' ); $authType = $options ['authorization_type']; - switch ($authType) { + switch ( $authType ) { case 'none' : $options ['auth_type'] = 'none'; $options ['enc_type'] = 'none'; @@ -152,81 +160,78 @@ class PostmanInstaller { break; default : } - update_option ( 'postman_options', $options ); + update_option( 'postman_options', $options ); } } // prior to 1.3.3, the version identifier was not stored and the passwords were plaintext - if (isset ( $options ['enc_type'] ) && ! (isset ( $options ['version'] ) || isset ( $postmanState ['version'] ))) { - $this->logger->debug ( "Upgrading database: added plugin version and encoding password" ); + if ( isset( $options ['enc_type'] ) && ! (isset( $options ['version'] ) || isset( $postmanState ['version'] )) ) { + $this->logger->debug( 'Upgrading database: added plugin version and encoding password' ); $options ['version'] = '1.3.3'; - if (isset ( $options ['basic_auth_password'] )) { - $options ['basic_auth_password'] = base64_encode ( $options ['basic_auth_password'] ); + if ( isset( $options ['basic_auth_password'] ) ) { + $options ['basic_auth_password'] = base64_encode( $options ['basic_auth_password'] ); } - update_option ( 'postman_options', $options ); + update_option( 'postman_options', $options ); } // prior to 1.4.2, the transport was not identified and the auth token had no vendor - if (isset ( $options ['auth_type'] ) && ! isset ( $options ['transport_type'] )) { - $this->logger->debug ( "Upgrading database: added transport_type and vendor_name" ); + if ( isset( $options ['auth_type'] ) && ! isset( $options ['transport_type'] ) ) { + $this->logger->debug( 'Upgrading database: added transport_type and vendor_name' ); $options ['transport_type'] = 'smtp'; - update_option ( 'postman_options', $options ); - if (isset ( $authOptions ['access_token'] ) && isset ( $options ['oauth_client_id'] )) { + update_option( 'postman_options', $options ); + if ( isset( $authOptions ['access_token'] ) && isset( $options ['oauth_client_id'] ) ) { // if there is a stored token.. - if (PostmanUtils::endsWith ( $options ['oauth_client_id'], 'googleusercontent.com' )) - $authOptions ['vendor_name'] = 'google'; - else if (strlen ( $options ['oauth_client_id'] < strlen ( $options ['oauth_client_secret'] ) )) + if ( PostmanUtils::endsWith( $options ['oauth_client_id'], 'googleusercontent.com' ) ) { + $authOptions ['vendor_name'] = 'google'; } else if ( strlen( $options ['oauth_client_id'] < strlen( $options ['oauth_client_secret'] ) ) ) { $authOptions ['vendor_name'] = 'microsoft'; - else - $authOptions ['vendor_name'] = 'yahoo'; - update_option ( 'postman_auth_token', $authOptions ); + } else { $authOptions ['vendor_name'] = 'yahoo'; } + update_option( 'postman_auth_token', $authOptions ); } } - + // for version 1.6.18, the envelope from was introduced - if (! empty ( $options ['sender_email'] ) && empty ( $options ['envelope_sender'] )) { - $this->logger->debug ( "Upgrading database: adding envelope_sender" ); + if ( ! empty( $options ['sender_email'] ) && empty( $options ['envelope_sender'] ) ) { + $this->logger->debug( 'Upgrading database: adding envelope_sender' ); $options ['envelope_sender'] = $options ['sender_email']; - update_option ( 'postman_options', $options ); + update_option( 'postman_options', $options ); } - - if (isset ( $postmanState ['version'] ) && version_compare ( $postmanState ['version'], '1.7.0', '<' )) { - if ($options ['mail_log_max_entries'] == 10) { + + if ( isset( $postmanState ['version'] ) && version_compare( $postmanState ['version'], '1.7.0', '<' ) ) { + if ( $options ['mail_log_max_entries'] == 10 ) { $options ['mail_log_max_entries'] = 250; } - $postmanStats = get_option ( 'postman_stats' ); + $postmanStats = get_option( 'postman_stats' ); $stateCleared = false; - if (! isset ( $postmanState ['delivery_success_total'] ) && isset ( $postmanStats ['delivery_success_total'] )) { + if ( ! isset( $postmanState ['delivery_success_total'] ) && isset( $postmanStats ['delivery_success_total'] ) ) { $postmanState ['delivery_success_total'] = $postmanStats ['delivery_success_total']; $stateCleared = true; } - if (! isset ( $postmanState ['delivery_fail_total'] ) && isset ( $postmanStats ['delivery_fail_total'] )) { + if ( ! isset( $postmanState ['delivery_fail_total'] ) && isset( $postmanStats ['delivery_fail_total'] ) ) { $postmanState ['delivery_fail_total'] = $postmanStats ['delivery_fail_total']; $stateCleared = true; } - if ($stateCleared) { - delete_option ( 'postman_stats' ); + if ( $stateCleared ) { + delete_option( 'postman_stats' ); } } - + // can we create a tmp file? - this code is duplicated in InputSanitizer - PostmanUtils::deleteLockFile (); - $lockSuccess = PostmanUtils::createLockFile (); + PostmanUtils::deleteLockFile(); + $lockSuccess = PostmanUtils::createLockFile(); // &= does not work as expected in my PHP - $lockSuccess = $lockSuccess && PostmanUtils::deleteLockFile (); + $lockSuccess = $lockSuccess && PostmanUtils::deleteLockFile(); $postmanState ['locking_enabled'] = $lockSuccess; - + // always update the version number - if (! isset ( $postmanState ['install_date'] )) { - $this->logger->debug ( "Upgrading database: adding install_date" ); - $postmanState ['install_date'] = time (); + if ( ! isset( $postmanState ['install_date'] ) ) { + $this->logger->debug( 'Upgrading database: adding install_date' ); + $postmanState ['install_date'] = time(); } - $pluginData = apply_filters ( 'postman_get_plugin_metadata', null ); + $pluginData = apply_filters( 'postman_get_plugin_metadata', null ); $postmanState ['version'] = $pluginData ['version']; - update_option ( 'postman_state', $postmanState ); - // - delete_option ( 'postman_session' ); - + update_option( 'postman_state', $postmanState ); + delete_option( 'postman_session' ); + // reload options - PostmanState::getInstance ()->reload (); - PostmanOptions::getInstance ()->reload (); + PostmanState::getInstance()->reload(); + PostmanOptions::getInstance()->reload(); } } diff --git a/Postman/PostmanPluginFeedback.php b/Postman/PostmanPluginFeedback.php index 3ac985d..b31011d 100644 --- a/Postman/PostmanPluginFeedback.php +++ b/Postman/PostmanPluginFeedback.php @@ -110,13 +110,13 @@ class PostmanPluginFeedback {
  • @@ -145,7 +145,7 @@ class PostmanPluginFeedback {
    diff --git a/Postman/PostmanViewController.php b/Postman/PostmanViewController.php index 99c3018..964e266 100644 --- a/Postman/PostmanViewController.php +++ b/Postman/PostmanViewController.php @@ -35,11 +35,34 @@ if ( ! class_exists( 'PostmanViewController' ) ) { PostmanUtils::registerAdminMenu( $this, 'addPurgeDataSubmenu' ); // initialize the scripts, stylesheets and form fields - add_action( 'admin_init', array( - $this, - 'registerStylesAndScripts', - ), 0 ); + add_action( 'admin_init', array( $this, 'registerStylesAndScripts' ), 0 ); + add_action( 'admin_init', array( $this, 'do_activation_redirect' ) ); + + } + + function do_activation_redirect() { + + // Bail if no activation redirect + if ( ! get_transient( '_post_activation_redirect' ) ) { + return; + } + + // Delete the redirect transient + // delete_transient( '_post_activation_redirect' ); + // Bail if activating from network, or bulk + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { + return; + } + + // Bail if the current user cannot see the about page + if ( ! current_user_can( 'manage_options' ) ) { + return; + } + + // Redirect to bbPress about page + wp_safe_redirect( add_query_arg( array( 'page' => 'post-about' ), admin_url( 'index.php' ) ) ); } + public static function getPageUrl( $slug ) { return PostmanUtils::getPageUrl( $slug ); } -- cgit v1.2.3