0337d704 |
1 | <?php |
2 | |
5476011b |
3 | $exa_max_length = 16; |
0337d704 |
4 | |
5 | function display_group(&$group, &$exalead_data, $keywords=false,$class = 'exa_groupe', $img_path = 'images/'){ |
5476011b |
6 | $compteur = 0; |
7 | $titre = ($keywords)?'Mot-clés':$group->title; |
8 | $gid = ($keywords)?'k':$group->gid; |
9 | if($keywords){ |
10 | $array = & $group; |
11 | } |
12 | else{ |
13 | $array = & $group->categories; |
14 | } |
15 | $res=" <div class=\"exa_groupe\" |
16 | <div class=\"titre\">".$titre.":</div> |
17 | <ul id=\"exa_group_".$gid."\">"; |
18 | foreach($array as $categorie){ |
19 | $compteur++; |
20 | $res+="<li class=\"exa_categorie\" id=\"exa_group_".$gid."_".$compteur.";\">"; |
21 | if($categorie->is_normal()){ |
22 | $res+="<a style=\"text-decoration: none;\" |
9b31f89c |
23 | href=\"?_C=".$exalead_data->query->context."&".$categorie->refine_href.";?>&_f=xml2\" |
5476011b |
24 | title=\"Afficher seulement ces résultats\"> |
25 | <img style=\"vertical-align: text-bottom;\" src=\"images/select.png\" alt=\"[+]\" />"; |
26 | if (empty($categorie->display)){ |
27 | $res+=$categorie->name; |
28 | } |
29 | else{ |
30 | $res+=$categorie->display; |
31 | } |
32 | if(!empty($categorie->count)){ |
33 | $res+=$categorie->count; |
34 | } |
35 | $res+="</a> |
9b31f89c |
36 | <a href=\"?_C=".$exalead_data->query->context."&".$categorie->exclude_href.";&_f=xml2\" |
5476011b |
37 | title=\"Ne pas afficher ces résultats\"> |
38 | <img style=\"vertical-align: text-bottom;\" src=\"images/moins.png\" alt=\"[-]\"/></a>"; |
39 | } |
40 | elseif($categorie->is_excluded()){ |
41 | $res+="<span style=\"text-decoration: line-through;\"> |
9b31f89c |
42 | <a href=\"?_C=".$exalead_data->query->context."&".$categorie->reset_href.";&_f=xml2\"> |
5476011b |
43 | <img style=\"vertical-align: text-bottom;\" src=\"images/select.png\" alt=\"[+]\" /> |
44 | ".$categorie->display.";</a> |
45 | </span>"; |
46 | } |
47 | else{ |
48 | $res+="<strong>".$categorie->display.";</strong> |
9b31f89c |
49 | <a href=\"?_C=".$exalead_data->query->context."&".$categorie->reset_href.";&_f=xml2\"> |
5476011b |
50 | <img style=\"vertical-align: text-bottom;\" src=\"images/moins.png\" alt=\"[-]\"/></a>"; |
51 | } |
52 | $res+="</li>"; |
53 | } |
54 | $res+=" </ul> |
55 | </div>"; |
56 | return $res; |
0337d704 |
57 | } |
58 | |
5476011b |
59 | |
60 | |
61 | |
0337d704 |
62 | function _display_groupes($params, &$smarty){ |
63 | |
64 | if(!empty($params['exalead_data'])){ |
65 | $exalead_data = &$GLOBALS[$params['exalead_data']]; |
66 | } |
67 | else{ |
68 | $exalead_data = &$GLOBALS['exalead_data']; |
69 | } |
70 | |
71 | foreach($exalead_data->groups as $group){ |
532148b4 |
72 | display_group($group, $exalead_data); |
0337d704 |
73 | } |
74 | |
75 | } |
76 | |
77 | function _display_keywords($params, &$smarty){ |
78 | if(!empty($params['exalead_data'])){ |
79 | $exalead_data = &$GLOBALS[$params['exalead_data']]; |
80 | } |
81 | else{ |
82 | $exalead_data = &$GLOBALS['exalead_data']; |
83 | } |
84 | |
85 | display_group($exalead_data->keywords, $exalead_data, true); |
86 | } |
87 | |
88 | function _exa_navigation_gauche($params, &$smarty){ |
89 | if(!empty($params['exalead_data'])){ |
90 | $exalead_data = &$GLOBALS[$params['exalead_data']]; |
91 | } |
92 | else{ |
93 | $exalead_data = &$GLOBALS['exalead_data']; |
94 | } |
95 | $res = ''; |
96 | if($exalead_data->start > 0){ |
97 | $debut_g = $exalead_data->start - 9; |
98 | $debut_d = $debut_g + 9; |
99 | if($debut_g < 0){ |
100 | $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=0\">[1-10]</a>"; |
101 | } |
102 | else{ |
103 | $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".($debut_g-1)."\">[$debut_g-$debut_d]</a>"; |
104 | } |
105 | } |
106 | return $res; |
107 | } |
108 | function _exa_navigation_droite($params, &$smarty){ |
109 | if(!empty($params['exalead_data'])){ |
110 | $exalead_data = &$GLOBALS[$params['exalead_data']]; |
111 | } |
112 | else{ |
113 | $exalead_data = &$GLOBALS['exalead_data']; |
114 | } |
115 | $max = -1; |
116 | if(!empty($params['max'])){ |
117 | $max = (int) $params['max']; |
118 | if(($max < 0) || ($max > $exalead_data->nhits)){ |
119 | $max = $exalead_data->nhits; |
120 | } |
121 | } |
122 | else{ |
123 | $max = $exalead_data->nhits; |
124 | } |
125 | $res = ''; |
126 | if(($exalead_data->end < $max) && ($max > 10)){ |
127 | $fin_g = $exalead_data->end + 1; |
128 | $fin_d = $fin_g + 10; |
129 | if($fin_d > $max){ |
130 | $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".($max-10)."\">[".($max-10)."-".($max)."]</a>"; |
131 | } |
132 | else{ |
133 | $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=$fin_g\">[".($fin_g+1)."-$fin_d]</a>"; |
134 | } |
135 | } |
136 | return $res; |
137 | } |
138 | |
139 | function _exa_navigation_barre($params, &$smarty){ |
140 | if(!empty($params['exalead_data'])){ |
141 | $exalead_data = &$GLOBALS[$params['exalead_data']]; |
142 | } |
143 | else{ |
144 | $exalead_data = &$GLOBALS['exalead_data']; |
145 | } |
146 | if(!empty($params['nb_res_per_page'])){ |
147 | $nb_res_per_page = (int) $params['nb_res_per_page']; |
148 | } |
149 | else |
150 | $nb_res_per_page = 10;//10 results per page |
151 | if(!empty($params['max_results']) && ((int) $params['max_results'] < $exalead_data->nhits)){ |
152 | $nb_hits = (int) $params['max_results']; |
153 | } |
154 | else{ |
155 | $nb_hits = (int) $exalead_data->nhits; |
156 | } |
831204ce |
157 | $date=false; |
158 | foreach($exalead_data->query->query_parameters as $parameter){ |
159 | if($parameter->name=="_sf"){ |
160 | if($parameter->value=="-date") |
161 | $date=true; |
162 | } |
163 | } |
164 | |
165 | |
0337d704 |
166 | $res = ''; |
167 | $nb_numero = 5;//We want 5 links |
168 | $current_page = (empty($_GET['_s'])?1:1+(int) ($_GET['_s'] / $nb_res_per_page)); |
169 | $first_number = 1; |
170 | if($nb_hits < ($nb_numero) * $nb_res_per_page){ |
171 | $nb_numero = (int) ($nb_hits / $nb_res_per_page); |
172 | } |
173 | else{ |
174 | if($current_page > ((int)$nb_numero/2)) |
175 | $first_number = 1 + $current_page - (int)($nb_numero/2); |
176 | if($nb_hits < (($first_number + $nb_numero - 1) * $nb_res_per_page)){ |
177 | $first_number = (int) ($nb_hits / $nb_res_per_page) - $nb_numero+2; |
178 | } |
179 | } |
180 | |
831204ce |
181 | if ($current_page*$nb_res_per_page >$nb_res_per_page){ |
182 | $res.="<a href=\"?_C={$exalead_data->query->context}&_s=".(($current_page-2)*$nb_res_per_page); |
183 | if($date) $res.="&_sf=-date"; |
184 | $res.="\">Précédent</a> "; |
0337d704 |
185 | } |
831204ce |
186 | for($i = $first_number; $i <= $nb_numero + $first_number; $i++){ |
187 | $k=$nb_res_per_page*($i-1)+1; |
188 | $j=$nb_res_per_page*$i; |
189 | if($i == $current_page){ |
190 | $res .= "<strong>$k-$j</strong> "; |
191 | } |
192 | elseif($k<=$nb_hits){ |
193 | $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".(($i-1)*$nb_res_per_page); |
194 | if($date) $res.="&_sf=-date"; |
195 | $res.="\">$k-$j</a> "; |
196 | } |
197 | } |
198 | if ($current_page*10<$nb_hits){ |
199 | $res.="<a href=\"?_C={$exalead_data->query->context}&_s=".(($current_page)*$nb_res_per_page); |
200 | if($date) $res.="&_sf=-date"; |
201 | $res.="\">Suivant</a>"; |
0337d704 |
202 | } |
0337d704 |
203 | if($date) |
831204ce |
204 | $res.=" - <a href=\"?_C={$exalead_data->query->context}&_f=xml2\">[Classer par pertinence]</a>"; |
0337d704 |
205 | else |
831204ce |
206 | $res.=" - <a href=\"?_C={$exalead_data->query->context}&_sf=-date&_f=xml2\">[Classer par date]</a>"; |
0337d704 |
207 | return $res; |
208 | } |
209 | |
210 | |
211 | function _little_nav_barre($params, &$smarty){ |
212 | if(!empty($params['exalead_data'])){ |
213 | $exalead_data = &$GLOBALS[$params['exalead_data']]; |
214 | } |
215 | else{ |
216 | $exalead_data = &$GLOBALS['exalead_data']; |
217 | } |
218 | $box=false; |
219 | if(!empty($params['where'])) |
220 | if($params['where']=='box') |
221 | $box=true; |
222 | $date=false; |
223 | foreach($exalead_data->query->query_parameters as $parameter){ |
224 | if($parameter->name=="_sf"){ |
225 | if($parameter->value=="-date") |
226 | $date=true; |
227 | } |
228 | } |
229 | $dizaine=10*(int)($exalead_data->start/10); |
230 | $res=""; |
231 | if ($box) |
232 | $res .= "<table>"; |
233 | else |
234 | $res.= "<table class=\"table\">"; |
235 | $res.="<tr>"; |
236 | if($box) |
237 | $res.="<td class=\"gauche\">"; |
238 | else |
239 | $res .=" <td width=\"20%\" style=\"text-align: left;\">"; |
240 | if($exalead_data->start != 0){ |
241 | $num=$exalead_data->start-1; |
d2f7c47a |
242 | $res .="<a href=\"?_C={$exalead_data->query->context}&_s=".$num."\">Précédent</a>"; |
0337d704 |
243 | } |
244 | $num=$exalead_data->start+1; |
245 | $res .= "</td>"; |
246 | if($box){ |
247 | $res.="<td class=\"centre\"> |
248 | CV : ".$num." / {$exalead_data->nhits}<br />"; |
249 | } |
250 | else{ |
251 | $res.="<td width=\"60%\" style=\"text-align: center;\"> |
252 | CV : ".$num." / {$exalead_data->nhits} -"; |
253 | } |
254 | if($date) |
9306cf48 |
255 | $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}&_sf=-date&_f=xml2&_s=".$dizaine."\">Retour à la recherche</a>"; |
0337d704 |
256 | else |
9306cf48 |
257 | $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}&_f=xml2&_s=".$dizaine."\">Retour à la recherche</a>"; |
0337d704 |
258 | $res .="</td>"; |
259 | if($box) |
260 | $res.="<td class=\"droite\">"; |
261 | else |
262 | $res .= "<td width=\"20%\" style=\"text-align: right;\">"; |
263 | $num=$exalead_data->start+1; |
264 | if( $exalead_data->start+1 < $exalead_data->nhits) |
265 | $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".$num."\">Suivant</a>"; |
266 | $res .="</td> |
267 | </tr> |
268 | </table>"; |
269 | return $res; |
270 | } |
271 | |
272 | //categorie = true if this line is for a category, false if this is for a keyword |
1d0df6fb |
273 | function _display_3_columns($title, $count, $refine, $exclude, $categorie,$hide=-1){ |
0337d704 |
274 | if ($title!='Inconnu'){ |
275 | global $exa_max_length; |
e583e6bb |
276 | if($categorie) $title_exclude = 'Ne pas afficher cette catégorie'; |
277 | else $title_exclude = 'Ne pas afficher ce mot-clé'; |
0337d704 |
278 | $extract = ((strlen($title) > $exa_max_length + 3)?substr($title,0,$exa_max_length).'...':$title); |
1d0df6fb |
279 | $result="<tr class=\"categ\""; |
280 | if ($hide>0) { |
e583e6bb |
281 | $result .= " id=\"cache_$hide\" onclick=\"cacheId('cache_$hide')\"";//Pour pouvoir cacher des catégories |
1d0df6fb |
282 | } |
283 | $result.="> |
284 | <td> |
285 | <a style=\"text-decoration: none;\" |
286 | href=\"?_C=".$refine."&_f=xml2\" |
287 | title=\"$title\" |
288 | >$extract</a></td><td width=\"10%\">$count</td><td width=\"10%\"> |
289 | <a href=\"?_C=".$exclude."&_f=xml2\" |
290 | title=\"$title_exclude\">[-]</a></td> |
291 | </tr>"; |
292 | |
293 | return $result; |
0337d704 |
294 | } |
295 | } |
296 | |
297 | //excluded = true if this line is an excluded result, = false if this line is a refined result |
298 | //categorie = true if this line is for a category, false if this is for a keyword |
299 | function _display_2_columns($title, $reset, $excluded, $categorie){ |
300 | global $exa_max_length; |
301 | if($excluded){ |
e583e6bb |
302 | if($categorie) $title_link = 'Afficher de nouveau cette catégorie'; |
303 | else $title_link = 'Afficher de nouveau ce mot-clé'; |
0337d704 |
304 | $link = '[+]'; |
305 | $style = 'text-decoration: line-through;'; |
306 | } else{ |
e583e6bb |
307 | if($categorie) $title_link = 'Voir les autres catégories'; |
308 | else $title_link = 'Voir les autres mots-clés'; |
0337d704 |
309 | $link = '[-]'; |
310 | $style = 'text-decoration: none; font-weight: bold;'; |
311 | } |
312 | $extract = ((strlen($title) > $exa_max_length + 3)?substr($title,0,$exa_max_length).'...':$title); |
313 | return "<tr class=\"categ\"> |
314 | <td colspan=\"2\"> |
315 | <a style=\"$style\" href=\"?_C=".$reset."&_f=xml2\" |
316 | title=\"$title\">$extract</a> |
317 | </td> |
318 | <td width=\"10%\"><a style=\"$style\" |
319 | href=\"?_C=".$reset."&_f=xml2\" |
320 | title=\"$title_link\" |
321 | >$link</a> |
322 | </td> |
323 | </tr>"; |
324 | } |
325 | |
1d0df6fb |
326 | function _display_resume_groupe_category(&$group, $context, $padding = '',$limit=100){ |
327 | $result = ''; |
328 | $cnt=0; |
329 | foreach($group->categories as $categorie){ |
330 | $cnt ++; |
331 | if($cnt==$limit) break; |
0337d704 |
332 | $title = (empty($categorie->display)?$categorie->name:$categorie->display); |
333 | $count = (empty($categorie->count)?'':' ('.$categorie->count.')'); |
f8646c5d |
334 | $categorie->refine_href=str_replace('/_c=', '/&_c=', $categorie->refine_href);//correction d'un bug |
9b31f89c |
335 | $refine = $context.'&'.$categorie->refine_href; |
1d0df6fb |
336 | $exclude = $context.'&'.$categorie->exclude_href; |
337 | $reset = $context.'&'.$categorie->reset_href; |
0337d704 |
338 | |
1d0df6fb |
339 | if ($categorie->display != '') { |
340 | if($categorie->is_normal()){ |
341 | $result .= _display_3_columns($padding.$title, $count, $refine, $exclude, '',$cnt-$limit); |
342 | } |
343 | else{ |
344 | $result .= _display_2_columns($padding.$title, $reset, $categorie->is_excluded(),'', $cnt-$limit); |
345 | } |
346 | } |
e583e6bb |
347 | if(count($categorie->categories) > 0 && ($_SESSION['show_all']||$title=="france"||!$categorie->is_normal()) ){ |
348 | $result .= _display_resume_groupe_category($categorie, $context, $pagging.'-',$limit-$cnt); |
1d0df6fb |
349 | } |
350 | } |
351 | return $result; |
0337d704 |
352 | } |
353 | |
354 | /** |
355 | * This function is used to resume database content for given group (template argument 'groupe') |
356 | */ |
357 | function _display_resume_groupe($params, &$smarty){ |
358 | global $exa_max_length; |
359 | if(!empty($params['exalead_data'])){ |
360 | $exalead_data = &$GLOBALS[$params['exalead_data']]; |
361 | } |
362 | else{ |
363 | $exalead_data = &$GLOBALS['exalead_data']; |
364 | } |
365 | if(empty($params['groupe'])){ |
366 | return ''; |
367 | } |
368 | $groupe = $params['groupe']; |
369 | $name = $params['display']; |
370 | foreach($exalead_data->groups as $group){ |
371 | if($group->title == $groupe){ |
1d0df6fb |
372 | if($groupe=="Zone"){ |
373 | if($_SESSION["show_all"]) { |
374 | $result = "<table class=\"exa_resume\"><th colspan=\"2\" class=\"titre\">".gettext($name)."</th> |
375 | <th><a href=\"anciens_cherche_offres_exa.php?hide=1&".$params['url']."\"><img src='images/icons/fww.gif'/></a></th>"; |
376 | |
377 | } |
378 | else{ |
379 | $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>"; |
380 | } |
381 | $result .= _display_resume_groupe_category($group, $exalead_data->query->context,'',$params['limit']); |
382 | } |
383 | else{ |
384 | $result = "<table class=\"exa_resume\"><th colspan=\"3\" class=\"titre\">".gettext($name)."</th>"; |
e583e6bb |
385 | if (isset($params['limit']) && $params['limit']>0) |
386 | { |
387 | $result .= _display_resume_groupe_category($group, $exalead_data->query->context,'',$params['limit']); |
388 | |
389 | }else |
390 | { |
391 | $result .= _display_resume_groupe_category($group, $exalead_data->query->context); |
392 | } |
1d0df6fb |
393 | } |
0337d704 |
394 | $result .= "</table>"; |
395 | return $result; |
396 | } |
397 | } |
398 | } |
399 | |
400 | /** |
401 | * This function is used to resume database content for keywords |
402 | */ |
403 | function _display_resume_keywords($params, &$smarty){ |
404 | global $exa_max_length; |
405 | if(!empty($params['exalead_data'])){ |
406 | $exalead_data = &$GLOBALS[$params['exalead_data']]; |
407 | } |
408 | else{ |
409 | $exalead_data = &$GLOBALS['exalead_data']; |
410 | } |
411 | |
412 | //if no keywrods, do not display anything |
413 | if(count($exalead_data->keywords) == 0) return ''; |
414 | $name=$params['display']; |
415 | $result = "<table class=\"exa_resume\"><th colspan=\"3\" class=\"titre\">".gettext($name)."</th>"; |
416 | foreach($exalead_data->keywords as $keyword){ |
417 | if($keyword->display != ''){ |
418 | $title = (empty($keyword->display)?$keyword->name:$keyword->display); |
419 | $count = (empty($keyword->count)?'':' ('.$keyword->count.')'); |
420 | $refine = $exalead_data->query->context.'/'.$keyword->refine_href; |
421 | $exclude = $exalead_data->query->context.'/'.$keyword->exclude_href; |
422 | $reset = $exalead_data->query->context.'/'.$keyword->reset_href; |
423 | if($keyword->is_normal()){ |
424 | $result .= _display_3_columns($title, $count, $refine, $exclude, false); |
425 | } |
426 | else{ |
427 | $result .= _display_2_columns($title, $reset, $keyword->is_excluded(), false); |
428 | } |
429 | } |
430 | } |
431 | $result .= "</table>"; |
432 | return $result; |
433 | } |
434 | |
435 | function register_smarty_exalead(&$page){ |
436 | $page->register_function('little_nav_barre','_little_nav_barre'); |
437 | $page->register_function('exa_display_groupes', '_display_groupes'); |
438 | $page->register_function('exa_display_resume_groupe', '_display_resume_groupe'); |
439 | $page->register_function('exa_display_resume_keywords', '_display_resume_keywords'); |
440 | $page->register_function('exa_display_keywords', '_display_keywords'); |
441 | $page->register_function('exa_navigation_gauche', '_exa_navigation_gauche'); |
442 | $page->register_function('exa_navigation_droite', '_exa_navigation_droite'); |
443 | $page->register_function('exa_navigation_barre', '_exa_navigation_barre'); |
444 | } |
445 | |
446 | if(isset($page)){ |
447 | register_smarty_exalead($page); |
448 | } |
449 | |
450 | ?> |