Changeset 1536246
- Timestamp:
- 11/18/2016 11:01:29 AM (9 years ago)
- Location:
- acf-qtranslate/trunk
- Files:
-
- 6 edited
-
acf-qtranslate.php (modified) (1 diff)
-
assets/acf_4/qtranslatex.js (modified) (4 diffs)
-
assets/acf_5/qtranslatex.js (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
src/acf_4/fields/wysiwyg.php (modified) (3 diffs)
-
src/plugin.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
acf-qtranslate/trunk/acf-qtranslate.php
r1536127 r1536246 4 4 Plugin URI: http://github.com/funkjedi/acf-qtranslate 5 5 Description: Provides multilingual versions of the text, text area, and wysiwyg fields. 6 Version: 1.7.1 56 Version: 1.7.16 7 7 Author: funkjedi 8 8 Author URI: http://funkjedi.com -
acf-qtranslate/trunk/assets/acf_4/qtranslatex.js
r1536127 r1536246 28 28 }); 29 29 30 var post_type = jQuery('#post_type').val(); 31 32 // Whitelist fields for translation 33 function isTranslatableField(field){ 34 if (post_type === 'acf-field-group') { 35 if (field.id.match(/acf-field-field_[a-z0-9]+_label/)) return true; 36 if (field.id.match(/acf-field-field_[a-z0-9]+_instructions/)) return true; 37 if (field.id.match(/acf-field-field_[a-z0-9]+_default_value/)) return true; 38 return false; 39 } 40 return true; 41 } 42 30 43 // Watch and add content hooks when new fields are added 31 var timeoutContentHooksTinyMCE;32 44 jQuery(document).on('acf/setup_fields', function(e, new_field) { 33 45 new_field = jQuery(new_field); … … 40 52 return; 41 53 } 54 55 if (!isTranslatableField(field)) return; 42 56 43 57 qTranslateConfig.qtx.addContentHookC(this, field.closest('form').get(0)); … … 56 70 // Run in a setTimeout block to give the tinyMCE instance 57 71 // enough time to initialize before setting the editor hooks 58 clearTimeout(timeoutContentHooksTinyMCE); 59 timeoutContentHooksTinyMCE = setTimeout(function(){ 60 qTranslateConfig.qtx.addContentHooksTinyMCE(); 72 setTimeout(function(){ 61 73 jQuery.each(tinyMCE.editors, function(i, ed){ 62 var mceInit = tinyMCEPreInit.mceInit[ed.id]; 63 console.log('initEditors:',mceInit); 64 if (mceInit && mceInit.init_instance_callback) { 65 mceInit.init_instance_callback(ed); 66 } 74 setEditorHooks(ed); 67 75 }); 68 }, 50);76 },50); 69 77 }); 70 78 … … 77 85 }); 78 86 87 88 // Extracted from qTranslate-X 89 // admin/js/common.js#L840 90 function setEditorHooks(ed) { 91 var id = ed.id; 92 if (!id) return; 93 var h=qTranslateConfig.qtx.hasContentHook(id); 94 if(!h || h.mce) return; 95 h.mce=ed; 96 ed.getContainer().className += ' qtranxs-translatable'; 97 ed.getElement().className += ' qtranxs-translatable'; 98 var updateTinyMCEonInit = h.updateTinyMCEonInit; 99 if (updateTinyMCEonInit == null) { 100 var text_e = ed.getContent({format: 'html'}).replace(/\s+/g,''); 101 var text_h = h.contentField.value.replace(/\s+/g,''); 102 updateTinyMCEonInit = text_e != text_h; 103 } 104 if (updateTinyMCEonInit) { 105 text = h.contentField.value; 106 if (h.wpautop && window.switchEditors) { 107 text = window.switchEditors.wpautop(text); 108 } 109 h.mce.setContent(text,{format: 'html'}); 110 } 111 return h; 112 } 113 79 114 }); -
acf-qtranslate/trunk/assets/acf_5/qtranslatex.js
r1536127 r1536246 37 37 }); 38 38 39 var post_type = jQuery('#post_type').val(); 40 41 // Whitelist fields for translation 42 function isTranslatableField(field){ 43 if (post_type === 'acf-field-group') { 44 if (field.id.match(/acf_fields-\d+-label/)) return true; 45 if (field.id.match(/acf_fields-\d+-instructions/)) return true; 46 if (field.id.match(/acf_fields-\d+-default_value/)) return true; 47 return false; 48 } 49 return true; 50 } 51 39 52 // Setup field types 40 53 jQuery.each(field_types, function(field_type, selector) { … … 44 57 var form = jQuery(this).closest('form').get(0); 45 58 var field = jQuery(this).find(selector).get(0); 59 if (!isTranslatableField(field)) return; 46 60 qTranslateConfig.qtx.addContentHookC(field, form); 47 61 }); … … 51 65 var form = $el.closest('form').get(0); 52 66 var field = $el.find(selector).get(0); 67 if (!isTranslatableField(field)) return; 53 68 qTranslateConfig.qtx.addContentHookC(field, form); 54 69 -
acf-qtranslate/trunk/readme.txt
r1536127 r1536246 4 4 Requires at least: 3.5.0 5 5 Tested up to: 4.6.1 6 Version: 1.7.1 57 Stable tag: 1.7.1 56 Version: 1.7.16 7 Stable tag: 1.7.16 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 59 59 60 60 == Changelog == 61 62 = 1.7.16 = 63 * Bug Fix: Fixed ACF4 support for standard WYSIWYG field 64 * Bug Fix: Updated ACF4 qTranslate WYSIWYG field 65 * Bug Fix: Prevent translation of key `acf-field-group` fields 61 66 62 67 = 1.7.15 = -
acf-qtranslate/trunk/src/acf_4/fields/wysiwyg.php
r1519271 r1536246 30 30 ); 31 31 32 // Create an acf version of the_content filter (acf_the_content) 33 if( isset($GLOBALS['wp_embed']) ) { 34 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 40 add_filter( 'acf_the_content', 'capital_P_dangit', 11 ); 41 add_filter( 'acf_the_content', 'wptexturize' ); 42 add_filter( 'acf_the_content', 'convert_smilies' ); 43 add_filter( 'acf_the_content', 'convert_chars' ); 44 add_filter( 'acf_the_content', 'wpautop' ); 45 add_filter( 'acf_the_content', 'shortcode_unautop' ); 46 //add_filter( 'acf_the_content', 'prepend_attachment' ); *should only be for the_content (causes double image on attachment page) 47 add_filter( 'acf_the_content', 'do_shortcode', 11); 48 32 49 acf_field::__construct(); 50 51 // filters 52 add_filter( 'acf/fields/wysiwyg/toolbars', array( $this, 'toolbars'), 1, 1 ); 53 add_filter( 'mce_external_plugins', array( $this, 'mce_external_plugins'), 20, 1 ); 33 54 } 34 55 … … 62 83 $values = qtrans_split($field['value'], $quicktags = true); 63 84 $currentLanguage = $this->plugin->get_active_language(); 64 85 86 // vars 87 //$id = uniqid('acf-editor-'); 88 $id = 'wysiwyg-' . $field['id'] . '-' . uniqid(); 89 $default_editor = 'tinymce'; 90 65 91 // filter value for editor 66 remove_all_filters('acf_the_editor_content'); 67 92 remove_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 ); 93 remove_filter( 'acf_the_editor_content', 'wp_htmledit_pre', 10, 1 ); 94 remove_filter( 'acf_the_editor_content', 'wp_richedit_pre', 10, 1 ); 95 68 96 // WP 4.3 69 if( version_compare($wp_version, '4.3', '>=' ) ) { 70 add_filter( 'acf_the_editor_content', 'format_for_editor' );97 if( version_compare($wp_version, '4.3', '>=' ) ) { 98 add_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 ); 71 99 // WP < 4.3 72 } else { 73 $function = user_can_richedit() ? 'wp_richedit_pre' : 'wp_htmledit_pre'; 74 add_filter('acf_the_editor_content', $function );100 } else { 101 $function = user_can_richedit() ? 'wp_richedit_pre' : 'wp_htmledit_pre'; 102 add_filter('acf_the_editor_content', $function, 10, 1); 75 103 } 76 104 … … 83 111 84 112 foreach ($languages as $language): 85 $value = $values[$language];86 113 $id = 'wysiwyg-' . $field['id'] . '-' . uniqid(); 87 114 $name = $field['name'] . "[$language]"; 88 $class = ($language === $currentLanguage) ? 'acf_wysiwyg wp-editor-wrap current-language' : 'acf_wysiwyg wp-editor-wrap'; 115 $class = ($language === $currentLanguage) ? 'current-language' : ''; 116 $value = apply_filters('acf_the_editor_content', $values[$language], 'tinymce'); 89 117 90 118 ?> 91 <div id="wp-<?php echo $id; ?>-wrap" class="<?php echo $class; ?>" data-toolbar="<?php echo $field['toolbar']; ?>" data-upload="<?php echo $field['media_upload']; ?>" data-language="<?php echo $language; ?>"> 92 <?php if( user_can_richedit() && $field['media_upload'] == 'yes' ): ?> 93 <?php if( version_compare($wp_version, '3.3', '<') ): ?> 94 <div id="editor-toolbar"> 95 <div id="media-buttons" class="hide-if-no-js"> 96 <?php do_action( 'media_buttons' ); ?> 97 </div> 98 </div> 99 <?php else: ?> 100 <div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools"> 101 <div id="wp-<?php echo $id; ?>-media-buttons" class="hide-if-no-js wp-media-buttons"> 102 <?php do_action( 'media_buttons' ); ?> 103 </div> 104 </div> 119 <div id="wp-<?php echo $id; ?>-wrap" class="acf_wysiwyg wp-core-ui wp-editor-wrap tmce-active <?php echo $class; ?>" data-toolbar="<?php echo $field['toolbar']; ?>" data-upload="<?php echo $field['media_upload']; ?>" data-language="<?php echo $language; ?>"> 120 <div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools hide-if-no-js"> 121 <?php if( user_can_richedit() && $field['media_upload'] == 'yes' ): ?> 122 <div id="wp-<?php echo $id; ?>-media-buttons" class="wp-media-buttons"> 123 <?php do_action( 'media_buttons', $id ); ?> 124 </div> 105 125 <?php endif; ?> 106 < ?php endif; ?>126 </div> 107 127 <div id="wp-<?php echo $id; ?>-editor-container" class="wp-editor-container"> 108 <textarea id="<?php echo $id; ?>" class="qtx-wp-editor-area" name="<?php echo $name; ?>" ><?php echo apply_filters( 'acf_the_editor_content', $value, 'tinymce' ); ?></textarea>128 <textarea id="<?php echo $id; ?>" class="qtx-wp-editor-area" name="<?php echo $name; ?>"><?php echo $value; ?></textarea> 109 129 </div> 110 130 </div> 131 111 132 <?php endforeach; 112 133 -
acf-qtranslate/trunk/src/plugin.php
r1536127 r1536246 17 17 add_action('after_setup_theme', array($this, 'after_setup_theme'), -10); 18 18 add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); 19 add_action('admin_footer', array($this, 'admin_footer')); 19 20 add_action('admin_menu', array($this, 'admin_menu')); 20 21 add_action('admin_init', array($this, 'admin_init')); … … 167 168 168 169 /** 170 * Output a hidden block that can be use to force qTranslate-X 171 * to include the LSB. 172 */ 173 public function admin_footer() { 174 echo '<span id="acf-qtranslate-lsb-shim" style="display:none">[:en]LSB[:]</span>'; 175 } 176 177 /** 169 178 * Add settings link on plugin page. 170 179 * @param array … … 183 192 public function qtranslate_load_admin_page_config($config) 184 193 { 185 $config['acf-options-page'] = array( 186 'pages' => array('admin.php' => 'page='), 187 'anchors' => array('poststuff' => array('where' => 'first last')), 188 'forms' => array( 194 $config['acf-display-nodes'] = array( 195 'pages' => array('post.php' => '', 'admin.php' => 'page='), 196 'forms' => array( 197 'wpwrap' => array( 198 'fields' => array( 199 'lsb-shim' => array( 200 'jquery' => '#acf-qtranslate-lsb-shim', 201 'encode' => 'display', 202 ), 203 'acf4-field-group-handle' => array( 204 'jquery' => '.acf_postbox h2 span,.acf_postbox h3 span', 205 'encode' => 'display', 206 ), 207 'acf5-field-group-handle' => array( 208 'jquery' => '.acf-postbox h2 span,.acf-postbox h3 span', 209 'encode' => 'display', 210 ), 211 'acf5-field-label' => array( 212 'jquery' => '.acf-field .acf-label label', 213 'encode' => 'display', 214 ), 215 'acf5-field-description' => array( 216 'jquery' => '.acf-field .acf-label p.description', 217 'encode' => 'display', 218 ), 219 )), 220 ), 221 ); 222 223 $config['acf-field-group'] = array( 224 'pages' => array('post.php' => ''), 225 'post_type' => 'acf-field-group', 226 'forms' => array( 189 227 'post' => array( 190 228 'fields' => array( 191 'acf4-field-group-hX' => array( 192 'jquery' => '.acf_postbox h2 span,.acf_postbox h3 span', 193 'encode' => 'display', 194 ), 195 'acf5-field-group-hX' => array( 196 'jquery' => '.acf-postbox h2 span,.acf-postbox h3 span', 229 'field-group-object-label' => array( 230 'jquery' => '.li-field-label .edit-field', 197 231 'encode' => 'display', 198 232 ),
Note: See TracChangeset
for help on using the changeset viewer.