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