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