Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions assets/image_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
resize: 1,
position: 5,
absolute: false,
isDefault: true
isDefault: true,
isJIT: false
};

var params = {
Expand All @@ -33,7 +34,6 @@
var SVG = '.svg';

var createUrl = function (imgSrc, params) {

var newSrc = 'image/{resize}/{width}/{height}{position}';

newSrc = newSrc.replace('{resize}', params.resize);
Expand Down Expand Up @@ -66,7 +66,6 @@
}

if (!!node.length) {

var
width = parseInt(node.attr('data-width'), 10),
height = parseInt(node.attr('data-height'), 10),
Expand All @@ -80,9 +79,11 @@
params.position = position || params.position;
params.absolute = absolute || params.absolute;
params.isDefault = false;
params.isJIT = true;

return false; //exit for
}

return true;
});

Expand Down Expand Up @@ -134,7 +135,7 @@
}

var p = getParameters(classes, defaults);
var url = createUrl(imgSrc, p);
var url = (p.isJIT) ? createUrl(imgSrc, p) : imgSrc;

// bind load event
img.addEventListener('load', function (e) { _imageLoaded(e, p, this.src); });
Expand Down
119 changes: 62 additions & 57 deletions extension.meta.xml
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension id="image_preview" status="released" xmlns="http://symphony-cms.com/schemas/extension/1.0">
<name>Image Preview</name>
<description>Replaces the textual link to the image with the real image</description>
<repo type="github">https://github.com/Solutions-Nitriques/image_preview</repo>
<url type="discuss">http://getsymphony.com/discuss/thread/71485/</url>
<url type="issues">https://github.com/Solutions-Nitriques/image_preview/issues</url>
<types>
<type>Interface</type>
<type>Field</type>
<type>Preview</type>
</types>
<authors>
<author>
<name github="DeuxHuitHuit" symphony="nitriques" twitter="DeuxHuitHuit">Deux Huit Huit</name>
<website>https://deuxhuithuit.com/</website>
</author>
</authors>
<releases>
<release version="2.4.0" date="2017-11-13" min="2.3" max="2.x.x">
- Add support for multi-upload field
</release>
<release version="2.3.3" date="2017-03-22" min="2.3" max="2.x.x">
- Supported on PHP 7
- Fixed parameters to fit the parent method
</release>
<release version="2.3.2" date="2015-09-28" min="2.3" max="2.6.x">
- Added missing .field-multilingual_upload selector
</release>
<release version="2.3.1" date="2015-08-10" min="2.3" max="2.6.x">
- UI (css) fixes
</release>
<release version="2.3.0" date="2015-05-13" min="2.3" max="2.6.x">
- Added support for svg
- Do not request any file if there is already an image in the link
</release>
<release version="2.2" date="2014-07-22" min="2.3" max="2.4">
- Compatibility for custom url: assets are now loaded using full absolute url
- Support for Association Drawer
</release>
<release version="2.1" date="2012-11-27" min="2.3" max="2.4">
- Compatibility with multilingual fields (more than one file/link)
</release>
<release version="2.0" date="2012-11-27" min="2.3" max="2.4">
- Added a Image Preview Settings field :
It is now possible to customize how images are previewed.
You can change those settings by adding one or more `Image Preview Settings` field to you section.
- Minor UI updates
</release>
<release version="1.1" date="2012-07-17" min="2.3" max="2.3.6">
- Compatibility with Symphony 2.3
</release>
<release version="1.0" date="2011-06-13" min="2.2" max="2.2.5">
- Initial release
</release>
</releases>
</extension>
<?xml version="1.0" encoding="UTF-8"?>
<extension id="image_preview" status="released" xmlns="http://symphony-cms.com/schemas/extension/1.0">
<name>Image Preview</name>
<description>Replaces the textual link to the image with the real image</description>
<repo type="github">https://github.com/Solutions-Nitriques/image_preview</repo>
<url type="discuss">http://getsymphony.com/discuss/thread/71485/</url>
<url type="issues">https://github.com/Solutions-Nitriques/image_preview/issues</url>
<types>
<type>Interface</type>
<type>Field</type>
<type>Preview</type>
</types>
<authors>
<author>
<name github="DeuxHuitHuit" symphony="nitriques" twitter="DeuxHuitHuit">Deux Huit Huit</name>
<website>https://deuxhuithuit.com/</website>
</author>
</authors>
<releases>
<release version="3.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x">
- Update for Symphony 4.x
- Code refactoring for Database and EQFA
- Replace deprecated method fetch() by select()
</release>
<release version="2.4.0" date="2017-11-13" min="2.3" max="2.x.x">
- Add support for multi-upload field
</release>
<release version="2.3.3" date="2017-03-22" min="2.3" max="2.x.x">
- Supported on PHP 7
- Fixed parameters to fit the parent method
</release>
<release version="2.3.2" date="2015-09-28" min="2.3" max="2.6.x">
- Added missing .field-multilingual_upload selector
</release>
<release version="2.3.1" date="2015-08-10" min="2.3" max="2.6.x">
- UI (css) fixes
</release>
<release version="2.3.0" date="2015-05-13" min="2.3" max="2.6.x">
- Added support for svg
- Do not request any file if there is already an image in the link
</release>
<release version="2.2" date="2014-07-22" min="2.3" max="2.4">
- Compatibility for custom url: assets are now loaded using full absolute url
- Support for Association Drawer
</release>
<release version="2.1" date="2012-11-27" min="2.3" max="2.4">
- Compatibility with multilingual fields (more than one file/link)
</release>
<release version="2.0" date="2012-11-27" min="2.3" max="2.4">
- Added a Image Preview Settings field :
It is now possible to customize how images are previewed.
You can change those settings by adding one or more `Image Preview Settings` field to you section.
- Minor UI updates
</release>
<release version="1.1" date="2012-07-17" min="2.3" max="2.3.6">
- Compatibility with Symphony 2.3
</release>
<release version="1.0" date="2011-06-13" min="2.2" max="2.2.5">
- Initial release
</release>
</releases>
</extension>
138 changes: 98 additions & 40 deletions fields/field.image_preview_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,19 @@ public function commit()
$settings['entry-absolute'] = empty($e_absolute) ? 'no' : $e_absolute;

