Skip to content

Commit

Permalink
Version 1.0.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
gitlost committed Jan 17, 2017
1 parent fa6d985 commit 082f791
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 178 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ php:
env:
- WP_VERSION=nightly
- WP_VERSION=latest
- WP_VERSION=4.7
- WP_VERSION=4.6.1
- WP_VERSION=4.5.4
- WP_VERSION=4.4.5
Expand All @@ -25,8 +26,6 @@ env:

matrix:
exclude:
- php: 7.1
env: WP_VERSION=latest
- php: 7.1
env: WP_VERSION=4.6.1
- php: 7.1
Expand Down Expand Up @@ -63,9 +62,9 @@ before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION

script:
- PHPRC=. WP_TESTS_DIR=/tmp/wordpress-tests-lib phpunit
- PHPRC=. WP_TESTS_DIR=/tmp/wordpress-tests-lib phpunit --verbose

after_success:
- if [[ ( $TRAVIS_PHP_VERSION = '7' || $TRAVIS_PHP_VERSION > '7' ) && $WP_VERSION = 'latest' ]] then
- if [[ $TRAVIS_PHP_VERSION = '7.1' && $WP_VERSION = 'latest' ]] then
- PHPRC=. WP_TESTS_DIR=/tmp/wordpress-tests-lib phpunit --coverage-clover clover.xml && bash <(curl -s https://codecov.io/bash)
- fi
54 changes: 25 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,42 @@
**Contributors:** [gitlost](https://profiles.wordpress.org/gitlost), [zodiac1978](https://profiles.wordpress.org/zodiac1978)
**Tags:** Unicode, Normalization, Form C, Unicode Normalization Form C, Normalize, Normalizer, UTF-8, NFC
**Requires at least:** 3.9.13
**Tested up to:** 4.7.0
**Stable tag:** 1.0.5
**Tested up to:** 4.7.1
**Stable tag:** 1.0.6
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Normalizes UTF-8 input to Normalization Form C.

## Description ##

This is a souped-up version of the [Normalizer plugin](https://wordpress.org/plugins/normalizer/ "Normalizer - WordPress Plugins") by
[Torsten Landsiedel](https://profiles.wordpress.org/zodiac1978/).
This is a souped-up version of the [Normalizer plugin](https://wordpress.org/plugins/normalizer/ "Normalizer - WordPress Plugins") by [Torsten Landsiedel](https://profiles.wordpress.org/zodiac1978/).

It adds WP filters to normalize UTF-8 data coming into the system to the
[de facto web standard Normalization Form C](https://www.w3.org/International/docs/charmod-norm/#choice-of-normalization-form "Choice of Normalization Form").
The Unicode Consortium report is at [Unicode Normalization Forms](http://www.unicode.org/reports/tr15/).
It adds WP filters to normalize UTF-8 data coming into the system to the [de facto web standard Normalization Form C](https://www.w3.org/International/docs/charmod-norm/#choice-of-normalization-form "Choice of Normalization Form"). The Unicode Consortium report is at [Unicode Normalization Forms](http://www.unicode.org/reports/tr15/).

### Polyfills ###

For best performance [install](http://php.net/manual/en/intl.installation.php) (if possible)
the [PHP Internationalization extension `Intl`](http://php.net/manual/en/intro.intl.php),
which includes the PHP class `Normalizer`.
For best performance [install](http://php.net/manual/en/intl.installation.php) (if possible) the [PHP Internationalization extension `Intl`](http://php.net/manual/en/intro.intl.php), which includes the PHP class `Normalizer`.

However the plugin works without the PHP `Intl` extension being installed, as it uses (a modified version of)
the [Symfony `Normalizer` polyfill](https://github.com/symfony/polyfill/tree/master/src/Intl/Normalizer).
However the plugin works without the PHP `Intl` extension being installed, as it uses (a modified version of) the [Symfony `Normalizer` polyfill](https://github.com/symfony/polyfill/tree/master/src/Intl/Normalizer).

Also text pasted into (most) inputs is normalized immediately using the JavaScript [`normalize()` method](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/normalize).
For browsers without normalization support, the [unorm polyfill](https://github.com/walling/unorm) is used.
Also text pasted into (most) inputs is normalized immediately using the JavaScript [`normalize()` method](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/normalize). For browsers without normalization support, the [unorm polyfill](https://github.com/walling/unorm) is used.

### Background ###

For further info, see the WP Trac ticket [#30130 Normalize characters with combining marks to precomposed characters](https://core.trac.wordpress.org/ticket/30130)
and this [Make WP Core comment](https://make.wordpress.org/core/2016/05/17/may-17-feature-projects-chat-and-prompt/#comment-30300).
For further info, see the WP Trac ticket [#30130 Normalize characters with combining marks to precomposed characters](https://core.trac.wordpress.org/ticket/30130) and this [Make WP Core comment](https://make.wordpress.org/core/2016/05/17/may-17-feature-projects-chat-and-prompt/#comment-30300).

The plugin also works around the Safari-specific issues raised by the WP Trac ticket [#22363 Accents in attachment filenames should be sanitized](https://core.trac.wordpress.org/ticket/22363).

### Scanner ###

For existing data, the plugin includes an administration tool to scan and normalize the database.
**Important:** before using this tool to normalize, please [backup your database](https://codex.wordpress.org/WordPress_Backups).
This is especially important if your database contains non-normalized serialized data, as this plugin uses the same suck-and-see technique as interconnect/it's
[Database Search and Replace Script in PHP](https://interconnectit.com/products/search-and-replace-for-wordpress-databases/) to deal with serialized
data, and is fallible.
For existing data, the plugin includes an administration tool to scan and normalize the database. **Important:** before using this tool to normalize, please [backup your database](https://codex.wordpress.org/WordPress_Backups). This is especially important if your database contains non-normalized serialized data, as this plugin uses the same suck-and-see technique as interconnect/it's [Database Search and Replace Script in PHP](https://interconnectit.com/products/search-and-replace-for-wordpress-databases/) to deal with serialized data, and is fallible.

### And ###

A google-cheating schoolboy French translation is supplied.

The plugin should run on PHP 5.2.17 to 7.0.13, and on WP 3.9.13 to 4.7.0.
The plugin should run on PHP 5.2.17 to 7.1, and on WP 3.9.13 to 4.7.1.

The project is on [github](https://github.com/gitlost/unfc-normalize).

Expand All @@ -64,23 +52,23 @@ Install in the standard way via the 'Plugins' menu in WordPress and then activat

### How can I normalize extra stuff? ###

You can add normalization to anything that passes its content through a filter. The canonical way is to use the `unfc_extra_filters` filter which returns an array of filter names -
for instance, in your theme's `functions.php` file, add:
You can add normalization to anything that passes its content through a filter. The canonical way is to use the `unfc_extra_filters` filter which returns an array of filter names - for instance, in your theme's `functions.php` file, add:

function mytheme_unfc_extra_filters( $extra_filters ) {
$extra_filters[] = 'myfilter';
return $extra_filters;
}
add_filter( 'unfc_extra_filters', 'mytheme_unfc_extra_filters' );

Note that the `unfc_extra_filters` filter is only called in the administration backend. You can also add a filter directly, to be called in the frontend or backend, by referencing the
global PHP variable `unfc_normalize`, but you should ensure that the `Normalizer` polyfill is loaded if you don't have the PHP `Intl` extension installed:
Note that the `unfc_extra_filters` filter is only called in the administration backend. You can also add a filter directly, to be called in the frontend or backend, by referencing the global PHP variable `unfc_normalize`, but you should ensure that the `Normalizer` polyfill is loaded if you don't have the PHP `Intl` extension installed:

global $unfc_normalize;
if ( ! function_exists( 'normalizer_is_normalized' ) ) { // If the "Intl" extension is not installed...
$unfc_normalize->load_unfc_normalizer_class(); // ...load the polyfill.
if ( $unfc_normalize ) {
if ( ! function_exists( 'normalizer_is_normalized' ) ) { // If the "Intl" extension is not installed...
$unfc_normalize->load_unfc_normalizer_class(); // ...load the polyfill.
}
add_filter( 'myfilter', array( $unfc_normalize, 'normalize' ), 6 /* Or whatever priority you choose */ );
}
add_filter( 'myfilter', array( $unfc_normalize, 'normalize' ), 6 /* Or whatever priority you choose */ );

### Does it have a tool to normalize the filenames of files uploaded prior to its enabling? ###

Expand All @@ -103,6 +91,11 @@ No, it doesn't. Alas, such files would have to re-uploaded. However if (enough -

## Changelog ##

### 1.0.6 ###
* Require explicit define of UNFC_DEBUG. Move load of debug file to 'init'.
* Safari submit workaround.
* WP 4.7.1 compatible.

### 1.0.5 ###
* Do load of normalizer in slugs list constructor not items list. Fixes slugs listing crash when Intl extension not installed.
* Ignore case when checking charset (UNFC_Normalize::is_blog_utf8()).
Expand Down Expand Up @@ -144,6 +137,9 @@ No, it doesn't. Alas, such files would have to re-uploaded. However if (enough -

## Upgrade Notice ##

### 1.0.6 ###
Less noisy when WP_DEBUG set.

### 1.0.5 ###
Fixes fatal error on check slugs listing in DB check tool when Intl extension not available.

Expand Down
Binary file modified dist/unfc-normalize-1.0.5.zip
Binary file not shown.
Binary file added dist/unfc-normalize-1.0.6.zip
Binary file not shown.
21 changes: 10 additions & 11 deletions includes/class-unfc-normalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,11 @@ static function tested_wp_version() {
* Called on 'init' action.
*/
function init() {
//unfc_debug_log( "dont_js=", $this->dont_js, ", dont_paste=", $this->dont_paste, ", dont_filter=", $this->dont_filter, ", no_normalizer=", $this->no_normalizer );
// Debug functions - no-ops unless UNFC_DEBUG is set.
if ( ! function_exists( 'unfc_debug_log' ) ) {
require dirname( __FILE__ ) . '/debug.php';
}
unfc_debug_log( "dont_js=", $this->dont_js, ", dont_paste=", $this->dont_paste, ", dont_filter=", $this->dont_filter, ", no_normalizer=", $this->no_normalizer );

$this->base = '';
// TODO: Reset $this->added_filters ??
Expand Down Expand Up @@ -558,7 +562,7 @@ function init() {
}
}

//unfc_debug_log( "base=", $this->base, ", added_filters=", $this->added_filters );
unfc_debug_log( "base=", $this->base, ", added_filters=", $this->added_filters );
}

/**
Expand Down Expand Up @@ -823,8 +827,8 @@ function sanitize_meta( $meta_value, $meta_key, $meta_type ) {
* Called on 'admin_enqueue_scripts' and 'wp_enqueue_scripts' actions.
*/
function enqueue_scripts() {
$suffix = defined( "SCRIPT_DEBUG" ) && SCRIPT_DEBUG ? '' : '.min';
$rangyinputs_suffix = defined( "SCRIPT_DEBUG" ) && SCRIPT_DEBUG ? '-src' : '';
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$rangyinputs_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '-src' : '';

// Load IE8 Array.prototype.reduceRight polyfill for unorm.
wp_enqueue_script( 'unfc-ie8', plugins_url( "js/ie8{$suffix}.js", UNFC_FILE ), array(), UNFC_VERSION );
Expand All @@ -844,10 +848,10 @@ function enqueue_scripts() {
// Our parameters.
$params = array(
'please_wait_msg' => '<div class="notice notice-warning inline"><p>' . __( 'Please wait...', 'unfc-normalize' )
. '<span class="spinner is-active" style="float:none;margin-top:0;"></span></p></div>',
. '<span class="spinner is-active" style="float:none;margin-top:-2px;"></span></p></div>',
'no_items_selected_msg' => '<div class="notice notice-warning is-dismissible inline"><p>' . $this->db_check_error_msg( UNFC_DB_CHECK_SELECT_ERROR ) . '</p></div>',
'is' => array( // Gets around stringification of direct localize elements.
'script_debug' => defined( "SCRIPT_DEBUG" ) && SCRIPT_DEBUG,
'script_debug' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && defined( 'UNFC_DEBUG' ) && UNFC_DEBUG,
'dont_paste' => $this->dont_paste,
'db_check_loaded' => $this->db_check_loaded,
),
Expand Down Expand Up @@ -2480,8 +2484,3 @@ static function get_post_meta( $post_id, $key = '', $single = false /*ignore*/ )
return $ret;
}
}

// Debug functions - no-ops unless WP_DEBUG is set.
if ( ! function_exists( 'unfc_debug_log' ) ) {
require dirname( __FILE__ ) . '/debug.php';
}
5 changes: 2 additions & 3 deletions includes/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;

if ( ! defined( 'UNFC_DEBUG' ) ) define( 'UNFC_DEBUG', defined( 'WP_DEBUG' ) ? WP_DEBUG : false );

if ( UNFC_DEBUG ) :
if ( defined( 'UNFC_DEBUG' ) && UNFC_DEBUG ) :

if ( ! defined( 'UNFC_DEBUG_PRINT_LIMIT' ) ) define( 'UNFC_DEBUG_PRINT_LIMIT', 256 );

Expand All @@ -31,6 +29,7 @@ function unfc_error_log() {
*/
function unfc_debug_log() {
if ( ! UNFC_DEBUG ) return '';
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && is_string( $_REQUEST['action'] ) && 'heartbeat' === $_REQUEST['action'] ) return '';
$func_get_args = func_get_args();
$ret = unfc_debug_trace( debug_backtrace(), $func_get_args );
$ret[0] = $ret[0] . "\n\t";
Expand Down
12 changes: 10 additions & 2 deletions js/unfc-normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ var unfc_normalize = unfc_normalize || {}; // Our namespace.
$msgs.hide();
$( 'h1', $db_check ).first().after( $msg );
unfc_normalize.makeNoticesDismissible( $db_check );
if ( $.browser && $.browser.safari ) {
// Safari apparently suspends rendering in a submit handler, so hack around it. See http://stackoverflow.com/a/1164177/664741
// Still no spinner, but better than nothing.
e.preventDefault();
$( '.spinner', $msg ).removeClass( 'is-active' ); // Hide as it doesn't spin.
$this.unbind( 'click' );
setTimeout( function() { $this.click(); }, 0 );
}
} );
}
};
Expand All @@ -170,12 +178,12 @@ var unfc_normalize = unfc_normalize || {}; // Our namespace.
if ( $db_check_list.length ) {
$form = $( 'form.unfc_db_check_list_form', $db_check_list );
if ( $form.length ) {
// Remove the "wp-admin/common.js" #17685 submit handler which doesn't apply here & is buggy anyway.
// Remove the "wp-admin/js/common.js" #17685 submit handler which doesn't apply here & is buggy anyway.
$form.off( 'submit' );
// Save some round-tripping to the server for nowt.
$( '#doaction, #doaction2', $db_check_list ).click( function ( e ) {
var $bulk_action = $( '#bulk-action-selector-' + ( 'doaction' === this.id ? 'top' : 'bottom' ) + ' option:selected', $db_check_list ),
action = $bulk_action.val(), $current_page = $( 'input#current-page-selector', $db_check_list ), $msg, $msgs, checkeds;
action = $bulk_action.val(), $msg, $msgs, checkeds;
if ( '-1' !== action ) {
checkeds = $.makeArray( $( 'input[name="item[]"]:checked', $db_check_list ).map( function () {
return this.value;
Expand Down
Loading

0 comments on commit 082f791

Please sign in to comment.