From 53a076d2889212e18472271b210802f0e87c8b17 Mon Sep 17 00:00:00 2001 From: progress44 Date: Sat, 26 Oct 2019 01:11:57 +0200 Subject: [PATCH] [+] Fixed latest smudges --- classes/options.php | 4 ++-- classes/sink.php | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/classes/options.php b/classes/options.php index 94ae411..2a25f3a 100644 --- a/classes/options.php +++ b/classes/options.php @@ -150,8 +150,8 @@ public function loadOptions() continue; } - $config['value'] = $this->getValueForOption($config); - if ($config['required'] && empty($config['value'])) { + $this->config_map[$key]['value'] = $this->getValueForOption($config); + if ($this->config_map[$key]['required'] && empty($this->config_map[$key]['value'])) { $continue = false; } } diff --git a/classes/sink.php b/classes/sink.php index a8dd73d..3a17e1b 100644 --- a/classes/sink.php +++ b/classes/sink.php @@ -66,6 +66,7 @@ public function __construct() } $options = $this->options->loadOptions(); + if (!$options) { $this->ui->renderNotice('notice-error', 'Plugin not loaded, missing configuration'); return; @@ -87,16 +88,16 @@ private function getS3Client() { $config = [ 'version' => 'latest', - 'region' => $this->config_map[0], + 'region' => $this->config_map[0]['value'], 'credentials' => [ - 'key' => $this->config_map[2], - 'secret' => $this->config_map[3], + 'key' => $this->config_map[2]['value'], + 'secret' => $this->config_map[3]['value'], ] ]; - if (! empty($this->config_map[7])) { + if (! empty($this->config_map[7]['value'])) { $config['http'] = [ - 'proxy' => $this->config_map[7].':'.$this->config_map[8], + 'proxy' => $this->config_map[7]['value'].':'.$this->config_map[8]['value'], ]; } @@ -133,18 +134,19 @@ public function createDefaultDir($dir, $key) try { if (!file_exists($dir.$key)) { mkdir($dir.$key); + die; } // Moved because it should always create the directory first. - if (! empty($this->config_map[6])) { - return $this->config_map[6]; + if (! empty($this->config_map[6]['value'])) { + return $this->config_map[6]['value']; } - if (true == $this->config_map[5]) { + if (true == $this->config_map[5]['value']) { return WP_SITEURL; } - $result = $client->getObjectUrl($this->config_map[1], $key); + $result = $client->getObjectUrl($this->config_map[1]['value'], $key); } catch (\Exception $e) { if (is_admin()) { $this->ui->renderNotice('notice-error', 'There was an error while configuring S3'); @@ -164,9 +166,8 @@ public function setUploadDir($uploads) { // Instantiate an Amazon S3 client. $client = $this->registerS3StreamWrapper(); - - $dir = "s3://".$this->config_map[1]."/"; - $key = $this->config_map['4'] ? $this->config_map['4'] : $this->default_uploads_folder; + $dir = "s3://".$this->config_map[1]['value']."/"; + $key = $this->config_map['4']['value'] ?: $this->default_uploads_folder; $result = $this->createDefaultDir($dir, $key); $uploads = array_merge(