PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.5
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.5
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
acymailing / back / Classes / ConfigurationClass.php

ConfigurationClass.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.5, at back/Classes/ConfigurationClass.php

126 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Classes;
4
5 use AcyMailing\Controllers\ConfigurationController;
6 use AcyMailing\Core\AcymClass;
7
8 class ConfigurationClass extends AcymClass
9 {
10 private array $values = [];
11
12 public function __construct()
13 {
14 parent::__construct();
15
16 $this->table = 'configuration';
17 $this->pkey = 'name';
18 }
19
20 public function load(): void
21 {
22 $this->values = acym_loadObjectList('SELECT * FROM #__acym_configuration', 'name');
23 }
24
25 public function get(string $namekey, $default = '')
26 {
27 if (isset($this->values[$namekey])) {
28 return $this->values[$namekey]->value;
29 }
30
31 return $default;
32 }
33
34 /**
35 * @param object|array $element
36 *
37 * @Deprecated 10.6.0 No longer used because of type mismatch.
38 * @See ConfigurationClass::saveConfig() as a replacement.
39 */
40 public function save($element): ?int
41 {
42 $this->saveConfig((array)$element);
43
44 return null;
45 }
46
47 public function saveConfig(array $newConfig, bool $escape = true): bool
48 {
49 $oldFollowupPriority = $this->get('followup_max_priority', 0) == 1;
50
51 $previousCronSecurity = $this->get('cron_security', 0);
52 $previousCronSecurityKey = $this->get('cron_key');
53 $params = [];
54 foreach ($newConfig as $name => $value) {
55 //If it's a password containing only * then we just consider the user saved again the config but there is no modification on the password
56 if (!empty($value)) {
57 if (strpos($name, 'password') !== false && trim($value, '*') === '') {
58 continue;
59 }
60 if (strpos($name, 'key') !== false && strpos($value, '**********') !== false) {
61 continue;
62 }
63 }
64
65 if ($name === 'multilingual' && $value === '1') {
66 $remindme = json_decode($this->get('remindme', '[]'), true);
67 if (!in_array('multilingual', $remindme)) {
68 $remindme[] = 'multilingual';
69 $params[] = '("remindme",'.acym_escapeDB(json_encode($remindme)).')';
70 }
71 }
72
73 if (is_array($value)) {
74 $value = implode(',', $value);
75 }
76
77 //We update the current instance in the same time
78 if (empty($this->values[$name])) {
79 $this->values[$name] = new \stdClass();
80 }
81 $this->values[$name]->value = $value;
82
83 // We do a strip tags to avoid HTML injections
84 if ($escape && !is_null($value)) {
85 $params[] = '('.acym_escapeDB(acym_stripTags($name)).','.acym_escapeDB(acym_stripTags($value)).')';
86 } else {
87 $params[] = '('.acym_escapeDB($name).','.acym_escapeDB($value).')';
88 }
89 }
90
91 $activeCron = $this->get('active_cron', 0);
92 $newCronSecurity = $this->get('cron_security', 0);
93 $newCronSecurityKey = $this->get('cron_key');
94 // Handle cron key activation or modification while automated tasks are active
95 if (!empty($activeCron) && !empty($newCronSecurity) && (empty($previousCronSecurity) || $previousCronSecurityKey !== $newCronSecurityKey)) {
96 $configurationController = new ConfigurationController();
97 $deactivationResult = $configurationController->modifyCron('deactivateCron');
98 if (!empty($deactivationResult)) {
99 $configurationController->modifyCron('activateCron');
100 }
101 }
102
103 if (empty($params)) {
104 return true;
105 }
106
107 try {
108 // We do a replace so that values are always kept up to date and added if necessary in the mean time
109 $status = acym_query('REPLACE INTO #__acym_configuration (`name`, `value`) VALUES '.implode(',', $params));
110 } catch (\Exception $e) {
111 $status = false;
112 }
113
114 if ($status === false) {
115 acym_display(isset($e) ? $e->getMessage() : substr(acym_stripTags(acym_getDBError()), 0, 200).'...', 'error');
116 }
117
118 $newFollowupPriority = $this->get('followup_max_priority', 0) == 1;
119
120 $mailClass = new MailClass();
121 $mailClass->updateFollowupPriority($oldFollowupPriority, $newFollowupPriority);
122
123 return (bool)$status;
124 }
125 }
126