| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Services\FormBuilder\Notifications; |
| 4 |
|
| 5 |
use FluentForm\Framework\Foundation\Application; |
| 6 |
use FluentForm\Framework\Helpers\ArrayHelper; |
| 7 |
|
| 8 |
class EmailNotificationActions |
| 9 |
{ |
| 10 |
protected $app = null; |
| 11 |
|
| 12 |
public function __construct(Application $app) |
| 13 |
{ |
| 14 |
$this->app = $app; |
| 15 |
} |
| 16 |
|
| 17 |
public function register() |
| 18 |
{ |
| 19 |
add_filter('fluentform_notifying_async_email_notifications', '__return_false', 9); |
| 20 |
|
| 21 |
add_filter('fluentform_global_notification_active_types', function ($types) { |
| 22 |
$types['notifications'] = 'email_notifications'; |
| 23 |
return $types; |
| 24 |
}); |
| 25 |
|
| 26 |
add_action('fluentform_integration_notify_notifications', array($this, 'notify'), 10, 4); |
| 27 |
} |
| 28 |
|
| 29 |
public function notify($feed, $formData, $entry, $form) |
| 30 |
{ |
| 31 |
$notifier = $this->app->make( |
| 32 |
'FluentForm\App\Services\FormBuilder\Notifications\EmailNotification' |
| 33 |
); |
| 34 |
|
| 35 |
$emailData = $feed['processedValues']; |
| 36 |
|
| 37 |
$emailAttachments = []; |
| 38 |
if(!empty($emailData['attachments']) && is_array($emailData['attachments'])) { |
| 39 |
$attachments = []; |
| 40 |
foreach ($emailData['attachments'] as $name) { |
| 41 |
$fileUrls = ArrayHelper::get($formData, $name); |
| 42 |
if($fileUrls && is_array($fileUrls)) { |
| 43 |
foreach ($fileUrls as $url) { |
| 44 |
$filePath = str_replace( |
| 45 |
site_url(''), |
| 46 |
wp_normalize_path( untrailingslashit( ABSPATH ) ), |
| 47 |
$url |
| 48 |
); |
| 49 |
if(file_exists($filePath)) { |
| 50 |
$attachments[] = $filePath; |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
$emailAttachments = $attachments; |
| 56 |
} |
| 57 |
|
| 58 |
// let others to apply attachments |
| 59 |
$emailAttachments = apply_filters('fluentform_email_attachments', $emailAttachments, $emailData, $formData, $entry, $form); |
| 60 |
if($emailAttachments) { |
| 61 |
$emailData['attachments'] = $emailAttachments; |
| 62 |
} |
| 63 |
|
| 64 |
$notifier->notify($emailData, $formData, $form, $entry->id); |
| 65 |
} |
| 66 |
} |
| 67 |
|