options = $options; $this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath; $this->authorizationToken = $authorizationToken; $this->oauthScribe = $oauthScribe; $this->adminController = $adminController; $this->logger = new PostmanLogger( get_class( $this ) ); PostmanUtils::registerAdminMenu( $this, 'generateDefaultContent' ); PostmanUtils::registerAdminMenu( $this, 'addPurgeDataSubmenu' ); // initialize the scripts, stylesheets and form fields add_action( 'admin_init', array( $this, 'registerStylesAndScripts' ), 0 ); add_action( 'wp_ajax_delete_lock_file', array( $this, 'delete_lock_file' ) ); add_action( 'wp_ajax_dismiss_version_notify', array( $this, 'dismiss_version_notify' ) ); //add_action( 'admin_init', array( $this, 'do_activation_redirect' ) ); } function dismiss_version_notify() { check_ajax_referer( 'postsmtp', 'security' ); $version = sanitize_text_field($_POST['version']); $result = update_option('postman_release_version_'. $version, true ); } function delete_lock_file() { check_ajax_referer( 'postman', 'security' ); if ( ! PostmanUtils::lockFileExists() ) { echo __('No lock file found.', Postman::TEXT_DOMAIN ); die(); } echo PostmanUtils::deleteLockFile() == true ? __('Success, try to send test email.', Postman::TEXT_DOMAIN ) : __('Failed, try again.', Postman::TEXT_DOMAIN ); die(); } 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 ); } /** * Add options page */ public function generateDefaultContent() { // This page will be under "Settings" $pageTitle = sprintf( __( '%s Setup', Postman::TEXT_DOMAIN ), __( 'Post SMTP', Postman::TEXT_DOMAIN ) ); $pluginName = __( 'Post SMTP', Postman::TEXT_DOMAIN ); $uniqueId = self::POSTMAN_MENU_SLUG; $pageOptions = array( $this, 'outputDefaultContent', ); $mainPostmanSettingsPage = add_menu_page( $pageTitle, $pluginName, Postman::MANAGE_POSTMAN_CAPABILITY_NAME, $uniqueId, $pageOptions ); // When the plugin options page is loaded, also load the stylesheet add_action( 'admin_print_styles-' . $mainPostmanSettingsPage, array( $this, 'enqueueHomeScreenStylesheet', ) ); } function enqueueHomeScreenStylesheet() { wp_enqueue_style( PostmanViewController::POSTMAN_STYLE ); wp_enqueue_script( 'postman_script' ); } /** * Register the Email Test screen */ public function addPurgeDataSubmenu() { $page = add_submenu_page( null, sprintf( __( '%s Setup', Postman::TEXT_DOMAIN ), __( 'Post SMTP', Postman::TEXT_DOMAIN ) ), __( 'Post SMTP', Postman::TEXT_DOMAIN ), Postman::MANAGE_POSTMAN_CAPABILITY_NAME, PostmanAdminController::MANAGE_OPTIONS_PAGE_SLUG, array( $this, 'outputPurgeDataContent', ) ); // When the plugin options page is loaded, also load the stylesheet add_action( 'admin_print_styles-' . $page, array( $this, 'enqueueHomeScreenStylesheet', ) ); } /** * Register and add settings */ public function registerStylesAndScripts() { if ( $this->logger->isTrace() ) { $this->logger->trace( 'registerStylesAndScripts()' ); } // register the stylesheet and javascript external resources $pluginData = apply_filters( 'postman_get_plugin_metadata', null ); wp_register_style( PostmanViewController::POSTMAN_STYLE, plugins_url( 'style/postman.css', $this->rootPluginFilenameAndPath ), null, $pluginData ['version'] ); wp_register_style( 'jquery_ui_style', plugins_url( 'style/jquery-steps/jquery-ui.css', $this->rootPluginFilenameAndPath ), PostmanViewController::POSTMAN_STYLE, '1.1.0' ); wp_register_style( 'jquery_steps_style', plugins_url( 'style/jquery-steps/jquery.steps.css', $this->rootPluginFilenameAndPath ), PostmanViewController::POSTMAN_STYLE, '1.1.0' ); wp_register_script( PostmanViewController::POSTMAN_SCRIPT, plugins_url( 'script/postman.js', $this->rootPluginFilenameAndPath ), array( PostmanViewController::JQUERY_SCRIPT, 'jquery-ui-core', 'jquery-ui-datepicker', ), $pluginData ['version'] ); wp_register_script( 'sprintf', plugins_url( 'script/sprintf/sprintf.min.js', $this->rootPluginFilenameAndPath ), null, '1.0.2' ); wp_register_script( 'jquery_steps_script', plugins_url( 'script/jquery-steps/jquery.steps.min.js', $this->rootPluginFilenameAndPath ), array( PostmanViewController::JQUERY_SCRIPT ), '1.1.0' ); wp_register_script( 'jquery_validation', plugins_url( 'script/jquery-validate/jquery.validate.min.js', $this->rootPluginFilenameAndPath ), array( PostmanViewController::JQUERY_SCRIPT ), '1.13.1' ); wp_localize_script( PostmanViewController::POSTMAN_SCRIPT, 'postman_ajax_msg', array( 'bad_response' => __( 'An unexpected error occurred', Postman::TEXT_DOMAIN ), 'corrupt_response' => __( 'Unexpected PHP messages corrupted the Ajax response', Postman::TEXT_DOMAIN ), ) ); wp_localize_script( 'jquery_steps_script', 'steps_current_step', 'steps_current_step' ); wp_localize_script( 'jquery_steps_script', 'steps_pagination', 'steps_pagination' ); wp_localize_script( 'jquery_steps_script', 'steps_finish', _x( 'Finish', 'Press this button to Finish this task', Postman::TEXT_DOMAIN ) ); wp_localize_script( 'jquery_steps_script', 'steps_next', _x( 'Next', 'Press this button to go to the next step', Postman::TEXT_DOMAIN ) ); wp_localize_script( 'jquery_steps_script', 'steps_previous', _x( 'Previous', 'Press this button to go to the previous step', Postman::TEXT_DOMAIN ) ); wp_localize_script( 'jquery_steps_script', 'steps_loading', 'steps_loading' ); } /** * Options page callback */ public function outputDefaultContent() { // Set class property print '
'; $this->displayTopNavigation(); if ( ! PostmanPreRequisitesCheck::isReady() ) { printf( '

