}
- public function fixImages( $content )
- {
- $dom = new DOMDocument( '1.0', 'UTF-8' );
- $dom->encoding = 'UTF-8';
- $test = $dom->loadHTML( '<?xml encoding="UTF-8">' . $content );
- $images = $dom->getElementsByTagName( 'img' );
- foreach ( $images as $image ) {
- $width = $height = $align = null;
- if ( $image->hasAttribute( 'class' ) ) {
- // Is it left or right or center?
- if ( preg_match( '/alignleft/', $image->getAttribute('class'))) {
- $align = 'left';
- }
- if ( preg_match( '/alignright/', $image->getAttribute('class'))) {
- $align = 'right';
- }
- if ( preg_match( '/aligncenter/', $image->getAttribute('class'))) {
- $align = 'center';
- }
- }
- switch ( $align ) {
- case 'left':
- $image->setAttribute( 'style', 'float: left; margin: 10px;' );
- break;
- case 'right':
- $image->setAttribute( 'style', 'float: right; margin: 10px;' );
- break;
- case 'center':
- $image->setAttribute( 'style', 'display: block; text-align: center; margin: 0 auto;' );
- break;
- }
- }
- $content = $dom->saveHTML();
- return $content;
- }
-
}
--- /dev/null
+<?php
+namespace GlmMessages;
+
+/**
+ * Class mailer
+ *
+ * Deals with creating the html body and sending of emails.
+ */
+class mailer
+{
+ /**
+ * sendHtmlEmail
+ *
+ * Create html email and send using wp_mail.
+ *
+ * @param mixed $to To email address
+ * @param mixed $subject Subject line for the email
+ * @param mixed $htmlMessage Html message for the email
+ *
+ * @access public
+ * @return void
+ */
+ public function sendHtmlEmail( $from, $to, $subject, $htmlMessage, $fromName, $replyTo = null )
+ {
+
+ // Set the From name using this wordpress hook.
+ add_filter(
+ 'wp_mail_from_name',
+ function ( $name ) use ( $fromName ) {
+ return $fromName;
+ }
+ );
+ // Send confirmation email, set the content type to allow html by using this filter
+ add_filter( 'wp_mail_content_type', function() {
+ return 'text/html';
+ } );
+
+ $message = $htmlMessage;
+ $header[] = 'From:' . $from;
+ if ( $replyTo ) {
+ $header[] = 'Reply-To:' . $replyTo;
+ }
+
+ wp_mail( $to, $subject, $message, $header );
+
+ remove_filter( 'wp_mail_from_name' );
+ remove_filter( 'wp_mail_content_type' );
+ }
+
+ /**
+ * Merge template and data to produce HTML
+ *
+ * Checks the theme's view directories and the view directories for
+ * this plugin for a matching view file.
+ *
+ * Note that $view needs to have the proper view directory path
+ * includes. (i.e. "/views/front/registrations/summary.html")
+ *
+ * $view may also be a template as a string if $viewIsString is true.
+ *
+ * @param $data array Array of data to merge with the template
+ * @param $view string Name of view file (see above))
+ * @param $viewIsString boolean If true, $view is a string containing the view.
+ *
+ * @access public
+ * @return void
+ */
+ function generateHTML( $data, $view, $message, $process_id, $email )
+ {
+
+ // Load Smarty Template support.
+ $smarty = new \smartyTemplateSupport();
+
+ // Add standard parameters.
+ require GLM_MEMBERS_PLUGIN_SETUP_PATH . '/standardTemplateParams.php';
+
+ // Add data from model to Smarty template.
+ if ( is_array( $data ) && count( $data ) > 0 ) {
+ foreach ( $data as $k => $d ) {
+ $smarty->templateAssign( $k, $d );
+ }
+ }
+
+ $emailContent = $smarty->template->fetch( 'eval:' . $this->fixImages( $view ) );
+ $tData = array(
+ 'image' => $message['image'],
+ 'content' => $emailContent,
+ 'footer' => $message['footer'],
+ 'templateName' => $message['title'],
+ 'process_id' => $process_id,
+ 'email' => $email,
+ );
+ if ( is_array( $tData ) && count( $tData ) > 0 ) {
+ foreach ( $tData as $k => $d ) {
+ $smarty->templateAssign( $k, $d );
+ }
+ }
+
+ $viewPath = GLM_MEMBERS_MESSAGES_PLUGIN_PATH . '/views';
+ $smarty->template->setTemplateDir( $viewPath );
+ $viewFile = 'email/messages/newsletter.html';
+ $out = $smarty->template->fetch( $viewFile );
+
+ return $out;
+
+ }
+
+ /**
+ * Deal with the images.
+ *
+ * This will update the styles for images so they float properly in the email.
+ */
+ public function fixImages( $content )
+ {
+ $dom = new \DOMDocument( '1.0', 'UTF-8' );
+ $dom->encoding = 'UTF-8';
+ $test = $dom->loadHTML( '<?xml encoding="UTF-8">' . $content );
+ $images = $dom->getElementsByTagName( 'img' );
+ foreach ( $images as $image ) {
+ $width = $height = $align = null;
+ if ( $image->hasAttribute( 'class' ) ) {
+ // Is it left or right or center?
+ if ( preg_match( '/alignleft/', $image->getAttribute('class'))) {
+ $align = 'left';
+ }
+ if ( preg_match( '/alignright/', $image->getAttribute('class'))) {
+ $align = 'right';
+ }
+ if ( preg_match( '/aligncenter/', $image->getAttribute('class'))) {
+ $align = 'center';
+ }
+ }
+ switch ( $align ) {
+ case 'left':
+ $image->setAttribute( 'style', 'float: left; margin: 10px;' );
+ break;
+ case 'right':
+ $image->setAttribute( 'style', 'float: right; margin: 10px;' );
+ break;
+ case 'center':
+ $image->setAttribute( 'style', 'display: block; text-align: center; margin: 0 auto;' );
+ break;
+ }
+ }
+ $content = $dom->saveHTML();
+ return $content;
+ }
+}
require_once GLM_MEMBERS_MESSAGES_PLUGIN_CLASS_PATH.'/data/dataEmailMessages.php';
require_once GLM_MEMBERS_MESSAGES_PLUGIN_CLASS_PATH.'/data/dataEmailTemplates.php';
require_once GLM_MEMBERS_MESSAGES_PLUGIN_CLASS_PATH.'/data/dataEmailLogs.php';
+require_once GLM_MEMBERS_MESSAGES_PLUGIN_CLASS_PATH.'/mailer.php';
+
+use GlmMessages\mailer as glmMailer;
/*
* This class performs the work for the default action of the "Members" menu
*/
public function queueHtmlMessages( $data, $messageId, $sendNow = false )
{
- $message = $this->getEntry( $messageId );
+ $glmMailer = new glmMailer();
+ $message = $this->getEntry( $messageId );
$fromEmail = $message['from_email'];
$fromName = $message['from_name'];
$replyToEmail = $message['reply_to_email'];
'mobile_phone' => $contact['mobile_phone'],
)
);
- $messageBody = $this->generateHTML( $emailData, wpautop( $message['message_body'] ), $message, $process_id, $contact['email'] );
+ $messageBody = $glmMailer->generateHTML( $emailData, wpautop( $message['message_body'] ), $message, $process_id, $contact['email'] );
if ( $sendNow ) {
- $this->sendHtmlEmail(
+ $glmMailer->sendHtmlEmail(
$fromEmail,
$contact['email'],
$subject,
}
}
- /**
- * Merge template and data to produce HTML
- *
- * Checks the theme's view directories and the view directories for
- * this plugin for a matching view file.
- *
- * Note that $view needs to have the proper view directory path
- * includes. (i.e. "/views/front/registrations/summary.html")
- *
- * $view may also be a template as a string if $viewIsString is true.
- *
- * @param $data array Array of data to merge with the template
- * @param $view string Name of view file (see above))
- * @param $viewIsString boolean If true, $view is a string containing the view.
- *
- * @access public
- * @return void
- */
- function generateHTML( $data, $view, $message, $process_id, $email )
- {
-
- // Load Smarty Template support.
- $smarty = new smartyTemplateSupport();
-
- // Add standard parameters.
- require GLM_MEMBERS_PLUGIN_SETUP_PATH . '/standardTemplateParams.php';
-
- // Add data from model to Smarty template.
- if ( is_array( $data ) && count( $data ) > 0 ) {
- foreach ( $data as $k => $d ) {
- $smarty->templateAssign( $k, $d );
- }
- }
-
- $emailContent = $smarty->template->fetch( 'eval:' . $this->fixImages( $view ) );
- $tData = array(
- 'image' => $message['image'],
- 'content' => $emailContent,
- 'footer' => $message['footer'],
- 'templateName' => $message['title'],
- 'process_id' => $process_id,
- 'email' => $email,
- );
- if ( is_array( $tData ) && count( $tData ) > 0 ) {
- foreach ( $tData as $k => $d ) {
- $smarty->templateAssign( $k, $d );
- }
- }
-
- $viewPath = GLM_MEMBERS_MESSAGES_PLUGIN_PATH . '/views';
- $smarty->template->setTemplateDir( $viewPath );
- $viewFile = 'email/messages/newsletter.html';
- $out = $smarty->template->fetch( $viewFile );
-
- return $out;
-
- }
-
- /**
- * sendHtmlEmail
- *
- * Create html email and send using wp_mail.
- *
- * @param mixed $to To email address
- * @param mixed $subject Subject line for the email
- * @param mixed $htmlMessage Html message for the email
- *
- * @access public
- * @return void
- */
- public function sendHtmlEmail( $from, $to, $subject, $htmlMessage, $fromName, $replyTo = null )
- {
-
- // Set the From name using this wordpress hook.
- add_filter(
- 'wp_mail_from_name',
- function ( $name ) use ( $fromName ) {
-
- return $fromName;
- }
- );
- // Send confirmation email, set the content type to allow html by using this filter
- add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
-
-
- $message = $htmlMessage;
- $header[] = 'From:' . $from;
- if ( $replyTo ) {
- $header[] = 'Reply-To:' . $replyTo;
- }
-
- wp_mail( $to, $subject, $message, $header );
-
- }
-
- /**
- * Set content type of the email.
- *
- * Used as filter for the wp_mail_content_type
- */
- function set_content_type()
- {
- return 'text/html';
- }
}
* @link http://dev.gaslightmedia.com/
*/
+require_once GLM_MEMBERS_MESSAGES_PLUGIN_CLASS_PATH.'/mailer.php';
+
+use GlmMessages\mailer as glmMailer;
+
+/**
+ * Send Messages Emails class
+ *
+ * Grab all queued emails and sends them out.
+ */
class GlmMembersAdmin_messages_sendMessagesEmails
{
// $notiicationTest to true to just display notification messages
public function modelAction( $actionData = false )
{
+ $glmMailer = new glmMailer();
trigger_error( 'sendMessagesEmail started', E_USER_NOTICE );
// Request a Lock
if ( $emailQueues ) {
foreach ( $emailQueues as $email ) {
- $this->sendHtmlEmail(
+ $glmMailer->sendHtmlEmail(
$email['from_email'],
$email['to_email'],
$email['subject'],
}
- /**
- * sendHtmlEmail
- *
- * Create html email and send using wp_mail.
- *
- * @param mixed $to To email address
- * @param mixed $subject Subject line for the email
- * @param mixed $htmlMessage Html message for the email
- *
- * @access public
- * @return void
- */
- public function sendHtmlEmail( $from, $to, $subject, $htmlMessage, $fromName, $replyTo = null )
- {
-
- // Set the From name using this wordpress hook.
- add_filter(
- 'wp_mail_from_name',
- function ( $name ) use ( $fromName ) {
- return $fromName;
- }
- );
- // Send confirmation email, set the content type to allow html by using this filter
- add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
-
-
- $message = $htmlMessage;
- $header[] = 'From:' . $from;
- if ( $replyTo ) {
- $header[] = 'Reply-To:' . $replyTo;
- }
-
- wp_mail( $to, $subject, $message, $header );
-
- }
-
- /**
- * Set content type of the email.
- *
- * Used as filter for the wp_mail_content_type
- */
- function set_content_type()
- {
- return 'text/html';
- }
}