summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Hassine <yehuda@myinbox.in>2019-04-22 00:23:38 +0300
committerYehuda Hassine <yehuda@myinbox.in>2019-04-22 00:23:38 +0300
commit7781aa65cef32d8c8196979edb21ec4551e5b904 (patch)
tree2a7944400ede6a9a574a83ce89d010b26628fe02
parentdad9828e8c866e50d6e44aebd103f1ab97409a5b (diff)
downloadPost-SMTP-7781aa65cef32d8c8196979edb21ec4551e5b904.zip
better meta query,bugs, optimization
-rw-r--r--Postman/Postman-Email-Log/PostmanEmailLogController.php9
-rw-r--r--Postman/Postman-Email-Log/PostmanEmailLogView.php6
-rw-r--r--Postman/PostmanEmailLogs.php111
-rw-r--r--Postman/PostmanInstaller.php5
-rw-r--r--Postman/PostmanLogMeta.php76
-rw-r--r--Postman/PostmanUtils.php18
-rw-r--r--Postman/PostmanWpMail.php4
7 files changed, 126 insertions, 103 deletions
diff --git a/Postman/Postman-Email-Log/PostmanEmailLogController.php b/Postman/Postman-Email-Log/PostmanEmailLogController.php
index 530b3a5..f625a82 100644
--- a/Postman/Postman-Email-Log/PostmanEmailLogController.php
+++ b/Postman/Postman-Email-Log/PostmanEmailLogController.php
@@ -1,4 +1,5 @@
<?php
+require_once dirname(__DIR__) . '/PostmanEmailLogs.php';
require_once 'PostmanEmailLogService.php';
require_once 'PostmanEmailLogView.php';
@@ -78,7 +79,7 @@ class PostmanEmailLogController {
$postid = $this->getRequestParameter( 'email' );
if ( ! empty( $postid ) ) {
$post = get_post( $postid );
- $meta_values = get_post_meta( $postid );
+ $meta_values = PostmanEmailLogs::get_data( $postid );
if ( isset( $_POST['mail_to'] ) && ! empty( $_POST['mail_to'] ) ) {
$emails = explode( ',', $_POST['mail_to'] );
@@ -87,7 +88,7 @@ class PostmanEmailLogController {
$to = $meta_values ['original_to'] [0];
}
- $success = wp_mail( $to, $meta_values ['original_subject'] [0], $meta_values ['original_message'] [0], $meta_values ['original_headers'] [0] );
+ $success = wp_mail( $to, $meta_values ['original_subject'] [0], maybe_unserialize( $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 );
@@ -202,7 +203,7 @@ class PostmanEmailLogController {
$this->logger->trace( 'handling view item' );
$postid = $_REQUEST ['email'];
$post = get_post( $postid );
- $meta_values = get_post_meta( $postid );
+ $meta_values = PostmanEmailLogs::get_data( $postid );
// https://css-tricks.com/examples/hrs/
print '<html><head><style>body {font-family: monospace;} hr {
border: 0;
@@ -260,7 +261,7 @@ class PostmanEmailLogController {
$this->logger->trace( 'handling view transcript item' );
$postid = $_REQUEST ['email'];
$post = get_post( $postid );
- $meta_values = get_post_meta( $postid );
+ $meta_values = PostmanEmailLogs::get_data( $postid );
// https://css-tricks.com/examples/hrs/
print '<html><head><style>body {font-family: monospace;} hr {
border: 0;
diff --git a/Postman/Postman-Email-Log/PostmanEmailLogView.php b/Postman/Postman-Email-Log/PostmanEmailLogView.php
index 2f41bcf..a9722bd 100644
--- a/Postman/Postman-Email-Log/PostmanEmailLogView.php
+++ b/Postman/Postman-Email-Log/PostmanEmailLogView.php
@@ -1,5 +1,7 @@
<?php
+require_once dirname(__DIR__) . '/PostmanEmailLogs.php';
+
/**
* See http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/
*/
@@ -92,7 +94,7 @@ class PostmanEmailLogView extends WP_List_Table {
$transcriptUrl = admin_url( sprintf( $iframeUri, 'transcript', $item ['ID'] ) );
$resendUrl = admin_url( sprintf( $iframeUri, 'resend', $item ['ID'] ) );
- $meta_values = get_post_meta( $item ['ID'] );
+ $meta_values = PostmanEmailLogs::get_data( $item ['ID'] );
$actions = array(
'delete' => sprintf( '<a href="%s">%s</a>', $deleteUrl, _x( 'Delete', 'Delete an item from the email log', 'post-smtp' ) ),
@@ -365,7 +367,7 @@ class PostmanEmailLogView extends WP_List_Table {
/* Translators: where %s indicates the relative time from now */
$date = sprintf( _x( '%s ago', 'A relative time as in "five days ago"', 'post-smtp' ), $humanTime );
}
- $meta_values = get_post_meta( $post->ID );
+ $meta_values = PostmanEmailLogs::get_data( $post->ID );
$sent_to = array_map( 'sanitize_email', explode( ',' , $meta_values ['to_header'] [0] ) );
$flattenedPost = array(
// the post title must be escaped as they are displayed in the HTML output
diff --git a/Postman/PostmanEmailLogs.php b/Postman/PostmanEmailLogs.php
new file mode 100644
index 0000000..c7b6175
--- /dev/null
+++ b/Postman/PostmanEmailLogs.php
@@ -0,0 +1,111 @@
+<?php
+
+class PostmanEmailLogs {
+
+ private $db;
+
+ public $db_name = 'post_smtp_logs';
+
+ private static $fields = array(
+ 'success',
+ 'from_header',
+ 'to_header',
+ 'cc_header',
+ 'bcc_header',
+ 'reply_to_header',
+ 'transport_uri',
+ 'original_to',
+ 'original_subject',
+ 'original_message',
+ 'original_headers',
+ 'session_transcript'
+ );
+
+ private static $instance;
+
+ public static function get_instance() {
+ if ( ! self::$instance ) {
+ self::$instanc = new static();
+ }
+
+ return self::$instance;
+ }
+
+ private function __construct() {
+ global $wpdb;
+
+ $this->db = $wpdb;
+ }
+
+ function install_table() {
+
+ global $wpdb;
+
+ $sql = "CREATE TABLE `{$wpdb->prefix}_{$this->db_name}` (

+ `id` bigint(20) NOT NULL AUTO_INCREMENT,
";
+
+ foreach ($this->fields as $field ) {
+ if ( $field == 'original_message' || $field == 'session_transcript' ) {
+ $sql .= "`" . $field . "` longtext DEFAULT NULL,";
+ continue;
+ }
+ $sql .= "`" . $field . "` varchar(255) DEFAULT NULL,";
+ }
+ $sql .= "PRIMARY KEY (`id`)) ENGINE=InnoDB CHARSET={$wpdb->charset} COLLATE={$wpdb->collate};
";
+
+ dbDelta( $sql );
+ }
+
+ public static function get_data( $post_id ) {
+ $fields = array();
+ foreach ( self::$fields as $field ) {
+ $fields[$field][0] = get_post_meta( $post_id, $field, true );
+ }
+
+ return $fields;
+ }
+
+ public static function get_fields() {
+ return self::$fields;
+ }
+
+ function migrate_data() {
+ $args = array(
+ 'post_type' => 'postman_sent_mail',
+ 'posts_per_page' => -1,
+ );
+
+ $logs = new WP_Query($args);
+
+ $failed_records = 0;
+ foreach ( $logs->posts as $log ) {
+
+ foreach ($this->fields as $key ) {
+ $value = $this->get_meta( $log->ID, $key, true );
+
+ if ( $this->add_meta( $log->ID, $key, $value ) ) {
+ delete_post_meta( $log->ID, $key );
+ } else {
+ $failed_records++;
+ }
+ }
+ }
+ }
+
+ function load() {
+ $this->db->select();
+ }
+
+ /**
+ * @param array $data
+ */
+ function save( $data ) {
+ $this->db->query( $this->db->prepare(
+ "
+ INSERT INTO $this->db_name
+ ( " . implode( ',', array_keys( $data ) ) . " )
+ VALUES ( " . str_repeat( '%s', count( $data ) ) . " )", array_values( $data )
+ ) );
+ }
+
+} \ No newline at end of file
diff --git a/Postman/PostmanInstaller.php b/Postman/PostmanInstaller.php
index f011251..f3616f2 100644
--- a/Postman/PostmanInstaller.php
+++ b/Postman/PostmanInstaller.php
@@ -24,6 +24,7 @@ class PostmanInstaller {
* Handle activation of the plugin
*/
public function activatePostman() {
+ delete_option( 'postman_release_version' );
$options = get_option( PostmanOptions::POSTMAN_OPTIONS );
$args = array(
'fallback_smtp_enabled' => 'no',
@@ -41,10 +42,6 @@ class PostmanInstaller {
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
-/* $role = get_role( Postman::ADMINISTRATOR_ROLE_NAME );
- $role->add_cap( Postman::MANAGE_POSTMAN_CAPABILITY_NAME );
- $role->add_cap( Postman::MANAGE_POSTMAN_CAPABILITY_LOGS );*/
-
$options['post_smtp_allow_overwrite'] = '1';
update_site_option( PostmanOptions::POSTMAN_NETWORK_OPTIONS, $options );
diff --git a/Postman/PostmanLogMeta.php b/Postman/PostmanLogMeta.php
deleted file mode 100644
index 8a05b3a..0000000
--- a/Postman/PostmanLogMeta.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-
-class PostmanLogMeta {
-
- public $log_meta_type = 'post_smtp_logs';
-
- private $meta_fields = array(
- 'success',
- 'from_header',
- 'to_header',
- 'cc_header',
- 'bcc_header',
- 'reply_to_header',
- 'transport_uri',
- 'original_to',
- 'original_subject',
- 'original_message',
- 'original_headers',
- 'session_transcript'
- );
-
- function install_table() {
-
- global $wpdb;
-
- $sql = "CREATE TABLE `{$this->log_meta_type}_{$wpdb->prefix}_{$this->log_meta_type}` (

- `meta_id` bigint(20) NOT NULL AUTO_INCREMENT,

- `post_smtp_id` bigint(20) NOT NULL DEFAULT '0',

- `meta_key` varchar(255) DEFAULT NULL,
 `meta_value` longtext,

- PRIMARY KEY (`meta_id`),

- KEY `post_smtp_id` (`post_smtp_id`),

- KEY `meta_key` (`meta_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
-
- dbDelta( $sql );
- }
-
- function migrate_data() {
- $args = array(
- 'post_type' => 'postman_sent_mail',
- 'posts_per_page' => -1,
- );
-
- $logs = new WP_Query($args);
-
- $failed_records = 0;
- foreach ( $logs->posts as $log ) {
-
- foreach ( $this->meta_fields as $key ) {
- $value = $this->get_meta( $log->ID, $key, true );
-
- if ( $this->add_meta( $log->ID, $key, $value ) ) {
- delete_post_meta( $log->ID, $key );
- } else {
- $failed_records++;
- }
- }
- }
- }
-
- function add_meta( $post_id = 0, $meta_key = '', $meta_value = '' ) {
- return add_metadata( $this->log_meta_type, $post_id, $meta_key, $meta_value );
- }
-
- function update_meta( $post_id = 0, $meta_key = '', $meta_value = '' ) {
- return update_metadata( $this->log_meta_type, $post_id, $meta_key, $meta_value );
- }
-
- function get_meta( $post_id = 0, $meta_key = '', $single = false ) {
- return get_metadata( $this->log_meta_type, $post_id, $meta_key, $single );
- }
-
- function delete_meta( $post_id = 0, $meta_key = '' ) {
- return delete_metadata( $this->log_meta_type, $post_id, $meta_key );
- }
-
-} \ No newline at end of file
diff --git a/Postman/PostmanUtils.php b/Postman/PostmanUtils.php
index 5b42270..6858fe3 100644
--- a/Postman/PostmanUtils.php
+++ b/Postman/PostmanUtils.php
@@ -447,7 +447,7 @@ class PostmanUtils {
}
public static function getServerName() {
- $host = 'localhost.localdomain';
+ $host = 'localhost';
if (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER)) {
$host = $_SERVER['SERVER_NAME'];
@@ -457,22 +457,6 @@ class PostmanUtils {
$host = php_uname('n');
}
- // as final option - if ip returned or hostname without extension (not valid dns name)
- $extension = pathinfo( $host, PATHINFO_EXTENSION );
- if ( filter_var( $host, FILTER_VALIDATE_IP ) || empty( $extension ) ) {
- $siteurl = get_bloginfo('url');
- $temp_host = parse_url( $siteurl, PHP_URL_HOST);
-
- $dnsr = dns_get_record( $temp_host, DNS_A );
- $ip = gethostbyname( $temp_host );
-
- foreach ( $dnsr as $record ) {
- if ( $record['host'] == $temp_host && $record['ip'] == $ip ) {
- $host = $temp_host;
- }
- }
- }
-
return str_replace('www.', '', $host );
}
diff --git a/Postman/PostmanWpMail.php b/Postman/PostmanWpMail.php
index 5228fdd..41586b4 100644
--- a/Postman/PostmanWpMail.php
+++ b/Postman/PostmanWpMail.php
@@ -41,6 +41,10 @@ if ( ! class_exists( 'PostmanWpMail' ) ) {
// initialize for sending
$this->init();
+ if ( ! is_array( $headers ) ) {
+ $headers = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
+ }
+
// Apply critical headers
$headers = $this->apply_default_headers( (array)$headers );