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