The Higher Education and Research forge

Home My Page Projects Code Snippets Project Openings MonLabo
Summary Activity Tracker Tasks Docs SCM Files Dokuwiki Continious Integration Listes Sympa

SCM Repository

1 <?php
2 //error_reporting(E_ALL);
3 //ini_set('display_errors',1);
4 if (!defined('WP_PLUGIN_DIR')) exit('No direct script access allowed');
6 require_once( __DIR__ . '/MonLabo_shortcodes.php' );
8 /**
9  * Class MonLabo_shortcodes_publications
10  *
11  * @package
12  */
14 class MonLabo_shortcodes_publications extends MonLabo_shortcodes_mother_class {
15     /*
16         static function suppress_bibtex_value_limiter($string)
18         static function custom_publications_list                ($atts)
19         static function custom_publications_list_web            ($atts, $webservice_class_name='MonLabo_contact_webservices')
20         static function custom_publications_list_preprare_url   ($atts)
22         static function publications_list                   ($atts)
23         static function publications_list_web               ($atts,  $webservice_class_name='MonLabo_contact_webservices')
24         static function publications_list_prepare_url       ($years, $units="", $teams="")
26         static function parse_haltools_response ($hal_content = "")
27         static function format_publi            ($format = "ieee", $data_publi, $currentlang)
28         static function bibtex_to_ieee_authors  ($authors_bib_string)
29         static function bibtex_to_apa_authors   ($authors_bib_string)
30         static function format_bib_field        ($array, $field, $format )
32     */
34     private static function _MonLaboPersonsIds_into_publicationServerAuthorsIds($persons_id) {
35         return self::_MonLabo__item__ids_into_publicationServer__item__ids($persons_id, "person");
36     }
38     private static function _MonLaboTeamsIds_into_publicationServerTeamsIds($teams_id) {
39         return self::_MonLabo__item__ids_into_publicationServer__item__ids($teams_id, "team");
40     }
42     private static function _MonLaboUnitsIds_into_publicationServerUnitsIds($units_id) {
43         return self::_MonLabo__item__ids_into_publicationServer__item__ids($units_id, "unit");
44     }
46     private static function _MonLabo__item__ids_into_publicationServer__item__ids($items_id, $type_of_item) {
47         $publication_database_ids=array();
48         if (!empty($items_id)) {
49             $field_name="";
50             $options4 = get_option( 'MonLabo_settings_group4' );
51             switch ($type_of_item) {
52                 case 'person':
53                     if ($options4["MonLabo_uses_descartes_publi"]=="1") {
54                         $field_name="descartes_publi_author_id";
55                     } elseif ($options4["MonLabo_uses_hal_publi"]=="1") {
56                         $field_name="hal_publi_author_id";
57                     }
58                     $get_item_information_function_name="get_person_information";
59                     break;
60                 case 'team':
61                     if ($options4["MonLabo_uses_descartes_publi"]=="1") {
62                         $field_name="descartes_publi_team_id";
63                     } elseif ($options4["MonLabo_uses_hal_publi"]=="1") {
64                         $field_name="hal_publi_team_id";
65                     }
66                     $get_item_information_function_name="get_team_information";
67                     break;
68                 case 'unit':
69                     if ($options4["MonLabo_uses_descartes_publi"]=="1") {
70                         $field_name="descartes_publi_unit_id";
71                     } elseif ($options4["MonLabo_uses_hal_publi"]=="1") {
72                         $field_name="hal_publi_unit_id";
73                     }
74                     $get_item_information_function_name="get_unit_information";
75                     break;
76             }
77             if(!empty($field_name)) {
78                 $MonLabo_access_data = New MonLabo_access_data();
79                 foreach ($items_id as $item_id) {
80                     $the_item = $MonLabo_access_data->$get_item_information_function_name($item_id);
81                     if ((!empty($the_item)) and (!empty($the_item->$field_name))) {
82                         $publication_database_ids=array_merge($publication_database_ids,MonLaboLib::prepare_multiple_values_variable_into_array($the_item->$field_name));
83                     }
84                 }
85             }
86         }
87         return array_unique($publication_database_ids);
88     }
90     //==========================================================================
91     /**
92      * Supprimer les carractères entourant une chaine parmis les carractères
93      * quotes, doubles quotes, accolades ou doubles accolades.
94      * @param string $string Chaine à traiter
95      * @return string Chaine traitée
96      */
97     //==========================================================================
98     static function suppress_bibtex_value_limiter($string) {
99         $string=trim($string);
100         $size=strlen($string)-1;
101         if ($size>0){
102             if($string[0]==$string[$size]) {
103                 if(($string[0]=='"') or ($string[0]=="'")) {
104                     $string=substr($string, 1, -1);  //Si "chaine" ou 'chaine'
105                 }
106             } elseif(($string[0]=='{') and ($string[$size]=='}')) {
107                 if ($size>3){
108                     if(($string[1]=='{') and ($string[$size-1]=='}')) {
109                         $string=substr($string, 1, -1); //Si {{chaine}}
110                     }
111                 }
112                 $string=substr($string, 1, -1); //Si {chaine} ou {{chaine}}
113             }
114         }
115         return trim($string);
116     }
118     static function build_HAL_POST_query($years, $languageHAL, $style_citation_reference) {
119         $POST_query=array();
121         //Calcul des paramètres des années
122         //--------------------------------
123         if(strlen($years)>0) {
124             $anneeMinAndMax = explode("-", $years);
125             $anneeMin = $anneeMinAndMax[0];
126             if(count($anneeMinAndMax)>1) {
127                 $anneeMax = $anneeMinAndMax[1];
128             } else {
129                 $anneeMax = $anneeMinAndMax[0];
130             }
131             if (!empty($anneeMin)) {
132                 $POST_query["annee_publideb"]="$anneeMin";
133                 if (!empty($anneeMax)) {
134                     $POST_query["annee_publifin"]="$anneeMax";
135                 }
136             } else {
137                 if (!empty($anneeMax)) {
138                     $POST_query["annee_publifin"]="$anneeMax";
139                 }
140             }
141         }
143         //Calcul des autres paramètres de requête
144         //---------------------------------------
145         $POST_query["tri_exp"]="typdoc";
146         $POST_query["tri_exp2"]="annee_publi";
147         $POST_query["tri_exp3"]="auteur_exp";
148         if (strcmp($style_citation_reference, "hal") == 0) {
149             $POST_query["CB_ref_biblio"]="oui";
150             $POST_query["ordre_aff"]="TA";
151             $POST_query["Fen"]="Aff";
152             $POST_query["langue"]=$languageHAL;
153             $api_base_url="https://haltools.archives-ouvertes.fr/Public/afficheRequetePubli.php?";
154             $request_mode="native_html_display";
155         } else {
156             $POST_query["CB_accent_latex"]="non";
157             $POST_query["format_export"]="bibtex";
158             $POST_query["langue"]="Anglais";
159             $api_base_url="https://haltools.inria.fr/Public/exportPubli.php?";
160             $request_mode="generate_html_from_bibtext";
161         }
162         return array($api_base_url, $POST_query, $request_mode);
163     }
165     //==========================================================================
166     /**
167      * partie non testable du Shortcode [custom_publications_list]
168      * @param array $atts tableau de paramètres du shortcode
169      * @return string URL de la page a web de la requête vers la base de publication
170      */
171     //==========================================================================
172     static function custom_publications_list($atts) {
173         // @codeCoverageIgnoreStart
174         return self::custom_publications_list_web($atts);
175         // @codeCoverageIgnoreEnd
176     }
178     //==========================================================================
179     /**
180      * partie testable du Shortcode [custom_publications_list]
181      * @param array $atts tableau de paramètres du shortcode
182      * @param string $webservice_class_name nom de la classe qui sera utilisée pour faire la requête CURL
183      *                                      (permet de substituer un CURL par une fonction bouchon en test unitaire)
184      * @return string Code HTML généré par la requête
185      */
186     //==========================================================================
187     static function custom_publications_list_web($atts, $webservice_class_name='MonLabo_contact_webservices') {
188         $url=self::custom_publications_list_preprare_url($atts);
189         $webservice_class_instance=New $webservice_class_name();
190         return (empty($url) ? "" : $webservice_class_instance->curl_get_content($url));
191     }
193     //==========================================================================
194     /**
195      * générateur de requête URL du Shortcode [custom_publications_list]
196      * @param array $atts tableau de paramètres du shortcode
197      * @return string URL de la page a web de la requête vers la base de publication
198      */
199     //==========================================================================
200     static function custom_publications_list_preprare_url($atts) {
201         $MonLabo_access_data = New MonLabo_access_data();
203         $options4=get_option( 'MonLabo_settings_group4' );
205         // normalize attribute keys, lowercase
206         $atts = array_change_key_case((array)$atts, CASE_LOWER);
208         // Get the parameters and set default values
209         extract( shortcode_atts(
210             array(
211                 "alias" => "null",
212                 "unite" => "null",
213                 "equipe" => "null",
214                 "years" => "",
215                 "year" => "",
216                 "annee" => "",
217                 "debug" => "null",
218                 "type" => "null",
219                 "auteurid" => "null",
220                 "lang" => "null",
221                 "nohighlight" => "null",
222                 "displaytype" => "null",
223                 "format" => "null",
224                 "idhal" => "null",
225                 "struct" => "null",
226             ), $atts, 'custom_publications_list' )
227         );
228         //Normalize values keys
229         $debug=strtolower($debug);
230         $type=strtolower($type);
231         $lang=strtolower($lang);
232         $nohighlight=strtolower($nohighlight);
233         $displaytype=strtolower($displaytype);
234         $format=strtolower($format);
235         if ($years=="")   { $years = $year;      } //Pouvoir utiliser le paramètre years au sigulier au besoin
236         if ($years=="")   { $years = $annee;     } //Par defaut years remplace annee sauf si years est vide
238         // Build url from parameters
239         $POST_query=array();
241         //Pour des publications Descartes Publi
242         //-------------------------------------
243         if ($options4["MonLabo_uses_descartes_publi"]=="1") {
244             if($alias<>"null")        {$POST_query["alias"]=$alias;     }
245             if($unite<>"null")        {$POST_query["unite"]=$unite;    }
246             if($equipe<>"null") {
247                 if ($equipe=="*") {  //Get all the descartes_publi_team_id list of teams configured in MonLabo
248                     $all_teams_id = array_keys($MonLabo_access_data->get_teams_information());
249                     $Descartes_team_ids   = self::_MonLaboTeamsIds_into_publicationServerTeamsIds($all_teams_id);
250                     if(!empty($Descartes_team_ids)) { $equipe=implode("|", $Descartes_team_ids); }
251                 }
252                 $POST_query["equipe"] = $equipe;
253             }
254             if(strlen($years)>0)        { $POST_query["annee"]=$years;       }
255             if($debug<>"null")          { $POST_query["debug"]=$debug;                                  }
256             if($type<>"null")           { $POST_query["type"]=$type;        }
257             if($auteurid<>"null")       { $POST_query["auteurid"]=$auteurid;    }
258             if($lang<>"null")           { $POST_query["lang"]=$lang;        }
259             if($nohighlight<>"null")    { $POST_query["nohighlight"]=$nohighlight; }
260             if($displaytype<>"null")    { $POST_query["displaytype"]=$displaytype; }
261             if($format<>"null")         { $POST_query["format"]=$format;       }
263             $api_base_url=$options4['MonLabo_DescartesPubmed_api_url']."?";
264             return $api_base_url.http_build_query ($POST_query);
266         //Pour des publications HAL
267         //-------------------------
268         } elseif ($options4["MonLabo_uses_hal_publi"]=="1") {
269             //Choix de la langue
270             switch ($lang) {
271                 case "en":
272                     $languageHAL="Anglais";
273                     break;
274                 default: //fr
275                     $languageHAL="Francais";
276             }
277             //Formatage de la requête
278             list($api_base_url, $POST_query, $request_mode) = self::build_HAL_POST_query($years, $languageHAL, "hal");
279             if($idhal<>"null") {
280                 $POST_query["idHal"]=implode(";",MonLaboLib::prepare_multiple_values_variable_into_array($idhal));
281             } elseif($struct<>"null") {
282                 $POST_query["struct"]=implode(";",MonLaboLib::prepare_multiple_values_variable_into_array($struct));
283             }
284             return $api_base_url.http_build_query ($POST_query);
285         }
287     }
289     //==========================================================================
290     /**
291      * partie non testable du Shortcode [publications_list]
292      * @param array $atts tableau de paramètres du shortcode
293      * @return string URL de la page a web de la requête vers la base de publication
294      */
295     //==========================================================================
296     static function publications_list($atts) {
297         // @codeCoverageIgnoreStart
298         return self::publications_list_web($atts);
299         // @codeCoverageIgnoreEnd
300     }
302     //==========================================================================
303     /**
304      * partie testable du Shortcode [publications_list]
305      * @param array $atts tableau de paramètres du shortcode
306      * @param string $webservice_class_name nom de la classe qui sera utilisée pour faire la requête CURL
307      *                                      (permet de substituer un CURL par une fonction bouchon en test unitaire)
308      * @return string Code HTML généré par la requête
309      */
310     //==========================================================================
311     static function publications_list_web( $atts,  $webservice_class_name='MonLabo_contact_webservices') {
312         // 0 - Initialisations
313         //--------------------
314         $publications="";
315         $a_afficher='';
316         $options4 = get_option( 'MonLabo_settings_group4' );
317         $style_citation_reference = $options4["MonLabo_hal_publi_style"];
318         $currentlang = get_bloginfo('language');
319         $webservice_class_instance=New $webservice_class_name();
321         // 1 - Récupération des paramètres et valeurs par défaut
322         //------------------------------------------------------
324         // normalize attribute keys, lowercase
325         $atts = array_change_key_case((array)$atts, CASE_LOWER);
327         // get parameters
328         extract( shortcode_atts(
329                                 array(
330                                     'title' => "",               //Optional title
331                                     'titre' => "",
332                                     'annee' => "",
333                                     'year' => "",
334                                     'years' => "",
335                                     "units" => "",
336                                     "unit" => "",
337                                     "teams" => "",
338                                     "team" => "",
339                                     "persons" => "",
340                                     "person" => "",
341                                 ), $atts, 'publications_list' )
342         );
344         //Curation des paramètres homonymes, surnuméraires ou incompatibles
345         if ($persons=="") { $persons = $person;  } //Pouvoir utiliser le paramètre $persons au sigulier au besoin
346         if ($teams=="")   { $teams = $team;      } //Pouvoir utiliser le paramètre teams au sigulier au besoin
347         if ($units=="")   { $units = $unit;      } //Pouvoir utiliser le paramètre units au sigulier au besoin
348         if ($title=="")   { $title = $titre;     } //Pouvoir utiliser le paramètre title en français ou anglais
349         if ($years=="")   { $years = $year;      } //Pouvoir utiliser le paramètre years au sigulier au besoin
350         if ($years=="")   { $years = $annee;     } //Pouvoir utiliser le paramètre annee en français ou anglais
352         //Valeur par défaut du paramètre titre
353         if ($options4["MonLabo_uses_descartes_publi"]==1) {
354             if (strcmp ($title, "")==0) {
355                 $title = MonLabo_translate('Recent Publications',$currentlang);
356             }
357         }
359         // 2 - On forge l'URL et demande le mode de traitement de cette URL
360         //-----------------------------------------------------------------
361         list($request_mode, $url)=self::publications_list_prepare_url( $years, $units, $teams, $persons);
362         //var_dump($request_mode, $url);
364         // 3 - Traitement de l'URL
365         //------------------------
366         switch ($request_mode) {
367             case 'native_html_display':
368                 $contenu = $webservice_class_instance->curl_get_content($url);
369                 //Aller chercher le code au sein des balises <body></body> si elles existent
370                 if (!empty($contenu)) {
371                     $contenu_explose = explode ("<body>", $contenu);
372                     if (count($contenu_explose)>1) {
373                         $contenu_explose = explode ("</body>", $contenu_explose[1]);
374                     }
375                     $publications = $contenu_explose[0];
376                 } else {
377                     $publications="";
378                 }
379                 break;
381             case 'generate_html_from_bibtext':
382                 $hal_content = $webservice_class_instance->curl_get_content($url);
383                 $publi = self::parse_haltools_response($hal_content);
384                 $publications = self::format_publi($style_citation_reference, $publi, $currentlang);
385                 break;
387             default:
388                 $publications="";
389                 break;
390         }
392         // 4 - affichage des publications
393         //-------------------------------
394         if(strlen($publications)>10) {
395             $a_afficher .= '<h1>'.$title.'</h1>';
396             $a_afficher .= $publications;
397         }
399         return $a_afficher;
400     }
402     ///////////////////////////////////////////////////////////////////////////////////////////
403     //                        SPECIFIC LIBRAIRY FOR THE HAL PUBLICATIONS
404     ///////////////////////////////////////////////////////////////////////////////////////////
406     //==========================================================================
407     /**
408     * générateur de requête URL du Shortcode [publications_list]
409      * @param string $years
410      * @param string $units
411      * @param string $teams
412      * @return string URL de la page a web de la requête vers la base de publication
413      */
414     //==========================================================================
415     static function publications_list_prepare_url( $years, $units="", $teams="", $persons="") {
416         $MonLabo_access_data = New MonLabo_access_data();
417         $POST_query=array();
419         //-----------------------------
420         // 1 - Récupération des options
421         //-----------------------------
422         $options1 = get_option( 'MonLabo_settings_group1' );
423         $options4 = get_option( 'MonLabo_settings_group4' );
424         $style_citation_reference = $options4["MonLabo_hal_publi_style"];
425         if ($options4["MonLabo_uses_descartes_publi"]=="1") {
426             $format=$options4['MonLabo_DescartesPubmed_format'];
427         }
428         $request_mode="";
429         $request="";
431         //-------------------------------
432         // 2 - Détermination de la langue
433         //-------------------------------
434         switch (get_bloginfo('language')) {
435             case "en-US":
436             case "en-GB":
437                 $languageHAL="Anglais";
438                 $languageShortcode="en";
439                 break;
440             default: //"fr-FR"
441                 $languageHAL="Francais";
442                 $languageShortcode="fr";
443         }
446         //-------------------------------------
447         // 3 - Si persons, teams ou units = '*'
448         //-------------------------------------
449         if ($persons=="*") {
450             $all_persons_id = array_keys($MonLabo_access_data->get_persons_information());
451             if(!empty($all_persons_id)) { $persons=implode("|", $all_persons_id); }
452         }
453         if ($teams=="*") {
454             $all_teams_id = array_keys($MonLabo_access_data->get_teams_information());
455             if(!empty($all_teams_id)) { $teams=implode("|", $all_teams_id); }
456         }
457         if ($units=="*") {
458             $all_units_id = array_keys($MonLabo_access_data->get_units_information());
459             if(!empty($all_units_id)) { $units=implode("|", $all_units_id); }
460         }
462         //----------------------------------
463         // 4 - Détermination du type de page
464         //----------------------------------
465         $persons_id=array();
466         $teams_id=array();
467         $units_id=array();
468         if(($teams=='') and ($units=='') and ($persons=='')) {
469             //Déterminer a qui apartient la page courante
470             $persons=self::_person_of_curent_page();
471             $page_mode="user_page";
472             if(empty($persons)) {
473                 $teams=self::_team_of_curent_page();
474                 $page_mode="team_or_unit_page";
475                 if(empty($teams)) {
476                     $units=self::_unit_of_curent_page();
477                     if(empty($units)) {
478                         $page_mode="main_structure_page";
479                     }
480                 }
481             }
482         } else {
483           if(empty($persons)) {
484             $page_mode="team_or_unit_page";
485           } else {
486             $page_mode="user_page";
487           }
488         }
489         //Mise en tableau
490         $teams_id      = MonLaboLib::prepare_multiple_values_variable_into_array($teams);
491         $units_id      = MonLaboLib::prepare_multiple_values_variable_into_array($units);
492         $persons_id    = MonLaboLib::prepare_multiple_values_variable_into_array($persons);
494         //----------------------------------------------------------------
495         // 5.1 Traitement si le serveur de publication est Paris Descartes
496         //----------------------------------------------------------------
497         if ($options4["MonLabo_uses_descartes_publi"]=="1") {
498             $request_mode="native_html_display";
499             $api_base_url=$options4['MonLabo_DescartesPubmed_api_url']."?";
501             //Paramètres communs
502             $POST_query["lang"]="$languageShortcode";
503             $POST_query["type"]="*";
504             $POST_query["displaytype"]="with_titles";
505             $POST_query["format"]="$format";
506             if(strlen($years)>0) {
507                 $POST_query["annee"]="$years";
508             }
510             if ($page_mode=="team_or_unit_page") {
511                 //Formatage de la requête
512                 $Descartes_team_ids   = self::_MonLaboTeamsIds_into_publicationServerTeamsIds($teams_id);
513                 $Descartes_unit_ids   = self::_MonLaboUnitsIds_into_publicationServerUnitsIds($units_id);
514                 if(!empty($Descartes_team_ids)) {
515                     $POST_query["equipe"]=implode("|", $Descartes_team_ids);
516                 }
517                 if(!empty($Descartes_unit_ids)) {
518                     $POST_query["unite"]=implode("|", $Descartes_unit_ids);
519                 }
520                 if((!empty($Descartes_team_ids)) or (!empty($Descartes_unit_ids))) {
521                     if(strlen($years)==0) {
522                         $POST_query["annee"]="-5"; //Par défaut prendre les 5 dernières années
523                     }
524                 } else {
525                     //Page d'équipe ou d'unite, mais n'indique pas d'ID Descartes
526                     return array("", ""); /*Vide*/
527                 }
528             } elseif($page_mode=="user_page") {
529                 $Descartes_ids=self::_MonLaboPersonsIds_into_publicationServerAuthorsIds($persons_id);
530                 if(!empty($Descartes_ids)) {
531                     $POST_query["auteurid"]=implode("|", $Descartes_ids);
532                 } else {
533                     return array("", ""); /*Vide*/
534                 }
535             } else { //$page_mode=="main_structure_page"
536                 return array("", ""); /*Vide*/
537             }
539         //----------------------------------------------------
540         // 5.2 Traitement si le serveur de publication est HAL
541         //----------------------------------------------------
542         } elseif ($options4["MonLabo_uses_hal_publi"]=="1") {
544             //Construction de la la requête de base
545             //-------------------------------------
546             list($api_base_url, $POST_query, $request_mode) = self::build_HAL_POST_query($years, $languageHAL, $style_citation_reference);
548             //Calcul du paramètre identifiant l'équipe, la personne ou la structure
549             //---------------------------------------------------------------------
550             if($page_mode=="user_page") { //Personne
551                 $idHal = self::_MonLaboPersonsIds_into_publicationServerAuthorsIds($persons_id);
552                 if(!empty($idHal)) {
553                     $POST_query["idHal"]=implode(";", $idHal);
554                 } else {
555                     return array("", ""); /*Erreur*/
556                 }
557             } else {
558                 //Determine la liste des ID HAL a utiliser
559                 $HAL_ids=array();
560                 $idHal=array();
561                 if ($page_mode=="team_or_unit_page") { //Equipe
562                     $HAL_ids =                       self::_MonLaboTeamsIds_into_publicationServerTeamsIds($teams_id);
563                     // Si pas de hal_publi_team_id définis pour les équipes
564                     if( (!empty($teams_id)) and (empty($HAL_ids))) {
565                         //Retourner les publications des membres de l'équipe
566                         foreach ($teams_id as $team_id) {
567                             $idHal=array_merge($idHal, self::_MonLaboPersonsIds_into_publicationServerAuthorsIds($MonLabo_access_data->get_persons_id_for_a_team($team_id)));
568                         }
569                     }
570                     $unitHAL_ids=self::_MonLaboUnitsIds_into_publicationServerUnitsIds($units_id);
571                     $HAL_ids = array_merge($HAL_ids, $unitHAL_ids);
572                     // Si pas de hal_publi_team_id définis pour les unités
573                     if( (!empty($units_id)) and (empty($unitHAL_ids))) {
574                         //Retourner les publications des membres de l'unité
575                         foreach ($units_id as $unit_id) {
576                             $idHal=array_merge($idHal, self::_MonLaboPersonsIds_into_publicationServerAuthorsIds(array_keys($MonLabo_access_data->get_persons_information_for_an_unit($unit_id))));
577                         }
578                     }
579                 } elseif($page_mode=="main_structure_page") {
580                     if (!empty($options1["MonLabo_hal_publi_struct_id"])) {
581                         $HAL_ids = MonLaboLib::prepare_multiple_values_variable_into_array($options1["MonLabo_hal_publi_struct_id"]);
582                     }
583                 }
584                 //Nettoyage des ID HAL non numériques
585                 if(!empty($HAL_ids)) {
586                     foreach ($HAL_ids as $key => $value) {
587                         if (!is_numeric($value)) {
588                             unset($HAL_ids[$key]);
589                         }
590                     }
591                 }
592                 //Formatage de la requête
593                 //Les paramètres idHal et struct sont incompatibles.
594                 if(!empty($idHal)) {
595                     $POST_query["idHal"]=implode(";", $idHal);
596                 } elseif(!empty($HAL_ids)) {
597                     $POST_query["struct"]=implode(";", $HAL_ids);
598                 } else {
599                     return array("", ""); /*Vide*/
600                 }
601             }
602         }
603         //---------------------------------------------------
604         // 6 - contruire l'URL
605         //---------------------------------------------------
606         $url="";
607         if ($request_mode!="") {
608             $url = $api_base_url.http_build_query ($POST_query);
609         }
610         return array($request_mode, $url);
611     }
613     //==========================================================================
614     /**
615      * Analyseur syntaxique de la page retournée par haltools
616      * @param string $hal_content la page retournée par haltools
617      * @return array le tableau des publications [type][année][ordre][champs]
618      *               champs : titre, auteur, article
619      */
620     //==========================================================================
621     static function parse_haltools_response($hal_content = "") {
622         $publi =array();
623       /*
624         $caractere_texte = array("à", "À", "á", "Á", "â", "Â", "ã", "Ā", "ä", "Ä", "å", "Å", "æ", "Æ",
625                                  "è", "È", "é", "É", "ê", "Ê", "ë", "Ë",
626                                  "ì", "Ì", "í", "Í", "î", "Î", "ï", "Ï",
627                                  "ò", "Ò", "ó", "Ó", "ô", "Ô", "õ", "Õ", "ö", "Ö", "ø", "Ø",
628                                  "ù", "Ù", "ú", "Ú", "û", "Û", "ü", "Ü",
629                                  "ñ", "ç", "Ç", "ý", "Ý", "ß",
630                                  "°",
631                                 );
632         */
633         $caractere_texte = array("&agrave;", "&Agrave;", "&aacute;", "&Aacute;", "&acirc;", "&Acirc;", "&atilde;", "&Atilde;", "&auml;", "&Auml;", "&aring;", "&Aring;", "&aelig;", "&AElig;",
634                                  "&egrave;", "&Egrave;", "&eacute;", "&Eacute;", "&ecirc;", "&Ecirc;", "&etilde;", "&Etilde;", "&euml;", "&Euml;",
635                                  "&igrave;", "&Igrave;", "&iacute;", "&Iacute;", "&icirc;", "&Icirc;", "&itilde;", "&Itilde;", "&iuml;", "&Iuml;",
636                                  "&ograve;", "&Ograve;", "&oacute;", "&Oacute;", "&ocirc;", "&Ocirc;", "&otilde;", "&Otilde;", "&ouml;", "&Ouml;", "&oslash;", "&Oslash;", "&oelig;", "&OElig;",
637                                  "&ugrave;", "&Ugrave;", "&uacute;", "&Uacute;", "&ucirc;", "&Ucirc;", "&utilde;", "&Utilde;", "&uuml;", "&Uuml;",
638                                  "&ntilde;", "&ccedil;", "&Ccedil;", "&yacute;", "&Yacute;", "&szlig;", "&amp;",
639                                  "&deg;",
640                                 );
641         $caractere_latex = array("{\`a}", "{\`A}", "{\'a}", "{\'A}", "{\^a}", "{\^A}", "{\~a}", "{\~A}", '{\"a}', '{\"A}', '{\aa}', '{\AA}', '{\ae}', '{\AE}',
642                                  "{\`e}", "{\`E}", "{\'e}", "{\'E}", "{\^e}", "{\^E}", "{\~e}", "{\~E}", '{\"e}', '{\"E}',
643                                  "{\`i}", "{\`I}", "{\'i}", "{\'I}", "{\^i}", "{\^I}", "{\~i}", "{\~I}", '{\"i}', '{\"I}',
644                                  "{\`o}", "{\`O}", "{\'o}", "{\'O}", "{\^o}", "{\^O}", '{\~o}', '{\~O}', '{\"o}', '{\"O}', '{\o}', '{\O}', '{\oe}', '{\OE}',
645                                  "{\`u}", "{\`U}", "{\'u}", "{\'U}", "{\^u}", "{\^U}", "{\~u}", "{\~U}", '{\"u}', '{\"U}',
646                                  "{\~n}", "{\c c}", "{\c C}", "{\'y}", "{\'Y}", "{\ss}", "\&",
647                                  '{\textdegree}',
648                                 );
649         /*$webservice_class_instance=New $webservice_class_name();
650         $hal_content = $webservice_class_instance->curl_get_content($url);*/
652         $data_contenu = explode ("@", $hal_content); //Séparer chaque entrée bibliographique
653         foreach ($data_contenu as $id_publi => $datum_publi) {
654             $datum_publi = str_replace($caractere_latex, $caractere_texte, $datum_publi);
655             if ($id_publi != 0) { //On ne prend que après le premier @
656                 // correction du probleme de MONTH dans hal
657                 //On recherche "MONTH = truc," et on le remplace par "MONTH = {truc},"
658                 //Cette recherche se fait indépendament de la case (/i) et du nombre de carracères d'espacement ou tabulation autour du =
659                 $datum_publi=preg_replace('/MONTH\s*=\s*(\S+)\s*,/i', 'MONTH = {${1}},', $datum_publi);
660                 //type = mot en début de chaine avant le première accolade. (/s est pour le traitement multiligne)
661                 $type=preg_replace('/^([^{]+)\S*{.*/s','${1}',$datum_publi);
662                 //contenu = tout ce qui est dans les accolades suivantes (les espaces et sauts de lignes autour ne comptent pas)
663                 $contenu=preg_replace('/^([^{]+)\S*{\S*(.*)\S*}\S*$/s','${2}',$datum_publi);
664                 //On récupère un gros tableau des "field" = "values", en étant tolérant sur les espaces surnuméraires.
665                 preg_match_all('/(?P<field>\w+)[ \t]*=[ \t]*(?P<values>.*)\S*,\S*[\n\r\f]+/', $contenu, $matches);
666                 $fields=$matches['field'];
667                 $values=$matches['values'];
668                 $publi_tmp=array();
669                 foreach ($fields as $key => $value) {
670                     $publi_tmp [strtoupper($fields[$key]) ] = $values[$key];
671                 }
672                 //nettoyage de chaque champs
673                 foreach ($publi_tmp as $key => $value) {
674                     $value=self::suppress_bibtex_value_limiter($value);
675                     $publi_tmp[$key] = str_replace(['{','}'], "", $value);
676                 }
677                 if (!empty($publi_tmp['YEAR'])) {
678                     $annee = $publi_tmp['YEAR'];
679                 } else {
680                     $annee = "unknown year"; //En cas de fichier bib invalide
681                 }
682                 if (!empty($publi_tmp['TYPE'])) {
683                     if (strcmp(substr($publi_tmp['TYPE'], 0, 12), "Habilitation") == 0) {
684                         $publi['hdr'][$annee][] = $publi_tmp;
685                     } elseif (strcmp($publi_tmp['TYPE'], "Theses") == 0) {
686                         $publi['phdthesis'][$annee][] = $publi_tmp;
687                     } else {
688                         $publi[$type][$annee][] = $publi_tmp;
689                     }
690                 } else {
691                     $publi[$type][$annee][] = $publi_tmp;
692                 }
693             }
694         }
695         return $publi;
696     }
698     //==========================================================================
699     /**
700      * formatage des publications
701      * @param string $publi le tableau des publications[type][année][ordre][champs]
702      * @return string le html à afficher
703      */
704     //==========================================================================
705     static function format_publi($format = "ieee", $data_publi, $currentlang) {
706         //Voir https://doc.archives-ouvertes.fr/bib2hal/champs-bibtex-obligatoiresoptionnels-par-type/
707         //Il faudra rajouter:
708         //@conference
709         //@presconf
710         //@poster
711         //@inbook
712         //@proceedings
713         //@manual
714         //@note
716         $type_name = array(
717             "article"       => array( "en" => "Journal articles"                        ,"fr" => "Article dans une revue"),
718             "inproceedings" => array( "en" => "Conference papers"                       ,"fr" => "Communication dans un congrès"),
719             "incollection"  => array( "en" => "Book sections"                           ,"fr" => "Chapitre d'ouvrage"),
720             "book"          => array( "en" => "Books"                                   ,"fr" => "Ouvrage (y compris édition critique et traduction)"),
721             "hdr"           => array( "en" => "Habilitation à diriger des recherches"   ,"fr" => "HDR"),
722             "mastersthesis" => array( "en" => "Master thesis"                           ,"fr" => "Mémoire d'étudiant"),
723             "techreport"    => array( "en" => "Reports"                                 ,"fr" => "Rapport"),
724             "misc"          => array( "en" => "Other publications"                      ,"fr" => "Autre publication"),
725             //Sont aussi classés dans la categorie bibtex @misc les catégories HAL suivantes :
726             //              - Posters
727             //              - Autre rapport, séminaire, workshop
728             //              - Document associé à des manifestations scientifiques
729             //              - Carte
730             "phdthesis"     => array( "en" => "Theses"                                  ,"fr" => "Thèse"),
731             "unpublished"   => array( "en" => "Preprints, Working Papers, ..."          ,"fr" => "Pré-publication, Document de travail"),
732             //Sont aussi classés dans la categorie bibtex @unpublished les catégories HAL suivantes :
733             //              - Cours
734             "patent"        => array( "en" => "Patents"                                 ,"fr" => "Brevet"), //TODO rajouter le formatage
735             "proceedings"   => array( "en" => "Directions of work or proceedings"       ,"fr" => "Direction d'ouvrage, Proceedings, Dossier"), //TODO rajouter le formatage
736         );
737         switch ($currentlang) {
738             case 'en-US':
739             case 'en-GB':
740                 $lang="en";
741                 break;
743             case 'fr-FR':
744             default:
745                 $lang="fr";
746                 break;
747         }
749         $a_afficher='<div id="res_script">';
750         if (!empty($data_publi)) {
751             foreach ($data_publi as $type => $datum_type) {
752                 if(in_array($type, array_keys($type_name))) { //Vérifier qu'on est capable de traiter le $type dans le switch
753                     $a_afficher.="<p class='Rubrique'>".$type_name[$type][$lang]."</p>";
754                     foreach ($datum_type as $date => $datum_date) {
755                         $a_afficher.="<p class='SousRubrique'>".$date."</p>";
756                         foreach ($datum_date as $ordre => $datum_order) {
757                             if(!empty($datum_order['AUTHOR'])) { //Ne rien afficher si pas d'auteur
758                                 $a_afficher.="<dl class='NoticeRes'><dt class='ChampRes'>ref_biblio</dt><dd class='ValeurRes ref_biblio'>";
759                                 switch ($format) {
760                                     case "ieee" :
761                                         $a_afficher .= self::bibtex_to_ieee_authors($datum_order['AUTHOR']);
762                                         switch ($type) {
763                                             case "article" :
764                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
765                                                 $a_afficher .= self::format_bib_field($datum_order, 'JOURNAL', " <i>#{field}</i>");
766                                                 $a_afficher .= self::format_bib_field($datum_order, 'VOLUME', ", vol. #{field}");
767                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', ", no. #{field}");
768                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
769                                                 $a_afficher .= ", ";
770                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
771                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
772                                                 break;
773                                             case "inproceedings" : // Communication dans un congrès
774                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
775                                                 $a_afficher .= self::format_bib_field($datum_order, 'BOOKTITLE', " in <i>#{field}</i>");
776                                                 $a_afficher .= self::format_bib_field($datum_order, 'ADDRESS', ", #{field}");
777                                                 $a_afficher .= ", ";
778                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
779                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
780                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
781                                                 break;
782                                             case "incollection" : // Chapitre d'ouvrage
783                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
784                                                 $a_afficher .= self::format_bib_field($datum_order, 'BOOKTITLE', " in <i>#{field}</i>");
785                                                 $a_afficher .= self::format_bib_field($datum_order, 'SERIES', " (#{field})");
786                                                 if (!empty($datum_order['ADDRESS'])) {
787                                                   $a_afficher .= ", ".$datum_order['ADDRESS'];
788                                                   $a_afficher .= self::format_bib_field($datum_order, 'PUBLISHER', ": #{field}");
789                                                 } else {
790                                                   $a_afficher .= self::format_bib_field($datum_order, 'PUBLISHER', ", #{field}");
791                                                 }
792                                                 $a_afficher .= ", ";
793                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
794                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
795                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
796                                                 break;
797                                             case "book" : // Ouvrage (y compris édition critique et traduction)
798                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", <i>#{field}</i>");
799                                                 $a_afficher .= self::format_bib_field($datum_order, 'SERIES', " (#{field})");
800                                                 if (!empty($datum_order['ADDRESS'])) {
801                                                   $a_afficher .= ", ".$datum_order['ADDRESS'];
802                                                   $a_afficher .= self::format_bib_field($datum_order, 'PUBLISHER', ": #{field}");
803                                                 } else {
804                                                   $a_afficher .= self::format_bib_field($datum_order, 'PUBLISHER', ", #{field}");
805                                                 }
806                                                 $a_afficher .= ", ";
807                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
808                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
809                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
810                                                 break;
811                                             case "hdr" : // HDR
812                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
813                                                 $a_afficher .= " H.D.R. dissertation";
814                                                 $a_afficher .= self::format_bib_field($datum_order, 'SCHOOL', ", #{field}");
815                                                 $a_afficher .= ", ";
816                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
817                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
818                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
819                                                 break;
820                                             case "mastersthesis" : // Mémoire d'étudiant
821                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
822                                                 $a_afficher .= " student dissertation";
823                                                 $a_afficher .= self::format_bib_field($datum_order, 'SCHOOL', ", #{field}");
824                                                 $a_afficher .= ", ";
825                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
826                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
827                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
828                                                 break;
829                                             case "techreport" : // Rapport
830                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
831                                                 $a_afficher .= " unpublished";
832                                                 $a_afficher .= ", ";
833                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
834                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
835                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
836                                                 break;
837                                             case "misc" : //Autre publication
838                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
839                                                 $a_afficher .= " unpublished";
840                                                 $a_afficher .= self::format_bib_field($datum_order, 'HOWPUBLISHED', ", <i>#{field}</i>");
841                                                 $a_afficher .= ", ";
842                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
843                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
844                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
845                                                 break;
846                                             case "phdthesis" : // Thèse
847                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
848                                                 $a_afficher .= " M.S. thesis";
849                                                 $a_afficher .= self::format_bib_field($datum_order, 'SCHOOL', ", #{field}");
850                                                 $a_afficher .= ", ";
851                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
852                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
853                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', ", no. #{field}");
854                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
855                                                 break;
856                                             case "unpublished" : // Pré-publication, Document de travail
857                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
858                                                 $a_afficher .= " unpublished";
859                                                 $a_afficher .= ", ";
860                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
861                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
862                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
863                                                 break;
864                                             case "patent" : // brevet
865                                                 //http://libraryguides.vu.edu.au/ieeereferencing/standardsandpatents
866                                                 //Author(s) Initial(s). Surname(s), “Title of patent,” Published Patent’s country of origin and number xxxx, Abbrev. Month. Day, Year of Publication.​
867                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
868                                                 $a_afficher .= self::format_bib_field($datum_order, 'ADDRESS', " #{field}");
869                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', " Patent #{field}");
870                                                 $a_afficher .= ", ";
871                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
872                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
873                                                 break;
874                                             case "proceedings" : // Direction d'ouvrage, Proceedings, Dossier
875                                                 //http://libraryguides.vu.edu.au/ieeereferencing/confernenceproceedings
876                                                 //Author(s) Initial(s). Surname(s), “Title of paper,” in <i>Abbrev. Name of Conf.</i>, [location of conference is optional], [vol., no. if available], Year, pp. xxx–xxx.
877                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
878                                                 $a_afficher .= self::format_bib_field($datum_order, 'BOOKTITLE', " in <i>#{field}</i>");
879                                                 $a_afficher .= self::format_bib_field($datum_order, 'ADDRESS', ", #{field}");
880                                                 $a_afficher .= ", ";
881                                                 $a_afficher .= self::format_bib_field($datum_order, 'MONTH', "#{field}. ");
882                                                 $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
883                                                 $a_afficher .= self::format_bib_field($datum_order, 'VOLUME', ", vol. #{field}");
884                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', ", no. #{field}");
885                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", pp. #{field}");
886                                                 break;
887                                         }
888                                         $a_afficher .= ".";
889                                         $a_afficher .= self::format_bib_field($datum_order,  'DOI', " <a target=\"_blank\" href=\"http://dx.doi.org/#{field}\">&lt;#{field}&gt;</a>.");
890                                         $a_afficher .= self::format_bib_field($datum_order, 'HAL_ID-URL', " #{field}.");
891                                         $a_afficher .= self::format_bib_field($datum_order, 'PDF', " <a href=\"#{field}\" target=\"_blank\"><img style=\"width:11px; height:11px;\" src=\"http://haltools.archives-ouvertes.fr/images/Haltools_pdf.png\" title=\"#{field}\" border=\"0\"></a>");
892                                         break;
894                                     case "apa" :
895                                         $a_afficher .= self::bibtex_to_apa_authors($datum_order['AUTHOR']);
896                                         $a_afficher .= " (";
897                                         $a_afficher .= self::format_bib_field($datum_order, 'YEAR', "#{field}");
898                                         $a_afficher .= self::format_bib_field($datum_order, 'MONTH', ", #{field}");
899                                         $a_afficher .= ").";
900                                         switch ($type) {
901                                             case "article" :
902                                                 $a_afficher .= " ";
903                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " #{field}.");
904                                                 $a_afficher .= self::format_bib_field($datum_order, 'JOURNAL', " <i>#{field}</i>");
905                                                 $a_afficher .= self::format_bib_field($datum_order, 'VOLUME', ", #{field}");
906                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', " (#{field})");
907                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", #{field}");
908                                                 break;
909                                             case "inproceedings" : // Communication dans un congrès
910                                                 $a_afficher .= " ";
911                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " <i>#{field}</i>.");
912                                                 $a_afficher .= self::format_bib_field($datum_order, 'BOOKTITLE', " Paper presented at the #{field}");
913                                                 $a_afficher .= self::format_bib_field($datum_order, 'ADDRESS', ", #{field}");
914                                                 $a_afficher .= self::format_bib_field($datum_order, 'VOLUME', ", #{field}");
915                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', " (#{field})");
916                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", #{field}");
917                                                 break;
918                                             case "incollection" : // Chapitre d'ouvrage
919                                                 if (!empty($datum_order['EDITOR'])) {
920                                                     $a_afficher .= " In ".$datum_order['EDITOR'];
921                                                     $a_afficher .= self::format_bib_field($datum_order, 'BOOKTITLE', ", <i>#{field}</i>");
922                                                 } else {
923                                                     $a_afficher .= self::format_bib_field($datum_order, 'BOOKTITLE', " <i>#{field}</i>");
924                                                 }
925                                                 $a_afficher .= self::format_bib_field($datum_order, 'BOOKTITLE', ", <i>#{field}</i>");
926                                                 $a_afficher .= self::format_bib_field($datum_order, 'SERIES', ", #{field}");
927                                                 $a_afficher .= self::format_bib_field($datum_order, 'VOLUME', ", #{field}");
928                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', " (#{field})");
929                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", #{field}");
930                                                 break;
931                                             case "book" : // Ouvrage (y compris édition critique et traduction)
932                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " <i>#{field}</i>");
933                                                 if (!empty($datum_order['EDITOR'])) {
934                                                   $a_afficher .= " In ".$datum_order['EDITOR'];
935                                                   $a_afficher .= self::format_bib_field($datum_order, 'PUBLISHER', ", #{field}");
936                                                 } else {
937                                                   $a_afficher .= self::format_bib_field($datum_order, 'PUBLISHER', " #{field}");
938                                                 }
939                                                 $a_afficher .= self::format_bib_field($datum_order, 'BOOKTITLE', ", <i>#{field}</i>");
940                                                 $a_afficher .= self::format_bib_field($datum_order, 'SERIES', ", #{field}");
941                                                 $a_afficher .= self::format_bib_field($datum_order, 'VOLUME', ", #{field}");
942                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', " (#{field})");
943                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", #{field}");
944                                                 break;
945                                             case "hdr" : // HDR
946                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " <i>#{field}</i>");
947                                                 if (empty($datum_order['PDF'])) {
948                                                     $a_afficher .= ", HDR not published ";
949                                                     $a_afficher .= self::format_bib_field($datum_order, 'SCHOOL', ", HDR not published #{field}");
950                                                 } else {
951                                                     $a_afficher .= self::format_bib_field($datum_order, 'SCHOOL', ", HDR (#{field})");
952                                                 }
953                                                 break;
954                                             case "mastersthesis" : // Mémoire d'étudiant
955                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " <i>#{field}</i>");
956                                                 if (empty($datum_order['PDF'])) {
957                                                     $a_afficher .= ", HDR not published ";
958                                                     $a_afficher .= self::format_bib_field($datum_order, 'SCHOOL', ", HDR not published #{field}");
959                                                 } else {
960                                                     $a_afficher .= self::format_bib_field($datum_order, 'SCHOOL', ", HDR (#{field})");
961                                                 }
962                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", #{field}");
963                                                 break;
964                                             case "techreport" : // Rapport
965                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " <i>#{field}</i>");
966                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', " (#{field})");
967                                                 $a_afficher .= self::format_bib_field($datum_order, 'INSTITUTION', ", #{field}");
968                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", #{field}");
969                                                 break;
970                                             case "misc" : // Autre publication
971                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " <i>#{field}</i>");
972                                                 $a_afficher .= self::format_bib_field($datum_order, 'HOWPUBLISHED', ", Paper presented at the #{field}");
973                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", #{field}");
974                                                 break;
975                                             case "phdthesis" : // Thèse
976                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " <i>#{field}</i>");
977                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', " (#{field})");
978                                                 if (empty($datum_order['PDF'])) {
979                                                     $a_afficher .= ", Thesis not published ";
980                                                     $a_afficher .= self::format_bib_field($datum_order, 'SCHOOL', ", Thesis not published #{field}");
981                                                 } else {
982                                                     $a_afficher .= self::format_bib_field($datum_order, 'SCHOOL', ", Thesis (#{field})");
983                                                 }
984                                                 break;
985                                             case "unpublished" : // Pré-publication, Document de travail
986                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " <i>#{field}</i>");
987                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', ", #{field}");
988                                                 break;
989                                             case "patent" : // brevet
990                                                 //http://libraryguides.vu.edu.au/apa-referencing/patents-and-standards
991                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', " <i>#{field}</i>");
992                                                 $a_afficher .= self::format_bib_field($datum_order, 'NUMBER', " <i>No. #{field}</i>");
993                                                 $a_afficher .= self::format_bib_field($datum_order, 'ADDRESS', "#{field}");
994                                                 $a_afficher .= self::format_bib_field($datum_order, 'PUBLISHER', ": #{field}");
995                                                 break;
996                                             case "proceedings" : // Direction d'ouvrage, Proceedings, Dossier
997                                                 //http://libraryguides.vu.edu.au/apa-referencing/conference-proceedings
998                                                 $a_afficher .= self::format_bib_field($datum_order, 'TITLE', ", \"#{field},\"");
999                                                 $a_afficher .= self::format_bib_field($datum_order, 'EDITOR', ", #{field}");
1000                                                 $a_afficher .= self::format_bib_field($datum_order, 'BOOKTITLE', ", <i>#{field}</i>");
1001                                                 $a_afficher .= self::format_bib_field($datum_order, 'PAGES', " (pp. #{field})");
1002                                                 $a_afficher .= ". ";
1003                                                 $a_afficher .= self::format_bib_field($datum_order, 'ADDRESS', "#{field}");
1004                                                 $a_afficher .= self::format_bib_field($datum_order, 'PUBLISHER', ": #{field}");
1005                                                 break;
1006                                         }
1007                                         $a_afficher .= ".";
1008                                         $a_afficher .= self::format_bib_field($datum_order,  'DOI', " <a target=\"_blank\" href=\"http://dx.doi.org/#{field}\">&lt;#{field}&gt;</a>.");
1009                                         $a_afficher .= self::format_bib_field($datum_order, 'HAL_ID-URL', " #{field}.");
1010                                         $a_afficher .= self::format_bib_field($datum_order, 'PDF', " <a href=\"#{field}\" target=\"_blank\"><img style=\"width:11px; height:11px;\" src=\"http://haltools.archives-ouvertes.fr/images/Haltools_pdf.png\" title=\"#{field}\" border=\"0\"></a>");
1011                                         break;
1012                                 }
1013                                 $a_afficher.="</dd></dl>";
1014                             }
1015                         }
1016                     }
1017                 }
1018             }
1019         }
1020         $a_afficher.='</div>';
1021         return $a_afficher;
1022     }
1024     //==========================================================================
1025     /**
1026      * formatage des auteurs au format IEEE à partir des auteurs BibTex
1027      * @param string $authors_bib_string auteurs au format BibTex
1028      * @return string auteurs au format IEEE
1029      */
1030     //==========================================================================
1031     static function bibtex_to_ieee_authors($authors_bib_string) {
1032         $authors = explode(" and ", $authors_bib_string);
1033         $authors_names = array();
1034         foreach ($authors as $author) {
1035             $names = explode(",", $author);
1036             $first_names = explode(" ", trim($names[1]));
1037             $abreviated_first_names = array();
1038             foreach ($first_names as $first_name_datum) {
1039                 $composed_first_names = explode("-", $first_name_datum);
1040                 if (count($composed_first_names) > 1) {
1041                     $abreviated_composed_first_names = array();
1042                     foreach ($composed_first_names as $composed_first_name) {
1043                         $abreviated_composed_first_names[] = strtoupper(substr(trim($composed_first_name), 0, 1)).'.';
1044                     }
1045                     $abreviated_first_names[] = implode("-", $abreviated_composed_first_names);
1046                 } else {
1047                     $abreviated_first_names[] = strtoupper(substr(trim($composed_first_names[0]), 0, 1)).'.';
1048                 }
1049             }
1050             $last_names = explode(" ", trim($names[0]));
1051             $cased_last_names = array();
1052             foreach ($last_names as $last_name_datum) {
1053                 $composed_last_names = explode("-", $last_name_datum);
1054                 if (count($composed_last_names) > 1) {
1055                     $cased_composed_last_names = array();
1056                     foreach ($composed_last_names as $composed_last_name) {
1057                         $cased_composed_last_names[] = ucwords(strtolower(trim($composed_last_name)));
1058                     }
1059                     $cased_last_names[] = implode("-", $cased_composed_last_names);
1060                 } else {
1061                     $cased_last_names[] = ucwords(strtolower(trim($composed_last_names[0])));
1062                 }
1063             }
1064             $first_name = implode(" ", $abreviated_first_names);
1065             $last_name = implode(" ", $cased_last_names);
1066             $authors_names[] = $first_name." ".$last_name;
1067         }
1068         if (count($authors) > 1) {
1069             $authors_name = implode(array_splice($authors_names, 0, count($authors_names)-1), ", ");
1070             if (!empty($authors_names)) {
1071                 $authors_name .= ", and ".$authors_names[0];
1072             }
1073         } else {
1074             $authors_name = $authors_names[0];
1075         }
1076         return $authors_name;
1077     }
1079     //==========================================================================
1080     /**
1081      * formatage des auteurs au format APA à partir des auteurs BibTex
1082      * @param string $authors_bib_string auteurs au format BibTex
1083      * @return string auteurs au format APA
1084      */
1085     //==========================================================================
1086     static function bibtex_to_apa_authors($authors_bib_string){
1087         $authors = explode(" and ", $authors_bib_string);
1088         $authors_names = array();
1089         foreach ($authors as $author) {
1090             $names = explode(",", $author);
1091             $first_names = explode(" ", trim($names[1]));
1092             $abreviated_first_names = array();
1093             foreach ($first_names as $first_name_datum) {
1094                 $composed_first_names = explode("-", $first_name_datum);
1095                 if (count($composed_first_names) > 1) {
1096                     $abreviated_composed_first_names = array();
1097                     foreach ($composed_first_names as $composed_first_name) {
1098                         $abreviated_composed_first_names[] = strtoupper(substr(trim($composed_first_name), 0, 1)).'.';
1099                     }
1100                     $abreviated_first_names[] = implode("-", $abreviated_composed_first_names);
1101                 } else {
1102                     $abreviated_first_names[] = strtoupper(substr(trim($composed_first_names[0]), 0, 1)).'.';
1103                 }
1104             }
1105             $first_name = implode("", $abreviated_first_names);
1106             $last_name = ucwords(strtolower(trim($names[0])));
1107             $authors_names[] = $last_name.", ".$first_name;
1108         }
1109         if (count($authors) > 1) {
1110             $authors_name = implode(array_splice($authors_names, 0, count($authors_names)-1), ", ");
1111             if (!empty($authors_names)) {
1112                 $authors_name .= ", & ".$authors_names[0];
1113             }
1114         } else {
1115             $authors_name = $authors_names[0];
1116         }
1117         return $authors_name;
1118     }
1120     //==========================================================================
1121     /**
1122      * formatage des champs issus d'un fichier BibTex
1123      * @param array $array tableau où récupérer le champs BibTex
1124      * @param string $field index du champs du tableau à récupérer
1125      * @param string $format formatage à produire à partir du champs
1126      * @return string code HTML généré
1127      */
1128     //==========================================================================
1129     static function format_bib_field($array, $field, $format ){
1130         $a_afficher="";
1131         $field=strtoupper($field);
1132         //Pre-preprocess:
1133         //-----------
1134         if ($field=='HAL_ID-URL') {
1135             if (!empty($array['HAL_ID']) and !empty($array['URL'])) {
1136                 //lien de HAL_ID avec URL
1137                 $field='HAL_ID';
1138                 $format = str_replace("#{field}", "<a target=\"_blank\" href=\"".$array['URL']."\">&lt;#{field}&gt;</a>", $format);
1139             } elseif (!empty($array['HAL_ID']) and  empty($array['URL'])) {
1140                 //lien de HAL_ID avec HAL_ID
1141                 $field='HAL_ID';
1142                 $format = str_replace("#{field}", "<a target=\"_blank\" href=\"https://hal.archives-ouvertes.fr/".$array['HAL_ID']."\">&lt;#{field}&gt;</a>", $format);
1143             } elseif (empty($array['HAL_ID']) and !empty($array['URL'])) {
1144                 //lien URL simple
1145                 $field='URL';
1146                 $format = str_replace("#{field}", "<a target=\"_blank\" href=\"".$array['URL']."\">#{field}</a>", $format);
1147             } else {
1148                 //ne rien afficher
1149                 $field='INVALID';
1150             }
1151         }
1153         if (!empty($array[$field])) {
1155             //Preprocess:
1156             //-----------
1157             switch ($field) {
1158                 case 'PAGES':
1159                 $reprocessed=trim(str_replace('p', "", str_replace('p.', "", str_replace('pp', "", str_replace('pp.', "", $array[$field])))));
1160                 break;
1162                 case 'MONTH':
1163                 $reprocessed=substr($array[$field], 0, 3);
1164                 break;
1166                 default:
1167                 $reprocessed=$array[$field];
1168                 break;
1169             }
1171             //Process:
1172             //-------
1173             $a_afficher .= str_replace("#{field}", $reprocessed, $format);
1174         }
1175         return $a_afficher;
1176     }
1180 /**
1181  * Class MonLabo_contact_webservices
1182  *
1183  * @package
1184  */
1185 class MonLabo_contact_webservices {
1186     //==========================================================================
1187     /**
1188      * Récupère le contenur d'une URL (fonction non testable car utilise un site extérieur)
1189      * @param string $url URL du contenu à récupérer
1190      * @return string contenu de la page à l'adresse $url
1191      */
1192     //==========================================================================
1193     function curl_get_content($url) {
1194         // @codeCoverageIgnoreStart
1195         $ch_rech = curl_init();                    // Initialiser CURL.
1196         curl_setopt($ch_rech, CURLOPT_URL, $url);  // Indiquer quel URL à récupérer
1197         curl_setopt($ch_rech, CURLOPT_HEADER, 0);  // Ne pas inclure l'header dans la réponse.
1198         //curl_setopt($ch_rech, CURLOPT_SSL_VERIFYPEER, false); // pour que CURL ne vérifie pas le certificat.
1199         ob_start();                                // Commencer à 'cache' l'output.
1200         curl_exec($ch_rech);                       // Exécuter la requète.
1201         curl_close($ch_rech);                      // Fermer CURL.
1202         $contenu = ob_get_contents();              // Sauvegarder 'cache' dans variable $Results.
1203         ob_end_clean();                            // Vider le buffer.
1204         return $contenu;
1205         // @codeCoverageIgnoreEnd
1206     }
1208 ?>