git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-359
authorJean-Marc Coic <jean-marc.coic@polytechnique.org>
Sun, 16 Jan 2005 20:35:50 +0000 (20:35 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:43 +0000 (23:27 +0200)
include/exalead/exalead.class.php
include/exalead/exalead.parser.inc.php
include/exalead/exalead.smarty.inc.php

index dfcd6dc..18290de 100644 (file)
@@ -61,6 +61,7 @@ class ExaleadKeyword{
 
 class ExaleadGroup{
 
+  var $gid = "";
   var $categories = array();
   var $title = "";
   var $clipped = false;
@@ -75,6 +76,7 @@ class ExaleadGroup{
     $this->categories[] = $category;
   }
 
+  function setGid($gid){$this->gid = $gid;}
   function setTitle($title){$this->title = $title;}
   function setClipped($clipped){$this->clipped = $clipped;}
   function setCount($count){$this->count = $count;}
@@ -83,6 +85,7 @@ class ExaleadGroup{
   function setResetHref($reset_href){$this->reset_href = $reset_href;}
 
   function clear(){
+   $this->gid = "";
    $this->categories = array();
    $this->title = "";
    $this->clipped = false;
index 5a2eb6c..ba68898 100644 (file)
 require_once('exalead.class.php');
 
 function convert_url($string){
-    return str_replace('+', '%2B', $string);
+  return str_replace('+', '%2B', $string);
 }
 
-class Exalead{
-
-    var $parserId;
-
-    var $data;
-
-    var $currentGroup;
-    var $currentCategory;
-    var $currentSpelling;
-    var $currentHit;
-    var $currentHitField;
-    var $currentHitGroup;
-    var $currentHitCategory;
-    var $currentAction;
-    var $currentTextSegment;
-    var $currentQuery;
-    var $currentQueryTerm;
-    var $currentQueryParameter;
-    var $currentKeyword;
-
-    //url de base du produit Exalead
-    var $base_cgi = '';
-
-    /****    Constructeur     *********/
-
-
-    function Exalead($base_cgi = ''){
-        $this->data = new ExaleadData();
-        $this->currentGroup = new ExaleadGroup();
-        $this->currentCategory = new ExaleadCategory();
-        $this->currentSpelling = new ExaleadSpelling();
-        $this->currentHit = new ExaleadHit();
-        $this->currentHitField = new ExaleadHitField();
-        $this->currentHitGroup = new ExaleadHitGroup();
-        $this->currentHitCategory = new ExaleadHitCategory();
-        $this->currentAction = new ExaleadAction();
-        $this->currentTextSegment = new ExaleadTextSegment();
-        $this->currentQuery = new ExaleadQuery();
-        $this->currentQueryTerm = new ExaleadQueryTerm();
-        $this->currentQueryParameter = new ExaleadQueryParameter();
-        $this->currentKeyword = new ExaleadKeyword();
-
-        //url de base du produit Exalead
-        $this->base_cgi = $base_cgi;
-    }
-
-    /****  Fonctions d'interface avec le cgi d'Exalead Corporate   ******/
-
-    function set_base_cgi($base_cgi){
-        $this->base_cgi = $base_cgi;
-    }
-
-    //retourne vrai si une requete a été faite, faux sinon
-    function query($varname = 'query'){
-        if(!empty($_REQUEST[$varname])){
-
-            $this->first_query(stripslashes($_REQUEST[$varname]));
-            return true;
-        }
-        elseif(isset($_GET['_C'])){
-
-            $this->handle_get();
-            return true;
-        }
-        return false;
-    }
-
-    //a appeller pour faire la premiere requete
-    function first_query($query, $offset = 0){
-        if(empty($this->base_cgi)) return false;
-
-        $query_exa = $this->base_cgi."?_q=".urlencode($query)."&_f=xml2";
-        if($offset > 0){
-            $query_exa .= "&_s=".$offset;
-        }
-
-        $xml_response = file_get_contents($query_exa);
-        $this->parse($xml_response);
-    }
-
-    function handle_get(){
-        if(empty($this->base_cgi)) return false;
-        if(empty($_GET['_C'])) return false;// _C est le contexte Exalead
-        $query_exa = $this->base_cgi.'/_C='.str_replace(' ', '%20', $_GET['_C']).'&_f=xml2';
-        if(!empty($_GET['_s'])){
-            $query_exa .= "&_s=".$_GET['_s'];
-        }
-        $xml_response = file_get_contents($query_exa);
-        $this->parse($xml_response);
-    }
-
-    /********      Fonctions annexes relatives au parser     ********/
-
-    function createParser(){
-        $this->parserId = xml_parser_create(); 
-        xml_set_element_handler($this->parserId, array(&$this, "startElement"), array(&$this, "endElement"));
-        xml_set_character_data_handler($this->parserId, array(&$this, "parsePCData"));
-    }
-
-    function setElementHandler($stratElement, $endElement){
-    }
-
-    function freeParser(){
-        xml_parser_free($this->parserId);
-    }
-
-    function parseString($string){
-        if (!xml_parse($this->parserId, $string, true)) {
-            die(sprintf("XML error: %s at line %d",
-                        xml_error_string(xml_get_error_code($this->parserId)),
-                        xml_get_current_line_number($this->parserId)));
-        }
-    }
-
-
-
-    /********        Méthode qui lance le parser           ***********/
-
-    function parse($string){
-        $this->createParser();
-        $this->parseString($string);
-        $this->freeParser();
-    }
-
-    /*********      fonctions spécifiques à chaque balise     ******/
-
-    //Ces méthodes peuvent être surchargées
-
-    function startQuery(&$attrs){
-        $this->currentQuery->query = utf8_decode($attrs['QUERY']);
-        $this->currentQuery->context = $attrs['CONTEXT'];
-        $this->currentQuery->time = $attrs['TIME'];
-        if(isset($attrs['INTERRUPTED'])) $this->currentQuery->interrupted = $attrs['INTERRUPTED'];
-        if(isset($attrs['BROWSED'])) $this->currentQuery->browsed = $attrs['BROWSED'];
-    }
-
-    function StartQueryTerm(&$attrs){
-        $this->currentQueryTerm->level = $attrs['LEVEL'];
-        $this->currentQueryTerm->regexp = utf8_decode($attrs['REGEXP']);
-    }
-
-    function startQueryParameter(&$attrs){
-        $this->currentQueryParameter->name = $attrs['NAME'];
-        if(isset($attrs['VALUE'])) $this->currentQueryParameter->value = utf8_decode($attrs['VALUE']);
-    }
-
-    function startKeyword(&$attrs){
-        if(isset($attrs['NAME'])) $this->currentKeyword->name = $attrs['NAME'];
-        $this->currentKeyword->display = utf8_decode( $attrs['DISPLAY'] );
-        $this->currentKeyword->count = $attrs['COUNT'];
-        $this->currentKeyword->automatic = $attrs['AUTOMATIC'];
-        if(isset($attrs['REFINEHREF'])) $this->currentKeyword->refine_href = convert_url($attrs['REFINEHREF']);
-        if(isset($attrs['EXCLUDEHREF'])) $this->currentKeyword->exclude_href = $attrs['EXCLUDEHREF'];
-        if(isset($attrs['RESETHREF'])) $this->currentKeyword->reset_href = $attrs['RESETHREF'];
-    }
-
-    function startHits(&$attrs){
-        $this->data->nmatches = $attrs['NMATCHES'];
-        $this->data->nhits = $attrs['NHITS'];
-        if(isset($attrs['INTERRUPTED'])) $this->data->interrupted = $attrs['INTERRUPTED'];
-        $this->data->last = $attrs['LAST'];
-        $this->data->end = $attrs['END'];
-        $this->data->start = $attrs['START'];
-    }
+$GLOBALS['query_all'] = 'a*';
 
-    function startHit(&$attrs){
-        $this->currentHit->url = $attrs['URL'];
-        $this->currentHit->score = $attrs['SCORE'];
-    }
-
-    function startHitGroup(&$attrs){
-        $this->currentHitGroup->title = utf8_decode($attrs['TITLE']);
-        $this->currentHitGroup->gid = $attrs['GID'];
-    }
-
-    function startHitCategory(&$attrs){
-        $this->currentHitCategory->name = $attrs['NAME'];
-        $this->currentHitCategory->display = utf8_decode($attrs['DISPLAY']);
-        $this->currentHitCategory->cref = $attrs['CREF'];
-        $this->currentHitCategory->gid = $attrs['GID'];
-        if(isset($attrs['BROWSEHREF'])) $this->currentHitCategory->browsehref = $attrs['BROWSEHREF'];
-    }
-
-    function startAction(&$attrs){
-        $this->currentAction->display = $attrs['DISPLAY'];
-        $this->currentAction->kind = $attrs['KIND'];
-        if(isset($attrs['EXECHREF']))$this->currentAction->execHref = $attrs['EXECHREF'];
-    }
-
-    function startHitField(&$attrs){
-        $this->currentHitField->name = $attrs['NAME'];
-        if(isset($attrs['VALUE'])) $this->currentHitField->value = utf8_decode($attrs['VALUE']);
-    }
-
-    function startTextSeg(&$attrs){
-        $this->currentTextSegment->setHighlighted($attrs['HIGHLIGHTED']);
-    }
-    function startTextCut(&$attrs){}
-
-    function startSpellingSuggestionVariant(&$attrs){
-        $this->currentSpelling->setDisplay($attrs['DISPLAY']);
-        $this->currentSpelling->setQueryHref($attrs['QUERY']);
-    }
-
-    function startGroup(&$attrs){
-        $this->currentGroup->setTitle(utf8_decode($attrs['TITLE']));
-        $this->currentGroup->setClipped($attrs['CLIPPED']);
-        $this->currentGroup->setCount($attrs['COUNT']);
-        $this->currentGroup->setBrowsed($attrs['BROWSED']);
-        if(isset($attrs['CLIPHREF'])) $this->currentGroup->setClipHref($attrs['CLIPHREF']);
-        if(isset($attrs['RESETHREF'])) $this->currentGroup->setResetHref($attrs['RESETHREF']);
-    }
-
-    function startCategory(&$attrs){
-        $this->currentCategory->name = $attrs['NAME'];
-        $this->currentCategory->display = utf8_decode($attrs['DISPLAY']);
-        $this->currentCategory->count = $attrs['COUNT'];
-        $this->currentCategory->automatic = $attrs['AUTOMATIC'];
-        if(isset($attrs['REFINEHREF'])) $this->currentCategory->refine_href = convert_url($attrs['REFINEHREF']);
-        //if(isset($attrs['REFINEHREF'])) $this->currentCategory->refine_href = $attrs['REFINEHREF'];
-        if(isset($attrs['EXCLUDEHREF'])) $this->currentCategory->exclude_href = $attrs['EXCLUDEHREF'];
-        if(isset($attrs['RESETHREF'])) $this->currentCategory->reset_href = $attrs['RESETHREF'];
-        $this->currentCategory->cref = $attrs['CREF'];
-        $this->currentCategory->gid = $attrs['GID'];
-        $this->currentCategory->gcount = $attrs['GCOUNT'];
-    }
-
-    function startSearch(&$attrs){}
-
-    function startElement($parser, $name, $attrs) {
-        //echo "start $name<br />";
-        //recupération des paramètres de query
-        if($name == 'QUERY'){
-            $this->startQuery($attrs);
-        }
-        elseif($name == 'QUERYTERM'){
-            $this->startQueryTerm($attrs);
-        }
-        elseif($name == 'QUERYPARAMETER'){
-            $this->startQueryParameter($attrs);
-        }
-        //gestion des mots-clés
-        elseif($name == 'KEYWORD'){
-            $this->startKeyword($attrs);
-        }
-        //gestion des resultats
-        elseif($name == 'HITS'){
-            $this->startHits($attrs);
-        }
-        elseif($name == 'HIT'){
-            $this->startHit($attrs);
-        }
-        elseif($name == 'HITFIELD'){
-            $this->startHitField($attrs);
-        }
-        elseif($name == 'HITGROUP'){
-            $this->startHitGroup($attrs);
-        }
-        elseif($name == 'HITCATEGORY'){
-            $this->startHitCategory($attrs);
-        }
-        elseif($name == 'ACTION'){
-            $this->startAction($attrs);
-        }
-        elseif($name == 'TEXTSEG'){
-            $this->startTextSeg($attrs);
-        }
-        elseif($name == 'TEXTCUT'){
-            $this->startTextCut($attrs);
-        }
-        //gestion suggestions d'orthographe
-        elseif($name == 'SPELLINGSUGGESTIONVARIANT'){
-            $this->startSpellingSuggestionVariant($attrs);
-        }
-        //gestion des categories pour raffiner
-        elseif($name == 'GROUP'){
-            $this->startGroup($attrs);
-        }
-        elseif($name == 'CATEGORY'){
-            $this->startCategory($attrs);
-        }
-        elseif($name == 'SEARCH'){
-            $this->startSearch($attrs);
-        }
-    }
-
-    function endQuery(){
-        $this->data->query = $this->currentQuery;
-        $this->currentQuery->clear();
-    }
-    function endQueryTerm(){
-        $this->currentQuery->addTerm($this->currentQueryTerm);
-        $this->currentQueryTerm->clear();
-    }
-    function endQueryParameter(){
-        $this->currentQuery->addParameter($this->currentQueryParameter);
-        $this->currentQueryParameter->clear();
-    }
-    function endKeyword(){
-        $this->data->addKeyword($this->currentKeyword);
-        $this->currentKeyword->clear();
-    }
-    function endHits(){
-    }
-    function endHit(){
-        $this->data->addHit($this->currentHit);
-        $this->currentHit->clear();
-    }
-    function endHitGroup(){
-        $this->currentHit->addHitGroup($this->currentHitGroup);
-        $this->currentHitGroup->clear();
-    }
-    function endHitCategory(){
-        $this->currentHitGroup->addHitCategory($this->currentHitCategory);
-        $this->currentHitCategory->clear();
-    }
-    function endAction(){
-        $this->currentHit->addAction($this->currentAction);
-        $this->currentAction->clear();
-    }
-    function endHitField(){
-        $this->currentHit->addHitField($this->currentHitField);
-        $this->currentHitField->clear();
-    }
-    function endTextSeg(){
-        $this->currentHitField->addTextSegment($this->currentTextSegment);
-        $this->currentTextSegment->clear();
-    }
-    function endTextCut(){
-        $this->currentHitField->setHasTextCut(true);
-    }
-    function endSpellingSuggestionVariant(){
-        $this->data->addSpelling($this->currentSpelling);
-        $this->currentSpelling->clear();
-    }
-    function endGroup(){
-        $this->data->addGroup($this->currentGroup);
-        $this->currentGroup->clear();
-    }
-    function endCategory(){
-        $this->currentGroup->addCategory($this->currentCategory);
-        $this->currentCategory->clear();
-    }
-    function endSearch(){
-    }
-
-
-    function endElement($parser, $name) {
-        //echo "end $name<br >";
-        if($name == 'QUERY'){
-            $this->endQuery();
-        }
-        elseif($name == 'QUERYTERM'){
-            $this->endQueryTerm();
-        }
-        elseif($name == 'QUERYPARAMETER'){
-            $this->endQueryParameter();
-        }
-        elseif($name == 'KEYWORD'){
-            $this->endKeyword();
-        }
-        elseif($name == 'HITS'){
-            $this->endHits();
-        }
-        elseif($name == 'HIT'){
-            $this->endHit();
-        }
-        elseif($name == 'HITFIELD'){
-            $this->endHitField();
-        }
-        elseif($name == 'HITGROUP'){
-            $this->endHitGroup();
-        }
-        elseif($name == 'HITCATEGORY'){
-            $this->endHitCategory();
-        }
-        elseif($name == 'ACTION'){
-            $this->endAction();
-        }
-        elseif($name == 'TEXTSEG'){
-            $this->endTextSeg();
-        }
-        elseif($name == 'TEXTCUT'){
-            $this->endTextCut();
-        }
-        //gestion suggestions d'orthographe
-        elseif($name == 'SPELLINGSUGGESTIONVARIANT'){
-            $this->endSpellingSuggestionVariant();
-        }
-        //gestion des categories pour raffiner
-        elseif($name == 'GROUP'){
-            $this->endGroup();
-        }
-        elseif($name == 'CATEGORY'){
-            $this->endCategory();
-        }
-        elseif($name == 'SEARCH'){
-            $this->endSearch();
-        }
-    }
+class Exalead{
 
-    function parsePCData($parser, $text){
-        $this->currentTextSegment->append(utf8_decode($text));
-    }
+  var $parserId;
+
+  var $data;
+
+  var $currentGroup;
+  var $currentCategory;
+  var $currentSpelling;
+  var $currentHit;
+  var $currentHitField;
+  var $currentHitGroup;
+  var $currentHitCategory;
+  var $currentAction;
+  var $currentTextSegment;
+  var $currentQuery;
+  var $currentQueryTerm;
+  var $currentQueryParameter;
+  var $currentKeyword;
+
+  //url de base du produit Exalead
+  var $base_cgi = '';
+
+/****    Constructeur     *********/
+
+
+  function Exalead($base_cgi = ''){
+     $this->data = new ExaleadData();
+     $this->currentGroup = new ExaleadGroup();
+     $this->currentCategory = new ExaleadCategory();
+     $this->currentSpelling = new ExaleadSpelling();
+     $this->currentHit = new ExaleadHit();
+     $this->currentHitField = new ExaleadHitField();
+     $this->currentHitGroup = new ExaleadHitGroup();
+     $this->currentHitCategory = new ExaleadHitCategory();
+     $this->currentAction = new ExaleadAction();
+     $this->currentTextSegment = new ExaleadTextSegment();
+     $this->currentQuery = new ExaleadQuery();
+     $this->currentQueryTerm = new ExaleadQueryTerm();
+     $this->currentQueryParameter = new ExaleadQueryParameter();
+     $this->currentKeyword = new ExaleadKeyword();
+
+     //url de base du produit Exalead
+     $this->base_cgi = $base_cgi;
+  }
+
+/****  Fonctions d'interface avec le cgi d'Exalead Corporate   ******/
+
+  function set_base_cgi($base_cgi){
+    $this->base_cgi = $base_cgi;
+  }
+
+  //retourne vrai si une requete a été faite, faux sinon
+  function query($varname = 'query'){
+    if(!empty($_REQUEST[$varname])){
+
+      $this->first_query(stripslashes($_REQUEST[$varname]));
+      return true;
+    }
+    elseif(isset($_REQUEST['_C'])){
+
+      $this->handle_request();
+      return true;
+    }
+    return false;
+  }
+
+  //a appeller pour faire la premiere requete
+  function first_query($query, $offset = 0){
+    if(empty($this->base_cgi)) return false;
+    
+    $query_exa = $this->base_cgi."?_q=".urlencode($query)."&_f=xml2";
+    if($offset > 0){
+      $query_exa .= "&_s=".$offset;
+    }
+
+    $xml_response = file_get_contents($query_exa);
+    $this->parse($xml_response);
+  }
+
+  //pour recuperer tous les résultats d'une base indexée
+  function get_db_dump(){
+    $this->first_query($GLOBALS['query_all']);
+  }
+
+  function handle_request(){
+    if(empty($this->base_cgi)) return false;
+    if(empty($_REQUEST['_C'])) return false;// _C est le contexte Exalead
+    $query_exa = $this->base_cgi.'/_C='.str_replace(' ', '%20', $_REQUEST['_C']).'&_f=xml2';
+    if(!empty($_REQUEST['_s'])){
+      $query_exa .= "&_s=".((int) $_REQUEST['_s']);
+    }
+    $xml_response = file_get_contents($query_exa);
+    $this->parse($xml_response);
+  }
+
+/********      Fonctions annexes relatives au parser     ********/
+
+  function createParser(){
+    $this->parserId = xml_parser_create(); 
+    xml_set_element_handler($this->parserId, array(&$this, "startElement"), array(&$this, "endElement"));
+    xml_set_character_data_handler($this->parserId, array(&$this, "parsePCData"));
+  }
+  
+  function freeParser(){
+    xml_parser_free($this->parserId);
+  }
+  
+  function parseString($string){
+    if (!xml_parse($this->parserId, $string, true)) {
+       die(sprintf("XML error: %s at line %d",
+             xml_error_string(xml_get_error_code($this->parserId)),
+             xml_get_current_line_number($this->parserId)));
+    }
+  }
+
+
+
+/********        Méthode qui lance le parser           ***********/
+
+  function parse($string){
+    $this->createParser();
+    $this->parseString($string);
+    $this->freeParser();
+  }
+
+/*********      fonctions spécifiques à chaque balise     ******/
+
+//Ces méthodes peuvent être surchargées
+
+  function startQuery(&$attrs){
+     $this->currentQuery->query = utf8_decode($attrs['QUERY']);
+     $this->currentQuery->context = $attrs['CONTEXT'];
+     $this->currentQuery->time = $attrs['TIME'];
+     if(isset($attrs['INTERRUPTED'])) $this->currentQuery->interrupted = $attrs['INTERRUPTED'];
+     if(isset($attrs['BROWSED'])) $this->currentQuery->browsed = $attrs['BROWSED'];
+  }
+  
+  function StartQueryTerm(&$attrs){
+     $this->currentQueryTerm->level = $attrs['LEVEL'];
+     $this->currentQueryTerm->regexp = utf8_decode($attrs['REGEXP']);
+  }
+
+  function startQueryParameter(&$attrs){
+     $this->currentQueryParameter->name = $attrs['NAME'];
+     if(isset($attrs['VALUE'])) $this->currentQueryParameter->value = utf8_decode($attrs['VALUE']);
+  }
+
+  function startKeyword(&$attrs){
+     if(isset($attrs['NAME'])) $this->currentKeyword->name = $attrs['NAME'];
+     $this->currentKeyword->display = utf8_decode( $attrs['DISPLAY'] );
+     $this->currentKeyword->count = $attrs['COUNT'];
+     $this->currentKeyword->automatic = $attrs['AUTOMATIC'];
+     if(isset($attrs['REFINEHREF'])) $this->currentKeyword->refine_href = convert_url($attrs['REFINEHREF']);
+     if(isset($attrs['EXCLUDEHREF'])) $this->currentKeyword->exclude_href = $attrs['EXCLUDEHREF'];
+     if(isset($attrs['RESETHREF'])) $this->currentKeyword->reset_href = $attrs['RESETHREF'];
+  }
+
+  function startHits(&$attrs){
+     $this->data->nmatches = $attrs['NMATCHES'];
+     $this->data->nhits = $attrs['NHITS'];
+     if(isset($attrs['INTERRUPTED'])) $this->data->interrupted = $attrs['INTERRUPTED'];
+     $this->data->last = $attrs['LAST'];
+     $this->data->end = $attrs['END'];
+     $this->data->start = $attrs['START'];
+  }
+  
+  function startHit(&$attrs){
+     $this->currentHit->url = $attrs['URL'];
+     $this->currentHit->score = $attrs['SCORE'];
+  }
+  function startHitGroup(&$attrs){
+     $this->currentHitGroup->title = utf8_decode($attrs['TITLE']);
+     $this->currentHitGroup->gid = $attrs['GID'];
+  }
+  
+  function startHitCategory(&$attrs){
+     $this->currentHitCategory->name = $attrs['NAME'];
+     $this->currentHitCategory->display = utf8_decode($attrs['DISPLAY']);
+     $this->currentHitCategory->cref = $attrs['CREF'];
+     $this->currentHitCategory->gid = $attrs['GID'];
+     if(isset($attrs['BROWSEHREF'])) $this->currentHitCategory->browsehref = $attrs['BROWSEHREF'];
+  }
+  
+  function startAction(&$attrs){
+     $this->currentAction->display = $attrs['DISPLAY'];
+     $this->currentAction->kind = $attrs['KIND'];
+     if(isset($attrs['EXECHREF']))$this->currentAction->execHref = $attrs['EXECHREF'];
+  }
+  function startHitField(&$attrs){
+     $this->currentHitField->name = $attrs['NAME'];
+     if(isset($attrs['VALUE'])) $this->currentHitField->value = utf8_decode($attrs['VALUE']);
+  }
+  function startTextSeg(&$attrs){
+    $this->currentTextSegment->setHighlighted($attrs['HIGHLIGHTED']);
+  }
+  function startTextCut(&$attrs){}
+
+  function startSpellingSuggestionVariant(&$attrs){
+     $this->currentSpelling->setDisplay($attrs['DISPLAY']);
+     $this->currentSpelling->setQueryHref($attrs['QUERY']);
+  }
+
+  function startGroup(&$attrs){
+     $this->currentGroup->setGid(utf8_decode($attrs['GID']));
+     $this->currentGroup->setTitle(utf8_decode($attrs['TITLE']));
+     $this->currentGroup->setClipped($attrs['CLIPPED']);
+     $this->currentGroup->setCount($attrs['COUNT']);
+     $this->currentGroup->setBrowsed($attrs['BROWSED']);
+     if(isset($attrs['CLIPHREF'])) $this->currentGroup->setClipHref($attrs['CLIPHREF']);
+     if(isset($attrs['RESETHREF'])) $this->currentGroup->setResetHref($attrs['RESETHREF']);
+  }
+
+  function startCategory(&$attrs){
+     $this->currentCategory->name = utf8_decode($attrs['NAME']);
+     $this->currentCategory->display = utf8_decode($attrs['DISPLAY']);
+     $this->currentCategory->count = $attrs['COUNT'];
+     $this->currentCategory->automatic = $attrs['AUTOMATIC'];
+     if(isset($attrs['REFINEHREF'])) $this->currentCategory->refine_href = convert_url($attrs['REFINEHREF']);
+     //if(isset($attrs['REFINEHREF'])) $this->currentCategory->refine_href = $attrs['REFINEHREF'];
+     if(isset($attrs['EXCLUDEHREF'])) $this->currentCategory->exclude_href = $attrs['EXCLUDEHREF'];
+     if(isset($attrs['RESETHREF'])) $this->currentCategory->reset_href = $attrs['RESETHREF'];
+     $this->currentCategory->cref = $attrs['CREF'];
+     $this->currentCategory->gid = $attrs['GID'];
+     $this->currentCategory->gcount = $attrs['GCOUNT'];
+  }
+
+  function startSearch(&$attrs){}
+
+  function startElement($parser, $name, $attrs) {
+   //echo "start $name<br />";
+   //recupération des paramètres de query
+   if($name == 'QUERY'){
+     $this->startQuery($attrs);
+   }
+   elseif($name == 'QUERYTERM'){
+     $this->startQueryTerm($attrs);
+   }
+   elseif($name == 'QUERYPARAMETER'){
+     $this->startQueryParameter($attrs);
+   }
+   //gestion des mots-clés
+   elseif($name == 'KEYWORD'){
+     $this->startKeyword($attrs);
+   }
+   //gestion des resultats
+   elseif($name == 'HITS'){
+     $this->startHits($attrs);
+   }
+   elseif($name == 'HIT'){
+     $this->startHit($attrs);
+   }
+   elseif($name == 'HITFIELD'){
+     $this->startHitField($attrs);
+   }
+   elseif($name == 'HITGROUP'){
+     $this->startHitGroup($attrs);
+   }
+   elseif($name == 'HITCATEGORY'){
+     $this->startHitCategory($attrs);
+   }
+   elseif($name == 'ACTION'){
+     $this->startAction($attrs);
+   }
+   elseif($name == 'TEXTSEG'){
+     $this->startTextSeg($attrs);
+   }
+   elseif($name == 'TEXTCUT'){
+     $this->startTextCut($attrs);
+   }
+   //gestion suggestions d'orthographe
+   elseif($name == 'SPELLINGSUGGESTIONVARIANT'){
+     $this->startSpellingSuggestionVariant($attrs);
+   }
+   //gestion des categories pour raffiner
+   elseif($name == 'GROUP'){
+     $this->startGroup($attrs);
+   }
+   elseif($name == 'CATEGORY'){
+     $this->startCategory($attrs);
+   }
+   elseif($name == 'SEARCH'){
+     $this->startSearch($attrs);
+   }
+  }
+
+  function endQuery(){
+     $this->data->query = $this->currentQuery;
+     $this->currentQuery->clear();
+  }
+  function endQueryTerm(){
+     $this->currentQuery->addTerm($this->currentQueryTerm);
+     $this->currentQueryTerm->clear();
+  }
+  function endQueryParameter(){
+     $this->currentQuery->addParameter($this->currentQueryParameter);
+     $this->currentQueryParameter->clear();
+  }
+  function endKeyword(){
+     $this->data->addKeyword($this->currentKeyword);
+     $this->currentKeyword->clear();
+  }
+  function endHits(){
+  }
+  function endHit(){
+     $this->data->addHit($this->currentHit);
+     $this->currentHit->clear();
+  }
+  function endHitGroup(){
+    $this->currentHit->addHitGroup($this->currentHitGroup);
+    $this->currentHitGroup->clear();
+  }
+  function endHitCategory(){
+    $this->currentHitGroup->addHitCategory($this->currentHitCategory);
+    $this->currentHitCategory->clear();
+  }
+  function endAction(){
+    $this->currentHit->addAction($this->currentAction);
+    $this->currentAction->clear();
+  }
+  function endHitField(){
+     $this->currentHit->addHitField($this->currentHitField);
+     $this->currentHitField->clear();
+  }
+  function endTextSeg(){
+     $this->currentHitField->addTextSegment($this->currentTextSegment);
+     $this->currentTextSegment->clear();
+  }
+  function endTextCut(){
+     $this->currentHitField->setHasTextCut(true);
+  }
+  function endSpellingSuggestionVariant(){
+     $this->data->addSpelling($this->currentSpelling);
+     $this->currentSpelling->clear();
+  }
+  function endGroup(){
+     $this->data->addGroup($this->currentGroup);
+     $this->currentGroup->clear();
+  }
+  function endCategory(){
+     $this->currentGroup->addCategory($this->currentCategory);
+     $this->currentCategory->clear();
+  }
+  function endSearch(){
+  }
+
+  
+  function endElement($parser, $name) {
+   //echo "end $name<br >";
+   if($name == 'QUERY'){
+     $this->endQuery();
+   }
+   elseif($name == 'QUERYTERM'){
+     $this->endQueryTerm();
+   }
+   elseif($name == 'QUERYPARAMETER'){
+     $this->endQueryParameter();
+   }
+   elseif($name == 'KEYWORD'){
+     $this->endKeyword();
+   }
+   elseif($name == 'HITS'){
+     $this->endHits();
+   }
+   elseif($name == 'HIT'){
+     $this->endHit();
+   }
+   elseif($name == 'HITFIELD'){
+     $this->endHitField();
+   }
+   elseif($name == 'HITGROUP'){
+     $this->endHitGroup();
+   }
+   elseif($name == 'HITCATEGORY'){
+     $this->endHitCategory();
+   }
+   elseif($name == 'ACTION'){
+     $this->endAction();
+   }
+   elseif($name == 'TEXTSEG'){
+     $this->endTextSeg();
+   }
+   elseif($name == 'TEXTCUT'){
+     $this->endTextCut();
+   }
+   //gestion suggestions d'orthographe
+   elseif($name == 'SPELLINGSUGGESTIONVARIANT'){
+     $this->endSpellingSuggestionVariant();
+   }
+   //gestion des categories pour raffiner
+   elseif($name == 'GROUP'){
+     $this->endGroup();
+   }
+   elseif($name == 'CATEGORY'){
+     $this->endCategory();
+   }
+   elseif($name == 'SEARCH'){
+     $this->endSearch();
+   }
+  }
+
+  function parsePCData($parser, $text){
+    $this->currentTextSegment->append(utf8_decode($text));
+  }
 
 }
 
index 40aa379..722da1e 100644 (file)
@@ -22,13 +22,9 @@ function display_group(&$group, &$exalead_data, $keywords=false,$class = 'exa_gr
 ?>
         <a style="text-decoration: none;"
            href="?_C=<?php echo $exalead_data->query->context.'/'.$categorie->refine_href;?>&amp;_f=xml2"
-                onMouseOver="javascript:select_categorie(this, 'exa_group_<?php echo $gid?>')"
-               onMouseOut="javascript:unselect_categorie(this, 'exa_group_<?php echo $gid?>')"
                title="Afficher seulement ces résultats"
-           ><img style="vertical-align: text-bottom;" src="images/select.png" alt="[+]" /><?php echo $categorie->display;?> (<?php echo $categorie->count;?>)</a>
+           ><img style="vertical-align: text-bottom;" src="images/select.png" alt="[+]" /><?php echo (empty($categorie->display)?$categorie->name:$categorie->display).(empty($categorie->count)?'':' ('.$categorie->count.')');?></a>
        <a href="?_C=<?php echo $exalead_data->query->context.'/'.$categorie->exclude_href;?>&amp;_f=xml2"
-                onMouseOver="javascript:exclude_categorie('exa_group_<?php echo $gid.'_'.$compteur;?>')"
-               onMouseOut="javascript:unexclude_categorie('exa_group_<?php echo $gid.'_'.$compteur;?>')" 
                title="Ne pas afficher ces résultats"
               ><img style="vertical-align: text-bottom;"  src="images/moins.png" alt="[-]"/></a>
 <?php
@@ -80,9 +76,63 @@ function _display_keywords($params, &$smarty){
   display_group($exalead_data->keywords, $exalead_data, true);
 }
 
+function _exa_navigation_gauche($params, &$smarty){
+  if(!empty($params['exalead_data'])){
+    $exalead_data = &$GLOBALS[$params['exalead_data']];
+  }
+  else{
+    $exalead_data = &$GLOBALS['exalead_data'];
+  }
+  $res = '';
+  if($exalead_data->start > 0){
+    $debut_g = $exalead_data->start - 9;
+    $debut_d = $debut_g + 9;
+    if($debut_g < 0){
+      $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=0\">[1-10]</a>";
+    }
+    else{
+      $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".($debut_g-1)."\">[$debut_g-$debut_d]</a>";
+    }
+  }
+  return $res;
+}
+function _exa_navigation_droite($params, &$smarty){
+  if(!empty($params['exalead_data'])){
+    $exalead_data = &$GLOBALS[$params['exalead_data']];
+  }
+  else{
+    $exalead_data = &$GLOBALS['exalead_data'];
+  }
+  $max = -1;
+  if(!empty($params['max'])){
+    $max = (int) $params['max'];
+    if(($max < 0) || ($max > $exalead_data->nhits)){
+      $max = $exalead_data->nhits;
+    }
+  }
+  else{
+    $max = $exalead_data->nhits;
+  }
+  $res = '';
+  if(($exalead_data->end < $max) && ($max > 10)){
+    $fin_g = $exalead_data->end + 1;
+    $fin_d = $fin_g + 10;
+    if($fin_d > $max){
+      $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".($max-10)."\">[".($max-10)."-".($max)."]</a>";
+    }
+    else{
+      $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=$fin_g\">[".($fin_g+1)."-$fin_d]</a>";
+    }
+  }
+  return $res;
+}
+
+
 function register_smarty_exalead(&$page){
   $page->register_function('exa_display_groupes', '_display_groupes');
   $page->register_function('exa_display_keywords', '_display_keywords');
+  $page->register_function('exa_navigation_gauche', '_exa_navigation_gauche');
+  $page->register_function('exa_navigation_droite', '_exa_navigation_droite');
 }
 
 if(isset($page)){