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