@@ -42,15 +42,15 @@ discard block |
||
| 42 | 42 | /** |
| 43 | 43 | * @return Email |
| 44 | 44 | */ |
| 45 | - public function compose(array $email) |
|
| 45 | + public function compose( array $email ) |
|
| 46 | 46 | { |
| 47 | - $this->normalize($email); |
|
| 47 | + $this->normalize( $email ); |
|
| 48 | 48 | $this->attachments = $this->email['attachments']; |
| 49 | 49 | $this->headers = $this->buildHeaders(); |
| 50 | 50 | $this->message = $this->buildHtmlMessage(); |
| 51 | 51 | $this->subject = $this->email['subject']; |
| 52 | 52 | $this->to = $this->email['to']; |
| 53 | - add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
| 53 | + add_action( 'phpmailer_init', [$this, 'buildPlainTextMessage'] ); |
|
| 54 | 54 | return $this; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | * @param string $format |
| 59 | 59 | * @return string|null |
| 60 | 60 | */ |
| 61 | - public function read($format = '') |
|
| 61 | + public function read( $format = '' ) |
|
| 62 | 62 | { |
| 63 | - if ('plaintext' == $format) { |
|
| 64 | - $message = $this->stripHtmlTags($this->message); |
|
| 65 | - return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
| 63 | + if( 'plaintext' == $format ) { |
|
| 64 | + $message = $this->stripHtmlTags( $this->message ); |
|
| 65 | + return apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
| 66 | 66 | } |
| 67 | 67 | return $this->message; |
| 68 | 68 | } |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function send() |
| 74 | 74 | { |
| 75 | - if (!$this->message || !$this->subject || !$this->to) { |
|
| 75 | + if( !$this->message || !$this->subject || !$this->to ) { |
|
| 76 | 76 | return; |
| 77 | 77 | } |
| 78 | - add_action('wp_mail_failed', [$this, 'logMailError']); |
|
| 78 | + add_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
| 79 | 79 | $sent = wp_mail( |
| 80 | 80 | $this->to, |
| 81 | 81 | $this->subject, |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $this->headers, |
| 84 | 84 | $this->attachments |
| 85 | 85 | ); |
| 86 | - remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
| 86 | + remove_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
| 87 | 87 | $this->reset(); |
| 88 | 88 | return $sent; |
| 89 | 89 | } |
@@ -92,16 +92,16 @@ discard block |
||
| 92 | 92 | * @return void |
| 93 | 93 | * @action phpmailer_init |
| 94 | 94 | */ |
| 95 | - public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
| 95 | + public function buildPlainTextMessage( PHPMailer $phpmailer ) |
|
| 96 | 96 | { |
| 97 | - if (empty($this->email)) { |
|
| 97 | + if( empty($this->email) ) { |
|
| 98 | 98 | return; |
| 99 | 99 | } |
| 100 | - if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
| 100 | + if( 'text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody) ) { |
|
| 101 | 101 | return; |
| 102 | 102 | } |
| 103 | - $message = $this->stripHtmlTags($phpmailer->Body); |
|
| 104 | - $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
| 103 | + $message = $this->stripHtmlTags( $phpmailer->Body ); |
|
| 104 | + $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -112,14 +112,14 @@ discard block |
||
| 112 | 112 | $allowed = [ |
| 113 | 113 | 'bcc', 'cc', 'from', 'reply-to', |
| 114 | 114 | ]; |
| 115 | - $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
| 116 | - $headers = array_filter($headers); |
|
| 117 | - foreach ($headers as $key => $value) { |
|
| 115 | + $headers = array_intersect_key( $this->email, array_flip( $allowed ) ); |
|
| 116 | + $headers = array_filter( $headers ); |
|
| 117 | + foreach( $headers as $key => $value ) { |
|
| 118 | 118 | unset($headers[$key]); |
| 119 | 119 | $headers[] = $key.': '.$value; |
| 120 | 120 | } |
| 121 | 121 | $headers[] = 'Content-Type: text/html'; |
| 122 | - return apply_filters('site-reviews/email/headers', $headers, $this); |
|
| 122 | + return apply_filters( 'site-reviews/email/headers', $headers, $this ); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -127,54 +127,54 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | protected function buildHtmlMessage() |
| 129 | 129 | { |
| 130 | - $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
| 131 | - if (!empty($template)) { |
|
| 132 | - $message = glsr(Template::class)->interpolate( |
|
| 130 | + $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) ); |
|
| 131 | + if( !empty($template) ) { |
|
| 132 | + $message = glsr( Template::class )->interpolate( |
|
| 133 | 133 | $template, |
| 134 | 134 | ['context' => $this->email['template-tags']], |
| 135 | 135 | $this->email['template'] |
| 136 | 136 | ); |
| 137 | - } elseif ($this->email['template']) { |
|
| 138 | - $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
| 137 | + } elseif( $this->email['template'] ) { |
|
| 138 | + $message = glsr( Template::class )->build( 'templates/'.$this->email['template'], [ |
|
| 139 | 139 | 'context' => $this->email['template-tags'], |
| 140 | - ]); |
|
| 140 | + ] ); |
|
| 141 | 141 | } |
| 142 | - if (!isset($message)) { |
|
| 142 | + if( !isset($message) ) { |
|
| 143 | 143 | $message = $this->email['message']; |
| 144 | 144 | } |
| 145 | 145 | $message = $this->email['before'].$message.$this->email['after']; |
| 146 | - $message = strip_shortcodes($message); |
|
| 147 | - $message = wptexturize($message); |
|
| 148 | - $message = wpautop($message); |
|
| 149 | - $message = str_replace('<> ', '', $message); |
|
| 150 | - $message = str_replace(']]>', ']]>', $message); |
|
| 151 | - $message = glsr(Template::class)->build('partials/email/index', [ |
|
| 146 | + $message = strip_shortcodes( $message ); |
|
| 147 | + $message = wptexturize( $message ); |
|
| 148 | + $message = wpautop( $message ); |
|
| 149 | + $message = str_replace( '<> ', '', $message ); |
|
| 150 | + $message = str_replace( ']]>', ']]>', $message ); |
|
| 151 | + $message = glsr( Template::class )->build( 'partials/email/index', [ |
|
| 152 | 152 | 'context' => ['message' => $message], |
| 153 | - ]); |
|
| 154 | - return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
| 153 | + ] ); |
|
| 154 | + return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | 158 | * @param \WP_Error $error |
| 159 | 159 | * @return void |
| 160 | 160 | */ |
| 161 | - protected function logMailError($error) |
|
| 161 | + protected function logMailError( $error ) |
|
| 162 | 162 | { |
| 163 | - glsr_log()->error('Email was not sent (wp_mail failed)') |
|
| 164 | - ->debug($this) |
|
| 165 | - ->debug($error); |
|
| 163 | + glsr_log()->error( 'Email was not sent (wp_mail failed)' ) |
|
| 164 | + ->debug( $this ) |
|
| 165 | + ->debug( $error ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | 169 | * @return void |
| 170 | 170 | */ |
| 171 | - protected function normalize(array $email = []) |
|
| 171 | + protected function normalize( array $email = [] ) |
|
| 172 | 172 | { |
| 173 | - $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
| 174 | - if (empty($email['reply-to'])) { |
|
| 173 | + $email = shortcode_atts( glsr( EmailDefaults::class )->defaults(), $email ); |
|
| 174 | + if( empty($email['reply-to']) ) { |
|
| 175 | 175 | $email['reply-to'] = $email['from']; |
| 176 | 176 | } |
| 177 | - $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
| 177 | + $this->email = apply_filters( 'site-reviews/email/compose', $email, $this ); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -193,21 +193,21 @@ discard block |
||
| 193 | 193 | /** |
| 194 | 194 | * @return string |
| 195 | 195 | */ |
| 196 | - protected function stripHtmlTags($string) |
|
| 196 | + protected function stripHtmlTags( $string ) |
|
| 197 | 197 | { |
| 198 | 198 | // remove invisible elements |
| 199 | - $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
| 199 | + $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string ); |
|
| 200 | 200 | // replace certain elements with a line-break |
| 201 | - $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
| 201 | + $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string ); |
|
| 202 | 202 | // replace other elements with a space |
| 203 | - $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
| 203 | + $string = preg_replace( '@</(td|th)@iu', ' $0', $string ); |
|
| 204 | 204 | // add a placeholder for plain-text bullets to list elements |
| 205 | - $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
| 205 | + $string = preg_replace( '@<(li)[^>]*?>@siu', '$0-o-^-o-', $string ); |
|
| 206 | 206 | // strip all remaining HTML tags |
| 207 | - $string = wp_strip_all_tags($string); |
|
| 208 | - $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
| 209 | - $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
| 210 | - $string = str_replace('-o-^-o-', ' - ', $string); |
|
| 211 | - return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
| 207 | + $string = wp_strip_all_tags( $string ); |
|
| 208 | + $string = wp_specialchars_decode( $string, ENT_QUOTES ); |
|
| 209 | + $string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string ); |
|
| 210 | + $string = str_replace( '-o-^-o-', ' - ', $string ); |
|
| 211 | + return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' ); |
|
| 212 | 212 | } |
| 213 | 213 | } |