[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / textwheel / typographie / en.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 anglaise
18
19 function typographie_en($t) {
20 static $trans;
21
22 if (!isset($trans)) {
23 $trans = array(
24 "&nbsp;" => '~',
25 "'" => '&#8217;'
26 );
27 $charset = isset($GLOBALS['meta']['charset']) ? $GLOBALS['meta']['charset'] : '';
28 switch ($charset) {
29 case 'utf-8':
30 $trans["\xc2\xa0"] = '~';
31 break;
32 default:
33 $trans["\xa0"] = '~';
34 break;
35 }
36 }
37
38 # cette chaine ne peut pas exister,
39 # cf. TYPO_PROTECTEUR dans inc/texte
40 $pro = "-\x2-";
41
42 $t = str_replace(array_keys($trans), array_values($trans), $t);
43
44 /* 2 */
45 $t = preg_replace('/ --?,|(?: %)(?:\W|$)/S', '~$0', $t);
46
47 /* 4 */
48 $t = preg_replace('/Mr\.? /S', '$0~', $t);
49
50 if (strpos($t, '\~') !== false) {
51 $t = str_replace('\~', "\x1\x14", $t);
52 }
53
54 if (strpos($t, '~') !== false) {
55 $t = preg_replace("/ *~+ */S", "~", $t);
56 }
57
58 $t = preg_replace("/--([^-]|$)/S", "$pro&mdash;$1", $t, -1, $c);
59 if ($c) {
60 $t = preg_replace("/([-\n])$pro&mdash;/S", "$1--", $t);
61 $t = str_replace($pro, '', $t);
62 }
63
64 $t = str_replace('~', '&nbsp;', $t);
65
66 if (strpos($t, "\x1") !== false) {
67 $t = str_replace("\x1\x14", '~', $t);
68 }
69
70 return $t;
71 }