6 function display_group(&$group, &$exalead_data, $keywords=false
,$class = 'exa_groupe', $img_path = 'images/'){
8 $titre = ($keywords)?
'Mot-clés':$group->title
;
9 $gid = ($keywords)?
'k':$group->gid
;
13 $array = & $group->categories
;
15 <div
class="exa_groupe">
16 <div
class="titre"><?php
echo $titre?
> :</div
>
17 <ul id
="exa_group_<?php echo $gid?>">
19 foreach($array as $categorie){
22 <li
class="exa_categorie" id
="exa_group_<?php echo $gid.'_'.$compteur;?>">
24 if($categorie->is_normal()){
26 <a style
="text-decoration: none;"
27 href
="?_C=<?php echo $exalead_data->query->context.'/'.$categorie->refine_href;?>&_f=xml2"
28 title
="Afficher seulement ces résultats"
29 ><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
>
30 <a href
="?_C=<?php echo $exalead_data->query->context.'/'.$categorie->exclude_href;?>&_f=xml2"
31 title
="Ne pas afficher ces résultats"
32 ><img style
="vertical-align: text-bottom;" src
="images/moins.png" alt
="[-]"/></a
>
35 elseif($categorie->is_excluded()){
37 <span style
="text-decoration: line-through;">
38 <a href
="?_C=<?php echo $exalead_data->query->context.'/'.$categorie->reset_href;?>&_f=xml2"><img style
="vertical-align: text-bottom;" src
="images/select.png" alt
="[+]" /> <?php
echo $categorie->display
;?
></a
>
44 <strong
><?php
echo $categorie->display
;?
></strong
>
45 <a href
="?_C=<?php echo $exalead_data->query->context.'/'.$categorie->reset_href;?>&_f=xml2"><img style
="vertical-align: text-bottom;" src
="images/moins.png" alt
="[-]"/></a
>
56 function _display_groupes($params, &$smarty){
58 if(!empty($params['exalead_data'])){
59 $exalead_data = &$GLOBALS[$params['exalead_data']];
62 $exalead_data = &$GLOBALS['exalead_data'];
65 foreach($exalead_data->groups
as $group){
66 display_group($group, $exalead_data);
71 function _display_keywords($params, &$smarty){
72 if(!empty($params['exalead_data'])){
73 $exalead_data = &$GLOBALS[$params['exalead_data']];
76 $exalead_data = &$GLOBALS['exalead_data'];
79 display_group($exalead_data->keywords
, $exalead_data, true
);
82 function _exa_navigation_gauche($params, &$smarty){
83 if(!empty($params['exalead_data'])){
84 $exalead_data = &$GLOBALS[$params['exalead_data']];
87 $exalead_data = &$GLOBALS['exalead_data'];
90 if($exalead_data->start
> 0){
91 $debut_g = $exalead_data->start
- 9;
92 $debut_d = $debut_g +
9;
94 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=0\">[1-10]</a>";
97 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".($debut_g-1)."\">[$debut_g-$debut_d]</a>";
102 function _exa_navigation_droite($params, &$smarty){
103 if(!empty($params['exalead_data'])){
104 $exalead_data = &$GLOBALS[$params['exalead_data']];
107 $exalead_data = &$GLOBALS['exalead_data'];
110 if(!empty($params['max'])){
111 $max = (int) $params['max'];
112 if(($max < 0) ||
($max > $exalead_data->nhits
)){
113 $max = $exalead_data->nhits
;
117 $max = $exalead_data->nhits
;
120 if(($exalead_data->end
< $max) && ($max > 10)){
121 $fin_g = $exalead_data->end +
1;
122 $fin_d = $fin_g +
10;
124 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".($max-10)."\">[".($max-10)."-".($max)."]</a>";
127 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=$fin_g\">[".($fin_g+
1)."-$fin_d]</a>";
133 function _exa_navigation_barre($params, &$smarty){
134 if(!empty($params['exalead_data'])){
135 $exalead_data = &$GLOBALS[$params['exalead_data']];
138 $exalead_data = &$GLOBALS['exalead_data'];
140 if(!empty($params['nb_res_per_page'])){
141 $nb_res_per_page = (int) $params['nb_res_per_page'];
144 $nb_res_per_page = 10;//10 results per page
145 if(!empty($params['max_results']) && ((int) $params['max_results'] < $exalead_data->nhits
)){
146 $nb_hits = (int) $params['max_results'];
149 $nb_hits = (int) $exalead_data->nhits
;
152 $nb_numero = 5;//We want 5 links
153 $current_page = (empty($_GET['_s'])?
1:1+
(int) ($_GET['_s'] / $nb_res_per_page));
155 if($nb_hits < ($nb_numero) * $nb_res_per_page){
156 $nb_numero = (int) ($nb_hits / $nb_res_per_page);
159 if($current_page > ((int)$nb_numero/2))
160 $first_number = 1 +
$current_page - (int)($nb_numero/2);
161 if($nb_hits < (($first_number +
$nb_numero - 1) * $nb_res_per_page)){
162 $first_number = (int) ($nb_hits / $nb_res_per_page) - $nb_numero+
2;
166 if ($current_page*$nb_res_per_page >$nb_res_per_page)
167 $res.="<a href=\"?_C={$exalead_data->query->context}&_s=".(($current_page-2)*$nb_res_per_page)."\">Precedent</a> ";
168 for($i = $first_number; $i <= $nb_numero +
$first_number-1; $i++
){
169 $k=$nb_res_per_page*($i-1)+
1;
170 $j=$nb_res_per_page*$i;
171 if($i == $current_page){
172 $res .= "<strong>$k-$j</strong> ";
175 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".(($i-1)*$nb_res_per_page)."\">$k-$j</a> ";
178 if ($current_page*10<$nb_hits)
179 $res.="<a href=\"?_C={$exalead_data->query->context}&_s=".(($current_page)*$nb_res_per_page)."\">Suivant</a>";
181 foreach($exalead_data->query
->query_parameters
as $parameter){
182 if($parameter->name
=="_sf"){
183 if($parameter->value
=="-date")
189 $res.=" - <a href=\"?_C={$exalead_data->query->context}/_sf=relevance&_f=xml2\">[Classer par pertinence]</a>";
191 $res.=" - <a href=\"?_C={$exalead_data->query->context}/_sf=-date&_f=xml2\">[Classer par date]</a>";
196 function _little_nav_barre($params, &$smarty){
197 if(!empty($params['exalead_data'])){
198 $exalead_data = &$GLOBALS[$params['exalead_data']];
201 $exalead_data = &$GLOBALS['exalead_data'];
204 if(!empty($params['where']))
205 if($params['where']=='box')
208 foreach($exalead_data->query
->query_parameters
as $parameter){
209 if($parameter->name
=="_sf"){
210 if($parameter->value
=="-date")
214 $dizaine=10*(int)($exalead_data->start
/10);
219 $res.= "<table class=\"table\">";
222 $res.="<td class=\"gauche\">";
224 $res .=" <td width=\"20%\" style=\"text-align: left;\">";
225 if($exalead_data->start
!= 0){
226 $num=$exalead_data->start
-1;
227 $res .="<a href=\"?_C={$exalead_data->query->context}&_s=".$num."\">Précédent</a>";
229 $num=$exalead_data->start+
1;
232 $res.="<td class=\"centre\">
233 CV : ".$num." / {$exalead_data->nhits}<br />";
236 $res.="<td width=\"60%\" style=\"text-align: center;\">
237 CV : ".$num." / {$exalead_data->nhits} -";
240 $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}/_sf=-date&_f=xml2&_s=".$dizaine."\">Retour à la recherche</a>";
242 $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}/_sf=-relevance&_f=xml2&_s=".$dizaine."\">Retour à la recherche</a>";
245 $res.="<td class=\"droite\">";
247 $res .= "<td width=\"20%\" style=\"text-align: right;\">";
248 $num=$exalead_data->start+
1;
249 if( $exalead_data->start+
1 < $exalead_data->nhits
)
250 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".$num."\">Suivant</a>";
257 //categorie = true if this line is for a category, false if this is for a keyword
258 function _display_3_columns($title, $count, $refine, $exclude, $categorie){
259 if ($title!='Inconnu'){
260 global $exa_max_length;
261 if($categorie) $title_exclude = 'Ne pas afficher cette catégorie';
262 else $title_exclude = 'Ne pas afficher ce mot-clé';
263 $extract = ((strlen($title) > $exa_max_length +
3)?
substr($title,0,$exa_max_length).'...':$title);
264 return "<tr class=\"categ\">
266 <a style=\"text-decoration: none;\"
267 href=\"?_C=".$refine."&_f=xml2\"
269 >$extract</a></td><td width=\"10%\">$count</td><td width=\"10%\">
270 <a href=\"?_C=".$exclude."&_f=xml2\"
271 title=\"$title_exclude\">[-]</a></td>
276 //excluded = true if this line is an excluded result, = false if this line is a refined result
277 //categorie = true if this line is for a category, false if this is for a keyword
278 function _display_2_columns($title, $reset, $excluded, $categorie){
279 global $exa_max_length;
281 if($categorie) $title_link = 'Afficher de nouveau cette catégorie';
282 else $title_link = 'Afficher de nouveau ce mot-clé';
284 $style = 'text-decoration: line-through;';
286 if($categorie) $title_link = 'Voir les autres catégories';
287 else $title_link = 'Voir les autres mots-clés';
289 $style = 'text-decoration: none; font-weight: bold;';
291 $extract = ((strlen($title) > $exa_max_length +
3)?
substr($title,0,$exa_max_length).'...':$title);
292 return "<tr class=\"categ\">
294 <a style=\"$style\" href=\"?_C=".$reset."&_f=xml2\"
295 title=\"$title\">$extract</a>
297 <td width=\"10%\"><a style=\"$style\"
298 href=\"?_C=".$reset."&_f=xml2\"
299 title=\"$title_link\"
305 function _display_resume_groupe_category(&$group, $context, $padding = ''){
307 foreach($group->categories
as $categorie){
308 $title = (empty($categorie->display
)?
$categorie->name
:$categorie->display
);
309 $count = (empty($categorie->count
)?
'':' ('.$categorie->count
.')');
310 $refine = $context.'/'.$categorie->refine_href
;
311 $exclude = $context.'/'.$categorie->exclude_href
;
312 $reset = $context.'/'.$categorie->reset_href
;
314 if($categorie->display
!= ''){
315 if($categorie->is_normal()){
316 $result .= _display_3_columns($padding.$title, $count, $refine, $exclude, true
);
319 $result .= _display_2_columns($padding.$title, $reset, $categorie->is_excluded(), true
);
322 if(count($categorie->categories
) > 0){
323 $result .= _display_resume_groupe_category($categorie, $context, $padding.'-');
330 * This function is used to resume database content for given group (template argument 'groupe')
332 function _display_resume_groupe($params, &$smarty){
333 global $exa_max_length;
334 if(!empty($params['exalead_data'])){
335 $exalead_data = &$GLOBALS[$params['exalead_data']];
338 $exalead_data = &$GLOBALS['exalead_data'];
340 if(empty($params['groupe'])){
343 $groupe = $params['groupe'];
344 $name = $params['display'];
345 foreach($exalead_data->groups
as $group){
346 if($group->title
== $groupe){
347 $result = "<table class=\"exa_resume\"><th colspan=\"3\" class=\"titre\">".gettext($name)."</th>";
348 $result .= _display_resume_groupe_category($group, $exalead_data->query
->context
);
349 $result .= "</table>";
356 * This function is used to resume database content for keywords
358 function _display_resume_keywords($params, &$smarty){
359 global $exa_max_length;
360 if(!empty($params['exalead_data'])){
361 $exalead_data = &$GLOBALS[$params['exalead_data']];
364 $exalead_data = &$GLOBALS['exalead_data'];
367 //if no keywrods, do not display anything
368 if(count($exalead_data->keywords
) == 0) return '';
369 $name=$params['display'];
370 $result = "<table class=\"exa_resume\"><th colspan=\"3\" class=\"titre\">".gettext($name)."</th>";
371 foreach($exalead_data->keywords
as $keyword){
372 if($keyword->display
!= ''){
373 $title = (empty($keyword->display
)?
$keyword->name
:$keyword->display
);
374 $count = (empty($keyword->count
)?
'':' ('.$keyword->count
.')');
375 $refine = $exalead_data->query
->context
.'/'.$keyword->refine_href
;
376 $exclude = $exalead_data->query
->context
.'/'.$keyword->exclude_href
;
377 $reset = $exalead_data->query
->context
.'/'.$keyword->reset_href
;
378 if($keyword->is_normal()){
379 $result .= _display_3_columns($title, $count, $refine, $exclude, false
);
382 $result .= _display_2_columns($title, $reset, $keyword->is_excluded(), false
);
386 $result .= "</table>";
390 function register_smarty_exalead(&$page){
391 $page->register_function('little_nav_barre','_little_nav_barre');
392 $page->register_function('exa_display_groupes', '_display_groupes');
393 $page->register_function('exa_display_resume_groupe', '_display_resume_groupe');
394 $page->register_function('exa_display_resume_keywords', '_display_resume_keywords');
395 $page->register_function('exa_display_keywords', '_display_keywords');
396 $page->register_function('exa_navigation_gauche', '_exa_navigation_gauche');
397 $page->register_function('exa_navigation_droite', '_exa_navigation_droite');
398 $page->register_function('exa_navigation_barre', '_exa_navigation_barre');
402 register_smarty_exalead($page);