Skip to content

Commit

Permalink
Release 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Ghita committed May 15, 2012
1 parent 5f61aa0 commit 37add92
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 122 deletions.
12 changes: 0 additions & 12 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
Field: Multilingual File Upload
==============

A field that allows file upload for different frontend languages.

* Version: 1.5
* Build Date: 2012-05-14
* Authors:
- Vlad Ghita
* Requirements:
- Symphony 2.3
- [Frontend Localisation 1.5](https://github.com/vlad-ghita/frontend_localisation)



## 1 About ##

This is the multilingual version of the classic upload field.
Expand Down
115 changes: 74 additions & 41 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@



define_safe(MUF_NAME, 'Field: Multilingual File Upload');
define_safe(MUF_NAME, 'Field: Multilingual Upload');
define_safe(MUF_GROUP, 'multilingual_upload_field');



class extension_multilingual_upload_field extends Extension
class Extension_Multilingual_Upload_Field extends Extension
{
const FIELD_TABLE = 'tbl_fields_multilingual_upload';

protected $assets_loaded = false;
protected static $assets_loaded = false;



Expand All @@ -21,8 +22,8 @@ class extension_multilingual_upload_field extends Extension
/*------------------------------------------------------------------------------------------------*/

public function install(){
return Symphony::Database()->query("
CREATE TABLE `tbl_fields_multilingualupload` (
return Symphony::Database()->query(sprintf(
"CREATE TABLE `%s` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`destination` varchar(255) NOT NULL,
Expand All @@ -31,8 +32,9 @@ public function install(){
`def_ref_lang` enum('yes','no') default 'yes',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
self::FIELD_TABLE
));
}

public function update($previous_version){
Expand All @@ -41,11 +43,28 @@ public function update($previous_version){
Symphony::Database()->query("UPDATE `tbl_fields_multilingualupload` SET `def_ref_lang` = 'no'");
}

if( version_compare($previous_version, '1.6', '<') ){
Symphony::Database()->query(sprintf(
"RENAME TABLE `tbl_fields_multilingualupload` TO `%s`;",
self::FIELD_TABLE
));
}

return true;
}

public function uninstall(){
Symphony::Database()->query("DROP TABLE `tbl_fields_multilingualupload`");
try{
Symphony::Database()->query(sprintf(
"DROP TABLE `%s`",
self::FIELD_TABLE
));
}
catch( DatabaseException $dbe ){
// table deosn't exist
}

return true;
}


Expand Down Expand Up @@ -99,74 +118,88 @@ public function dAddCustomPreferenceFieldsets($context){
* @param array $context
*/
public function dFLSavePreferences($context){
$fields = Symphony::Database()->fetch('SELECT `field_id` FROM `tbl_fields_multilingualupload`');
$fields = Symphony::Database()->fetch(sprintf(
'SELECT `field_id` FROM `%s`',
self::FIELD_TABLE
));

if( is_array($fields) && !empty($fields) ){
$consolidate = $context['context']['settings'][MUF_GROUP]['consolidate'];

if( $fields ){
// Foreach field check multilanguage values foreach language
foreach( $fields as $field ){
$entries_table = 'tbl_entries_data_'.$field["field_id"];

try{
$show_columns = Symphony::Database()->fetch("SHOW COLUMNS FROM `{$entries_table}` LIKE 'file-%';");
$show_columns = Symphony::Database()->fetch(sprintf(
"SHOW COLUMNS FROM `%s` LIKE 'file-%%'",
$entries_table
));
}
catch( DatabaseException $dbe ){
// Field doesn't exist. Better remove it's settings
Symphony::Database()->query("DELETE FROM `tbl_fields_multilingualupload` WHERE `field_id` = {$field["field_id"]};");
Symphony::Database()->query(sprintf(
"DELETE FROM `%s` WHERE `field_id` = '%s';",
self::FIELD_TABLE, $field["field_id"]
));
continue;
}

$columns = array();

if( $show_columns ){
// Remove obsolete fields
if( is_array($show_columns) && !empty($show_columns) )

foreach( $show_columns as $column ){
$lc = substr($column['Field'], strlen($column['Field']) - 2);

// If not consolidate option AND column lang_code not in supported languages codes -> Drop Column
if( ($_POST['settings'][MUF_GROUP]['consolidate'] !== 'yes') && !in_array($lc, $context['new_langs']) ){
Symphony::Database()->query("ALTER TABLE `{$entries_table}` DROP COLUMN `file-{$lc}`");
Symphony::Database()->query("ALTER TABLE `{$entries_table}` DROP COLUMN `size-{$lc}`");
Symphony::Database()->query("ALTER TABLE `{$entries_table}` DROP COLUMN `mimetype-{$lc}`");
Symphony::Database()->query("ALTER TABLE `{$entries_table}` DROP COLUMN `meta-{$lc}`");
} else{
if( ($consolidate !== 'yes') && !in_array($lc, $context['new_langs']) )
Symphony::Database()->query(sprintf(
'ALTER TABLE `%1$s`
DROP COLUMN `file-%2$s`,
DROP COLUMN `size-%2$s`,
DROP COLUMN `mimetype-%2$s`,
DROP COLUMN `meta-%2$s`;',
$entries_table, $lc
));
else
$columns[] = $column['Field'];
}
}
}

// Add new fields
foreach( $context['new_langs'] as $lc ){
// If column lang_code dosen't exist in the laguange drop columns

if( !in_array('file-'.$lc, $columns) ){
Symphony::Database()->query("ALTER TABLE `{$entries_table}` ADD COLUMN `file-{$lc}` varchar(255) default NULL");
Symphony::Database()->query("ALTER TABLE `{$entries_table}` ADD COLUMN `size-{$lc}` int(11) unsigned NULL");
Symphony::Database()->query("ALTER TABLE `{$entries_table}` ADD COLUMN `mimetype-{$lc}` varchar(50) default NULL");
Symphony::Database()->query("ALTER TABLE `{$entries_table}` ADD COLUMN `meta-{$lc}` varchar(255) default NULL");
}
}

foreach( $context['new_langs'] as $lc )

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;',
$entries_table, $lc
));
}
}
}



/*------------------------------------------------------------------------------------------------*/
/* Utilities */
/* Public utilities */
/*------------------------------------------------------------------------------------------------*/

public function appendAssets(){
if( $this->assets_loaded === false ){
$this->assets_loaded = true;
public static function appendAssets(){
if( self::$assets_loaded === false
&& class_exists('Administration')
&& Administration::instance() instanceof Administration
&& Administration::instance()->Page instanceof HTMLPage ){

self::$assets_loaded = true;

$page = Administration::instance()->Page;

$page->addScriptToHead(URL.'/extensions/'.MUF_GROUP.'/assets/'.MUF_GROUP.'.publish.js', null, false);

// multilingual stuff
$fl_assets = URL.'/extensions/frontend_localisation/assets/frontend_localisation.multilingual_tabs';
$page->addStylesheetToHead($fl_assets.'.css', 'screen', null, false);
$page->addScriptToHead($fl_assets.'_init.js', null, false);
}
}
}
6 changes: 5 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
</authors>

<dependencies>
<dependency version="1.4">https://github.com/vlad-ghita/frontend_localisation</dependency>
<dependency version="1.6">https://github.com/vlad-ghita/frontend_localisation</dependency>
</dependencies>

<releases>
<release version="1.6" date="2012-05-15"><![CDATA[
* Frontend Localisation 1.6 compatibility.
]]></release>

<release version="1.5" date="2012-05-14"><![CDATA[
* Frontend Localisation 1.5 compatibility.
]]></release>
Expand Down
Loading

0 comments on commit 37add92

Please sign in to comment.