| @@ -1,95 +1,0 @@ | ||
| 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 | - const FOLLOWUP_USER_CREATION = 'user_creation'; | |
| 26 | - const FOLLOWUP_USER_CONFIRMATION = 'user_confirmation'; | |
| 27 | - | |
| 28 | - private array $triggerMail = ['user_click', 'user_open']; | |
| 29 | - private array $triggers = [ | |
| 30 | - 'user_creation' => 'ACYM_ON_USER_CREATION', | |
| 31 | - 'user_modification' => 'ACYM_ON_USER_MODIFICATION', | |
| 32 | - 'user_click' => 'ACYM_WHEN_USER_CLICKS_MAIL', | |
| 33 | - 'user_open' => 'ACYM_WHEN_USER_OPEN_MAIL', | |
| 34 | - 'user_confirmation' => 'ACYM_WHEN_USER_CONFIRMS_SUBSCRIPTION', | |
| 35 | - ]; | |
| 36 | - | |
| 37 | - public function __construct() | |
| 38 | - { | |
| 39 | - parent::__construct(); | |
| 40 | - $this->pluginDescription->name = acym_translation('ACYM_SUBSCRIBER'); | |
| 41 | - } | |
| 42 | - | |
| 43 | - public function onAcymToggleUserConfirmed($userId, $newValue) | |
| 44 | - { | |
| 45 | - if ($newValue == 1) { | |
| 46 | - $userClass = new UserClass(); | |
| 47 | - $userClass->confirm($userId); | |
| 48 | - } | |
| 49 | - } | |
| 50 | - | |
| 51 | - public function onAcymDeclareDataSourcesBirthdayTrigger(&$dataSources) | |
| 52 | - { | |
| 53 | - $data = [ | |
| 54 | - 'source_name' => 'AcyMailing', | |
| 55 | - 'fields' => [], | |
| 56 | - 'no_fields_error_message' => 'ACYM_NO_FIELDS_BIRTHDAY_TRIGGER', | |
| 57 | - ]; | |
| 58 | - | |
| 59 | - $fieldClass = new FieldClass(); | |
| 60 | - | |
| 61 | - $fieldsData = $fieldClass->getMatchingElements(['types' => ['date']]); | |
| 62 | - $fields = $fieldsData['elements']; | |
| 63 | - | |
| 64 | - foreach ($fields as $oneField) { | |
| 65 | - $data['fields'][] = [ | |
| 66 | - 'name' => $oneField->name, | |
| 67 | - 'id' => $oneField->id, | |
| 68 | - 'format' => 'Y-m-d', | |
| 69 | - 'query' => 'SELECT user_id, value AS date FROM #__acym_user_has_field WHERE field_id = '.intval($oneField->id), | |
| 70 | - ]; | |
| 71 | - } | |
| 72 | - | |
| 73 | - $dataSources['acymailing'] = $data; | |
| 74 | - } | |
| 75 | - | |
| 76 | - public function onBeforeSaveConfigFields(&$newConfig) | |
| 77 | - { | |
| 78 | - $fieldToExportOnChange = $this->config->get('export_data_changes_fields', []); | |
| 79 | - if (empty($fieldToExportOnChange)) return; | |
| 80 | - | |
| 81 | - if (!is_array($fieldToExportOnChange)) $fieldToExportOnChange = explode(',', $fieldToExportOnChange); | |
| 82 | - | |
| 83 | - if (empty($newConfig['export_data_changes_fields'])) $newConfig['export_data_changes_fields'] = []; | |
| 84 | - | |
| 85 | - if ($fieldToExportOnChange == $newConfig['export_data_changes_fields']) return; | |
| 86 | - | |
| 87 | - $exportHelper = new ExportHelper(); | |
| 88 | - $fileExportPath = $exportHelper->getExportChangesFilePath(); | |
| 89 | - | |
| 90 | - if (!file_exists($fileExportPath)) return; | |
| 91 | - | |
| 92 | - $newFilename = $exportHelper->generateExportChangesFilePathConfigChanges(); | |
| 93 | - @rename($fileExportPath, $newFilename); | |
| 94 | - } | |
| 95 | -} | |