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/Classes/ConfigurationClass.php +29 -14 10.2.2 → 11.1.0 View file →
@@ -6,9 +6,9 @@
6 6 use AcyMailing\Core\AcymClass;
7 7
8 8 class ConfigurationClass extends AcymClass
9 9 {
10 - private $values = [];
10 + private array $values = [];
11 11
12 12 public function __construct()
13 13 {
14 14 parent::__construct();
@@ -16,14 +16,14 @@
16 16 $this->table = 'configuration';
17 17 $this->pkey = 'name';
18 18 }
19 19
20 - public function load()
20 + public function load(): void
21 21 {
22 22 $this->values = acym_loadObjectList('SELECT * FROM #__acym_configuration', 'name');
23 23 }
24 24
25 - public function get($namekey, $default = '')
25 + public function get(string $namekey, $default = '')
26 26 {
27 27 if (isset($this->values[$namekey])) {
28 28 return $this->values[$namekey]->value;
29 29 }
@@ -30,18 +30,30 @@
30 30
31 31 return $default;
32 32 }
33 33
34 - public function save($newConfig, $escape = true)
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
35 41 {
36 - $oldFollowupPriority = $this->get('followup_max_priority', 0);
42 + $this->saveConfig((array)$element);
37 43
38 - $query = 'REPLACE INTO #__acym_configuration (`name`, `value`) VALUES ';
44 + return null;
45 + }
39 46
47 + public function saveConfig(array $newConfig, bool $escape = true): bool
48 + {
49 + $oldFollowupPriority = $this->get('followup_max_priority', 0) == 1;
50 +
40 51 $previousCronSecurity = $this->get('cron_security', 0);
41 52 $previousCronSecurityKey = $this->get('cron_key');
42 53 $params = [];
43 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
44 56 if (!empty($value)) {
45 57 if (strpos($name, 'password') !== false && trim($value, '*') === '') {
46 58 continue;
47 59 }
@@ -53,9 +65,9 @@
53 65 if ($name === 'multilingual' && $value === '1') {
54 66 $remindme = json_decode($this->get('remindme', '[]'), true);
55 67 if (!in_array('multilingual', $remindme)) {
56 68 $remindme[] = 'multilingual';
57 - $this->save(['remindme' => json_encode($remindme)]);
69 + $params[] = '("remindme",'.acym_escapeDB(json_encode($remindme)).')';
58 70 }
59 71 }
60 72
61 73 if (is_array($value)) {
@@ -61,15 +73,17 @@
61 73 if (is_array($value)) {
62 74 $value = implode(',', $value);
63 75 }
64 76
77 + //We update the current instance in the same time
65 78 if (empty($this->values[$name])) {
66 79 $this->values[$name] = new \stdClass();
67 80 }
68 81 $this->values[$name]->value = $value;
69 82
83 + // We do a strip tags to avoid HTML injections
70 84 if ($escape && !is_null($value)) {
71 - $params[] = '('.acym_escapeDB(strip_tags($name)).','.acym_escapeDB(strip_tags($value)).')';
85 + $params[] = '('.acym_escapeDB(acym_stripTags($name)).','.acym_escapeDB(acym_stripTags($value)).')';
72 86 } else {
73 87 $params[] = '('.acym_escapeDB($name).','.acym_escapeDB($value).')';
74 88 }
75 89 }
@@ -76,8 +90,9 @@
76 90
77 91 $activeCron = $this->get('active_cron', 0);
78 92 $newCronSecurity = $this->get('cron_security', 0);
79 93 $newCronSecurityKey = $this->get('cron_key');
94 + // Handle cron key activation or modification while automated tasks are active
80 95 if (!empty($activeCron) && !empty($newCronSecurity) && (empty($previousCronSecurity) || $previousCronSecurityKey !== $newCronSecurityKey)) {
81 96 $configurationController = new ConfigurationController();
82 97 $deactivationResult = $configurationController->modifyCron('deactivateCron');
83 98 if (!empty($deactivationResult)) {
@@ -88,23 +103,23 @@
88 103 if (empty($params)) {
89 104 return true;
90 105 }
91 106
92 - $query .= implode(',', $params);
93 -
94 107 try {
95 - $status = acym_query($query);
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));
96 110 } catch (\Exception $e) {
97 111 $status = false;
98 112 }
113 +
99 114 if ($status === false) {
100 - acym_display(isset($e) ? $e->getMessage() : substr(strip_tags(acym_getDBError()), 0, 200).'...', 'error');
115 + acym_display(isset($e) ? $e->getMessage() : substr(acym_stripTags(acym_getDBError()), 0, 200).'...', 'error');
101 116 }
102 117
103 - $newFollowupPriority = $this->get('followup_max_priority', 0);
118 + $newFollowupPriority = $this->get('followup_max_priority', 0) == 1;
104 119
105 120 $mailClass = new MailClass();
106 121 $mailClass->updateFollowupPriority($oldFollowupPriority, $newFollowupPriority);
107 122
108 - return $status;
123 + return (bool)$status;
109 124 }
110 125 }