[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /***************************************************** 3 * This file is part of Agora, web based content management system. 4 * 5 * Agora is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * 9 * Agora is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details (file "COPYING"). 13 * 14 * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière. 15 * List of authors detailed in "copyright_fr.html" file. 16 * E-mail : agora@sig.premier-ministre.gouv.fr 17 * Web site : http://www.agora.gouv.fr 18 *****************************************************/ 19 // Ce fichier ne sera execute qu'une fois 20 if (defined("_ECRIRE_INC_SURLIGNE")) 21 return; 22 23 define("_ECRIRE_INC_SURLIGNE", "1"); 24 25 // utilise avec ob_start() et ob_get_contents() pour 26 // mettre en rouge les mots passes dans $var_recherche 27 function surligner_mots ($page, $mots) { 28 global $nombre_surligne; 29 include_ecrire ("inc_texte.php"); // pour le reglage de $nombre_surligne 30 31 // si quelqu'un a une idee pour rendre ca compatible utf-8 ? 32 $accents = 33 /* A */ chr(192). chr(193). chr(194). chr(195). chr(196). chr(197). 34 /* a */ chr(224). chr(225). chr(226). chr(227). chr(228). chr(229). 35 /* O */ chr(210). chr(211). chr(212). chr(213). chr(214). chr(216). 36 /* o */ chr(242). chr(243). chr(244). chr(245). chr(246). chr(248). 37 /* E */ chr(200). chr(201). chr(202). chr(203). 38 /* e */ chr(232). chr(233). chr(234). chr(235). 39 /* Cc */ chr(199). chr(231). 40 /* I */ chr(204). chr(205). chr(206). chr(207). 41 /* i */ chr(236). chr(237). chr(238). chr(239). 42 /* U */ chr(217). chr(218). chr(219). chr(220). 43 /* u */ chr(249). chr(250). chr(251). chr(252). 44 /* yNn */ chr(255). chr(209). chr(241); 45 46 $accents_regexp = array("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). "]", "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). "]", "e" => "[e" . chr(232). chr(233). chr(234). chr(235). chr(200). chr(201). chr(202). chr(203). "]", "c" => "[c" . chr(199). chr(231). "]", "i" => "[i" . chr(236). chr(237). chr(238). chr(239). chr(204). chr(205). chr(206). chr(207). "]", "u" => "[u" . chr(249). chr(250). chr(251). chr(252). chr(217). chr(218). chr(219). chr(220). "]", "y" => "[y" . chr(255). "]", "n" => "[n" . chr(209). chr(241). "]"); 47 48 // Remplacer les caracteres potentiellement accentues dans la chaine 49 // de recherche par les choix correspondants en syntaxe regexp (!) 50 $mots = split("[[:space:]]+", $mots); 51 52 while (list(, $mot) = each($mots)) { 53 if (strlen($mot) >= 2) { 54 $mot = strtr($mot, $accents, "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn"); 55 $mot = strtr(strtolower($mot), $accents_regexp); 56 $mots_surligne[] = $mot; 57 } 58 } 59 60 // ne pas traiter tout ce qui est avant </head> ou <body> 61 $regexp = '/<\/head>|<body[^>]*>/i'; 62 63 if (preg_match($regexp, $page, $exp)) { 64 $debut = substr($page, 0, strpos($page, $exp[0]) + strlen($exp[0])); 65 $page = substr($page, strlen($debut)); 66 } 67 else 68 $debut = ''; 69 70 // Remplacer une occurence de mot maxi par espace inter-tag (max 1 par paragraphe, sauf italiques etc.) 71 // se limiter a 4 remplacements pour ne pas bouffer le CPU ; 72 // traiter <textarea...>....</textarea> comme un tag. 73 if ($mots_surligne) { 74 $page = preg_replace('/(<textarea[^>]*>)([^<>]*)(<\/textarea>)/Uis', '\1<<SPIP\2>>\3', $page); 75 $regexp = '/((^|>)([^<]*[^[:alnum:]_<])?)((' . join('|', $mots_surligne). ')[[:alnum:]_]*?)/Uis'; 76 $page = preg_replace($regexp, '\1<span class="spip_surligne">\4</span>', $page, $nombre_surligne); 77 $page = preg_replace('/(<textarea[^>]*>)<<SPIP([^<>]*)>>(<\/textarea>)/Uis', '\1\2\3', $page); 78 } 79 80 return $debut . $page; 81 } 82 83 // debut et fin, appeles depuis les squelettes 84 function debut_surligne ($mots, $mode_surligne) { 85 switch ($mode_surligne) { 86 case 'auto': // on arrive du debut de la page, on ne touche pas au buffer 87 ob_end_flush(); 88 ob_start(); 89 $mode_surligne = 'actif'; 90 break; 91 92 case 'actif': // il y a un buffer a traiter 93 $la_page = surligner_mots(ob_get_contents(), $mots); 94 ob_end_clean(); 95 echo $la_page; 96 ob_start(); 97 $mode_surligne = 'actif'; 98 break; 99 100 case 'inactif': // il n'y a pas de buffer 101 ob_start(); 102 $mode_surligne = 'actif'; 103 break; 104 105 case false: // conditions pas reunies (flag_preserver, etc.) 106 break; 107 } 108 109 return $mode_surligne; 110 } 111 112 function fin_surligne ($mots, $mode_surligne) { 113 switch ($mode_surligne) { 114 case 'auto': // on arrive du debut de la page, on s'occupe du buffer 115 $la_page = surligner_mots(ob_get_contents(), $mots); 116 ob_end_clean(); 117 echo $la_page; 118 ob_start(); 119 $mode_surligne = 'inactif'; 120 break; 121 122 case 'actif': // il y a un buffer a traiter 123 $la_page = surligner_mots(ob_get_contents(), $mots); 124 ob_end_clean(); 125 echo $la_page; 126 $mode_surligne = 'inactif'; 127 break; 128 129 case 'inactif': // il n'y a pas de buffer 130 break; 131 132 case false: // conditions pas reunies (flag_preserver, etc.) 133 break; 134 } 135 136 return $mode_surligne; 137 } 138 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |