[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / inc / surligne.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
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 if (!defined('_ECRIRE_INC_VERSION')) return;
16
17 // Ces commentaires vont etre substitue's en mode recherche
18 // voir les champs SURLIGNE dans inc-index-squel
19
20 define('MARQUEUR_SURLIGNE', 'debut_surligneconditionnel');
21 define('MARQUEUR_FSURLIGNE', 'finde_surligneconditionnel');
22
23
24 // http://doc.spip.org/@surligner_mots
25 function surligner_mots($page) {
26 $surlignejs_engines = array(
27 array(",".str_replace(array("/","."),array("\/","\."),$GLOBALS['meta']['adresse_site']).",i", ",recherche=([^&]+),i"), //SPIP
28 array(",^http://(www\.)?google\.,i", ",q=([^&]+),i"), // Google
29 array(",^http://(www\.)?search\.yahoo\.,i", ",p=([^&]+),i"), // Yahoo
30 array(",^http://(www\.)?search\.msn\.,i", ",q=([^&]+),i"), // MSN
31 array(",^http://(www\.)?search\.live\.,i", ",query=([^&]+),i"), // MSN Live
32 array(",^http://(www\.)?search\.aol\.,i", ",userQuery=([^&]+),i"), // AOL
33 array(",^http://(www\.)?ask\.com,i", ",q=([^&]+),i"), // Ask.com
34 array(",^http://(www\.)?altavista\.,i", ",q=([^&]+),i"), // AltaVista
35 array(",^http://(www\.)?feedster\.,i", ",q=([^&]+),i"), // Feedster
36 array(",^http://(www\.)?search\.lycos\.,i", ",q=([^&]+),i"), // Lycos
37 array(",^http://(www\.)?alltheweb\.,i", ",q=([^&]+),i"), // AllTheWeb
38 array(",^http://(www\.)?technorati\.com,i", ",([^\?\/]+)(?:\?.*)$,i"), // Technorati
39 );
40
41
42 $ref = $_SERVER['HTTP_REFERER'];
43 //avoid a js injection
44 if($surcharge_surligne=_request("var_recherche")) {
45 $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),","$1\\\\$2",$surcharge_surligne);
46 $surcharge_surligne = str_replace("\\","\\\\",$surcharge_surligne);
47 if($GLOBALS['meta']['charset']=='utf-8') {
48 include_spip('inc/charsets');
49 if(!is_utf8($surcharge_surligne)) $surcharge_surligne = utf8_encode($surcharge_surligne);
50 }
51 }
52 foreach($surlignejs_engines as $engine)
53 if($surcharge_surligne || (preg_match($engine[0],$ref) && preg_match($engine[1],$ref))) {
54
55 //good referrer found or var_recherche is not null
56 include_spip('inc/filtres');
57 $script = "
58 <script type='text/javascript' src='".url_absolue(find_in_path('javascript/SearchHighlight.js'))."'></script>
59 <script type='text/javascript'>/*<![CDATA[*/
60 if (window.jQuery)
61 (function(\$){\$(function(){
62 \$(document).SearchHighlight({
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 ?>