[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / inc / surligne.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 // Ces commentaires vont etre substitue's en mode recherche
16 // voir balise_DEBUT_SURLIGNE et balise_FIN_SURLIGNE
17
18 define('MARQUEUR_SURLIGNE', 'debut_surligneconditionnel');
19 define('MARQUEUR_FSURLIGNE', 'finde_surligneconditionnel');
20
21
22 // http://doc.spip.org/@surligner_mots
23 function surligner_mots($page, $surcharge_surligne = '') {
24 $surlignejs_engines = array(
25 array(",".str_replace(array("/", "."), array("\/", "\."), $GLOBALS['meta']['adresse_site']).",i", ",recherche=([^&]+),i"), //SPIP
26 array(",^http://(www\.)?google\.,i", ",q=([^&]+),i"), // Google
27 array(",^http://(www\.)?search\.yahoo\.,i", ",p=([^&]+),i"), // Yahoo
28 array(",^http://(www\.)?search\.msn\.,i", ",q=([^&]+),i"), // MSN
29 array(",^http://(www\.)?search\.live\.,i", ",query=([^&]+),i"), // MSN Live
30 array(",^http://(www\.)?search\.aol\.,i", ",userQuery=([^&]+),i"), // AOL
31 array(",^http://(www\.)?ask\.com,i", ",q=([^&]+),i"), // Ask.com
32 array(",^http://(www\.)?altavista\.,i", ",q=([^&]+),i"), // AltaVista
33 array(",^http://(www\.)?feedster\.,i", ",q=([^&]+),i"), // Feedster
34 array(",^http://(www\.)?search\.lycos\.,i", ",q=([^&]+),i"), // Lycos
35 array(",^http://(www\.)?alltheweb\.,i", ",q=([^&]+),i"), // AllTheWeb
36 array(",^http://(www\.)?technorati\.com,i", ",([^\?\/]+)(?:\?.*)$,i"), // Technorati
37 );
38
39
40 $ref = $_SERVER['HTTP_REFERER'];
41 //avoid a js injection
42 if ($surcharge_surligne){
43 $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", "$1\\\\$2", $surcharge_surligne);
44 $surcharge_surligne = str_replace("\\", "\\\\", $surcharge_surligne);
45 if ($GLOBALS['meta']['charset']=='utf-8'){
46 include_spip('inc/charsets');
47 if (!is_utf8($surcharge_surligne)) $surcharge_surligne = utf8_encode($surcharge_surligne);
48 }
49 $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final
50 }
51 foreach ($surlignejs_engines as $engine)
52 if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))){
53
54 //good referrer found or var_recherche is not null
55 include_spip('inc/filtres');
56 $script = "
57 <script type='text/javascript' src='".url_absolue(find_in_path('javascript/SearchHighlight.js'))."'></script>
58 <script type='text/javascript'>/*<![CDATA[*/
59 if (window.jQuery)
60 (function(\$){\$(function(){
61 \$(document).SearchHighlight({
62 tag_name:'".(html5_permis() ? 'mark' : 'span')."',
63 style_name:'spip_surligne',
64 exact:'whole',
65 style_name_suffix:false,
66 engines:[/^".str_replace(array("/", "."), array("\/", "\."), $GLOBALS['meta']['adresse_site'])."/i,/recherche=([^&]+)/i],
67 highlight:'.surlignable',
68 nohighlight:'.pas_surlignable'".
69 ($surcharge_surligne ? ",
70 keys:'$surcharge_surligne'" : "").",
71 min_length: 3
72 })
73 });
74 })(jQuery);
75 /*]]>*/</script>
76 ";
77 // on l'insere juste avant </head>, sinon tout en bas
78 if (is_null($l = strpos($page, '</head>')))
79 $l = strlen($page);
80 $page = substr_replace($page, $script, $l, 0);
81 break;
82 }
83 return $page;
84 }
85
86 ?>