diff options
author | yehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664> | 2017-10-15 06:46:12 +0000 |
---|---|---|
committer | yehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664> | 2017-10-15 06:46:12 +0000 |
commit | ca6c8f41c1a2b9a4b5acae91419a6a114e1c77c6 (patch) | |
tree | 40ff112761d82af1d8c1c89d30ede8206502e17b /Postman/Postman-Controller | |
parent | 8812fbf61bde539d1599e239044595ccb8a2c3a5 (diff) | |
download | Post-SMTP-ca6c8f41c1a2b9a4b5acae91419a6a114e1c77c6.zip |
release
Diffstat (limited to 'Postman/Postman-Controller')
3 files changed, 319 insertions, 0 deletions
diff --git a/Postman/Postman-Controller/PostmanAdminPointer.php b/Postman/Postman-Controller/PostmanAdminPointer.php new file mode 100644 index 0000000..16bd6a2 --- /dev/null +++ b/Postman/Postman-Controller/PostmanAdminPointer.php @@ -0,0 +1,107 @@ +<?php +if (! class_exists ( 'PostmanAdminPointer' )) { + + /** + * From http://code.tutsplus.com/articles/integrating-with-wordpress-ui-admin-pointers--wp-26853 + * + * @author jasonhendriks + * + */ + class PostmanAdminPointer { + private $logger; + private $rootPluginFilenameAndPath; + + /** + * + * @param unknown $rootPluginFilenameAndPath + */ + function __construct($rootPluginFilenameAndPath) { + $this->logger = new PostmanLogger ( get_class ( $this ) ); + $this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath; + + // Don't run on WP < 3.3 + if (get_bloginfo ( 'version' ) < '3.3' || true) + return; + + add_action ( 'admin_enqueue_scripts', array ( + $this, + 'wptuts_pointer_load' + ), 1000 ); + add_filter ( 'postman_admin_pointers-settings_page_postman', array ( + $this, + 'wptuts_register_pointer_testing' + ) ); + } + + /** + * + * @param unknown $hook_suffix + */ + function wptuts_pointer_load($hook_suffix) { + // only do this for administrators + if (PostmanUtils::isAdmin ()) { + $this->logger->trace ( 'wptuts' ); + + $screen = get_current_screen (); + $screen_id = $screen->id; + + // Get pointers for this screen + $pointers = apply_filters ( 'postman_admin_pointers-' . $screen_id, array () ); + + if (! $pointers || ! is_array ( $pointers )) + return; + + // Get dismissed pointers + $dismissed = explode ( ',', ( string ) get_user_meta ( get_current_user_id (), 'dismissed_wp_pointers', true ) ); + $this->logger->trace ( $dismissed ); + $valid_pointers = array (); + + // Check pointers and remove dismissed ones. + foreach ( $pointers as $pointer_id => $pointer ) { + + // Sanity check + if (in_array ( $pointer_id, $dismissed ) || empty ( $pointer ) || empty ( $pointer_id ) || empty ( $pointer ['target'] ) || empty ( $pointer ['options'] )) + continue; + + $pointer ['pointer_id'] = $pointer_id; + + // Add the pointer to $valid_pointers array + $valid_pointers ['pointers'] [] = $pointer; + } + + // No valid pointers? Stop here. + if (empty ( $valid_pointers )) { + return; + } + + // Add pointers style to queue. + wp_enqueue_style ( 'wp-pointer' ); + + // Add pointers script to queue. Add custom script. + wp_enqueue_script ( 'postman_admin_pointer', plugins_url ( 'script/postman-admin-pointer.js', $this->rootPluginFilenameAndPath ), array ( + 'wp-pointer' + ) ); + + // Add pointer options to script. + wp_localize_script ( 'postman_admin_pointer', 'postman_admin_pointer', $valid_pointers ); + $this->logger->trace ( 'out wptuts' ); + } + } + function wptuts_register_pointer_testing($p) { + // only do this for administrators + if (PostmanUtils::isAdmin () && false) { + $p ['postman16_log'] = array ( + 'target' => '.configure_manually', + 'options' => array ( + 'content' => '', + 'position' => array ( + 'edge' => 'top', + 'align' => 'left' + ) + ) + ); + return $p; + } + } + } +} diff --git a/Postman/Postman-Controller/PostmanDashboardWidgetController.php b/Postman/Postman-Controller/PostmanDashboardWidgetController.php new file mode 100644 index 0000000..7393ee3 --- /dev/null +++ b/Postman/Postman-Controller/PostmanDashboardWidgetController.php @@ -0,0 +1,157 @@ +<?php +if (! class_exists ( "PostmanDashboardWidgetController" )) { + + // + class PostmanDashboardWidgetController { + private $rootPluginFilenameAndPath; + private $options; + private $authorizationToken; + private $wpMailBinder; + + /** + * Start up + */ + public function __construct($rootPluginFilenameAndPath, PostmanOptions $options, PostmanOAuthToken $authorizationToken, PostmanWpMailBinder $binder) { + assert ( ! empty ( $rootPluginFilenameAndPath ) ); + assert ( ! empty ( $options ) ); + assert ( ! empty ( $authorizationToken ) ); + assert ( ! empty ( $binder ) ); + $this->rootPluginFilenameAndPath = $rootPluginFilenameAndPath; + $this->options = $options; + $this->authorizationToken = $authorizationToken; + $this->wpMailBinder = $binder; + + add_action ( 'wp_dashboard_setup', array ( + $this, + 'addDashboardWidget' + ) ); + + add_action ( 'wp_network_dashboard_setup', array ( + $this, + 'addNetworkDashboardWidget' + ) ); + + // dashboard glance mod + if ($this->options->isMailLoggingEnabled ()) { + add_filter ( 'dashboard_glance_items', array ( + $this, + 'customizeAtAGlanceDashboardWidget' + ), 10, 1 ); + } + + // Postman API: register the human-readable plugin state + add_filter ( 'print_postman_status', array ( + $this, + 'print_postman_status' + ) ); + } + + /** + * Add a widget to the dashboard. + * + * This function is hooked into the 'wp_dashboard_setup' action below. + */ + public function addDashboardWidget() { + // only display to the widget to administrator + if (PostmanUtils::isAdmin ()) { + wp_add_dashboard_widget ( 'example_dashboard_widget', __ ( 'Postman SMTP', Postman::TEXT_DOMAIN ), array ( + $this, + 'printDashboardWidget' + ) ); // Display function. + } + } + + /** + * Add a widget to the network dashboard + */ + public function addNetworkDashboardWidget() { + // only display to the widget to administrator + if (PostmanUtils::isAdmin ()) { + wp_add_dashboard_widget ( 'example_dashboard_widget', __ ( 'Postman SMTP', Postman::TEXT_DOMAIN ), array ( + $this, + 'printNetworkDashboardWidget' + ) ); // Display function. + } + } + + /** + * Create the function to output the contents of our Dashboard Widget. + */ + public function printDashboardWidget() { + $goToSettings = sprintf ( '<a href="%s">%s</a>', PostmanUtils::getSettingsPageUrl (), __ ( 'Settings', Postman::TEXT_DOMAIN ) ); + $goToEmailLog = sprintf ( '%s', _x ( 'Email Log', 'The log of Emails that have been delivered', Postman::TEXT_DOMAIN ) ); + if ($this->options->isMailLoggingEnabled ()) { + $goToEmailLog = sprintf ( '<a href="%s">%s</a>', PostmanUtils::getEmailLogPageUrl (), $goToEmailLog ); + } + apply_filters ( 'print_postman_status', null ); + printf ( '<p>%s | %s</p>', $goToEmailLog, $goToSettings ); + } + + /** + * Print the human-readable plugin state + */ + public function print_postman_status() { + if (! PostmanPreRequisitesCheck::isReady ()) { + printf ( '<p><span style="color:red">%s</span></p>', __ ( 'Error: Postman is missing a required PHP library.', Postman::TEXT_DOMAIN ) ); + } else if ($this->wpMailBinder->isUnboundDueToException ()) { + printf ( '<p><span style="color:red">%s</span></p>', __ ( 'Postman: wp_mail has been declared by another plugin or theme, so you won\'t be able to use Postman until the conflict is resolved.', Postman::TEXT_DOMAIN ) ); + } else { + if ($this->options->getRunMode () != PostmanOptions::RUN_MODE_PRODUCTION) { + printf ( '<p><span style="background-color:yellow">%s</span></p>', __ ( 'Postman is in <em>non-Production</em> mode and is dumping all emails.', Postman::TEXT_DOMAIN ) ); + } else if (PostmanTransportRegistry::getInstance ()->getSelectedTransport ()->isConfiguredAndReady ()) { + printf ( '<p class="wp-menu-image dashicons-before dashicons-email"> %s </p>', sprintf ( _n ( '<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> email.', '<span style="color:green">Postman is configured</span> and has delivered <span style="color:green">%d</span> emails.', PostmanState::getInstance ()->getSuccessfulDeliveries (), Postman::TEXT_DOMAIN ), PostmanState::getInstance ()->getSuccessfulDeliveries () ) ); + } else { + printf ( '<p><span style="color:red">%s</span></p>', __ ( 'Postman is <em>not</em> configured and is mimicking out-of-the-box WordPress email delivery.', Postman::TEXT_DOMAIN ) ); + } + $currentTransport = PostmanTransportRegistry::getInstance ()->getActiveTransport (); + $deliveryDetails = $currentTransport->getDeliveryDetails ( $this->options ); + printf ( '<p>%s</p>', $deliveryDetails ); + } + } + + /** + * Create the function to output the contents of our Dashboard Widget. + */ + public function printNetworkDashboardWidget() { + printf ( '<p class="wp-menu-image dashicons-before dashicons-email"> %s</p>', __ ( 'Postman is operating in per-site mode.', Postman::TEXT_DOMAIN ) ); + } + + /** + * From http://www.hughlashbrooke.com/2014/02/wordpress-add-items-glance-widget/ + * http://coffeecupweb.com/how-to-add-custom-post-types-to-at-a-glance-dashboard-widget-in-wordpress/ + * + * @param unknown $items + * @return string + */ + function customizeAtAGlanceDashboardWidget($items = array()) { + // only modify the At-a-Glance for administrators + if (PostmanUtils::isAdmin ()) { + $post_types = array ( + PostmanEmailLogPostType::POSTMAN_CUSTOM_POST_TYPE_SLUG + ); + + foreach ( $post_types as $type ) { + + if (! post_type_exists ( $type )) + continue; + + $num_posts = wp_count_posts ( $type ); + + if ($num_posts) { + + $published = intval ( $num_posts->publish ); + $privated = intval ( $num_posts->private ); + $post_type = get_post_type_object ( $type ); + + $text = _n ( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $privated, Postman::TEXT_DOMAIN ); + $text = sprintf ( $text, number_format_i18n ( $privated ) ); + + $items [] = sprintf ( '<a class="%1$s-count" href="%3$s">%2$s</a>', $type, $text, PostmanUtils::getEmailLogPageUrl () ) . "\n"; + } + } + + return $items; + } + } + } +}
\ No newline at end of file diff --git a/Postman/Postman-Controller/PostmanManageConfigurationAjaxHandler.php b/Postman/Postman-Controller/PostmanManageConfigurationAjaxHandler.php new file mode 100644 index 0000000..2c05b3a --- /dev/null +++ b/Postman/Postman-Controller/PostmanManageConfigurationAjaxHandler.php @@ -0,0 +1,55 @@ +<?php +class PostmanWizardSocket { + + // these variables are populated by the Port Test + public $hostname; + public $hostnameDomainOnly; + public $port; + public $protocol; + public $secure; + public $mitm; + public $reportedHostname; + public $reportedHostnameDomainOnly; + public $message; + public $startTls; + public $authPlain; + public $auth_login; + public $auth_crammd5; + public $auth_xoauth; + public $auth_none; + public $try_smtps; + public $success; + public $transport; + + // these variables are populated by The Transport Recommenders + public $label; + public $id; + + /** + * + * @param unknown $queryHostData + */ + function __construct($queryHostData) { + $this->hostname = $queryHostData ['hostname']; + $this->hostnameDomainOnly = $queryHostData ['hostname_domain_only']; + $this->port = $queryHostData ['port']; + $this->protocol = $queryHostData ['protocol']; + $this->secure = PostmanUtils::parseBoolean ( $queryHostData ['secure'] ); + $this->mitm = PostmanUtils::parseBoolean ( $queryHostData ['mitm'] ); + $this->reportedHostname = $queryHostData ['reported_hostname']; + $this->reportedHostnameDomainOnly = $queryHostData ['reported_hostname_domain_only']; + $this->message = $queryHostData ['message']; + $this->startTls = PostmanUtils::parseBoolean ( $queryHostData ['start_tls'] ); + $this->authPlain = PostmanUtils::parseBoolean ( $queryHostData ['auth_plain'] ); + $this->auth_login = PostmanUtils::parseBoolean ( $queryHostData ['auth_login'] ); + $this->auth_crammd5 = PostmanUtils::parseBoolean ( $queryHostData ['auth_crammd5'] ); + $this->auth_xoauth = PostmanUtils::parseBoolean ( $queryHostData ['auth_xoauth'] ); + $this->auth_none = PostmanUtils::parseBoolean ( $queryHostData ['auth_none'] ); + $this->try_smtps = PostmanUtils::parseBoolean ( $queryHostData ['try_smtps'] ); + $this->success = PostmanUtils::parseBoolean ( $queryHostData ['success'] ); + $this->transport = $queryHostData ['transport']; + assert ( ! empty ( $this->transport ) ); + $this->id = sprintf ( '%s_%s', $this->hostname, $this->port ); + } +} + |