summaryrefslogtreecommitdiff
path: root/Postman/notifications
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2018-04-04 19:17:51 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2018-04-04 19:17:51 +0000
commit62b95f35576ea9b9178b900f9480fed0466211a2 (patch)
tree746cfdf1c0cdc8408b312870f881ed3684d8d60b /Postman/notifications
parenta83767b57bb15075e775f2336cfd77225b155799 (diff)
downloadPost-SMTP-62b95f35576ea9b9178b900f9480fed0466211a2.zip
notification & new gmail client
Diffstat (limited to 'Postman/notifications')
-rw-r--r--Postman/notifications/INotify.php4
-rw-r--r--Postman/notifications/PostmanMailNotify.php12
-rw-r--r--Postman/notifications/PostmanNotify.php17
-rw-r--r--Postman/notifications/PostmanPushoverNotify.php32
-rw-r--r--Postman/notifications/PostmanSlackNotify.php37
5 files changed, 102 insertions, 0 deletions
diff --git a/Postman/notifications/INotify.php b/Postman/notifications/INotify.php
new file mode 100644
index 0000000..d330cbe
--- /dev/null
+++ b/Postman/notifications/INotify.php
@@ -0,0 +1,4 @@
+<?php
+interface Postman_Notify {
+ public function send_message( $message );
+} \ No newline at end of file
diff --git a/Postman/notifications/PostmanMailNotify.php b/Postman/notifications/PostmanMailNotify.php
new file mode 100644
index 0000000..a14a5f4
--- /dev/null
+++ b/Postman/notifications/PostmanMailNotify.php
@@ -0,0 +1,12 @@
+<?php
+
+class PostmanMailNotify implements Postman_Notify {
+
+ public function send_message($message)
+ {
+ $to_email = get_bloginfo( 'admin_email' );
+ $domain = get_bloginfo( 'url' );
+
+ mail( $to_email, "{$domain}: " . __( 'Post SMTP email error', Postman::TEXT_DOMAIN ), $message , null, "-f{$to_email}" );
+ }
+} \ No newline at end of file
diff --git a/Postman/notifications/PostmanNotify.php b/Postman/notifications/PostmanNotify.php
new file mode 100644
index 0000000..22ca56f
--- /dev/null
+++ b/Postman/notifications/PostmanNotify.php
@@ -0,0 +1,17 @@
+<?php
+require_once 'INotify.php';
+require_once 'PostmanMailNotify.php';
+require_once 'PostmanPushoverNotify.php';
+require_once 'PostmanSlackNotify.php';
+
+class PostmanNotify {
+ private $notify;
+
+ public function __construct( Postman_Notify $notify ) {
+ $this->notify = $notify;
+ }
+
+ public function send( $message, $log ) {
+ $this->notify->send_message( $message );
+ }
+} \ No newline at end of file
diff --git a/Postman/notifications/PostmanPushoverNotify.php b/Postman/notifications/PostmanPushoverNotify.php
new file mode 100644
index 0000000..1c483b3
--- /dev/null
+++ b/Postman/notifications/PostmanPushoverNotify.php
@@ -0,0 +1,32 @@
+<?php
+
+class PostmanPushoverNotify implements Postman_Notify {
+
+ public function send_message($message)
+ {
+ $options = PostmanOptions::getInstance();
+
+ $api_url = "https://api.pushover.net/1/messages.json";
+ $app_token = $options->getPushoverToken();
+ $user_key = $options->getPushoverUser();
+
+ $args = array(
+ 'body' => array(
+ "token" => $app_token,
+ "user" => $user_key,
+ "message" => $message,
+ )
+ );
+
+ $result = wp_remote_post( $api_url, $args );
+
+ if ( is_wp_error($result) ) {
+ error_log( __CLASS__ . ': ' . $result->get_error_message() );
+ }
+
+ $body = json_decode( wp_remote_retrieve_body( $result ), true );
+ if ( $body['status'] == 0 ) {
+ error_log( __CLASS__ . ': ' . print_r( $body, true ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/Postman/notifications/PostmanSlackNotify.php b/Postman/notifications/PostmanSlackNotify.php
new file mode 100644
index 0000000..41094ed
--- /dev/null
+++ b/Postman/notifications/PostmanSlackNotify.php
@@ -0,0 +1,37 @@
+<?php
+
+class PostmanSlackNotify implements Postman_Notify {
+
+ public function send_message($message)
+ {
+ $options = PostmanOptions::getInstance();
+
+ $api_url = $options->getSlackToken();
+
+ $headers = array(
+ 'content-type' => 'application/json'
+ );
+
+ $body = array(
+ 'text' => $message
+ );
+
+ $args = array(
+ 'headers' => $headers,
+ 'body' => json_encode($body)
+ );
+
+ $result = wp_remote_post( $api_url, $args );
+
+ if ( is_wp_error($result) ) {
+ error_log( __CLASS__ . ': ' . $result->get_error_message() );
+ }
+
+ $code = wp_remote_retrieve_response_code( $result );
+ $message = wp_remote_retrieve_response_message( $result );
+
+ if ( $code != 200 && $message !== 'OK' ) {
+ error_log( __CLASS__ . ': ' . $message );
+ }
+ }
+} \ No newline at end of file