// DB
$tbl = self::FIELD_TBL_NAME;

Symphony::Database()->query("DELETE FROM `$tbl` WHERE `field_id` = '$id' LIMIT 1");
Symphony::Database()
->delete(self::FIELD_TBL_NAME)
->where(['field_id' => $id])
->limit(1)
->execute()
->success();

// return if the SQL command was successful
return Symphony::Database()->insert($settings, $tbl);
return Symphony::Database()
->insert(self::FIELD_TBL_NAME)
->values($settings)
->execute()
->success();
}


Expand Down Expand Up @@ -297,8 +304,13 @@ private function convertHandlesIntoIds($handles)
$parent_section = $this->get('parent_section');

foreach ($aHandles as $handle) {
$where = "AND t1.`element_name` = '$handle'";
$field = FieldManager::fetch(null, $parent_section, 'ASC', 'sortorder', null, null, $where);
$field = (new FieldManager)
->select()
->sort('sortorder', 'asc')
->section($parent_section)
->where(['t1.element_name' => $handle])
->execute()
->next();
$fieldId = array_keys($field);
$fieldId = $fieldId[0];

Expand Down Expand Up @@ -490,42 +502,88 @@ public function tearDown()
*/
public function createTable()
{
return Symphony::Database()->query(
"CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` (
`id` int(11) unsigned NOT NULL auto_increment,
`entry_id` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `entry_id` (`entry_id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
);
return Symphony::Database()
->create('tbl_entries_data_' . $this->get('id'))
->ifNotExists()
->fields([
'id' => [
'type' => 'int(11)',
'auto' => true,
],
'entry_id' => 'int(11)',
])
->keys([
'id' => 'primary',
'entry_id' => 'key',
])
->execute()
->success();
}

/**
* Creates the table needed for the settings of the field
*/
public static function createFieldTable()
{
$tbl = self::FIELD_TBL_NAME;

return Symphony::Database()->query("
CREATE TABLE IF NOT EXISTS `$tbl` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`field-handles` varchar(255) NOT NULL,
`table-width` int(11) unsigned NULL,
`table-height` int(11) unsigned NULL,
`table-resize` int(11) unsigned NULL,
`table-position` int(11) unsigned NULL,
`table-absolute` enum('yes','no') NOT NULL DEFAULT 'no',
`entry-width` int(11) unsigned NULL,
`entry-height` int(11) unsigned NULL,
`entry-resize` int(11) unsigned NULL,
`entry-position` int(11) unsigned NULL,
`entry-absolute` enum('yes','no') NOT NULL DEFAULT 'no',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
return Symphony::Database()
->create(self::FIELD_TBL_NAME)
->ifNotExists()
->fields([
'id' => [
'type' => 'int(11)',
'auto' => true,
],
'field_id' => 'int(11)',
'field-handles' => 'varchar(255)',
'table-width' => [
'type' => 'int(11)',
'null' => true,
],
'table-height' => [
'type' => 'int(11)',
'null' => true,
],
'table-resize' => [
'type' => 'int(11)',
'null' => true,
],
'table-position' => [
'type' => 'int(11)',
'null' => true,
],
'table-absolute' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
'entry-width' => [
'type' => 'int(11)',
'null' => true,
],
'entry-height' => [
'type' => 'int(11)',
'null' => true,
],
'entry-resize' => [
'type' => 'int(11)',
'null' => true,
],
'entry-position' => [
'type' => 'int(11)',
'null' => true,
],
'entry-absolute' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
])
->keys([
'id' => 'primary',
'field_id' => 'key',
])
->execute()
->success();
}


Expand All @@ -535,10 +593,10 @@ public static function createFieldTable()
*/
public static function deleteFieldTable()
{
$tbl = self::FIELD_TBL_NAME;

return Symphony::Database()->query("
DROP TABLE IF EXISTS `$tbl`
");
return Symphony::Database()
->drop(self::FIELD_TBL_NAME)
->ifExists()
->execute()
->success();
}
}