Changeset 1963238
- Timestamp:
- 10/26/2018 03:18:38 AM (7 years ago)
- Location:
- acf-qtranslate/trunk
- Files:
-
- 1 added
- 12 edited
-
acf-qtranslate.php (modified) (1 diff)
-
assets/acf_5/main.js (modified) (5 diffs)
-
assets/acf_5/qtranslatex.js (modified) (3 diffs)
-
assets/common.css (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
-
src/acf_5/acf.php (modified) (3 diffs)
-
src/acf_5/fields/file.php (modified) (1 diff)
-
src/acf_5/fields/image.php (modified) (2 diffs)
-
src/acf_5/fields/post_object.php (added)
-
src/acf_5/fields/text.php (modified) (1 diff)
-
src/acf_5/fields/textarea.php (modified) (1 diff)
-
src/acf_5/fields/url.php (modified) (2 diffs)
-
src/acf_5/fields/wysiwyg.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
acf-qtranslate/trunk/acf-qtranslate.php
r1948002 r1963238 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.2 46 Version: 1.7.25 7 7 Author: funkjedi 8 8 Author URI: http://funkjedi.com -
acf-qtranslate/trunk/assets/acf_5/main.js
r1948002 r1963238 1 /** 2 * Clone functionality from standard Image field type 3 */ 1 2 3 acf.registerFieldType(acf.models.FileField.extend({ 4 type: 'qtranslate_file', 5 6 $control: function(){ 7 return this.$('.acf-file-uploader.current-language'); 8 }, 9 10 $input: function(){ 11 return this.$('.acf-file-uploader.current-language input[type="hidden"]'); 12 }, 13 14 render: function( attachment ){ 15 16 // vars 17 attachment = this.validateAttachment( attachment ); 18 19 // update image 20 this.$control().find('img').attr({ 21 src: attachment.icon, 22 alt: attachment.alt, 23 title: attachment.title 24 }); 25 26 // update elements 27 this.$control().find('[data-name="title"]').text( attachment.title ); 28 this.$control().find('[data-name="filename"]').text( attachment.filename ).attr( 'href', attachment.url ); 29 this.$control().find('[data-name="filesize"]').text( attachment.filesizeHumanReadable ); 30 31 // vars 32 var val = attachment.id || ''; 33 34 // update val 35 acf.val( this.$input(), val ); 36 37 // update class 38 if( val ) { 39 this.$control().addClass('has-value'); 40 } else { 41 this.$control().removeClass('has-value'); 42 } 43 } 44 })); 45 46 4 47 acf.registerFieldType(acf.models.ImageField.extend({ 5 48 type: 'qtranslate_image', … … 14 57 15 58 render: function( attachment ){ 16 var control = this.$control();17 59 18 60 // vars … … 20 62 21 63 // update image 22 control.find('img').attr({64 this.$control().find('img').attr({ 23 65 src: attachment.url, 24 66 alt: attachment.alt, … … 34 76 // update class 35 77 if( val ) { 36 control.addClass('has-value');78 this.$control().addClass('has-value'); 37 79 } else { 38 control.removeClass('has-value');80 this.$control().removeClass('has-value'); 39 81 } 40 82 } 41 83 })); 42 84 43 /**44 * Clone functionality from standard File field type45 */46 acf.registerFieldType(acf.models.QtranslateImageField.extend({47 type: 'qtranslate_file',48 render: function( attachment ){49 var control = this.$control();50 51 // vars52 attachment = this.validateAttachment( attachment );53 85 54 // update image 55 this.$control().find(' img').attr({ 56 src: attachment.icon, 57 alt: attachment.alt, 58 title: attachment.title 59 }); 86 acf.registerFieldType(acf.models.PostObjectField.extend({ 87 type: 'qtranslate_post_object', 60 88 61 // update elements 62 control.find('[data-name="title"]').text( attachment.title ); 63 control.find('[data-name="filename"]').text( attachment.filename ).attr( 'href', attachment.url ); 64 control.find('[data-name="filesize"]').text( attachment.filesizeHumanReadable ); 89 $input: function(){ 90 return this.$('.acf-post-object.current-language select'); 91 }, 92 93 initialize: function(){ 94 var self = this; 65 95 66 96 // vars 67 var val = attachment.id || '';97 var $select = this.$input(); 68 98 69 // update val70 acf.val( this.$input(), val);99 // inherit data 100 this.inherit( $select ); 71 101 72 // update class 73 if( val ) { 74 control.addClass('has-value'); 75 } else { 76 control.removeClass('has-value'); 102 // select2 103 if( this.get('ui') ) { 104 105 // populate ajax_data (allowing custom attribute to already exist) 106 var ajaxAction = this.get('ajax_action'); 107 if( !ajaxAction ) { 108 ajaxAction = 'acf/fields/' + this.get('type') + '/query'; 109 } 110 111 // select2 112 this.select2 = []; 113 this.$('.acf-post-object select').each(function() { 114 self.select2.push(acf.newSelect2(self.$(this), { 115 field: self, 116 ajax: self.get('ajax'), 117 multiple: self.get('multiple'), 118 placeholder: self.get('placeholder'), 119 allowNull: self.get('allow_null'), 120 ajaxAction: ajaxAction, 121 })); 122 }); 77 123 } 78 124 }, 125 126 onRemove: function(){ 127 if( this.select2 ) { 128 for (var i=0; i < this.select2.length; i++) { 129 this.select2[i].destroy(); 130 } 131 } 132 } 79 133 })); 134 135 136 acf.registerFieldType(acf.models.UrlField.extend({ 137 type: 'qtranslate_url', 138 139 $control: function(){ 140 return this.$('.acf-input-wrap.current-language'); 141 }, 142 143 $input: function(){ 144 return this.$('.acf-input-wrap.current-language input[type="url"]'); 145 } 146 })); 147 80 148 81 149 acf.registerFieldType(acf.models.WysiwygField.extend({ 82 150 type: 'qtranslate_wysiwyg', 151 83 152 initializeEditor: function() { 84 153 var self = this; … … 115 184 })); 116 185 117 acf.registerFieldType(acf.models.UrlField.extend({118 type: 'qtranslate_url',119 $control: function(){120 return this.$('.acf-input-wrap.current-language');121 },122 123 $input: function(){124 return this.$('.acf-input-wrap.current-language input[type="url"]');125 },126 isValid: function(){127 128 // vars129 var val = this.val();130 131 // bail early if no val132 if( !val ) {133 return false;134 }135 136 // url137 if( val.indexOf('://') !== -1 ) {138 return true;139 }140 141 // protocol relative url142 if( val.indexOf('//') === 0 ) {143 return true;144 }145 146 // relative url147 if( val.indexOf('/') === 0 ) {148 return true;149 }150 151 // return152 return false;153 },154 155 render: function(){156 157 // add class158 if( this.isValid() ) {159 this.$control().addClass('-valid');160 } else {161 this.$control().removeClass('-valid');162 }163 },164 })); -
acf-qtranslate/trunk/assets/acf_5/qtranslatex.js
r1536246 r1963238 1 1 2 2 (function(){ 3 3 4 var windowLoadCompleted = false; 4 5 jQuery(window).load(function() { … … 89 90 // however ACF removes the elements from the DOM early so 90 91 // we must hook into handler and perform updates there 91 var _hooked_repeater_remove = acf.fields.repeater.remove; 92 acf.fields.repeater.remove = function($el) { 92 var repeaterFieldRemove; 93 94 if (acf.models) { 95 repeaterFieldRemove = acf.models.RepeaterField.prototype.remove; 96 } else { 97 repeaterFieldRemove = acf.fields.repeater.remove; 98 } 99 100 function repeaterRemove($el) { 93 101 var row = ($el.$el || $el).closest('.acf-row'); // support old versions of ACF5PRO as well 94 102 row.find(_.toArray(field_types).join(',')).filter('.qtranxs-translatable').each(function() { … … 96 104 }); 97 105 // call the original handler 98 _hooked_repeater_remove.call(this, $el);106 repeaterFieldRemove.call(this, $el); 99 107 }; 100 101 108 }); 102 109 -
acf-qtranslate/trunk/assets/common.css
r1948002 r1963238 36 36 border: 1px solid #ededed; 37 37 margin-left: -1px; 38 padding: 6px 7px;39 38 text-transform: uppercase; 40 39 cursor: pointer 40 } 41 42 .multi-language-field > .wp-switch-editor:last-of-type { 43 margin-left: 5px; 41 44 } 42 45 … … 68 71 .multi-language-field > fieldset, 69 72 .multi-language-field .acf_wysiwyg, 70 .multi-language-field .acf- url,73 .multi-language-field .acf-post-object, 71 74 .multi-language-field .acf-editor-wrap, 72 75 .multi-language-field .acf-file-uploader, 73 .multi-language-field .acf-image-uploader { display: none } 76 .multi-language-field .acf-image-uploader, 77 .multi-language-field .acf-url > input { display: none } 74 78 75 79 .multi-language-field .acf_input input, … … 81 85 } 82 86 83 .acf-input .acf-url input[type="text"] { 84 padding-left: 25px; 87 .multi-language-field .acf-url { 88 position: relative; 89 clear: both; 85 90 } 86 91 … … 106 111 border-bottom-color: #f5f5f5; 107 112 } 113 114 .multi-language-field-post-object .select2-container--default .select2-selection--multiple, 115 .multi-language-field-post-object .select2-container--default.select2-container--focus .select2-selection--multiple { 116 border-color: #ddd; 117 border-radius: 0; 118 } -
acf-qtranslate/trunk/readme.txt
r1948002 r1963238 3 3 Tags: acf, advanced custom fields, qtranslate, add-on, admin 4 4 Requires at least: 3.5.0 5 Tested up to: 4. 7.26 Version: 1.7.2 47 Stable tag: 1.7.2 45 Tested up to: 4.9.8 6 Version: 1.7.25 7 Stable tag: 1.7.25 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 55 55 56 56 == Changelog == 57 58 = 1.7.25 = 59 * Core: Added qTranslate suffix to field labels 60 * Core: (asedano) Added ACF5 support for Post Object field 61 * Bug Fix: Fixed issue with File fields 57 62 58 63 = 1.7.24 = … … 189 194 == Upgrade Notice == 190 195 191 Bug Fix: Fixed issue with saving File and Image fields after ACF 5.5.5 upgrade196 Bug Fix: Fixed issue with File fields -
acf-qtranslate/trunk/src/acf_5/acf.php
r1948002 r1963238 30 30 require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/file.php'; 31 31 require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/image.php'; 32 require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/post_object.php'; 32 33 require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/text.php'; 33 34 require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/textarea.php'; 35 require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/url.php'; 34 36 require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/wysiwyg.php'; 35 require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/url.php';36 37 38 acf()->fields->register_field_type(new acf_qtranslate_acf_5_file($this->plugin)); 39 acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin)); 40 acf()->fields->register_field_type(new acf_qtranslate_acf_5_post_object($this->plugin)); 37 41 acf()->fields->register_field_type(new acf_qtranslate_acf_5_text($this->plugin)); 38 42 acf()->fields->register_field_type(new acf_qtranslate_acf_5_textarea($this->plugin)); 43 acf()->fields->register_field_type(new acf_qtranslate_acf_5_url($this->plugin)); 39 44 acf()->fields->register_field_type(new acf_qtranslate_acf_5_wysiwyg($this->plugin)); 40 acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin));41 acf()->fields->register_field_type(new acf_qtranslate_acf_5_file($this->plugin));42 acf()->fields->register_field_type(new acf_qtranslate_acf_5_url($this->plugin));43 45 } 44 46 … … 57 59 if (is_string($value)) { 58 60 $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value); 61 $value = maybe_unserialize($value); 59 62 } 63 60 64 return $value; 61 65 } … … 100 104 'qtranslate_file', 101 105 'qtranslate_image', 106 'qtranslate_post_object', 102 107 'qtranslate_text', 103 108 'qtranslate_textarea', 104 'qtranslate_wysiwyg' 109 'qtranslate_url', 110 'qtranslate_wysiwyg', 105 111 ); 106 112 -
acf-qtranslate/trunk/src/acf_5/fields/file.php
r1708392 r1963238 48 48 // vars 49 49 $this->name = 'qtranslate_file'; 50 $this->label = __("File ",'acf');50 $this->label = __("File (qTranslate)",'acf'); 51 51 $this->category = __("qTranslate", 'acf'); 52 52 $this->defaults = array( -
acf-qtranslate/trunk/src/acf_5/fields/image.php
r1708392 r1963238 9 9 protected $plugin; 10 10 11 11 12 /* 12 13 * __construct … … 32 33 33 34 /* 34 * __construct 35 * 36 * This function will setup the field type data 37 * 38 * @type function 39 * @date 5/03/2014 40 * @since 5.0.0 41 * 42 * @param n/a 43 * @return n/a 44 */ 45 35 * __construct 36 * 37 * This function will setup the field type data 38 * 39 * @type function 40 * @date 5/03/2014 41 * @since 5.0.0 42 * 43 * @param n/a 44 * @return n/a 45 */ 46 46 function initialize() { 47 47 48 48 // vars 49 49 $this->name = 'qtranslate_image'; 50 $this->label = __("Image ",'acf');50 $this->label = __("Image (qTranslate)",'acf'); 51 51 $this->category = __("qTranslate", 'acf'); 52 52 $this->defaults = array( -
acf-qtranslate/trunk/src/acf_5/fields/text.php
r1948002 r1963238 48 48 // vars 49 49 $this->name = 'qtranslate_text'; 50 $this->label = __("Text ",'acf');50 $this->label = __("Text (qTranslate)",'acf'); 51 51 $this->category = __("qTranslate",'acf'); 52 52 $this->defaults = array( -
acf-qtranslate/trunk/src/acf_5/fields/textarea.php
r1948002 r1963238 48 48 // vars 49 49 $this->name = 'qtranslate_textarea'; 50 $this->label = __("Text Area ",'acf');50 $this->label = __("Text Area (qTranslate)",'acf'); 51 51 $this->category = __("qTranslate",'acf'); 52 52 $this->defaults = array( -
acf-qtranslate/trunk/src/acf_5/fields/url.php
r1948002 r1963238 1 1 <?php 2 2 3 class acf_qtranslate_acf_5_url extends acf_qtranslate_acf_5_text { 3 class acf_qtranslate_acf_5_url extends acf_field_url { 4 5 /** 6 * The plugin instance. 7 * @var \acf_qtranslate\plugin 8 */ 9 protected $plugin; 10 11 12 /* 13 * __construct 14 * 15 * This function will setup the field type data 16 * 17 * @type function 18 * @date 5/03/2014 19 * @since 5.0.0 20 * 21 * @param n/a 22 * @return n/a 23 */ 24 function __construct($plugin) { 25 $this->plugin = $plugin; 26 27 if (version_compare($plugin->acf_version(), '5.6.0') < 0) { 28 $this->initialize(); 29 } 30 31 acf_field::__construct(); 32 } 33 34 /* 35 * initialize 36 * 37 * This function will setup the field type data 38 * 39 * @type function 40 * @date 5/03/2014 41 * @since 5.0.0 42 * 43 * @param n/a 44 * @return n/a 45 */ 4 46 function initialize() { 5 47 6 48 // vars 7 49 $this->name = 'qtranslate_url'; 8 $this->label = __("Url ",'acf');50 $this->label = __("Url (qTranslate)",'acf'); 9 51 $this->category = __("qTranslate",'acf'); 10 52 $this->defaults = array( 11 53 'default_value' => '', 12 'maxlength' => '',13 54 'placeholder' => '', 14 'prepend' => '',15 'append' => ''16 55 ); 17 56 … … 36 75 37 76 // vars 38 $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' ); 39 $s = array( 'readonly', 'disabled' ); 40 $e = ''; 77 $atts = array(); 78 $keys = array( 'type', 'id', 'class', 'name', 'value', 'placeholder', 'pattern' ); 79 $keys2 = array( 'readonly', 'disabled', 'required' ); 80 $html = ''; 41 81 42 // maxlength 43 if( $field['maxlength'] !== "" ) { 44 $o[] = 'maxlength'; 82 83 // atts (value="123") 84 foreach( $keys as $k ) { 85 if( isset($field[ $k ]) ) $atts[ $k ] = $field[ $k ]; 45 86 } 46 87 47 // populate atts 48 $atts = array();49 foreach( $ oas $k ) {50 $atts[ $k ] = $field[ $k ];88 89 // atts2 (disabled="disabled") 90 foreach( $keys2 as $k ) { 91 if( !empty($field[ $k ]) ) $atts[ $k ] = $k; 51 92 } 52 93 53 // special atts 54 foreach( $s as $k ) { 55 if( isset($field[ $k ]) && $field[ $k ] ) { 56 $atts[ $k ] = $k; 57 } 58 } 94 95 // remove empty atts 96 $atts = acf_clean_atts( $atts ); 97 59 98 60 99 // render 61 $ e .= '<div class="acf-url-wrap multi-language-field">';100 $html .= '<div class="acf-input-wrap multi-language-field">'; 62 101 63 102 foreach ($languages as $language) { 64 103 $class = ($language === $currentLanguage) ? 'wp-switch-editor current-language' : 'wp-switch-editor'; 65 $ e.= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';104 $html .= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; 66 105 } 106 107 $html .= '<div class="acf-url">'; 108 $html .= '<i class="acf-icon -globe -small"></i>'; 67 109 68 110 foreach ($languages as $language) { 69 111 $atts['class'] = $field['class']; 70 71 $atts['type'] = 'text'; 112 if ($language === $currentLanguage) { 113 $atts['class'] .= ' current-language'; 114 } 115 $atts['type'] = 'url'; 72 116 $atts['name'] = $field['name'] . "[$language]"; 73 117 $atts['value'] = $values[$language]; 74 75 $container_class = 'acf-input-wrap acf-url'; 76 if ($language === $currentLanguage) { 77 $container_class .= ' current-language'; 78 } 79 80 $e .= '<div class="' . $container_class . '" data-language="' . $language . '">'; 81 $e .= '<i class="acf-icon -globe -small"></i>'; 82 $e .= '<input ' . acf_esc_attr( $atts ) . ' />'; 83 $e .= '</div>'; 84 118 $atts['data-language'] = $language; 119 $html .= acf_get_text_input( $atts ); 85 120 } 86 121 87 $e .= '</div>'; 122 $html .= '</div>'; 123 $html .= '</div>'; 88 124 89 125 // return 90 echo $ e;126 echo $html; 91 127 } 92 128 93 function validate_value( $valid, $value, $field, $input ){ 94 foreach ($value as $valor) { 95 // bail early if empty 96 if ( empty( $valor ) ) { 129 /* 130 * update_value() 131 * 132 * This filter is appied to the $value before it is updated in the db 133 * 134 * @type filter 135 * @since 3.6 136 * @date 23/01/13 137 * 138 * @param $value - the value which will be saved in the database 139 * @param $post_id - the $post_id of which the value will be saved 140 * @param $field - the field array holding all the field options 141 * 142 * @return $value - the modified value 143 */ 144 function update_value($value, $post_id, $field) { 145 return qtrans_join($value); 146 } 97 147 98 continue;99 100 }101 102 if ( strpos( $valor, '://' ) !== false ) {103 104 // url105 106 } elseif ( strpos( $valor, '//' ) === 0 ) {107 108 // protocol relative url109 110 } elseif ( strpos( $valor, '/' ) === 0 ) {111 112 // relative url113 114 } else {115 116 $valid = __( 'Value must be a valid URL', 'acf' );117 118 }119 }120 121 // return122 return $valid;123 }124 148 } -
acf-qtranslate/trunk/src/acf_5/fields/wysiwyg.php
r1948002 r1963238 50 50 // vars 51 51 $this->name = 'qtranslate_wysiwyg'; 52 $this->label = __("Wysiwyg Editor ",'acf');52 $this->label = __("Wysiwyg Editor (qTranslate)",'acf'); 53 53 $this->category = __("qTranslate",'acf'); 54 54 $this->defaults = array(
Note: See TracChangeset
for help on using the changeset viewer.