Completed
Push — master ( 5fe043...600d7a )
by Jamie
04:01
created
classes/models/FrmNotification.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@  discard block
 block discarded – undo
2 2
 
3 3
 class FrmNotification {
4 4
 	public function __construct() {
5
-        if ( ! defined('ABSPATH') ) {
6
-            die('You are not allowed to call this page directly.');
5
+        if ( ! defined( 'ABSPATH' ) ) {
6
+            die( 'You are not allowed to call this page directly.' );
7 7
         }
8
-        add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3);
8
+        add_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3 );
9 9
     }
10 10
 
11 11
 	public static function trigger_email( $action, $entry, $form ) {
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
         $email_key = $action->ID;
14 14
 
15 15
         // Set the subject
16
-        if ( empty($notification['email_subject']) ) {
17
-            $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]');
16
+        if ( empty( $notification['email_subject'] ) ) {
17
+            $notification['email_subject'] = sprintf( __( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]' );
18 18
         }
19 19
 
20 20
         $plain_text = $notification['plain_text'] ? true : false;
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
             'email_subject', 'email_message',
27 27
         );
28 28
 
29
-        add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false'));
29
+        add_filter( 'frm_plain_text_email', ( $plain_text ? '__return_true' : '__return_false' ) );
30 30
 
31 31
         //Get all values in entry in order to get User ID field ID
32 32
         $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' );
@@ -37,29 +37,29 @@  discard block
 block discarded – undo
37 37
                 $user_id_key = $value->field_key;
38 38
                 break;
39 39
             }
40
-            unset($value);
40
+            unset( $value );
41 41
         }
42 42
 
43 43
         //Filter and prepare the email fields
44 44
         foreach ( $filter_fields as $f ) {
45 45
             //Don't allow empty From
46
-			if ( $f == 'from' && empty( $notification[ $f ] ) ) {
47
-				$notification[ $f ] = '[admin_email]';
46
+			if ( $f == 'from' && empty( $notification[$f] ) ) {
47
+				$notification[$f] = '[admin_email]';
48 48
 			} else if ( in_array( $f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from' ) ) ) {
49 49
 				//Remove brackets
50 50
                 //Add a space in case there isn't one
51
-				$notification[ $f ] = str_replace( '<', ' ', $notification[ $f ] );
52
-				$notification[ $f ] = str_replace( array( '"', '>' ), '', $notification[ $f ] );
51
+				$notification[$f] = str_replace( '<', ' ', $notification[$f] );
52
+				$notification[$f] = str_replace( array( '"', '>' ), '', $notification[$f] );
53 53
 
54 54
                 //Switch userID shortcode to email address
55
-				if ( strpos( $notification[ $f ], '[' . $user_id_field . ']' ) !== false || strpos( $notification[ $f ], '[' . $user_id_key . ']' ) !== false ) {
56
-					$user_data = get_userdata( $entry->metas[ $user_id_field ] );
55
+				if ( strpos( $notification[$f], '[' . $user_id_field . ']' ) !== false || strpos( $notification[$f], '[' . $user_id_key . ']' ) !== false ) {
56
+					$user_data = get_userdata( $entry->metas[$user_id_field] );
57 57
                     $user_email = $user_data->user_email;
58
-					$notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] );
58
+					$notification[$f] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[$f] );
59 59
                 }
60 60
             }
61 61
 
62
-			$notification[ $f ] = FrmFieldsHelper::basic_replace_shortcodes( $notification[ $f ], $form, $entry );
62
+			$notification[$f] = FrmFieldsHelper::basic_replace_shortcodes( $notification[$f], $form, $entry );
63 63
         }
64 64
 
65 65
         //Put recipients, cc, and bcc into an array if they aren't empty
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		$cc = self::explode_emails( $notification['cc'] );
68 68
 		$bcc = self::explode_emails( $notification['bcc'] );
69 69
 
70
-        $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form'));
70
+        $to_emails = apply_filters( 'frm_to_email', $to_emails, $values, $form->id, compact( 'email_key', 'entry', 'form' ) );
71 71
 
72 72
         // Stop now if there aren't any recipients
