+++ /dev/null
-<?php
-
-
-class ExaleadData{
-
- var $query;
- var $groups = array();
- var $hits = array();
- var $spellings = array();
- var $keywords = array();
-
- var $nhits = "";
- var $nmatches = "";
- var $estimated = false;
- var $last = "";
- var $start = "";
- var $end = "";
-
- function ExaleadData(){}
-
- function setQuery($query){$this->query = $query;}
- function addHit($hit){$this->hits[] = $hit;}
- function addGroup($group){$this->groups[] = $group;}
- function addSpelling($spelling){$this->spellings[] = $spelling;}
- function addKeyword($keyword){$this->keywords[] = $keyword;}
-}
-
-class ExaleadKeyword{
- var $name = "";
- var $display = "";
- var $count = "";
- var $automatic = "";
- var $refine_href = "";
- var $exclude_href = "";
- var $reset_href = "";
-
- function ExaleadKeyword(){}
- function clear(){
- $name = "";
- $display = "";
- $count = "";
- $automatic = "";
- $refine_href = "";
- $exclude_href = "";
- $reset_href = "";
- }
-
- function is_normal(){
- return empty($this->reset_href);
- }
-
- function is_refined(){
- return ( (!empty($this->reset_href)) && ($this->count > 0) );
- }
-
- function is_excluded(){
- return ( (!empty($this->reset_href)) && ($this->count == 0) );
- }
-
-}
-
-class ExaleadGroup{
-
- var $gid = "";
- var $categories = array();
- var $title = "";
- var $clipped = false;
- var $count = "";
- var $browsed = false;
- var $clip_href = "";
- var $reset_href = "";
-
- function ExaleadGroup(){}
-
- function addCategory($category){
- $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;}
- function setBrowsed($browsed){$this->browsed = $browsed;}
- function setClipHref($clip_href){$this->clip_href = $clip_href;}
- function setResetHref($reset_href){$this->reset_href = $reset_href;}
-
- function clear(){
- $this->gid = "";
- $this->categories = array();
- $this->title = "";
- $this->clipped = false;
- $this->count = "";
- $this->browsed = false;
- $this->clip_href = "";
- $this->reset_href = "";
- }
-
-}
-
-class ExaleadSpelling{
-
- var $display = "";
- var $query_href = "";
-
- function ExaleadSpelling(){}
-
- function setDisplay($display){$this->display = $display;}
- function setQueryHref($query_href){$this->query_href = $query_href;}
-
- function clear(){
- $this->display = "";
- $this->query_href = "";
- }
-}
-
-class ExaleadCategory{
- var $name = "";
- var $display = "";
- var $count = "";
- var $automatic = false;
- var $refine_href = "";
- var $exclude_href = "";
- var $reset_href = "";
- var $cref = "";
- var $gid = "";
- var $gcount = "";
- var $categories = array();
-
- function ExaleadCategory(){}
-
- function addCategory($category){
- $this->categories[] = $category;
- }
-
- function clear(){
- $this->name = "";
- $this->display = "";
- $this->count = "";
- $this->automatic = false;
- $this->refine_href = "";
- $this->exclude_href = "";
- $this->reset_href = "";
- $this->cref = "";
- $this->gid = "";
- $this->gcount = "";
- }
-
- function is_normal(){
- return empty($this->reset_href);
- }
-
- function is_refined(){
- return ( (!empty($this->reset_href)) && ($this->count > 0) );
- }
-
- function is_excluded(){
- return ( (!empty($this->reset_href)) && ($this->count == 0) );
- }
-
-}
-
-class ExaleadHit{
- var $hitfields = array();
- var $hitgroups = array();
- var $actions = array();
- var $score = "";
- var $url = "";
-
- function ExaleadHit(){}
-
- function addHitField($hitfield){$this->hitfields[] = $hitfield;}
- function addHitGroup($hitgroup){$this->hitgroups[] = $hitgroup;}
- function addAction($action){$this->actions[] = $action;}
-
- function clear(){
- $this->hitfields = array();
- $this->hitgroups = array();
- $this->actions = array();
- $this->score = "";
- $this->url = "";
- }
-}
-
-class ExaleadHitGroup{
- var $hitcategories = array();
- var $title = '';
- var $gid = '';
-
- function ExaleadHitGroup(){}
-
- function addHitCategory($hitcategory){$this->hitcategories[] = $hitcategory;}
-
- function clear(){
- $this->hitcategories = array();
- $this->title = '';
- $this->gid = '';
- }
-}
-
-class ExaleadHitCategory{
- var $name = '';
- var $display = '';
- var $cref = '';
- var $gid = '';
- var $browseHref = '';
-
- function ExaleadHitCategory(){}
-
- function clear(){
- $this->name = '';
- $this->display = '';
- $this->cref = '';
- $this->gid = '';
- $this->browseHref = '';
- }
-}
-
-class ExaleadHitField{
- var $text_segments = array();
- var $has_text_cut = false;
- var $name = "";
- var $value = "";
-
- function ExaleadHitField(){}
-
- function addTextSegment($text_segment){$this->text_segments[] = $text_segment;}
- function setHasTextCut($has_text_cut){$this->has_text_cut = $has_text_cut;}
-
- function clear(){
- $this->text_segments = array();
- $this->has_text_cut = false;
- $this->name = "";
- $this->value = "";
- }
-}
-
-class ExaleadAction{
- var $display;
- var $kind;
- var $execHref;
-
- function ExaleadAction(){}
-
- function clear(){
- $this->display = '';
- $this->kind = '';
- $this->execHref = '';
- }
-}
-
-class ExaleadTextSegment{
- var $text = "";
- var $highlighted = false;
-
- function ExaleadTextSegment(){
- }
-
- function setHighlighted($highlighted){$this->highlighted = $highlighted;}
-
- function append($text){
- $this->text .= $text;
- }
-
- function clear(){
- $this->text = "";
- $this->highlighted = false;
- }
-}
-
-class ExaleadQuery{
- var $query_parameters = array();
- var $query_terms = array();
- var $query = "";
- var $context = "";
- var $time = "";
- var $interrupted = false;
- var $browsed = false;
-
- function ExaleadQuery(){}
-
- function addParameter($parameter){$this->query_parameters[] = $parameter;}
- function addTerm($term){$this->query_terms[] = $term;}
-
- function clear(){
- $this->query_parameters = array();
- $this->query_terms = array();
- $this->query = "";
- $this->context = "";
- $this->time = "";
- $this->interrupted = false;
- $this->browsed = false;
- }
-}
-
-class ExaleadQueryParameter{
-
- var $name = "";
- var $value = "";
-
- function ExaleadQueryParameter(){}
-
- function clear(){
- $this->name = "";
- $this->value = "";
- }
-}
-
-class ExaleadQueryTerm{
-
- var $level = "";
- var $regexp = "";
-
- function ExaleadQueryTerm(){}
-
- function clear(){
- $this->regexp = "";
- $this->level = "";
- }
-}
-
-
-?>
+++ /dev/null
-<?php
-
-require_once(dirname(__FILE__).'/exalead.class.php');
-
-function convert_url($string)
-{
- return str_replace('+', '%2B', $string);
-}
-
-$GLOBALS['query_all'] = 'a*';
-
-class Exalead
-{
-
- var $parserId;
-
- var $data;
-
- var $currentGroup;
- var $currentCategories = array();
- 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 = '';
-
- // Query to dump indexed database
- var $query_all= '';
-
- /**** Constructeur *********/
-
-
- function Exalead($base_cgi = '', $override_query_all = '')
- {
- $this->data = new ExaleadData();
- $this->currentGroup = new ExaleadGroup();
- $this->currentCategories = array();
- $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;
- if (!empty($override_query_all)) {
- $this->query_all = $override_query_all;
- } else {
- $this->query_all = $GLOBALS['query_all'];
- }
- }
-
- /**** 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;
-
- //$tmp = parse_url($this->base_cgi);
- //$view_name = substr($tmp['path'], 5);
- //$query_exa = $this->base_cgi."?_q=".urlencode($query)."&_f=xml2&A=-1&_vn=".$view_name;
- $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($this->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['_c'])) {
- $query_exa .= "&_c=".urlencode($_REQUEST['_c']);
- }
- if (!empty($_REQUEST['_s'])) {
- $query_exa .= "&_s=".((int) $_REQUEST['_s']);
- }
- if (isset($_REQUEST['_z'])) {
- $query_exa .= "&_z=".$_REQUEST['_z'];
- }
- if (isset($_REQUEST['_sf'])) {
- $query_exa .= "&_sf=".$_REQUEST['_sf'];
- }
- $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)
- {
- $currentCategory = new ExaleadCategory();
- $currentCategory->name = utf8_decode($attrs['NAME']);
- $currentCategory->display = utf8_decode($attrs['DISPLAY']);
- $currentCategory->count = $attrs['COUNT'];
- $currentCategory->automatic = $attrs['AUTOMATIC'];
- $currentCategory->cref = $attrs['CREF'];
- if (isset($attrs['REFINEHREF'])) $currentCategory->refine_href = convert_url($attrs['REFINEHREF']);
- $currentCategory->exclude_href = '_c=-'.$currentCategory->cref;
- if (isset($attrs['RESETHREF'])) {
- $currentCategory->reset_href = $attrs['RESETHREF'];
- }
- $currentCategory->gid = $attrs['GID'];
- $currentCategory->gcount = $attrs['GCOUNT'];
- $this->currentCategories[] = $currentCategory;
- }
-
- function startSearch(&$attrs) { }
-
- function startElement($parser, $name, $attrs)
- {
- //recupération des paramètres de query
- switch ($name) {
- case 'QUERY':
- $this->startQuery($attrs);
- break;
- case 'QUERYTERM':
- $this->startQueryTerm($attrs);
- break;
- case 'QUERYPARAMETER':
- $this->startQueryParameter($attrs);
- break;
- case 'KEYWORD':
- $this->startKeyword($attrs);
- break;
- case 'HITS':
- $this->startHits($attrs);
- break;
- case 'HIT':
- $this->startHit($attrs);
- break;
- case 'HITFIELD':
- $this->startHitField($attrs);
- break;
- case 'HITGROUP':
- $this->startHitGroup($attrs);
- break;
- case 'HITCATEGORY':
- $this->startHitCategory($attrs);
- break;
- case 'ACTION':
- $this->startAction($attrs);
- break;
- case 'TEXTSEG':
- $this->startTextSeg($attrs);
- break;
- case 'TEXTCUT':
- $this->startTextCut($attrs);
- break;
- case 'SPELLINGSUGGESTIONVARIANT':
- $this->startSpellingSuggestionVariant($attrs);
- break;
- case 'GROUP':
- $this->startGroup($attrs);
- break;
- case 'CATEGORY':
- $this->startCategory($attrs);
- break;
- case 'SEARCH':
- $this->startSearch($attrs);
- break;
- }
- }
-
- 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()
- {
- //the parent element is a Group element ?
- if (count($this->currentCategories) == 1) {
- $this->currentGroup->addCategory(array_pop($this->currentCategories));
- } else {
- //var_dump($this->currentCategories);
- $category = array_pop($this->currentCategories);
- //reset($this->currentCategories);
- end($this->currentCategories);
- //var_dump($this->currentCategories);
- $parentCategory = &$this->currentCategories[key($this->currentCategories)];
- //var_dump($parentCategory);
- $parentCategory->addCategory($category);
- }
- }
- function endSearch() { }
-
-
- function endElement($parser, $name)
- {
- switch ($name) {
- case 'QUERY':
- $this->endQuery();
- break;
- case 'QUERYTERM':
- $this->endQueryTerm();
- break;
- case 'QUERYPARAMETER':
- $this->endQueryParameter();
- break;
- case 'KEYWORD':
- $this->endKeyword();
- break;
- case 'HITS':
- $this->endHits();
- break;
- case 'HIT':
- $this->endHit();
- break;
- case 'HITFIELD':
- $this->endHitField();
- break;
- case 'HITGROUP':
- $this->endHitGroup();
- break;
- case 'HITCATEGORY':
- $this->endHitCategory();
- break;
- case 'ACTION':
- $this->endAction();
- break;
- case 'TEXTSEG':
- $this->endTextSeg();
- break;
- case 'TEXTCUT':
- $this->endTextCut();
- break;
- //gestion suggestions d'orthographe
- case 'SPELLINGSUGGESTIONVARIANT':
- $this->endSpellingSuggestionVariant();
- break;
- //gestion des categories pour raffiner
- case 'GROUP':
- $this->endGroup();
- break;
- case 'CATEGORY':
- $this->endCategory();
- break;
- case 'SEARCH':
- $this->endSearch();
- break;
- }
- }
-
- function parsePCData($parser, $text)
- {
- $this->currentTextSegment->append(utf8_decode($text));
- }
-}
-
-?>
+++ /dev/null
-<?php
-
-$exa_max_length = 16;
-
-function display_group(&$group, &$exalead_data, $keywords=false,$class = 'exa_groupe', $img_path = 'images/'){
- $compteur = 0;
- $titre = ($keywords)?'Mot-clés':$group->title;
- $gid = ($keywords)?'k':$group->gid;
- if($keywords){
- $array = & $group;
- }
- else{
- $array = & $group->categories;
- }
- $res=" <div class=\"exa_groupe\"
- <div class=\"titre\">".$titre.":</div>
- <ul id=\"exa_group_".$gid."\">";
- foreach($array as $categorie){
- $compteur++;
- $res+="<li class=\"exa_categorie\" id=\"exa_group_".$gid."_".$compteur.";\">";
- if($categorie->is_normal()){
- $res+="<a style=\"text-decoration: none;\"
- href=\"?_C=".$exalead_data->query->context."&".$categorie->refine_href.";?>&_f=xml2\"
- title=\"Afficher seulement ces résultats\">
- <img style=\"vertical-align: text-bottom;\" src=\"images/select.png\" alt=\"[+]\" />";
- if (empty($categorie->display)){
- $res+=$categorie->name;
- }
- else{
- $res+=$categorie->display;
- }
- if(!empty($categorie->count)){
- $res+=$categorie->count;
- }
- $res+="</a>
- <a href=\"?_C=".$exalead_data->query->context."&".$categorie->exclude_href.";&_f=xml2\"
- title=\"Ne pas afficher ces résultats\">
- <img style=\"vertical-align: text-bottom;\" src=\"images/moins.png\" alt=\"[-]\"/></a>";
- }
- elseif($categorie->is_excluded()){
- $res+="<span style=\"text-decoration: line-through;\">
- <a href=\"?_C=".$exalead_data->query->context."&".$categorie->reset_href.";&_f=xml2\">
- <img style=\"vertical-align: text-bottom;\" src=\"images/select.png\" alt=\"[+]\" />
- ".$categorie->display.";</a>
- </span>";
- }
- else{
- $res+="<strong>".$categorie->display.";</strong>
- <a href=\"?_C=".$exalead_data->query->context."&".$categorie->reset_href.";&_f=xml2\">
- <img style=\"vertical-align: text-bottom;\" src=\"images/moins.png\" alt=\"[-]\"/></a>";
- }
- $res+="</li>";
- }
- $res+=" </ul>
- </div>";
- return $res;
-}
-
-
-
-
-function _display_groupes($params, &$smarty){
-
- if(!empty($params['exalead_data'])){
- $exalead_data = &$GLOBALS[$params['exalead_data']];
- }
- else{
- $exalead_data = &$GLOBALS['exalead_data'];
- }
-
- foreach($exalead_data->groups as $group){
- display_group($group, $exalead_data);
- }
-
-}
-
-function _display_keywords($params, &$smarty){
- if(!empty($params['exalead_data'])){
- $exalead_data = &$GLOBALS[$params['exalead_data']];
- }
- else{
- $exalead_data = &$GLOBALS['exalead_data'];
- }
-
- 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 _exa_navigation_barre($params, &$smarty){
- if(!empty($params['exalead_data'])){
- $exalead_data = &$GLOBALS[$params['exalead_data']];
- }
- else{
- $exalead_data = &$GLOBALS['exalead_data'];
- }
- if(!empty($params['nb_res_per_page'])){
- $nb_res_per_page = (int) $params['nb_res_per_page'];
- }
- else
- $nb_res_per_page = 10;//10 results per page
- if(!empty($params['max_results']) && ((int) $params['max_results'] < $exalead_data->nhits)){
- $nb_hits = (int) $params['max_results'];
- }
- else{
- $nb_hits = (int) $exalead_data->nhits;
- }
- $date=false;
- foreach($exalead_data->query->query_parameters as $parameter){
- if($parameter->name=="_sf"){
- if($parameter->value=="-date")
- $date=true;
- }
- }
-
-
- $res = '';
- $nb_numero = 5;//We want 5 links
- $current_page = (empty($_GET['_s'])?1:1+(int) ($_GET['_s'] / $nb_res_per_page));
- $first_number = 1;
- if($nb_hits < ($nb_numero) * $nb_res_per_page){
- $nb_numero = (int) ($nb_hits / $nb_res_per_page);
- }
- else{
- if($current_page > ((int)$nb_numero/2))
- $first_number = 1 + $current_page - (int)($nb_numero/2);
- if($nb_hits < (($first_number + $nb_numero - 1) * $nb_res_per_page)){
- $first_number = (int) ($nb_hits / $nb_res_per_page) - $nb_numero+2;
- }
- }
-
- if ($current_page*$nb_res_per_page >$nb_res_per_page){
- $res.="<a href=\"?_C={$exalead_data->query->context}&_s=".(($current_page-2)*$nb_res_per_page);
- if($date) $res.="&_sf=-date";
- $res.="\">Précédent</a> ";
- }
- for($i = $first_number; $i <= $nb_numero + $first_number; $i++){
- $k=$nb_res_per_page*($i-1)+1;
- $j=$nb_res_per_page*$i;
- if($i == $current_page){
- $res .= "<strong>$k-$j</strong> ";
- }
- elseif($k<=$nb_hits){
- $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".(($i-1)*$nb_res_per_page);
- if($date) $res.="&_sf=-date";
- $res.="\">$k-$j</a> ";
- }
- }
- if ($current_page*10<$nb_hits){
- $res.="<a href=\"?_C={$exalead_data->query->context}&_s=".(($current_page)*$nb_res_per_page);
- if($date) $res.="&_sf=-date";
- $res.="\">Suivant</a>";
- }
- if($date)
- $res.=" - <a href=\"?_C={$exalead_data->query->context}&_f=xml2\">[Classer par pertinence]</a>";
- else
- $res.=" - <a href=\"?_C={$exalead_data->query->context}&_sf=-date&_f=xml2\">[Classer par date]</a>";
- return $res;
-}
-
-
-function _little_nav_barre($params, &$smarty){
- if(!empty($params['exalead_data'])){
- $exalead_data = &$GLOBALS[$params['exalead_data']];
- }
- else{
- $exalead_data = &$GLOBALS['exalead_data'];
- }
- $box=false;
- if(!empty($params['where']))
- if($params['where']=='box')
- $box=true;
- $date=false;
- foreach($exalead_data->query->query_parameters as $parameter){
- if($parameter->name=="_sf"){
- if($parameter->value=="-date")
- $date=true;
- }
- }
- $dizaine=10*(int)($exalead_data->start/10);
- $res="";
- if ($box)
- $res .= "<table>";
- else
- $res.= "<table class=\"table\">";
- $res.="<tr>";
- if($box)
- $res.="<td class=\"gauche\">";
- else
- $res .=" <td width=\"20%\" style=\"text-align: left;\">";
- if($exalead_data->start != 0){
- $num=$exalead_data->start-1;
- $res .="<a href=\"?_C={$exalead_data->query->context}&_s=".$num."\">Précédent</a>";
- }
- $num=$exalead_data->start+1;
- $res .= "</td>";
- if($box){
- $res.="<td class=\"centre\">
- CV : ".$num." / {$exalead_data->nhits}<br />";
- }
- else{
- $res.="<td width=\"60%\" style=\"text-align: center;\">
- CV : ".$num." / {$exalead_data->nhits} -";
- }
- if($date)
- $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}&_sf=-date&_f=xml2&_s=".$dizaine."\">Retour à la recherche</a>";
- else
- $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}&_f=xml2&_s=".$dizaine."\">Retour à la recherche</a>";
- $res .="</td>";
- if($box)
- $res.="<td class=\"droite\">";
- else
- $res .= "<td width=\"20%\" style=\"text-align: right;\">";
- $num=$exalead_data->start+1;
- if( $exalead_data->start+1 < $exalead_data->nhits)
- $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".$num."\">Suivant</a>";
- $res .="</td>
- </tr>
- </table>";
- return $res;
-}
-
-//categorie = true if this line is for a category, false if this is for a keyword
-function _display_3_columns($title, $count, $refine, $exclude, $categorie,$hide=-1){
-if ($title!='Inconnu'){
- global $exa_max_length;
- if($categorie) $title_exclude = 'Ne pas afficher cette catégorie';
- else $title_exclude = 'Ne pas afficher ce mot-clé';
- $extract = ((strlen($title) > $exa_max_length + 3)?substr($title,0,$exa_max_length).'...':$title);
- $result="<tr class=\"categ\"";
- if ($hide>0) {
- $result .= " id=\"cache_$hide\" onclick=\"cacheId('cache_$hide')\"";//Pour pouvoir cacher des catégories
- }
- $result.=">
- <td>
- <a style=\"text-decoration: none;\"
- href=\"?_C=".$refine."&_f=xml2\"
- title=\"$title\"
- >$extract</a></td><td width=\"10%\">$count</td><td width=\"10%\">
- <a href=\"?_C=".$exclude."&_f=xml2\"
- title=\"$title_exclude\">[-]</a></td>
- </tr>";
-
- return $result;
-}
-}
-
-//excluded = true if this line is an excluded result, = false if this line is a refined result
-//categorie = true if this line is for a category, false if this is for a keyword
-function _display_2_columns($title, $reset, $excluded, $categorie){
- global $exa_max_length;
- if($excluded){
- if($categorie) $title_link = 'Afficher de nouveau cette catégorie';
- else $title_link = 'Afficher de nouveau ce mot-clé';
- $link = '[+]';
- $style = 'text-decoration: line-through;';
- } else{
- if($categorie) $title_link = 'Voir les autres catégories';
- else $title_link = 'Voir les autres mots-clés';
- $link = '[-]';
- $style = 'text-decoration: none; font-weight: bold;';
- }
- $extract = ((strlen($title) > $exa_max_length + 3)?substr($title,0,$exa_max_length).'...':$title);
- return "<tr class=\"categ\">
- <td colspan=\"2\">
- <a style=\"$style\" href=\"?_C=".$reset."&_f=xml2\"
- title=\"$title\">$extract</a>
- </td>
- <td width=\"10%\"><a style=\"$style\"
- href=\"?_C=".$reset."&_f=xml2\"
- title=\"$title_link\"
- >$link</a>
- </td>
- </tr>";
-}
-
-function _display_resume_groupe_category(&$group, $context, $padding = '',$limit=100){
- $result = '';
- $cnt=0;
- foreach($group->categories as $categorie){
- $cnt ++;
- if($cnt==$limit) break;
- $title = (empty($categorie->display)?$categorie->name:$categorie->display);
- $count = (empty($categorie->count)?'':' ('.$categorie->count.')');
- $categorie->refine_href=str_replace('/_c=', '/&_c=', $categorie->refine_href);//correction d'un bug
- $refine = $context.'&'.$categorie->refine_href;
- $exclude = $context.'&'.$categorie->exclude_href;
- $reset = $context.'&'.$categorie->reset_href;
-
- if ($categorie->display != '') {
- if($categorie->is_normal()){
- $result .= _display_3_columns($padding.$title, $count, $refine, $exclude, '',$cnt-$limit);
- }
- else{
- $result .= _display_2_columns($padding.$title, $reset, $categorie->is_excluded(),'', $cnt-$limit);
- }
- }
- if(count($categorie->categories) > 0 && ($_SESSION['show_all']||$title=="france"||!$categorie->is_normal()) ){
- $result .= _display_resume_groupe_category($categorie, $context, $pagging.'-',$limit-$cnt);
- }
- }
- return $result;
-}
-
-/**
-* This function is used to resume database content for given group (template argument 'groupe')
-*/
-function _display_resume_groupe($params, &$smarty){
- global $exa_max_length;
- if(!empty($params['exalead_data'])){
- $exalead_data = &$GLOBALS[$params['exalead_data']];
- }
- else{
- $exalead_data = &$GLOBALS['exalead_data'];
- }
- if(empty($params['groupe'])){
- return '';
- }
- $groupe = $params['groupe'];
- $name = $params['display'];
- foreach($exalead_data->groups as $group){
- if($group->title == $groupe){
- if($groupe=="Zone"){
- if($_SESSION["show_all"]) {
- $result = "<table class=\"exa_resume\"><th colspan=\"2\" class=\"titre\">".gettext($name)."</th>
- <th><a href=\"anciens_cherche_offres_exa.php?hide=1&".$params['url']."\"><img src='images/icons/fww.gif'/></a></th>";
-
- }
- else{
- $result = "<table class=\"exa_resume\"><th colspan=\"2\" class=\"titre\">".gettext($name)."</th><th><a href=\"anciens_cherche_offres_exa.php?show_all=1&".$params['url']."\"><img src='images/icons/rww.gif'/></a></th>";
- }
- $result .= _display_resume_groupe_category($group, $exalead_data->query->context,'',$params['limit']);
- }
- else{
- $result = "<table class=\"exa_resume\"><th colspan=\"3\" class=\"titre\">".gettext($name)."</th>";
- if (isset($params['limit']) && $params['limit']>0)
- {
- $result .= _display_resume_groupe_category($group, $exalead_data->query->context,'',$params['limit']);
-
- }else
- {
- $result .= _display_resume_groupe_category($group, $exalead_data->query->context);
- }
- }
- $result .= "</table>";
- return $result;
- }
- }
-}
-
-/**
-* This function is used to resume database content for keywords
-*/
-function _display_resume_keywords($params, &$smarty){
- global $exa_max_length;
- if(!empty($params['exalead_data'])){
- $exalead_data = &$GLOBALS[$params['exalead_data']];
- }
- else{
- $exalead_data = &$GLOBALS['exalead_data'];
- }
-
- //if no keywrods, do not display anything
- if(count($exalead_data->keywords) == 0) return '';
- $name=$params['display'];
- $result = "<table class=\"exa_resume\"><th colspan=\"3\" class=\"titre\">".gettext($name)."</th>";
- foreach($exalead_data->keywords as $keyword){
- if($keyword->display != ''){
- $title = (empty($keyword->display)?$keyword->name:$keyword->display);
- $count = (empty($keyword->count)?'':' ('.$keyword->count.')');
- $refine = $exalead_data->query->context.'/'.$keyword->refine_href;
- $exclude = $exalead_data->query->context.'/'.$keyword->exclude_href;
- $reset = $exalead_data->query->context.'/'.$keyword->reset_href;
- if($keyword->is_normal()){
- $result .= _display_3_columns($title, $count, $refine, $exclude, false);
- }
- else{
- $result .= _display_2_columns($title, $reset, $keyword->is_excluded(), false);
- }
- }
- }
- $result .= "</table>";
- return $result;
-}
-
-function register_smarty_exalead(&$page){
- $page->register_function('little_nav_barre','_little_nav_barre');
- $page->register_function('exa_display_groupes', '_display_groupes');
- $page->register_function('exa_display_resume_groupe', '_display_resume_groupe');
- $page->register_function('exa_display_resume_keywords', '_display_resume_keywords');
- $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');
- $page->register_function('exa_navigation_barre', '_exa_navigation_barre');
-}
-
-if(isset($page)){
- register_smarty_exalead($page);
-}
-
-?>