%s

', __( 'Postman is unable to run. Email delivery is being handled by WordPress (or another plugin).', Postman::TEXT_DOMAIN ) ); } else { $ready_messsage = PostmanTransportRegistry::getInstance()->getReadyMessage(); $statusMessage = $ready_messsage['message']; if ( PostmanTransportRegistry::getInstance()->getActiveTransport()->isConfiguredAndReady() ) { if ( $this->options->getRunMode() != PostmanOptions::RUN_MODE_PRODUCTION ) { printf( '

%s

', $statusMessage ); } else { printf( '

%s

', $statusMessage ); } } else { printf( '

%s

', $statusMessage ); } $this->printDeliveryDetails(); /* translators: where %d is the number of emails delivered */ print '

'; printf( _n( 'Postman has delivered %d email.', 'Postman has delivered %d emails.', PostmanState::getInstance()->getSuccessfulDeliveries(), Postman::TEXT_DOMAIN ), PostmanState::getInstance()->getSuccessfulDeliveries() ); if ( $this->options->isMailLoggingEnabled() ) { print ' '; printf( __( 'The last %d email attempts are recorded in the log.', Postman::TEXT_DOMAIN ), PostmanOptions::getInstance()->getMailLoggingMaxEntries(), PostmanUtils::getEmailLogPageUrl() ); } print '

'; } if ( $this->options->isNew() ) { printf( '

%s

', __( 'Thank-you for choosing Postman!', Postman::TEXT_DOMAIN ) ); /* translators: where %s is the URL of the Setup Wizard */ printf( '

%s

