Skip to content

Commit

Permalink
SQL and PHP cases
Browse files Browse the repository at this point in the history
PHP true,false,null in lowercase
SQL keywords uppercase
Fix "Remove File" position
  • Loading branch information
Alexandra Nantel committed Aug 25, 2017
1 parent a389c80 commit aefff05
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion assets/multilingual_image_upload.publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

$(document).ready(function(){
if ($('div.file:has(a):has(em)').length === 0) {
$('<em>' + Symphony.Language.get('Remove File') + '</em>').appendTo('div.file:has(a)').click(function (event) {
$('<em>' + Symphony.Language.get('Remove File') + '</em>').appendTo('div.file:has(a) .frame').click(function (event) {
event.preventDefault();

var div = $(this).parent(),
Expand Down
32 changes: 16 additions & 16 deletions content/content.convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require_once(EXTENSIONS . '/multilingual_image_upload/fields/field.multilingual_image_upload.php');

class contentExtensionMultilingual_Image_UploadConvert extends JSONPage {

/**
*
* Builds the content view
Expand All @@ -22,30 +22,30 @@ public function view() {
$this->setHttpStatus($this->_Result['status']);
return;
}

if (!is_array($this->_context) || empty($this->_context)) {
$this->_Result['error'] = 'Parameters not found';
return;
}

$id = MySQL::cleanValue($this->_context[0]);
$this->_Result['ok'] = true;

$field = FieldManager::fetch($id);

if ($field == null || !($field instanceof fieldImage_upload)) {
$this->_Result['error'] = "Field $id not found.";
$this->_Result['ok'] = false;
return;
}

try {
// Check for languages
$langs = FLang::getLangs();
if (empty($langs)) {
throw new Exception('No language found. Please check that you have at least one.');
}

$destination = MySQL::cleanValue($field->get('destination'));
$validator = MySQL::cleanValue($field->get('validator'));
$unique = MySQL::cleanValue($field->get('unique'));
Expand All @@ -54,8 +54,8 @@ public function view() {
$max_width = MySQL::cleanValue($field->get('max_width'));
$max_height = MySQL::cleanValue($field->get('max_height'));
$resize = MySQL::cleanValue($field->get('resize'));
$requiredLang = $field->get('required') == 'yes' ? "'main'" : 'NULL';
$requiredLang = $field->get('required') == 'yes' ? "'main'" : 'null';

// ALTER data table SQL: add new cols
$entries_table = "tbl_entries_data_$id";
$query = "ALTER TABLE `$entries_table` ";
Expand All @@ -69,17 +69,17 @@ public function view() {
}
$query = trim($query, ',') . ';';
Symphony::Database()->query($query);

// Copy values to default lang
$defLang = FLang::getMainLang();
$query = "UPDATE `$entries_table` SET ";
$query .= " `file-$defLang` = `file`,
`size-$defLang` = `size`,
`mimetype-$defLang` = `mimetype`,
`meta-$defLang` = `meta`;";

Symphony::Database()->query($query);

// Insert into multilingual
Symphony::Database()->query("
INSERT INTO `tbl_fields_multilingual_image_upload`
Expand All @@ -93,22 +93,22 @@ public function view() {
'$max_width', '$max_height',
'$resize', $requiredLang)
");

// remove from textbox
Symphony::Database()->query("
DELETE FROM `tbl_fields_textbox`
WHERE `field_id` = $id
");

// update type
Symphony::Database()->query("
UPDATE `tbl_fields` SET `type` = 'multilingual_image_upload'
WHERE `id` = $id
");

} catch (Exception $ex) {
$this->_Result['ok'] = false;
$this->_Result['error'] = $ex->getMessage();
}
}
}
}
26 changes: 13 additions & 13 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ public function install()
{
return Symphony::Database()->query(sprintf(
"CREATE TABLE `%s` (
`id` INT(11) unsigned NOT NULL auto_increment,
`field_id` INT(11) unsigned NOT NULL,
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`field_id` INT(11) UNSIGNED NOT NULL,
`destination` VARCHAR(255) NOT NULL,
`validator` VARCHAR(50),
`unique` enum('yes','no') NOT NULL DEFAULT 'yes',
`unique` ENUM('yes','no') NOT NULL DEFAULT 'yes',
`default_main_lang` ENUM('yes', 'no') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',
`required_languages` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
`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',
`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;",
Expand Down Expand Up @@ -81,7 +81,7 @@ public function update($previousVersion = false)
// Before 1.7.1
if (version_compare($previousVersion, '1.7.1', '<')) {
$query = sprintf("ALTER TABLE `%s`
ADD COLUMN `resize` enum('yes','no') NOT NULL DEFAULT 'yes'
ADD COLUMN `resize` ENUM('yes','no') NOT NULL DEFAULT 'yes'
", self::FIELD_TABLE);
try {
$ret = Symphony::Database()->query($query);
Expand Down Expand Up @@ -232,10 +232,10 @@ public function dFLSavePreferences($context)
if (!in_array('file-'.$lc, $columns)) {
Symphony::Database()->query(sprintf(
'ALTER TABLE `%1$s`
ADD COLUMN `file-%2$s` varchar(255) default NULL,
ADD COLUMN `size-%2$s` int(11) unsigned NULL,
ADD COLUMN `mimetype-%2$s` varchar(50) default NULL,
ADD COLUMN `meta-%2$s` varchar(255) default NULL;',
ADD COLUMN `file-%2$s` VARCHAR(255) DEFAULT NULL,
ADD COLUMN `size-%2$s` INT(11) UNSIGNED NULL,
ADD COLUMN `mimetype-%2$s` VARCHAR(50) DEFAULT NULL,
ADD COLUMN `meta-%2$s` VARCHAR(255) DEFAULT NULL;',
$entries_table, $lc
));
}
Expand Down
22 changes: 11 additions & 11 deletions fields/field.multilingual_image_upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public static function generateTableColumns()
{
$cols = array();
foreach (FLang::getLangs() as $lc) {
$cols[] = "`file-{$lc}` varchar(255) default NULL,";
$cols[] = "`size-{$lc}` int(11) unsigned NULL,";
$cols[] = "`mimetype-{$lc}` varchar(50) default NULL,";
$cols[] = "`meta-{$lc}` varchar(255) default NULL,";
$cols[] = "`file-{$lc}` VARCHAR(255) DEFAULT NULL,";
$cols[] = "`size-{$lc}` INT(11) UNSIGNED NULL,";
$cols[] = "`mimetype-{$lc}` VARCHAR(50) DEFAULT NULL,";
$cols[] = "`meta-{$lc}` VARCHAR(255) DEFAULT NULL,";
}
return $cols;
}
Expand All @@ -46,12 +46,12 @@ public function createTable()
{
$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,
`file` varchar(255) default NULL,
`size` int(11) unsigned NULL,
`mimetype` varchar(50) default NULL,
`meta` varchar(255) default NULL,";
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`entry_id` INT(11) UNSIGNED NOT NULL,
`file` VARCHAR(255) DEFAULT NULL,
`size` INT(11) UNSIGNED NULL,
`mimetype` VARCHAR(50) DEFAULT NULL,
`meta` VARCHAR(255) DEFAULT NULL,";

$query .= implode('', self::generateTableColumns());

Expand Down Expand Up @@ -288,7 +288,7 @@ public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWit

foreach ($langs as $lc) {
$div = new XMLElement('div', null, array('class' => 'file tab-panel tab-'.$lc));
$frame = new XMLElement('div', NULL, array('class' => 'frame'));
$frame = new XMLElement('div', null, array('class' => 'frame'));

$file = 'file-'.$lc;

Expand Down

0 comments on commit aefff05

Please sign in to comment.