[ Index ] |
|
Code source de SPIP 1.8.3 |
1 <?php 2 3 /***************************************************************************\ 4 * SPIP, Systeme de publication pour l'internet * 5 * * 6 * Copyright (c) 2001-2005 * 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 14 // 15 // Ce fichier ne sera execute qu'une fois 16 if (defined("_ECRIRE_INC_SURLIGNE")) return; 17 define("_ECRIRE_INC_SURLIGNE", "1"); 18 19 // Ces commentaires vont etre substitue's en mode recherche 20 // voir les champs SURLIGNE dans inc-index-squel 21 22 define("MARQUEUR_SURLIGNE", '!-- debut_surligneconditionnel -->'); 23 define("MARQUEUR_FSURLIGNE", '!-- finde_surligneconditionnel -->'); 24 25 function surligner_sans_accents ($mot) { 26 $accents = 27 /* A */ chr(192).chr(193).chr(194).chr(195).chr(196).chr(197). 28 /* a */ chr(224).chr(225).chr(226).chr(227).chr(228).chr(229). 29 /* O */ chr(210).chr(211).chr(212).chr(213).chr(214).chr(216). 30 /* o */ chr(242).chr(243).chr(244).chr(245).chr(246).chr(248). 31 /* E */ chr(200).chr(201).chr(202).chr(203). 32 /* e */ chr(232).chr(233).chr(234).chr(235). 33 /* Cc */ chr(199).chr(231). 34 /* I */ chr(204).chr(205).chr(206).chr(207). 35 /* i */ chr(236).chr(237).chr(238).chr(239). 36 /* U */ chr(217).chr(218).chr(219).chr(220). 37 /* u */ chr(249).chr(250).chr(251).chr(252). 38 /* yNn */ chr(255).chr(209).chr(241); 39 40 if (lire_meta('charset') == 'utf-8') { 41 include_ecrire ('inc_charsets.php3'); 42 $mot = unicode2charset(utf_8_to_unicode($mot), 'iso-8859-1'); 43 } 44 45 return strtr($mot, $accents, "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn"); 46 } 47 48 // tres sale 49 function split_by_char($str) { 50 $len = strlen($str); 51 $streturn = array(); 52 for ($i=0; $i<$len; $i++) { 53 $streturn[$i] = substr($str, $i, 1); 54 } 55 return $streturn; 56 } 57 58 function surligner_regexp_accents ($mot) { 59 $accents_regexp = array( 60 "a" => "[a".chr(224).chr(225).chr(226).chr(227).chr(228).chr(229). chr(192).chr(193).chr(194).chr(195).chr(196).chr(197)."]", 61 "o" => "[o".chr(242).chr(243).chr(244).chr(245).chr(246).chr(248). chr(210).chr(211).chr(212).chr(213).chr(214).chr(216)."]", 62 "e" => "[e".chr(232).chr(233).chr(234).chr(235). chr(200).chr(201).chr(202).chr(203)."]", 63 "c" => "[c".chr(199).chr(231)."]", 64 "i" => "[i".chr(236).chr(237).chr(238).chr(239). chr(204).chr(205).chr(206).chr(207)."]", 65 "u" => "[u".chr(249).chr(250).chr(251).chr(252). chr(217).chr(218).chr(219).chr(220)."]", 66 "y" => "[y".chr(255)."]", 67 "n" => "[n".chr(209).chr(241)."]" 68 ); 69 70 $mot = surligner_sans_accents ($mot); 71 if (lire_meta('charset') == 'utf-8') { 72 while(list($k,$s) = each ($accents_regexp)) { 73 $accents_regexp_utf8[$k] = "(".join("|", split_by_char(ereg_replace("\]|\[","",$accents_regexp[$k]))).")"; 74 } 75 $mot = strtr(strtolower($mot), $accents_regexp_utf8); 76 $mot = importer_charset($mot, 'iso-8859-1'); 77 } else 78 $mot = strtr(strtolower($mot), $accents_regexp); 79 80 return $mot; 81 } 82 83 84 // mettre en rouge les mots passes dans $var_recherche 85 function surligner_mots($page, $mots) { 86 global $nombre_surligne; 87 include_ecrire ("inc_texte.php3"); // pour le reglage de $nombre_surligne 88 89 // Remplacer les caracteres potentiellement accentues dans la chaine 90 // de recherche par les choix correspondants en syntaxe regexp (!) 91 $mots = split("[[:space:]]+", $mots); 92 93 while (list(, $mot) = each ($mots)) { 94 if (strlen($mot) >= 2) { 95 $mot = surligner_regexp_accents(preg_quote(str_replace('/', '', $mot))); 96 $mots_surligne[] = $mot; 97 } 98 } 99 100 if (!$mots_surligne) return $page; 101 102 $regexp = '/((^|>)([^<]*[^[:alnum:]_<])?)((' 103 . join('|', $mots_surligne) 104 . ')[[:alnum:]_]*?)/Uis'; 105 106 // en cas de surlignement limite' (champs #SURLIGNE), 107 // le compilateur a inse're' les balises de surlignement 108 // sur toute la zone; reste a` raffiner. 109 // On boucle pour le cas ou` il y a plusieurs zones 110 111 $p = strpos($page, MARQUEUR_SURLIGNE); 112 if ($p !== false) { 113 $debut = ''; 114 while ($p) { 115 $debut .= substr($page, 0, $p-1); 116 $page = substr($page, $p+strlen(MARQUEUR_SURLIGNE)); 117 if (!$q = strpos($page,MARQUEUR_FSURLIGNE)) 118 $q = 1+strlen($page); 119 $debut .= trouve_surligne(substr($page, 0, $q-1), $regexp); 120 $page = substr($page, $q+strlen(MARQUEUR_FSURLIGNE)); 121 $p = strpos($page,MARQUEUR_SURLIGNE); 122 } 123 return $debut . $page; 124 } else { 125 // pour toute la page: ignorer ce qui est avant </head> ou <body> 126 $re = '/<\/head>|<body[^>]*>/i'; 127 if (preg_match($re, $page, $exp)) { 128 $debut = substr($page, 0, strpos($page, $exp[0])+strlen($exp[0])); 129 $page = substr($page, strlen($debut)); 130 } else 131 $debut = ''; 132 return $debut . trouve_surligne($page, $regexp); 133 } 134 } 135 136 function trouve_surligne($page, $regexp) { 137 // Remplacer une occurrence de mot maxi par espace inter-tag 138 // (max 1 par paragraphe, sauf italiques etc.) 139 // se limiter a 4 remplacements pour ne pas bouffer le CPU ; 140 // traiter <textarea...>....</textarea> comme un tag. 141 global $nombre_surligne; 142 $page = preg_replace('/(<textarea[^>]*>)([^<>]*)(<\/textarea>)/Uis', '\1<<SPIP\2>>\3', $page); 143 $page = preg_replace($regexp, '\1<span class="spip_surligne">\4</span>', $page, $nombre_surligne); 144 $page = preg_replace('/(<textarea[^>]*>)<<SPIP([^<>]*)>>(<\/textarea>)/Uis', '\1\2\3', $page); 145 return $page ; 146 } 147 148 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Feb 22 22:27:47 2007 | par Balluche grâce à PHPXref 0.7 |