', sprintf( __( 'Let\'s get started! All users are strongly encouraged to run the Setup Wizard.', Postman::TEXT_DOMAIN ), $this->getPageUrl( PostmanConfigurationController::CONFIGURATION_WIZARD_SLUG ) ) ); printf( '

%s

', sprintf( __( 'Alternately, manually configure your own settings and/or modify advanced options.', Postman::TEXT_DOMAIN ), $this->getPageUrl( PostmanConfigurationController::CONFIGURATION_SLUG ) ) ); } else { if ( PostmanState::getInstance()->isTimeToReviewPostman() && ! PostmanOptions::getInstance()->isNew() ) { print '


'; /* translators: where %s is the URL to the WordPress.org review and ratings page */ printf( '%s

', sprintf( __( 'Please consider leaving a review to help spread the word! :D', Postman::TEXT_DOMAIN ), 'https://wordpress.org/support/view/plugin-reviews/post-smtp?filter=5' ) ); } printf( '

%s :-)

', sprintf( __( 'Postman needs translators! Please take a moment to translate a few sentences on-line', Postman::TEXT_DOMAIN ), 'https://translate.wordpress.org/projects/wp-plugins/post-smtp/stable' ) ); } printf( '

%s

', __( 'New for v1.7! Send mail with the Mandrill or SendGrid APIs.', Postman::TEXT_DOMAIN ) ); } /** */ private function printDeliveryDetails() { $currentTransport = PostmanTransportRegistry::getInstance()->getActiveTransport(); $deliveryDetails = $currentTransport->getDeliveryDetails( $this->options ); printf( '

%s

', $deliveryDetails ); } /** * * @param unknown $title * @param string $slug */ public static function outputChildPageHeader( $title, $slug = '' ) { printf( '

%s

', sprintf( __( '%s Setup', Postman::TEXT_DOMAIN ), __( 'Post SMTP', Postman::TEXT_DOMAIN ) ) ); printf( '
', $slug ); print '
'; print '
'; print '
'; printf( '

%s

', $title ); print '
'; printf( '

%s %s

', self::BACK_ARROW_SYMBOL, PostmanUtils::getSettingsPageUrl(), _x( 'Back To Main Menu', 'Return to main menu link', Postman::TEXT_DOMAIN ) ); print '
'; } /** */ public function outputPurgeDataContent() { $importTitle = __( 'Import', Postman::TEXT_DOMAIN ); $exportTile = __( 'Export', Postman::TEXT_DOMAIN ); $resetTitle = __( 'Reset Plugin', Postman::TEXT_DOMAIN ); $options = $this->options; print '
'; PostmanViewController::outputChildPageHeader( sprintf( '%s/%s/%s', $importTitle, $exportTile, $resetTitle ) ); print '
'; printf( '

%s

', $exportTile ); printf( '

%s

', __( 'Copy this data into another instance of Postman to duplicate the configuration.', Postman::TEXT_DOMAIN ) ); $data = ''; if ( ! PostmanPreRequisitesCheck::checkZlibEncode() ) { $extraDeleteButtonAttributes = sprintf( 'disabled="true"' ); $data = ''; } else { $extraDeleteButtonAttributes = ''; if ( ! $options->isNew() ) { $data = $options->export(); } } printf( '', $extraDeleteButtonAttributes, $data ); print '
'; print '
'; printf( '

%s

', $importTitle ); print '
'; wp_nonce_field( PostmanAdminController::IMPORT_SETTINGS_SLUG ); printf( '', PostmanAdminController::IMPORT_SETTINGS_SLUG ); print '

'; printf( '%s', __( 'Paste data from another instance of Postman here to duplicate the configuration.', Postman::TEXT_DOMAIN ) ); if ( PostmanTransportRegistry::getInstance()->getSelectedTransport()->isOAuthUsed( PostmanOptions::getInstance()->getAuthenticationType() ) ) { $warning = __( 'Warning', Postman::TEXT_DOMAIN ); $errorMessage = __( 'Using the same OAuth 2.0 Client ID and Client Secret from this site at the same time as another site will cause failures.', Postman::TEXT_DOMAIN ); printf( ' %s: %s', $warning, $errorMessage ); } print '

'; printf( '', $extraDeleteButtonAttributes ); submit_button( __( 'Import', Postman::TEXT_DOMAIN ), 'primary', 'import', true, $extraDeleteButtonAttributes ); print '
'; print '
'; print '
'; printf( '

%s

