Update for sending emails
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 9 Aug 2019 15:37:28 +0000 (11:37 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 9 Aug 2019 15:37:28 +0000 (11:37 -0400)
add fixImages method to sending of emails

models/admin/messages/index.php

index a11094b..309ca54 100644 (file)
@@ -664,7 +664,7 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages
             }
         }
 
-        $emailContent = $smarty->template->fetch( 'eval:' . $view );
+        $emailContent = $smarty->template->fetch( 'eval:' . $this->fixImages( $view ) );
 
         $Templates = new GlmDataEmailTemplates( $this->wpdb, $this->config );
         $template  = $Templates->getEntry( $template );
@@ -690,4 +690,39 @@ class GlmMembersAdmin_messages_index extends GlmDataEmailMessages
 
     }
 
+    public function fixImages( $content )
+    {
+        $dom           = new DOMDocument( '1.0', 'UTF-8' );
+        $dom->encoding = 'UTF-8';
+        $test          = $dom->loadHTML( $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: 5px;' );
+                break;
+            case 'right':
+                $image->setAttribute( 'style', 'float: right; margin: 5px;' );
+                break;
+            case 'center':
+                $image->setAttribute( 'style', 'display: block; text-align: center; margin: 0 auto;' );
+                break;
+            }
+        }
+        $content = $dom->saveHTML();
+        return $content;
+    }
 }