[SPIP] v3.2.1-->v3.2.2
[lhc/web/www.git] / www / ecrire / typographie / fr.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2019 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) {
14 return;
15 }
16
17 // Correction typographique francaise
18
19 function typographie_fr_dist($letexte) {
20
21 static $trans;
22
23 // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ;
24 // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe
25 if (!$trans) {
26 $trans = array(
27 "'" => '&#8217;',
28 '&nbsp;' => '~',
29 '&raquo;' => '&#187;',
30 '&laquo;' => '&#171;',
31 '&rdquo;' => '&#8221;',
32 '&ldquo;' => '&#8220;',
33 '&deg;' => '&#176;'
34 );
35 $chars = array(160 => '~', 187 => '&#187;', 171 => '&#171;', 148 => '&#8221;', 147 => '&#8220;', 176 => '&#176;');
36 $chars_trans = array_keys($chars);
37 $chars = array_values($chars);
38 $chars_trans = implode(' ', array_map('chr', $chars_trans));
39 $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer'));
40 $chars_trans = explode(' ', $chars_trans);
41 foreach ($chars as $k => $r) {
42 $trans[$chars_trans[$k]] = $r;
43 }
44 }
45
46 $letexte = strtr($letexte, $trans);
47
48 $cherche1 = array(
49 /* 1 */
50 '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S',
51 /* 2 */
52 '/&#187;| --?,|(?::(?!:)| %)(?:\W|$)/S',
53 /* 3 */
54 '/([^[<(!?.])([!?][!?\.]*)/iS',
55 /* 4 */
56 '/&#171;|(?:M(?:M?\.|mes?|r\.?)|[MnN]&#176;) /S'
57 );
58 $remplace1 = array(
59 /* 1 */
60 '\1~;',
61 /* 2 */
62 '~\0',
63 /* 3 */
64 '\1~\2',
65 /* 4 */
66 '\0~'
67 );
68 $letexte = preg_replace($cherche1, $remplace1, $letexte);
69 $letexte = preg_replace('/ *~+ */S', '~', $letexte);
70
71 $cherche2 = array(
72 '/([^-\n]|^)--([^-]|$)/S',
73 ',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S',
74 '/~/'
75 );
76 $remplace2 = array(
77 '\1&mdash;\2',
78 '\1\3\4',
79 '&nbsp;'
80 );
81 $letexte = preg_replace($cherche2, $remplace2, $letexte);
82
83 return $letexte;
84 }