first reimport from platal
[platal.git] / include / exalead / exalead.smarty.inc.php
1 <?php
2
3
4 $exa_max_length = 15;
5
6 function display_group(&$group, &$exalead_data, $keywords=false,$class = 'exa_groupe', $img_path = 'images/'){
7 $compteur = 0;
8 $titre = ($keywords)?'Mot-clés':$group->title;
9 $gid = ($keywords)?'k':$group->gid;
10 if($keywords)
11 $array = & $group;
12 else
13 $array = & $group->categories;
14 ?>
15 <div class="exa_groupe">
16 <div class="titre"><?php echo $titre?> :</div>
17 <ul id="exa_group_<?php echo $gid?>">
18 <?php
19 foreach($array as $categorie){
20 $compteur++;
21 ?>
22 <li class="exa_categorie" id="exa_group_<?php echo $gid.'_'.$compteur;?>">
23 <?php
24 if($categorie->is_normal()){
25 ?>
26 <a style="text-decoration: none;"
27 href="?_C=<?php echo $exalead_data->query->context.'/'.$categorie->refine_href;?>&amp;_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;?>&amp;_f=xml2"
31 title="Ne pas afficher ces résultats"
32 ><img style="vertical-align: text-bottom;" src="images/moins.png" alt="[-]"/></a>
33 <?php
34 }
35 elseif($categorie->is_excluded()){
36 ?>
37 <span style="text-decoration: line-through;">
38 <a href="?_C=<?php echo $exalead_data->query->context.'/'.$categorie->reset_href;?>&amp;_f=xml2"><img style="vertical-align: text-bottom;" src="images/select.png" alt="[+]" /> <?php echo $categorie->display;?></a>
39 </span>
40 <?php
41 }
42 else{
43 ?>
44 <strong><?php echo $categorie->display;?></strong>
45 <a href="?_C=<?php echo $exalead_data->query->context.'/'.$categorie->reset_href;?>&amp;_f=xml2"><img style="vertical-align: text-bottom;" src="images/moins.png" alt="[-]"/></a>
46 <?php
47 }
48 echo '</li>';
49 }
50 ?>
51 </ul>
52 </div>
53 <?php
54 }
55
56 function _display_groupes($params, &$smarty){
57
58 if(!empty($params['exalead_data'])){
59 $exalead_data = &$GLOBALS[$params['exalead_data']];
60 }
61 else{
62 $exalead_data = &$GLOBALS['exalead_data'];
63 }
64
65 foreach($exalead_data->groups as $group){
66 display_group($group, $exalead_data);
67 }
68
69 }
70
71 function _display_keywords($params, &$smarty){
72 if(!empty($params['exalead_data'])){
73 $exalead_data = &$GLOBALS[$params['exalead_data']];
74 }
75 else{
76 $exalead_data = &$GLOBALS['exalead_data'];
77 }
78
79 display_group($exalead_data->keywords, $exalead_data, true);
80 }
81
82 function _exa_navigation_gauche($params, &$smarty){
83 if(!empty($params['exalead_data'])){
84 $exalead_data = &$GLOBALS[$params['exalead_data']];
85 }
86 else{
87 $exalead_data = &$GLOBALS['exalead_data'];
88 }
89 $res = '';
90 if($exalead_data->start > 0){
91 $debut_g = $exalead_data->start - 9;
92 $debut_d = $debut_g + 9;
93 if($debut_g < 0){
94 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=0\">[1-10]</a>";
95 }
96 else{
97 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".($debut_g-1)."\">[$debut_g-$debut_d]</a>";
98 }
99 }
100 return $res;
101 }
102 function _exa_navigation_droite($params, &$smarty){
103 if(!empty($params['exalead_data'])){
104 $exalead_data = &$GLOBALS[$params['exalead_data']];
105 }
106 else{
107 $exalead_data = &$GLOBALS['exalead_data'];
108 }
109 $max = -1;
110 if(!empty($params['max'])){
111 $max = (int) $params['max'];
112 if(($max < 0) || ($max > $exalead_data->nhits)){
113 $max = $exalead_data->nhits;
114 }
115 }
116 else{
117 $max = $exalead_data->nhits;
118 }
119 $res = '';
120 if(($exalead_data->end < $max) && ($max > 10)){
121 $fin_g = $exalead_data->end + 1;
122 $fin_d = $fin_g + 10;
123 if($fin_d > $max){
124 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".($max-10)."\">[".($max-10)."-".($max)."]</a>";
125 }
126 else{
127 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=$fin_g\">[".($fin_g+1)."-$fin_d]</a>";
128 }
129 }
130 return $res;
131 }
132
133 function _exa_navigation_barre($params, &$smarty){
134 if(!empty($params['exalead_data'])){
135 $exalead_data = &$GLOBALS[$params['exalead_data']];
136 }
137 else{
138 $exalead_data = &$GLOBALS['exalead_data'];
139 }
140 if(!empty($params['nb_res_per_page'])){
141 $nb_res_per_page = (int) $params['nb_res_per_page'];
142 }
143 else
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'];
147 }
148 else{
149 $nb_hits = (int) $exalead_data->nhits;
150 }
151 $res = '';
152 $nb_numero = 5;//We want 5 links
153 $current_page = (empty($_GET['_s'])?1:1+(int) ($_GET['_s'] / $nb_res_per_page));
154 $first_number = 1;
155 if($nb_hits < ($nb_numero) * $nb_res_per_page){
156 $nb_numero = (int) ($nb_hits / $nb_res_per_page);
157 }
158 else{
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;
163 }
164 }
165
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> ";
173 }
174 else{
175 $res .= "<a href=\"?_C={$exalead_data->query->context}&_s=".(($i-1)*$nb_res_per_page)."\">$k-$j</a> ";
176 }
177 }
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>";
180 $date=false;
181 foreach($exalead_data->query->query_parameters as $parameter){
182 if($parameter->name=="_sf"){
183 if($parameter->value=="-date")
184 $date=true;
185 }
186 }
187
188 if($date)
189 $res.=" - <a href=\"?_C={$exalead_data->query->context}/_sf=relevance&amp;_f=xml2\">[Classer par pertinence]</a>";
190 else
191 $res.=" - <a href=\"?_C={$exalead_data->query->context}/_sf=-date&amp;_f=xml2\">[Classer par date]</a>";
192 return $res;
193 }
194
195
196 function _little_nav_barre($params, &$smarty){
197 if(!empty($params['exalead_data'])){
198 $exalead_data = &$GLOBALS[$params['exalead_data']];
199 }
200 else{
201 $exalead_data = &$GLOBALS['exalead_data'];
202 }
203 $box=false;
204 if(!empty($params['where']))
205 if($params['where']=='box')
206 $box=true;
207 $date=false;
208 foreach($exalead_data->query->query_parameters as $parameter){
209 if($parameter->name=="_sf"){
210 if($parameter->value=="-date")
211 $date=true;
212 }
213 }
214 $dizaine=10*(int)($exalead_data->start/10);
215 $res="";
216 if ($box)
217 $res .= "<table>";
218 else
219 $res.= "<table class=\"table\">";
220 $res.="<tr>";
221 if($box)
222 $res.="<td class=\"gauche\">";
223 else
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>";
228 }
229 $num=$exalead_data->start+1;
230 $res .= "</td>";
231 if($box){
232 $res.="<td class=\"centre\">
233 CV : ".$num." / {$exalead_data->nhits}<br />";
234 }
235 else{
236 $res.="<td width=\"60%\" style=\"text-align: center;\">
237 CV : ".$num." / {$exalead_data->nhits} -";
238 }
239 if($date)
240 $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}/_sf=-date&amp;_f=xml2&amp;_s=".$dizaine."\">Retour à la recherche</a>";
241 else
242 $res.="<a href=\"ec_cherche_cv.php?_C={$exalead_data->query->context}/_sf=-relevance&amp;_f=xml2&amp;_s=".$dizaine."\">Retour à la recherche</a>";
243 $res .="</td>";
244 if($box)
245 $res.="<td class=\"droite\">";
246 else
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>";
251 $res .="</td>
252 </tr>
253 </table>";
254 return $res;
255 }
256
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\">
265 <td>
266 <a style=\"text-decoration: none;\"
267 href=\"?_C=".$refine."&amp;_f=xml2\"
268 title=\"$title\"
269 >$extract</a></td><td width=\"10%\">$count</td><td width=\"10%\">
270 <a href=\"?_C=".$exclude."&amp;_f=xml2\"
271 title=\"$title_exclude\">[-]</a></td>
272 </tr>";
273 }
274 }
275
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;
280 if($excluded){
281 if($categorie) $title_link = 'Afficher de nouveau cette catégorie';
282 else $title_link = 'Afficher de nouveau ce mot-clé';
283 $link = '[+]';
284 $style = 'text-decoration: line-through;';
285 } else{
286 if($categorie) $title_link = 'Voir les autres catégories';
287 else $title_link = 'Voir les autres mots-clés';
288 $link = '[-]';
289 $style = 'text-decoration: none; font-weight: bold;';
290 }
291 $extract = ((strlen($title) > $exa_max_length + 3)?substr($title,0,$exa_max_length).'...':$title);
292 return "<tr class=\"categ\">
293 <td colspan=\"2\">
294 <a style=\"$style\" href=\"?_C=".$reset."&amp;_f=xml2\"
295 title=\"$title\">$extract</a>
296 </td>
297 <td width=\"10%\"><a style=\"$style\"
298 href=\"?_C=".$reset."&amp;_f=xml2\"
299 title=\"$title_link\"
300 >$link</a>
301 </td>
302 </tr>";
303 }
304
305 function _display_resume_groupe_category(&$group, $context, $padding = ''){
306 $result = '';
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;
313
314 if($categorie->display != ''){
315 if($categorie->is_normal()){
316 $result .= _display_3_columns($padding.$title, $count, $refine, $exclude, true);
317 }
318 else{
319 $result .= _display_2_columns($padding.$title, $reset, $categorie->is_excluded(), true);
320 }
321 }
322 if(count($categorie->categories) > 0){
323 $result .= _display_resume_groupe_category($categorie, $context, $padding.'-');
324 }
325 }
326 return $result;
327 }
328
329 /**
330 * This function is used to resume database content for given group (template argument 'groupe')
331 */
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']];
336 }
337 else{
338 $exalead_data = &$GLOBALS['exalead_data'];
339 }
340 if(empty($params['groupe'])){
341 return '';
342 }
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>";
350 return $result;
351 }
352 }
353 }
354
355 /**
356 * This function is used to resume database content for keywords
357 */
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']];
362 }
363 else{
364 $exalead_data = &$GLOBALS['exalead_data'];
365 }
366
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);
380 }
381 else{
382 $result .= _display_2_columns($title, $reset, $keyword->is_excluded(), false);
383 }
384 }
385 }
386 $result .= "</table>";
387 return $result;
388 }
389
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');
399 }
400
401 if(isset($page)){
402 register_smarty_exalead($page);
403 }
404
405 ?>