PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.2
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 10.10.2, at back/Classes/ConfigurationClass.php

115 lines 3.6 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 public function save($element): ?int
35 {
36 $this->saveConfig((array)$element);
37
38 return null;
39 }
40
41 public function saveConfig(array $newConfig, bool $escape = true): bool
42 {
43 $oldFollowupPriority = $this->get('followup_max_priority', 0) == 1;
44
45 $previousCronSecurity = $this->get('cron_security', 0);
46 $previousCronSecurityKey = $this->get('cron_key');
47 $params = [];
48 foreach ($newConfig as $name => $value) {
49 if (!empty($value)) {
50 if (strpos($name, 'password') !== false && trim($value, '*') === '') {
51 continue;
52 }
53 if (strpos($name, 'key') !== false && strpos($value, '**********') !== false) {
54 continue;
55 }
56 }
57
58 if ($name === 'multilingual' && $value === '1') {
59 $remindme = json_decode($this->get('remindme', '[]'), true);
60 if (!in_array('multilingual', $remindme)) {
61 $remindme[] = 'multilingual';
62 $params[] = '("remindme",'.acym_escapeDB(json_encode($remindme)).')';
63 }
64 }
65
66 if (is_array($value)) {
67 $value = implode(',', $value);
68 }
69
70 if (empty($this->values[$name])) {
71 $this->values[$name] = new \stdClass();
72 }
73 $this->values[$name]->value = $value;
74
75 if ($escape && !is_null($value)) {
76 $params[] = '('.acym_escapeDB(strip_tags($name)).','.acym_escapeDB(strip_tags($value)).')';
77 } else {
78 $params[] = '('.acym_escapeDB($name).','.acym_escapeDB($value).')';
79 }
80 }
81
82 $activeCron = $this->get('active_cron', 0);
83 $newCronSecurity = $this->get('cron_security', 0);
84 $newCronSecurityKey = $this->get('cron_key');
85 if (!empty($activeCron) && !empty($newCronSecurity) && (empty($previousCronSecurity) || $previousCronSecurityKey !== $newCronSecurityKey)) {
86 $configurationController = new ConfigurationController();
87 $deactivationResult = $configurationController->modifyCron('deactivateCron');
88 if (!empty($deactivationResult)) {
89 $configurationController->modifyCron('activateCron');
90 }
91 }
92
93 if (empty($params)) {
94 return true;
95 }
96
97 try {
98 $status = acym_query('REPLACE INTO #__acym_configuration (`name`, `value`) VALUES '.implode(',', $params));
99 } catch (\Exception $e) {
100 $status = false;
101 }
102
103 if ($status === false) {
104 acym_display(isset($e) ? $e->getMessage() : substr(strip_tags(acym_getDBError()), 0, 200).'...', 'error');
105 }
106
107 $newFollowupPriority = $this->get('followup_max_priority', 0) == 1;
108
109 $mailClass = new MailClass();
110 $mailClass->updateFollowupPriority($oldFollowupPriority, $newFollowupPriority);
111
112 return (bool)$status;
113 }
114 }
115