From 8bc29074486f88fcf50e57495e2774d78074ee7f Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Mon, 1 May 2017 16:54:55 -0400 Subject: [PATCH 01/16] Fix compatibility php 7 strict mode. --- extension.driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index ace31c0..e06aa21 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -2,8 +2,8 @@ if (!defined('__IN_SYMPHONY__')) die('

Symphony Error

You cannot directly access this file

'); - define_safe(IMAGE_UPLOAD_NAME, 'Image Upload'); - define_safe(IMAGE_UPLOAD_GROUP, 'image_upload'); + define_safe('IMAGE_UPLOAD_NAME', 'Image Upload'); + define_safe('IMAGE_UPLOAD_GROUP', 'image_upload'); class extension_image_upload extends Extension { From d44abcde454c076565f924b26981836aabbdd658 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Mon, 1 May 2017 17:01:35 -0400 Subject: [PATCH 02/16] Update release version --- extension.meta.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extension.meta.xml b/extension.meta.xml index 43fd2d6..5a0a6f9 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -24,6 +24,9 @@ https://github.com/symphonycms/jit_image_manipulation + Date: Wed, 17 May 2017 10:58:11 -0400 Subject: [PATCH 03/16] Update php-min/php-max info --- extension.meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index 5a0a6f9..61cfe6f 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -24,7 +24,7 @@ https://github.com/symphonycms/jit_image_manipulation - Date: Fri, 19 May 2017 13:55:26 -0400 Subject: [PATCH 04/16] Format dependencies properly. --- extension.meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index 61cfe6f..55bddad 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -21,7 +21,7 @@ - https://github.com/symphonycms/jit_image_manipulation + jit_image_manipulation Date: Tue, 30 May 2017 15:47:17 -0400 Subject: [PATCH 05/16] Make extension work without JIT --- extension.meta.xml | 3 --- fields/field.image_upload.php | 13 ++++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/extension.meta.xml b/extension.meta.xml index 55bddad..f6d4245 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -20,9 +20,6 @@ https://deuxhuithuit.com/ - - jit_image_manipulation - get('max_width'); $sizes[__('Max height')] = $this->get('max_height'); } - + foreach($sizes as $key => $size) { if (!empty($size) && $size != 0) { $sizeMessage .= $key.': '.$size.'px, '; @@ -532,8 +532,11 @@ public function prepareTableValue($data, XMLElement $link = null, $entry_id = nu $destination = str_replace('/workspace', '', $this->get('destination')) . '/'; + $extman = Symphony::ExtensionManager(); + $status = $extman->fetchStatus(array('handle' => 'jit_image_manipulation')); + $src = ''; - if (isset($data['mimetype']) && self::isSvg($data['mimetype'])) { + if ((isset($data['mimetype']) && self::isSvg($data['mimetype'])) || !in_array(EXTENSION_ENABLED, $status)) { $src = URL . '/workspace' . $destination . $file; } else { From 9da3cbe6557d869208f11435895a07490f868153 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 30 May 2017 16:03:52 -0400 Subject: [PATCH 06/16] Remove unnecessary inline style on images --- fields/field.image_upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fields/field.image_upload.php b/fields/field.image_upload.php index fd0df7a..fa926f5 100644 --- a/fields/field.image_upload.php +++ b/fields/field.image_upload.php @@ -542,7 +542,7 @@ public function prepareTableValue($data, XMLElement $link = null, $entry_id = nu else { $src = URL . '/image/1/' . $width . '/' . $height . $destination . $file; } - $image = ''.$this->get('label').' of Entry '.$entry_id.''; + $image = ''.$this->get('label').' of Entry '.$entry_id.''; if ($link) { $link->setValue($image); From 1fe4d3ed8c22d3794bee9ee87b5b1e15017f2a08 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 31 May 2017 16:36:39 -0400 Subject: [PATCH 07/16] Fix i value setting --- fields/field.image_upload.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fields/field.image_upload.php b/fields/field.image_upload.php index fa926f5..7ed3d4d 100644 --- a/fields/field.image_upload.php +++ b/fields/field.image_upload.php @@ -466,13 +466,9 @@ public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWit if ($label != null) { // try to find the i element $i = $this->getChildrenWithClass($wrapper, null, 'i'); - if ($i == null) { - // create one and prepend it if nothing found - $i = new XMLElement('i'); - $label->prependChild($i); + if ($i != null) { + $i->setValue(' '.$this->generateHelpMessage()); } - - $i->setValue(' '.$this->generateHelpMessage()); } } @@ -548,7 +544,7 @@ public function prepareTableValue($data, XMLElement $link = null, $entry_id = nu $link->setValue($image); } else{ - $link = Widget::Anchor($image, URL.$this->get('destination').'/'.$file); + $link = Widget::Anchor($image, URL.$this->get('destination').'/'.$file, null, null, null, array('target' => '_blank')); } $link->setAttribute('data-path', $this->get('destination')); return $link->generate(); From 94141e39ebdd836c2cd4e91ac086d76b1c20d435 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 24 Aug 2017 15:41:35 -0400 Subject: [PATCH 08/16] SQL and PHP cases PHP true,false,null in lowercase SQL keywords uppercase --- extension.driver.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index e06aa21..3e41994 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -15,16 +15,16 @@ public function install() { return Symphony::Database()->query( "CREATE TABLE `tbl_fields_image_upload` ( - `id` int(11) unsigned NOT NULL auto_increment, - `field_id` int(11) unsigned NOT NULL, - `destination` varchar(255) NOT NULL, - `validator` varchar(50), - `unique` varchar(50), - `min_width` int(11) unsigned, - `min_height` int(11) unsigned, - `max_width` int(11) unsigned, - `max_height` int(11) unsigned, - `resize` enum('yes','no') NOT NULL DEFAULT 'yes', + `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `field_id` INT(11) UNSIGNED NOT NULL, + `destination` VARCHAR(255) NOT NULL, + `validator` VARCHAR(50), + `unique` VARCHAR(50), + `min_width` INT(11) UNSIGNED, + `min_height` INT(11) UNSIGNED, + `max_width` INT(11) UNSIGNED, + `max_height` INT(11) UNSIGNED, + `resize` ENUM('yes','no') NOT NULL DEFAULT 'yes', PRIMARY KEY (`id`), KEY `field_id` (`field_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" @@ -38,8 +38,8 @@ public function update($previousVersion = false) { // Before 1.1 if ($ret && version_compare($previousVersion, '1.1', '<')) { $query = "ALTER TABLE `tbl_fields_image_upload` - ADD `max_width` int(11) unsigned, - ADD `max_height` int(11) unsigned, + ADD `max_width` INT(11) UNSIGNED, + ADD `max_height` INT(11) UNSIGNED, DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; try { @@ -52,7 +52,7 @@ public function update($previousVersion = false) { // Before 1.3 if ($ret && version_compare($previousVersion, '1.3', '<')) { $query = "ALTER TABLE `tbl_fields_image_upload` - ADD COLUMN `resize` enum('yes','no') NOT NULL DEFAULT 'yes'"; + ADD COLUMN `resize` ENUM('yes','no') NOT NULL DEFAULT 'yes'"; try { $ret = Symphony::Database()->query($query); } From e3044f83201e708ee91bd3183083ba009e9fb509 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 29 May 2018 16:12:49 -0400 Subject: [PATCH 09/16] Code refactoring for Database and EQFA --- extension.driver.php | 107 ++++++++++++++++++++++++++----------------- extension.meta.xml | 1 + 2 files changed, 67 insertions(+), 41 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 3e41994..7484eeb 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -13,22 +13,36 @@ class extension_image_upload extends Extension public function install() { - return Symphony::Database()->query( - "CREATE TABLE `tbl_fields_image_upload` ( - `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `field_id` INT(11) UNSIGNED NOT NULL, - `destination` VARCHAR(255) NOT NULL, - `validator` VARCHAR(50), - `unique` VARCHAR(50), - `min_width` INT(11) UNSIGNED, - `min_height` INT(11) UNSIGNED, - `max_width` INT(11) UNSIGNED, - `max_height` INT(11) UNSIGNED, - `resize` ENUM('yes','no') NOT NULL DEFAULT 'yes', - PRIMARY KEY (`id`), - KEY `field_id` (`field_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" - ); + return Symphony::Database() + ->create('tbl_fields_image_upload') + ->ifNotExists() + ->charset('utf8') + ->collate('utf8_unicode_ci') + ->fields([ + 'id' => [ + 'type' => 'int(11)', + 'auto' => true, + ], + 'field_id' => 'int(11)', + 'destination' => 'varchar(255)', + 'validator' => 'varchar(50)', + 'unique' => 'varchar(50)', + 'min_width' => 'int(11)', + 'min_height' => 'int(11)', + 'max_width' => 'int(11)', + 'max_height' => 'int(11)', + 'resize' => [ + 'type' => 'enum', + 'values' => ['yes','no'], + 'default' => 'yes' + ], + ]) + ->keys([ + 'id' => 'primary', + 'field_id' => 'key', + ]) + ->execute() + ->success(); } public function update($previousVersion = false) { @@ -37,41 +51,49 @@ public function update($previousVersion = false) { // Before 1.1 if ($ret && version_compare($previousVersion, '1.1', '<')) { - $query = "ALTER TABLE `tbl_fields_image_upload` - ADD `max_width` INT(11) UNSIGNED, - ADD `max_height` INT(11) UNSIGNED, - DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; - - try { - Symphony::Database()->query($query); - } - catch (Exception $e) { - } + Symphony::Database() + ->alter('tbl_fields_image_upload') + ->add([ + 'max_width' => 'int(11)', + 'max_height' => 'int(11)', + ]) + ->execute() + ->success(); } // Before 1.3 if ($ret && version_compare($previousVersion, '1.3', '<')) { - $query = "ALTER TABLE `tbl_fields_image_upload` - ADD COLUMN `resize` ENUM('yes','no') NOT NULL DEFAULT 'yes'"; - try { - $ret = Symphony::Database()->query($query); - } - catch (Exception $e) { - // ignore ? - } + Symphony::Database() + ->alter('tbl_fields_image_upload') + ->add([ + 'resize' => [ + 'type' => 'enum', + 'values' => ['yes','no'], + 'default' => 'yes', + ], + ]) + ->execute() + ->success(); } // Before 1.4 if ($ret && version_compare($previousVersion, '1.4', '<')) { // Remove directory from the upload fields, #1719 - $upload_tables = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_image_upload`"); + $upload_tables = Symphony::Database() + ->select('field_id') + ->from('tbl_fields_image_upload') + ->execute() + ->column('field_id'); if (is_array($upload_tables) && !empty($upload_tables)) { foreach($upload_tables as $field) { - Symphony::Database()->query(sprintf( - "UPDATE tbl_entries_data_%d SET file = substring_index(file, '/', -1)", - $field - )); + Symphony::Database() + ->update("tbl_entries_data_$field") + ->set([ + 'file' => "substring_index(file, '/', -1)", + ]) + ->execute() + ->success(); } } } @@ -80,7 +102,10 @@ public function update($previousVersion = false) { } public function uninstall() { - return Symphony::Database()->query("DROP TABLE `tbl_fields_image_upload`"); + return Symphony::Database() + ->drop('tbl_fields_image_upload') + ->ifExists() + ->execute() + ->success(); } - } diff --git a/extension.meta.xml b/extension.meta.xml index f6d4245..417babe 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -23,6 +23,7 @@ Date: Wed, 30 May 2018 16:29:10 -0400 Subject: [PATCH 10/16] Fix select structure --- extension.driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.driver.php b/extension.driver.php index 7484eeb..09cf616 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -80,7 +80,7 @@ public function update($previousVersion = false) { if ($ret && version_compare($previousVersion, '1.4', '<')) { // Remove directory from the upload fields, #1719 $upload_tables = Symphony::Database() - ->select('field_id') + ->select(['field_id']) ->from('tbl_fields_image_upload') ->execute() ->column('field_id'); From cb9e42914a712ba6528d1ce325bd17e39c798fac Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 6 Jun 2018 10:19:47 -0400 Subject: [PATCH 11/16] Fix fetchStatus on JIT --- fields/field.image_upload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fields/field.image_upload.php b/fields/field.image_upload.php index 7ed3d4d..0a5a247 100644 --- a/fields/field.image_upload.php +++ b/fields/field.image_upload.php @@ -37,10 +37,10 @@ public function __construct() */ public static function resize($file, $width, $height, $mimetype) { - $jit_status = ExtensionManager::fetchStatus(array('handle' => 'jit_image_manipulation')); + $jit_status = Symphony::ExtensionManager()->fetchStatus(array('handle' => 'jit_image_manipulation')); // process image using JIT mode 1 - if ($jit_status[0] === EXTENSION_ENABLED) { + if ($jit_status[0] === Extension::EXTENSION_ENABLED) { require_once(EXTENSIONS.'/jit_image_manipulation/lib/class.image.php'); try { From 0f3136fae0b609218e2059e08ed143158603521e Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 7 Jun 2018 15:44:58 -0400 Subject: [PATCH 12/16] Fix dependency status --- fields/field.image_upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fields/field.image_upload.php b/fields/field.image_upload.php index 0a5a247..72aa116 100644 --- a/fields/field.image_upload.php +++ b/fields/field.image_upload.php @@ -532,7 +532,7 @@ public function prepareTableValue($data, XMLElement $link = null, $entry_id = nu $status = $extman->fetchStatus(array('handle' => 'jit_image_manipulation')); $src = ''; - if ((isset($data['mimetype']) && self::isSvg($data['mimetype'])) || !in_array(EXTENSION_ENABLED, $status)) { + if ((isset($data['mimetype']) && self::isSvg($data['mimetype'])) || !in_array(Extension::EXTENSION_ENABLED, $status)) { $src = URL . '/workspace' . $destination . $file; } else { From 7e614069331e1157b5161ae5a6290f94dc8bc089 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 11 Dec 2018 15:46:08 -0500 Subject: [PATCH 13/16] Add svg mimetype case. --- fields/field.image_upload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/fields/field.image_upload.php b/fields/field.image_upload.php index 72aa116..17ed149 100644 --- a/fields/field.image_upload.php +++ b/fields/field.image_upload.php @@ -9,6 +9,7 @@ class fieldImage_upload extends fieldUpload protected static $svgMimeTypes = array( 'image/svg+xml', 'image/svg', + 'text/plain', ); /*------------------------------------------------------------------------------------------------*/ From 341694a08a2073bc9540515cd265e421237431a9 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 13 Dec 2018 14:52:45 -0500 Subject: [PATCH 14/16] Add svg mimetype case. --- fields/field.image_upload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/fields/field.image_upload.php b/fields/field.image_upload.php index 17ed149..3bb3465 100644 --- a/fields/field.image_upload.php +++ b/fields/field.image_upload.php @@ -10,6 +10,7 @@ class fieldImage_upload extends fieldUpload 'image/svg+xml', 'image/svg', 'text/plain', + 'application/octet-stream', ); /*------------------------------------------------------------------------------------------------*/ From 8b4ff41ef7756d9517bea447b66a9d05167238fd Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 18 Dec 2018 09:44:27 -0500 Subject: [PATCH 15/16] Remote SQL collate and charset definitions. --- extension.driver.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 09cf616..bc525be 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -16,8 +16,6 @@ public function install() return Symphony::Database() ->create('tbl_fields_image_upload') ->ifNotExists() - ->charset('utf8') - ->collate('utf8_unicode_ci') ->fields([ 'id' => [ 'type' => 'int(11)', From f89b233904206f77de362415a9d4bffb74286302 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 17 Jan 2019 13:15:34 -0500 Subject: [PATCH 16/16] Apply patch by @nitriques. --- fields/field.image_upload.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fields/field.image_upload.php b/fields/field.image_upload.php index 3bb3465..a89f026 100644 --- a/fields/field.image_upload.php +++ b/fields/field.image_upload.php @@ -289,10 +289,10 @@ public function commit() $settings['destination'] = $this->get('destination'); $settings['validator'] = ($settings['validator'] == 'custom' ? null : $this->get('validator')); $settings['unique'] = $this->get('unique'); - $settings['min_width'] = $this->get('min_width'); - $settings['min_height'] = $this->get('min_height'); - $settings['max_width'] = $this->get('max_width'); - $settings['max_height'] = $this->get('max_height'); + $settings['min_width'] = (int)$this->get('min_width'); + $settings['min_height'] = (int)$this->get('min_height'); + $settings['max_width'] = (int)$this->get('max_width'); + $settings['max_height'] = (int)$this->get('max_height'); $settings['resize'] = $this->get('resize') == 'yes' ? 'yes' : 'no'; return FieldManager::saveSettings($id, $settings);