@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Surligne |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -35,44 +35,44 @@ discard block |
||
| 35 | 35 | * Page HTML |
| 36 | 36 | **/ |
| 37 | 37 | function surligner_mots($page, $surcharge_surligne = '') { |
| 38 | - $surlignejs_engines = array( |
|
| 39 | - array( |
|
| 40 | - "," . str_replace(array("/", "."), array("\/", "\."), $GLOBALS['meta']['adresse_site']) . ",i", |
|
| 41 | - ",recherche=([^&]+),i" |
|
| 42 | - ), //SPIP |
|
| 43 | - array(",^http://(www\.)?google\.,i", ",q=([^&]+),i"), // Google |
|
| 44 | - array(",^http://(www\.)?search\.yahoo\.,i", ",p=([^&]+),i"), // Yahoo |
|
| 45 | - array(",^http://(www\.)?search\.msn\.,i", ",q=([^&]+),i"), // MSN |
|
| 46 | - array(",^http://(www\.)?search\.live\.,i", ",query=([^&]+),i"), // MSN Live |
|
| 47 | - array(",^http://(www\.)?search\.aol\.,i", ",userQuery=([^&]+),i"), // AOL |
|
| 48 | - array(",^http://(www\.)?ask\.com,i", ",q=([^&]+),i"), // Ask.com |
|
| 49 | - array(",^http://(www\.)?altavista\.,i", ",q=([^&]+),i"), // AltaVista |
|
| 50 | - array(",^http://(www\.)?feedster\.,i", ",q=([^&]+),i"), // Feedster |
|
| 51 | - array(",^http://(www\.)?search\.lycos\.,i", ",q=([^&]+),i"), // Lycos |
|
| 52 | - array(",^http://(www\.)?alltheweb\.,i", ",q=([^&]+),i"), // AllTheWeb |
|
| 53 | - array(",^http://(www\.)?technorati\.com,i", ",([^\?\/]+)(?:\?.*)$,i"), // Technorati |
|
| 54 | - ); |
|
| 38 | + $surlignejs_engines = array( |
|
| 39 | + array( |
|
| 40 | + "," . str_replace(array("/", "."), array("\/", "\."), $GLOBALS['meta']['adresse_site']) . ",i", |
|
| 41 | + ",recherche=([^&]+),i" |
|
| 42 | + ), //SPIP |
|
| 43 | + array(",^http://(www\.)?google\.,i", ",q=([^&]+),i"), // Google |
|
| 44 | + array(",^http://(www\.)?search\.yahoo\.,i", ",p=([^&]+),i"), // Yahoo |
|
| 45 | + array(",^http://(www\.)?search\.msn\.,i", ",q=([^&]+),i"), // MSN |
|
| 46 | + array(",^http://(www\.)?search\.live\.,i", ",query=([^&]+),i"), // MSN Live |
|
| 47 | + array(",^http://(www\.)?search\.aol\.,i", ",userQuery=([^&]+),i"), // AOL |
|
| 48 | + array(",^http://(www\.)?ask\.com,i", ",q=([^&]+),i"), // Ask.com |
|
| 49 | + array(",^http://(www\.)?altavista\.,i", ",q=([^&]+),i"), // AltaVista |
|
| 50 | + array(",^http://(www\.)?feedster\.,i", ",q=([^&]+),i"), // Feedster |
|
| 51 | + array(",^http://(www\.)?search\.lycos\.,i", ",q=([^&]+),i"), // Lycos |
|
| 52 | + array(",^http://(www\.)?alltheweb\.,i", ",q=([^&]+),i"), // AllTheWeb |
|
| 53 | + array(",^http://(www\.)?technorati\.com,i", ",([^\?\/]+)(?:\?.*)$,i"), // Technorati |
|
| 54 | + ); |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
|
| 58 | - //avoid a js injection |
|
| 59 | - if ($surcharge_surligne) { |
|
| 60 | - $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", "$1\\\\$2", $surcharge_surligne); |
|
| 61 | - $surcharge_surligne = str_replace("\\", "\\\\", $surcharge_surligne); |
|
| 62 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 63 | - include_spip('inc/charsets'); |
|
| 64 | - if (!is_utf8($surcharge_surligne)) { |
|
| 65 | - $surcharge_surligne = utf8_encode($surcharge_surligne); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final |
|
| 69 | - } |
|
| 70 | - foreach ($surlignejs_engines as $engine) { |
|
| 71 | - if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))) { |
|
| 57 | + $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
|
| 58 | + //avoid a js injection |
|
| 59 | + if ($surcharge_surligne) { |
|
| 60 | + $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", "$1\\\\$2", $surcharge_surligne); |
|
| 61 | + $surcharge_surligne = str_replace("\\", "\\\\", $surcharge_surligne); |
|
| 62 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 63 | + include_spip('inc/charsets'); |
|
| 64 | + if (!is_utf8($surcharge_surligne)) { |
|
| 65 | + $surcharge_surligne = utf8_encode($surcharge_surligne); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final |
|
| 69 | + } |
|
| 70 | + foreach ($surlignejs_engines as $engine) { |
|
| 71 | + if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))) { |
|
| 72 | 72 | |
| 73 | - //good referrer found or var_recherche is not null |
|
| 74 | - include_spip('inc/filtres'); |
|
| 75 | - $script = " |
|
| 73 | + //good referrer found or var_recherche is not null |
|
| 74 | + include_spip('inc/filtres'); |
|
| 75 | + $script = " |
|
| 76 | 76 | <script type='text/javascript' src='" . url_absolue(find_in_path('javascript/SearchHighlight.js')) . "'></script> |
| 77 | 77 | <script type='text/javascript'>/*<![CDATA[*/ |
| 78 | 78 | if (window.jQuery) |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | engines:[/^" . str_replace(array("/", "."), array("\/", "\."), $GLOBALS['meta']['adresse_site']) . "/i,/recherche=([^&]+)/i], |
| 86 | 86 | highlight:'.surlignable', |
| 87 | 87 | nohighlight:'.pas_surlignable'" . |
| 88 | - ($surcharge_surligne ? ", |
|
| 88 | + ($surcharge_surligne ? ", |
|
| 89 | 89 | keys:'$surcharge_surligne'" : "") . ", |
| 90 | 90 | min_length: 3 |
| 91 | 91 | }) |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | })(jQuery); |
| 94 | 94 | /*]]>*/</script> |
| 95 | 95 | "; |
| 96 | - // on l'insere juste avant </head>, sinon tout en bas |
|
| 97 | - if (is_null($l = strpos($page, '</head>'))) { |
|
| 98 | - $l = strlen($page); |
|
| 99 | - } |
|
| 100 | - $page = substr_replace($page, $script, $l, 0); |
|
| 101 | - break; |
|
| 102 | - } |
|
| 103 | - } |
|
| 96 | + // on l'insere juste avant </head>, sinon tout en bas |
|
| 97 | + if (is_null($l = strpos($page, '</head>'))) { |
|
| 98 | + $l = strlen($page); |
|
| 99 | + } |
|
| 100 | + $page = substr_replace($page, $script, $l, 0); |
|
| 101 | + break; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $page; |
|
| 105 | + return $page; |
|
| 106 | 106 | } |