-
Notifications
You must be signed in to change notification settings - Fork 0
/
texte-inclusif.php
134 lines (119 loc) · 5.52 KB
/
texte-inclusif.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Plugin Name: Texte inclusif
* Version: 1.0
* Plugin URI: -
* Author: Bunker D
* Author URI: http://bunkerd.fr/
* License: MIT
* License URI: https://mit-license.org
* Text Domain: texte-inclusif
* Description: Reconnaît les termes inclusifs féminins·masculins, remplacent les points utilisés par la forme choisie par l'administrateur,
* et rend l'emploi d'une forme inclusive aux logiciels de lecture automatique (aide aux personnes malvoyantes).
*
* Compatible with WordPress 4.0 through 4.9.4
*
* @package Text_Inclusif
* @author Bunker D
* @version 1.0
*/
/*
Copyright (c) 2018 by Bunker D (bunkerd)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
defined( 'ABSPATH' ) or die();
function bd_incl_replace( $content ) {
$sep = get_option('bd_inclusif_sep','·');
$content = ' ' . $content . ' ';
// Set the encoding to UTF-8.
if ( function_exists( 'mb_regex_encoding' ) ) {
$encoding = mb_regex_encoding();
mb_regex_encoding( 'UTF-8' );
} else {
$encoding = null;
}
// Do the relevant substitutions
$srch = array(
'~(?!<.*?)(?<=(?!<\pL[^>]*?)[\s>])((?:\pP|&\pL*;|&#\d*;|"|\'|“|‘|«|…)*?)(?!http|www)([\pLéÉèÈêÊîÎôÔûÛ]+)(?:\.|·|•)(?!com|gov|edu|org|xyz|int|fr|be|ch|de|uk|ca|es|it|quebec)([\pLéÉèÈêÊîÎôÔûÛ]+)(?=(\pP|&\pL*;|&#\d*;|"|\'|”|’|»|…)*?[\s<])(?![^<>]*?>)~Ss',
'~(?!<.*?)(?<=[\s>])((?:\pP|&\pL*;|&#\d*;|"|\'|“|‘|«|…)*?)(?!http|www)([\pLéÉèÈêÊîÎôÔûÛ]+)(?:\.|·|•)([\pLéÉèÈêÊîÎôÔûÛ]+)(?:\.|·|•)s(?=(\pP|&\pL*;|&#\d*;|"|\'|”|’|»|…)*?[\s<])(?![^<>]*?>)~Ss'
);
$repl = array(
"$1$2<span aria-hidden=\"true\" x=\"\">{$sep}$3</span>",
"$1$2<span aria-hidden=\"true\" x=\"\">{$sep}$3{$sep}</span>s"
);
$content = preg_replace($srch,$repl,$content);
// Restore original encoding.
if ( $encoding ) {
mb_regex_encoding( $encoding );
}
return trim( $content );
}
add_filter( 'the_title' , 'bd_incl_replace' );
add_filter( 'the_content' , 'bd_incl_replace' );
if ( get_option('bd_inclusif_comm',true) ) {
add_filter( 'comment_text' , 'bd_incl_replace' );
}
if ( is_admin() ) {
add_action('admin_menu', function() {
add_options_page( 'Configuration du texte inclusif', 'Texte inclusif', 'manage_options', 'inclusif', 'bd_inclusif_options_page' );
});
add_action( 'admin_init', function() {
register_setting( 'bd-inclusif-options' , 'bd_inclusif_sep' , array('default' => '·') );
register_setting( 'bd-inclusif-options' , 'bd_inclusif_comm' , array('default' => 'on') );
});
}
function bd_inclusif_options_page() {
?>
<div class="wrap">
<form action="options.php" method="post">
<?php
settings_fields( 'bd-inclusif-options' );
do_settings_sections( 'bd-inclusif-options' );
?>
<h1>Configuration du texte inclusif</h1>
<table class="form-table">
<tbody>
<tr>
<th>Séprataur utilisé :</th>
<td>
<select name="bd_inclusif_sep">
<option value="·" <?php echo esc_attr( get_option('bd_inclusif_sep','·') ) == '·' ? 'selected="selected"' : ''; ?>>Point médian : ·</option>
<option value="." <?php echo esc_attr( get_option('bd_inclusif_sep','·') ) == '.' ? 'selected="selected"' : ''; ?>>Point bas : .</option>
<option value="•" <?php echo esc_attr( get_option('bd_inclusif_sep','·') ) == '•' ? 'selected="selected"' : ''; ?>>Point gras : •</option>
</select>
</td>
</tr>
<tr>
<th>Traitement des commentaires :</th>
<td>
<input name="bd_inclusif_comm" type="checkbox" value="1" <?php checked( '1', get_option('bd_inclusif_comm',true) ); ?> />
</td>
</tr>
<tr>
<td><?php submit_button(); ?></td>
</tr>
</tbody>
</table>
</form>
</div>
<?php
}
register_uninstall_hook( __FILE__, 'bd_inclusif_uninstall' );
function bd_inclusif_uninstall() {
delete_option( 'bd_inclusif_sep' );
delete_option( 'bd_inclusif_comm' );
}