[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / textwheel / 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($t) {
20
21 static $trans;
22
23 if (!isset($trans)) {
24 $trans = array(
25 "&nbsp;" => '~',
26 "&raquo;" => '&#187;',
27 "&laquo;" => '&#171;',
28 "&rdquo;" => '&#8221;',
29 "&ldquo;" => '&#8220;',
30 "&deg;" => '&#176;',
31 "'" => '&#8217;'
32 );
33 $charset = isset($GLOBALS['meta']['charset']) ? $GLOBALS['meta']['charset'] : '';
34 switch ($charset) {
35 case 'utf-8':
36 $trans["\xc2\xa0"] = '~';
37 $trans["\xc2\xbb"] = '&#187;';
38 $trans["\xc2\xab"] = '&#171;';
39 $trans["\xe2\x80\x94"] = '--';
40 $trans["\xe2\x80\x9d"] = '&#8221;';
41 $trans["\xe2\x80\x9c"] = '&#8220;';
42 $trans["\xc2\xb0"] = '&#176;';
43 $trans["\xe2\x80\x89"] = '~'; # &finesp;
44 break;
45 default:
46 $trans["\xa0"] = '~';
47 $trans["\xab"] = '&#171;';
48 $trans["\xbb"] = '&#187;';
49 $trans["\xb0"] = '&#176;';
50 break;
51 }
52 }
53
54 # cette chaine ne peut pas exister,
55 # cf. TYPO_PROTECTEUR dans inc/texte
56 $pro = "-\x2-";
57
58 $t = str_replace(array_keys($trans), array_values($trans), $t);
59
60 # la typo du ; risque de clasher avec les entites &xxx;
61 if (strpos($t, ';') !== false) {
62 $t = str_replace(';', '~;', $t);
63 $t = preg_replace(',(&#?[0-9a-z]+)~;,iS', '$1;', $t);
64 }
65
66 /* 2 */
67 $t = preg_replace('/&#187;| --?,|(?::(?!:)| %)(?:\W|$)/S', '~$0', $t);
68
69 /* 3 */
70 $t = preg_replace('/[!?][!?\.]*/S', "$pro~$0", $t, -1, $c);
71 if ($c) {
72 $t = preg_replace("/([\[<\(!\?\.])$pro~/S", '$1', $t);
73 $t = str_replace("$pro", '', $t);
74 }
75
76 /* 4 */
77 $t = preg_replace('/&#171;|M(?:M?\.|mes?|r\.?|&#176;) |[nN]&#176; /S', '$0~', $t);
78
79 if (strpos($t, '\~') !== false) {
80 $t = str_replace('\~', "\x1\x14", $t);
81 }
82
83 if (strpos($t, '~') !== false) {
84 $t = preg_replace("/ *~+ */S", "~", $t);
85 }
86
87 $t = preg_replace("/--([^-]|$)/S", "$pro&mdash;$1", $t, -1, $c);
88 if ($c) {
89 $t = preg_replace("/([-\n])$pro&mdash;/S", "$1--", $t);
90 $t = str_replace($pro, '', $t);
91 }
92
93 $t = preg_replace(',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S', '$1$3$4', $t);
94 $t = str_replace('~', '&nbsp;', $t);
95
96 if (strpos($t, "\x1") !== false) {
97 $t = str_replace("\x1\x14", '~', $t);
98 }
99
100 return $t;
101 }