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