/**
  */
 public function outputDiagnosticsContent()
 {
     // test features
     print '<div class="wrap">';
     PostmanViewController::outputChildPageHeader(__('Diagnostic Test', Postman::TEXT_DOMAIN));
     printf('<h4>%s</h4>', __('Are you having issues with Postman?', Postman::TEXT_DOMAIN));
     /* translators: where %1$s and %2$s are the URLs to the Troubleshooting and Support Forums on WordPress.org */
     printf('<p style="margin:0 10px">%s</p>', sprintf(__('Please check the <a href="%1$s">troubleshooting and error messages</a> page and the <a href="%2$s">support forum</a>.', Postman::TEXT_DOMAIN), 'https://wordpress.org/plugins/postman-smtp/other_notes/', 'https://wordpress.org/support/plugin/postman-smtp'));
     printf('<h4>%s</h4>', __('Diagnostic Test', Postman::TEXT_DOMAIN));
     printf('<p style="margin:0 10px">%s</p><br/>', sprintf(__('If you write for help, please include the following:', Postman::TEXT_DOMAIN), 'https://wordpress.org/plugins/postman-smtp/other_notes/', 'https://wordpress.org/support/plugin/postman-smtp'));
     printf('<textarea readonly="readonly" id="diagnostic-text" cols="80" rows="15">%s</textarea>', _x('Checking..', 'The "please wait" message', Postman::TEXT_DOMAIN));
     print '</div>';
 }
 /**
  * This Ajax function retrieves the OAuth redirectUrl and help text for based on the SMTP hostname supplied
  */
 function getWizardConfigurationViaAjax()
 {
     $this->logger->debug('in getWizardConfiguration');
     $originalSmtpServer = $this->getRequestParameter('original_smtp_server');
     $queryHostData = $this->getHostDataFromRequest();
     $userPortOverride = $this->getUserPortOverride();
     $userAuthOverride = $this->getUserAuthOverride();
     // determine a configuration recommendation
     $winningRecommendation = $this->getWinningRecommendation($queryHostData, $userPortOverride, $userAuthOverride, $originalSmtpServer);
     $this->logger->trace('winning recommendation:');
     $this->logger->trace($winningRecommendation);
     // create user override menu
     $overrideMenu = $this->createOverrideMenu($queryHostData, $winningRecommendation, $userPortOverride, $userAuthOverride);
     $this->logger->trace('override menu:');
     $this->logger->trace($overrideMenu);
     // create the reponse
     $response = array();
     $configuration = array();
     $response['referer'] = 'wizard';
     if (isset($userPortOverride) || isset($userAuthOverride)) {
         $configuration['user_override'] = true;
     }
     if (isset($winningRecommendation)) {
         // create an appropriate (theoretical) transport
         $transport = PostmanTransportRegistry::getInstance()->getTransport($winningRecommendation['transport']);
         $scribe = PostmanConfigTextHelperFactory::createScribe($winningRecommendation['hostname'], $transport);
         $this->populateResponseFromScribe($scribe, $configuration);
         $this->populateResponseFromTransport($winningRecommendation, $configuration);
         $response['override_menu'] = $overrideMenu;
         $response['configuration'] = $configuration;
         $this->logger->trace('configuration:');
         $this->logger->trace($configuration);
         wp_send_json_success($response);
     } else {
         /* translators: where %s is the URL to the Connectivity Test page */
         $configuration['message'] = sprintf(__('Postman can\'t find any way to send mail on your system. Run a <a href="%s">connectivity test</a>.', 'postman-smtp'), PostmanViewController::getPageUrl(PostmanViewController::PORT_TEST_SLUG));
         $response['configuration'] = $configuration;
         $this->logger->trace('configuration:');
         $this->logger->trace($configuration);
         wp_send_json_error($response);
     }
 }
 /**
  */
 public function outputPortTestContent()
 {
     print '<div class="wrap">';
     PostmanViewController::outputChildPageHeader(__('Connectivity Test', Postman::TEXT_DOMAIN));
     print '<p>';
     print __('This test determines which well-known ports are available for Postman to use.', Postman::TEXT_DOMAIN);
     print '<form id="port_test_form_id" method="post">';
     printf('<label for="hostname">%s</label>', __('Outgoing Mail Server Hostname', Postman::TEXT_DOMAIN));
     $this->port_test_hostname_callback();
     submit_button(_x('Begin Test', 'Button Label', Postman::TEXT_DOMAIN), 'primary', 'begin-port-test', true);
     print '</form>';
     print '<table id="connectivity_test_table">';
     print sprintf('<tr><th rowspan="2">%s</th><th rowspan="2">%s</th><th rowspan="2">%s</th><th rowspan="2">%s</th><th rowspan="2">%s</th><th colspan="5">%s</th></tr>', __('Transport', Postman::TEXT_DOMAIN), _x('Socket', 'A socket is the network term for host and port together', Postman::TEXT_DOMAIN), __('Status', Postman::TEXT_DOMAIN) . '<sup>*</sup>', __('Service Available', Postman::TEXT_DOMAIN), __('Server ID', Postman::TEXT_DOMAIN), __('Authentication', Postman::TEXT_DOMAIN));
     print sprintf('<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>', 'None', 'Login', 'Plain', 'CRAM-MD5', 'OAuth 2.0');
     $sockets = PostmanTransportRegistry::getInstance()->getSocketsForSetupWizardToProbe();
     foreach ($sockets as $socket) {
         if ($socket['smtp']) {
             print sprintf('<tr id="%s"><th class="name">%s</th><td class="socket">%s:%s</td><td class="firewall resettable">-</td><td class="service resettable">-</td><td class="reported_id resettable">-</td><td class="auth_none resettable">-</td><td class="auth_login resettable">-</td><td class="auth_plain resettable">-</td><td class="auth_crammd5 resettable">-</td><td class="auth_xoauth2 resettable">-</td></tr>', $socket['id'], $socket['transport_name'], $socket['host'], $socket['port']);
         } else {
             print sprintf('<tr id="%s"><th class="name">%s</th><td class="socket">%s:%s</td><td class="firewall resettable">-</td><td class="service resettable">-</td><td class="reported_id resettable">-</td><td colspan="5">%s</td></tr>', $socket['id'], $socket['transport_name'], $socket['host'], $socket['port'], __('n/a', Postman::TEXT_DOMAIN));
         }
     }
     print '</table>';
     /* Translators: Where %s is the name of the service providing Internet connectivity test */
     printf('<p class="portquiz" style="display:none; font-size:0.8em">* %s</p>', sprintf(__('According to %s', Postman::TEXT_DOMAIN), '<a target="_new" href="http://ww.downor.me/portquiz.net">portquiz.net</a>'));
     printf('<p class="ajax-loader" style="display:none"><img src="%s"/></p>', plugins_url('postman-smtp/style/ajax-loader.gif'));
     print '<section id="conclusion" style="display:none">';
     print sprintf('<h3>%s:</h3>', __('Summary', Postman::TEXT_DOMAIN));
     print '<ol class="conclusion">';
     print '</ol>';
     print '</section>';
     print '<section id="blocked-port-help" style="display:none">';
     print sprintf('<p><b>%s</b></p>', __('A test with <span style="color:red">"No"</span> Service Available indicates one or more of these issues:', Postman::TEXT_DOMAIN));
     print '<ol>';
     printf('<li>%s</li>', __('Your web host has placed a firewall between this site and the Internet', Postman::TEXT_DOMAIN));
     printf('<li>%s</li>', __('The SMTP hostname is wrong or the mail server does not provide service on this port', Postman::TEXT_DOMAIN));
     /* translators: where (1) is the URL and (2) is the system */
     $systemBlockMessage = __('Your <a href="%1$s">%2$s configuration</a> is preventing outbound connections', Postman::TEXT_DOMAIN);
     printf('<li>%s</li>', sprintf($systemBlockMessage, 'http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen', 'PHP'));
     printf('<li>%s</li>', sprintf($systemBlockMessage, 'http://wp-mix.com/disable-external-url-requests/', 'WordPress'));
     print '</ol></p>';
     print sprintf('<p><b>%s</b></p>', __('If the issues above can not be resolved, your last option is to configure Postman to use an email account managed by your web host with an SMTP server managed by your web host.', Postman::TEXT_DOMAIN));
     print '</section>';
     print '</div>';
 }
 /**
  * Once the Port Tests have run, the results are analyzed.
  * The Transport place bids on the sockets and highest bid becomes the recommended
  * The UI response is built so the user may choose a different socket with different options.
  */
 function getWizardConfigurationViaAjax()
 {
     $this->logger->debug('in getWizardConfiguration');
     $originalSmtpServer = $this->getRequestParameter('original_smtp_server');
     $queryHostData = $this->getHostDataFromRequest();
     $sockets = array();
     foreach ($queryHostData as $id => $datum) {
         array_push($sockets, new PostmanWizardSocket($datum));
     }
     $this->logger->error($sockets);
     $userPortOverride = $this->getUserPortOverride();
     $userAuthOverride = $this->getUserAuthOverride();
     // determine a configuration recommendation
     $winningRecommendation = $this->getWinningRecommendation($sockets, $userPortOverride, $userAuthOverride, $originalSmtpServer);
     if ($this->logger->isTrace()) {
         $this->logger->trace('winning recommendation:');
         $this->logger->trace($winningRecommendation);
     }
     // create the reponse
     $response = array();
     $configuration = array();
     $response['referer'] = 'wizard';
     if (isset($userPortOverride) || isset($userAuthOverride)) {
         $configuration['user_override'] = true;
     }
     if (isset($winningRecommendation)) {
         // create an appropriate (theoretical) transport
         $transport = PostmanTransportRegistry::getInstance()->getTransport($winningRecommendation['transport']);
         // create user override menu
         $overrideMenu = $this->createOverrideMenus($sockets, $winningRecommendation, $userPortOverride, $userAuthOverride);
         if ($this->logger->isTrace()) {
             $this->logger->trace('override menu:');
             $this->logger->trace($overrideMenu);
         }
         $queryHostName = $winningRecommendation['hostname'];
         if ($this->logger->isDebug()) {
             $this->logger->debug('Getting scribe for ' . $queryHostName);
         }
         $generalConfig1 = $transport->populateConfiguration($queryHostName);
         $generalConfig2 = $transport->populateConfigurationFromRecommendation($winningRecommendation);
         $configuration = array_merge($configuration, $generalConfig1, $generalConfig2);
         $response['override_menu'] = $overrideMenu;
         $response['configuration'] = $configuration;
         if ($this->logger->isTrace()) {
             $this->logger->trace('configuration:');
             $this->logger->trace($configuration);
             $this->logger->trace('response:');
             $this->logger->trace($response);
         }
         wp_send_json_success($response);
     } else {
         /* translators: where %s is the URL to the Connectivity Test page */
         $configuration['message'] = sprintf(__('Postman can\'t find any way to send mail on your system. Run a <a href="%s">connectivity test</a>.', Postman::TEXT_DOMAIN), PostmanViewController::getPageUrl(PostmanViewController::PORT_TEST_SLUG));
         $response['configuration'] = $configuration;
         if ($this->logger->isTrace()) {
             $this->logger->trace('configuration:');
             $this->logger->trace($configuration);
         }
         wp_send_json_error($response);
     }
 }
 /**
  */
 public function outputPurgeDataContent()
 {
     $importTitle = __('Import', Postman::TEXT_DOMAIN);
     $exportTile = __('Export', Postman::TEXT_DOMAIN);
     $resetTitle = __('Reset Plugin', Postman::TEXT_DOMAIN);
     $options = $this->options;
     print '<div class="wrap">';
     PostmanViewController::outputChildPageHeader(sprintf('%s/%s/%s', $importTitle, $exportTile, $resetTitle));
     print '<section id="export_settings">';
     printf('<h3><span>%s<span></h3>', $exportTile);
     printf('<p><span>%s</span></p>', __('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('<textarea cols="80" rows="5" readonly="true" name="settings" %s>%s</textarea>', $extraDeleteButtonAttributes, $data);
     print '</section>';
     print '<section id="import_settings">';
     printf('<h3><span>%s<span></h3>', $importTitle);
     print '<form method="POST" action="' . get_admin_url() . 'admin-post.php">';
     wp_nonce_field(PostmanAdminController::IMPORT_SETTINGS_SLUG);
     printf('<input type="hidden" name="action" value="%s" />', PostmanAdminController::IMPORT_SETTINGS_SLUG);
     print '<p>';
     printf('<span>%s</span>', __('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(' <span><b>%s</b>: %s</span>', $warning, $errorMessage);
     }
     print '</p>';
     printf('<textarea cols="80" rows="5" name="settings" %s></textarea>', $extraDeleteButtonAttributes);
     submit_button(__('Import', Postman::TEXT_DOMAIN), 'primary', 'import', true, $extraDeleteButtonAttributes);
     print '</form>';
     print '</section>';
     print '<section id="delete_settings">';
     printf('<h3><span>%s<span></h3>', $resetTitle);
     print '<form method="POST" action="' . get_admin_url() . 'admin-post.php">';
     wp_nonce_field(PostmanAdminController::PURGE_DATA_SLUG);
     printf('<input type="hidden" name="action" value="%s" />', PostmanAdminController::PURGE_DATA_SLUG);
     printf('<p><span>%s</span></p><p><span>%s</span></p>', __('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 '</form>';
     print '</section>';
     print '</div>';
 }
 /**
  */
 public function outputTestEmailContent()
 {
     print '<div class="wrap">';
     PostmanViewController::outputChildPageHeader(__('Send a Test Email', Postman::TEXT_DOMAIN));
     printf('<form id="postman_test_email_wizard" method="post" action="%s">', PostmanUtils::getSettingsPageUrl());
     // Step 1
     printf('<h5>%s</h5>', __('Specify the Recipient', Postman::TEXT_DOMAIN));
     print '<fieldset>';
     printf('<legend>%s</legend>', __('Who is this message going to?', Postman::TEXT_DOMAIN));
     printf('<p>%s', __('This utility allows you to send an email message for testing.', Postman::TEXT_DOMAIN));
     print ' ';
     /* translators: where %d is an amount of time, in seconds */
     printf('%s</p>', sprintf(_n('If there is a problem, Postman will give up after %d second.', 'If there is a problem, Postman will give up after %d seconds.', $this->options->getReadTimeout(), Postman::TEXT_DOMAIN), $this->options->getReadTimeout()));
     printf('<label for="postman_test_options[test_email]">%s</label>', _x('Recipient Email Address', 'Configuration Input Field', Postman::TEXT_DOMAIN));
     print $this->test_email_callback();
     print '</fieldset>';
     // Step 2
     printf('<h5>%s</h5>', __('Send The Message', Postman::TEXT_DOMAIN));
     print '<fieldset>';
     print '<legend>';
     print __('Sending the message:', Postman::TEXT_DOMAIN);
     printf(' <span id="postman_test_message_status">%s</span>', _x('In Outbox', 'Email Test Status', Postman::TEXT_DOMAIN));
     print '</legend>';
     print '<section>';
     printf('<p><label>%s</label></p>', __('Status', Postman::TEXT_DOMAIN));
     print '<textarea id="postman_test_message_error_message" readonly="readonly" cols="65" rows="4"></textarea>';
     print '</section>';
     print '</fieldset>';
     // Step 3
     printf('<h5>%s</h5>', __('Session Transcript', Postman::TEXT_DOMAIN));
     print '<fieldset>';
     printf('<legend>%s</legend>', __('Examine the Session Transcript if you need to.', Postman::TEXT_DOMAIN));
     printf('<p>%s</p>', __('This is the conversation between Postman and the mail server. It can be useful for diagnosing problems. <b>DO NOT</b> post it on-line, it may contain your account password.', Postman::TEXT_DOMAIN));
     print '<section>';
     printf('<p><label for="postman_test_message_transcript">%s</label></p>', __('Session Transcript', Postman::TEXT_DOMAIN));
     print '<textarea readonly="readonly" id="postman_test_message_transcript" cols="65" rows="8"></textarea>';
     print '</section>';
     print '</fieldset>';
     print '</form>';
     print '</div>';
 }