[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / 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_dist($letexte) {
18
19 static $trans;
20
21 // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ;
22 // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe
23 if (!$trans) {
24 $trans = array(
25 "'" => "&#8217;",
26 "&nbsp;" => "~",
27 "&raquo;" => "&#187;",
28 "&laquo;" => "&#171;",
29 "&rdquo;" => "&#8221;",
30 "&ldquo;" => "&#8220;",
31 "&deg;" => "&#176;"
32 );
33 $chars = array(160 => '~', 187 => '&#187;', 171 => '&#171;', 148 => '&#8221;', 147 => '&#8220;', 176 => '&#176;');
34 $chars_trans = array_keys($chars);
35 $chars = array_values($chars);
36 $chars_trans = implode(' ',array_map('chr',$chars_trans));
37 $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer'));
38 $chars_trans = explode(" ",$chars_trans);
39 foreach($chars as $k=>$r)
40 $trans[$chars_trans[$k]] = $r;
41 }
42
43 $letexte = strtr($letexte, $trans);
44
45 $cherche1 = array(
46 /* 1 */ '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S',
47 /* 2 */ '/&#187;| --?,|(?::(?!:)| %)(?:\W|$)/S',
48 /* 3 */ '/([^[<(!?.])([!?][!?\.]*)/iS',
49 /* 4 */ '/&#171;|(?:M(?:M?\.|mes?|r\.?)|[MnN]&#176;) /S'
50 );
51 $remplace1 = array(
52 /* 1 */ '\1~;',
53 /* 2 */ '~\0',
54 /* 3 */ '\1~\2',
55 /* 4 */ '\0~'
56 );
57 $letexte = preg_replace($cherche1, $remplace1, $letexte);
58 $letexte = preg_replace("/ *~+ */S", "~", $letexte);
59
60 $cherche2 = array(
61 '/([^-\n]|^)--([^-]|$)/S',
62 ',(' ._PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S',
63 '/~/'
64 );
65 $remplace2 = array(
66 '\1&mdash;\2',
67 '\1\3\4',
68 '&nbsp;'
69 );
70 $letexte = preg_replace($cherche2, $remplace2, $letexte);
71
72 return $letexte;
73 }