| @@ -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,30 +30,44 @@ | ||
| 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) { |
| 44 | - if (strpos($name, 'password') !== false && !empty($value) && trim($value, '*') == '') { | |
| 45 | - continue; | |
| 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 | + } | |
| 46 | 63 | } |
| 47 | - if (strpos($name, 'key') !== false && !empty($value) && strpos($value, '**********') !== false) { | |
| 48 | - continue; | |
| 49 | - } | |
| 50 | 64 | |
| 51 | 65 | if ($name === 'multilingual' && $value === '1') { |
| 52 | 66 | $remindme = json_decode($this->get('remindme', '[]'), true); |
| 53 | 67 | if (!in_array('multilingual', $remindme)) { |
| 54 | 68 | $remindme[] = 'multilingual'; |
| 55 | - $this->save(['remindme' => json_encode($remindme)]); | |
| 69 | + $params[] = '("remindme",'.acym_escapeDB(json_encode($remindme)).')'; | |
| 56 | 70 | } |
| 57 | 71 | } |
| 58 | 72 | |
| 59 | 73 | if (is_array($value)) { |
| @@ -59,15 +73,17 @@ | ||
| 59 | 73 | if (is_array($value)) { |
| 60 | 74 | $value = implode(',', $value); |
| 61 | 75 | } |
| 62 | 76 | |
| 77 | + //We update the current instance in the same time | |
| 63 | 78 | if (empty($this->values[$name])) { |
| 64 | 79 | $this->values[$name] = new \stdClass(); |
| 65 | 80 | } |
| 66 | 81 | $this->values[$name]->value = $value; |
| 67 | 82 | |
| 68 | - if ($escape) { | |
| 69 | - $params[] = '('.acym_escapeDB(strip_tags($name)).','.acym_escapeDB(strip_tags($value)).')'; | |
| 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)).')'; | |
| 70 | 86 | } else { |
| 71 | 87 | $params[] = '('.acym_escapeDB($name).','.acym_escapeDB($value).')'; |
| 72 | 88 | } |
| 73 | 89 | } |
| @@ -74,11 +90,13 @@ | ||
| 74 | 90 | |
| 75 | 91 | $activeCron = $this->get('active_cron', 0); |
| 76 | 92 | $newCronSecurity = $this->get('cron_security', 0); |
| 77 | 93 | $newCronSecurityKey = $this->get('cron_key'); |
| 94 | + // Handle cron key activation or modification while automated tasks are active | |
| 78 | 95 | if (!empty($activeCron) && !empty($newCronSecurity) && (empty($previousCronSecurity) || $previousCronSecurityKey !== $newCronSecurityKey)) { |
| 79 | 96 | $configurationController = new ConfigurationController(); |
| 80 | - if ($configurationController->modifyCron('deactivateCron') !== false) { | |
| 97 | + $deactivationResult = $configurationController->modifyCron('deactivateCron'); | |
| 98 | + if (!empty($deactivationResult)) { | |
| 81 | 99 | $configurationController->modifyCron('activateCron'); |
| 82 | 100 | } |
| 83 | 101 | } |
| 84 | 102 | |
| @@ -85,23 +103,23 @@ | ||
| 85 | 103 | if (empty($params)) { |
| 86 | 104 | return true; |
| 87 | 105 | } |
| 88 | 106 | |
| 89 | - $query .= implode(',', $params); | |
| 90 | - | |
| 91 | 107 | try { |
| 92 | - $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)); | |
| 93 | 110 | } catch (\Exception $e) { |
| 94 | 111 | $status = false; |
| 95 | 112 | } |
| 113 | + | |
| 96 | 114 | if ($status === false) { |
| 97 | - 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'); | |
| 98 | 116 | } |
| 99 | 117 | |
| 100 | - $newFollowupPriority = $this->get('followup_max_priority', 0); | |
| 118 | + $newFollowupPriority = $this->get('followup_max_priority', 0) == 1; | |
| 101 | 119 | |
| 102 | 120 | $mailClass = new MailClass(); |
| 103 | 121 | $mailClass->updateFollowupPriority($oldFollowupPriority, $newFollowupPriority); |
| 104 | 122 | |
| 105 | - return $status; | |
| 123 | + return (bool)$status; | |
| 106 | 124 | } |
| 107 | 125 | } |