| 1 |
<?php |
| 2 |
|
| 3 |
use AcyMailing\Helpers\ExportHelper; |
| 4 |
use AcyMailing\Core\AcymPlugin; |
| 5 |
use AcyMailing\Classes\UserClass; |
| 6 |
use AcyMailing\Classes\FieldClass; |
| 7 |
use AcyMailing\Classes\AutomationClass; |
| 8 |
|
| 9 |
require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberAutomationTriggers.php'; |
| 10 |
require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberAutomationConditions.php'; |
| 11 |
require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberAutomationFilters.php'; |
| 12 |
require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberAutomationActions.php'; |
| 13 |
require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberFollowup.php'; |
| 14 |
require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberInsertion.php'; |
| 15 |
|
| 16 |
class plgAcymSubscriber extends AcymPlugin |
| 17 |
{ |
| 18 |
use SubscriberAutomationTriggers; |
| 19 |
use SubscriberAutomationConditions; |
| 20 |
use SubscriberAutomationFilters; |
| 21 |
use SubscriberAutomationActions; |
| 22 |
use SubscriberFollowup; |
| 23 |
use SubscriberInsertion; |
| 24 |
|
| 25 |
private string $followTriggerName = 'user_creation'; |
| 26 |
private array $triggerMail = ['user_click', 'user_open']; |
| 27 |
private array $triggers = [ |
| 28 |
'user_creation' => 'ACYM_ON_USER_CREATION', |
| 29 |
'user_modification' => 'ACYM_ON_USER_MODIFICATION', |
| 30 |
'user_click' => 'ACYM_WHEN_USER_CLICKS_MAIL', |
| 31 |
'user_open' => 'ACYM_WHEN_USER_OPEN_MAIL', |
| 32 |
'user_confirmation' => 'ACYM_WHEN_USER_CONFIRMS_SUBSCRIPTION', |
| 33 |
]; |
| 34 |
|
| 35 |
public function __construct() |
| 36 |
{ |
| 37 |
parent::__construct(); |
| 38 |
$this->pluginDescription->name = acym_translation('ACYM_SUBSCRIBER'); |
| 39 |
} |
| 40 |
|
| 41 |
public function onAcymToggleUserConfirmed($userId, $newValue) |
| 42 |
{ |
| 43 |
if ($newValue == 1) { |
| 44 |
$userClass = new UserClass(); |
| 45 |
$userClass->confirm($userId); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
public function onAcymDeclareDataSourcesBirthdayTrigger(&$dataSources) |
| 50 |
{ |
| 51 |
$data = [ |
| 52 |
'source_name' => 'AcyMailing', |
| 53 |
'fields' => [], |
| 54 |
'no_fields_error_message' => 'ACYM_NO_FIELDS_BIRTHDAY_TRIGGER', |
| 55 |
]; |
| 56 |
|
| 57 |
$fieldClass = new FieldClass(); |
| 58 |
|
| 59 |
$fieldsData = $fieldClass->getMatchingElements(['types' => ['date']]); |
| 60 |
$fields = $fieldsData['elements']; |
| 61 |
|
| 62 |
foreach ($fields as $oneField) { |
| 63 |
$data['fields'][] = [ |
| 64 |
'name' => $oneField->name, |
| 65 |
'id' => $oneField->id, |
| 66 |
'format' => 'Y-m-d', |
| 67 |
'query' => 'SELECT user_id, value AS date FROM #__acym_user_has_field WHERE field_id = '.intval($oneField->id), |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
$dataSources['acymailing'] = $data; |
| 72 |
} |
| 73 |
|
| 74 |
public function onBeforeSaveConfigFields(&$newConfig) |
| 75 |
{ |
| 76 |
$fieldToExportOnChange = $this->config->get('export_data_changes_fields', []); |
| 77 |
if (empty($fieldToExportOnChange)) return; |
| 78 |
|
| 79 |
if (!is_array($fieldToExportOnChange)) $fieldToExportOnChange = explode(',', $fieldToExportOnChange); |
| 80 |
|
| 81 |
if (empty($newConfig['export_data_changes_fields'])) $newConfig['export_data_changes_fields'] = []; |
| 82 |
|
| 83 |
if ($fieldToExportOnChange == $newConfig['export_data_changes_fields']) return; |
| 84 |
|
| 85 |
$exportHelper = new ExportHelper(); |
| 86 |
$fileExportPath = $exportHelper->getExportChangesFilePath(); |
| 87 |
|
| 88 |
if (!file_exists($fileExportPath)) return; |
| 89 |
|
| 90 |
$newFilename = $exportHelper->generateExportChangesFilePathConfigChanges(); |
| 91 |
@rename($fileExportPath, $newFilename); |
| 92 |
} |
| 93 |
} |
| 94 |
|