ACF qTranslate - Version 1.5

Version Description

Added support for qTranslate-X Remove ACFv5 WYSIWYG implementation as it was very broken

Download this release

Release Info

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

Code changes from version 1.4 to 1.5

acf-qtranslate.php CHANGED
@@ -29,21 +29,135 @@ function acf_qtranslate_acf_major_version() {
29
  }
30
 
31
 
 
 
 
 
 
 
 
 
32
 
33
- // qTranslate Monkey Patches
34
 
35
- add_action('plugins_loaded', 'acf_qtranslate_monkey_patch', 3);
36
- function acf_qtranslate_monkey_patch() {
 
37
  global $q_config;
38
 
39
- // http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=3497
40
- if (strpos($q_config['js']['qtrans_switch'], 'originalSwitchEditors') === false) {
41
- $q_config['js']['qtrans_switch'] = "originalSwitchEditors = jQuery.extend(true, {}, switchEditors);\n" . $q_config['js']['qtrans_switch'];
42
- $q_config['js']['qtrans_switch'] = preg_replace("/(var vta = document\.getElementById\('qtrans_textarea_' \+ id\);)/", "\$1\nif(!vta)return originalSwitchEditors.go(id, lang);", $q_config['js']['qtrans_switch']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- // https://github.com/funkjedi/acf-qtranslate/issues/2#issuecomment-37612918
46
- if (strpos($q_config['js']['qtrans_hook_on_tinyMCE'], 'ed.editorId.match(/^qtrans_/)') === false) {
47
- $q_config['js']['qtrans_hook_on_tinyMCE'] = preg_replace("/(qtrans_save\(switchEditors\.pre_wpautop\(o\.content\)\);)/", "if (ed.editorId.match(/^qtrans_/)) \$1", $q_config['js']['qtrans_hook_on_tinyMCE']);
48
  }
 
 
49
  }
29
  }
30
 
31
 
32
+ // if using qTranslate-X include a qTranslate compatibility
33
+ // layer for all required functions
34
+ add_action('plugins_loaded', 'acf_qtranslate_compatibility', 3);
35
+ function acf_qtranslate_compatibility() {
36
+ if (defined('QTX_VERSION')) {
37
+ require_once dirname(__FILE__) . '/qtranslate-compatibility.php';
38
+ }
39
+ }
40
 
 
41
 
42
+ // qTranslate Monkey Patches
43
+ add_action('plugins_loaded', 'acf_qtranslate_monkey_patches', 3);
44
+ function acf_qtranslate_monkey_patches() {
45
  global $q_config;
46
 
47
+ // qTranslate and mqTranslate init at priority 3 so if they
48
+ // are active then QTRANS_INIT should be defined
49
+ if (acf_qtranslate_enabled() && defined('QTRANS_INIT')) {
50
+
51
+ // http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=3497
52
+ if (strpos($q_config['js']['qtrans_switch'], 'originalSwitchEditors') === false) {
53
+ $q_config['js']['qtrans_switch'] = "originalSwitchEditors = jQuery.extend(true, {}, switchEditors);\n" . $q_config['js']['qtrans_switch'];
54
+ $q_config['js']['qtrans_switch'] = preg_replace("/(var vta = document\.getElementById\('qtrans_textarea_' \+ id\);)/", "\$1\nif(!vta)return originalSwitchEditors.go(id, lang);", $q_config['js']['qtrans_switch']);
55
+ }
56
+
57
+ // https://github.com/funkjedi/acf-qtranslate/issues/2#issuecomment-37612918
58
+ if (strpos($q_config['js']['qtrans_hook_on_tinyMCE'], 'ed.editorId.match(/^qtrans_/)') === false) {
59
+ $q_config['js']['qtrans_hook_on_tinyMCE'] = preg_replace("/(qtrans_save\(switchEditors\.pre_wpautop\(o\.content\)\);)/", "if (ed.editorId.match(/^qtrans_/)) \$1", $q_config['js']['qtrans_hook_on_tinyMCE']);
60
+ }
61
+
62
+ }
63
+ }
64
+
65
+
66
+
67
+ function acf_qtranslate_get_visible_fields($args = false) {
68
+ global $post, $typenow;
69
+ if ($args === false) {
70
+ $args = array(
71
+ 'post_id' => $post->ID,
72
+ 'post_type' => $typenow,
73
+ );
74
+ }
75
+ $supported_field_types = array(
76
+ 'text',
77
+ 'textarea',
78
+ );
79
+ $field_ids = array();
80
+ foreach (acf_get_field_groups($args) as $field_group) {
81
+ $fields = acf_get_fields($field_group);
82
+ foreach ($fields as $field) {
83
+ if (in_array($field['type'], $supported_field_types)) {
84
+ $field_ids[] = array('id' => 'acf-' . $field['key']);
85
+ }
86
+ }
87
  }
88
+ return $field_ids;
89
+ }
90
+
91
+
92
+ add_filter('qtranslate_load_admin_page_config', 'acf_qtranslate_load_admin_page_config');
93
+ function acf_qtranslate_load_admin_page_config($page_configs)
94
+ {
95
+ global $pagenow;
96
+ switch ($pagenow) {
97
+
98
+ // add support for regular pages and posts
99
+ case 'post.php':
100
+ case 'post-new.php':
101
+ $page_configs[] = array(
102
+ 'pages' => array(
103
+ 'post.php' => '',
104
+ 'post-new.php' => ''),
105
+ 'forms' => array(
106
+ array('fields' => acf_qtranslate_get_visible_fields())
107
+ ));
108
+ break;
109
+
110
+ // add support for ACF Option Pages
111
+ case 'admin.php':
112
+ foreach (acf_get_options_pages() as $page) {
113
+ $page_configs[] = array(
114
+ 'pages' => array('admin.php' => 'page=' . $page['menu_slug']),
115
+ 'forms' => array(
116
+ array('fields' => acf_qtranslate_get_visible_fields())
117
+ ));
118
+ }
119
+ break;
120
+
121
+ // add support for new user page
122
+ case 'user-new.php':
123
+ $args = array(
124
+ 'user_id' => 'new',
125
+ 'user_form' => 'edit',
126
+ );
127
+ $page_configs[] = array(
128
+ 'pages' => array('user-new.php' => ''),
129
+ 'forms' => array(
130
+ array('fields' => acf_qtranslate_get_visible_fields($args))
131
+ ));
132
+ break;
133
+
134
+ // add support for edit user page
135
+ case 'user-edit.php':
136
+ $args = array(
137
+ 'user_id' => @$_GET['user_id'],
138
+ 'user_form' => 'edit',
139
+ );
140
+ $page_configs[] = array(
141
+ 'pages' => array('user-edit.php' => 'user_id='),
142
+ 'forms' => array(
143
+ array('fields' => acf_qtranslate_get_visible_fields($args))
144
+ ));
145
+ break;
146
+
147
+ // add support for profile page
148
+ case 'profile.php':
149
+ $args = array(
150
+ 'user_id' => get_current_user_id(),
151
+ 'user_form' => 'edit',
152
+ );
153
+ $page_configs[] = array(
154
+ 'pages' => array('profile.php' => ''),
155
+ 'forms' => array(
156
+ array('fields' => acf_qtranslate_get_visible_fields($args))
157
+ ));
158
+ break;
159
 
 
 
 
160
  }
161
+
162
+ return $page_configs;
163
  }
qtranslate-compatibility.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // compatibility with qTranslate-X
4
+
5
+ if (function_exists('qtrans_getLanguage') === false):
6
+ function qtrans_getLanguage() {
7
+ return qtranxf_getLanguage();
8
+ }
9
+ endif;
10
+
11
+ if (function_exists('qtrans_getSortedLanguages') === false):
12
+ function qtrans_getSortedLanguages($reverse = false) {
13
+ return qtranxf_getSortedLanguages($reverse);
14
+ }
15
+ endif;
16
+
17
+ if (function_exists('qtrans_join') === false):
18
+ function qtrans_join($texts) {
19
+ // qtranxf_join_c doesn't handle non-array values to
20
+ // maintain compatibility with qtrans_join we must handle it here
21
+ if (is_array($texts) === false) {
22
+ $texts = qtranxf_split($texts, false);
23
+ }
24
+ return qtranxf_join_c($texts);
25
+ }
26
+ endif;
27
+
28
+ if (function_exists('qtrans_split') === false):
29
+ function qtrans_split($text, $quicktags = true) {
30
+ return qtranxf_split($text, $quicktags);
31
+ }
32
+ endif;
33
+
34
+ if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage') === false):
35
+ function qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($content) {
36
+ return qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($content);
37
+ }
38
+ endif;
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: funkjedi
3
  Tags: acf, advanced custom fields, qtranslate, add-on, admin
4
  Requires at least: 3.0.0
5
- Tested up to: 3.9.2
6
- Version: 1.4
7
- Stable tag: 1.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -48,6 +48,10 @@ The plugin is based on code samples posted to the [ACF support forums](http://ol
48
 
49
  == Changelog ==
50
 
 
 
 
 
51
  = 1.4 =
52
  Updated with support for Advanced Customs Fields v5
53
  Tested using mqTranslate in place of 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.5
7
+ Stable tag: 1.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
48
 
49
  == Changelog ==
50
 
51
+ = 1.5 =
52
+ Added support for qTranslate-X
53
+ Remove ACFv5 WYSIWYG implementation as it was very broken
54
+
55
  = 1.4 =
56
  Updated with support for Advanced Customs Fields v5
57
  Tested using mqTranslate in place of qTranslate
v4/assets/input.css CHANGED
@@ -1,4 +1,7 @@
1
 
 
 
 
2
 
3
  .qtrans_title_wrap {
4
  margin-bottom: 20px;
@@ -18,14 +21,6 @@
18
 
19
  .acf_wysiwyg .wp-editor-container { border: 1px solid #e5e5e5 !important; }
20
 
21
- .multi-language-field {
22
- margin-top: -38px;
23
- }
24
-
25
- .acf-input-table .multi-language-field {
26
- margin-top: -6px;
27
- }
28
-
29
  .multi-language-field .wp-switch-editor {
30
  border-color: #dedede;
31
  position: relative;
@@ -60,7 +55,8 @@
60
  .multi-language-field > textarea,
61
  .multi-language-field > fieldset,
62
  .multi-language-field .acf_wysiwyg,
63
- .multi-language-field .acf-image-uploader { display: none }
 
64
 
65
  .multi-language-field .acf_input input,
66
  .multi-language-field .acf_input textarea,
@@ -68,13 +64,15 @@
68
 
69
  .multi-language-field-wysiwyg { margin-top: 0 }
70
 
71
- .multi-language-field .acf-image-uploader {
 
72
  padding: 20px 10px 10px;
73
  clear: right;
74
  border: 1px solid #dfdfdf;
75
  }
76
 
77
- .multi-language-field .acf-image-uploader.current-language { background: #fff; }
 
78
 
79
  .multi-language-field-wysiwyg .wp-switch-editor {
80
  background-color: #ebebeb;
1
 
2
+ .multi-language-field { margin-top: -38px; }
3
+
4
+ #edit-slug-box { margin-top: -15px; }
5
 
6
  .qtrans_title_wrap {
7
  margin-bottom: 20px;
21
 
22
  .acf_wysiwyg .wp-editor-container { border: 1px solid #e5e5e5 !important; }
23
 
 
 
 
 
 
 
 
 
24
  .multi-language-field .wp-switch-editor {
25
  border-color: #dedede;
26
  position: relative;
55
  .multi-language-field > textarea,
56
  .multi-language-field > fieldset,
57
  .multi-language-field .acf_wysiwyg,
58
+ .multi-language-field .acf-image-uploader,
59
+ .multi-language-field .acf-file-uploader { display: none }
60
 
61
  .multi-language-field .acf_input input,
62
  .multi-language-field .acf_input textarea,
64
 
65
  .multi-language-field-wysiwyg { margin-top: 0 }
66
 
67
+ .multi-language-field .acf-image-uploader,
68
+ .multi-language-field .acf-file-uploader {
69
  padding: 20px 10px 10px;
70
  clear: right;
71
  border: 1px solid #dfdfdf;
72
  }
73
 
74
+ .multi-language-field .acf-image-uploader.current-language,
75
+ .multi-language-field .acf-file-uploader { background: #fff; }
76
 
77
  .multi-language-field-wysiwyg .wp-switch-editor {
78
  background-color: #ebebeb;
v4/fields/file.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class acf_field_qtranslate_file extends acf_field_file
4
+ {
5
+
6
+ function __construct()
7
+ {
8
+ // Grab defaults
9
+ $this->name = 'qtranslate_file';
10
+ $this->label = __("File",'acf');
11
+ $this->category = __("qTranslate", 'acf');
12
+ $this->defaults = array(
13
+ 'save_format' => 'object',
14
+ 'library' => 'all'
15
+ );
16
+ $this->l10n = array(
17
+ 'select' => __("Select File",'acf'),
18
+ 'edit' => __("Edit File",'acf'),
19
+ 'update' => __("Update File",'acf'),
20
+ 'uploadedTo' => __("uploaded to this post",'acf'),
21
+ );
22
+
23
+ acf_field::__construct();
24
+
25
+ // filters
26
+ add_filter('get_media_item_args', array($this, 'get_media_item_args'));
27
+ add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
28
+
29
+
30
+ // JSON
31
+ add_action('wp_ajax_acf/fields/file/get_files', array($this, 'ajax_get_files'));
32
+ add_action('wp_ajax_nopriv_acf/fields/file/get_files', array($this, 'ajax_get_files'), 10, 1);
33
+ }
34
+
35
+ function create_field($field)
36
+ {
37
+ if (!acf_qtranslate_enabled()) {
38
+ parent::create_field($field);
39
+ return;
40
+ }
41
+
42
+ global $q_config;
43
+ $languages = qtrans_getSortedLanguages(true);
44
+ $values = qtrans_split($field['value'], $quicktags = true);
45
+ $currentLanguage = qtrans_getLanguage();
46
+
47
+ echo '<div class="multi-language-field multi-language-field-file">';
48
+
49
+ foreach ($languages as $language) {
50
+ $class = 'wp-switch-editor';
51
+ if ($language === $currentLanguage) {
52
+ $class .= ' current-language';
53
+ }
54
+ echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
55
+ }
56
+
57
+ $base_class = $field['class'];
58
+ $base_name = $field['name'];
59
+ foreach ($languages as $language) :
60
+ $value = $values[$language];
61
+ $o = array(
62
+ 'class' => '',
63
+ 'icon' => '',
64
+ 'title' => '',
65
+ 'size' => '',
66
+ 'url' => '',
67
+ 'name' => '',
68
+ );
69
+
70
+ if($value && is_numeric($value)) {
71
+ $file = get_post($value);
72
+
73
+ if($file) {
74
+ $o['class'] = 'active';
75
+ $o['icon'] = wp_mime_type_icon( $file->ID );
76
+ $o['title'] = $file->post_title;
77
+ $o['size'] = size_format(filesize( get_attached_file( $file->ID ) ));
78
+ $o['url'] = wp_get_attachment_url( $file->ID );
79
+
80
+ $explode = explode('/', $o['url']);
81
+ $o['name'] = end( $explode );
82
+ }
83
+ }
84
+
85
+ $field['class'] = $base_class;
86
+ if ($language === $currentLanguage) {
87
+ $field['class'] .= ' current-language';
88
+ $o['class'] .= ' current-language';
89
+ }
90
+
91
+ $field['name'] = $base_name . '[' . $language . ']';
92
+
93
+ ?>
94
+ <div class="acf-file-uploader clearfix <?php echo $o['class']; ?>" data-library="<?php echo $field['library']; ?>" data-language="<?php echo $language; ?>">
95
+ <input class="acf-file-value" type="hidden" name="<?php echo $field['name']; ?>" value="<?php echo $value; ?>" />
96
+ <div class="has-file">
97
+ <ul class="hl clearfix">
98
+ <li>
99
+ <img class="acf-file-icon" src="<?php echo $o['icon']; ?>" alt=""/>
100
+ <div class="hover">
101
+ <ul class="bl">
102
+ <li><a href="#" class="acf-button-delete ir">Remove</a></li>
103
+ <li><a href="#" class="acf-button-edit ir">Edit</a></li>
104
+ </ul>
105
+ </div>
106
+ </li>
107
+ <li>
108
+ <p>
109
+ <strong class="acf-file-title"><?php echo $o['title']; ?></strong>
110
+ </p>
111
+ <p>
112
+ <strong><?php _e('Name', 'acf'); ?>:</strong>
113
+ <a class="acf-file-name" href="<?php echo $o['url']; ?>" target="_blank"><?php echo $o['name']; ?></a>
114
+ </p>
115
+ <p>
116
+ <strong><?php _e('Size', 'acf'); ?>:</strong>
117
+ <span class="acf-file-size"><?php echo $o['size']; ?></span>
118
+ </p>
119
+
120
+ </li>
121
+ </ul>
122
+ </div>
123
+ <div class="no-file">
124
+ <ul class="hl clearfix">
125
+ <li>
126
+ <p><?php _e('No File Selected','acf'); ?> <a href="#" class="button add-file"><?php _e('Add File','acf'); ?></p></a>
127
+ </li>
128
+ </ul>
129
+ </div>
130
+ </div>
131
+ <?php endforeach;
132
+
133
+ echo '</div>';
134
+ }
135
+
136
+ function format_value($value, $post_id, $field)
137
+ {
138
+ return $value;
139
+ }
140
+
141
+ function format_value_for_api($value, $post_id, $field)
142
+ {
143
+ if (acf_qtranslate_enabled()) {
144
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
145
+ }
146
+
147
+ return parent::format_value_for_api($value, $post_id, $field);
148
+ }
149
+
150
+ function update_value($value, $post_id, $field)
151
+ {
152
+ if (acf_qtranslate_enabled()) {
153
+ $value = qtrans_join($value);
154
+ }
155
+
156
+ return $value;
157
+ }
158
+
159
+ function create_options( $field )
160
+ {
161
+ parent::create_options($field);
162
+ }
163
+ }
164
+
165
+ new acf_field_qtranslate_file();
v4/init.php CHANGED
@@ -14,6 +14,7 @@ function acf_qtranslate_plugin_v4_register_fields() {
14
  require_once dirname(__FILE__) . '/fields/textarea.php';
15
  require_once dirname(__FILE__) . '/fields/wysiwyg.php';
16
  require_once dirname(__FILE__) . '/fields/image.php';
 
17
  }
18
 
19
  add_filter('acf/format_value_for_api', 'acf_qtranslate_plugin_v4_format_value_for_api');
14
  require_once dirname(__FILE__) . '/fields/textarea.php';
15
  require_once dirname(__FILE__) . '/fields/wysiwyg.php';
16
  require_once dirname(__FILE__) . '/fields/image.php';
17
+ require_once dirname(__FILE__) . '/fields/file.php';
18
  }
19
 
20
  add_filter('acf/format_value_for_api', 'acf_qtranslate_plugin_v4_format_value_for_api');
v5/assets/input.css CHANGED
@@ -31,6 +31,7 @@
31
  position: relative;
32
  top: 1px;
33
  z-index: 100;
 
34
  }
35
 
36
  .multi-language-field input,
31
  position: relative;
32
  top: 1px;
33
  z-index: 100;
34
+ float: right;
35
  }
36
 
37
  .multi-language-field input,
v5/assets/input.js CHANGED
@@ -11,7 +11,7 @@ jQuery(function($) {
11
 
12
  // if a TinyMCE hasn't been initalize for this language then initalize it
13
  if (!parent.find('.current-language .mce-tinymce').length) {
14
- acf.do_action('ready', parent.parents('.acf-field'));
15
  }
16
  });
17
 
@@ -25,346 +25,3 @@ jQuery(function($) {
25
 
26
 
27
  });
28
-
29
-
30
-
31
- (function($){
32
-
33
- acf.fields.qtranslate_wysiwyg = acf.field.extend({
34
-
35
- type: 'qtranslate_wysiwyg',
36
- $el: null,
37
- $textarea: null,
38
- toolbars: {},
39
-
40
- actions: {
41
- 'ready': 'initialize',
42
- 'append': 'initialize',
43
- 'remove': 'disable',
44
- 'sortstart': 'disable',
45
- 'sortstop': 'enable'
46
- },
47
-
48
- focus: function(){
49
-
50
- // update vars
51
- this.$el = this.$field.find('.wp-editor-wrap.current-language').last();
52
- this.$textarea = this.$el.find('textarea');
53
-
54
-
55
- // settings
56
- this.settings = acf.get_data( this.$el );
57
- this.settings.id = this.$textarea.attr('id');
58
- },
59
-
60
- initialize: function(){
61
-
62
- // bail early if no tinymce
63
- if( typeof tinyMCEPreInit === 'undefined' ) {
64
-
65
- return false;
66
-
67
- }
68
-
69
-
70
- // vars
71
- var mceInit = this.get_mceInit(),
72
- qtInit = this.get_qtInit();
73
-
74
-
75
- // append settings
76
- tinyMCEPreInit.mceInit[ mceInit.id ] = mceInit;
77
- tinyMCEPreInit.qtInit[ qtInit.id ] = qtInit;
78
-
79
-
80
- // initialize mceInit
81
- if( this.$el.hasClass('tmce-active') ) {
82
-
83
- try {
84
-
85
- tinymce.init( mceInit );
86
-
87
- } catch(e){}
88
-
89
- }
90
-
91
-
92
- // initialize qtInit
93
- try {
94
-
95
- var qtag = quicktags( qtInit );
96
-
97
- this._buttonsInit( qtag );
98
-
99
- } catch(e){}
100
-
101
- },
102
-
103
-
104
- get_mceInit : function(){
105
-
106
- // reference
107
- var $field = this.$field;
108
-
109
-
110
- // vars
111
- var toolbar = this.get_toolbar( this.settings.toolbar ),
112
- mceInit = $.extend({}, tinyMCEPreInit.mceInit.acf_content);
113
-
114
-
115
- // selector
116
- mceInit.selector = '#' + this.settings.id;
117
-
118
-
119
- // id
120
- mceInit.id = this.settings.id; // tinymce v4
121
- mceInit.elements = this.settings.id; // tinymce v3
122
-
123
-
124
- // toolbar
125
- if( toolbar ) {
126
-
127
- var k = (tinymce.majorVersion < 4) ? 'theme_advanced_buttons' : 'toolbar';
128
-
129
- for( var i = 1; i < 5; i++ ) {
130
-
131
- mceInit[ k + i ] = acf.isset(toolbar, i) ? toolbar[i] : '';
132
-
133
- }
134
-
135
- }
136
-
137
-
138
- // events
139
- if( tinymce.majorVersion < 4 ) {
140
-
141
- mceInit.setup = function( ed ){
142
-
143
- ed.onInit.add(function(ed, event) {
144
-
145
- // focus
146
- $(ed.getBody()).on('focus', function(){
147
-
148
- acf.validation.remove_error( $field );
149
-
150
- });
151
-
152
- $(ed.getBody()).on('blur', function(){
153
-
154
- // update the hidden textarea
155
- // - This fixes a bug when adding a taxonomy term as the form is not posted and the hidden textarea is never populated!
156
-
157
- // save to textarea
158
- ed.save();
159
-
160
-
161
- // trigger change on textarea
162
- $field.find('textarea').trigger('change');
163
-
164
- });
165
-
166
- });
167
-
168
- };
169
-
170
- } else {
171
-
172
- mceInit.setup = function( ed ){
173
-
174
- ed.on('focus', function(e) {
175
-
176
- acf.validation.remove_error( $field );
177
-
178
- });
179
-
180
- ed.on('blur', function(e) {
181
-
182
- // update the hidden textarea
183
- // - This fixes a but when adding a taxonomy term as the form is not posted and the hidden textarea is never populated!
184
-
185
- // save to textarea
186
- ed.save();
187
-
188
-
189
- // trigger change on textarea
190
- $field.find('textarea').trigger('change');
191
-
192
- });
193
-
194
- };
195
-
196
- }
197
-
198
-
199
- // hook for 3rd party customization
200
- mceInit = acf.apply_filters('wysiwyg_tinymce_settings', mceInit, mceInit.id);
201
-
202
-
203
- // return
204
- return mceInit;
205
-
206
- },
207
-
208
- get_qtInit : function(){
209
-
210
- // vars
211
- var qtInit = $.extend({}, tinyMCEPreInit.qtInit.acf_content);
212
-
213
-
214
- // id
215
- qtInit.id = this.settings.id;
216
-
217
-
218
- // hook for 3rd party customization
219
- qtInit = acf.apply_filters('wysiwyg_quicktags_settings', qtInit, qtInit.id);
220
-
221
-
222
- // return
223
- return qtInit;
224
-
225
- },
226
-
227
- /*
228
- * disable
229
- *
230
- * This function will disable the tinymce for a given field
231
- * Note: txtarea_el is different from $textarea.val() and is the value that you see, not the value that you save.
232
- * this allows text like <--more--> to wok instead of showing as an image when the tinymce is removed
233
- *
234
- * @type function
235
- * @date 1/08/2014
236
- * @since 5.0.0
237
- *
238
- * @param n/a
239
- * @return n/a
240
- */
241
-
242
- disable: function(){
243
-
244
- try {
245
-
246
- // vars
247
- var ed = tinyMCE.get( this.settings.id ),
248
- txtarea_el = tinyMCE.DOM.get( this.settings.id );
249
- val = txtarea_el.value;
250
-
251
-
252
- // destory
253
- ed.destroy();
254
-
255
-
256
- // update value
257
- if( this.$field.find('.wp-editor-wrap').hasClass('html-active') ) {
258
-
259
- txtarea_el.value = val;
260
-
261
- }
262
-
263
-
264
- } catch(e) {}
265
-
266
- },
267
-
268
- enable: function(){
269
-
270
- // bail early if html mode
271
- if( this.$field.find('.wp-editor-wrap').hasClass('html-active') ) {
272
-
273
- return;
274
-
275
- }
276
-
277
-
278
- try {
279
-
280
- tinyMCE.init( tinyMCEPreInit.mceInit[ this.settings.id ] );
281
-
282
- } catch(e) {}
283
-
284
-
285
- },
286
-
287
- get_toolbar : function( name ){
288
-
289
- // bail early if toolbar doesn't exist
290
- if( typeof this.toolbars[ name ] !== 'undefined' ) {
291
-
292
- return this.toolbars[ name ];
293
-
294
- }
295
-
296
-
297
- // return
298
- return false;
299
-
300
- },
301
-
302
-
303
- /*
304
- * _buttonsInit
305
- *
306
- * This function will add the quicktags HTML to a WYSIWYG field. Normaly, this is added via quicktags on document ready,
307
- * however, there is no support for 'append'. Source: wp-includes/js/quicktags.js:245
308
- *
309
- * @type function
310
- * @date 1/08/2014
311
- * @since 5.0.0
312
- *
313
- * @param ed (object) quicktag object
314
- * @return n/a
315
- */
316
-
317
- _buttonsInit: function( ed ) {
318
- var defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,';
319
-
320
- canvas = ed.canvas;
321
- name = ed.name;
322
- settings = ed.settings;
323
- html = '';
324
- theButtons = {};
325
- use = '';
326
-
327
- // set buttons
328
- if ( settings.buttons ) {
329
- use = ','+settings.buttons+',';
330
- }
331
-
332
- for ( i in edButtons ) {
333
- if ( !edButtons[i] ) {
334
- continue;
335
- }
336
-
337
- id = edButtons[i].id;
338
- if ( use && defaults.indexOf( ',' + id + ',' ) !== -1 && use.indexOf( ',' + id + ',' ) === -1 ) {
339
- continue;
340
- }
341
-
342
- if ( !edButtons[i].instance || edButtons[i].instance === inst ) {
343
- theButtons[id] = edButtons[i];
344
-
345
- if ( edButtons[i].html ) {
346
- html += edButtons[i].html(name + '_');
347
- }
348
- }
349
- }
350
-
351
- if ( use && use.indexOf(',fullscreen,') !== -1 ) {
352
- theButtons.fullscreen = new qt.FullscreenButton();
353
- html += theButtons.fullscreen.html(name + '_');
354
- }
355
-
356
-
357
- if ( 'rtl' === document.getElementsByTagName('html')[0].dir ) {
358
- theButtons.textdirection = new qt.TextDirectionButton();
359
- html += theButtons.textdirection.html(name + '_');
360
- }
361
-
362
- ed.toolbar.innerHTML = html;
363
- ed.theButtons = theButtons;
364
-
365
- },
366
-
367
- });
368
-
369
- })(jQuery);
370
-
11
 
12
  // if a TinyMCE hasn't been initalize for this language then initalize it
13
  if (!parent.find('.current-language .mce-tinymce').length) {
14
+ //acf.do_action('ready', parent.parents('.acf-field'));
15
  }
16
  });
17
 
25
 
26
 
27
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
v5/fields/wysiwyg.php CHANGED
@@ -36,176 +36,6 @@ class acf_field_qtranslate_wysiwyg extends acf_field_wysiwyg
36
  acf_field::__construct();
37
  }
38
 
39
-
40
- function render_field($field)
41
- {
42
- if (!acf_qtranslate_enabled()) {
43
- acf_field_wysiwyg::render_field($field);
44
- return;
45
- }
46
-
47
- // enqueue
48
- acf_enqueue_uploader();
49
-
50
-
51
- // vars
52
- $id = $field['id'] . '-' . uniqid();
53
- $mode = 'html';
54
- $show_tabs = true;
55
-
56
-
57
- // get height
58
- $height = acf_get_user_setting('wysiwyg_height', 300);
59
- $height = max( $height, 300 ); // minimum height is 300
60
-
61
-
62
- // detect mode
63
- if( $field['tabs'] == 'visual' ) {
64
-
65
- // case: visual tab only
66
- $mode = 'tmce';
67
- $show_tabs = false;
68
-
69
- } elseif( $field['tabs'] == 'text' ) {
70
-
71
- // case: text tab only
72
- $show_tabs = false;
73
-
74
- } elseif( wp_default_editor() == 'tinymce' ) {
75
-
76
- // case: both tabs
77
- $mode = 'tmce';
78
-
79
- }
80
-
81
-
82
- // mode
83
- $switch_class = $mode . '-active';
84
-
85
-
86
- // filter value for editor
87
- remove_all_filters( 'acf_the_editor_content' );
88
-
89
- if( $mode == 'tmce' ) {
90
-
91
- add_filter('acf_the_editor_content', 'wp_richedit_pre');
92
-
93
- } else {
94
-
95
- add_filter('acf_the_editor_content', 'wp_htmledit_pre');
96
-
97
- }
98
-
99
- $field['value'] = apply_filters( 'acf_the_editor_content', $field['value'] );
100
-
101
-
102
- global $q_config, $wp_version;
103
- $languages = qtrans_getSortedLanguages(true);
104
- $values = qtrans_split($field['value'], $quicktags = true);
105
-
106
- echo '<div class="multi-language-field multi-language-field-wysiwyg">';
107
-
108
- foreach ($languages as $language) {
109
- $class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
110
- echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
111
- }
112
-
113
- $uid = $field['id'] . '-' . uniqid();
114
- foreach ($languages as $language):
115
- $value = $values[$language];
116
- $id = $field['id'] . "-$language";
117
- $name = $field['name'] . "[$language]";
118
- if ($language === end($languages)) {
119
- $switch_class .= ' current-language';
120
- }
121
-
122
- ?>
123
- <div id="wp-<?php echo $id; ?>-wrap" class="acf-wysiwyg-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; ?>">
124
- <div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools hide-if-no-js">
125
- <?php if( $field['media_upload'] ): ?>
126
- <div id="wp-<?php echo $id; ?>-media-buttons" class="wp-media-buttons">
127
- <?php do_action( 'media_buttons' ); ?>
128
- </div>
129
- <?php endif; ?>
130
- <?php if( user_can_richedit() && $show_tabs ): ?>
131
- <div class="wp-editor-tabs">
132
- <a id="<?php echo $id; ?>-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);"><?php echo _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ); ?></a>
133
- <a id="<?php echo $id; ?>-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);"><?php echo __('Visual'); ?></a>
134
- </div>
135
- <?php endif; ?>
136
- </div>
137
- <div id="wp-<?php echo $id; ?>-editor-container" class="wp-editor-container">
138
- <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>
139
- </div>
140
- </div>
141
- <?php endforeach;
142
-
143
- echo '</div>';
144
- }
145
-
146
-
147
- function input_form_data( $args ) {
148
-
149
- // vars
150
- $json = array();
151
- $toolbars = $this->get_toolbars();
152
-
153
-
154
- // loop through toolbars
155
- if( !empty($toolbars) ) {
156
-
157
- foreach( $toolbars as $label => $rows ) {
158
-
159
- // vars
160
- $label = sanitize_title( $label );
161
- $label = str_replace('-', '_', $label);
162
-
163
-
164
- // append to $json
165
- $json[ $label ] = array();
166
-
167
-
168
- // convert to strings
169
- if( !empty($rows) ) {
170
-
171
- foreach( $rows as $i => $row ) {
172
-
173
- $json[ $label ][ $i ] = implode(',', $row);
174
-
175
- }
176
- // foreach
177
-
178
- }
179
- // if
180
-
181
- }
182
- // foreach
183
-
184
- }
185
- // if
186
-
187
- ?>
188
- <script type="text/javascript">
189
- (function($) {
190
-
191
- acf.fields.qtranslate_wysiwyg.toolbars = <?php echo json_encode( $json ); ?>;
192
-
193
- })(jQuery);
194
- </script>
195
- <?php
196
-
197
- }
198
-
199
-
200
- function update_value($value, $post_id, $field)
201
- {
202
- if (acf_qtranslate_enabled()) {
203
- $value = qtrans_join($value);
204
- }
205
-
206
- return $value;
207
- }
208
-
209
  }
210
 
211
 
36
  acf_field::__construct();
37
  }
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  }
40
 
41