The Higher Education and Research forge

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

SCM Repository

1 <?php
2 //error_reporting( E_ALL );
3 //ini_set( 'display_errors',1 );
4 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                         $all_persons_id = MonLaboLib::secured_array_keys( $MonLabo_access_data->get_persons_information() );
527                         if ( !empty( $all_persons_id ) ) {
528                                 $persons = MonLaboLib::secured_implode( '|', $all_persons_id );
529                         }
530                 }
531                 if ( '*' === $teams ) {
532                         $all_teams_id = MonLaboLib::secured_array_keys( $MonLabo_access_data->get_teams_information() );
533                         if ( !empty( $all_teams_id ) ) { $teams = MonLaboLib::secured_implode( '|', $all_teams_id ); }
534                 }
535                 if ( '*' === $units ) {
536                         $all_units_id = MonLaboLib::secured_array_keys( $MonLabo_access_data->get_units_information() );
537                         if ( !empty( $all_units_id ) ) { $units = MonLaboLib::secured_implode( '|', $all_units_id ); }
538                 }
540                 //----------------------------------
541                 // 4 - Détermination du type de page
542                 //----------------------------------
543                 $persons_id = array();
544                 $teams_id = array();
545                 $units_id = array();
546                 if ( ( '' === $teams ) and ( '' === $units ) and ( '' === $persons ) ) {
547                         //Déterminer a qui apartient la page courante
548                         $persons = self::_person_of_curent_page();
549                         $page_mode = 'user_page';
550                         if ( empty( $persons ) ) {
551                                 $teams = self::_team_of_curent_page();
552                                 $page_mode = 'team_or_unit_page';
553                                 if ( empty( $teams ) ) {
554                                         $units = self::_unit_of_curent_page();
555                                         if ( empty( $units ) ) {
556                                                 $page_mode = 'main_structure_page';
557                                         }
558                                 }
559                         }
560                 } else {
561                   if ( empty( $persons ) ) {
562                         $page_mode = 'team_or_unit_page';
563                   } else {
564                         $page_mode = 'user_page';
565                   }
566                 }
567                 //Mise en tableau
568                 $teams_id         = MonLaboLib::prepare_multiple_values_variable_into_array( $teams );
569                 $units_id         = MonLaboLib::prepare_multiple_values_variable_into_array( $units );
570                 $persons_id     = MonLaboLib::prepare_multiple_values_variable_into_array( $persons );
572                 //----------------------------------------------------------------
573                 // 5.1 Traitement si le serveur de publication est Paris Descartes
574                 //----------------------------------------------------------------
575                 if ( 'DescartesPubli' === $base_to_use ) {
576                         $request_mode = 'native_html_display';
577                         $api_base_url = $options4['MonLabo_DescartesPubmed_api_url'].'?';
579                         //Paramètres communs
580                         $POST_query['lang'] = "$languageShortcode";
581                         $POST_query['type'] = '*';
582                         $POST_query['orga_types'] = 'par_titre';
583                         $POST_query['format'] = "$descartes_format_in_options";
584                         if ( strlen( $years )>0 ) {
585                                 $POST_query['annee'] = "$years";
586                         }
587                         if ( !('' === $limit) ) {
588                                 $POST_query['limit'] = intval( $limit );
589                         }
590                         if ( !('' === $offset) ) {
591                                 $POST_query['offset'] = intval( $offset );
592                         }
594                         //On ecrase les autres paramètres avec les paramètres experts
595                         $expert_mode = false;
596                         if ( '__empty__' != $descartes_alias ) {
597                                 $POST_query['alias'] = $descartes_alias;
598                                 $expert_mode = true;
599                         }
600                         if ( '__empty__' != $descartes_auteurid ) {
601                                 $POST_query['auteurid'] = $descartes_auteurid;
602                                 $expert_mode = true;
603                         }
604                         if ( '__empty__' != $descartes_equipe ) {
605                                 if ( '*' === $descartes_equipe ) {  //Get all the descartes_publi_team_id list of teams configured in MonLabo
606                                         $all_teams_id = MonLaboLib::secured_array_keys( $MonLabo_access_data->get_teams_information() );
607                                         $descartes_team_ids   = self::_MonLaboTeamsIds_into_publicationServerTeamsIds( $all_teams_id, $base_to_use );
608                                         if ( !empty( $descartes_team_ids ) ) { $descartes_equipe = MonLaboLib::secured_implode( '|', $descartes_team_ids ); }
609                                 }
610                                 $POST_query['equipe'] = $descartes_equipe;
611                                 $expert_mode = true;
612                         }
613                         if ( '__empty__' != $descartes_unite ) {
614                                 $POST_query['unite'] = $descartes_unite;
615                                 $expert_mode = true;
616                         }
617                         if ( '__empty__' != $descartes_typepub ) { //Ce paramètre expert est compatible avec les autres
618                                 $POST_query['type'] = $descartes_typepub;
619                         }
620                         if ( '__empty__' != $descartes_nohighlight ) { //Ce paramètre expert est compatible avec les autres
621                                 $POST_query['nohighlight'] = $descartes_nohighlight;
622                         }
623                         if ( '__empty__' != $descartes_orga_types ) { //Ce paramètre expert est compatible avec les autres
624                                 $POST_query['orga_types'] = $descartes_orga_types;
625                         }
626                         if ( '__empty__' != $descartes_format ) { //Ce paramètre expert est compatible avec les autres
627                                 $POST_query['format'] = $descartes_format;
628                         }
629                         if ( '__empty__' != $descartes_debug ) { //Ce paramètre expert est compatible avec les autres
630                                 $POST_query['debug'] = $descartes_debug;
631                         }
633                         if ( false === $expert_mode ) {
634                                 //En cas d'absence de paramètres experts
635                                 if ( 'team_or_unit_page' === $page_mode ) {
636                                         //Formatage de la requête
637                                         $descartes_team_ids   = self::_MonLaboTeamsIds_into_publicationServerTeamsIds( $teams_id, $base_to_use );
638                                         $descartes_unit_ids   = self::_MonLaboUnitsIds_into_publicationServerUnitsIds( $units_id, $base_to_use );
639                                         if ( !empty( $descartes_team_ids ) ) {
640                                                 $POST_query['equipe'] = MonLaboLib::secured_implode( '|', $descartes_team_ids );
641                                         }
642                                         if ( !empty( $descartes_unit_ids ) ) {
643                                                 $POST_query['unite'] = MonLaboLib::secured_implode( '|', $descartes_unit_ids );
644                                         }
645                                         if ( ( !empty( $descartes_team_ids ) ) or ( !empty( $descartes_unit_ids ) ) ) {
646                                                 if ( strlen( $years ) === 0 ) {
647                                                         $POST_query['annee'] = '-5'; //Par défaut prendre les 5 dernières années
648                                                 }
649                                         } else {
650                                                 //Page d'équipe ou d'unite, mais n'indique pas d'ID Descartes
651                                                 return array( '', '' ); /*Vide*/
652                                         }
653                                 } elseif ( 'user_page' === $page_mode ) {
654                                         $descartes_ids = self::_MonLaboPersonsIds_into_publicationServerAuthorsIds( $persons_id, $base_to_use );
655                                         if ( !empty( $descartes_ids ) ) {
656                                                 $POST_query['auteurid'] = MonLaboLib::secured_implode( '|', $descartes_ids );
657                                         } else {
658                                                 return array( '', '' ); /*Vide*/
659                                         }
660                                 } elseif ( 'main_structure_page' === $page_mode ) {
661                                         //On retourne les publications de toutes les personnes
662                                         $persons = '';
663                                         $all_persons_id = MonLaboLib::secured_array_keys( $MonLabo_access_data->get_persons_information() );
664                                         if ( !empty( $all_persons_id ) ) { $persons = MonLaboLib::secured_implode( '|', $all_persons_id ); }
665                                         $persons_id     = MonLaboLib::prepare_multiple_values_variable_into_array( $persons );
666                                         $descartes_ids = self::_MonLaboPersonsIds_into_publicationServerAuthorsIds( $persons_id, $base_to_use );
667                                         if ( !empty( $descartes_ids ) ) {
668                                                 $POST_query['auteurid'] = MonLaboLib::secured_implode( '|', $descartes_ids );
669                                         } else {
670                                                 return array( '', '' ); /*Vide*/
671                                         }
672                                 } else {
673                                         return array( '', '' ); /*Vide*/
674                                 }
675                         }
676                 //----------------------------------------------------
677                 // 5.2 Traitement si le serveur de publication est HAL
678                 //----------------------------------------------------
679                 } elseif ( 'hal' === $base_to_use ) {
681                         //Construction de la la requête de base
682                         //-------------------------------------
683                         list( $api_base_url, $POST_query, $request_mode ) = self::build_HAL_POST_query( $years, $languageHAL, $style_citation_reference );
685                         //Calcul du paramètre identifiant l'équipe, la personne ou la structure
686                         //---------------------------------------------------------------------
687                         $HAL_ids = array();
688                         $idHal = array();
690                         //On ecrase les autres paramètres avec les paramètres experts
691                         if ( '__empty__' != $hal_idhal ) {
692                                 $idHal= MonLaboLib::prepare_multiple_values_variable_into_array( $hal_idhal );
693                         } elseif ( '__empty__' != $hal_struct ) {
694                                 $HAL_ids = MonLaboLib::prepare_multiple_values_variable_into_array( $hal_struct );
695                         } else {
696                                 //En cas d'absence de paramètres experts
697                                 if ( 'user_page' === $page_mode ) { //Personne
698                                                 $idHal = self::_MonLaboPersonsIds_into_publicationServerAuthorsIds( $persons_id, $base_to_use );
699                                 } else {
701                                         //Determine la liste des ID HAL a utiliser
702                                         if ( 'team_or_unit_page' === $page_mode ) { //Equipe
704                                                 $HAL_ids =                                         self::_MonLaboTeamsIds_into_publicationServerTeamsIds( $teams_id, $base_to_use );
705                                                 // Si pas de hal_publi_team_id définis pour les équipes
706                                                 if ( ( !empty( $teams_id ) ) and ( empty( $HAL_ids ) ) ) {
707                                                         //Retourner les publications des membres de l'équipe
708                                                         foreach ( $teams_id as $team_id ) {
709                                                                 $idHal = array_merge( $idHal, self::_MonLaboPersonsIds_into_publicationServerAuthorsIds( $MonLabo_access_data->get_persons_id_for_a_team( $team_id ), $base_to_use ) );
710                                                         }
711                                                 }
712                                                 $unitHAL_ids = self::_MonLaboUnitsIds_into_publicationServerUnitsIds( $units_id, $base_to_use );
713                                                 $HAL_ids = array_merge( $HAL_ids, $unitHAL_ids );
715                                                 // Si pas de hal_publi_team_id définis pour les unités
716                                                 if ( ( !empty( $units_id ) ) and ( empty( $unitHAL_ids ) ) ) {
717                                                         //Retourner les publications des membres de l'unité
718                                                         foreach ( $units_id as $unit_id ) {
719                                                                 $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 ) );
720                                                         }
721                                                 }
722                                         } elseif ( 'main_structure_page' === $page_mode ) {
723                                                 if ( !empty( $options1['MonLabo_hal_publi_struct_id'] ) ) {
724                                                         $HAL_ids = MonLaboLib::prepare_multiple_values_variable_into_array( $options1['MonLabo_hal_publi_struct_id'] );
725                                                 }
726                                         }
727                                         //Nettoyage des ID HAL non numériques
728                                         if ( !empty( $HAL_ids ) ) {
729                                                 foreach ( $HAL_ids as $key => $value ) {
730                                                         if ( !is_numeric( $value ) ) {
731                                                                 unset( $HAL_ids[$key] );
732                                                         }
733                                                 }
734                                         }
735                                 }
736                         }
737                         if ( !( '' === $limit ) ) {
738                                 $POST_query['NbAffiche'] = intval( $limit );
739                         }
740                         //Les paramètres idHal et struct sont incompatibles.
741                         if ( !empty( $idHal ) ) {
742                                 $POST_query['idHal'] = MonLaboLib::secured_implode( ';', $idHal );
743                         } elseif ( !empty( $HAL_ids ) ) {
744                                 $POST_query['struct'] = MonLaboLib::secured_implode( ';', $HAL_ids );
745                         } else {
746                                 return array( '', '' ); /*Vide*/
747                         }
748                 }
750                 //---------------------------------------------------
751                 // 7 - contruire l'URL
752                 //---------------------------------------------------
753                 $url = '';
754                 if ( !( '' === $request_mode ) ) {
755                         $url = $api_base_url.http_build_query ( $POST_query );
756                 }
757                 return array( $request_mode, $url );
758         }
760         //==========================================================================
761         /**
762          * Analyseur syntaxique de la page retournée par haltools
763          * @param string $hal_content la page retournée par haltools
764          * @return array le tableau des publications [type][année][ordre][champs]
765          *                         champs : titre, auteur, article
766          */
767         //==========================================================================
768         static function parse_haltools_response( $hal_content = '' ) {
769                 $publi =array();
770           /*
771                 $caractere_texte = array( 'à', 'À', 'á', 'Á', 'â', 'Â', 'ã', 'Ā', 'ä', 'Ä', 'å', 'Å', 'æ', 'Æ',
772                                                                  'è', 'È', 'é', 'É', 'ê', 'Ê', 'ë', 'Ë',
773                                                                  'ì', 'Ì', 'í', 'Í', 'î', 'Î', 'ï', 'Ï',
774                                                                  'ò', 'Ò', 'ó', 'Ó', 'ô', 'Ô', 'õ', 'Õ', 'ö', 'Ö', 'ø', 'Ø',
775                                                                  'ù', 'Ù', 'ú', 'Ú', 'û', 'Û', 'ü', 'Ü',
776                                                                  'ñ', 'ç', 'Ç', 'ý', 'Ý', 'ß',
777                                                                  '°',
778                                                                 );
779                 */
780                 $caractere_texte = array( '&agrave;', '&Agrave;', '&aacute;', '&Aacute;', '&acirc;', '&Acirc;', '&atilde;', '&Atilde;', '&auml;', '&Auml;', '&aring;', '&Aring;', '&aelig;', '&AElig;',
781                                                                  '&egrave;', '&Egrave;', '&eacute;', '&Eacute;', '&ecirc;', '&Ecirc;', '&etilde;', '&Etilde;', '&euml;', '&Euml;',
782                                                                  '&igrave;', '&Igrave;', '&iacute;', '&Iacute;', '&icirc;', '&Icirc;', '&itilde;', '&Itilde;', '&iuml;', '&Iuml;',
783                                                                  '&ograve;', '&Ograve;', '&oacute;', '&Oacute;', '&ocirc;', '&Ocirc;', '&otilde;', '&Otilde;', '&ouml;', '&Ouml;', '&oslash;', '&Oslash;', '&oelig;', '&OElig;',
784                                                                  '&ugrave;', '&Ugrave;', '&uacute;', '&Uacute;', '&ucirc;', '&Ucirc;', '&utilde;', '&Utilde;', '&uuml;', '&Uuml;',
785                                                                  '&ntilde;', '&ccedil;', '&Ccedil;', '&yacute;', '&Yacute;', '&szlig;', '&amp;',
786                                                                  '&deg;',
787                                                                 );
788                 $caractere_latex = array( '{\`a}', '{\`A}', "{\'a}", "{\'A}", '{\^a}', '{\^A}', '{\~a}', '{\~A}', '{\"a}', '{\"A}', '{\aa}', '{\AA}', '{\ae}', '{\AE}',
789                                                                  '{\`e}', '{\`E}', "{\'e}", "{\'E}", '{\^e}', '{\^E}', '{\~e}', '{\~E}', '{\"e}', '{\"E}',
790                                                                  '{\`i}', '{\`I}', "{\'i}", "{\'I}", '{\^i}', '{\^I}', '{\~i}', '{\~I}', '{\"i}', '{\"I}',
791                                                                  '{\`o}', '{\`O}', "{\'o}", "{\'O}", '{\^o}', '{\^O}', '{\~o}', '{\~O}', '{\"o}', '{\"O}', '{\o}', '{\O}', '{\oe}', '{\OE}',
792                                                                  '{\`u}', '{\`U}', "{\'u}", "{\'U}", '{\^u}', '{\^U}', '{\~u}', '{\~U}', '{\"u}', '{\"U}',
793                                                                  '{\~n}', '{\c c}', '{\c C}', "{\'y}", "{\'Y}", '{\ss}', '\&',
794                                                                  '{\textdegree}',
795                                                                 );
796                 /*$webservice_class_instance = New $webservice_class_name();
797                 $hal_content = $webservice_class_instance->webpage_get_content( $url );*/
799                 $data_contenu = explode ( '@', $hal_content ); //Séparer chaque entrée bibliographique
800                 foreach ( $data_contenu as $id_publi => $datum_publi ) {
801                         $datum_publi = str_replace( $caractere_latex, $caractere_texte, $datum_publi );
802                         if ( 0 != $id_publi ) { //On ne prend que après le premier @
803                                 // correction du probleme de MONTH dans hal
804                                 //On recherche 'MONTH = truc, ' et on le remplace par 'MONTH = {truc}, '
805                                 //Cette recherche se fait indépendament de la case ( /i ) et du nombre de carracères d'espacement ou tabulation autour du =
806                                 $datum_publi = preg_replace( '/MONTH\s*=\s*(\S+)\s*,/i', 'MONTH = {${1}},', $datum_publi );
807                                 //type = mot en début de chaine avant le première accolade. (/s est pour le traitement multiligne)
808                                 $type = preg_replace( '/^([^{]+)\S*{.*/s','${1}',$datum_publi );
809                                 //contenu = tout ce qui est dans les accolades suivantes (les espaces et sauts de lignes autour ne comptent pas)
810                                 $contenu = preg_replace( '/^([^{]+)\S*{\S*(.*)\S*}\S*$/s','${2}', $datum_publi );
811                                 //On récupère un gros tableau des 'field' = 'values', en étant tolérant sur les espaces surnuméraires.
812                                 preg_match_all( '/(?P<field>\w+)[ \t]* = [ \t]*(?P<values>.*)\S*,\S*[\n\r\f]+/', $contenu, $matches );
813                                 $fields = $matches['field'];
814                                 $values = $matches['values'];
815                                 $publi_tmp = array();
816                                 foreach ( $fields as $key => $value ) {
817                                         $publi_tmp [strtoupper( $fields[$key] ) ] = $values[$key];
818                                 }
819                                 //nettoyage de chaque champs
820                                 foreach ( $publi_tmp as $key => $value ) {
821                                         $value = self::suppress_bibtex_value_limiter( $value );
822                                         $publi_tmp[$key] = str_replace( array( '{','}' ), '', $value );
823                                 }
824                                 if ( !empty( $publi_tmp['YEAR'] ) ) {
825                                         $annee = $publi_tmp['YEAR'];
826                                 } else {
827                                         $annee = 'unknown year'; //En cas de fichier bib invalide
828                                 }
829                                 if ( !empty( $publi_tmp['TYPE'] ) ) {
830                                         if ( strcmp( substr( $publi_tmp['TYPE'], 0, 12 ), 'Habilitation' ) === 0 ) {
831                                                 $publi['hdr'][$annee][] = $publi_tmp;
832                                         } elseif ( strcmp( $publi_tmp['TYPE'], 'Theses' ) === 0 ) {
833                                                 $publi['phdthesis'][$annee][] = $publi_tmp;
834                                         } else {
835                                                 $publi[$type][$annee][] = $publi_tmp;
836                                         }
837                                 } else {
838                                         $publi[$type][$annee][] = $publi_tmp;
839                                 }
840                         }
841                 }
842                 return $publi;
843         }
845         //==========================================================================
846         /**
847          * formatage des publications
848          * @param string $publi le tableau des publications[type][année][ordre][champs]
849          * @return string le html à afficher
850          */
851         //==========================================================================
852         static function format_publi( $format = 'ieee', $data_publi, $currentlang ) {
853                 //Voir https://doc.archives-ouvertes.fr/bib2hal/champs-bibtex-obligatoiresoptionnels-par-type/
854                 //Il faudra rajouter:
855                 //@conference
856                 //@presconf
857                 //@poster
858                 //@inbook
859                 //@proceedings
860                 //@manual
861                 //@note
863                 $type_name = array(
864                         'article'          => array( 'en' => 'Journal articles'                                         , 'fr' => 'Article dans une revue' ),
865                         'inproceedings' => array( 'en' => 'Conference papers'                                      , 'fr' => 'Communication dans un congrès' ),
866                         'incollection'  => array( 'en' => 'Book sections'                                                  , 'fr' => 'Chapitre d\'ouvrage' ),
867                         'book'            => array( 'en' => 'Books'                                                                , 'fr' => 'Ouvrage (y compris édition critique et traduction)' ),
868                         'hdr'              => array( 'en' => 'Habilitation à diriger des recherches'   , 'fr' => 'HDR' ),
869                         'mastersthesis' => array( 'en' => 'Master thesis'                                                  , 'fr' => 'Mémoire d\'étudiant' ),
870                         'techreport'    => array( 'en' => 'Reports'                                                              , 'fr' => 'Rapport' ),
871                         'misc'            => array( 'en' => 'Other publications'                                          , 'fr' => 'Autre publication' ),
872                         //Sont aussi classés dans la categorie bibtex @misc les catégories HAL suivantes :
873                         //                        - Posters
874                         //                        - Autre rapport, séminaire, workshop
875                         //                        - Document associé à des manifestations scientifiques
876                         //                        - Carte
877                         'phdthesis'      => array( 'en' => 'Theses'                                                               , 'fr' => 'Thèse' ),
878                         'unpublished'   => array( 'en' => 'Preprints, Working Papers, ...'                , 'fr' => 'Pré-publication, Document de travail' ),
879                         //Sont aussi classés dans la categorie bibtex @unpublished les catégories HAL suivantes :
880                         //                        - Cours
881                         'patent'                => array( 'en' => 'Patents'                                                              , 'fr' => 'Brevet' ), //TODO rajouter le formatage
882                         'proceedings'   => array( 'en' => 'Directions of work or proceedings'      , 'fr' => 'Direction d\'ouvrage, Proceedings, Dossier' ), //TODO rajouter le formatage
883                 );
884                 switch ( $currentlang ) {
885                         case 'en-US':
886                         case 'en-GB':
887                         case 'en_US':
888                         case 'en_GB':
889                                 $lang = 'en';
890                                 break;
892                         default:
893                                 $lang = 'fr';
894                                 break;
895                 }
897                 $a_afficher = '<div id="res_script">';
898                 if ( !empty( $data_publi ) ) {
899                         foreach ( $data_publi as $type => $datum_type ) {
900                                 if ( in_array( $type, MonLaboLib::secured_array_keys( $type_name ) ) ) { //Vérifier qu'on est capable de traiter le $type dans le switch
901                                         $a_afficher .= "<p class='Rubrique'>".$type_name[$type][$lang].'</p>';
902                                         foreach ( $datum_type as $date => $datum_date ) {
903                                                 $a_afficher .= "<p class='SousRubrique'>".$date.'</p>';
904                                                 foreach ( $datum_date as $ordre => $datum_order ) {
905                                                         if ( !empty( $datum_order['AUTHOR'] ) ) { //Ne rien afficher si pas d'auteur
906                                                                 $a_afficher .= "<dl class='NoticeRes'><dt class='ChampRes'>ref_biblio</dt><dd class='ValeurRes ref_biblio'>";
907                                                                 switch ( $format ) {
908                                                                         case 'ieee' :
909                                                                                 $a_afficher .= self::bibtex_to_ieee_authors( $datum_order['AUTHOR'] );
910                                                                                 switch ( $type ) {
911                                                                                         case 'article' :
912                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
913                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'JOURNAL', ' <i>#{field}</i>' );
914                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'VOLUME', ', vol. #{field}' );
915                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ', no. #{field}' );
916                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
917                                                                                                 $a_afficher .= ', ';
918                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
919                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
920                                                                                                 break;
921                                                                                         case 'inproceedings' : // Communication dans un congrès
922                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
923                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'BOOKTITLE', ' in <i>#{field}</i>' );
924                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'ADDRESS', ', #{field}' );
925                                                                                                 $a_afficher .= ', ';
926                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
927                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
928                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
929                                                                                                 break;
930                                                                                         case 'incollection' : // Chapitre d'ouvrage
931                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
932                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'BOOKTITLE', ' in <i>#{field}</i>' );
933                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'SERIES', ' (#{field})' );
934                                                                                                 if ( !empty( $datum_order['ADDRESS'] ) ) {
935                                                                                                   $a_afficher .= ', '.$datum_order['ADDRESS'];
936                                                                                                   $a_afficher .= self::format_bib_field( $datum_order, 'PUBLISHER', ': #{field}' );
937                                                                                                 } else {
938                                                                                                   $a_afficher .= self::format_bib_field( $datum_order, 'PUBLISHER', ', #{field}' );
939                                                                                                 }
940                                                                                                 $a_afficher .= ', ';
941                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
942                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
943                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
944                                                                                                 break;
945                                                                                         case 'book' : // Ouvrage (y compris édition critique et traduction )
946                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', <i>#{field}</i>' );
947                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'SERIES', ' (#{field})' );
948                                                                                                 if ( !empty( $datum_order['ADDRESS'] ) ) {
949                                                                                                   $a_afficher .= ', '.$datum_order['ADDRESS'];
950                                                                                                   $a_afficher .= self::format_bib_field( $datum_order, 'PUBLISHER', ': #{field}' );
951                                                                                                 } else {
952                                                                                                   $a_afficher .= self::format_bib_field( $datum_order, 'PUBLISHER', ', #{field}' );
953                                                                                                 }
954                                                                                                 $a_afficher .= ', ';
955                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
956                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
957                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
958                                                                                                 break;
959                                                                                         case 'hdr' : // HDR
960                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
961                                                                                                 $a_afficher .= ' H.D.R. dissertation';
962                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'SCHOOL', ', #{field}' );
963                                                                                                 $a_afficher .= ', ';
964                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
965                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
966                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
967                                                                                                 break;
968                                                                                         case 'mastersthesis' : // Mémoire d'étudiant
969                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
970                                                                                                 $a_afficher .= ' student dissertation';
971                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'SCHOOL', ', #{field}' );
972                                                                                                 $a_afficher .= ', ';
973                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
974                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
975                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
976                                                                                                 break;
977                                                                                         case 'techreport' : // Rapport
978                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
979                                                                                                 $a_afficher .= ' unpublished';
980                                                                                                 $a_afficher .= ', ';
981                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
982                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
983                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
984                                                                                                 break;
985                                                                                         case 'misc' : //Autre publication
986                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
987                                                                                                 $a_afficher .= ' unpublished';
988                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'HOWPUBLISHED', ', <i>#{field}</i>' );
989                                                                                                 $a_afficher .= ', ';
990                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
991                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
992                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
993                                                                                                 break;
994                                                                                         case 'phdthesis' : // Thèse
995                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
996                                                                                                 $a_afficher .= ' M.S. thesis';
997                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'SCHOOL', ', #{field}' );
998                                                                                                 $a_afficher .= ', ';
999                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
1000                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
1001                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ', no. #{field}' );
1002                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
1003                                                                                                 break;
1004                                                                                         case 'unpublished' : // Pré-publication, Document de travail
1005                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
1006                                                                                                 $a_afficher .= ' unpublished';
1007                                                                                                 $a_afficher .= ', ';
1008                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
1009                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
1010                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
1011                                                                                                 break;
1012                                                                                         case 'patent' : // brevet
1013                                                                                                 //http://libraryguides.vu.edu.au/ieeereferencing/standardsandpatents
1014                                                                                                 //Author(s) Initial(s). Surname(s), “Title of patent,” Published Patent’s country of origin and number xxxx, Abbrev. Month. Day, Year of Publication.​
1015                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
1016                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'ADDRESS', ' #{field}' );
1017                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ' Patent #{field}' );
1018                                                                                                 $a_afficher .= ', ';
1019                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
1020                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
1021                                                                                                 break;
1022                                                                                         case 'proceedings' : // Direction d'ouvrage, Proceedings, Dossier
1023                                                                                                 //http://libraryguides.vu.edu.au/ieeereferencing/confernenceproceedings
1024                                                                                                 //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.
1025                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
1026                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'BOOKTITLE', ' in <i>#{field}</i>' );
1027                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'ADDRESS', ', #{field}' );
1028                                                                                                 $a_afficher .= ', ';
1029                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', '#{field}. ' );
1030                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
1031                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'VOLUME', ', vol. #{field}' );
1032                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ', no. #{field}' );
1033                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', pp. #{field}' );
1034                                                                                                 break;
1035                                                                                 }
1036                                                                                 $a_afficher .= '.';
1037                                                                                 $a_afficher .= self::format_bib_field( $datum_order,  'DOI', ' <a target="_blank" href="http://dx.doi.org/#{field}">&lt;#{field}&gt;</a>.' );
1038                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'HAL_ID-URL', ' #{field}.' );
1039                                                                                 $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>' );
1040                                                                                 break;
1042                                                                         case 'apa' :
1043                                                                                 $a_afficher .= self::bibtex_to_apa_authors( $datum_order['AUTHOR'] );
1044                                                                                 $a_afficher .= ' (';
1045                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'YEAR', '#{field}' );
1046                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'MONTH', ', #{field}' );
1047                                                                                 $a_afficher .= ').';
1048                                                                                 switch ( $type ) {
1049                                                                                         case 'article' :
1050                                                                                                 $a_afficher .= ' ';
1051                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' #{field}.' );
1052                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'JOURNAL', ' <i>#{field}</i>' );
1053                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'VOLUME', ', #{field}' );
1054                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ' (#{field})' );
1055                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', #{field}' );
1056                                                                                                 break;
1057                                                                                         case 'inproceedings' : // Communication dans un congrès
1058                                                                                                 $a_afficher .= ' ';
1059                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' <i>#{field}</i>.' );
1060                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'BOOKTITLE', ' Paper presented at the #{field}' );
1061                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'ADDRESS', ', #{field}' );
1062                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'VOLUME', ', #{field}' );
1063                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ' (#{field})' );
1064                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', #{field}' );
1065                                                                                                 break;
1066                                                                                         case 'incollection' : // Chapitre d'ouvrage
1067                                                                                                 if ( !empty( $datum_order['EDITOR'] ) ) {
1068                                                                                                         $a_afficher .= ' In '.$datum_order['EDITOR'];
1069                                                                                                         $a_afficher .= self::format_bib_field( $datum_order, 'BOOKTITLE', ', <i>#{field}</i>' );
1070                                                                                                 } else {
1071                                                                                                         $a_afficher .= self::format_bib_field( $datum_order, 'BOOKTITLE', ' <i>#{field}</i>' );
1072                                                                                                 }
1073                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'BOOKTITLE', ', <i>#{field}</i>' );
1074                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'SERIES', ', #{field}' );
1075                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'VOLUME', ', #{field}' );
1076                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ' (#{field})' );
1077                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', #{field}' );
1078                                                                                                 break;
1079                                                                                         case 'book' : // Ouvrage (y compris édition critique et traduction)
1080                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' <i>#{field}</i>' );
1081                                                                                                 if ( !empty( $datum_order['EDITOR'] ) ) {
1082                                                                                                   $a_afficher .= ' In '.$datum_order['EDITOR'];
1083                                                                                                   $a_afficher .= self::format_bib_field( $datum_order, 'PUBLISHER', ', #{field}' );
1084                                                                                                 } else {
1085                                                                                                   $a_afficher .= self::format_bib_field( $datum_order, 'PUBLISHER', ' #{field}' );
1086                                                                                                 }
1087                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'BOOKTITLE', ', <i>#{field}</i>' );
1088                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'SERIES', ', #{field}' );
1089                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'VOLUME', ', #{field}' );
1090                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ' (#{field})' );
1091                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', #{field}' );
1092                                                                                                 break;
1093                                                                                         case 'hdr' : // HDR
1094                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' <i>#{field}</i>' );
1095                                                                                                 if ( empty( $datum_order['PDF'] ) ) {
1096                                                                                                         $a_afficher .= ', HDR not published ';
1097                                                                                                         $a_afficher .= self::format_bib_field( $datum_order, 'SCHOOL', ', HDR not published #{field}' );
1098                                                                                                 } else {
1099                                                                                                         $a_afficher .= self::format_bib_field( $datum_order, 'SCHOOL', ', HDR (#{field})' );
1100                                                                                                 }
1101                                                                                                 break;
1102                                                                                         case 'mastersthesis' : // Mémoire d'étudiant
1103                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' <i>#{field}</i>' );
1104                                                                                                 if ( empty( $datum_order['PDF'] ) ) {
1105                                                                                                         $a_afficher .= ', HDR not published ';
1106                                                                                                         $a_afficher .= self::format_bib_field( $datum_order, 'SCHOOL', ', HDR not published #{field}' );
1107                                                                                                 } else {
1108                                                                                                         $a_afficher .= self::format_bib_field( $datum_order, 'SCHOOL', ', HDR (#{field})' );
1109                                                                                                 }
1110                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', #{field}' );
1111                                                                                                 break;
1112                                                                                         case 'techreport' : // Rapport
1113                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' <i>#{field}</i>' );
1114                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ' (#{field})' );
1115                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'INSTITUTION', ', #{field}' );
1116                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', #{field}' );
1117                                                                                                 break;
1118                                                                                         case 'misc' : // Autre publication
1119                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' <i>#{field}</i>' );
1120                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'HOWPUBLISHED', ', Paper presented at the #{field}' );
1121                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', #{field}' );
1122                                                                                                 break;
1123                                                                                         case 'phdthesis' : // Thèse
1124                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' <i>#{field}</i>' );
1125                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ' (#{field})' );
1126                                                                                                 if (empty( $datum_order['PDF'] ) ) {
1127                                                                                                         $a_afficher .= ', Thesis not published ';
1128                                                                                                         $a_afficher .= self::format_bib_field( $datum_order, 'SCHOOL', ', Thesis not published #{field}' );
1129                                                                                                 } else {
1130                                                                                                         $a_afficher .= self::format_bib_field( $datum_order, 'SCHOOL', ', Thesis (#{field})' );
1131                                                                                                 }
1132                                                                                                 break;
1133                                                                                         case 'unpublished' : // Pré-publication, Document de travail
1134                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' <i>#{field}</i>' );
1135                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ', #{field}' );
1136                                                                                                 break;
1137                                                                                         case 'patent' : // brevet
1138                                                                                                 //http://libraryguides.vu.edu.au/apa-referencing/patents-and-standards
1139                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ' <i>#{field}</i>' );
1140                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'NUMBER', ' <i>No. #{field}</i>' );
1141                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'ADDRESS', '#{field}' );
1142                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PUBLISHER', ': #{field}' );
1143                                                                                                 break;
1144                                                                                         case 'proceedings' : // Direction d'ouvrage, Proceedings, Dossier
1145                                                                                                 //http://libraryguides.vu.edu.au/apa-referencing/conference-proceedings
1146                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'TITLE', ', "#{field},"' );
1147                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'EDITOR', ', #{field}' );
1148                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'BOOKTITLE', ', <i>#{field}</i>' );
1149                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PAGES', ' (pp. #{field})' );
1150                                                                                                 $a_afficher .= '. ';
1151                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'ADDRESS', '#{field}' );
1152                                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'PUBLISHER', ': #{field}' );
1153                                                                                                 break;
1154                                                                                 }
1155                                                                                 $a_afficher .= '.';
1156                                                                                 $a_afficher .= self::format_bib_field( $datum_order,  'DOI', ' <a target="_blank" href="http://dx.doi.org/#{field}">&lt;#{field}&gt;</a>.' );
1157                                                                                 $a_afficher .= self::format_bib_field( $datum_order, 'HAL_ID-URL', ' #{field}.' );
1158                                                                                 $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>' );
1159                                                                                 break;
1160                                                                 }
1161                                                                 $a_afficher .= '</dd></dl>';
1162                                                         }
1163                                                 }
1164                                         }
1165                                 }
1166                         }
1167                 }
1168                 $a_afficher .= '</div>';
1169                 return $a_afficher;
1170         }
1172         //==========================================================================
1173         /**
1174          * formatage des auteurs au format IEEE à partir des auteurs BibTex
1175          * @param string $authors_bib_string auteurs au format BibTex
1176          * @return string auteurs au format IEEE
1177          */
1178         //==========================================================================
1179         static function bibtex_to_ieee_authors( $authors_bib_string ) {
1180                 $authors = explode( ' and ', $authors_bib_string );
1181                 $authors_names = array();
1182                 foreach ( $authors as $author ) {
1183                         $names = explode( ',', $author );
1184                         $first_names = explode( ' ', trim( $names[1] ) );
1185                         $abreviated_first_names = array();
1186                         foreach ( $first_names as $first_name_datum ) {
1187                                 $composed_first_names = explode( '-', $first_name_datum );
1188                                 if ( count( $composed_first_names ) > 1 ) {
1189                                         $abreviated_composed_first_names = array();
1190                                         foreach ( $composed_first_names as $composed_first_name ) {
1191                                                 $abreviated_composed_first_names[] = strtoupper( substr( trim( $composed_first_name ), 0, 1 ) ).'.';
1192                                         }
1193                                         $abreviated_first_names[] = MonLaboLib::secured_implode( '-', $abreviated_composed_first_names );
1194                                 } else {
1195                                         $abreviated_first_names[] = strtoupper( substr( trim( $composed_first_names[0] ), 0, 1 ) ).'.';
1196                                 }
1197                         }
1198                         $last_names = explode( ' ', trim( $names[0] ) );
1199                         $cased_last_names = array();
1200                         foreach ( $last_names as $last_name_datum ) {
1201                                 $composed_last_names = explode( '-', $last_name_datum );
1202                                 if ( count( $composed_last_names ) > 1 ) {
1203                                         $cased_composed_last_names = array();
1204                                         foreach ( $composed_last_names as $composed_last_name ) {
1205                                                 $cased_composed_last_names[] = ucwords( strtolower( trim( $composed_last_name ) ) );
1206                                         }
1207                                         $cased_last_names[] = MonLaboLib::secured_implode( '-', $cased_composed_last_names );
1208                                 } else {
1209                                         $cased_last_names[] = ucwords( strtolower( trim( $composed_last_names[0] ) ) );
1210                                 }
1211                         }
1212                         $first_name = MonLaboLib::secured_implode( ' ', $abreviated_first_names );
1213                         $last_name = MonLaboLib::secured_implode( ' ', $cased_last_names );
1214                         $authors_names[] = $first_name.' '.$last_name;
1215                 }
1216                 if ( count( $authors ) > 1 ) {
1217                         $authors_name = MonLaboLib::secured_implode( ', ', array_splice( $authors_names, 0, count( $authors_names )-1 ) );
1218                         if ( !empty( $authors_names ) ) {
1219                                 $authors_name .= ', and '.$authors_names[0];
1220                         }
1221                 } else {
1222                         $authors_name = $authors_names[0];
1223                 }
1224                 return $authors_name;
1225         }
1227         //==========================================================================
1228         /**
1229          * formatage des auteurs au format APA à partir des auteurs BibTex
1230          * @param string $authors_bib_string auteurs au format BibTex
1231          * @return string auteurs au format APA
1232          */
1233         //==========================================================================
1234         static function bibtex_to_apa_authors( $authors_bib_string ) {
1235                 $authors = explode( ' and ', $authors_bib_string );
1236                 $authors_names = array();
1237                 foreach ( $authors as $author ) {
1238                         $names = explode( ',', $author );
1239                         $first_names = explode( ' ', trim( $names[1] ) );
1240                         $abreviated_first_names = array();
1241                         foreach ( $first_names as $first_name_datum ) {
1242                                 $composed_first_names = explode( '-', $first_name_datum );
1243                                 if ( count( $composed_first_names ) > 1 ) {
1244                                         $abreviated_composed_first_names = array();
1245                                         foreach ( $composed_first_names as $composed_first_name ) {
1246                                                 $abreviated_composed_first_names[] = strtoupper( substr( trim( $composed_first_name ), 0, 1 ) ).'.';
1247                                         }
1248                                         $abreviated_first_names[] = MonLaboLib::secured_implode( '-', $abreviated_composed_first_names );
1249                                 } else {
1250                                         $abreviated_first_names[] = strtoupper( substr( trim( $composed_first_names[0] ), 0, 1 ) ).'.';
1251                                 }
1252                         }
1253                         $first_name = MonLaboLib::secured_implode( '', $abreviated_first_names );
1254                         $last_name = ucwords( strtolower( trim( $names[0] ) ) );
1255                         $authors_names[] = $last_name.', '.$first_name;
1256                 }
1257                 if ( count( $authors ) > 1 ) {
1258                         $authors_name = MonLaboLib::secured_implode(', ', array_splice( $authors_names, 0, count( $authors_names )-1 ) );
1259                         if ( !empty( $authors_names ) ) {
1260                                 $authors_name .= ', & '.$authors_names[0];
1261                         }
1262                 } else {
1263                         $authors_name = $authors_names[0];
1264                 }
1265                 return $authors_name;
1266         }
1268         //==========================================================================
1269         /**
1270          * formatage des champs issus d'un fichier BibTex
1271          * @param array $array tableau où récupérer le champs BibTex
1272          * @param string $field index du champs du tableau à récupérer
1273          * @param string $format formatage à produire à partir du champs
1274          * @return string code HTML généré
1275          */
1276         //==========================================================================
1277         static function format_bib_field( $array, $field, $format ) {
1278                 $a_afficher = '';
1279                 $field = strtoupper( $field );
1280                 //Pre-preprocess:
1281                 //-----------
1282                 if ( 'HAL_ID-URL' === $field ) {
1283                         if ( !empty( $array['HAL_ID'] ) and !empty( $array['URL'] ) ) {
1284                                 //lien de HAL_ID avec URL
1285                                 $field = 'HAL_ID';
1286                                 $format = str_replace( '#{field}', '<a target="_blank" href="'.$array['URL'].'">&lt;#{field}&gt;</a>', $format );
1287                         } elseif ( !empty( $array['HAL_ID'] ) and  empty( $array['URL'] ) ) {
1288                                 //lien de HAL_ID avec HAL_ID
1289                                 $field = 'HAL_ID';
1290                                 $format = str_replace( '#{field}', '<a target="_blank" href="https://hal.archives-ouvertes.fr/'.$array['HAL_ID'].'">&lt;#{field}&gt;</a>', $format );
1291                         } elseif ( empty( $array['HAL_ID'] ) and !empty( $array['URL'] ) ) {
1292                                 //lien URL simple
1293                                 $field = 'URL';
1294                                 $format = str_replace( '#{field}', '<a target="_blank" href="'.$array['URL'].'">#{field}</a>', $format );
1295                         } else {
1296                                 //ne rien afficher
1297                                 $field = 'INVALID';
1298                         }
1299                 }
1301                 if ( !empty( $array[$field] ) ) {
1303                         //Preprocess:
1304                         //-----------
1305                         switch ( $field ) {
1306                                 case 'PAGES':
1307                                 $reprocessed = trim( str_replace( 'p', '', str_replace( 'p.', '', str_replace( 'pp', '', str_replace( 'pp.', '', $array[$field] ) ) ) ) );
1308                                 break;
1310                                 case 'MONTH':
1311                                 $reprocessed = substr( $array[$field], 0, 3 );
1312                                 break;
1314                                 default:
1315                                 $reprocessed = $array[$field];
1316                                 break;
1317                         }
1319                         //Process:
1320                         //-------
1321                         $a_afficher .= str_replace( '#{field}', $reprocessed, $format );
1322                 }
1323                 return $a_afficher;
1324         }
1328 /**
1329  * Class MonLabo_contact_webservices
1330  *
1331  * @package
1332  */
1333 class MonLabo_contact_webservices {
1334         //==========================================================================
1335         /**
1336          * Récupère le contenur d'une URL
1337          * @param string $url URL du contenu à récupérer
1338          * @return string contenu de la page à l'adresse $url
1339          */
1340         //==========================================================================
1341         function webpage_get_content( $url ) {
1342                 $contenu = wp_remote_get( $url );
1343                 if ( ( ! is_wp_error( $contenu ) ) and ( array_key_exists( "body", $contenu ) ) ) {
1344                         return $contenu['body'];
1345                 } else {
1346                         return "";
1347                 }
1348         }
1350 ?>