', $resetTitle ); print '
'; wp_nonce_field( PostmanAdminController::PURGE_DATA_SLUG ); printf( '', PostmanAdminController::PURGE_DATA_SLUG ); printf( '

%s

%s

', __( 'This will purge all of Postman\'s settings, including account credentials and the email log.', Postman::TEXT_DOMAIN ), __( 'Are you sure?', Postman::TEXT_DOMAIN ) ); $extraDeleteButtonAttributes = 'style="background-color:red;color:white"'; if ( $this->options->isNew() ) { $extraDeleteButtonAttributes .= ' disabled="true"'; } submit_button( $resetTitle, 'delete', 'submit', true, $extraDeleteButtonAttributes ); print '
'; print '
'; print '
'; } /** */ private function displayTopNavigation() { $version = PostmanState::getInstance()->getVersion(); $show = get_option('postman_release_version_'. $version ); printf( '

%s

', sprintf( __( '%s Setup', Postman::TEXT_DOMAIN ), __( 'Post SMTP', Postman::TEXT_DOMAIN ) ) ); if ( ! $show ) { echo '

Version ' . $version . ' Mailgun Europe region support: Read Here

'; } print '
'; print '
'; print '
'; print '
'; printf( '

%s

', __( 'Configuration', Postman::TEXT_DOMAIN ) ); printf( '%s', $this->getPageUrl( PostmanConfigurationController::CONFIGURATION_WIZARD_SLUG ), __( 'Start the Wizard', Postman::TEXT_DOMAIN ) ); printf( '

%s %s

', __( 'or', Postman::TEXT_DOMAIN ), $this->getPageUrl( PostmanConfigurationController::CONFIGURATION_SLUG ), __( 'Show All Settings', Postman::TEXT_DOMAIN ) ); print '
'; print '
'; printf( '

%s

', _x( 'Actions', 'Main Menu', Postman::TEXT_DOMAIN ) ); print '
    '; // Grant permission with Google PostmanTransportRegistry::getInstance()->getSelectedTransport()->printActionMenuItem(); if ( PostmanWpMailBinder::getInstance()->isBound() ) { printf( '
  • %s
  • ', $this->getPageUrl( PostmanSendTestEmailController::EMAIL_TEST_SLUG ), __( 'Send a Test Email', Postman::TEXT_DOMAIN ) ); } else { printf( '
  • %s
  • ', __( 'Send a Test Email', Postman::TEXT_DOMAIN ) ); } // import-export-reset menu item if ( ! $this->options->isNew() || true ) { $purgeLinkPattern = '
  • %2$s
  • '; } else { $purgeLinkPattern = '
  • %2$s
  • '; } $importTitle = __( 'Import', Postman::TEXT_DOMAIN ); $exportTile = __( 'Export', Postman::TEXT_DOMAIN ); $resetTitle = __( 'Reset Plugin', Postman::TEXT_DOMAIN ); $importExportReset = sprintf( '%s/%s/%s', $importTitle, $exportTile, $resetTitle ); printf( $purgeLinkPattern, $this->getPageUrl( PostmanAdminController::MANAGE_OPTIONS_PAGE_SLUG ), sprintf( '%s', $importExportReset ) ); print '
'; print '
'; print '
'; printf( '

%s

', _x( 'Troubleshooting', 'Main Menu', Postman::TEXT_DOMAIN ) ); print '
    '; printf( '
  • %s
  • ', $this->getPageUrl( PostmanConnectivityTestController::PORT_TEST_SLUG ), __( 'Connectivity Test', Postman::TEXT_DOMAIN ) ); printf( '
  • %s
  • ', $this->getPageUrl( PostmanDiagnosticTestController::DIAGNOSTICS_SLUG ), __( 'Diagnostic Test', Postman::TEXT_DOMAIN ) ); printf( '
  • %s
  • ', '#', wp_create_nonce( "postman" ), __( 'Release Lock File Error', Postman::TEXT_DOMAIN ) ); printf( '
  • %s
  • ', __( 'Online Support', Postman::TEXT_DOMAIN ) ); printf( '
  • %s
  • ', __( 'Guides', Postman::TEXT_DOMAIN ) ); print '
'; } } }