ACF qTranslate - Version 1.7.1

Version Description

  • Core: Added back ACFv5 support for WYSIWYG
  • Core: Added qTranslate-X support for the standard WYSIWYG field type
  • Core: Bumped version requirement to match ACF
  • Bug Fix: qTranslate-X switcher showing up on every admin page
Download this release

Release Info

Developer funkjedi
Plugin Icon wp plugin ACF qTranslate
Version 1.7.1
Comparing to
See all releases

Code changes from version 1.7 to 1.7.1

acf-qtranslate.php CHANGED
@@ -3,7 +3,7 @@
3
Plugin Name: Advanced Custom Fields: qTranslate
4
Plugin URI: http://github.com/funkjedi/acf-qtranslate
5
Description: Provides multilingual versions of the text, text area, and wysiwyg fields.
6
- Version: 1.7
7
Author: funkjedi
8
Author URI: http://funkjedi.com
9
License: GPLv2 or later
3
Plugin Name: Advanced Custom Fields: qTranslate
4
Plugin URI: http://github.com/funkjedi/acf-qtranslate
5
Description: Provides multilingual versions of the text, text area, and wysiwyg fields.
6
+ Version: 1.7.1
7
Author: funkjedi
8
Author URI: http://funkjedi.com
9
License: GPLv2 or later
assets/acf_5/main.js ADDED
@@ -0,0 +1,66 @@
1
+
2
+ /**
3
+ * Clone functionality from standard Image field type
4
+ */
5
+ acf.fields.qtranslate_image = acf.fields.image.extend({
6
+ type: 'qtranslate_image',
7
+ focus: function() {
8
+ this.$el = this.$field.find('.acf-image-uploader.current-language');
9
+ this.o = acf.get_data(this.$el);
10
+ }
11
+ });
12
+
13
+ /**
14
+ * Clone functionality from standard File field type
15
+ */
16
+ acf.fields.qtranslate_file = acf.fields.file.extend({
17
+ type: 'qtranslate_file',
18
+ focus: function() {
19
+ this.$el = this.$field.find('.acf-file-uploader.current-language');
20
+ this.o = acf.get_data(this.$el);
21
+ }
22
+ });
23
+
24
+ /**
25
+ * Clone functionality from standard WYSIWYG field type
26
+ */
27
+ acf.fields.qtranslate_wysiwyg = acf.fields.wysiwyg.extend({
28
+ type: 'qtranslate_wysiwyg',
29
+ focus: function() {
30
+ this.$el = this.$field.find('.wp-editor-wrap.current-language').last();
31
+ this.$textarea = this.$el.find('textarea');
32
+ this.o = acf.get_data(this.$el);
33
+ this.o.id = this.$textarea.attr('id');
34
+ },
35
+ initialize: function(){
36
+ if (typeof tinyMCEPreInit === 'undefined' || typeof tinymce === 'undefined') {
37
+ return false;
38
+ }
39
+ var self = this;
40
+ this.$field.find('.wp-editor-wrap').each(function() {
41
+ self.$el = jQuery(this);
42
+ self.$textarea = self.$el.find('textarea');
43
+ self.o = acf.get_data(self.$el);
44
+ self.o.id = self.$textarea.attr('id');
45
+ // vars
46
+ var mceInit = self.get_mceInit();
47
+ var qtInit = self.get_qtInit();
48
+ // append settings
49
+ tinyMCEPreInit.mceInit[ mceInit.id ] = mceInit;
50
+ tinyMCEPreInit.qtInit[ qtInit.id ] = qtInit;
51
+ // initialize mceInit
52
+ if (self.$el.hasClass('tmce-active')) {
53
+ try {
54
+ tinymce.init( mceInit );
55
+ } catch(e){}
56
+ }
57
+ // initialize qtInit
58
+ try {
59
+ var qtag = quicktags( qtInit );
60
+ self._buttonsInit( qtag );
61
+ } catch(e){}
62
+ });
63
+ this.focus();
64
+ }
65
+ });
66
+
assets/{input.css → common.css} RENAMED
@@ -15,7 +15,7 @@
15
}
16
17
.acf_wysiwyg .wp-editor-container,
18
- .acf-wysiwyg-wrap .wp-editor-container {
19
border: 1px solid #e5e5e5 !important;
20
}
21
@@ -62,7 +62,7 @@
62
.multi-language-field > textarea,
63
.multi-language-field > fieldset,
64
.multi-language-field .acf_wysiwyg,
65
- .multi-language-field .acf-wysiwyg-wrap,
66
.multi-language-field .acf-file-uploader,
67
.multi-language-field .acf-image-uploader { display: none }
68
15
}
16
17
.acf_wysiwyg .wp-editor-container,
18
+ .acf-editor-wrap .wp-editor-container {
19
border: 1px solid #e5e5e5 !important;
20
}
21
62
.multi-language-field > textarea,
63
.multi-language-field > fieldset,
64
.multi-language-field .acf_wysiwyg,
65
+ .multi-language-field .acf-editor-wrap,
66
.multi-language-field .acf-file-uploader,
67
.multi-language-field .acf-image-uploader { display: none }
68
assets/{input.js → common.js} RENAMED
@@ -1,4 +1,5 @@
1
2
jQuery(function($) {
3
4
var $body = $('body');
@@ -12,7 +13,7 @@ jQuery(function($) {
12
13
parent.find('.current-language').removeClass('current-language');
14
parent.find('[data-language="' + language + '"]').addClass('current-language');
15
- parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]').focus();
16
});
17
18
/**
@@ -37,5 +38,5 @@ jQuery(function($) {
37
$(this).parent('.multi-language-field').removeClass('focused');
38
});
39
40
-
41
});
1
2
+
3
jQuery(function($) {
4
5
var $body = $('body');
13
14
parent.find('.current-language').removeClass('current-language');
15
parent.find('[data-language="' + language + '"]').addClass('current-language');
16
+ parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]');
17
});
18
19
/**
38
$(this).parent('.multi-language-field').removeClass('focused');
39
});
40
41
});
42
+
compatibility/ppqtranslate.php ADDED
@@ -0,0 +1,33 @@
1
+ <?php
2
+
3
+ // provide qTranslate compatibility when using qTranslate Plus
4
+
5
+ if (function_exists('qtrans_getLanguage') === false):
6
+ function qtrans_getLanguage() {
7
+ return ppqtrans_getLanguage();
8
+ }
9
+ endif;
10
+
11
+ if (function_exists('qtrans_getSortedLanguages') === false):
12
+ function qtrans_getSortedLanguages($reverse = false) {
13
+ return ppqtrans_getSortedLanguages($reverse);
14
+ }
15
+ endif;
16
+
17
+ if (function_exists('qtrans_join') === false):
18
+ function qtrans_join($texts) {
19
+ return ppqtrans_join($texts);
20
+ }
21
+ endif;
22
+
23
+ if (function_exists('qtrans_split') === false):
24
+ function qtrans_split($text, $quicktags = true) {
25
+ return ppqtrans_split($text, $quicktags);
26
+ }
27
+ endif;
28
+
29
+ if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage') === false):
30
+ function qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($content) {
31
+ return ppqtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($content);
32
+ }
33
+ endif;
src/qtranslatex/qtranslate-compatibility.php → compatibility/qtranslatex.php RENAMED
File without changes
readme.txt CHANGED
@@ -1,73 +1,97 @@
1
=== ACF qTranslate ===
2
Contributors: funkjedi
3
Tags: acf, advanced custom fields, qtranslate, add-on, admin
4
- Requires at least: 3.0.0
5
Tested up to: 4.1.1
6
- Version: 1.7
7
- Stable tag: 1.7
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
11
- Adds qTranslate compatible fields for Text, Text Area, Wysiwyg Editor and Image.
12
13
- == Description ==
14
15
- This plugin adds a new Field Type category called qTranslate. This contains qTranslate compatible fields for Text, Text Area, Wysiwyg Editor and Image.
16
17
- If using qTranslate-X then the standard Text, Text Area and Email fields automatically support translation.
18
19
- Usage:
20
21
- * Install the plug-in (standard WordPress installation)
22
- * Set up a qTranslate field (standard Advanced Custom Field configuration)
23
- * Add or Edit a post and language tabs will show up above the qTranslate field
24
- * Click a language tab above the qTranslate field to switch languages
25
26
- Issues:
27
28
- All bugs reports or feature requests should be made in the [Github repository](https://github.com/funkjedi/acf-qtranslate/issues)
29
30
== Installation ==
31
32
- 1. Be sure to have **Advanced Custom Fields** installed and activated first
33
- 2. Upload `acf-qtranslate` directory to the `/wp-content/plugins/` directory
34
- 3. Activate the plugin through the 'Plugins' menu in WordPress
35
36
== Frequently Asked Questions ==
37
38
= What's the history behind this plugin? =
39
40
- The plugin is based on code samples posted to the [ACF support forums](http://old.support.advancedcustomfields.com/discussion/comment/20351#Comment_20351) by taeo.
41
42
== Screenshots ==
43
44
1. Shows the qTranslate Text and Image fields.
45
46
== Changelog ==
47
48
= 1.7 =
49
- Improved qTranslate-X support and utilize new language switchers
50
51
= 1.6 =
52
- Added ACFv4 support for qTranslate-X
53
54
= 1.5 =
55
- Added support for qTranslate-X
56
- Remove ACFv5 WYSIWYG implementation as it was very broken
57
58
= 1.4 =
59
- Updated with support for Advanced Customs Fields v5
60
- Tested using mqTranslate in place of qTranslate
61
62
= 1.3 =
63
- Updated styles for Wordpress 3.8
64
- Updated monkey patch qTranslate to fix [bug with multiple WYSIWYG editors](https://github.com/funkjedi/acf-qtranslate/issues/2#issuecomment-37612918)
65
66
= 1.2 =
67
- Monkey patch qTranslate to fix [bug with multiple WYSIWYG editors](http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=3497).
68
69
= 1.1 =
70
- Added support for Image Fields. Thanks to bookwyrm for the contribution.
71
72
= 1.0 =
73
- Initial Release. Thanks to taeo for the code samples this plugin was based on.
1
=== ACF qTranslate ===
2
Contributors: funkjedi
3
Tags: acf, advanced custom fields, qtranslate, add-on, admin
4
+ Requires at least: 3.5.0
5
Tested up to: 4.1.1
6
+ Version: 1.7.1
7
+ Stable tag: 1.7.1
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
11
+ Adds qTranslate compatible field types for Text, Text Area, Wysiwyg Editor and Image.
12
13
14
+ == Description ==
15
16
+ This plugin adds a new Field Type category called qTranslate. This contains qTranslate compatible fields for Text, Text Area, WYSIWYG, Image and File.
17
18
+ = Field Types =
19
+ * qTranslate Text (type text, api returns text)
20
+ * qTranslate Text Area (type text, api returns text)
21
+ * qTranslate WYSIWYG (a wordpress wysiwyg editor, api returns html)
22
+ * qTranslate Image (upload an image, api returns the url)
23
+ * qTranslate File (upload a file, api returns the url)
24
25
+ = qTranslate-X =
26
+ If using qTranslate-X the standard Text, Text Area and WYSIWYG field types all automatically support translation out of the box.
27
28
+ = Bug Submission =
29
+ https://github.com/funkjedi/acf-qtranslate/issues/
30
31
32
== Installation ==
33
34
+ **This plugins requires a qTranslate-based plugin to be installed:**
35
+
36
+ * [qTranslate](http://wordpress.org/extend/plugins/qtranslate/)
37
+ * [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/)
38
+ * [qTranslate Plus](https://wordpress.org/plugins/qtranslate-xp/)
39
+ * [mqTranslate](https://wordpress.org/plugins/mqtranslate/)
40
+ * [zTranslate](http://wordpress.org/extend/plugins/ztranslate/)
41
+
42
+ 1. Upload `acf-qtranslate` directory to the `/wp-content/plugins/` directory
43
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
44
+
45
46
== Frequently Asked Questions ==
47
48
= What's the history behind this plugin? =
49
+ The plugin is based on code samples posted to the ACF support forums by taeo back in 2013.
50
51
52
== Screenshots ==
53
54
1. Shows the qTranslate Text and Image fields.
55
56
+
57
== Changelog ==
58
59
+ = 1.7.1 =
60
+ * Core: Added back ACFv5 support for WYSIWYG
61
+ * Core: Added qTranslate-X support for the standard WYSIWYG field type
62
+ * Core: Bumped version requirement to match ACF
63
+ * Bug Fix: qTranslate-X switcher showing up on every admin page
64
+
65
= 1.7 =
66
+ * Core: Refactor of codebase
67
+ * Core: Support for qTranslate-X language switchers
68
69
= 1.6 =
70
+ * Added ACFv4 support for qTranslate-X
71
72
= 1.5 =
73
+ * Core: Added compatibility for qTranslate-X
74
+ * Bug Fix: Remove the broken ACFv5 WYSIWYG implementation
75
76
= 1.4 =
77
+ * Core: Added support for ACFv5
78
+ * Core: Tested compatibility with mqTranslate
79
80
= 1.3 =
81
+ * Core: Updated styles for Wordpress 3.8
82
+ * Bug Fix: qTranslate bug with multiple WYSIWYG editors
83
84
= 1.2 =
85
+ * Bug Fix: qTranslate bug with multiple WYSIWYG editors
86
87
= 1.1 =
88
+ * Core: Added support for Image Fields. Thanks to bookwyrm for the contribution.
89
90
= 1.0 =
91
+ * Initial Release. Thanks to taeo for the code samples this plugin was based on.
92
+
93
+
94
+ == Upgrade Notice ==
95
+
96
+ = 1.7.1 =
97
+ Added qTranslate-X support for the standard WYSIWYG field type
src/acf_4/acf.php CHANGED
@@ -12,35 +12,44 @@ use acf_qtranslate\plugin;
12
13
class acf implements acf_interface {
14
15
/*
16
* Create an instance.
17
* @return void
18
*/
19
- public function __construct() {
20
- $this->monkey_patch_qtranslate();
21
22
add_filter('acf/format_value_for_api', array($this, 'format_value_for_api'));
23
add_action('acf/register_fields', array($this, 'register_fields'));
24
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
25
}
26
27
/**
28
* Load javascript and stylesheets on admin pages.
29
*/
30
public function register_fields() {
31
- new file;
32
- new image;
33
- new text;
34
- new textarea;
35
- new wysiwyg;
36
}
37
38
/**
39
* Load javascript and stylesheets on admin pages.
40
*/
41
public function admin_enqueue_scripts() {
42
- wp_enqueue_style('acf_qtranslate_input', plugins_url('/assets/input.css', ACF_QTRANSLATE_PLUGIN));
43
- wp_enqueue_script('acf_qtranslate_input', plugins_url('/assets/input.js', ACF_QTRANSLATE_PLUGIN));
44
}
45
46
/**
12
13
class acf implements acf_interface {
14
15
+ /**
16
+ * The plugin instance.
17
+ * @var \acf_qtranslate\plugin
18
+ */
19
+ protected $plugin;
20
+
21
+
22
/*
23
* Create an instance.
24
* @return void
25
*/
26
+ public function __construct($plugin) {
27
+ $this->plugin = $plugin;
28
29
add_filter('acf/format_value_for_api', array($this, 'format_value_for_api'));
30
add_action('acf/register_fields', array($this, 'register_fields'));
31
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
32
+
33
+ $this->monkey_patch_qtranslate();
34
}
35
36
/**
37
* Load javascript and stylesheets on admin pages.
38
*/
39
public function register_fields() {
40
+ new text($this->plugin);
41
+ new textarea($this->plugin);
42
+ new wysiwyg($this->plugin);
43
+ new image($this->plugin);
44
+ new file($this->plugin);
45
}
46
47
/**
48
* Load javascript and stylesheets on admin pages.
49
*/
50
public function admin_enqueue_scripts() {
51
+ wp_enqueue_style('acf_qtranslate_common', plugins_url('/assets/common.css', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
52
+ wp_enqueue_script('acf_qtranslate_common', plugins_url('/assets/common.js', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
53
}
54
55
/**
src/acf_4/fields/file.php CHANGED
@@ -5,8 +5,14 @@ namespace acf_qtranslate\acf_4\fields;
5
use acf_field;
6
use acf_field_file;
7
8
- class file extends acf_field_file
9
- {
10
11
/*
12
* __construct
@@ -16,9 +22,9 @@ class file extends acf_field_file
16
* @since 3.6
17
* @date 23/01/13
18
*/
19
- function __construct()
20
- {
21
- // Grab defaults
22
$this->name = 'qtranslate_file';
23
$this->label = __("File",'acf');
24
$this->category = __("qTranslate", 'acf');
@@ -38,8 +44,8 @@ class file extends acf_field_file
38
// filters
39
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
40
add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
41
-
42
-
43
// JSON
44
add_action('wp_ajax_acf/fields/file/get_files', array($this, 'ajax_get_files'));
45
add_action('wp_ajax_nopriv_acf/fields/file/get_files', array($this, 'ajax_get_files'), 10, 1);
@@ -56,8 +62,7 @@ class file extends acf_field_file
56
* @since 3.6
57
* @date 23/01/13
58
*/
59
- function create_field($field)
60
- {
61
global $q_config;
62
$languages = qtrans_getSortedLanguages(true);
63
$values = qtrans_split($field['value'], $quicktags = true);
@@ -95,9 +100,9 @@ class file extends acf_field_file
95
$o['title'] = $file->post_title;
96
$o['size'] = size_format(filesize( get_attached_file( $file->ID ) ));
97
$o['url'] = wp_get_attachment_url( $file->ID );
98
-
99
$explode = explode('/', $o['url']);
100
- $o['name'] = end( $explode );
101
}
102
}
103
@@ -135,7 +140,7 @@ class file extends acf_field_file
135
<strong><?php _e('Size', 'acf'); ?>:</strong>
136
<span class="acf-file-size"><?php echo $o['size']; ?></span>
137
</p>
138
-
139
</li>
140
</ul>
141
</div>
@@ -159,8 +164,7 @@ class file extends acf_field_file
159
* @since: 3.6
160
* @created: 26/01/13
161
*/
162
- function format_value($value, $post_id, $field)
163
- {
164
return $value;
165
}
166
@@ -179,8 +183,7 @@ class file extends acf_field_file
179
*
180
* @return $value - the modified value
181
*/
182
- function format_value_for_api($value, $post_id, $field)
183
- {
184
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
185
return parent::format_value_for_api($value, $post_id, $field);
186
}
@@ -200,8 +203,7 @@ class file extends acf_field_file
200
*
201
* @return $value - the modified value
202
*/
203
- function update_value($value, $post_id, $field)
204
- {
205
return qtrans_join($value);
206
}
207
5
use acf_field;
6
use acf_field_file;
7
8
+ class file extends acf_field_file {
9
+
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
17
/*
18
* __construct
22
* @since 3.6
23
* @date 23/01/13
24
*/
25
+ function __construct($plugin) {
26
+ $this->plugin = $plugin;
27
+
28
$this->name = 'qtranslate_file';
29
$this->label = __("File",'acf');
30
$this->category = __("qTranslate", 'acf');
44
// filters
45
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
46
add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
47
+
48
+
49
// JSON
50
add_action('wp_ajax_acf/fields/file/get_files', array($this, 'ajax_get_files'));
51
add_action('wp_ajax_nopriv_acf/fields/file/get_files', array($this, 'ajax_get_files'), 10, 1);
62
* @since 3.6
63
* @date 23/01/13
64
*/
65
+ function create_field($field) {
66
global $q_config;
67
$languages = qtrans_getSortedLanguages(true);
68
$values = qtrans_split($field['value'], $quicktags = true);
100
$o['title'] = $file->post_title;
101
$o['size'] = size_format(filesize( get_attached_file( $file->ID ) ));
102
$o['url'] = wp_get_attachment_url( $file->ID );
103
+
104
$explode = explode('/', $o['url']);
105
+ $o['name'] = end( $explode );
106
}
107
}
108
140
<strong><?php _e('Size', 'acf'); ?>:</strong>
141
<span class="acf-file-size"><?php echo $o['size']; ?></span>
142
</p>
143
+
144
</li>
145
</ul>
146
</div>
164
* @since: 3.6
165
* @created: 26/01/13
166
*/
167
+ function format_value($value, $post_id, $field) {
168
return $value;
169
}
170
183
*
184
* @return $value - the modified value
185
*/
186
+ function format_value_for_api($value, $post_id, $field) {
187
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
188
return parent::format_value_for_api($value, $post_id, $field);
189
}
203
*
204
* @return $value - the modified value
205
*/
206
+ function update_value($value, $post_id, $field) {
207
return qtrans_join($value);
208
}
209
src/acf_4/fields/image.php CHANGED
@@ -7,6 +7,13 @@ use acf_field_image;
7
8
class image extends acf_field_image {
9
10
/*
11
* __construct
12
*
@@ -15,7 +22,9 @@ class image extends acf_field_image {
15
* @since 3.6
16
* @date 23/01/13
17
*/
18
- function __construct() {
19
$this->name = 'qtranslate_image';
20
$this->label = __("Image", 'acf');
21
$this->category = __("qTranslate", 'acf');
7
8
class image extends acf_field_image {
9
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
+
17
/*
18
* __construct
19
*
22
* @since 3.6
23
* @date 23/01/13
24
*/
25
+ function __construct($plugin) {
26
+ $this->plugin = $plugin;
27
+
28
$this->name = 'qtranslate_image';
29
$this->label = __("Image", 'acf');
30
$this->category = __("qTranslate", 'acf');
src/acf_4/fields/text.php CHANGED
@@ -7,6 +7,13 @@ use acf_field_text;
7
8
class text extends acf_field_text {
9
10
/*
11
* __construct
12
*
@@ -15,7 +22,9 @@ class text extends acf_field_text {
15
* @since 3.6
16
* @date 23/01/13
17
*/
18
- function __construct() {
19
$this->name = 'qtranslate_text';
20
$this->label = __("Text",'acf');
21
$this->category = __("qTranslate",'acf');
7
8
class text extends acf_field_text {
9
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
+
17
/*
18
* __construct
19
*
22
* @since 3.6
23
* @date 23/01/13
24
*/
25
+ function __construct($plugin) {
26
+ $this->plugin = $plugin;
27
+
28
$this->name = 'qtranslate_text';
29
$this->label = __("Text",'acf');
30
$this->category = __("qTranslate",'acf');
src/acf_4/fields/textarea.php CHANGED
@@ -7,6 +7,13 @@ use acf_field_textarea;
7
8
class textarea extends acf_field_textarea {
9
10
/*
11
* __construct
12
*
@@ -15,7 +22,9 @@ class textarea extends acf_field_textarea {
15
* @since 3.6
16
* @date 23/01/13
17
*/
18
- function __construct() {
19
$this->name = 'qtranslate_textarea';
20
$this->label = __("Text Area",'acf');
21
$this->category = __("qTranslate",'acf');
7
8
class textarea extends acf_field_textarea {
9
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
+
17
/*
18
* __construct
19
*
22
* @since 3.6
23
* @date 23/01/13
24
*/
25
+ function __construct($plugin) {
26
+ $this->plugin = $plugin;
27
+
28
$this->name = 'qtranslate_textarea';
29
$this->label = __("Text Area",'acf');
30
$this->category = __("qTranslate",'acf');
src/acf_4/fields/wysiwyg.php CHANGED
@@ -7,6 +7,13 @@ use acf_field_wysiwyg;
7
8
class wysiwyg extends acf_field_wysiwyg {
9
10
/*
11
* __construct
12
*
@@ -15,7 +22,9 @@ class wysiwyg extends acf_field_wysiwyg {
15
* @since 3.6
16
* @date 23/01/13
17
*/
18
- function __construct() {
19
$this->name = 'qtranslate_wysiwyg';
20
$this->label = __("Wysiwyg Editor",'acf');
21
$this->category = __("qTranslate",'acf');
7
8
class wysiwyg extends acf_field_wysiwyg {
9
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
+
17
/*
18
* __construct
19
*
22
* @since 3.6
23
* @date 23/01/13
24
*/
25
+ function __construct($plugin) {
26
+ $this->plugin = $plugin;
27
+
28
$this->name = 'qtranslate_wysiwyg';
29
$this->label = __("Wysiwyg Editor",'acf');
30
$this->category = __("qTranslate",'acf');
src/acf_5/acf.php CHANGED
@@ -3,6 +3,7 @@
3
namespace acf_qtranslate\acf_5;
4
5
use acf_qtranslate\acf_5\fields\image;
6
use acf_qtranslate\acf_5\fields\text;
7
use acf_qtranslate\acf_5\fields\textarea;
8
use acf_qtranslate\acf_5\fields\wysiwyg;
@@ -11,11 +12,20 @@ use acf_qtranslate\plugin;
11
12
class acf implements acf_interface {
13
14
/*
15
* Create an instance.
16
* @return void
17
*/
18
- public function __construct() {
19
add_filter('acf/format_value', array($this, 'format_value'));
20
add_action('acf/include_fields', array($this, 'include_fields'));
21
add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
@@ -25,18 +35,20 @@ class acf implements acf_interface {
25
* Load javascript and stylesheets on admin pages.
26
*/
27
public function include_fields() {
28
- new image;
29
- new text;
30
- new textarea;
31
- new wysiwyg;
32
}
33
34
/**
35
* Load javascript and stylesheets on admin pages.
36
*/
37
public function admin_enqueue_scripts() {
38
- wp_enqueue_style('acf_qtranslate_input', plugins_url('/assets/input.css', ACF_QTRANSLATE_PLUGIN));
39
- wp_enqueue_script('acf_qtranslate_input', plugins_url('/assets/input.js', ACF_QTRANSLATE_PLUGIN));
40
}
41
42
/**
3
namespace acf_qtranslate\acf_5;
4
5
use acf_qtranslate\acf_5\fields\image;
6
+ use acf_qtranslate\acf_5\fields\file;
7
use acf_qtranslate\acf_5\fields\text;
8
use acf_qtranslate\acf_5\fields\textarea;
9
use acf_qtranslate\acf_5\fields\wysiwyg;
12
13
class acf implements acf_interface {
14
15
+ /**
16
+ * The plugin instance.
17
+ * @var \acf_qtranslate\plugin
18
+ */
19
+ protected $plugin;
20
+
21
+
22
/*
23
* Create an instance.
24
* @return void
25
*/
26
+ public function __construct($plugin) {
27
+ $this->plugin = $plugin;
28
+
29
add_filter('acf/format_value', array($this, 'format_value'));
30
add_action('acf/include_fields', array($this, 'include_fields'));
31
add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
35
* Load javascript and stylesheets on admin pages.
36
*/
37
public function include_fields() {
38
+ new text($this->plugin);
39
+ new textarea($this->plugin);
40
+ new wysiwyg($this->plugin);
41
+ new image($this->plugin);
42
+ new file($this->plugin);
43
}
44
45
/**
46
* Load javascript and stylesheets on admin pages.
47
*/
48
public function admin_enqueue_scripts() {
49
+ wp_enqueue_style('acf_qtranslate_common', plugins_url('/assets/common.css', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
50
+ wp_enqueue_script('acf_qtranslate_common', plugins_url('/assets/common.js', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
51
+ wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/acf_5/main.js', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
52
}
53
54
/**
src/acf_5/fields/file.php ADDED
@@ -0,0 +1,217 @@
1
+ <?php
2
+
3
+ namespace acf_qtranslate\acf_5\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_file;
7
+
8
+ class file extends acf_field_file {
9
+
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
+
17
+ /*
18
+ * __construct
19
+ *
20
+ * This function will setup the field type data
21
+ *
22
+ * @type function
23
+ * @date 5/03/2014
24
+ * @since 5.0.0
25
+ *
26
+ * @param n/a
27
+ * @return n/a
28
+ */
29
+ function __construct($plugin) {
30
+ $this->plugin = $plugin;
31
+
32
+ $this->name = 'qtranslate_file';
33
+ $this->label = __("File", 'acf');
34
+ $this->category = __("qTranslate", 'acf');
35
+ $this->defaults = array(
36
+ 'return_format' => 'array',
37
+ 'library' => 'all',
38
+ 'min_size' => 0,
39
+ 'max_size' => 0,
40
+ 'mime_types' => ''
41
+ );
42
+ $this->l10n = array(
43
+ 'select' => __("Select File",'acf'),
44
+ 'edit' => __("Edit File",'acf'),
45
+ 'update' => __("Update File",'acf'),
46
+ 'uploadedTo' => __("uploaded to this post",'acf'),
47
+ );
48
+
49
+
50
+ // filters
51
+ add_filter('get_media_item_args', array($this, 'get_media_item_args'));
52
+ add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
53
+
54
+ acf_field::__construct();
55
+ }
56
+
57
+ /*
58
+ * render_field()
59
+ *
60
+ * Create the HTML interface for your field
61
+ *
62
+ * @param $field - an array holding all the field's data
63
+ *
64
+ * @type action
65
+ * @since 3.6
66
+ * @date 23/01/13
67
+ */
68
+ function render_field($field) {
69
+ global $q_config;
70
+ $languages = qtrans_getSortedLanguages(true);
71
+ $values = qtrans_split($field['value'], $quicktags = true);
72
+ $currentLanguage = qtrans_getLanguage();
73
+
74
+ // enqueue
75
+ acf_enqueue_uploader();
76
+
77
+ // vars
78
+ $o = array(
79
+ 'icon' => '',
80
+ 'title' => '',
81
+ 'size' => '',
82
+ 'url' => '',
83
+ 'name' => '',
84
+ );
85
+
86
+ $div = array(
87
+ 'class' => 'acf-file-uploader acf-cf',
88
+ 'data-library' => $field['library'],
89
+ 'data-mime_types' => $field['mime_types']
90
+ );
91
+
92
+ $input_atts = array(
93
+ 'type' => 'hidden',
94
+ 'name' => $field['name'],
95
+ 'value' => $field['value'],
96
+ 'data-name' => 'value-id'
97
+ );
98
+
99
+ $url = '';
100
+
101
+ echo '<div class="multi-language-field multi-language-field-image">';
102
+
103
+ foreach ($languages as $language) {
104
+ $class = 'wp-switch-editor';
105
+ if ($language === $currentLanguage) {
106
+ $class .= ' current-language';
107
+ }
108
+ echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
109
+ }
110
+
111
+ foreach ($languages as $language):
112
+
113
+ $input_atts['name'] = $field['name'] . '[' . $language . ']';
114
+ $field['value'] = $values[$language];
115
+ $div['data-language'] = $language;
116
+ $div['class'] = 'acf-file-uploader acf-cf';
117
+
118
+ // has value?
119
+ if( $field['value'] && is_numeric($field['value']) ) {
120
+ $file = get_post( $field['value'] );
121
+ if( $file ) {
122
+ $div['class'] .= ' has-value';
123
+
124
+ $o['icon'] = wp_mime_type_icon( $file->ID );
125
+ $o['title'] = $file->post_title;
126
+ $o['size'] = @size_format(filesize( get_attached_file( $file->ID ) ));
127
+ $o['url'] = wp_get_attachment_url( $file->ID );
128
+
129
+ $explode = explode('/', $o['url']);
130
+ $o['name'] = end( $explode );
131
+ }
132
+ }
133
+
134
+ // basic?
135
+ $basic = !current_user_can('upload_files');
136
+ if ($basic) {
137
+ $div['class'] .= ' basic';
138
+ }
139
+
140
+ if ($language === $currentLanguage) {
141
+ $div['class'] .= ' current-language';
142
+ }
143
+
144
+ ?>
145
+ <div <?php acf_esc_attr_e($div); ?>>
146
+ <div class="acf-hidden">
147
+ <?php acf_hidden_input(array( 'name' => $input_atts['name'], 'value' => $field['value'], 'data-name' => 'id' )); ?>
148
+ </div>
149
+ <div class="show-if-value file-wrap acf-soh">
150
+ <div class="file-icon">
151
+ <img data-name="icon" src="<?php echo $o['icon']; ?>" alt=""/>
152
+ </div>
153
+ <div class="file-info">
154
+ <p>
155
+ <strong data-name="title"><?php echo $o['title']; ?></strong>
156
+ </p>
157
+ <p>
158
+ <strong><?php _e('File Name', 'acf'); ?>:</strong>
159
+ <a data-name="name" href="<?php echo $o['url']; ?>" target="_blank"><?php echo $o['name']; ?></a>
160
+ </p>
161
+ <p>
162
+ <strong><?php _e('File Size', 'acf'); ?>:</strong>
163
+ <span data-name="size"><?php echo $o['size']; ?></span>
164
+ </p>
165
+
166
+ <ul class="acf-hl acf-soh-target">
167
+ <?php if( !$basic ): ?>
168
+ <li><a class="acf-icon dark" data-name="edit" href="#"><i class="acf-sprite-edit"></i></a></li>
169
+ <?php endif; ?>
170
+ <li><a class="acf-icon dark" data-name="remove" href="#"><i class="acf-sprite-delete"></i></a></li>
171
+ </ul>
172
+ </div>
173
+ </div>
174
+ <div class="hide-if-value">
175
+ <?php if( $basic ): ?>
176
+
177
+ <?php if( $field['value'] && !is_numeric($field['value']) ): ?>
178
+ <div class="acf-error-message"><p><?php echo $field['value']; ?></p></div>
179
+ <?php endif; ?>
180
+
181
+ <input type="file" name="<?php echo $field['name']; ?>" id="<?php echo $field['id']; ?>" />
182
+
183
+ <?php else: ?>
184
+
185
+ <p style="margin:0;"><?php _e('No File selected','acf'); ?> <a data-name="add" class="acf-button" href="#"><?php _e('Add File','acf'); ?></a></p>
186
+
187
+ <?php endif; ?>
188
+
189
+ </div>
190
+ </div>
191
+
192
+ <?php endforeach;
193
+
194
+ echo '</div>';
195
+ }
196
+
197
+ /*
198
+ * update_value()
199
+ *
200
+ * This filter is appied to the $value before it is updated in the db
201
+ *
202
+ * @type filter
203
+ * @since 3.6
204
+ * @date 23/01/13
205
+ *
206
+ * @param $value - the value which will be saved in the database
207
+ * @param $post_id - the $post_id of which the value will be saved
208
+ * @param $field - the field array holding all the field options
209
+ *
210
+ * @return $value - the modified value
211
+ */
212
+ function update_value($value, $post_id, $field) {
213
+ $value = parent::update_value($value, $post_id, $field);
214
+ return qtrans_join($value);
215
+ }
216
+
217
+ }
src/acf_5/fields/image.php CHANGED
@@ -7,6 +7,12 @@ use acf_field_image;
7
8
class image extends acf_field_image {
9
10
/*
11
* __construct
12
*
@@ -19,27 +25,38 @@ class image extends acf_field_image {
19
* @param n/a
20
* @return n/a
21
*/
22
- function __construct() {
23
$this->name = 'qtranslate_image';
24
$this->label = __("Image", 'acf');
25
$this->category = __("qTranslate", 'acf');
26
$this->defaults = array(
27
'return_format' => 'array',
28
'preview_size' => 'thumbnail',
29
- 'library' => 'all'
30
);
31
$this->l10n = array(
32
'select' => __("Select Image",'acf'),
33
'edit' => __("Edit Image",'acf'),
34
'update' => __("Update Image",'acf'),
35
- 'uploadedTo' => __("uploaded to this post",'acf'),
36
);
37
38
- acf_field::__construct();
39
40
// filters
41
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
42
add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
43
}
44
45
/*
@@ -63,17 +80,20 @@ class image extends acf_field_image {
63
acf_enqueue_uploader();
64
65
// vars
66
- $div_atts = array(
67
'class' => 'acf-image-uploader acf-cf',
68
'data-preview_size' => $field['preview_size'],
69
- 'data-library' => $field['library']
70
);
71
$input_atts = array(
72
'type' => 'hidden',
73
'name' => $field['name'],
74
'value' => $field['value'],
75
'data-name' => 'value-id'
76
);
77
$url = '';
78
79
echo '<div class="multi-language-field multi-language-field-image">';
@@ -90,35 +110,50 @@ class image extends acf_field_image {
90
91
$input_atts['name'] = $field['name'] . '[' . $language . ']';
92
$field['value'] = $values[$language];
93
- $div_atts['data-language'] = $language;
94
- $div_atts['class'] = 'acf-image-uploader acf-cf';
95
96
// has value?
97
if( $field['value'] && is_numeric($field['value']) ) {
98
$url = wp_get_attachment_image_src($field['value'], $field['preview_size']);
99
$url = $url[0];
100
101
- $div_atts['class'] .= ' has-value';
102
}
103
104
if ($language === $currentLanguage) {
105
- $div_atts['class'] .= ' current-language';
106
}
107
108
?>
109
- <div <?php acf_esc_attr_e( $div_atts ); ?>>
110
<div class="acf-hidden">
111
- <input <?php acf_esc_attr_e( $input_atts ); ?>/>
112
</div>
113
<div class="view show-if-value acf-soh">
114
<ul class="acf-hl acf-soh-target">
115
- <li><a class="acf-icon dark" data-name="edit-button" href="#"><i class="acf-sprite-edit"></i></a></li>
116
- <li><a class="acf-icon dark" data-name="remove-button" href="#"><i class="acf-sprite-delete"></i></a></li>
117
</ul>
118
- <img data-name="value-url" src="<?php echo $url; ?>" alt=""/>
119
</div>
120
<div class="view hide-if-value">
121
- <p><?php _e('No image selected','acf'); ?> <a data-name="add-button" class="acf-button" href="#"><?php _e('Add Image','acf'); ?></a></p>
122
</div>
123
</div>
124
7
8
class image extends acf_field_image {
9
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
/*
17
* __construct
18
*
25
* @param n/a
26
* @return n/a
27
*/
28
+ function __construct($plugin) {
29
+ $this->plugin = $plugin;
30
+
31
$this->name = 'qtranslate_image';
32
$this->label = __("Image", 'acf');
33
$this->category = __("qTranslate", 'acf');
34
$this->defaults = array(
35
'return_format' => 'array',
36
'preview_size' => 'thumbnail',
37
+ 'library' => 'all',
38
+ 'min_width' => 0,
39
+ 'min_height' => 0,
40
+ 'min_size' => 0,
41
+ 'max_width' => 0,
42
+ 'max_height' => 0,
43
+ 'max_size' => 0,
44
+ 'mime_types' => ''
45
);
46
$this->l10n = array(
47
'select' => __("Select Image",'acf'),
48
'edit' => __("Edit Image",'acf'),
49
'update' => __("Update Image",'acf'),
50
+ 'uploadedTo' => __("Uploaded to this post",'acf'),
51
+ 'all' => __("All images",'acf'),
52
);
53
54
55
// filters
56
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
57
add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
58
+
59
+ acf_field::__construct();
60
}
61
62
/*
80
acf_enqueue_uploader();
81
82
// vars
83
+ $div = array(
84
'class' => 'acf-image-uploader acf-cf',
85
'data-preview_size' => $field['preview_size'],
86
+ 'data-library' => $field['library'],
87
+ 'data-mime_types' => $field['mime_types']
88
);
89
+
90
$input_atts = array(
91
'type' => 'hidden',
92
'name' => $field['name'],
93
'value' => $field['value'],
94
'data-name' => 'value-id'
95
);
96
+
97
$url = '';
98
99
echo '<div class="multi-language-field multi-language-field-image">';
110
111
$input_atts['name'] = $field['name'] . '[' . $language . ']';
112
$field['value'] = $values[$language];
113
+ $div['data-language'] = $language;
114
+ $div['class'] = 'acf-image-uploader acf-cf';
115
116
// has value?
117
if( $field['value'] && is_numeric($field['value']) ) {
118
$url = wp_get_attachment_image_src($field['value'], $field['preview_size']);
119
$url = $url[0];
120
121
+ $div['class'] .= ' has-value';
122
+ }
123
+
124
+ // basic?
125
+ $basic = !current_user_can('upload_files');
126
+ if ($basic) {
127
+ $div['class'] .= ' basic';
128
}
129
130
if ($language === $currentLanguage) {
131
+ $div['class'] .= ' current-language';
132
}
133
134
?>
135
+ <div <?php acf_esc_attr_e( $div ); ?>>
136
<div class="acf-hidden">
137
+ <?php acf_hidden_input(array( 'name' => $input_atts['name'], 'value' => $field['value'], 'data-name' => 'id' )); ?>
138
</div>
139
<div class="view show-if-value acf-soh">
140
+ <img data-name="image" src="<?php echo $url; ?>" alt=""/>
141
<ul class="acf-hl acf-soh-target">
142
+ <?php if( !$basic ): ?>
143
+ <li><a class="acf-icon dark" data-name="edit" href="#"><i class="acf-sprite-edit"></i></a></li>
144
+ <?php endif; ?>
145
+ <li><a class="acf-icon dark" data-name="remove" href="#"><i class="acf-sprite-delete"></i></a></li>
146
</ul>
147
</div>
148
<div class="view hide-if-value">
149
+ <?php if( $basic ): ?>
150
+ <?php if( $field['value'] && !is_numeric($field['value']) ): ?>
151
+ <div class="acf-error-message"><p><?php echo $field['value']; ?></p></div>
152
+ <?php endif; ?>
153
+ <input type="file" name="<?php echo $field['name']; ?>" id="<?php echo $field['id']; ?>" />
154
+ <?php else: ?>
155
+ <p style="margin:0;"><?php _e('No image selected','acf'); ?> <a data-name="add" class="acf-button" href="#"><?php _e('Add Image','acf'); ?></a></p>
156
+ <?php endif; ?>
157
</div>
158
</div>
159
src/acf_5/fields/text.php CHANGED
@@ -7,6 +7,13 @@ use acf_field_text;
7
8
class text extends acf_field_text {
9
10
/*
11
* __construct
12
*
@@ -19,7 +26,9 @@ class text extends acf_field_text {
19
* @param n/a
20
* @return n/a
21
*/
22
- function __construct() {
23
$this->name = 'qtranslate_text';
24
$this->label = __("Text",'acf');
25
$this->category = __("qTranslate",'acf');
7
8
class text extends acf_field_text {
9
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
+
17
/*
18
* __construct
19
*
26
* @param n/a
27
* @return n/a
28
*/
29
+ function __construct($plugin) {
30
+ $this->plugin = $plugin;
31
+
32
$this->name = 'qtranslate_text';
33
$this->label = __("Text",'acf');
34
$this->category = __("qTranslate",'acf');
src/acf_5/fields/textarea.php CHANGED
@@ -7,6 +7,13 @@ use acf_field_textarea;
7
8
class textarea extends acf_field_textarea {
9
10
/*
11
* __construct
12
*
@@ -19,7 +26,9 @@ class textarea extends acf_field_textarea {
19
* @param n/a
20
* @return n/a
21
*/
22
- function __construct() {
23
$this->name = 'qtranslate_textarea';
24
$this->label = __("Text Area",'acf');
25
$this->category = __("qTranslate",'acf');
7
8
class textarea extends acf_field_textarea {
9
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
+
17
/*
18
* __construct
19
*
26
* @param n/a
27
* @return n/a
28
*/
29
+ function __construct($plugin) {
30
+ $this->plugin = $plugin;
31
+
32
$this->name = 'qtranslate_textarea';
33
$this->label = __("Text Area",'acf');
34
$this->category = __("qTranslate",'acf');
src/acf_5/fields/wysiwyg.php CHANGED
@@ -7,6 +7,13 @@ use acf_field_wysiwyg;
7
8
class wysiwyg extends acf_field_wysiwyg {
9
10
/*
11
* __construct
12
*
@@ -19,15 +26,17 @@ class wysiwyg extends acf_field_wysiwyg {
19
* @param n/a
20
* @return n/a
21
*/
22
- function __construct() {
23
$this->name = 'qtranslate_wysiwyg';
24
$this->label = __("Wysiwyg Editor",'acf');
25
$this->category = __("qTranslate",'acf');
26
$this->defaults = array(
27
- 'tabs' => 'all',
28
- 'toolbar' => 'full',
29
- 'media_upload' => 1,
30
- 'default_value' => '',
31
);
32
33
// Create an acf version of the_content filter (acf_the_content)
@@ -45,7 +54,128 @@ class wysiwyg extends acf_field_wysiwyg {
45
add_filter( 'acf_the_content', 'prepend_attachment' );
46
add_filter( 'acf_the_content', 'do_shortcode', 11);
47
48
acf_field::__construct();
49
}
50
51
}
7
8
class wysiwyg extends acf_field_wysiwyg {
9
10
+ /**
11
+ * The plugin instance.
12
+ * @var \acf_qtranslate\plugin
13
+ */
14
+ protected $plugin;
15
+
16
+
17
/*
18
* __construct
19
*
26
* @param n/a
27
* @return n/a
28
*/
29
+ function __construct($plugin) {
30
+ $this->plugin = $plugin;
31
+
32
$this->name = 'qtranslate_wysiwyg';
33
$this->label = __("Wysiwyg Editor",'acf');
34
$this->category = __("qTranslate",'acf');
35
$this->defaults = array(
36
+ 'tabs' => 'all',
37
+ 'toolbar' => 'full',
38
+ 'media_upload' => 1,
39
+ 'default_value' => '',
40
);
41
42
// Create an acf version of the_content filter (acf_the_content)
54
add_filter( 'acf_the_content', 'prepend_attachment' );
55
add_filter( 'acf_the_content', 'do_shortcode', 11);
56
57
+ // actions
58
+ add_action('acf/input/admin_footer_js', array($this, 'input_admin_footer_js'));
59
+
60
acf_field::__construct();
61
}
62
63
+ /*
64
+ * render_field()
65
+ *
66
+ * Create the HTML interface for your field
67
+ *
68
+ * @param $field - an array holding all the field's data
69
+ *
70
+ * @type action
71
+ * @since 3.6
72
+ * @date 23/01/13
73
+ */
74
+ function render_field($field) {
75
+
76
+ // enqueue
77
+ acf_enqueue_uploader();
78
+
79
+ // vars
80
+ $id = uniqid('acf-editor-');
81
+ //$id = $field['id'] . '-' . uniqid();
82
+ $mode = 'html';
83
+ $show_tabs = true;
84
+
85
+ // get height
86
+ $height = acf_get_user_setting('wysiwyg_height', 300);
87
+ $height = max( $height, 300 ); // minimum height is 300
88
+
89
+ // detect mode
90
+ // case: visual tab only
91
+ if ($field['tabs'] == 'visual') {
92
+ $mode = 'tmce';
93
+ $show_tabs = false;
94
+ }
95
+ // case: text tab only
96
+ elseif ($field['tabs'] == 'text') {
97
+ $show_tabs = false;
98
+ }
99
+ // case: both tabs
100
+ elseif (wp_default_editor() == 'tinymce') {
101
+ $mode = 'tmce';
102
+ }
103
+
104
+ // mode
105
+ $switch_class = $mode . '-active';
106
+
107
+ // filter value for editor
108
+ remove_all_filters('acf_the_editor_content');
109
+
110
+ if ($mode == 'tmce') {
111
+ add_filter('acf_the_editor_content', 'wp_richedit_pre');
112
+ }
113
+ else {
114
+ add_filter('acf_the_editor_content', 'wp_htmledit_pre');
115
+ }
116
+
117
+ global $q_config, $wp_version;
118
+ $languages = qtrans_getSortedLanguages(true);
119
+ $values = qtrans_split($field['value'], $quicktags = true);
120
+
121
+ echo '<div class="multi-language-field multi-language-field-wysiwyg">';
122
+
123
+ foreach ($languages as $language) {
124
+ $class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
125
+ echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
126
+ }
127
+
128
+ $uid = uniqid('acf-editor-');
129
+ foreach ($languages as $language):
130
+ $value = apply_filters('acf_the_editor_content', $values[$language]);
131
+ $id = $uid . "-$language";
132
+ $name = $field['name'] . "[$language]";
133
+ if ($language === end($languages)) {
134
+ $switch_class .= ' current-language';
135
+ }
136
+
137
+ ?>
138
+ <div id="wp-<?php echo $id; ?>-wrap" class="acfqt-inactive acf-editor-wrap wp-core-ui wp-editor-wrap <?php echo $switch_class; ?>" data-toolbar="<?php echo $field['toolbar']; ?>" data-upload="<?php echo $field['media_upload']; ?>" data-language="<?php echo $language; ?>">
139
+ <div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools hide-if-no-js">
140
+ <?php if( $field['media_upload'] ): ?>
141
+ <div id="wp-<?php echo $id; ?>-media-buttons" class="wp-media-buttons">
142
+ <?php do_action( 'media_buttons' ); ?>
143
+ </div>
144
+ <?php endif; ?>
145
+ <?php if( user_can_richedit() && $show_tabs ): ?>
146
+ <div class="wp-editor-tabs">
147
+ <button id="<?php echo $id; ?>-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);" type="button"><?php echo __('Visual', 'acf'); ?></button>
148
+ <button id="<?php echo $id; ?>-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);" type="button"><?php echo _x( 'Text', 'Name for the Text editor tab (formerly HTML)', 'acf' ); ?></button>
149
+ </div>
150
+ <?php endif; ?>
151
+ </div>
152
+ <div id="wp-<?php echo $id; ?>-editor-container" class="wp-editor-container">
153
+ <textarea id="<?php echo $id; ?>" class="wp-editor-area" name="<?php echo $name; ?>" <?php if($height): ?>style="height:<?php echo $height; ?>px;"<?php endif; ?>><?php echo $value; ?></textarea>
154
+ </div>
155
+ </div>
156
+
157
+ <?php endforeach;
158
+
159
+ echo '</div>';
160
+ }
161
+
162
+ /*
163
+ * update_value()
164
+ *
165
+ * This filter is appied to the $value before it is updated in the db
166
+ *
167
+ * @type filter
168
+ * @since 3.6
169
+ * @date 23/01/13
170
+ *
171
+ * @param $value - the value which will be saved in the database
172
+ * @param $post_id - the $post_id of which the value will be saved
173
+ * @param $field - the field array holding all the field options
174
+ *
175
+ * @return $value - the modified value
176
+ */
177
+ function update_value($value, $post_id, $field) {
178
+ return qtrans_join($value);
179
+ }
180
+
181
}
src/plugin.php CHANGED
@@ -24,12 +24,17 @@ class plugin {
24
25
// setup qtranslate fields for ACF 4
26
if ($this->acf_major_version() === 4) {
27
- $acf = new acf_4;
28
}
29
30
// setup qtranslate fields for ACF 5
31
if ($this->acf_major_version() === 5) {
32
- $acf = new acf_5;
33
}
34
35
// setup qtranslatex integration
@@ -98,7 +103,7 @@ class plugin {
98
'qtranslate-x/qtranslate.php',
99
'qtranslate-xp/ppqtranslate.php',
100
);
101
- foreach ($plugins as $name => $identifier) {
102
if ($this->is_plugin_active($identifier)) {
103
return true;
104
}
@@ -106,11 +111,25 @@ class plugin {
106
return false;
107
}
108
109
/**
110
* Check if qTranslate-X is enabled
111
*/
112
public function qtranslatex_enabled() {
113
- return defined('QTX_VERSION');
114
}
115
116
}
24
25
// setup qtranslate fields for ACF 4
26
if ($this->acf_major_version() === 4) {
27
+ $acf = new acf_4($this);
28
}
29
30
// setup qtranslate fields for ACF 5
31
if ($this->acf_major_version() === 5) {
32
+ $acf = new acf_5($this);
33
+ }
34
+
35
+ // setup ppqtranslate integration
36
+ if ($this->ppqtranslate_enabled()) {
37
+ new ppqtranslate($this, $acf);
38
}
39
40
// setup qtranslatex integration
103
'qtranslate-x/qtranslate.php',
104
'qtranslate-xp/ppqtranslate.php',
105
);
106
+ foreach ($plugins as $identifier) {
107
if ($this->is_plugin_active($identifier)) {
108
return true;
109
}
111
return false;
112
}
113
114
+ /**
115
+ * Check if qTranslate Plus is enabled
116
+ */
117
+ public function ppqtranslate_enabled() {
118
+ return function_exists('ppqtrans_getLanguage');
119
+ }
120
+
121
/**
122
* Check if qTranslate-X is enabled
123
*/
124
public function qtranslatex_enabled() {
125
+ return function_exists('qtranxf_getLanguage');
126
+ }
127
+
128
+ /**
129
+ * Check if mqTranslate is enabled
130
+ */
131
+ public function mqtranslate_enabled() {
132
+ return function_exists('mqtrans_currentUserCanEdit');
133
}
134
135
}
src/ppqtranslate.php ADDED
@@ -0,0 +1,33 @@
1
+ <?php
2
+
3
+ namespace acf_qtranslate;
4
+
5
+ class ppqtranslate {
6
+
7
+ /**
8
+ * An ACF instance.
9
+ * @var \acf_qtranslate\acf_interface
10
+ */
11
+ protected $acf;
12
+
13
+ /**
14
+ * The plugin instance.
15
+ * @var \acf_qtranslate\plugin
16
+ */
17
+ protected $plugin;
18
+
19
+
20
+ /**
21
+ * Create an instance.
22
+ * @return void
23
+ */
24
+ public function __construct(plugin $plugin, acf_interface $acf) {
25
+ $this->acf = $acf;
26
+ $this->plugin = $plugin;
27
+
28
+ // include compatibility functions
29
+ require_once ACF_QTRANSLATE_PLUGIN_DIR . 'compatibility/ppqtranslate.php';
30
+
31
+ }
32
+
33
+ }
src/qtranslatex.php CHANGED
@@ -25,10 +25,11 @@ class qtranslatex {
25
$this->acf = $acf;
26
$this->plugin = $plugin;
27
28
- // load qtranslate compatibility layer
29
- require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/qtranslatex/qtranslate-compatibility.php';
30
31
add_filter('admin_head', array($this, 'admin_head'));
32
add_filter('qtranslate_load_admin_page_config', array($this, 'qtranslate_load_admin_page_config'));
33
}
34
@@ -52,12 +53,30 @@ class qtranslatex {
52
global $pagenow;
53
54
$fields = $this->acf->get_visible_acf_fields();
55
- array_push($configs, array(
56
- 'pages' => array($pagenow => ''),
57
- 'forms' => array(array('fields' => $fields))
58
- ));
59
60
return $configs;
61
}
62
63
}
25
$this->acf = $acf;
26
$this->plugin = $plugin;
27
28
+ // include compatibility functions
29
+ require_once ACF_QTRANSLATE_PLUGIN_DIR . 'compatibility/qtranslatex.php';
30
31
add_filter('admin_head', array($this, 'admin_head'));
32
+ add_filter('qtranslate_custom_admin_js', array($this, 'qtranslate_custom_admin_js'));
33
add_filter('qtranslate_load_admin_page_config', array($this, 'qtranslate_load_admin_page_config'));
34
}
35
53
global $pagenow;
54
55
$fields = $this->acf->get_visible_acf_fields();
56
+ if (count($fields)) {
57
+ // ACF uses a single tinyMCE editor mceInit
58
+ // for all it's WYSIWYG fields
59
+ $fields[] = array('id' => 'acf_settings');
60
+
61
+ array_push($configs, array(
62
+ 'pages' => array($pagenow => ''),
63
+ 'forms' => array(array('fields' => $fields))
64
+ ));
65
+ }
66
67
return $configs;
68
}
69
70
+ /**
71
+ * Use the edit-post script on admin pages.
72
+ * @return string
73
+ */
74
+ public function qtranslate_custom_admin_js() {
75
+ global $pagenow;
76
+
77
+ if ($pagenow === 'admin.php' && isset($_GET['page'])) {
78
+ return 'admin/js/edit-post';
79
+ }
80
+ }
81
+
82
}