Make WordPress Core

Changeset 31734


Ignore:
Timestamp:
03/11/2015 10:54:49 PM (11 years ago)
Author:
pento
Message:

Add emoji URL support, and Twemoji fallback for displaying slugs in wp-admin, when the browser doesn't natively support emoji.

Props pento, SergeyBiryukov and boonebgorges.

Fixes #31328

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/inline-edit-post.js

    r31690 r31734  
    118118
    119119        edit : function(id) {
    120                 var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, cur_format, f;
     120                var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, cur_format, f, val;
    121121                t.revert();
    122122
     
    156156
    157157                for ( f = 0; f < fields.length; f++ ) {
    158                         $(':input[name="' + fields[f] + '"]', editRow).val( $('.'+fields[f], rowData).text() );
     158                        val = $('.'+fields[f], rowData);
     159                        // Deal with Twemoji
     160                        val.find( 'img' ).replaceWith( function() { return this.alt; } );
     161                        val = val.text();
     162                        $(':input[name="' + fields[f] + '"]', editRow).val( val );
    159163                }
    160164
     
    182186                //flat taxonomies
    183187                $('.tags_input', rowData).each(function(){
    184                         var terms = $(this).text(),
     188                        var terms = $(this),
    185189                                taxname = $(this).attr('id').replace('_' + id, ''),
    186190                                textarea = $('textarea.tax_input_' + taxname, editRow),
    187191                                comma = inlineEditL10n.comma;
     192
     193                        terms.find( 'img' ).replaceWith( function() { return this.alt; } );
     194                        terms = terms.text();
    188195
    189196                        if ( terms ) {
     
    266273                                                $(inlineEditPost.what+id).siblings('tr.hidden').addBack().remove();
    267274                                                $('#edit-'+id).before(r).remove();
     275                                                if ( WPEmoji ) {
     276                                                        WPEmoji.parse( $( inlineEditPost.what + id ).get( 0 ) );
     277                                                }
    268278                                                $(inlineEditPost.what+id).hide().fadeIn();
    269279                                        } else {
  • trunk/src/wp-admin/js/inline-edit-tax.js

    r31288 r31734  
    4646
    4747        edit : function(id) {
    48                 var editRow, rowData,
     48                var editRow, rowData, val,
    4949                        t = this;
    5050                t.revert();
     
    5959                $(t.what+id).hide().before(editRow).before('<tr class="hidden"></tr>');
    6060
    61                 $(':input[name="name"]', editRow).val( $('.name', rowData).text() );
    62                 $(':input[name="slug"]', editRow).val( $('.slug', rowData).text() );
     61                val = $('.name', rowData);
     62                val.find( 'img' ).replaceWith( function() { return this.alt; } );
     63                val = val.text();
     64                $(':input[name="name"]', editRow).val( val );
     65
     66                val = $('.slug', rowData);
     67                val.find( 'img' ).replaceWith( function() { return this.alt; } );
     68                val = val.text();
     69                $(':input[name="slug"]', editRow).val( val );
    6370
    6471                $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
     
    111118                                                $( '#parent' ).find( 'option[value=' + option_value + ']' ).text( row.find( '.row-title' ).text() );
    112119
     120                                                if ( WPEmoji ) {
     121                                                        WPEmoji.parse( row.get( 0 ) );
     122                                                }
     123
    113124                                                row.hide().fadeIn();
    114125                                        } else {
  • trunk/src/wp-admin/js/post.js

    r31538 r31734  
    713713                        b = $('#edit-slug-buttons'),
    714714                        revert_b = b.html(),
    715                         full = $('#editable-post-name-full').html();
     715                        full = $('#editable-post-name-full');
     716
     717                // Deal with Twemoji in the post-name
     718                full.find( 'img' ).replaceWith( function() { return this.alt; } );
     719                full = full.html();
    716720
    717721                $('#view-post-btn').hide();
     
    737741                                        });
    738742                                }
     743
     744                                if ( WPEmoji ) {
     745                                        WPEmoji.parse( box.get( 0 ) );
     746                                }
     747
    739748                                b.html(revert_b);
    740749                                real_slug.val(new_slug);
  • trunk/src/wp-admin/js/tags.js

    r26198 r31734  
    5050                                $( '.tags' ).prepend( res.responses[0].supplemental.parents ); // As the parent is not visible, Insert the version with Parent - Child - ThisTerm
    5151
     52                        if ( WPEmoji ) {
     53                                WPEmoji.parse( $( '.tags' ).get( 0 ) );
     54                        }
     55
    5256                        $('.tags .no-items').remove();
    5357
  • trunk/src/wp-includes/formatting.php

    r31733 r31734  
    786786                        $unicode_length++;
    787787                } else {
    788                         if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
     788                        if ( count( $values ) == 0 ) {
     789                                if ( $value < 224 ) {
     790                                        $num_octets = 2;
     791                                } elseif ( $value < 240 ) {
     792                                        $num_octets = 3;
     793                                } else {
     794                                        $num_octets = 4;
     795                                }
     796                        }
    789797
    790798                        $values[] = $value;
     
    793801                                break;
    794802                        if ( count( $values ) == $num_octets ) {
    795                                 if ($num_octets == 3) {
    796                                         $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
    797                                         $unicode_length += 9;
    798                                 } else {
    799                                         $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
    800                                         $unicode_length += 6;
     803                                for ( $j = 0; $j < $num_octets; $j++ ) {
     804                                        $unicode .= '%' . dechex( $values[ $j ] );
    801805                                }
     806
     807                                $unicode_length += $num_octets * 3;
    802808
    803809                                $values = array();
  • trunk/src/wp-includes/taxonomy.php

    r31652 r31734  
    28802880        $slug_provided = ! empty( $args['slug'] );
    28812881        if ( ! $slug_provided ) {
    2882                 $_name = trim( $name );
    2883                 $existing_term = get_term_by( 'name', $_name, $taxonomy );
    2884                 if ( $existing_term ) {
    2885                         $slug = $existing_term->slug;
    2886                 } else {
    2887                         $slug = sanitize_title( $name );
    2888                 }
     2882                $slug = sanitize_title( $name );
    28892883        } else {
    28902884                $slug = $args['slug'];
     
    29112905
    29122906        // Terms with duplicate names are not allowed at the same level of a taxonomy hierarchy.
    2913         if ( $exists = term_exists( $slug, $taxonomy ) ) {
    2914                 $existing_term = get_term( $exists['term_id'], $taxonomy );
    2915 
    2916                 if ( $name === $existing_term->name ) {
    2917 
    2918                         if ( is_taxonomy_hierarchical( $taxonomy ) ) {
    2919                                 $siblings = get_terms( $taxonomy, array( 'fields' => 'names', 'get' => 'all', 'parent' => $parent ) );
    2920                                 if ( in_array( $name, $siblings ) ) {
    2921                                         return new WP_Error( 'term_exists', __( 'A term with the name and slug already exists with this parent.' ), $exists['term_id'] );
    2922                                 }
    2923 
    2924                         } else {
    2925                                 return new WP_Error( 'term_exists', __( 'A term with the name and slug already exists in this taxonomy.' ), $exists['term_id'] );
     2907        if ( $existing_term = get_term_by( 'name', $name, $taxonomy ) ) {
     2908                if ( is_taxonomy_hierarchical( $taxonomy ) ) {
     2909                        $siblings = get_terms( $taxonomy, array( 'fields' => 'names', 'get' => 'all', 'parent' => $parent ) );
     2910                        if ( in_array( $name, $siblings ) ) {
     2911                                return new WP_Error( 'term_exists', __( 'A term with the name already exists with this parent.' ), $existing_term->term_id );
    29262912                        }
     2913                } else {
     2914                        return new WP_Error( 'term_exists', __( 'A term with the name already exists in this taxonomy.' ), $existing_term->term_id );
    29272915                }
    29282916        }
  • trunk/tests/phpunit/data/formatting/utf-8/entitized.txt

    r25002 r31734  
    44&#66;&#106;&#246;&#114;&#107;&#32;&#71;&#117;&#240;&#109;&#117;&#110;&#100;&#115;&#100;&#243;&#116;&#116;&#105;&#114;
    55&#23470;&#23822;&#12288;&#39423;
     6&#128077;
  • trunk/tests/phpunit/data/formatting/utf-8/u-urlencoded.txt

    r25002 r31734  
    44%u0042%u006A%u00F6%u0072%u006B%u0020%u0047%u0075%u00F0%u006D%u0075%u006E%u0064%u0073%u0064%u00F3%u0074%u0074%u0069%u0072
    55%u5BAE%u5D0E%u3000%u99FF
     6%u1F44D
  • trunk/tests/phpunit/data/formatting/utf-8/urlencoded.txt

    r25002 r31734  
    44Bj%c3%b6rk Gu%c3%b0mundsd%c3%b3ttir
    55%e5%ae%ae%e5%b4%8e%e3%80%80%e9%a7%bf
     6%f0%9f%91%8d
  • trunk/tests/phpunit/data/formatting/utf-8/utf-8.txt

    r25002 r31734  
    44Björk Guðmundsdóttir
    55宮崎 駿
     6👍
  • trunk/tests/phpunit/tests/formatting/UrlEncodedToEntities.php

    r25002 r31734  
    99         */
    1010        function test_convert_urlencoded_to_entities( $u_urlencoded, $entity ) {
    11                 $this->assertEquals( $entity, preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $u_urlencoded ), $entity );
     11                $this->assertEquals( $entity, preg_replace_callback('/\%u([0-9A-F]{4,5})/', '_convert_urlencoded_to_entities', $u_urlencoded ), $entity );
    1212        }
    1313
  • trunk/tests/phpunit/tests/term.php

    r31418 r31734  
    175175                // Test existing term name with unique slug
    176176                $term1 = $this->factory->tag->create( array( 'name' => 'Bozo', 'slug' => 'bozo1' ) );
    177                 $this->assertFalse( is_wp_error( $term1 ) );
    178                 $this->assertTrue( empty($term1->errors ) );
     177                $this->assertTrue( is_wp_error( $term1 ) );
     178                $this->assertSame( 'term_exists', $term1->get_error_code() );
     179                $this->assertEquals( $term->term_id, $term1->get_error_data() );
    179180
    180181                // Test an existing term name
Note: See TracChangeset for help on using the changeset viewer.