backport
[platal.git] / include / exalead / exalead.smarty.inc.php
CommitLineData
0337d704 1<?php
2
5476011b 3$exa_max_length = 16;
0337d704 4
5function 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.";?>&amp;_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.";&amp;_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.";&amp;_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.";&amp;_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 62function _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
77function _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
88function _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}
108function _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
139function _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 }
157 $res = '';
158 $nb_numero = 5;//We want 5 links
159 $current_page = (empty($_GET['_s'])?1:1+(int) ($_GET['_s'] / $nb_res_per_page));
160 $first_number = 1;
161 if($nb_hits < ($nb_numero) * $nb_res_per_page){
162 $nb_numero = (int) ($nb_hits / $nb_res_per_page);
163 }
164 else{
165 if($current_page > ((int)$nb_numero/2))
166 $first_number = 1 + $current_page - (int)($nb_numero/2);
167 if($nb_hits < (($first_number + $nb_numero - 1) * $nb_res_per_page)){
168 $first_number = (int) ($nb_hits / $nb_res_per_page) - $nb_numero+2;
169 }
170 }
171
172 if ($current_page*$nb_res_per_page >$nb_res_per_page)
173 $res.="<a href=\"?_C={$exalead_data->query->context}&_s=".(($current_page-2)*$nb_res_per_page)."\">Precedent</a> ";
174 for($i = $first_number; $i <= $nb_numero + $first_number-1; $i++){
175 $k=$nb_res_per_page*($i-1)+1;
176 $j=$nb_res_per_page*$i;
177 if($i == $current_page){
178 $res .= "<strong>$k-$j</strong> ";
179 }
180 else{
181 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".(($i-1)*$nb_res_per_page)."\">$k-$j</a> ";
182 }
183 }
184 if ($current_page*10<$nb_hits)
185 $res.="<a href=\"?_C={$exalead_data->query->context}&_s=".(($current_page)*$nb_res_per_page)."\">Suivant</a>";
186 $date=false;
187 foreach($exalead_data->query->query_parameters as $parameter){
188 if($parameter->name=="_sf"){
189 if($parameter->value=="-date")
190 $date=true;
191 }
192 }
193
194 if($date)
816226aa 195 $res.=" - <a href=\"?_C={$exalead_data->query->context}&amp;_sf=relevance&amp;_f=xml2\">[Classer par pertinence]</a>";
0337d704 196 else
816226aa 197 $res.=" - <a href=\"?_C={$exalead_data->query->context}&amp;_sf=-date&amp;_f=xml2\">[Classer par date]</a>";
0337d704 198 return $res;
199}
200
201
202function _little_nav_barre($params, &$smarty){
203 if(!empty($params['exalead_data'])){
204 $exalead_data = &$GLOBALS[$params['exalead_data']];
205 }
206 else{
207 $exalead_data = &$GLOBALS['exalead_data'];
208 }
209 $box=false;
210 if(!empty($params['where']))
211 if($params['where']=='box')
212 $box=true;
213 $date=false;
214 foreach($exalead_data->query->query_parameters as $parameter){
215 if($parameter->name=="_sf"){
216 if($parameter->value=="-date")
217 $date=true;
218 }
219 }
220 $dizaine=10*(int)($exalead_data->start/10);
221 $res="";
222 if ($box)
223 $res .= "<table>";
224 else
225 $res.= "<table class=\"table\">";
226 $res.="<tr>";
227 if($box)
228 $res.="<td class=\"gauche\">";
229 else
230 $res .=" <td width=\"20%\" style=\"text-align: left;\">";
231 if($exalead_data->start != 0){
232 $num=$exalead_data->start-1;
9b31f89c 233 $res .="<a href=\"?_C={$exalead_data->query->context}&_s=".$num."\">Précédent</a>";
0337d704 234 }
235 $num=$exalead_data->start+1;
236 $res .= "</td>";
237 if($box){
238 $res.="<td class=\"centre\">
239 CV : ".$num." / {$exalead_data->nhits}<br />";
240 }
241 else{
242 $res.="<td width=\"60%\" style=\"text-align: center;\">
243 CV : ".$num." / {$exalead_data->nhits} -";
244 }
245 if($date)
9b31f89c 246 $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}/_sf=-date&amp;_f=xml2&amp;_s=".$dizaine."\">Retour à la recherche</a>";
0337d704 247 else
9b31f89c 248 $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}/_sf=-relevance&amp;_f=xml2&amp;_s=".$dizaine."\">Retour à la recherche</a>";
0337d704 249 $res .="</td>";
250 if($box)
251 $res.="<td class=\"droite\">";
252 else
253 $res .= "<td width=\"20%\" style=\"text-align: right;\">";
254 $num=$exalead_data->start+1;
255 if( $exalead_data->start+1 < $exalead_data->nhits)
256 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".$num."\">Suivant</a>";
257 $res .="</td>
258 </tr>
259 </table>";
260 return $res;
261}
262
263//categorie = true if this line is for a category, false if this is for a keyword
264function _display_3_columns($title, $count, $refine, $exclude, $categorie){
265if ($title!='Inconnu'){
266 global $exa_max_length;
9b31f89c 267 if($categorie) $title_exclude = 'Ne pas afficher cette catégorie';
268 else $title_exclude = 'Ne pas afficher ce mot-clé';
0337d704 269 $extract = ((strlen($title) > $exa_max_length + 3)?substr($title,0,$exa_max_length).'...':$title);
270 return "<tr class=\"categ\">
271 <td>
272 <a style=\"text-decoration: none;\"
273 href=\"?_C=".$refine."&amp;_f=xml2\"
274 title=\"$title\"
275 >$extract</a></td><td width=\"10%\">$count</td><td width=\"10%\">
276 <a href=\"?_C=".$exclude."&amp;_f=xml2\"
277 title=\"$title_exclude\">[-]</a></td>
278 </tr>";
279}
280}
281
282//excluded = true if this line is an excluded result, = false if this line is a refined result
283//categorie = true if this line is for a category, false if this is for a keyword
284function _display_2_columns($title, $reset, $excluded, $categorie){
285 global $exa_max_length;
286 if($excluded){
9b31f89c 287 if($categorie) $title_link = 'Afficher de nouveau cette catégorie';
288 else $title_link = 'Afficher de nouveau ce mot-clé';
0337d704 289 $link = '[+]';
290 $style = 'text-decoration: line-through;';
291 } else{
9b31f89c 292 if($categorie) $title_link = 'Voir les autres catégories';
293 else $title_link = 'Voir les autres mots-clés';
0337d704 294 $link = '[-]';
295 $style = 'text-decoration: none; font-weight: bold;';
296 }
297 $extract = ((strlen($title) > $exa_max_length + 3)?substr($title,0,$exa_max_length).'...':$title);
298 return "<tr class=\"categ\">
299 <td colspan=\"2\">
300 <a style=\"$style\" href=\"?_C=".$reset."&amp;_f=xml2\"
301 title=\"$title\">$extract</a>
302 </td>
303 <td width=\"10%\"><a style=\"$style\"
304 href=\"?_C=".$reset."&amp;_f=xml2\"
305 title=\"$title_link\"
306 >$link</a>
307 </td>
308 </tr>";
309}
310
311function _display_resume_groupe_category(&$group, $context, $padding = ''){
312 $result = '';
313 foreach($group->categories as $categorie){
314 $title = (empty($categorie->display)?$categorie->name:$categorie->display);
315 $count = (empty($categorie->count)?'':' ('.$categorie->count.')');
9b31f89c 316 $refine = $context.'&'.$categorie->refine_href;
317 $exclude = $context.'&'.$categorie->exclude_href;
318 $reset = $context.'&'.$categorie->reset_href;
0337d704 319
320 if($categorie->display != ''){
321 if($categorie->is_normal()){
322 $result .= _display_3_columns($padding.$title, $count, $refine, $exclude, true);
323 }
324 else{
325 $result .= _display_2_columns($padding.$title, $reset, $categorie->is_excluded(), true);
326 }
327 }
328 if(count($categorie->categories) > 0){
329 $result .= _display_resume_groupe_category($categorie, $context, $padding.'-');
330 }
331 }
332 return $result;
333}
334
335/**
336* This function is used to resume database content for given group (template argument 'groupe')
337*/
338function _display_resume_groupe($params, &$smarty){
339 global $exa_max_length;
340 if(!empty($params['exalead_data'])){
341 $exalead_data = &$GLOBALS[$params['exalead_data']];
342 }
343 else{
344 $exalead_data = &$GLOBALS['exalead_data'];
345 }
346 if(empty($params['groupe'])){
347 return '';
348 }
349 $groupe = $params['groupe'];
350 $name = $params['display'];
351 foreach($exalead_data->groups as $group){
352 if($group->title == $groupe){
353 $result = "<table class=\"exa_resume\"><th colspan=\"3\" class=\"titre\">".gettext($name)."</th>";
354 $result .= _display_resume_groupe_category($group, $exalead_data->query->context);
355 $result .= "</table>";
356 return $result;
357 }
358 }
359}
360
361/**
362* This function is used to resume database content for keywords
363*/
364function _display_resume_keywords($params, &$smarty){
365 global $exa_max_length;
366 if(!empty($params['exalead_data'])){
367 $exalead_data = &$GLOBALS[$params['exalead_data']];
368 }
369 else{
370 $exalead_data = &$GLOBALS['exalead_data'];
371 }
372
373 //if no keywrods, do not display anything
374 if(count($exalead_data->keywords) == 0) return '';
375 $name=$params['display'];
376 $result = "<table class=\"exa_resume\"><th colspan=\"3\" class=\"titre\">".gettext($name)."</th>";
377 foreach($exalead_data->keywords as $keyword){
378 if($keyword->display != ''){
379 $title = (empty($keyword->display)?$keyword->name:$keyword->display);
380 $count = (empty($keyword->count)?'':' ('.$keyword->count.')');
381 $refine = $exalead_data->query->context.'/'.$keyword->refine_href;
382 $exclude = $exalead_data->query->context.'/'.$keyword->exclude_href;
383 $reset = $exalead_data->query->context.'/'.$keyword->reset_href;
384 if($keyword->is_normal()){
385 $result .= _display_3_columns($title, $count, $refine, $exclude, false);
386 }
387 else{
388 $result .= _display_2_columns($title, $reset, $keyword->is_excluded(), false);
389 }
390 }
391 }
392 $result .= "</table>";
393 return $result;
394}
395
396function register_smarty_exalead(&$page){
397 $page->register_function('little_nav_barre','_little_nav_barre');
398 $page->register_function('exa_display_groupes', '_display_groupes');
399 $page->register_function('exa_display_resume_groupe', '_display_resume_groupe');
400 $page->register_function('exa_display_resume_keywords', '_display_resume_keywords');
401 $page->register_function('exa_display_keywords', '_display_keywords');
402 $page->register_function('exa_navigation_gauche', '_exa_navigation_gauche');
403 $page->register_function('exa_navigation_droite', '_exa_navigation_droite');
404 $page->register_function('exa_navigation_barre', '_exa_navigation_barre');
405}
406
407if(isset($page)){
408 register_smarty_exalead($page);
409}
410
411?>