PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/spip/ecrire/typographie/fr.php

https://github.com/eyeswebcrea/espace-couture-sittler.fr
PHP | 73 lines | 51 code | 10 blank | 12 comment | 2 complexity | e305aa57feb33de88f7c498b912d25d9 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2011 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. if (!defined('_ECRIRE_INC_VERSION')) return;
  12. // Correction typographique francaise
  13. function typographie_fr_dist($letexte) {
  14. static $trans;
  15. // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ;
  16. // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe
  17. if (!$trans) {
  18. $trans = array(
  19. "'" => "&#8217;",
  20. "&nbsp;" => "~",
  21. "&raquo;" => "&#187;",
  22. "&laquo;" => "&#171;",
  23. "&rdquo;" => "&#8221;",
  24. "&ldquo;" => "&#8220;",
  25. "&deg;" => "&#176;"
  26. );
  27. $chars = array(160 => '~', 187 => '&#187;', 171 => '&#171;', 148 => '&#8221;', 147 => '&#8220;', 176 => '&#176;');
  28. $chars_trans = array_keys($chars);
  29. $chars = array_values($chars);
  30. $chars_trans = implode(' ',array_map('chr',$chars_trans));
  31. $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer'));
  32. $chars_trans = explode(" ",$chars_trans);
  33. foreach($chars as $k=>$r)
  34. $trans[$chars_trans[$k]] = $r;
  35. }
  36. $letexte = strtr($letexte, $trans);
  37. $cherche1 = array(
  38. /* 1 */ '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S',
  39. /* 2 */ '/&#187;| --?,|(?::| %)(?:\W|$)/S',
  40. /* 3 */ '/([^[<(])([!?][!?\.]*)/iS',
  41. /* 4 */ '/&#171;|(?:M(?:M?\.|mes?|r\.?)|[MnN]&#176;) /S'
  42. );
  43. $remplace1 = array(
  44. /* 1 */ '\1~;',
  45. /* 2 */ '~\0',
  46. /* 3 */ '\1~\2',
  47. /* 4 */ '\0~'
  48. );
  49. $letexte = preg_replace($cherche1, $remplace1, $letexte);
  50. $letexte = preg_replace("/ *~+ */S", "~", $letexte);
  51. $cherche2 = array(
  52. '/([^-\n]|^)--([^-]|$)/S',
  53. ',(http|https|ftp|mailto)~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S',
  54. '/~/'
  55. );
  56. $remplace2 = array(
  57. '\1&mdash;\2',
  58. '\1\3\4',
  59. '&nbsp;'
  60. );
  61. $letexte = preg_replace($cherche2, $remplace2, $letexte);
  62. return $letexte;
  63. }