Plugin Directory

Changeset 1963238


Ignore:
Timestamp:
10/26/2018 03:18:38 AM (7 years ago)
Author:
funkjedi
Message:

Syncing with Github

Location:
acf-qtranslate/trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • acf-qtranslate/trunk/acf-qtranslate.php

    r1948002 r1963238  
    44Plugin URI: http://github.com/funkjedi/acf-qtranslate
    55Description: Provides multilingual versions of the text, text area, and wysiwyg fields.
    6 Version: 1.7.24
     6Version: 1.7.25
    77Author: funkjedi
    88Author 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
     3acf.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
    447acf.registerFieldType(acf.models.ImageField.extend({
    548  type: 'qtranslate_image',
     
    1457
    1558  render: function( attachment ){
    16     var control = this.$control();
    1759
    1860    // vars
     
    2062
    2163    // update image
    22     control.find('img').attr({
     64    this.$control().find('img').attr({
    2365      src: attachment.url,
    2466      alt: attachment.alt,
     
    3476    // update class
    3577    if( val ) {
    36       control.addClass('has-value');
     78      this.$control().addClass('has-value');
    3779    } else {
    38       control.removeClass('has-value');
     80      this.$control().removeClass('has-value');
    3981    }
    4082  }
    4183}));
    4284
    43 /**
    44  * Clone functionality from standard File field type
    45  */
    46 acf.registerFieldType(acf.models.QtranslateImageField.extend({
    47   type: 'qtranslate_file',
    48   render: function( attachment ){
    49     var control = this.$control();
    50    
    51     // vars
    52     attachment = this.validateAttachment( attachment );
    5385
    54     // update image
    55     this.$control().find(' img').attr({
    56       src: attachment.icon,
    57       alt: attachment.alt,
    58       title: attachment.title
    59     });
     86acf.registerFieldType(acf.models.PostObjectField.extend({
     87  type: 'qtranslate_post_object',
    6088
    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;
    6595
    6696    // vars
    67     var val = attachment.id || '';
     97    var $select = this.$input();
    6898
    69     // update val
    70     acf.val( this.$input(), val );
     99    // inherit data
     100    this.inherit( $select );
    71101
    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      });
    77123    }
    78124  },
     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  }
    79133}));
     134
     135
     136acf.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
    80148
    81149acf.registerFieldType(acf.models.WysiwygField.extend({
    82150  type: 'qtranslate_wysiwyg',
     151
    83152  initializeEditor: function() {
    84153    var self = this;
     
    115184}));
    116185
    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     // vars
    129     var val = this.val();
    130 
    131     // bail early if no val
    132     if( !val ) {
    133       return false;
    134     }
    135 
    136     // url
    137     if( val.indexOf('://') !== -1 ) {
    138       return true;
    139     }
    140 
    141     // protocol relative url
    142     if( val.indexOf('//') === 0 ) {
    143       return true;
    144     }
    145 
    146     // relative url
    147     if( val.indexOf('/') === 0 ) {
    148       return true;
    149     }
    150 
    151     // return
    152     return false;
    153   },
    154 
    155   render: function(){
    156 
    157     // add class
    158     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  
    11
    22(function(){
     3
    34    var windowLoadCompleted = false;
    45    jQuery(window).load(function() {
     
    8990        // however ACF removes the elements from the DOM early so
    9091        // 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) {
    93101            var row = ($el.$el || $el).closest('.acf-row'); // support old versions of ACF5PRO as well
    94102            row.find(_.toArray(field_types).join(',')).filter('.qtranxs-translatable').each(function() {
     
    96104            });
    97105            // call the original handler
    98             _hooked_repeater_remove.call(this, $el);
     106            repeaterFieldRemove.call(this, $el);
    99107        };
    100 
    101108    });
    102109
  • acf-qtranslate/trunk/assets/common.css

    r1948002 r1963238  
    3636    border: 1px solid #ededed;
    3737    margin-left: -1px;
    38     padding: 6px 7px;
    3938    text-transform: uppercase;
    4039    cursor: pointer
     40}
     41
     42.multi-language-field > .wp-switch-editor:last-of-type {
     43    margin-left: 5px;
    4144}
    4245
     
    6871.multi-language-field > fieldset,
    6972.multi-language-field .acf_wysiwyg,
    70 .multi-language-field .acf-url,
     73.multi-language-field .acf-post-object,
    7174.multi-language-field .acf-editor-wrap,
    7275.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 }
    7478
    7579.multi-language-field .acf_input input,
     
    8185}
    8286
    83 .acf-input .acf-url input[type="text"] {
    84     padding-left: 25px;
     87.multi-language-field .acf-url {
     88    position: relative;
     89    clear: both;
    8590}
    8691
     
    106111    border-bottom-color: #f5f5f5;
    107112}
     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  
    33Tags: acf, advanced custom fields, qtranslate, add-on, admin
    44Requires at least: 3.5.0
    5 Tested up to: 4.7.2
    6 Version: 1.7.24
    7 Stable tag: 1.7.24
     5Tested up to: 4.9.8
     6Version: 1.7.25
     7Stable tag: 1.7.25
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5555
    5656== 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
    5762
    5863= 1.7.24 =
     
    189194== Upgrade Notice ==
    190195
    191 Bug Fix: Fixed issue with saving File and Image fields after ACF 5.5.5 upgrade
     196Bug Fix: Fixed issue with File fields
  • acf-qtranslate/trunk/src/acf_5/acf.php

    r1948002 r1963238  
    3030        require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/file.php';
    3131        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';
    3233        require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/text.php';
    3334        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';
    3436        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';
    3637
     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));
    3741        acf()->fields->register_field_type(new acf_qtranslate_acf_5_text($this->plugin));
    3842        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));
    3944        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));
    4345    }
    4446
     
    5759        if (is_string($value)) {
    5860            $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
     61            $value = maybe_unserialize($value);
    5962        }
     63
    6064        return $value;
    6165    }
     
    100104            'qtranslate_file',
    101105            'qtranslate_image',
     106            'qtranslate_post_object',
    102107            'qtranslate_text',
    103108            'qtranslate_textarea',
    104             'qtranslate_wysiwyg'
     109            'qtranslate_url',
     110            'qtranslate_wysiwyg',
    105111        );
    106112
  • acf-qtranslate/trunk/src/acf_5/fields/file.php

    r1708392 r1963238  
    4848        // vars
    4949        $this->name = 'qtranslate_file';
    50         $this->label = __("File",'acf');
     50        $this->label = __("File (qTranslate)",'acf');
    5151        $this->category = __("qTranslate", 'acf');
    5252        $this->defaults = array(
  • acf-qtranslate/trunk/src/acf_5/fields/image.php

    r1708392 r1963238  
    99    protected $plugin;
    1010
     11
    1112    /*
    1213     *  __construct
     
    3233
    3334    /*
    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     */
    4646    function initialize() {
    4747
    4848        // vars
    4949        $this->name = 'qtranslate_image';
    50         $this->label = __("Image",'acf');
     50        $this->label = __("Image (qTranslate)",'acf');
    5151        $this->category = __("qTranslate", 'acf');
    5252        $this->defaults = array(
  • acf-qtranslate/trunk/src/acf_5/fields/text.php

    r1948002 r1963238  
    4848        // vars
    4949        $this->name = 'qtranslate_text';
    50         $this->label = __("Text",'acf');
     50        $this->label = __("Text (qTranslate)",'acf');
    5151        $this->category = __("qTranslate",'acf');
    5252        $this->defaults = array(
  • acf-qtranslate/trunk/src/acf_5/fields/textarea.php

    r1948002 r1963238  
    4848        // vars
    4949        $this->name = 'qtranslate_textarea';
    50         $this->label = __("Text Area",'acf');
     50        $this->label = __("Text Area (qTranslate)",'acf');
    5151        $this->category = __("qTranslate",'acf');
    5252        $this->defaults = array(
  • acf-qtranslate/trunk/src/acf_5/fields/url.php

    r1948002 r1963238  
    11<?php
    22
    3 class acf_qtranslate_acf_5_url extends acf_qtranslate_acf_5_text {
     3class 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     */
    446    function initialize() {
    547
    648        // vars
    749        $this->name = 'qtranslate_url';
    8         $this->label = __("Url",'acf');
     50        $this->label = __("Url (qTranslate)",'acf');
    951        $this->category = __("qTranslate",'acf');
    1052        $this->defaults = array(
    1153            'default_value' => '',
    12             'maxlength'     => '',
    1354            'placeholder'   => '',
    14             'prepend'       => '',
    15             'append'        => ''
    1655        );
    1756
     
    3675
    3776        // 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 = '';
    4181
    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 ];
    4586        }
    4687
    47         // populate atts
    48         $atts = array();
    49         foreach( $o as $k ) {
    50             $atts[ $k ] = $field[ $k ];
     88
     89        // atts2 (disabled="disabled")
     90        foreach( $keys2 as $k ) {
     91            if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
    5192        }
    5293
    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
    5998
    6099        // render
    61         $e .= '<div class="acf-url-wrap multi-language-field">';
     100        $html .= '<div class="acf-input-wrap multi-language-field">';
    62101
    63102        foreach ($languages as $language) {
    64103            $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>';
    66105        }
     106
     107        $html .= '<div class="acf-url">';
     108        $html .= '<i class="acf-icon -globe -small"></i>';
    67109
    68110        foreach ($languages as $language) {
    69111            $atts['class'] = $field['class'];
    70 
    71             $atts['type'] = 'text';
     112            if ($language === $currentLanguage) {
     113                $atts['class'] .= ' current-language';
     114            }
     115            $atts['type'] = 'url';
    72116            $atts['name'] = $field['name'] . "[$language]";
    73117            $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 );
    85120        }
    86121
    87         $e .= '</div>';
     122        $html .= '</div>';
     123        $html .= '</div>';
    88124
    89125        // return
    90         echo $e;
     126        echo $html;
    91127    }
    92128
    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    }
    97147
    98                 continue;
    99 
    100             }
    101 
    102             if ( strpos( $valor, '://' ) !== false ) {
    103 
    104                 // url
    105 
    106             } elseif ( strpos( $valor, '//' ) === 0 ) {
    107 
    108                 // protocol relative url
    109 
    110             } elseif ( strpos( $valor, '/' ) === 0 ) {
    111 
    112                 // relative url
    113 
    114             } else {
    115 
    116                 $valid = __( 'Value must be a valid URL', 'acf' );
    117 
    118             }
    119         }
    120 
    121         // return
    122         return $valid;
    123     }
    124148}
  • acf-qtranslate/trunk/src/acf_5/fields/wysiwyg.php

    r1948002 r1963238  
    5050        // vars
    5151        $this->name = 'qtranslate_wysiwyg';
    52         $this->label = __("Wysiwyg Editor",'acf');
     52        $this->label = __("Wysiwyg Editor (qTranslate)",'acf');
    5353        $this->category = __("qTranslate",'acf');
    5454        $this->defaults = array(
Note: See TracChangeset for help on using the changeset viewer.