73 73
         if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) {
@@ -77,39 +77,39 @@  discard block
 block discarded – undo
77 77
         $to_emails = array_unique( (array) $to_emails );
78 78
 
79 79
         $prev_mail_body = $mail_body = $notification['email_message'];
80
-        $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
80
+        $mail_body = FrmEntriesHelper::replace_default_message( $mail_body, array(
81 81
             'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
82
-            'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
82
+            'user_info' => ( isset( $notification['inc_user_info'] ) ? $notification['inc_user_info'] : false ),
83 83
         ) );
84 84
 
85 85
         // Add the user info if it isn't already included
86 86
         if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) {
87
-            $data = maybe_unserialize($entry->description);
87
+            $data = maybe_unserialize( $entry->description );
88 88
 			$mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
89 89
 			$mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $entry->ip . "\r\n";
90 90
 			$mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntryFormat::get_browser( $data['browser'] ) . "\r\n";
91 91
 			$mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
92 92
         }
93
-        unset($prev_mail_body);
93
+        unset( $prev_mail_body );
94 94
 
95 95
         // Add attachments
96
-        $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') );
96
+        $attachments = apply_filters( 'frm_notification_attachment', array(), $form, compact( 'entry', 'email_key' ) );
97 97
 
98
-        if ( ! empty($notification['email_subject']) ) {
99
-            $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key'));
98
+        if ( ! empty( $notification['email_subject'] ) ) {
99
+            $notification['email_subject'] = apply_filters( 'frm_email_subject', $notification['email_subject'], compact( 'form', 'entry', 'email_key' ) );
100 100
         }
101 101
 
102 102
         // check for a phone number
103 103
         foreach ( (array) $to_emails as $email_key => $e ) {
104
-            if ( $e != '[admin_email]' && ! is_email($e) ) {
105
-                $e = explode(' ', $e);
104
+            if ( $e != '[admin_email]' && ! is_email( $e ) ) {
105
+                $e = explode( ' ', $e );
106 106
 
107 107
                 //If to_email has name <[email protected]> format
108
-                if ( is_email(end($e)) ) {
108
+                if ( is_email( end( $e ) ) ) {
109 109
                     continue;
110 110
                 }
111 111
 
112
-                do_action('frm_send_to_not_email', array(
112
+                do_action( 'frm_send_to_not_email', array(
113 113
                     'e'         => $e,
114 114
                     'subject'   => $notification['email_subject'],
115 115
                     'mail_body' => $mail_body,
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                     'email_key' => $email_key,
122 122
                 ) );
123 123
 
124
-				unset( $to_emails[ $email_key ] );
124
+				unset( $to_emails[$email_key] );
125 125
             }
126 126
         }
127 127
 
@@ -144,17 +144,17 @@  discard block
 block discarded – undo
144 144
 	public function entry_created( $entry_id, $form_id ) {
145 145
 		$new_function = 'FrmFormActionsController::trigger_actions("create", ' . $form_id . ', ' . $entry_id . ', "email")';
146 146
 		_deprecated_function( __FUNCTION__, '2.0', $new_function );
147
-        FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email');
147
+        FrmFormActionsController::trigger_actions( 'create', $form_id, $entry_id, 'email' );
148 148
     }
149 149
 
150 150
 	public function send_notification_email( $to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '' ) {
151 151
         _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' );
152 152
 
153
-        return self::send_email(compact(
153
+        return self::send_email( compact(
154 154
             'to_email', 'subject', 'message',
155 155
             'from', 'from_name', 'plain_text',
156 156
             'attachments', 'reply_to'
157
-        ));
157
+        ) );
158 158
     }
159 159
 
160 160
 	/**
@@ -187,28 +187,28 @@  discard block
 block discarded – undo
187 187
     private static function format_email_fields( &$atts, $admin_email ) {
188 188
 
189 189
         // If from is empty or is set to admin_email, set it now
190
-        $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from'];
190
+        $atts['from'] = ( empty( $atts['from'] ) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from'];
191 191
 
192 192
         // Filter values in these fields
193 193
 		$filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' );
194 194
 
195 195
         foreach ( $filter_fields as $f ) {
196 196
             // If empty, just skip it
197
-			if ( empty( $atts[ $f ] ) ) {
197
+			if ( empty( $atts[$f] ) ) {
198 198
                 continue;
199 199
             }
200 200
 
201 201
             // to_email, cc, and bcc can be an array
202
-			if ( is_array( $atts[ $f ] ) ) {
203
-				foreach ( $atts[ $f ] as $key => $val ) {
202
+			if ( is_array( $atts[$f] ) ) {
203
+				foreach ( $atts[$f] as $key => $val ) {
204 204
                     self::format_single_field( $atts, $f, $val, $key );
205 205
                     unset( $key, $val );
206 206
                 }
207
-                unset($f);
207
+                unset( $f );
208 208
                 continue;
209 209
             }
210 210
 
211
-			self::format_single_field( $atts, $f, $atts[ $f ] );
211
+			self::format_single_field( $atts, $f, $atts[$f] );
212 212
         }
213 213
 
214 214
         // If reply-to isn't set, make it match the from settings
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
             $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] );
217 217
         }
218 218
 
219
-        if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) {
219
+        if ( ! is_array( $atts['to_email'] ) && '[admin_email]' == $atts['to_email'] ) {
220 220
             $atts['to_email'] = $admin_email;
221 221
         }
222 222
     }
@@ -239,20 +239,20 @@  discard block
 block discarded – undo
239 239
     * @param int $key if in array, this will be set
240 240
     */
241 241
     private static function format_single_field( &$atts, $f, $val, $key = false ) {
242
-        $val = trim($val);
242
+        $val = trim( $val );
243 243
 
244 244
         // If just a plain email is used
245
-        if ( is_email($val) ) {
245
+        if ( is_email( $val ) ) {
246 246
             // add sender's name if not included in $from
247 247
             if ( $f == 'from' ) {
248
-				$part_2 = $atts[ $f ];
249
-                $part_1  = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
248
+				$part_2 = $atts[$f];
249
+                $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
250 250
             } else {
251 251
                 return;
252 252
             }
253 253
         } else {
254
-            $parts = explode(' ', $val);
255
-            $part_2 = end($parts);
254
+            $parts = explode( ' ', $val );
255
+            $part_2 = end( $parts );
256 256
 
257 257
             // If inputted correcly, $part_2 should be an email
258 258
             if ( is_email( $part_2 ) ) {
@@ -260,14 +260,14 @@  discard block
 block discarded – undo
260 260
             } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) {
261 261
 				// In case someone just puts a name in the From or Reply To field
262 262
 				$part_1 = $val;
263
-                $part_2 = get_option('admin_email');
263
+                $part_2 = get_option( 'admin_email' );
264 264
             } else {
265 265
 				// In case someone just puts a name in any other email field
266 266
                 if ( false !== $key ) {
267
-					unset( $atts[ $f ][ $key ] );
267
+					unset( $atts[$f][$key] );
268 268
                     return;
269 269
                 }
270
-				$atts[ $f ] = '';
270
+				$atts[$f] = '';
271 271
                 return;
272 272
             }
273 273
         }
@@ -288,14 +288,14 @@  discard block
 block discarded – undo
288 288
 
289 289
         // If value is an array
290 290
         if ( false !== $key ) {
291
-			$atts[ $f ][ $key ] = $final_val;
291
+			$atts[$f][$key] = $final_val;
292 292
             return;
293 293
         }
294
-		$atts[ $f ] = $final_val;
294
+		$atts[$f] = $final_val;
295 295
     }
296 296
 
297 297
 	public static function send_email( $atts ) {
298
-        $admin_email = get_option('admin_email');
298
+        $admin_email = get_option( 'admin_email' );
299 299
         $defaults = array(
300 300
             'to_email'      => $admin_email,
301 301
             'subject'       => '',
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
             'reply_to'      => $admin_email,
309 309
             'attachments'   => array(),
310 310
         );
311
-        $atts = wp_parse_args($atts, $defaults);
311
+        $atts = wp_parse_args( $atts, $defaults );
312 312
 
313 313
         // Put To, BCC, CC, Reply To, and From fields in the correct format
314 314
         self::format_email_fields( $atts, $admin_email );
@@ -321,14 +321,14 @@  discard block
 block discarded – undo
321 321
 		$array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc'] );
322 322
 		$cc = array( 'CC' => array(), 'BCC' => array() );
323 323
         foreach ( $array_fields as $key => $a_field ) {
324
-            if ( empty($a_field) ) {
324
+            if ( empty( $a_field ) ) {
325 325
                 continue;
326 326
             }
327 327
 
328 328
 			foreach ( (array) $a_field as $email ) {
329
-				$cc[ $key ][] = $email;
329
+				$cc[$key][] = $email;
330 330
             }
331
-            unset($key, $a_field);
331
+            unset( $key, $a_field );
332 332
         }
333 333
 		$cc = array_filter( $cc ); // remove cc and bcc if they are empty
334 334
 
@@ -337,52 +337,52 @@  discard block
 block discarded – undo
337 337
 		}
338 338
 
339 339
         $content_type   = $atts['plain_text'] ? 'text/plain' : 'text/html';
340
-        $charset        = get_option('blog_charset');
340
+        $charset        = get_option( 'blog_charset' );
341 341
 
342 342
 		$header[]       = 'Reply-To: ' . $atts['reply_to'];
343 343
 		$header[]       = 'Content-Type: ' . $content_type . '; charset="' . esc_attr( $charset ) . '"';
344
-        $atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES );
344
+        $atts['subject'] = wp_specialchars_decode( strip_tags( stripslashes( $atts['subject'] ) ), ENT_QUOTES );
345 345
 
346
-        $message        = do_shortcode($atts['message']);
346
+        $message = do_shortcode( $atts['message'] );
347 347
 
348 348
         if ( $atts['plain_text'] ) {
349 349
             //$message    = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars
350
-            $message    = wp_specialchars_decode(strip_tags($message), ENT_QUOTES );
350
+            $message = wp_specialchars_decode( strip_tags( $message ), ENT_QUOTES );
351 351
         } else {
352 352
 			// remove line breaks in HTML emails to prevent conflicts with Mandrill
353 353
         	add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' );
354 354
         }
355 355
 		$message = apply_filters( 'frm_email_message', $message, $atts );
356 356
 
357
-        $header         = apply_filters('frm_email_header', $header, array(
357
+        $header = apply_filters( 'frm_email_header', $header, array(
358 358
 			'to_email' => $atts['to_email'], 'subject' => $atts['subject'],
359 359
 		) );
360 360
 
361
-        if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) {
361
+        if ( apply_filters( 'frm_encode_subject', 1, $atts['subject'] ) ) {
362 362
 			$atts['subject'] = '=?' . $charset . '?B?' . base64_encode( $atts['subject'] ) . '?=';
363 363
         }
364 364
 
365
-        remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' );
366
-        remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter');
365
+        remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
366
+        remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
367 367
 
368
-        $sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']);
368
+        $sent = wp_mail( $recipient, $atts['subject'], $message, $header, $atts['attachments'] );
369 369
         if ( ! $sent ) {
370 370
 			$header = 'From: ' . $atts['from'] . "\r\n";
371
-            $recipient = implode(',', (array) $recipient);
372
-            $sent = mail($recipient, $atts['subject'], $message, $header);
371
+            $recipient = implode( ',', (array) $recipient );
372
+            $sent = mail( $recipient, $atts['subject'], $message, $header );
373 373
         }
374 374
 
375 375
 		// remove the filter now so other emails can still use it
376 376
 		remove_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' );
377 377
 
378
-        do_action('frm_notification', $recipient, $atts['subject'], $message);
378
+        do_action( 'frm_notification', $recipient, $atts['subject'], $message );
379 379
 
380 380
         if ( $sent ) {
381 381
 			$sent_to = array_merge( (array) $atts['to_email'], (array) $atts['cc'], (array) $atts['bcc'] );
382 382
             $sent_to = array_filter( $sent_to );
383
-            if ( apply_filters('frm_echo_emails', false) ) {
384
-                $temp = str_replace('<', '&lt;', $sent_to);
385
-				echo ' ' . FrmAppHelper::kses( implode(', ', (array) $temp ) );
383
+            if ( apply_filters( 'frm_echo_emails', false ) ) {
384
+                $temp = str_replace( '<', '&lt;', $sent_to );
385
+				echo ' ' . FrmAppHelper::kses( implode( ', ', (array) $temp ) );
386 386
             }
387 387
             return $sent_to;
388 388
         }
Please login to merge, or discard this patch.