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

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