PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/dynamics/subscriber/plugin.php +106 -0 11.1.1 → 11.1.0 View file →
@@ -1,0 +1,106 @@
1 +<?php
2 +defined('ABSPATH') || die('Restricted Access');
3 +
4 +use AcyMailing\Helpers\ExportHelper;
5 +use AcyMailing\Core\AcymPlugin;
6 +use AcyMailing\Classes\UserClass;
7 +use AcyMailing\Classes\FieldClass;
8 +use AcyMailing\Classes\AutomationClass;
9 +
10 +require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberAutomationTriggers.php';
11 +require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberAutomationConditions.php';
12 +require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberAutomationFilters.php';
13 +require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberAutomationActions.php';
14 +require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberFollowup.php';
15 +require_once __DIR__.DIRECTORY_SEPARATOR.'SubscriberInsertion.php';
16 +
17 +class plgAcymSubscriber extends AcymPlugin
18 +{
19 + use SubscriberAutomationTriggers;
20 + use SubscriberAutomationConditions;
21 + use SubscriberAutomationFilters;
22 + use SubscriberAutomationActions;
23 + use SubscriberFollowup;
24 + use SubscriberInsertion;
25 +
26 + const FOLLOWUP_USER_CREATION = 'user_creation';
27 + const FOLLOWUP_USER_CONFIRMATION = 'user_confirmation';
28 +
29 + private array $triggerMail = ['user_click', 'user_open'];
30 + private array $triggers = [
31 + 'user_creation' => 'ACYM_ON_USER_CREATION',
32 + 'user_modification' => 'ACYM_ON_USER_MODIFICATION',
33 + 'user_click' => 'ACYM_WHEN_USER_CLICKS_MAIL',
34 + 'user_open' => 'ACYM_WHEN_USER_OPEN_MAIL',
35 + 'user_confirmation' => 'ACYM_WHEN_USER_CONFIRMS_SUBSCRIPTION',
36 + ];
37 +
38 + public function __construct()
39 + {
40 + parent::__construct();
41 + $this->pluginDescription->name = acym_translation('ACYM_SUBSCRIBER');
42 + }
43 +
44 + public function onAcymToggleUserConfirmed($userId, $newValue)
45 + {
46 + if ($newValue == 1) {
47 + $userClass = new UserClass();
48 + $userClass->confirm($userId);
49 + }
50 + }
51 +
52 + public function onAcymDeclareDataSourcesBirthdayTrigger(&$dataSources)
53 + {
54 + $data = [
55 + 'source_name' => 'AcyMailing',
56 + 'fields' => [],
57 + 'no_fields_error_message' => 'ACYM_NO_FIELDS_BIRTHDAY_TRIGGER',
58 + ];
59 +
60 + $fieldClass = new FieldClass();
61 +
62 + $fieldsData = $fieldClass->getMatchingElements(['types' => ['date']]);
63 + $fields = $fieldsData['elements'];
64 +
65 + foreach ($fields as $oneField) {
66 + $data['fields'][] = [
67 + 'name' => $oneField->name,
68 + 'id' => $oneField->id,
69 + 'format' => 'Y-m-d',
70 + 'query' => 'SELECT user_id, value AS date FROM #__acym_user_has_field WHERE field_id = '.intval($oneField->id),
71 + ];
72 + }
73 +
74 + $dataSources['acymailing'] = $data;
75 + }
76 +
77 + public function onBeforeSaveConfigFields(&$newConfig)
78 + {
79 + $fieldToExportOnChange = $this->config->get('export_data_changes_fields', []);
80 + if (empty($fieldToExportOnChange)) {
81 + return;
82 + }
83 +
84 + if (!is_array($fieldToExportOnChange)) {
85 + $fieldToExportOnChange = explode(',', $fieldToExportOnChange);
86 + }
87 +
88 + if (empty($newConfig['export_data_changes_fields'])) {
89 + $newConfig['export_data_changes_fields'] = [];
90 + }
91 +
92 + if ($fieldToExportOnChange == $newConfig['export_data_changes_fields']) {
93 + return;
94 + }
95 +
96 + $exportHelper = new ExportHelper();
97 + $fileExportPath = $exportHelper->getExportChangesFilePath();
98 +
99 + if (!file_exists($fileExportPath)) {
100 + return;
101 + }
102 +
103 + $newFilename = $exportHelper->generateExportChangesFilePathConfigChanges();
104 + acym_moveFile($fileExportPath, $newFilename);
105 + }
106 +}