ACF qTranslate - Version 1.7

Version Description

Improved qTranslate-X support and utilize new language switchers

Download this release

Release Info

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

Code changes from version 1.6 to 1.7

acf-qtranslate.php CHANGED
@@ -3,188 +3,33 @@
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.4
7
  Author: funkjedi
8
  Author URI: http://funkjedi.com
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  */
12
 
13
- // http://support.advancedcustomfields.com/discussion/1181/prease-check-wp3-3-qtranslate-advance-custom-field/p1
 
14
 
15
- require_once dirname(__FILE__) . '/v4/init.php';
16
- require_once dirname(__FILE__) . '/v5/init.php';
17
 
18
-
19
- function acf_qtranslate_enabled() {
20
- return function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage');
21
- }
22
-
23
- function acf_qtranslate_acf_major_version() {
24
- if (function_exists('acf')) {
25
- $acf = acf();
26
- return (int) $acf->settings['version'][0];
27
- }
28
- return '';
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
- function acf_qtranslate_get_visible_fields($args = false) {
67
- global $post, $typenow;
68
- if ($args === false) {
69
- $args = array(
70
- 'post_id' => $post->ID,
71
- 'post_type' => $typenow,
72
- );
73
- }
74
- $supported_field_types = array(
75
- 'text',
76
- 'textarea',
77
- );
78
- $field_ids = array();
79
- foreach (acf_get_field_groups($args) as $field_group) {
80
- $fields = acf_get_fields($field_group);
81
- foreach ($fields as $field) {
82
- if (in_array($field['type'], $supported_field_types)) {
83
- $field_ids[] = array('id' => 'acf-' . $field['key']);
84
- }
85
- }
86
- }
87
- return $field_ids;
88
- }
89
-
90
-
91
- add_filter('qtranslate_load_admin_page_config', 'acf_qtranslate_load_admin_page_config');
92
- function acf_qtranslate_load_admin_page_config($page_configs)
93
- {
94
- global $pagenow;
95
-
96
- // very hacky support for v4
97
- if (acf_qtranslate_acf_major_version() === 4) {
98
- $args = array('post_id' => apply_filters('acf/get_post_id', false));
99
- $match_field_groups = apply_filters('acf/location/match_field_groups', array(), $args);
100
- $acfs = apply_filters('acf/get_field_groups', array());
101
- if (is_array($acfs)) {
102
- $field_ids = array();
103
- foreach ($acfs as $acf) {
104
- if (in_array($acf['id'], $match_field_groups)) {
105
- $fields = apply_filters('acf/field_group/get_fields', array(), $acf['id']);
106
- foreach ($fields as $field) {
107
- $field_ids[] = array('id' => $field['id']);
108
- }
109
- }
110
- }
111
- if (count($field_ids)) {
112
- $page_configs[] = array(
113
- 'pages' => array('' => ''),
114
- 'forms' => array(
115
- array('fields' => $field_ids)
116
- ));
117
- }
118
- }
119
- return $page_configs;
120
- }
121
 
122
 
123
- switch ($pagenow) {
124
 
125
- // add support for regular pages and posts
126
- case 'post.php':
127
- case 'post-new.php':
128
- $page_configs[] = array(
129
- 'pages' => array(
130
- 'post.php' => '',
131
- 'post-new.php' => ''),
132
- 'forms' => array(
133
- array('fields' => acf_qtranslate_get_visible_fields())
134
- ));
135
- break;
136
-
137
- // add support for ACF Option Pages
138
- case 'admin.php':
139
- foreach (acf_get_options_pages() as $page) {
140
- $page_configs[] = array(
141
- 'pages' => array('admin.php' => 'page=' . $page['menu_slug']),
142
- 'forms' => array(
143
- array('fields' => acf_qtranslate_get_visible_fields())
144
- ));
145
- }
146
- break;
147
-
148
- // add support for new user page
149
- case 'user-new.php':
150
- $args = array(
151
- 'user_id' => 'new',
152
- 'user_form' => 'edit',
153
- );
154
- $page_configs[] = array(
155
- 'pages' => array('user-new.php' => ''),
156
- 'forms' => array(
157
- array('fields' => acf_qtranslate_get_visible_fields($args))
158
- ));
159
- break;
160
-
161
- // add support for edit user page
162
- case 'user-edit.php':
163
- $args = array(
164
- 'user_id' => @$_GET['user_id'],
165
- 'user_form' => 'edit',
166
- );
167
- $page_configs[] = array(
168
- 'pages' => array('user-edit.php' => 'user_id='),
169
- 'forms' => array(
170
- array('fields' => acf_qtranslate_get_visible_fields($args))
171
- ));
172
- break;
173
-
174
- // add support for profile page
175
- case 'profile.php':
176
- $args = array(
177
- 'user_id' => get_current_user_id(),
178
- 'user_form' => 'edit',
179
- );
180
- $page_configs[] = array(
181
- 'pages' => array('profile.php' => ''),
182
- 'forms' => array(
183
- array('fields' => acf_qtranslate_get_visible_fields($args))
184
- ));
185
- break;
186
-
187
- }
188
-
189
- return $page_configs;
190
- }
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
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  */
12
 
13
+ define('ACF_QTRANSLATE_PLUGIN', __FILE__);
14
+ define('ACF_QTRANSLATE_PLUGIN_DIR', plugin_dir_path(ACF_QTRANSLATE_PLUGIN));
15
 
 
 
16
 
17
+ /**
18
+ * Create autoload to load plugin classes.
19
+ */
20
+ function acf_qtranslate_autoload($className) {
21
+ if (strpos($className, 'acf_qtranslate\\') === 0) {
22
+ $path = ACF_QTRANSLATE_PLUGIN_DIR . 'src/' . str_replace('\\', '/', substr($className, 15)) . '.php';
23
+ if (is_readable($path)) {
24
+ include $path;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
 
 
 
 
 
 
26
  }
27
  }
28
 
29
+ spl_autoload_register('acf_qtranslate_autoload');
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
 
 
33
 
34
+ // bootstrap plugin
35
+ new acf_qtranslate\plugin;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
{v5/assets → assets}/input.css RENAMED
@@ -1,5 +1,4 @@
1
 
2
-
3
  .qtrans_title_wrap {
4
  margin-bottom: 20px;
5
  padding: 0 !important;
@@ -15,8 +14,10 @@
15
  margin: 0;
16
  }
17
 
18
-
19
- .acf-wysiwyg-wrap .wp-editor-container { border: 1px solid #e5e5e5 !important; }
 
 
20
 
21
  .multi-language-field {
22
  margin-top: -38px;
@@ -27,11 +28,11 @@
27
  }
28
 
29
  .multi-language-field .wp-switch-editor {
30
- border-color: #dedede;
31
  position: relative;
32
  top: 1px;
33
  z-index: 100;
34
- float: right;
35
  }
36
 
37
  .multi-language-field input,
@@ -60,22 +61,28 @@
60
  .multi-language-field > input,
61
  .multi-language-field > textarea,
62
  .multi-language-field > fieldset,
 
63
  .multi-language-field .acf-wysiwyg-wrap,
 
64
  .multi-language-field .acf-image-uploader { display: none }
65
 
66
  .multi-language-field .acf_input input,
67
  .multi-language-field .acf_input textarea,
68
  .multi-language-field .current-language { display: block !important }
69
 
70
- .multi-language-field-wysiwyg { margin-top: 0 }
 
 
71
 
 
72
  .multi-language-field .acf-image-uploader {
73
- padding: 10px 10px 10px;
74
- clear: right;
75
- border: 1px solid #dfdfdf;
76
  }
77
 
78
- .multi-language-field .acf-image-uploader.current-language { background: #fff; }
 
79
 
80
  .multi-language-field-wysiwyg .wp-switch-editor {
81
  background-color: #ebebeb;
1
 
 
2
  .qtrans_title_wrap {
3
  margin-bottom: 20px;
4
  padding: 0 !important;
14
  margin: 0;
15
  }
16
 
17
+ .acf_wysiwyg .wp-editor-container,
18
+ .acf-wysiwyg-wrap .wp-editor-container {
19
+ border: 1px solid #e5e5e5 !important;
20
+ }
21
 
22
  .multi-language-field {
23
  margin-top: -38px;
28
  }
29
 
30
  .multi-language-field .wp-switch-editor {
31
+ float: right;
32
  position: relative;
33
  top: 1px;
34
  z-index: 100;
35
+ border-color: #dedede;
36
  }
37
 
38
  .multi-language-field input,
61
  .multi-language-field > input,
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
 
69
  .multi-language-field .acf_input input,
70
  .multi-language-field .acf_input textarea,
71
  .multi-language-field .current-language { display: block !important }
72
 
73
+ .multi-language-field-wysiwyg {
74
+ margin-top: 0;
75
+ }
76
 
77
+ .multi-language-field .acf-file-uploader,
78
  .multi-language-field .acf-image-uploader {
79
+ padding: 20px 10px 10px;
80
+ clear: right;
81
+ border: 1px solid #dfdfdf;
82
  }
83
 
84
+ .multi-language-field .acf-image-uploader.current-language,
85
+ .multi-language-field .acf-file-uploader { background: #fff; }
86
 
87
  .multi-language-field-wysiwyg .wp-switch-editor {
88
  background-color: #ebebeb;
assets/input.js ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ jQuery(function($) {
3
+
4
+ var $body = $('body');
5
+
6
+
7
+ /**
8
+ * Sync qtranslate language switchers with qtranslatex language switchers.
9
+ */
10
+ $body.on('click', '.qtranxs-lang-switch', function() {
11
+ var parent = $('.multi-language-field'), language = $(this).attr('lang');
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
+ /**
19
+ * Setup qtranslate language switchers.
20
+ */
21
+ $body.on('click', '.wp-switch-editor[data-language]', function() {
22
+ var parent = $(this).parent('.multi-language-field'), language = $(this).data('language');
23
+
24
+ parent.find('.current-language').removeClass('current-language');
25
+ parent.find('[data-language="' + language + '"]').addClass('current-language');
26
+ parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]').focus();
27
+ });
28
+
29
+ /**
30
+ * Focus/blur fields.
31
+ */
32
+ $body.on('focusin', '.multi-language-field input, .multi-language-field textarea', function() {
33
+ $(this).parent('.multi-language-field').addClass('focused');
34
+ });
35
+
36
+ $body.on('focusout', '.multi-language-field input, .multi-language-field textarea', function() {
37
+ $(this).parent('.multi-language-field').removeClass('focused');
38
+ });
39
+
40
+
41
+ });
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.6
7
- Stable tag: 1.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -12,13 +12,10 @@ Adds qTranslate compatible fields for Text, Text Area, Wysiwyg Editor and Image.
12
 
13
  == Description ==
14
 
15
- **Requires the following plugins**
16
-
17
- * [Advanced Custom Fields](http://wordpress.org/extend/plugins/advanced-custom-fields/)
18
- * [qTranslate](http://wordpress.org/plugins/qtranslate/)
19
-
20
  This plugin adds a new Field Type category called qTranslate. This contains qTranslate compatible fields for Text, Text Area, Wysiwyg Editor and Image.
21
 
 
 
22
  Usage:
23
 
24
  * Install the plug-in (standard WordPress installation)
@@ -48,6 +45,9 @@ The plugin is based on code samples posted to the [ACF support forums](http://ol
48
 
49
  == Changelog ==
50
 
 
 
 
51
  = 1.6 =
52
  Added ACFv4 support for qTranslate-X
53
 
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
 
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)
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
 
src/acf_4/acf.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace acf_qtranslate\acf_4;
4
+
5
+ use acf_qtranslate\acf_4\fields\file;
6
+ use acf_qtranslate\acf_4\fields\image;
7
+ use acf_qtranslate\acf_4\fields\text;
8
+ use acf_qtranslate\acf_4\fields\textarea;
9
+ use acf_qtranslate\acf_4\fields\wysiwyg;
10
+ use acf_qtranslate\acf_interface;
11
+ 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
+ /**
47
+ * This filter is applied to the $value after it is loaded from the db and
48
+ * before it is returned to the template via functions such as get_field().
49
+ */
50
+ public function format_value_for_api($value) {
51
+ if (is_string($value)) {
52
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
53
+ }
54
+ return $value;
55
+ }
56
+
57
+ /**
58
+ * Get the visible ACF fields.
59
+ * @return array
60
+ */
61
+ public function get_visible_acf_fields() {
62
+ global $post, $pagenow, $typenow;
63
+
64
+ $filter = array();
65
+ if ($pagenow === 'post.php' || $pagenow === 'post-new.php') {
66
+ if ($typenow !== 'acf') {
67
+ $filter['post_id'] = apply_filters('acf/get_post_id', false);
68
+ $filter['post_type'] = $typenow;
69
+ }
70
+ }
71
+ elseif ($pagenow === 'admin.php' && isset($_GET['page'])) {
72
+ $filter['post_id'] = apply_filters('acf/get_post_id', false);
73
+ $filter['post_type'] = $typenow;
74
+ }
75
+ elseif ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy'])) {
76
+ $filter['ef_taxonomy'] = filter_var($_GET['taxonomy'], FILTER_SANITIZE_STRING);
77
+ }
78
+ elseif ($pagenow === 'profile.php') {
79
+ $filter['ef_user'] = get_current_user_id();
80
+ }
81
+ elseif ($pagenow === 'user-edit.php' && isset($_GET['user_id'])) {
82
+ $filter['ef_user'] = filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT);
83
+ }
84
+ elseif ($pagenow === 'user-new.php') {
85
+ $filter['ef_user'] = 'all';
86
+ }
87
+ elseif ($pagenow === 'media.php' || $pagenow === 'upload.php') {
88
+ $filter['post_type'] = 'attachment';
89
+ }
90
+
91
+ if (count($filter) === 0) {
92
+ return array();
93
+ }
94
+
95
+ $supported_field_types = array(
96
+ 'email',
97
+ 'text',
98
+ 'textarea',
99
+ );
100
+
101
+ $visible_field_groups = apply_filters('acf/location/match_field_groups', array(), $filter);
102
+
103
+ $visible_fields = array();
104
+ foreach (apply_filters('acf/get_field_groups', array()) as $field_group) {
105
+ if (in_array($field_group['id'], $visible_field_groups)) {
106
+ $fields = apply_filters('acf/field_group/get_fields', array(), $field_group['id']);
107
+ foreach ($fields as $field) {
108
+ if (in_array($field['type'], $supported_field_types)) {
109
+ $visible_fields[] = array('id' => $field['id']);
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ return $visible_fields;
116
+ }
117
+
118
+ /**
119
+ * Monkey patches to fix little qTranslate javascript issues.
120
+ */
121
+ public function monkey_patch_qtranslate() {
122
+ global $q_config;
123
+
124
+ // http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=3497
125
+ if (isset($q_config['js']) && strpos($q_config['js']['qtrans_switch'], 'originalSwitchEditors') === false) {
126
+ $q_config['js']['qtrans_switch'] = "originalSwitchEditors = jQuery.extend(true, {}, switchEditors);\n" . $q_config['js']['qtrans_switch'];
127
+ $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']);
128
+ }
129
+
130
+ // https://github.com/funkjedi/acf-qtranslate/issues/2#issuecomment-37612918
131
+ if (isset($q_config['js']) && strpos($q_config['js']['qtrans_hook_on_tinyMCE'], 'ed.editorId.match(/^qtrans_/)') === false) {
132
+ $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']);
133
+ }
134
+ }
135
+ }
src/acf_4/fields/file.php ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace acf_qtranslate\acf_4\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_file;
7
+
8
+ class file extends acf_field_file
9
+ {
10
+
11
+ /*
12
+ * __construct
13
+ *
14
+ * Set name / label needed for actions / filters
15
+ *
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');
25
+ $this->defaults = array(
26
+ 'save_format' => 'object',
27
+ 'library' => 'all'
28
+ );
29
+ $this->l10n = array(
30
+ 'select' => __("Select File",'acf'),
31
+ 'edit' => __("Edit File",'acf'),
32
+ 'update' => __("Update File",'acf'),
33
+ 'uploadedTo' => __("uploaded to this post",'acf'),
34
+ );
35
+
36
+ acf_field::__construct();
37
+
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);
46
+ }
47
+
48
+ /*
49
+ * create_field()
50
+ *
51
+ * Create the HTML interface for your field
52
+ *
53
+ * @param $field - an array holding all the field's data
54
+ *
55
+ * @type action
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);
64
+ $currentLanguage = qtrans_getLanguage();
65
+
66
+ echo '<div class="multi-language-field multi-language-field-file">';
67
+
68
+ foreach ($languages as $language) {
69
+ $class = 'wp-switch-editor';
70
+ if ($language === $currentLanguage) {
71
+ $class .= ' current-language';
72
+ }
73
+ echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
74
+ }
75
+
76
+ $base_class = $field['class'];
77
+ $base_name = $field['name'];
78
+ foreach ($languages as $language) :
79
+ $value = $values[$language];
80
+ $o = array(
81
+ 'class' => '',
82
+ 'icon' => '',
83
+ 'title' => '',
84
+ 'size' => '',
85
+ 'url' => '',
86
+ 'name' => '',
87
+ );
88
+
89
+ if($value && is_numeric($value)) {
90
+ $file = get_post($value);
91
+
92
+ if($file) {
93
+ $o['class'] = 'active';
94
+ $o['icon'] = wp_mime_type_icon( $file->ID );
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
+
104
+ $field['class'] = $base_class;
105
+ if ($language === $currentLanguage) {
106
+ $field['class'] .= ' current-language';
107
+ $o['class'] .= ' current-language';
108
+ }
109
+
110
+ $field['name'] = $base_name . '[' . $language . ']';
111
+
112
+ ?>
113
+ <div class="acf-file-uploader clearfix <?php echo $o['class']; ?>" data-library="<?php echo $field['library']; ?>" data-language="<?php echo $language; ?>">
114
+ <input class="acf-file-value" type="hidden" name="<?php echo $field['name']; ?>" value="<?php echo $value; ?>" />
115
+ <div class="has-file">
116
+ <ul class="hl clearfix">
117
+ <li>
118
+ <img class="acf-file-icon" src="<?php echo $o['icon']; ?>" alt=""/>
119
+ <div class="hover">
120
+ <ul class="bl">
121
+ <li><a href="#" class="acf-button-delete ir">Remove</a></li>
122
+ <li><a href="#" class="acf-button-edit ir">Edit</a></li>
123
+ </ul>
124
+ </div>
125
+ </li>
126
+ <li>
127
+ <p>
128
+ <strong class="acf-file-title"><?php echo $o['title']; ?></strong>
129
+ </p>
130
+ <p>
131
+ <strong><?php _e('Name', 'acf'); ?>:</strong>
132
+ <a class="acf-file-name" href="<?php echo $o['url']; ?>" target="_blank"><?php echo $o['name']; ?></a>
133
+ </p>
134
+ <p>
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>
142
+ <div class="no-file">
143
+ <ul class="hl clearfix">
144
+ <li>
145
+ <p><?php _e('No File Selected','acf'); ?> <a href="#" class="button add-file"><?php _e('Add File','acf'); ?></p></a>
146
+ </li>
147
+ </ul>
148
+ </div>
149
+ </div>
150
+ <?php endforeach;
151
+
152
+ echo '</div>';
153
+ }
154
+
155
+ /*
156
+ * format_value
157
+ *
158
+ * @description: uses the basic value and allows the field type to format it
159
+ * @since: 3.6
160
+ * @created: 26/01/13
161
+ */
162
+ function format_value($value, $post_id, $field)
163
+ {
164
+ return $value;
165
+ }
166
+
167
+ /*
168
+ * format_value_for_api()
169
+ *
170
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
171
+ *
172
+ * @type filter
173
+ * @since 3.6
174
+ * @date 23/01/13
175
+ *
176
+ * @param $value - the value which was loaded from the database
177
+ * @param $post_id - the $post_id from which the value was loaded
178
+ * @param $field - the field array holding all the field options
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
+ }
187
+
188
+ /*
189
+ * update_value()
190
+ *
191
+ * This filter is appied to the $value before it is updated in the db
192
+ *
193
+ * @type filter
194
+ * @since 3.6
195
+ * @date 23/01/13
196
+ *
197
+ * @param $value - the value which will be saved in the database
198
+ * @param $post_id - the $post_id of which the value will be saved
199
+ * @param $field - the field array holding all the field options
200
+ *
201
+ * @return $value - the modified value
202
+ */
203
+ function update_value($value, $post_id, $field)
204
+ {
205
+ return qtrans_join($value);
206
+ }
207
+
208
+ }
{v4 → src/acf_4}/fields/image.php RENAMED
@@ -1,23 +1,34 @@
1
  <?php
2
 
3
- class acf_field_qtranslate_image extends acf_field_image
4
- {
5
-
6
- function __construct()
7
- {
 
 
 
 
 
 
 
 
 
 
 
8
  $this->name = 'qtranslate_image';
9
  $this->label = __("Image", 'acf');
10
  $this->category = __("qTranslate", 'acf');
11
  $this->defaults = array(
12
- 'save_format' => 'object',
13
- 'preview_size' => 'thumbnail',
14
- 'library' => 'all'
15
  );
16
  $this->l10n = array(
17
- 'select' => __("Select Image",'acf'),
18
- 'edit' => __("Edit Image",'acf'),
19
- 'update' => __("Update Image",'acf'),
20
- 'uploadedTo' => __("uploaded to this post",'acf'),
21
  );
22
 
23
  acf_field::__construct();
@@ -31,13 +42,18 @@ class acf_field_qtranslate_image extends acf_field_image
31
  add_action('wp_ajax_nopriv_acf/fields/image/get_images', array($this, 'ajax_get_images'), 10, 1);
32
  }
33
 
34
- function create_field($field)
35
- {
36
- if (!acf_qtranslate_enabled()) {
37
- acf_field_image::create_field($field);
38
- return;
39
- }
40
-
 
 
 
 
 
41
  global $q_config;
42
  $languages = qtrans_getSortedLanguages(true);
43
  $values = qtrans_split($field['value'], $quicktags = true);
@@ -97,34 +113,54 @@ class acf_field_qtranslate_image extends acf_field_image
97
  echo '</div>';
98
  }
99
 
100
- function format_value($value, $post_id, $field)
101
- {
 
 
 
 
 
 
102
  return $value;
103
  }
104
 
105
- function format_value_for_api($value, $post_id, $field)
106
- {
107
- if (acf_qtranslate_enabled()) {
108
- $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
109
- }
110
-
111
- return acf_field_image::format_value_for_api($value, $post_id, $field);
 
 
 
 
 
 
 
 
 
 
 
112
  }
113
 
114
- function update_value($value, $post_id, $field)
115
- {
116
- if (acf_qtranslate_enabled()) {
117
- $value = qtrans_join($value);
118
- }
119
-
120
- return $value;
 
 
 
 
 
 
 
 
 
 
121
  }
122
 
123
- function create_options( $field )
124
- {
125
- acf_field_image::create_options($field);
126
- }
127
  }
128
-
129
- new acf_field_qtranslate_image();
130
-
1
  <?php
2
 
3
+ namespace acf_qtranslate\acf_4\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_image;
7
+
8
+ class image extends acf_field_image {
9
+
10
+ /*
11
+ * __construct
12
+ *
13
+ * Set name / label needed for actions / filters
14
+ *
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');
22
  $this->defaults = array(
23
+ 'save_format' => 'object',
24
+ 'preview_size' => 'thumbnail',
25
+ 'library' => 'all'
26
  );
27
  $this->l10n = array(
28
+ 'select' => __("Select Image",'acf'),
29
+ 'edit' => __("Edit Image",'acf'),
30
+ 'update' => __("Update Image",'acf'),
31
+ 'uploadedTo' => __("uploaded to this post",'acf'),
32
  );
33
 
34
  acf_field::__construct();
42
  add_action('wp_ajax_nopriv_acf/fields/image/get_images', array($this, 'ajax_get_images'), 10, 1);
43
  }
44
 
45
+ /*
46
+ * create_field()
47
+ *
48
+ * Create the HTML interface for your field
49
+ *
50
+ * @param $field - an array holding all the field's data
51
+ *
52
+ * @type action
53
+ * @since 3.6
54
+ * @date 23/01/13
55
+ */
56
+ function create_field($field) {
57
  global $q_config;
58
  $languages = qtrans_getSortedLanguages(true);
59
  $values = qtrans_split($field['value'], $quicktags = true);
113
  echo '</div>';
114
  }
115
 
116
+ /*
117
+ * format_value
118
+ *
119
+ * @description: uses the basic value and allows the field type to format it
120
+ * @since: 3.6
121
+ * @created: 26/01/13
122
+ */
123
+ function format_value($value, $post_id, $field) {
124
  return $value;
125
  }
126
 
127
+ /*
128
+ * format_value_for_api()
129
+ *
130
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
131
+ *
132
+ * @type filter
133
+ * @since 3.6
134
+ * @date 23/01/13
135
+ *
136
+ * @param $value - the value which was loaded from the database
137
+ * @param $post_id - the $post_id from which the value was loaded
138
+ * @param $field - the field array holding all the field options
139
+ *
140
+ * @return $value - the modified value
141
+ */
142
+ function format_value_for_api($value, $post_id, $field) {
143
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
144
+ return parent::format_value_for_api($value, $post_id, $field);
145
  }
146
 
147
+ /*
148
+ * update_value()
149
+ *
150
+ * This filter is appied to the $value before it is updated in the db
151
+ *
152
+ * @type filter
153
+ * @since 3.6
154
+ * @date 23/01/13
155
+ *
156
+ * @param $value - the value which will be saved in the database
157
+ * @param $post_id - the $post_id of which the value will be saved
158
+ * @param $field - the field array holding all the field options
159
+ *
160
+ * @return $value - the modified value
161
+ */
162
+ function update_value($value, $post_id, $field) {
163
+ return qtrans_join($value);
164
  }
165
 
 
 
 
 
166
  }
 
 
 
src/acf_4/fields/text.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace acf_qtranslate\acf_4\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_text;
7
+
8
+ class text extends acf_field_text {
9
+
10
+ /*
11
+ * __construct
12
+ *
13
+ * Set name / label needed for actions / filters
14
+ *
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');
22
+
23
+ acf_field::__construct();
24
+ }
25
+
26
+ /*
27
+ * create_field()
28
+ *
29
+ * Create the HTML interface for your field
30
+ *
31
+ * @param $field - an array holding all the field's data
32
+ *
33
+ * @type action
34
+ * @since 3.6
35
+ * @date 23/01/13
36
+ */
37
+ function create_field($field) {
38
+ global $q_config;
39
+ $languages = qtrans_getSortedLanguages(true);
40
+ $values = qtrans_split($field['value'], $quicktags = true);
41
+
42
+ echo '<div class="multi-language-field">';
43
+
44
+ foreach ($languages as $language) {
45
+ $class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
46
+ echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
47
+ }
48
+
49
+ foreach ($languages as $language) {
50
+ $class = ($language === end($languages)) ? $field['class'] . ' current-language' : $field['class'];
51
+ echo '<input type="text" data-language="' . esc_attr($language) . '" value="' . esc_attr($values[$language]) . '" id="' . esc_attr( $field['id'] ) . '" class="' . esc_attr($class) . '" name="' . esc_attr($field['name'] . "[$language]") . '" />';
52
+ }
53
+
54
+ echo '</div>';
55
+ }
56
+
57
+ /*
58
+ * format_value
59
+ *
60
+ * @description: uses the basic value and allows the field type to format it
61
+ * @since: 3.6
62
+ * @created: 26/01/13
63
+ */
64
+ function format_value($value, $post_id, $field) {
65
+ return $value;
66
+ }
67
+
68
+ /*
69
+ * format_value_for_api()
70
+ *
71
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
72
+ *
73
+ * @type filter
74
+ * @since 3.6
75
+ * @date 23/01/13
76
+ *
77
+ * @param $value - the value which was loaded from the database
78
+ * @param $post_id - the $post_id from which the value was loaded
79
+ * @param $field - the field array holding all the field options
80
+ *
81
+ * @return $value - the modified value
82
+ */
83
+ function format_value_for_api($value, $post_id, $field) {
84
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
85
+ return parent::format_value_for_api($value, $post_id, $field);
86
+ }
87
+
88
+ /*
89
+ * update_value()
90
+ *
91
+ * This filter is appied to the $value before it is updated in the db
92
+ *
93
+ * @type filter
94
+ * @since 3.6
95
+ * @date 23/01/13
96
+ *
97
+ * @param $value - the value which will be saved in the database
98
+ * @param $post_id - the $post_id of which the value will be saved
99
+ * @param $field - the field array holding all the field options
100
+ *
101
+ * @return $value - the modified value
102
+ */
103
+ function update_value($value, $post_id, $field) {
104
+ return qtrans_join($value);
105
+ }
106
+
107
+ }
src/acf_4/fields/textarea.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace acf_qtranslate\acf_4\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_textarea;
7
+
8
+ class textarea extends acf_field_textarea {
9
+
10
+ /*
11
+ * __construct
12
+ *
13
+ * Set name / label needed for actions / filters
14
+ *
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');
22
+
23
+ acf_field::__construct();
24
+ }
25
+
26
+ /*
27
+ * create_field()
28
+ *
29
+ * Create the HTML interface for your field
30
+ *
31
+ * @param $field - an array holding all the field's data
32
+ *
33
+ * @type action
34
+ * @since 3.6
35
+ * @date 23/01/13
36
+ */
37
+ function create_field($field) {
38
+ global $q_config;
39
+ $languages = qtrans_getSortedLanguages(true);
40
+ $values = qtrans_split($field['value'], $quicktags = true);
41
+
42
+ echo '<div class="multi-language-field">';
43
+
44
+ foreach ($languages as $language) {
45
+ $class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
46
+ echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
47
+ }
48
+
49
+ foreach ($languages as $language) {
50
+ $class = ($language === end($languages)) ? $field['class'] . ' current-language' : $field['class'];
51
+ echo '<textarea data-language="' . esc_attr($language) . '" id="' . esc_attr( $field['id'] ) . '" rows="4" class="' . esc_attr($class) . '" name="' . esc_attr($field['name'] . "[$language]") . '">' . esc_textarea($values[$language]) . '</textarea>';
52
+ }
53
+
54
+ echo '</div>';
55
+ }
56
+
57
+ /*
58
+ * format_value
59
+ *
60
+ * @description: uses the basic value and allows the field type to format it
61
+ * @since: 3.6
62
+ * @created: 26/01/13
63
+ */
64
+ function format_value($value, $post_id, $field) {
65
+ return $value;
66
+ }
67
+
68
+ /*
69
+ * format_value_for_api()
70
+ *
71
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
72
+ *
73
+ * @type filter
74
+ * @since 3.6
75
+ * @date 23/01/13
76
+ *
77
+ * @param $value - the value which was loaded from the database
78
+ * @param $post_id - the $post_id from which the value was loaded
79
+ * @param $field - the field array holding all the field options
80
+ *
81
+ * @return $value - the modified value
82
+ */
83
+ function format_value_for_api($value, $post_id, $field) {
84
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
85
+ return parent::format_value_for_api($value, $post_id, $field);
86
+ }
87
+
88
+ /*
89
+ * update_value()
90
+ *
91
+ * This filter is appied to the $value before it is updated in the db
92
+ *
93
+ * @type filter
94
+ * @since 3.6
95
+ * @date 23/01/13
96
+ *
97
+ * @param $value - the value which will be saved in the database
98
+ * @param $post_id - the $post_id of which the value will be saved
99
+ * @param $field - the field array holding all the field options
100
+ *
101
+ * @return $value - the modified value
102
+ */
103
+ function update_value($value, $post_id, $field) {
104
+ return qtrans_join($value);
105
+ }
106
+
107
+ }
{v4 → src/acf_4}/fields/wysiwyg.php RENAMED
@@ -1,10 +1,21 @@
1
  <?php
2
 
3
- class acf_field_qtranslate_wysiwyg extends acf_field_wysiwyg
4
- {
5
-
6
- function __construct()
7
- {
 
 
 
 
 
 
 
 
 
 
 
8
  $this->name = 'qtranslate_wysiwyg';
9
  $this->label = __("Wysiwyg Editor",'acf');
10
  $this->category = __("qTranslate",'acf');
@@ -14,20 +25,35 @@ class acf_field_qtranslate_wysiwyg extends acf_field_wysiwyg
14
  add_filter('acf/fields/wysiwyg/toolbars', array($this, 'toolbars'), 1, 1);
15
  }
16
 
17
-
18
- function toolbars($toolbars)
19
- {
20
- return acf_field_wysiwyg::toolbars($toolbars);
 
 
 
 
 
 
 
 
 
 
 
21
  }
22
 
23
-
24
- function create_field($field)
25
- {
26
- if (!acf_qtranslate_enabled()) {
27
- acf_field_wysiwyg::create_field($field);
28
- return;
29
- }
30
-
 
 
 
 
31
  $defaults = array(
32
  'toolbar' => 'full',
33
  'media_upload' => 'yes',
@@ -78,32 +104,54 @@ class acf_field_qtranslate_wysiwyg extends acf_field_wysiwyg
78
  echo '</div>';
79
  }
80
 
81
-
82
- function format_value($value, $post_id, $field)
83
- {
 
 
 
 
 
84
  return $value;
85
  }
86
 
87
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  function format_value_for_api($value, $post_id, $field) {
89
- if (acf_qtranslate_enabled()) {
90
- $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
91
- }
92
-
93
- return acf_field_wysiwyg::format_value_for_api($value, $post_id, $field);
94
  }
95
 
96
-
97
- function update_value($value, $post_id, $field)
98
- {
99
- if (acf_qtranslate_enabled()) {
100
- $value = qtrans_join($value);
101
- }
102
-
103
- return $value;
 
 
 
 
 
 
 
 
 
104
  }
105
 
106
  }
107
-
108
-
109
- new acf_field_qtranslate_wysiwyg;
1
  <?php
2
 
3
+ namespace acf_qtranslate\acf_4\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_wysiwyg;
7
+
8
+ class wysiwyg extends acf_field_wysiwyg {
9
+
10
+ /*
11
+ * __construct
12
+ *
13
+ * Set name / label needed for actions / filters
14
+ *
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');
25
  add_filter('acf/fields/wysiwyg/toolbars', array($this, 'toolbars'), 1, 1);
26
  }
27
 
28
+ /*
29
+ * toolbars()
30
+ *
31
+ * This filter allowsyou to customize the WYSIWYG toolbars
32
+ *
33
+ * @param $toolbars - an array of toolbars
34
+ *
35
+ * @return $toolbars - the modified $toolbars
36
+ *
37
+ * @type filter
38
+ * @since 3.6
39
+ * @date 23/01/13
40
+ */
41
+ function toolbars($toolbars) {
42
+ return parent::toolbars($toolbars);
43
  }
44
 
45
+ /*
46
+ * create_field()
47
+ *
48
+ * Create the HTML interface for your field
49
+ *
50
+ * @param $field - an array holding all the field's data
51
+ *
52
+ * @type action
53
+ * @since 3.6
54
+ * @date 23/01/13
55
+ */
56
+ function create_field($field) {
57
  $defaults = array(
58
  'toolbar' => 'full',
59
  'media_upload' => 'yes',
104
  echo '</div>';
105
  }
106
 
107
+ /*
108
+ * format_value
109
+ *
110
+ * @description: uses the basic value and allows the field type to format it
111
+ * @since: 3.6
112
+ * @created: 26/01/13
113
+ */
114
+ function format_value($value, $post_id, $field) {
115
  return $value;
116
  }
117
 
118
+ /*
119
+ * format_value_for_api()
120
+ *
121
+ * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
122
+ *
123
+ * @type filter
124
+ * @since 3.6
125
+ * @date 23/01/13
126
+ *
127
+ * @param $value - the value which was loaded from the database
128
+ * @param $post_id - the $post_id from which the value was loaded
129
+ * @param $field - the field array holding all the field options
130
+ *
131
+ * @return $value - the modified value
132
+ */
133
  function format_value_for_api($value, $post_id, $field) {
134
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
135
+ return parent::format_value_for_api($value, $post_id, $field);
 
 
 
136
  }
137
 
138
+ /*
139
+ * update_value()
140
+ *
141
+ * This filter is appied to the $value before it is updated in the db
142
+ *
143
+ * @type filter
144
+ * @since 3.6
145
+ * @date 23/01/13
146
+ *
147
+ * @param $value - the value which will be saved in the database
148
+ * @param $post_id - the $post_id of which the value will be saved
149
+ * @param $field - the field array holding all the field options
150
+ *
151
+ * @return $value - the modified value
152
+ */
153
+ function update_value($value, $post_id, $field) {
154
+ return qtrans_join($value);
155
  }
156
 
157
  }
 
 
 
src/acf_5/acf.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
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;
9
+ use acf_qtranslate\acf_interface;
10
+ 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'));
22
+ }
23
+
24
+ /**
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
+ /**
43
+ * This filter is applied to the $value after it is loaded from the db and
44
+ * before it is returned to the template via functions such as get_field().
45
+ */
46
+ public function format_value($value) {
47
+ if (is_string($value)) {
48
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
49
+ }
50
+ return $value;
51
+ }
52
+
53
+ /**
54
+ * Get the visible ACF fields.
55
+ * @return array
56
+ */
57
+ public function get_visible_acf_fields() {
58
+ global $post, $pagenow, $typenow;
59
+
60
+ $filter = array();
61
+ if ($pagenow === 'post.php' || $pagenow === 'post-new.php') {
62
+ if ($typenow !== 'acf') {
63
+ $filter['post_id'] = $post->ID;
64
+ $filter['post_type'] = $typenow;
65
+ }
66
+ }
67
+ elseif ($pagenow === 'admin.php' && isset($_GET['page'])) {
68
+ $filter['post_id'] = $post->ID;
69
+ $filter['post_type'] = $typenow;
70
+ }
71
+ elseif ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy'])) {
72
+ $filter['taxonomy'] = filter_var($_GET['taxonomy'], FILTER_SANITIZE_STRING);
73
+ }
74
+ elseif ($pagenow === 'profile.php') {
75
+ $filter['user_id'] = get_current_user_id();
76
+ $filter['user_form'] = 'edit';
77
+ }
78
+ elseif ($pagenow === 'user-edit.php' && isset($_GET['user_id'])) {
79
+ $filter['user_id'] = filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT);
80
+ $filter['user_form'] = 'edit';
81
+ }
82
+ elseif ($pagenow === 'user-new.php') {
83
+ $filter['user_id'] = 'new';
84
+ $filter['user_form'] = 'edit';
85
+ }
86
+ elseif ($pagenow === 'media.php' || $pagenow === 'upload.php') {
87
+ $filter['attachment'] = 'All';
88
+ }
89
+
90
+ if (count($filter) === 0) {
91
+ return array();
92
+ }
93
+
94
+ $supported_field_types = array(
95
+ 'email',
96
+ 'text',
97
+ 'textarea',
98
+ );
99
+
100
+ $visible_fields = array();
101
+ foreach (acf_get_field_groups($args) as $field_group) {
102
+ $fields = acf_get_fields($field_group);
103
+ foreach ($fields as $field) {
104
+ if (in_array($field['type'], $supported_field_types)) {
105
+ $visible_fields[] = array('id' => 'acf-' . $field['key']);
106
+ }
107
+ }
108
+ }
109
+
110
+ return $visible_fields;
111
+ }
112
+
113
+ }
{v5 → src/acf_5}/fields/image.php RENAMED
@@ -1,23 +1,38 @@
1
  <?php
2
 
3
- class acf_field_qtranslate_image extends acf_field_image
4
- {
5
-
6
- function __construct()
7
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  $this->name = 'qtranslate_image';
9
  $this->label = __("Image", 'acf');
10
  $this->category = __("qTranslate", 'acf');
11
  $this->defaults = array(
12
- 'return_format' => 'array',
13
- 'preview_size' => 'thumbnail',
14
- 'library' => 'all'
15
  );
16
  $this->l10n = array(
17
- 'select' => __("Select Image",'acf'),
18
- 'edit' => __("Edit Image",'acf'),
19
- 'update' => __("Update Image",'acf'),
20
- 'uploadedTo' => __("uploaded to this post",'acf'),
21
  );
22
 
23
  acf_field::__construct();
@@ -27,23 +42,26 @@ class acf_field_qtranslate_image extends acf_field_image
27
  add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
28
  }
29
 
30
- function render_field($field)
31
- {
32
- if (!acf_qtranslate_enabled()) {
33
- acf_field_image::render_field($field);
34
- return;
35
- }
36
-
 
 
 
 
 
37
  global $q_config;
38
  $languages = qtrans_getSortedLanguages(true);
39
  $values = qtrans_split($field['value'], $quicktags = true);
40
  $currentLanguage = qtrans_getLanguage();
41
 
42
-
43
  // enqueue
44
  acf_enqueue_uploader();
45
 
46
-
47
  // vars
48
  $div_atts = array(
49
  'class' => 'acf-image-uploader acf-cf',
@@ -58,7 +76,6 @@ class acf_field_qtranslate_image extends acf_field_image
58
  );
59
  $url = '';
60
 
61
-
62
  echo '<div class="multi-language-field multi-language-field-image">';
63
 
64
  foreach ($languages as $language) {
@@ -78,12 +95,10 @@ class acf_field_qtranslate_image extends acf_field_image
78
 
79
  // has value?
80
  if( $field['value'] && is_numeric($field['value']) ) {
81
-
82
  $url = wp_get_attachment_image_src($field['value'], $field['preview_size']);
83
  $url = $url[0];
84
 
85
  $div_atts['class'] .= ' has-value';
86
-
87
  }
88
 
89
  if ($language === $currentLanguage) {
@@ -112,19 +127,24 @@ class acf_field_qtranslate_image extends acf_field_image
112
  echo '</div>';
113
  }
114
 
115
-
116
- function update_value($value, $post_id, $field)
117
- {
118
- $value = acf_field_image::update_value($value, $post_id, $field);
119
-
120
- if (acf_qtranslate_enabled()) {
121
- $value = qtrans_join($value);
122
- }
123
-
124
- return $value;
 
 
 
 
 
 
 
 
125
  }
126
 
127
  }
128
-
129
- new acf_field_qtranslate_image();
130
-
1
  <?php
2
 
3
+ namespace acf_qtranslate\acf_5\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_image;
7
+
8
+ class image extends acf_field_image {
9
+
10
+ /*
11
+ * __construct
12
+ *
13
+ * This function will setup the field type data
14
+ *
15
+ * @type function
16
+ * @date 5/03/2014
17
+ * @since 5.0.0
18
+ *
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();
42
  add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
43
  }
44
 
45
+ /*
46
+ * render_field()
47
+ *
48
+ * Create the HTML interface for your field
49
+ *
50
+ * @param $field - an array holding all the field's data
51
+ *
52
+ * @type action
53
+ * @since 3.6
54
+ * @date 23/01/13
55
+ */
56
+ function render_field($field) {
57
  global $q_config;
58
  $languages = qtrans_getSortedLanguages(true);
59
  $values = qtrans_split($field['value'], $quicktags = true);
60
  $currentLanguage = qtrans_getLanguage();
61
 
 
62
  // enqueue
63
  acf_enqueue_uploader();
64
 
 
65
  // vars
66
  $div_atts = array(
67
  'class' => 'acf-image-uploader acf-cf',
76
  );
77
  $url = '';
78
 
 
79
  echo '<div class="multi-language-field multi-language-field-image">';
80
 
81
  foreach ($languages as $language) {
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) {
127
  echo '</div>';
128
  }
129
 
130
+ /*
131
+ * update_value()
132
+ *
133
+ * This filter is appied to the $value before it is updated in the db
134
+ *
135
+ * @type filter
136
+ * @since 3.6
137
+ * @date 23/01/13
138
+ *
139
+ * @param $value - the value which will be saved in the database
140
+ * @param $post_id - the $post_id of which the value will be saved
141
+ * @param $field - the field array holding all the field options
142
+ *
143
+ * @return $value - the modified value
144
+ */
145
+ function update_value($value, $post_id, $field) {
146
+ $value = parent::update_value($value, $post_id, $field);
147
+ return qtrans_join($value);
148
  }
149
 
150
  }
 
 
 
{v5 → src/acf_5}/fields/text.php RENAMED
@@ -1,74 +1,80 @@
1
  <?php
2
 
3
- class acf_field_qtranslate_text extends acf_field_text
4
- {
5
-
6
- function __construct()
7
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  $this->name = 'qtranslate_text';
9
  $this->label = __("Text",'acf');
10
  $this->category = __("qTranslate",'acf');
11
  $this->defaults = array(
12
- 'default_value' => '',
13
- 'maxlength' => '',
14
- 'placeholder' => '',
15
- 'prepend' => '',
16
- 'append' => '',
17
- 'readonly' => 0,
18
- 'disabled' => 0,
19
  );
20
 
21
  acf_field::__construct();
22
  }
23
 
24
-
25
- function render_field($field)
26
- {
27
- if (!acf_qtranslate_enabled()) {
28
- acf_field_text::render_field($field);
29
- return;
30
- }
31
-
 
 
 
 
32
  global $q_config;
33
  $languages = qtrans_getSortedLanguages(true);
34
  $values = qtrans_split($field['value'], $quicktags = true);
35
 
36
-
37
  // vars
38
  $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' );
39
  $s = array( 'readonly', 'disabled' );
40
  $e = '';
41
 
42
-
43
  // maxlength
44
  if( $field['maxlength'] !== "" ) {
45
-
46
  $o[] = 'maxlength';
47
-
48
  }
49
 
50
-
51
  // populate atts
52
  $atts = array();
53
  foreach( $o as $k ) {
54
-
55
  $atts[ $k ] = $field[ $k ];
56
-
57
  }
58
 
59
-
60
  // special atts
61
  foreach( $s as $k ) {
62
-
63
  if( $field[ $k ] ) {
64
-
65
  $atts[ $k ] = $k;
66
-
67
  }
68
-
69
  }
70
 
71
-
72
  // render
73
  $e .= '<div class="acf-input-wrap multi-language-field">';
74
 
@@ -90,14 +96,23 @@ class acf_field_qtranslate_text extends acf_field_text
90
 
91
  $e .= '</div>';
92
 
93
-
94
  // return
95
  echo $e;
96
  }
97
 
98
-
99
- function render_field_settings( $field ) {
100
-
 
 
 
 
 
 
 
 
 
 
101
  // default_value
102
  acf_render_field_setting( $field, array(
103
  'label' => __('Default Value','acf'),
@@ -121,20 +136,25 @@ class acf_field_qtranslate_text extends acf_field_text
121
  'type' => 'number',
122
  'name' => 'maxlength',
123
  ));
124
-
125
  }
126
 
127
-
128
- function update_value($value, $post_id, $field)
129
- {
130
- if (acf_qtranslate_enabled()) {
131
- $value = qtrans_join($value);
132
- }
133
-
134
- return $value;
 
 
 
 
 
 
 
 
 
135
  }
136
 
137
  }
138
-
139
-
140
- new acf_field_qtranslate_text;
1
  <?php
2
 
3
+ namespace acf_qtranslate\acf_5\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_text;
7
+
8
+ class text extends acf_field_text {
9
+
10
+ /*
11
+ * __construct
12
+ *
13
+ * This function will setup the field type data
14
+ *
15
+ * @type function
16
+ * @date 5/03/2014
17
+ * @since 5.0.0
18
+ *
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');
26
  $this->defaults = array(
27
+ 'default_value' => '',
28
+ 'maxlength' => '',
29
+ 'placeholder' => '',
30
+ 'prepend' => '',
31
+ 'append' => '',
32
+ 'readonly' => 0,
33
+ 'disabled' => 0,
34
  );
35
 
36
  acf_field::__construct();
37
  }
38
 
39
+ /*
40
+ * render_field()
41
+ *
42
+ * Create the HTML interface for your field
43
+ *
44
+ * @param $field - an array holding all the field's data
45
+ *
46
+ * @type action
47
+ * @since 3.6
48
+ * @date 23/01/13
49
+ */
50
+ function render_field($field) {
51
  global $q_config;
52
  $languages = qtrans_getSortedLanguages(true);
53
  $values = qtrans_split($field['value'], $quicktags = true);
54
 
 
55
  // vars
56
  $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' );
57
  $s = array( 'readonly', 'disabled' );
58
  $e = '';
59
 
 
60
  // maxlength
61
  if( $field['maxlength'] !== "" ) {
 
62
  $o[] = 'maxlength';
 
63
  }
64
 
 
65
  // populate atts
66
  $atts = array();
67
  foreach( $o as $k ) {
 
68
  $atts[ $k ] = $field[ $k ];
 
69
  }
70
 
 
71
  // special atts
72
  foreach( $s as $k ) {
 
73
  if( $field[ $k ] ) {
 
74
  $atts[ $k ] = $k;
 
75
  }
 
76
  }
77
 
 
78
  // render
79
  $e .= '<div class="acf-input-wrap multi-language-field">';
80
 
96
 
97
  $e .= '</div>';
98
 
 
99
  // return
100
  echo $e;
101
  }
102
 
103
+ /*
104
+ * render_field_settings()
105
+ *
106
+ * Create extra options for your field. This is rendered when editing a field.
107
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
108
+ *
109
+ * @param $field - an array holding all the field's data
110
+ *
111
+ * @type action
112
+ * @since 3.6
113
+ * @date 23/01/13
114
+ */
115
+ function render_field_settings($field) {
116
  // default_value
117
  acf_render_field_setting( $field, array(
118
  'label' => __('Default Value','acf'),
136
  'type' => 'number',
137
  'name' => 'maxlength',
138
  ));
 
139
  }
140
 
141
+ /*
142
+ * update_value()
143
+ *
144
+ * This filter is appied to the $value before it is updated in the db
145
+ *
146
+ * @type filter
147
+ * @since 3.6
148
+ * @date 23/01/13
149
+ *
150
+ * @param $value - the value which will be saved in the database
151
+ * @param $post_id - the $post_id of which the value will be saved
152
+ * @param $field - the field array holding all the field options
153
+ *
154
+ * @return $value - the modified value
155
+ */
156
+ function update_value($value, $post_id, $field) {
157
+ return qtrans_join($value);
158
  }
159
 
160
  }
 
 
 
{v5 → src/acf_5}/fields/textarea.php RENAMED
@@ -1,82 +1,85 @@
1
  <?php
2
 
3
- class acf_field_qtranslate_textarea extends acf_field_textarea
4
- {
5
-
6
- function __construct()
7
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  $this->name = 'qtranslate_textarea';
9
  $this->label = __("Text Area",'acf');
10
  $this->category = __("qTranslate",'acf');
11
  $this->defaults = array(
12
- 'default_value' => '',
13
- 'new_lines' => '',
14
- 'maxlength' => '',
15
- 'placeholder' => '',
16
- 'readonly' => 0,
17
- 'disabled' => 0,
18
- 'rows' => ''
19
  );
20
 
21
  acf_field::__construct();
22
  }
23
 
24
-
25
- function render_field($field)
26
- {
27
- if (!acf_qtranslate_enabled()) {
28
- acf_field_textarea::render_field($field);
29
- return;
30
- }
31
-
 
 
 
 
32
  global $q_config;
33
  $languages = qtrans_getSortedLanguages(true);
34
  $values = qtrans_split($field['value'], $quicktags = true);
35
 
36
-
37
  // vars
38
  $o = array( 'id', 'class', 'name', 'placeholder', 'rows' );
39
  $s = array( 'readonly', 'disabled' );
40
  $e = '';
41
 
42
-
43
  // maxlength
44
  if( $field['maxlength'] !== '' ) {
45
-
46
  $o[] = 'maxlength';
47
-
48
  }
49
 
50
-
51
  // rows
52
  if( empty($field['rows']) ) {
53
-
54
  $field['rows'] = 8;
55
-
56
  }
57
 
58
-
59
  // populate atts
60
  $atts = array();
61
  foreach( $o as $k ) {
62
-
63
  $atts[ $k ] = $field[ $k ];
64
-
65
  }
66
 
67
-
68
  // special atts
69
  foreach( $s as $k ) {
70
-
71
  if( $field[ $k ] ) {
72
-
73
  $atts[ $k ] = $k;
74
-
75
  }
76
-
77
  }
78
 
79
-
80
  // render
81
  $e .= '<div class="acf-input-wrap multi-language-field">';
82
 
@@ -98,22 +101,27 @@ class acf_field_qtranslate_textarea extends acf_field_textarea
98
 
99
  $e .= '</div>';
100
 
101
-
102
  // return
103
  echo $e;
104
  }
105
 
106
-
107
- function update_value($value, $post_id, $field)
108
- {
109
- if (acf_qtranslate_enabled()) {
110
- $value = qtrans_join($value);
111
- }
112
-
113
- return $value;
 
 
 
 
 
 
 
 
 
114
  }
115
 
116
  }
117
-
118
-
119
- new acf_field_qtranslate_textarea;
1
  <?php
2
 
3
+ namespace acf_qtranslate\acf_5\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_textarea;
7
+
8
+ class textarea extends acf_field_textarea {
9
+
10
+ /*
11
+ * __construct
12
+ *
13
+ * This function will setup the field type data
14
+ *
15
+ * @type function
16
+ * @date 5/03/2014
17
+ * @since 5.0.0
18
+ *
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');
26
  $this->defaults = array(
27
+ 'default_value' => '',
28
+ 'new_lines' => '',
29
+ 'maxlength' => '',
30
+ 'placeholder' => '',
31
+ 'readonly' => 0,
32
+ 'disabled' => 0,
33
+ 'rows' => ''
34
  );
35
 
36
  acf_field::__construct();
37
  }
38
 
39
+ /*
40
+ * render_field()
41
+ *
42
+ * Create the HTML interface for your field
43
+ *
44
+ * @param $field - an array holding all the field's data
45
+ *
46
+ * @type action
47
+ * @since 3.6
48
+ * @date 23/01/13
49
+ */
50
+ function render_field($field) {
51
  global $q_config;
52
  $languages = qtrans_getSortedLanguages(true);
53
  $values = qtrans_split($field['value'], $quicktags = true);
54
 
 
55
  // vars
56
  $o = array( 'id', 'class', 'name', 'placeholder', 'rows' );
57
  $s = array( 'readonly', 'disabled' );
58
  $e = '';
59
 
 
60
  // maxlength
61
  if( $field['maxlength'] !== '' ) {
 
62
  $o[] = 'maxlength';
 
63
  }
64
 
 
65
  // rows
66
  if( empty($field['rows']) ) {
 
67
  $field['rows'] = 8;
 
68
  }
69
 
 
70
  // populate atts
71
  $atts = array();
72
  foreach( $o as $k ) {
 
73
  $atts[ $k ] = $field[ $k ];
 
74
  }
75
 
 
76
  // special atts
77
  foreach( $s as $k ) {
 
78
  if( $field[ $k ] ) {
 
79
  $atts[ $k ] = $k;
 
80
  }
 
81
  }
82
 
 
83
  // render
84
  $e .= '<div class="acf-input-wrap multi-language-field">';
85
 
101
 
102
  $e .= '</div>';
103
 
 
104
  // return
105
  echo $e;
106
  }
107
 
108
+ /*
109
+ * update_value()
110
+ *
111
+ * This filter is appied to the $value before it is updated in the db
112
+ *
113
+ * @type filter
114
+ * @since 3.6
115
+ * @date 23/01/13
116
+ *
117
+ * @param $value - the value which will be saved in the database
118
+ * @param $post_id - the $post_id of which the value will be saved
119
+ * @param $field - the field array holding all the field options
120
+ *
121
+ * @return $value - the modified value
122
+ */
123
+ function update_value($value, $post_id, $field) {
124
+ return qtrans_join($value);
125
  }
126
 
127
  }
 
 
 
{v5 → src/acf_5}/fields/wysiwyg.php RENAMED
@@ -1,27 +1,39 @@
1
  <?php
2
 
3
- class acf_field_qtranslate_wysiwyg extends acf_field_wysiwyg
4
- {
5
-
6
- function __construct()
7
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  $this->name = 'qtranslate_wysiwyg';
9
  $this->label = __("Wysiwyg Editor",'acf');
10
  $this->category = __("qTranslate",'acf');
11
  $this->defaults = array(
12
- 'tabs' => 'all',
13
- 'toolbar' => 'full',
14
- 'media_upload' => 1,
15
- 'default_value' => '',
16
  );
17
 
18
-
19
  // Create an acf version of the_content filter (acf_the_content)
20
  if( !empty($GLOBALS['wp_embed']) ) {
21
-
22
  add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
23
  add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
24
-
25
  }
26
 
27
  add_filter( 'acf_the_content', 'capital_P_dangit', 11 );
@@ -37,6 +49,3 @@ class acf_field_qtranslate_wysiwyg extends acf_field_wysiwyg
37
  }
38
 
39
  }
40
-
41
-
42
- new acf_field_qtranslate_wysiwyg;
1
  <?php
2
 
3
+ namespace acf_qtranslate\acf_5\fields;
4
+
5
+ use acf_field;
6
+ use acf_field_wysiwyg;
7
+
8
+ class wysiwyg extends acf_field_wysiwyg {
9
+
10
+ /*
11
+ * __construct
12
+ *
13
+ * This function will setup the field type data
14
+ *
15
+ * @type function
16
+ * @date 5/03/2014
17
+ * @since 5.0.0
18
+ *
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)
34
  if( !empty($GLOBALS['wp_embed']) ) {
 
35
  add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
36
  add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
 
37
  }
38
 
39
  add_filter( 'acf_the_content', 'capital_P_dangit', 11 );
49
  }
50
 
51
  }
 
 
 
src/acf_interface.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace acf_qtranslate;
4
+
5
+ interface acf_interface {
6
+
7
+ /**
8
+ * Get the visible ACF fields.
9
+ * @return array
10
+ */
11
+ public function get_visible_acf_fields();
12
+
13
+ }
src/plugin.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace acf_qtranslate;
4
+
5
+ use acf_qtranslate\acf_4\acf as acf_4;
6
+ use acf_qtranslate\acf_5\acf as acf_5;
7
+
8
+ class plugin {
9
+
10
+ /**
11
+ * Create an instance.
12
+ * @return void
13
+ */
14
+ public function __construct() {
15
+ add_action('plugins_loaded', array($this, 'plugins_loaded'), 3);
16
+ }
17
+
18
+ /**
19
+ * Setup plugin if Advanced Custom Fields is enabled.
20
+ * @return void
21
+ */
22
+ public function plugins_loaded() {
23
+ if ($this->acf_enabled() && $this->qtranslate_variant_enabled()) {
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
36
+ if ($this->qtranslatex_enabled()) {
37
+ new qtranslatex($this, $acf);
38
+ }
39
+
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Check whether the plugin is active by checking the active_plugins list.
45
+ *
46
+ * @param string $plugin Base plugin path from plugins directory.
47
+ * @return bool True, if in the active plugins list. False, not in the list.
48
+ */
49
+ public function is_plugin_active($plugin) {
50
+ return in_array($plugin, (array)get_option('active_plugins', array())) || $this->is_plugin_active_for_network($plugin);
51
+ }
52
+
53
+ /**
54
+ * Check whether the plugin is active for the entire network.
55
+ *
56
+ * @param string $plugin Base plugin path from plugins directory.
57
+ * @return bool True, if active for the network, otherwise false.
58
+ */
59
+ public function is_plugin_active_for_network($plugin) {
60
+ if (!is_multisite()) {
61
+ return false;
62
+ }
63
+ $plugins = get_site_option('active_sitewide_plugins');
64
+ if (isset($plugins[$plugin])) {
65
+ return true;
66
+ }
67
+ return false;
68
+ }
69
+
70
+ /**
71
+ * Check if Advanced Custom Fields is enabled.
72
+ * @return boolean
73
+ */
74
+ public function acf_enabled() {
75
+ if (function_exists('acf')) {
76
+ return $this->acf_major_version() === 4 || $this->acf_major_version() === 5;
77
+ }
78
+ return false;
79
+ }
80
+
81
+ /**
82
+ * Return the major version number for Advanced Custom Fields.
83
+ * @return int
84
+ */
85
+ public function acf_major_version() {
86
+ return (int) acf()->settings['version'][0];
87
+ }
88
+
89
+ /**
90
+ * Check if a qTranslate variant is enabled.
91
+ * @return boolean
92
+ */
93
+ public function qtranslate_variant_enabled() {
94
+ $plugins = array(
95
+ 'qtranslate/qtranslate.php',
96
+ 'ztranslate/ztranslate.php',
97
+ 'mqtranslate/mqtranslate.php',
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
+ }
105
+ }
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
+ }
src/qtranslatex.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace acf_qtranslate;
4
+
5
+ class qtranslatex {
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
+ // 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
+
35
+ /**
36
+ * Add class to the body element.
37
+ */
38
+ public function admin_head() {
39
+ ?>
40
+ <style>
41
+ .multi-language-field {margin-top:0!important;}
42
+ .multi-language-field .wp-switch-editor {display:none!important;}
43
+ </style>
44
+ <?php
45
+ }
46
+
47
+ /**
48
+ * Load ACF form element ids into qTranslate-X.
49
+ * @return void
50
+ */
51
+ public function qtranslate_load_admin_page_config($configs) {
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
+ }
qtranslate-compatibility.php → src/qtranslatex/qtranslate-compatibility.php RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- // compatibility with qTranslate-X
4
 
5
  if (function_exists('qtrans_getLanguage') === false):
6
  function qtrans_getLanguage() {
1
  <?php
2
 
3
+ // provide qTranslate compatibility when using qTranslate-X
4
 
5
  if (function_exists('qtrans_getLanguage') === false):
6
  function qtrans_getLanguage() {
v4/assets/input.css DELETED
@@ -1,87 +0,0 @@
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;
8
- padding: 0 !important;
9
- border: 0 !important;
10
- }
11
-
12
- .qtrans_title_input {
13
- padding: 3px 8px !important;
14
- font-size: 1.7em;
15
- line-height: 100%;
16
- height: 1.7em;
17
- outline: 0 !important;
18
- margin: 0;
19
- }
20
-
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;
27
- top: 1px;
28
- z-index: 100;
29
- float: right;
30
- }
31
-
32
- .multi-language-field input,
33
- .multi-language-field input:focus,
34
- .multi-language-field textarea,
35
- .multi-language-field textarea:focus {
36
- border-color: #ddd;
37
- box-shadow: none;
38
- }
39
-
40
- .multi-language-field.focused .wp-switch-editor {
41
- border-bottom-color: #ddd;
42
- }
43
-
44
- .multi-language-field.focused .wp-switch-editor.current-language {
45
- border-color: #ddd;
46
- border-bottom-color: #fff;
47
- }
48
-
49
- .multi-language-field .wp-switch-editor.current-language {
50
- background-color: #fff;
51
- border-bottom-color: #fff;
52
- color: #333;
53
- }
54
-
55
- .multi-language-field > input,
56
- .multi-language-field > textarea,
57
- .multi-language-field > fieldset,
58
- .multi-language-field .acf_wysiwyg,
59
- .multi-language-field .acf-image-uploader,
60
- .multi-language-field .acf-file-uploader { display: none }
61
-
62
- .multi-language-field .acf_input input,
63
- .multi-language-field .acf_input textarea,
64
- .multi-language-field .current-language { display: block !important }
65
-
66
- .multi-language-field-wysiwyg { margin-top: 0 }
67
-
68
- .multi-language-field .acf-image-uploader,
69
- .multi-language-field .acf-file-uploader {
70
- padding: 20px 10px 10px;
71
- clear: right;
72
- border: 1px solid #dfdfdf;
73
- }
74
-
75
- .multi-language-field .acf-image-uploader.current-language,
76
- .multi-language-field .acf-file-uploader { background: #fff; }
77
-
78
- .multi-language-field-wysiwyg .wp-switch-editor {
79
- background-color: #ebebeb;
80
- border-color: #dedede;
81
- }
82
-
83
- .multi-language-field-wysiwyg .wp-switch-editor.current-language {
84
- background-color: #f5f5f5;
85
- border-bottom-color: #f5f5f5;
86
- }
87
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
v4/assets/input.js DELETED
@@ -1,22 +0,0 @@
1
-
2
- jQuery(function($) {
3
-
4
-
5
- $('body').on('click', '.wp-switch-editor[data-language]', function() {
6
- var parent = $(this).parent('.multi-language-field'), language = $(this).data('language');
7
-
8
- parent.find('.current-language').removeClass('current-language');
9
- parent.find('[data-language="' + language + '"]').addClass('current-language');
10
- parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]').focus();
11
- });
12
-
13
- $('body').on('focusin', '.multi-language-field input, .multi-language-field textarea', function() {
14
- $(this).parent('.multi-language-field').addClass('focused');
15
- });
16
-
17
- $('body').on('focusout', '.multi-language-field input, .multi-language-field textarea', function() {
18
- $(this).parent('.multi-language-field').removeClass('focused');
19
- });
20
-
21
-
22
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
v4/fields/file.php DELETED
@@ -1,165 +0,0 @@
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/fields/text.php DELETED
@@ -1,70 +0,0 @@
1
- <?php
2
-
3
- class acf_field_qtranslate_text extends acf_field_text
4
- {
5
-
6
- function __construct()
7
- {
8
- $this->name = 'qtranslate_text';
9
- $this->label = __("Text",'acf');
10
- $this->category = __("qTranslate",'acf');
11
-
12
- acf_field::__construct();
13
- }
14
-
15
-
16
- function create_field($field)
17
- {
18
- if (!acf_qtranslate_enabled()) {
19
- acf_field_text::create_field($field);
20
- return;
21
- }
22
-
23
- global $q_config;
24
- $languages = qtrans_getSortedLanguages(true);
25
- $values = qtrans_split($field['value'], $quicktags = true);
26
-
27
- echo '<div class="multi-language-field">';
28
-
29
- foreach ($languages as $language) {
30
- $class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
31
- echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
32
- }
33
-
34
- foreach ($languages as $language) {
35
- $class = ($language === end($languages)) ? $field['class'] . ' current-language' : $field['class'];
36
- echo '<input type="text" data-language="' . esc_attr($language) . '" value="' . esc_attr($values[$language]) . '" id="' . esc_attr( $field['id'] ) . '" class="' . esc_attr($class) . '" name="' . esc_attr($field['name'] . "[$language]") . '" />';
37
- }
38
-
39
- echo '</div>';
40
- }
41
-
42
-
43
- function format_value($value, $post_id, $field)
44
- {
45
- return $value;
46
- }
47
-
48
-
49
- function format_value_for_api($value, $post_id, $field) {
50
- if (acf_qtranslate_enabled()) {
51
- $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
52
- }
53
-
54
- return acf_field_text::format_value_for_api($value, $post_id, $field);
55
- }
56
-
57
-
58
- function update_value($value, $post_id, $field)
59
- {
60
- if (acf_qtranslate_enabled()) {
61
- $value = qtrans_join($value);
62
- }
63
-
64
- return $value;
65
- }
66
-
67
- }
68
-
69
-
70
- new acf_field_qtranslate_text;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
v4/fields/textarea.php DELETED
@@ -1,70 +0,0 @@
1
- <?php
2
-
3
- class acf_field_qtranslate_textarea extends acf_field_textarea
4
- {
5
-
6
- function __construct()
7
- {
8
- $this->name = 'qtranslate_textarea';
9
- $this->label = __("Text Area",'acf');
10
- $this->category = __("qTranslate",'acf');
11
-
12
- acf_field::__construct();
13
- }
14
-
15
-
16
- function create_field($field)
17
- {
18
- if (!acf_qtranslate_enabled()) {
19
- acf_field_textarea::create_field($field);
20
- return;
21
- }
22
-
23
- global $q_config;
24
- $languages = qtrans_getSortedLanguages(true);
25
- $values = qtrans_split($field['value'], $quicktags = true);
26
-
27
- echo '<div class="multi-language-field">';
28
-
29
- foreach ($languages as $language) {
30
- $class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
31
- echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
32
- }
33
-
34
- foreach ($languages as $language) {
35
- $class = ($language === end($languages)) ? $field['class'] . ' current-language' : $field['class'];
36
- echo '<textarea data-language="' . esc_attr($language) . '" id="' . esc_attr( $field['id'] ) . '" rows="4" class="' . esc_attr($class) . '" name="' . esc_attr($field['name'] . "[$language]") . '">' . esc_textarea($values[$language]) . '</textarea>';
37
- }
38
-
39
- echo '</div>';
40
- }
41
-
42
-
43
- function format_value($value, $post_id, $field)
44
- {
45
- return $value;
46
- }
47
-
48
-
49
- function format_value_for_api($value, $post_id, $field) {
50
- if (acf_qtranslate_enabled()) {
51
- $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
52
- }
53
-
54
- return acf_field_textarea::format_value_for_api($value, $post_id, $field);
55
- }
56
-
57
-
58
- function update_value($value, $post_id, $field)
59
- {
60
- if (acf_qtranslate_enabled()) {
61
- $value = qtrans_join($value);
62
- }
63
-
64
- return $value;
65
- }
66
-
67
- }
68
-
69
-
70
- new acf_field_qtranslate_textarea;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
v4/init.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
- add_action('admin_enqueue_scripts', 'acf_qtranslate_v4_admin_enqueue_scripts');
4
- function acf_qtranslate_v4_admin_enqueue_scripts() {
5
- if (acf_qtranslate_acf_major_version() === 4) {
6
- wp_enqueue_style('acf_qtranslate_main', plugins_url('/assets/input.css', __FILE__));
7
- wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/input.js', __FILE__));
8
- }
9
- }
10
-
11
- add_action('acf/register_fields', 'acf_qtranslate_plugin_v4_register_fields');
12
- function acf_qtranslate_plugin_v4_register_fields() {
13
- require_once dirname(__FILE__) . '/fields/text.php';
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');
21
- function acf_qtranslate_plugin_v4_format_value_for_api($value) {
22
- if (acf_qtranslate_enabled() && is_string($value)) {
23
- $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
24
- }
25
- return $value;
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
v5/assets/input.js DELETED
@@ -1,27 +0,0 @@
1
-
2
- jQuery(function($) {
3
-
4
-
5
- $('body').on('click', '.wp-switch-editor[data-language]', function() {
6
- var parent = $(this).parent('.multi-language-field'), language = $(this).data('language');
7
-
8
- parent.find('.current-language').removeClass('current-language');
9
- parent.find('[data-language="' + language + '"]').addClass('current-language');
10
- parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]').focus();
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
-
18
- $('body').on('focusin', '.multi-language-field input, .multi-language-field textarea', function() {
19
- $(this).parent('.multi-language-field').addClass('focused');
20
- });
21
-
22
- $('body').on('focusout', '.multi-language-field input, .multi-language-field textarea', function() {
23
- $(this).parent('.multi-language-field').removeClass('focused');
24
- });
25
-
26
-
27
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
v5/init.php DELETED
@@ -1,31 +0,0 @@
1
- <?php
2
-
3
- add_action('acf/input/admin_enqueue_scripts', 'acf_qtranslate_v5_admin_enqueue_scripts');
4
- function acf_qtranslate_v5_admin_enqueue_scripts() {
5
- if (acf_qtranslate_acf_major_version() === 5) {
6
- wp_enqueue_style('editor-buttons');
7
- wp_enqueue_style('acf_qtranslate_main', plugins_url('/assets/input.css', __FILE__));
8
- wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/input.js', __FILE__));
9
- }
10
- }
11
-
12
- add_action('acf/include_field_types', 'acf_qtranslate_plugin_v5_include_field_types');
13
- function acf_qtranslate_plugin_v5_include_field_types($version) {
14
- require_once dirname(__FILE__) . '/fields/text.php';
15
- require_once dirname(__FILE__) . '/fields/textarea.php';
16
- require_once dirname(__FILE__) . '/fields/wysiwyg.php';
17
- require_once dirname(__FILE__) . '/fields/image.php';
18
- }
19
-
20
- add_filter('acf/format_value', 'acf_qtranslate_plugin_v5_format_value');
21
- function acf_qtranslate_plugin_v5_format_value($value) {
22
- // we must check the version here since acf/format_value is a valid filter
23
- // ACF v4 however it serves a slightly different purpose
24
- if (acf_qtranslate_acf_major_version() === 5) {
25
- if (acf_qtranslate_enabled() && is_string($value)) {
26
- $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
27
- }
28
- return $value;
29
- }
30
- return $value;
31
- }