PluginProbe
HAL / 2.7
HAL v2.7
trunk 1.0 1.1 1.2 1.3 1.4 1.4.2 1.4.3 1.4.4 2.0 2.0.1 2.0.10 2.0.2 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.2 2.3 2.4 2.4.1 2.4.2 2.5 All 30 releases
hal / wp-hal.php

wp-hal.php in HAL 2.7, at wp-hal.php

1,537 lines 88.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: HAL
4 * Plugin URI: http://www.ccsd.cnrs.fr
5 * Description: Crée une page qui remonte les publications d'un auteur ou d'une structure en relation avec HAL et un widget des dernières publications d'un auteur ou d'une structure.
6 * Version: 2.6.1
7 * Author: CCSD
8 * Author URI: http://www.ccsd.cnrs.fr
9 * Text Domain: wp-hal
10 * Domain Path: /lang/
11 */
12
13
14 // Traduction de la description
15 __("Crée une page qui remonte les publications d'un auteur ou d'une structure en relation avec HAL et un widget des dernières publications d'un auteur ou d'une structure.", "wp-hal");
16
17 //Récupère les constantes
18 require_once("constantes.php");
19
20
21 if (wphal_locale == 'fr_FR') {
22 define('wphal_lang', 'fr');
23 } elseif (wphal_locale == 'es_ES') {
24 define('wphal_lang', 'es');
25 } else {
26 define('wphal_lang', 'en');
27 }
28
29 function wphal_is_curl_installed() {
30 $loaded_extentions = get_loaded_extensions();
31 if (in_array ('curl', $loaded_extentions)) {
32 return true;
33 }
34 else {
35 return false;
36 }
37 }
38
39 // Création du shortcode ('nom du shortcode', 'fonction appelée')
40 add_shortcode( 'cv-hal', 'wphal_cv_hal' );
41 add_shortcode( 'nb-doc', 'wphal_nb_doc' );
42
43
44 function wphal_charger_languages() {
45 load_plugin_textdomain('wp-hal', false, dirname(plugin_basename(__FILE__)) . '/lang/');
46 }
47
48 add_action('plugins_loaded', 'wphal_charger_languages');
49
50 function wphal_action_links( $links, $file ) {
51 if ( $file != plugin_basename( __FILE__ ))
52 return $links;
53
54 $settings_link = '<a href="admin.php?page=wp-hal.php">' . __( 'Paramètres', 'wp-hal' ) . '</a>';
55
56 array_unshift( $links, $settings_link );
57
58 return $links;
59 }
60
61 add_filter( 'query_vars', 'wphal_query_vars' );
62 function wphal_query_vars( $query_vars ) {
63 $query_vars[] = 'hal_page';
64 return $query_vars;
65 }
66
67 add_filter( 'plugin_action_links', 'wphal_action_links',10,2);
68 /**
69 * @param $url
70 * @return object
71 */
72 function wphal_do_common_curl_call($url) {
73 $response = wp_remote_get($url, [
74 'timeout'=>20,
75 'user-agent'=>"HAL Plugin Wordpress " . wphal_version,
76 'headers' => ['Content-type'=> 'application/json']
77 ]);
78 // we could ve parsed the response but if in general if no results then we get empty content
79 $body = wp_remote_retrieve_body($response);
80 // Récupération du résultat JSON
81 $json = json_decode($body);
82 return $json;
83 }
84
85 function wphal_clear_transients()
86 {
87 global $wpdb;
88 // delete all "hal namespace" transients
89 $sql = "
90 DELETE
91 FROM {$wpdb->options}
92 WHERE option_name like '\_transient\_hal\_%'
93 OR option_name like '\_transient\_timeout\_hal\_%'
94 ";
95
96 $wpdb->query($sql);
97 }
98
99 /**
100 * fetches data from cache or download data from HAL API
101 * @param $url
102 * @return object
103 */
104 function wphal_do_get_data($url) {
105 $transient_id = 'hal_'.md5($url);
106 if(!empty(get_option('option_erase_cache'))){
107 // we reset cache transient for hal namespace
108 wphal_clear_transients();
109 update_option('option_erase_cache', '');
110 }
111 $cache_expiration = empty(get_option('option_cache_timeout')) ? 1 * DAY_IN_SECONDS : intval(get_option('option_cache_timeout')) * MINUTE_IN_SECONDS;
112 if ( false === ( $value = get_transient( $transient_id ) ) ) {
113 $json = wphal_do_common_curl_call($url);
114 if($json)
115 set_transient( $transient_id, $json, $cache_expiration);
116 return $json;
117 } else{
118 return $value;
119 }
120 }
121
122 /**
123 * PLUGIN SHORTCODE ND-DOC
124 * @param $param
125 * @return int
126 */
127 function wphal_nb_doc($param)
128 {
129 $idhal = wphal_verifSolr(get_option('option_idhal'));
130 extract(shortcode_atts(array(
131 'type' => get_option('option_type'),
132 'id' => $idhal
133 ),
134 $param
135 ));
136 /**
137 * @var $id : defined by extract
138 * @var string $type : defined by extract
139 */
140 $id = wphal_verifSolr($id);
141
142 $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&rows=0&wt=json';
143
144 $json =wphal_do_get_data($url);
145 return $json->response->numFound;
146 }
147 /**
148 * PLUGIN SHORTCODE CV-HAL
149 * @param $param
150 * @return string
151 */
152 function wphal_cv_hal($param){
153 $content = '';
154 if ( !wphal_is_curl_installed() ) {
155 $content = 'CURL not installed, please check the <a href="https://wordpress.org/plugins/hal/faq/" target="_blank" id="curl">FAQ</a> with the code : CURL';
156 } else {
157 $possible_ids = ["authIdHal_s", "structId_i", "anrProjectId_i", "europeanProjectId_i", "collCode_s"];
158 $option_choix = !empty(get_option('option_choix')) ? get_option('option_choix') : [];
159 if(in_array('disciplines', $option_choix)){ //Lance les scripts pour le Graphique
160 wp_enqueue_style('wp-hal-style2');
161
162 wp_enqueue_script('wp-hal-script1');
163 wp_enqueue_script('wp-hal-script2');
164 wp_enqueue_script('wp-hal-script3');
165 }
166 $facetdomain = null;
167
168 // those parameters are configured from plusing settings
169 $default_id = wphal_verifSolr(get_option('option_idhal'));
170 $default_type = get_option('option_type');
171 $default_contact = get_option('option_infocontact');
172 // here we merge with shortcode parameters
173 extract(shortcode_atts(array(
174 'type' => $default_type,
175 'id' => $default_id,
176 'contact' => $default_contact
177 ),
178 $param
179 ));
180 $content = 'Plugin is not configured correctly or shortcode parameters are not valid, please check the <a href="https://doc.hal.science/afficher-une-liste-de-publications-dans-wordpress/" target="_blank" id="wrong_params">documentation</a>';
181
182 /** @var $id : defined by extract
183 * @var string $type : defined by extract
184 * @var string $contact : defined by extract
185 */
186 if (!empty($id) && in_array($type, $possible_ids)) {
187 $id = wphal_verifSolr($id);
188
189 // in case the type is struct we need to split in order to build facet and display it back
190 $structIDs =[];
191 if($type=="structId_i"){
192 $structIDs = explode(' OR ', $id);
193 }
194
195 $facets = wphal_buildfacet($option_choix, $structIDs);
196 $facetQuery = !empty($facets) ? 'facet.field='.implode("&facet.field=", $facets).'&facet.limit=200&facet.mincount=1&facet=true':'';
197
198 if (get_option('option_groupe') == 'grouper') {
199 //cURL sur l'API pour récupérer les données
200 $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&group=true&group.field=docType_s&group.limit=1000&fl=docid,citationFull_s&'.$facetQuery.'&sort=' . wphal_producedDateY . '&wt=json&json.nl=arrarr';
201 } elseif (get_option('option_groupe') == 'paginer') {
202 $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&fl=docid,citationFull_s&'.$facetQuery.'&sort=' . wphal_producedDateY . '&wt=json&json.nl=arrarr';
203 }
204
205 $json = wphal_do_get_data($url);
206 if(!isset($json->error)){
207 $hal_page = (get_query_var('hal_page')) ? get_query_var('hal_page') : 1;
208
209 $content = '<div id="wphal-content">';
210 if (is_array($option_choix) && !empty($option_choix)){
211 $content .= '<ul id="wphal-menu">';
212 $content .= '<li><a href="#publications" onclick="displayElem(\'publications\'); return false;" style="font-size:18px; text-decoration: none;">' . __('Publications', 'wp-hal') . '</a></li>';
213
214 $content .= '<li><a href="#filtres" onclick="return false;" style="font-size:18px; text-decoration: none; cursor:default;">' . __('Filtres', 'wp-hal') . '</a>';
215 $content .= '<ul id="wphal-filtres">';
216 foreach ($option_choix as $option) {
217 if ($option == 'contact') {
218 $content .= '<li><a href="#contact" onclick="displayElem(\'wphal-contact\'); return false;" style="margin:1px; text-decoration: none;">' . __('Contact', 'wp-hal');
219 $content .= '</a></li>';
220 }
221 if ($option == 'disciplines') {
222 $content .= '<li><a href="#disciplines" onclick="displayElem(\'wphal-disciplines\'); return false;" style="margin:1px; text-decoration: none;">' . __('Disciplines', 'wp-hal');
223 $content .= '</a></li>';
224 }
225 if ($option == 'mots-clefs') {
226 $content .= '<li><a href="#keywords" onclick="displayElem(\'wphal-keywords\'); return false;" style="margin:1px; text-decoration: none;">' . __('Mots-clefs', 'wp-hal');
227 $content .= '</a></li>';
228 }
229 if ($option == 'auteurs') {
230 $content .= '<li><a href="#auteurs" onclick="displayElem(\'wphal-auteurs\'); return false;" style="margin:1px; text-decoration: none;">' . __('Auteurs', 'wp-hal');
231 $content .= '</a></li>';
232 }
233 if ($option == 'affiliated') {
234 $content .= '<li><a href="#affiliated" onclick="displayElem(\'wphal-affiliated\'); return false;" style="margin:1px; text-decoration: none;">' . __('Auteurs de la structure', 'wp-hal');
235 $content .= '</a></li>';
236 }
237 if ($option == 'revues') {
238 $content .= '<li><a href="#revues" onclick="displayElem(\'wphal-revues\'); return false;" style="margin:1px; text-decoration: none;">' . __('Revues', 'wp-hal');
239 $content .= '</a></li>';
240 }
241 if ($option == 'annee') {
242 $content .= '<li><a href="#annees" onclick="displayElem(\'wphal-annees\'); return false;" style="margin:1px; text-decoration: none;">' . __('Année de production', 'wp-hal');
243 $content .= '</a></li>';
244 }
245 if ($option == 'institution') {
246 $content .= '<li><a href="#insts" onclick="displayElem(\'wphal-insts\'); return false;" style="margin:1px; text-decoration: none;">' . __('Institutions', 'wp-hal');
247 $content .= '</a></li>';
248 }
249 if ($option == 'laboratoire') {
250 $content .= '<li><a href="#labs" onclick="displayElem(\'wphal-labs\'); return false;" style="margin:1px; text-decoration: none;">' . __('Laboratoires', 'wp-hal');
251 $content .= '</a></li>';
252 }
253 if ($option == 'departement') {
254 $content .= '<li><a href="#depts" onclick="displayElem(\'wphal-depts\'); return false;" style="margin:1px; text-decoration: none;">' . __('Départements', 'wp-hal');
255 $content .= '</a></li>';
256 }
257 if ($option == 'equipe') {
258 $content .= '<li><a href="#equipes" onclick="displayElem(\'wphal-equipes\'); return false;" style="margin:1px; text-decoration: none;">' . __('Équipes de recherche', 'wp-hal');
259 $content .= '</a></li>';
260 }
261 }
262 $content .= '</ul></li>';
263
264 $content .= '</ul><br/><hr>';
265 }
266
267 $content .= '<div id="meta">
268 <div class="display" id="wphal-contact" style="display: none;">
269 <h3 class="wphal-titre">' . __('Contact', 'wp-hal');
270 $content .= '</h3>
271
272 <ul id="wphal-cont" style="list-style-type: none;">';
273
274 if ($contact == 'yes' && $type == 'authIdHal_s') {
275 $urlauthor = wphal_urlauthor . '?indent=true&fq=valid_s:PREFERRED&fl=fullName_s,idHal_s,hasCV_bool,arxivId_s,idrefId_s,isniId_s,orcidId_s,viafId_s&q=idHal_s:' . urlencode($id);
276 $jsonauthor = wphal_do_get_data($urlauthor);
277
278 foreach ($jsonauthor->response->docs as $i=>$doc) {
279 $content .= '<div class="wphal-infocontact" id="wphal-infocontact'.$i.'">';
280 if ($doc->fullName_s != '') {
281 $content .= '<li class="wphal-fullname"><span>Nom : </span><span>'. $doc->fullName_s .'</span></li>';
282 }
283 if ($doc->idHal_s != '') {
284 $content .= '<li class="wphal-idhal"><span>IdHAL : </span><span>' . $doc->idHal_s . '</span></li>';
285 }
286 if ($doc->hasCV_bool == true){
287 $content .= '<li class="wphal-cvhal"><span>CV HAL : </span><a href="'.esc_url(cvhal. $doc->idHal_s).'" target="_blank">CV de '.$doc->fullName_s.'</a></li>';
288 }
289 if (isset($doc->arxivId_s ) && is_array($doc->arxivId_s)) {
290 $content .= '<li class="wphal-"><span>arXiv : </span><span>';
291 foreach($doc->arxivId_s as $arxivId_s){
292 $content .= '<a href="' . esc_url($arxivId_s) . '" target="_blank">' . substr(strrchr($arxivId_s, "/"), 1) . '</a> ,';
293 }
294 $content .= '</span></li>';
295 }
296 if (isset($doc->idrefId_s ) && is_array($doc->idrefId_s)) {
297 $content .= '<li class="wphal-"><span>IdRef : </span><span>';
298 foreach($doc->idrefId_s as $idref){
299 $content .= '<a href="' . esc_url($idref) . '" target="_blank">' . substr(strrchr($idref, "/"), 1) . '</a> ,';
300 }
301 $content .= '</span></li>';
302 }
303 if (isset($doc->orcidId_s ) && $doc->orcidId_s != '') {
304 $content .= '<li class="wphal-"><span>ORCID : </span><span>';
305 foreach($doc->orcidId_s as $orcidId_s){
306 $content .= '<a href="' . esc_url($orcidId_s) . '" target="_blank">' . substr(strrchr($orcidId_s, "/"), 1) . '</a> ,';
307 }
308 $content .= '</span></li>';
309 }
310 if (isset($doc->viafId_s ) && $doc->viafId_s != '') {
311 $content .= '<li class="wphal-"><span>VIAF : </span><span>';
312 foreach($doc->viafId_s as $viafId_s){
313 $content .= '<a href="' . esc_url($viafId_s) . '" target="_blank">' . substr(strrchr($viafId_s, "/"), 1) . '</a> ,';
314 }
315 $content .= '</span></li>';
316 }
317 if (isset($doc->isniId_s ) && $doc->isniId_s != '') {
318 $content .= '<li class="wphal-"><span>ISNI : </span><span>';
319 foreach($doc->isniId_s as $isniId_s){
320 $content .= '<a href="' . esc_url($isniId_s) . '" target="_blank">' . substr(strrchr($isniId_s, "/"), 1) . '</a> ,';
321 }
322 $content .= '</span></li>';
323 }
324 $content .= '</div>';
325 }
326 }
327 if (get_option('option_email') != '') {
328 $content .= '<li><img alt="mail" src=" ' . esc_url(plugin_dir_url(__FILE__) . 'img/mail.svg').' " style=" width:16px; margin-left:2px; margin-right:2px;"/><a href="'.esc_url('mailto:' . get_option('option_email')) . '" target="_blank">' . get_option('option_email') . '</a></li>';
329 }
330 if (get_option('option_tel') != '') {
331 $content .= '<li><img alt="phone" src=" ' . esc_url(plugin_dir_url(__FILE__) . 'img/phone.svg'). '" style="width:16px; margin-left:2px; margin-right:2px;"/>' . get_option('option_tel') . '</li>';
332 }
333 if (get_option('option_social0') != '') {
334 $content .= '<li><a href="'.esc_url('http://www.facebook.com/' . get_option('option_social0')) . '" target="_blank"><img
335 alt="Facebook" src=" ' . esc_url(plugin_dir_url(__FILE__) . 'img/facebook.svg').'" style="width:32px; margin:4px;"/></a></li>';
336 }
337 if (get_option('option_social1') != '') {
338 $content .= '<li><a href="'.esc_url('http://www.twitter.com/' . get_option('option_social1')) . '" target="_blank"><img
339 alt="Twitter" src=" ' . esc_url(plugin_dir_url(__FILE__) . 'img/twitter.svg').'" style="width:32px; margin:4px;"/></a></li>';
340 }
341 if (get_option('option_social2') != '') {
342 $content .= '<li><a href="'.esc_url('https://plus.google.com/u/0/+' . get_option('option_social2')) . '" target="_blank"><img
343 alt="Google+" src=" ' . esc_url(plugin_dir_url(__FILE__) . 'img/google-plus.svg').'" style="width:32px; margin:4px;"/></a></li>';
344 }
345 if (get_option('option_social3') != '') {
346 $content .= '<li><a href="'.esc_url('https://www.linkedin.com/in/' . get_option('option_social3')) . '" target="_blank"><img
347 alt="LinkedIn" src=" ' . esc_url(plugin_dir_url(__FILE__) . 'img/linkedin.svg').'" style="width:32px; margin:4px;"/></a></li>';
348 }
349 $content .= '</ul>
350 </div>
351 <div class="display" id="wphal-disciplines" style="display: none;">
352 <h3 class="wphal-titre">' . __('Disciplines', 'wp-hal') . '</h3>';
353
354 if (wphal_locale == 'fr_FR') {
355 $facetdomain = isset($json->facet_counts->facet_fields->fr_domainAllCodeLabel_fs) ? $json->facet_counts->facet_fields->fr_domainAllCodeLabel_fs:null;
356 } elseif (wphal_locale == 'es_ES') {
357 $facetdomain = isset($json->facet_counts->facet_fields->es_domainAllCodeLabel_fs) ? $json->facet_counts->facet_fields->es_domainAllCodeLabel_fs:null;
358 } else {
359 $facetdomain = isset($json->facet_counts->facet_fields->en_domainAllCodeLabel_fs) ? $json->facet_counts->facet_fields->en_domainAllCodeLabel_fs:null;
360 }
361
362 if (!is_null($facetdomain) && !empty($facetdomain)) {
363 $content .= '<div id="listdisci">';
364 $content .= '<span id="tridisciplines">';
365 $content .= '<button type="button" class="trial" id="tridisci" onclick="toggleSort(this, true, \'wphal-discipline\', \'wphal-discipline\', \'tridisci\'); return false;" style="font-size:16px; text-decoration: none;" >Tri Alphabétique</button>';
366 $content .= '<button type="button" class="trioc" id="trinbdisci" onclick="toggleSort(this, false, \'wphal-discipline\', \'wphal-discipline\', \'trinbdisci\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
367 $content .= '</span>';
368 $content .= '<ul id="wphal-discipline" class="wphal-discipline">';
369 foreach ($facetdomain as $res) {
370 $name = explode(wphal_delimiter, $res[0]);
371 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=domainAllCode_s:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
372 }
373 $content .= '</ul>';
374 $content .= '</div>';
375
376 $content .= '<div id="wphal-graph" style="display:none;">';
377 $content .= '<div id="wphal-piedisci"></div>';
378 $content .= '</div>';
379 $content .= '<button type="button" style="text-decoration: none;" id="wphal-disci" onclick="visibilitedisci(\'listdisci\',\'wphal-graph\',\'tridisciplines\'); return false;" >' . __('Graphique', 'wp-hal');
380 $content .= '</button>';
381 }
382 $content .= '</div>
383 <div class="display" id="wphal-keywords" style="display: none;">
384 <h3 class="wphal-titre">' . __('Mots-clefs', 'wp-hal') . '</h3>';
385 if (isset($json->facet_counts->facet_fields->keyword_s) && !is_null($json->facet_counts->facet_fields->keyword_s) && !empty($json->facet_counts->facet_fields->keyword_s)) {
386 $content .= '<div id="wphal-keys">';
387 $r = 0;
388 // CSS Nuage de mots
389 $maxsize = 25;
390 $minsize = 10;
391 $maxval = max(array_values($json->facet_counts->facet_fields->keyword_s[1]));
392 $minval = min(array_values($json->facet_counts->facet_fields->keyword_s[1]));
393 if(!is_numeric($minval)) {$minval = 0;}
394 if(!is_numeric($maxval)) {$maxval = 0;}
395 $spread = ($maxval - $minval);
396 $step = ($maxsize - $minsize) / $spread;
397 $tab = array();
398 foreach ($json->facet_counts->facet_fields->keyword_s as $res) {
399 $r = $r + 1;
400 if ($r > 20) {
401 break;
402 }
403 $tab[] = $res;
404 }
405 asort($tab); // Tri du tableau par ordre alphabétique
406 foreach ($tab as $res) {
407 $size = round($minsize + (($res[1] - $minval) * $step));
408 $content .= '<a style="display: inline-block; font-size:' . $size . 'px" href="' . esc_url(halv3 . '?q=keyword_s:' . urlencode('"' . $res[0] . '"') . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $res[0] . '</a>&nbsp;';
409 }
410 $content .= '</div>';
411 $content .= '<div id="keysuite" style="display:none;">';
412 $content .= '<span id="trikeywords">';
413 $content .= '<button type="button" class="trial" id="trikey" onclick="toggleSort(this, true, \'wphal-keyw\', \'wphal-keyword\', \'trikey\'); return false;" style="font-size:16px; text-decoration: none;" >Tri Alphabétique</button>';
414 $content .= '<button type="button" class="trioc" id="trinbkey" onclick="toggleSort(this, false, \'wphal-keyw\', \'wphal-keyword\', \'trinbkey\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
415 $content .= '</span>';
416 $content .= '<ul class="wphal-keyword">';
417 $content .= '<div id="wphal-keyw">';
418 foreach ($json->facet_counts->facet_fields->keyword_s as $res) {
419 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=keyword_s:' . urlencode('"' . $res[0] . '"') . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $res[0] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
420 }
421 $content .= '</div>';
422 $content .= '</ul>';
423 $content .= '</div>';
424 $content .= '<button type="button" style="text-decoration: none;" id="wphal-key" onclick="visibilitekey(\'wphal-keys\',\'keysuite\', \'trikeywords\'); return false;" >' . __('Liste complète', 'wp-hal');
425 $content .= '</button>';
426 }
427 $content .= '</div>
428 <div class="display" id="wphal-auteurs" style="display: none;">
429 <h3 class="wphal-titre">' . __('Auteurs', 'wp-hal') . '</h3>';
430 if (isset($json->facet_counts->facet_fields->authIdLastNameFirstName_fs) && !is_null($json->facet_counts->facet_fields->authIdLastNameFirstName_fs) && !empty($json->facet_counts->facet_fields->authIdLastNameFirstName_fs)) {
431 $content .= '<span id="triauteurs">';
432 $content .= '<button type="button" class="trial" id="triaut" onclick="toggleSort(this, true, \'wphal-aut\', \'auteursuite\', \'triaut\'); return false;" style="font-size:16px; text-decoration: none;" >Tri Alphabétique</button>';
433 $content .= '<button type="button" class="trioc" id="trinbaut" onclick="toggleSort(this, false, \'wphal-aut\', \'auteursuite\', \'trinbaut\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
434 $content .= '</span>';
435 $content .= '<ul class="wphal-auteurs" style="list-style-type: none;">';
436 $content .= '<div id="wphal-aut">';
437 $r = 0;
438 foreach ($json->facet_counts->facet_fields->authIdLastNameFirstName_fs as $res) {
439 $r = $r + 1;
440 if ($r > 10) {
441 break;
442 }
443 $name = explode(wphal_delimiter, $res[0]);
444 if($name[0] == 0){
445 $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[1]."\"");
446 }else{
447 $q = "authIdPerson_i:$name[0]";
448 }
449 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><img alt="user" src=" ' . esc_url(plugin_dir_url(__FILE__) . '/img/user.svg').'" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="' . esc_url(halv3 . '?q='. $q . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
450 }
451 $i = 1;
452 $content .= '<div id="auteursuite" style="display:none;">';
453 foreach ($json->facet_counts->facet_fields->authIdLastNameFirstName_fs as $res) {
454 if ($r < 10) {
455 break;
456 }
457 if ($i < $r) {
458 $i = $i + 1;
459 } else {
460 $name = explode(wphal_delimiter, $res[0]);
461 if($name[0] == 0){
462 $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[1]."\"");
463 }else{
464 $q = "authIdPerson_i:$name[0]";
465 }
466 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><img alt="user" src=" ' . esc_url(plugin_dir_url(__FILE__) . '/img/user.svg').'" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="' . esc_url(halv3 . '?q='. $q . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
467 }
468 }
469 $content .= '</div>';
470 $content .= '</div>';
471 $content .= '</ul>';
472 if ($r > 10) {
473 $content .= '<button type="button" style="text-decoration: none;" id="wphal-auteur" onclick="visibilite(\'auteursuite\'); return false;" >' . __('Liste complète', 'wp-hal');
474 $content .= '</button>';
475 }
476 }
477 $content .= '</div>
478 <div class="display" id="wphal-affiliated" style="display: none;">
479 <h3 class="wphal-titre">' . __('Auteurs de la structure', 'wp-hal') . '</h3>';
480 $parsed_facetfield = isset($json->facet_counts->facet_fields) ? wphal_parse_affiliation_facet($json->facet_counts->facet_fields, $structIDs) : [];
481 if (!empty($parsed_facetfield)) {
482 $content .= '<span id="triauteurs">';
483 $content .= '<button type="button" class="trial" id="triaff" onclick="toggleSort(this, true, \'wphal-aff\', \'affiliateduite\', \'triaff\'); return false;" style="font-size:16px; text-decoration: none;" >Tri Alphabétique</button>';
484 $content .= '<button type="button" class="trioc" id="trinbaff" onclick="toggleSort(this, false, \'wphal-aff\', \'affiliateduite\', \'trinbaff\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
485 $content .= '</span>';
486 $content .= '<ul class="wphal-auteurs" style="list-style-type: none;">';
487 $content .= '<div id="wphal-aff">';
488 $r = 0;
489 foreach ($parsed_facetfield as $author=>$count) {
490 $r = $r + 1;
491 if ($r > 10) {
492 break;
493 }
494 $name = explode(wphal_delimiter, $author);
495 if($name[1] == 0){
496 $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[2]."\"");
497 }else{
498 $q = "authIdPerson_i:$name[1]";
499 }
500 $content .= '<li class="metadata" data-percentage="' . $count . '"><img alt="user" src=" ' . esc_url(plugin_dir_url(__FILE__) . '/img/user.svg').'" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="' . esc_url(halv3 . '?q='. $q . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[2] . '</a><span class="wphal-nbmetadata">' . $count . '</span></li>';
501 }
502 $i = 1;
503 $content .= '<div id="affiliateduite" style="display:none;">';
504 foreach ($parsed_facetfield as $author=>$count) {
505 if ($r < 10) {
506 break;
507 }
508 if ($i < $r) {
509 $i = $i + 1;
510 } else {
511 $name = explode(wphal_delimiter, $author);
512 if($name[1] == 0){
513 $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[2]."\"");
514 }else{
515 $q = "authIdPerson_i:$name[1]";
516 }
517 $content .= '<li class="metadata" data-percentage="' . $count . '"><img alt="user" src=" ' . esc_url(plugin_dir_url(__FILE__) . '/img/user.svg').'" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="' . esc_url(halv3 . '?q='. $q . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[2] . '</a><span class="wphal-nbmetadata">' . $count . '</span></li>';
518 }
519 }
520 $content .= '</div>';
521 $content .= '</div>';
522 $content .= '</ul>';
523 if ($r > 10) {
524 $content .= '<button type="button" style="text-decoration: none;" id="wphal-auteur" onclick="visibilite(\'affiliateduite\'); return false;" >' . __('Liste complète', 'wp-hal');
525 $content .= '</button>';
526 }
527 }
528 $content .= '</div>
529 <div class="display" id="wphal-revues" style="display: none;">
530 <h3 class="wphal-titre">' . __('Revues', 'wp-hal') . '</h3>';
531 if (isset($json->facet_counts->facet_fields->journalIdTitle_fs) && !is_null($json->facet_counts->facet_fields->journalIdTitle_fs) && !empty($json->facet_counts->facet_fields->journalIdTitle_fs)) {
532 $content .= '<span id="trirevues">';
533 $content .= '<button type="button" class="trial" id="trirev" onclick="toggleSort(this, true, \'wphal-rev\', \'revuesuite\', \'trirev\'); return false;" style="font-size:16px; text-decoration: none;" >Tri Alphabétique</button>';
534 $content .= '<button type="button" class="trioc" id="trinbrev" onclick="toggleSort(this, false, \'wphal-rev\', \'revuesuite\', \'trinbrev\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
535 $content .= '</span>';
536 $content .= '<ul class="wphal-revues">';
537 $content .= '<div id="wphal-rev">';
538 $r = 0;
539 foreach ($json->facet_counts->facet_fields->journalIdTitle_fs as $res) {
540 $r = $r + 1;
541 if ($r > 10) {
542 break;
543 }
544 $name = explode(wphal_delimiter, $res[0]);
545 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=journalId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
546 }
547 $i = 1;
548 $content .= '<div id="revuesuite" style="display:none;">';
549 foreach ($json->facet_counts->facet_fields->journalIdTitle_fs as $res) {
550 if ($r < 10) {
551 break;
552 }
553 if ($i < $r) {
554 $i = $i + 1;
555 } else {
556 $name = explode(wphal_delimiter, $res[0]);
557 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=journalId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
558 }
559 }
560 $content .= '</div>';
561 $content .= '</div>';
562 $content .= '</ul>';
563 if ($r > 10) {
564 $content .= '<button type="button" style="text-decoration: none;" id="wphal-revue" onclick="visibiliterevues(\'revuesuite\'); return false;" >' . __('Liste complète', 'wp-hal');
565 $content .= '</button>';
566 }
567 }
568 $content .= '</div>
569 <div class="display" id="wphal-annees" style="display: none;">
570 <h3 class="wphal-titre">' . __('Année de production', 'wp-hal') . '</h3>';
571 if (isset($json->facet_counts->facet_fields->producedDateY_i) && !is_null($json->facet_counts->facet_fields->producedDateY_i) && !empty($json->facet_counts->facet_fields->producedDateY_i)) {
572 $content .= '<span id="triannees">';
573 $content .= '<button type="button" class="trial" id="trian" onclick="toggleSort(this, true, \'wphal-an\', \'anneesuite\', \'trian\'); return false;" style="font-size:16px; text-decoration: none;" >Tri Alphabétique</button>';
574 $content .= '<button type="button" class="trioc" id="trinban" onclick="toggleSort(this, false, \'wphal-an\', \'anneesuite\', \'trinban\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
575 $content .= '</span>';
576 $content .= '<ul class="wphal-annees">';
577 $content .= '<div id="wphal-an">';
578
579 rsort($json->facet_counts->facet_fields->producedDateY_i);
580 $r = 0;
581 foreach ($json->facet_counts->facet_fields->producedDateY_i as $res) {
582 $r = $r + 1;
583 if ($r > 10) {
584 break;
585 }
586 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=producedDateY_i:' . urlencode($res[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $res[0] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
587 }
588 $i = 1;
589 $content .= '<div id="anneesuite" style="display:none;">';
590 foreach ($json->facet_counts->facet_fields->producedDateY_i as $res) {
591 if ($r < 10) {
592 break;
593 }
594 if ($i < $r) {
595 $i = $i + 1;
596 } else {
597 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=producedDateY_i:' . urlencode($res[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $res[0] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
598 }
599 }
600 $content .= '</div>';
601 $content .= '</div>';
602 $content .= '</ul>';
603 if ($r > 10) {
604 $content .= '<button type="button" style="text-decoration: none;" id="wphal-annee" onclick="visibiliteannee(\'anneesuite\'); return false;" >' . __('Liste complète', 'wp-hal');
605 $content .= '</button>';
606 }
607 }
608 $content .= '</div>
609 <div class="display" id="wphal-insts" style="display: none;">
610 <h3 class="wphal-titre">' . __('Institutions', 'wp-hal') . '</h3>';
611 if (isset($json->facet_counts->facet_fields->instStructIdName_fs) && !is_null($json->facet_counts->facet_fields->instStructIdName_fs) && !empty($json->facet_counts->facet_fields->instStructIdName_fs)) {
612 $content .= '<span id="triinsts">';
613 $content .= '<button type="button" class="trial" id="triinst" onclick="toggleSort(this, true, \'wphal-institu\', \'instsuite\', \'triinst\'); return false;" style="font-size:16px; text-decoration: none;" >Tri Alphabétique</button>';
614 $content .= '<button type="button" class="trioc" id="trinbinst" onclick="toggleSort(this, false, \'wphal-institu\', \'instsuite\', \'trinbinst\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
615 $content .= '</span>';
616 $content .= '<ul class="wphal-insts">';
617 $content .= '<div id="wphal-institu">';
618 $r = 0;
619 foreach ($json->facet_counts->facet_fields->instStructIdName_fs as $res) {
620 $r = $r + 1;
621 if ($r > 10) {
622 break;
623 }
624 $name = explode(wphal_delimiter, $res[0]);
625 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=instStructId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
626 }
627 $i = 1;
628 $content .= '<div id="instsuite" style="display:none;">';
629 foreach ($json->facet_counts->facet_fields->instStructIdName_fs as $res) {
630 if ($r < 10) {
631 break;
632 }
633 if ($i < $r) {
634 $i = $i + 1;
635 } else {
636 $name = explode(wphal_delimiter, $res[0]);
637 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=instStructId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
638 }
639 }
640 $content .= '</div>';
641 $content .= '</div>';
642 $content .= '</ul>';
643 if ($r > 10) {
644 $content .= '<button type="button" style="text-decoration: none;" id="wphal-inst" onclick="visibiliteinst(\'instsuite\'); return false;" >' . __('Liste complète', 'wp-hal');
645 $content .= '</button>';
646 }
647 }
648 $content .= '</div>
649 <div class="display" id="wphal-labs" style="display: none;">
650 <h3 class="wphal-titre">' . __('Laboratoires', 'wp-hal') . '</h3>';
651 if (isset($json->facet_counts->facet_fields->labStructIdName_fs) && !is_null($json->facet_counts->facet_fields->labStructIdName_fs) && !empty($json->facet_counts->facet_fields->labStructIdName_fs)) {
652 $content .= '<span id="trilabs">';
653 $content .= '<button type="button" class="trial" id="trilab" onclick="toggleSort(this, true, \'wphal-labo\', \'labsuite\', \'trilab\'); return false;" style="font-size:16px; text-decoration: none;" >Tri Alphabétique</button>';
654 $content .= '<button type="button" class="trioc" id="trinblab" onclick="toggleSort(this, false, \'wphal-labo\', \'labsuite\', \'trinblab\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
655 $content .= '</span>';
656 $content .= '<ul class="wphal-labs">';
657 $content .= '<div id="wphal-labo">';
658
659 $r = 0;
660 foreach ($json->facet_counts->facet_fields->labStructIdName_fs as $res) {
661 $r = $r + 1;
662 if ($r > 10) {
663 break;
664 }
665 $name = explode(wphal_delimiter, $res[0]);
666 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=labStructId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
667 }
668 $i = 1;
669 $content .= '<div id="labsuite" style="display:none;">';
670 foreach ($json->facet_counts->facet_fields->labStructIdName_fs as $res) {
671 if ($r < 10) {
672 break;
673 }
674 if ($i < $r) {
675 $i = $i + 1;
676 } else {
677 $name = explode(wphal_delimiter, $res[0]);
678 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=labStructId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
679 }
680 }
681 $content .= '</div>';
682 $content .= '</div>';
683 $content .= '</ul>';
684 if ($r > 10) {
685 $content .= '<button type="button" style="text-decoration: none;" id="wphal-lab" onclick="visibilitelab(\'labsuite\'); return false;" >' . __('Liste complète', 'wp-hal');
686 $content .= '</button>';
687 }
688 }
689 $content .= '</div>
690 <div class="display" id="wphal-depts" style="display: none;">
691 <h3 class="wphal-titre">' . __('Départements', 'wp-hal') . '</h3>';
692 if (isset($json->facet_counts->facet_fields->deptStructIdName_fs) && !is_null($json->facet_counts->facet_fields->deptStructIdName_fs) && !empty($json->facet_counts->facet_fields->deptStructIdName_fs)) {
693 $content .= '<span id="tridept">';
694 $content .= '<button type="button" class="trial" id="tridept" onclick="toggleSort(this, true, \'wphal-dpt\', \'deptsuite\', \'tridept\'); return false;" style="font-size:16px; text-decoration: none;" >Tri Alphabétique</button>';
695 $content .= '<button type="button" class="trioc" id="trinbdept" onclick="toggleSort(this, false, \'wphal-dpt\', \'deptsuite\', \'trinbdept\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
696 $content .= '</span>';
697 $content .= '<ul class="wphal-depts">';
698 $content .= '<div id="wphal-dpt">';
699 $r = 0;
700 foreach ($json->facet_counts->facet_fields->deptStructIdName_fs as $res) {
701 $r = $r + 1;
702 if ($r > 10) {
703 break;
704 }
705 $name = explode(wphal_delimiter, $res[0]);
706 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=deptStructId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
707 }
708 $i = 1;
709 $content .= '<div id="deptsuite" style="display:none;">';
710 foreach ($json->facet_counts->facet_fields->deptStructIdName_fs as $res) {
711 if ($r < 10) {
712 break;
713 }
714 if ($i < $r) {
715 $i = $i + 1;
716 } else {
717 $name = explode(wphal_delimiter, $res[0]);
718 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=deptStructId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
719 }
720 }
721 $content .= '</div>';
722 $content .= '</div>';
723 $content .= '</ul>';
724 if ($r > 10) {
725 $content .= '<button type="button" style="text-decoration: none;" id="wphal-dept" onclick="visibilitedept(\'deptsuite\'); return false;" >' . __('Liste complète', 'wp-hal');
726 $content .= '</button>';
727 }
728 }
729 $content .= '</div>
730 <div class="display" id="wphal-equipes" style="display: none;">
731 <h3 class="wphal-titre">' . __('Équipes de recherche', 'wp-hal') . '</h3>';
732 if (isset($json->facet_counts->facet_fields->rteamStructIdName_fs) && !is_null($json->facet_counts->facet_fields->rteamStructIdName_fs) && !empty($json->facet_counts->facet_fields->rteamStructIdName_fs)) {
733 $content .= '<span id="triequipe">';
734 $content .= '<button type="button" class="trial" id="triequipe" onclick="toggleSort(this, true, \'wphal-rteam\', \'equipesuite\', \'triequipe\'); return false;" style="font-size:16px;text-decoration: none;" >Tri Alphabétique</button>';
735 $content .= '<button type="button" class="trioc" id="trinbequipe" onclick="toggleSort(this, false, \'wphal-rteam\', \'equipesuite\', \'trinbequipe\'); return false;" style="font-size:16px; text-decoration: none;">Tri Occurrence</button>';
736 $content .= '</span>';
737 $content .= '<ul class="wphal-equipes">';
738 $content .= '<div id="wphal-rteam">';
739
740 $r = 0;
741 $name=[];
742 foreach ($json->facet_counts->facet_fields->rteamStructIdName_fs as $res) {
743 $r = $r + 1;
744 if ($r > 10) {
745 break;
746 }
747 $name = explode(wphal_delimiter, $res[0]);
748 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=rteamStructId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
749 }
750 $i = 1;
751 $content .= '<div id="equipesuite" style="display:none;">';
752 foreach ($json->facet_counts->facet_fields->rteamStructIdName_fs as $res) {
753 if ($r < 10) {
754 break;
755 }
756 if ($i < $r) {
757 $i = $i + 1;
758 } else {
759 $name = explode(wphal_delimiter, $res[0]);
760 $content .= '<li class="metadata" data-percentage="' . $res[1] . '"><a href="' . esc_url(halv3 . '?q=rteamStructId_i:' . urlencode($name[0]) . "+AND+" . $type . ':(' . $id . ')').'" target="_blank">' . $name[1] . '</a><span class="wphal-nbmetadata">' . $res[1] . '</span></li>';
761 }
762 }
763 $content .= '</div>';
764 $content .= '</div>';
765 $content .= '</ul>';
766 if ($r > 10) {
767 $content .= '<button type="button" style="text-decoration: none;" id="wphal-equipe" onclick="visibiliteequipe(\'equipesuite\'); return false;" >' . __('Liste complète', 'wp-hal');
768 $content .= '</button>';
769 }
770 }
771 $content .= '</div>
772 <div class="display" id="publications">';
773 if(null === $json || !isset($jsontype->response)) {
774 if (get_option('option_groupe') == 'grouper') {
775 $doctype = file_get_contents(plugin_dir_path(__FILE__) . 'json' . DIRECTORY_SEPARATOR . 'doctype_fr.json');
776 $jsontype = json_decode($doctype);
777
778 //LISTE DES DOCUMENTS PAR GROUPE
779
780 $content .= '<div class="counter-doc"><span class="wphal-nbtot">' . $json->grouped->docType_s->matches . ' </span>';
781 $content .= __('documents', 'wp-hal') . '</div><br>';
782 for ($i = 0; !empty($jsontype->response->result->doc[$i]); $i++) {
783 for ($d = 0; !empty($json->grouped->docType_s->groups[$d]); $d++) {
784 if ($json->grouped->docType_s->groups[$d]->groupValue == $jsontype->response->result->doc[$i]->str[0]) {
785 $titre = $jsontype->response->result->doc[$i]->str[1];
786 $content .= '<div class="grp-div"><h3 class="wphal-titre-groupe">' . __($titre, 'wp-hal') . '<span class="wphal-nbmetadata" style="margin-left:10px;">' . $json->grouped->docType_s->groups[$d]->doclist->numFound . ' ' . _n('document', 'documents', $json->grouped->docType_s->groups[$d]->doclist->numFound, 'wp-hal') . '</span></h3>';
787 $content .= '<div class="grp-content">';
788 $content .= '<ul>';
789 foreach ($json->grouped->docType_s->groups[$d]->doclist->docs as $result) {
790 $content .= '<li>' . $result->citationFull_s . '</li>';
791 }
792 $content .= '</ul></div>';
793 $content .= '</div><br>';
794 break;
795 }
796 }
797 }
798 } elseif (get_option('option_groupe') == 'paginer') {
799
800 //LISTE DES DOCUMENTS AVEC PAGINATION
801 $content .= '<div class="counter-doc"><span class="wphal-nbtot">' . $json->response->numFound . ' </span>';
802 $content .= __('documents', 'wp-hal') . '</div><br>';
803
804 //--MODULE PAGINATION--//
805 $messagesParPage = 10;
806
807 $total = $json->response->numFound;
808
809 $nombreDePages = ceil($total / $messagesParPage);
810
811 if (isset($hal_page)) {
812 $pageActuelle = intval($hal_page);
813
814 if ($pageActuelle > $nombreDePages) {
815 $pageActuelle = $nombreDePages;
816 }
817 } else {
818 $pageActuelle = 1;
819 }
820 $premiereEntree = ($pageActuelle - 1) * $messagesParPage;
821
822 $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&fl=docid,citationFull_s,keyword_s,bookTitle_s,producedDate_s,authFullName_s&start=' . $premiereEntree . '&rows=' . $messagesParPage . '&sort=' . wphal_producedDateY . '&wt=json';
823 $json = wphal_do_get_data($url);
824
825 //--MODULE PAGINATION--//
826 $count_results = is_array($json->response->docs) ? count($json->response->docs) : 0;
827 if ($count_results > 0) {
828 $content .= '<ul>';
829 for ($i = 0; $i <= $count_results - 1; $i++) {
830 $content .= '<li>' . $json->response->docs[$i]->citationFull_s . '</li>';
831 }
832 $content .= '</ul>';
833 } else {
834 $content = '<div> no results !</div>';
835 }
836 if ($total > $messagesParPage) {
837 $base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'];
838 $url = $base_url . $_SERVER["REQUEST_URI"];
839 $explodedURL = explode('?', $url);
840 $queryString = isset($explodedURL[1]) ? $explodedURL[1] : "";
841 $pagedHref = $explodedURL[0];
842 if (!empty($queryString)) {
843 $parsedQueryString = [];
844 parse_str($queryString, $parsedQueryString);
845 if (isset($parsedQueryString["hal_page"])) {
846 unset($parsedQueryString["hal_page"]);
847 }
848 $pagedHref .= '?';
849 foreach ($parsedQueryString as $name => $value) {
850 $pagedHref .= $name . '=' . $value . '&';
851 }
852 // we add it back..
853 $pagedHref .= 'hal_page=';
854 } else {
855 $pagedHref .= '?hal_page=';
856 }
857
858 //--AFFICHAGE PAGINATION--//
859 $precedents = $pageActuelle - 2;
860 $suivants = $pageActuelle + 2;
861 $precedent = $pageActuelle - 1;
862 $suivant = $pageActuelle + 1;
863 $penultimate = $nombreDePages - 1;
864
865 $content .= '<ul class="wphal-pagination">';
866 //--BOUTON PRECEDENT--//
867 if ($pageActuelle != 1) {
868 $content .= '<li><a href="' . $pagedHref . $precedent . '">&laquo;</a></li>';
869 }
870 if ($nombreDePages <= 6) {// Cas 1 : 6 pages ou moins - Pas de troncature
871 for ($i = 1; $i <= $nombreDePages; $i++) {
872 if ($i == $pageActuelle) {
873 $content .= '<li class="active"><a href="#">' . $i . '</a></li>';
874 } else {
875 $content .= ' <li><a href="' . $pagedHref . $i . '">' . $i . '</a></li> ';
876 }
877 }
878 } elseif ($nombreDePages >= 7) {// Cas 2 : 7 pages ou plus - Troncature
879 if ($pageActuelle <= 3) {// Lorsque l'on est sur les trois premières pages
880 for ($i = 1; $i <= 4; $i++) {
881 if ($i == $pageActuelle) {
882 $content .= '<li class="active"><a href="#">' . $i . '</a></li>';
883 } else {
884 $content .= '<li><a href="' . $pagedHref . $i . '">' . $i . '</a></li>';
885 }
886 }
887 $content .= '<li class="disabled"><a href="#">&hellip;</a></li>';
888 $content .= '<li><a href="' . $pagedHref . $penultimate . '">' . $penultimate . '</a></li>';
889 $content .= '<li><a href="' . $pagedHref . $nombreDePages . '">' . $nombreDePages . '</a></li>';
890 }
891 if ($pageActuelle >= 4 && $pageActuelle <= $penultimate - 2) {//Lorsque l'on arrive sur la quatrième page
892 $content .= '<li><a href="' . $pagedHref . '1">1</a></li>';
893 $content .= '<li class="disabled"><a href="#">&hellip;</a></li>';
894 $content .= '<li><a href="' . $pagedHref . $precedents . '">' . $precedents . '</a></li>';
895 $content .= '<li><a href="' . $pagedHref . $precedent . '">' . $precedent . '</a></li>';
896 $content .= '<li class="active"><a href="#">' . $pageActuelle . '</a></li>';
897 $content .= '<li><a href="' . $pagedHref . $suivant . '">' . $suivant . '</a></li>';
898 $content .= '<li><a href="' . $pagedHref . $suivants . '">' . $suivants . '</a></li>';
899 $content .= '<li class="disabled"><a href="#">&hellip;</a></li>';
900 $content .= '<li><a href="' . $pagedHref . $nombreDePages . '">' . $nombreDePages . '</a></li>';
901 }
902 if ($pageActuelle >= $penultimate - 1) {
903 $content .= '<li><a href="' . $pagedHref . '1">1</a></li>';
904 $content .= '<li><a href="' . $pagedHref . '2">2</a></li>';
905 $content .= '<li class="disabled"><a href="#">&hellip;</a></li>';
906 for ($i = $penultimate - 2; $i <= $nombreDePages; $i++) {
907 if ($i == $pageActuelle) {
908 $content .= '<li class="active"><a href="#">' . $i . '</a></li>';
909 } else {
910 $content .= '<li><a href="' . $pagedHref . $i . '">' . $i . '</a></li>';
911 }
912 }
913 }
914 }
915 //--BOUTON SUIVANT--//
916 if ($pageActuelle < $nombreDePages) {
917 $content .= '<li><a href="' . $pagedHref . $suivant . '">&raquo;</a></li>';
918 }
919 $content .= '</ul>';
920 //--AFFICHAGE PAGINATION--//
921 }
922 }
923 } else {
924 $content .= '<div> empty response !</div>';
925 }
926 $content .= '</div>
927 </div>
928 </div>';
929 }}
930 $content .= '<div class="wphal-footer">';
931 $content .= '<p style="color:#B3B2B0">' . __("Documents récupérés de l'archive ouverte HAL", 'wp-hal') . '&nbsp;<a href="' . wphal_site . '" target="_blank"><img alt="logo" src=" ' . esc_url(plugin_dir_url(__FILE__) . 'img/logo-hal.png').'" style="width:90px;"></a></p>';
932 $content .= '</div>';
933
934 //--AFFICHAGE GRAPHIQUE DOMAINE--//
935 if (!is_null($facetdomain)) {
936 foreach ($facetdomain as $res) {
937 $name = explode(wphal_delimiter, $res[0])[1];
938 $value = $res[1];
939 $array[] = array($name, $value);
940 }
941 wp_localize_script('wp-hal-script4', 'WPWallSettings', $array);
942 }
943 $translation = array('liste' => __('Liste', 'wp-hal'), 'compl' => __('Liste complète', 'wp-hal'), 'princ' => __('Liste principale', 'wp-hal'), 'graph' => __('Graphique', 'wp-hal'), 'nuage' => __('Nuage de mots', 'wp-hal'));
944 wp_localize_script('wp-hal-script4', 'translate', $translation);
945 }
946 // tags other that those will be stripped
947 $allowed_html_tags = array(
948 'div' => array(
949 'class' => array(),
950 'id' => array(),
951 'style' => array(),
952 ),
953 "span"=> array(
954 'class' => array(),
955 'id' => array(),
956 'style' => array(),
957 ),
958 "img"=> array(
959 'alt' => array(),
960 'src' => array(),
961 'style' => array(),
962
963 ),
964 'p' => array(
965 'style' => array(),
966 'id' => array(),
967 ),
968 'h3' => array(
969 'id' => array(),
970 'class' => array(),
971 'style' => array()
972 ),
973 'a' => array(
974 'href' => array(),
975 'target' => array(),
976 'title' => array(),
977 'id' => array(),
978 'class' => array(),
979 'style' => array(),
980 'onclick' => array(),
981 ),
982 'ul' => array(
983 'class' => array(),
984 'id' => array(),
985 'style' => array(),
986 ),
987 'li' => array(
988 'class' => array(),
989 'id' => array(),
990 'data-percentage' => array()
991 ),
992 'button' => array(
993 'class' => array(),
994 'id' => array(),
995 'type' => array(),
996 'style' => array(),
997 'onclick' => array()
998 )
999 ,'br' => array()
1000 ,'hr' => array()
1001 ,'i' => array(),
1002 );
1003 add_filter( 'safe_style_css', function( $styles ) {
1004 $styles[] = 'display';
1005 return $styles;
1006 } );
1007 return wp_kses($content, $allowed_html_tags);
1008 }
1009
1010 /**
1011 * build facet query based on the option choice
1012 *
1013 * @param array $option_choix
1014 * @param array $structIDs to build prefixed facet
1015 * @return array
1016 */
1017 function wphal_buildfacet($option_choix, $structIDs)
1018 {
1019 $facetQuery = [];
1020 if (is_array($option_choix) && !empty($option_choix)) {
1021 foreach ($option_choix as $option) {
1022 if ($option == 'disciplines') {
1023 $facetQuery[] = wphal_lang . '_domainAllCodeLabel_fs';
1024 }
1025 if ($option == 'mots-clefs') {
1026 $facetQuery[] = 'keyword_s';
1027 }
1028 if ($option == 'auteurs') {
1029 $facetQuery[] = 'authIdLastNameFirstName_fs';
1030 }
1031 if ($option == 'revues') {
1032 $facetQuery[] = 'journalIdTitle_fs';
1033 }
1034 if ($option == 'annee') {
1035 $facetQuery[] = 'producedDateY_i';
1036 }
1037 if ($option == 'institution') {
1038 $facetQuery[] = 'instStructIdName_fs';
1039 }
1040 if ($option == 'laboratoire') {
1041 $facetQuery[] = 'labStructIdName_fs';
1042 }
1043 if ($option == 'departement') {
1044 $facetQuery[] = 'deptStructIdName_fs';
1045 }
1046 if ($option == 'equipe') {
1047 $facetQuery[] = 'rteamStructIdName_fs';
1048 }
1049 if ($option == 'affiliated') {
1050 $facetField = 'structHasAuthIdHalPersonid_s';
1051 foreach($structIDs as $k => $structID){
1052 $facetPrefix = $structID . wphal_delimiter;
1053 $facetQuery[] = '&facet.field={!key=affiliated_' . $k . '+facet.prefix=' . urlencode($facetPrefix) . '}' . urlencode($facetField);
1054 }
1055 }
1056 }
1057 }
1058 return $facetQuery;
1059 }
1060
1061 function wphal_verifSolr($values){
1062 $verifsolr = explode(',',$values);
1063 $numverif = count($verifsolr);
1064 $solrsql = '';
1065 if ($numverif<1024){
1066 $solrsql = str_replace(',',' OR ',$values);
1067 } else {
1068 $listsolrsql = explode(',',$values);
1069 for($i=0;$i<1024;$i++){
1070 if ($i == 0){
1071 $solrsql = $listsolrsql[$i];
1072 } else {
1073 $solrsql .= ' OR ';
1074 $solrsql .= $listsolrsql[$i];
1075 }
1076 }
1077 }
1078
1079 return $solrsql;
1080 }
1081
1082
1083 /**
1084 * parses the affiliation facet
1085 *
1086 * @return array
1087 */
1088 function wphal_parse_affiliation_facet($facet_fields, $structIDs)
1089 {
1090 $result=[];
1091 foreach($structIDs as $k => $structID){
1092 if(isset($facet_fields->{'affiliated_'.$k}) && !empty($facet_fields->{'affiliated_'.$k})){
1093 foreach($facet_fields->{'affiliated_'.$k} as $r){
1094 $t = explode(wphal_delimiter_join, $r[0]);
1095 if (!isset($result[$t[1]])){
1096 $result[$t[1]] = $r[1];
1097 }else {
1098 $result[$t[1]] += $r[1];
1099 }
1100 }
1101 }
1102 }
1103 return $result;
1104 }
1105
1106 function wphal_adding_style() {
1107 wp_register_style('wp-hal-style1', plugins_url('/css/style.css', __FILE__));
1108 wp_register_style('wp-hal-style2', plugins_url('/css/jquery.jqplot.css', __FILE__));
1109
1110 wp_enqueue_style('wp-hal-style1');
1111 }
1112
1113 function wphal_adding_script() {
1114 wp_register_script('wp-hal-script1',plugins_url('/js/jquery.jqplot.js', __FILE__));
1115 wp_register_script('wp-hal-script2',plugins_url('/js/jqplot.highlighter.js', __FILE__));
1116 wp_register_script('wp-hal-script3',plugins_url('/js/jqplot.pieRenderer.js', __FILE__));
1117 wp_register_script('wp-hal-script4',plugins_url('/js/cv-hal.js', __FILE__));
1118
1119
1120 wp_enqueue_script("jquery");
1121 wp_enqueue_script('wp-hal-script4', false, array(), false, true);
1122 }
1123
1124 /**
1125 * Récupère les fichiers css et js
1126 */
1127 if ( wphal_is_curl_installed() ) {
1128 add_action('wp_enqueue_scripts', 'wphal_adding_style');
1129 add_action('wp_enqueue_scripts', 'wphal_adding_script');
1130 }
1131
1132 /**
1133 * Charge lorsque le plugin est désactivé
1134 */
1135 register_deactivation_hook( __FILE__, 'wphal_reset_option' );
1136
1137 /**
1138 * Ajoute le widget wphal à l'initialisation des widgets
1139 */
1140 add_action('widgets_init','wphal_init');
1141
1142 /**
1143 * Ajoute le menu à l'initialisation du menu admin
1144 */
1145 add_action( 'admin_menu', 'wphal_menu' );
1146
1147 /**
1148 * Fonction de création du menu
1149 */
1150 function wphal_menu() {
1151 add_menu_page( 'Options', 'Hal', 'manage_options', 'wp-hal.php', 'wphal_option' , '', 21);
1152
1153 add_action( 'admin_init', 'wphal_register_settings' );
1154 }
1155
1156
1157 /**
1158 * Initialise le nouveau widget
1159 */
1160 function wphal_init(){
1161 register_widget("wphal_widget");
1162 }
1163
1164 /***********************************************************************************************************************
1165 * PLUGIN WIDGET
1166 **********************************************************************************************************************/
1167
1168 /**
1169 * Classe du widget wphal
1170 */
1171
1172 class wphal_widget extends WP_widget{
1173 /**
1174 * Défini les propriétés du widget
1175 */
1176 function __construct(){
1177 $options = array(
1178 "classname" => "wphal-publications",
1179 "description" => __("Afficher les dernières publications d'un auteur ou d'une structure.", 'wp-hal')
1180 );
1181
1182 parent::__construct(
1183 'hal-publications',
1184 __("Publications HAL", 'wp-hal'),
1185 $options
1186 );
1187 }
1188
1189 /**
1190 * Crée le widget
1191 * @param $args
1192 * @param $instance
1193 */
1194 function widget($args, $instance){
1195 if(isset($instance['idhal']) && !empty($instance['idhal'])) {
1196 $content = '';
1197 extract($args);
1198 /**
1199 * @var $before_widget : defined by extract
1200 * @var $before_title : defined by extract
1201 * @var $after_title : defined by extract
1202 * @var $after_widget : defined by extract
1203 */
1204 if (!wphal_is_curl_installed()) {
1205 $content = 'Please check the <a href="https://wordpress.org/plugins/hal/faq/" target="_blank" id="FAQ">FAQ</a> with the code : CURL';
1206
1207 } else {
1208 $instance['idhal'] = wphal_verifSolr($instance['idhal']);
1209 $fieldName = $instance['typetext'] == 'title_s' ? 'title_s':'citationFull_s';
1210
1211 $url = wphal_api . '?q=*:*&fq=' . $instance['select'] . ':' . urlencode($instance['idhal']) . '&fl=uri_s,' . $fieldName . '&sort=' . wphal_producedDateY . '&rows=' . $instance['nbdoc'] . '&wt=json';
1212 $json = wphal_do_get_data($url);
1213
1214 $count_results = is_array($json->response->docs) ? count($json->response->docs) : 0;
1215 if (isset($json->response->docs) && $count_results > 0) {
1216 $content = '<ul class="widhal-ul">';
1217 for ($i = 0; $i < $count_results - 1; $i++) {
1218 if ($fieldName == 'title_s') {
1219 $typetext = $json->response->docs[$i]->title_s[0];
1220 } else {
1221 $typetext = $json->response->docs[$i]->citationFull_s;
1222 }
1223 $content .= '<li class="widhal-li"><a href="' . esc_url($json->response->docs[$i]->uri_s) . '" target="_blank">' . $typetext . '</a></li>';
1224 }
1225 $content .= '</ul>';
1226 } else {
1227 $content = '<div> no results !</div>';
1228 }
1229 }
1230 // tags other that those will be stripped
1231 $allowed_html_tags = array(
1232 'div' => array(
1233 'class' => array(),
1234 'id' => array(),
1235 ),
1236 'h2' => array(),
1237 'section' => array(),
1238 'a' => array(
1239 'href' => array(),
1240 'target' => array(),
1241 'title' => array(),
1242 'id' => array(),
1243 'class' => array(),
1244 ),
1245 'ul' => array(
1246 'class' => array(),
1247 'id' => array(),
1248 ),
1249 'li' => array(
1250 'class' => array(),
1251 'id' => array(),
1252 )
1253 );
1254 $widget_block = $before_widget;
1255 $widget_block .= $before_title . $instance['titre'] . $after_title;
1256 $widget_block .= $content;
1257 $widget_block .= $after_widget;
1258 echo wp_kses($widget_block, $allowed_html_tags);
1259 }
1260 }
1261
1262 /**
1263 * Sauvegarde des données
1264 * @param $new
1265 * @param $old
1266 */
1267 function update($new, $old){
1268 //the id must be provided
1269 if(isset($new['idhal']) && !empty($new['idhal'])) {
1270 $new['idhal'] = wphal_sanitize_username($new['idhal']);
1271 $new['nbdoc'] = wphal_sanitize_id($new['nbdoc']);
1272 return $new;
1273 }else
1274 return false;
1275 }
1276
1277 /**
1278 * Formulaire du widget
1279 * @param $instance
1280 */
1281 function form($instance){
1282
1283 $defaut = array(
1284 'titre' => __("Publications Hal", 'wp-hal'),
1285 'select' => "authIdHal_s",
1286 'typetext' => "title_s",
1287 'idhal' => "",
1288 'nbdoc' => 5
1289 );
1290 $instance = wp_parse_args($instance,$defaut);
1291 ?>
1292 <p>
1293 <label for="<?php echo esc_attr($this->get_field_id("titre"));?>"><?php echo esc_html(__('Titre','wp-hal')) .' :'?></label>
1294 <input value="<?php echo esc_js($instance['titre']);?>" name="<?php echo esc_attr($this->get_field_name("titre"));?>" id="<?php echo esc_attr($this->get_field_id("titre"));?>" class="widefat" type="text"/>
1295 </p>
1296 <p>
1297 <label for="<?php echo esc_attr($this->get_field_id("nbdoc"));?>"><?php echo esc_html(__("Nombre de documents affichés",'wp-hal')) .' :'?></label>
1298 <input class="tiny-text" id="<?php echo esc_attr($this->get_field_id("nbdoc"));?>" name="<?php echo esc_attr($this->get_field_name("nbdoc"));?>" type="number" step="1" min="1" max="10" value="<?php echo esc_js($instance['nbdoc']);?>" size="3">
1299 </p>
1300 <p>
1301 <label for="<?php echo esc_attr($this->get_field_id("typetext"));?>"><?php echo esc_html(__("Type d'affichage",'wp-hal')) .' :'?></label>
1302 <select id="<?php echo esc_attr($this->get_field_id("typetext"));?>" name="<?php echo esc_attr($this->get_field_name("typetext"));?>">
1303 <option id="<?php echo esc_attr($this->get_field_id("Title"));?>" value="title_s" <?php echo esc_attr(($instance["typetext"] == "title_s")?'selected':''); ?>><label for="<?php echo wp_kses($this->get_field_id("Title"), []);?>"><?php echo esc_html(__("Titre", 'wp-hal'))?></label></option>
1304 <option id="<?php echo esc_attr($this->get_field_id("Citation"));?>" value="citationFull_s" <?php echo esc_attr(($instance["typetext"] == "citationFull_s")?'selected':''); ?>><label for="<?php echo esc_attr($this->get_field_id("Citation"));?>"><?php echo esc_html(__("Citation", 'wp-hal'), [])?></label></option>
1305 </select>
1306 </p>
1307 <p>
1308 <label for="<?php echo esc_attr($this->get_field_id("select"));?>"><?php echo esc_html(__("Type d'Id",'wp-hal') .' :')?></label>
1309 <select id="<?php echo esc_attr($this->get_field_id("select"));?>" name="<?php echo esc_attr($this->get_field_name("select"));?>">
1310 <option id="<?php echo esc_attr($this->get_field_id("Idhal"));?>" value="authIdHal_s" <?php echo esc_attr(($instance["select"] == "authIdHal_s")?'selected':''); ?>><label for="<?php echo esc_attr($this->get_field_id("Idhal"));?>">Id Hal</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : laurent-capelli)','wp-hal'));?></span></option>
1311 <option id="<?php echo esc_attr($this->get_field_id("StructId"));?>" value="structId_i" <?php echo esc_attr(($instance["select"] == "structId_i")?'selected':''); ?>><label for="<?php echo esc_attr($this->get_field_id("StructId"));?>">Struct Id</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : 413106)','wp-hal'));?></span></option>
1312 <option id="<?php echo esc_attr($this->get_field_id("Anrproject"));?>" value="anrProjectId_i" <?php echo esc_attr(($instance["select"] == "anrProjectId_i")?'selected':''); ?>><label for="<?php echo esc_attr($this->get_field_id("Anrproject"));?>">anrProject Id</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : 1646)','wp-hal'));?></span></option>
1313 <option id="<?php echo esc_attr($this->get_field_id("Europeanproject"));?>" value="europeanProjectId_i" <?php echo esc_attr(($instance["select"] == "europeanProjectId_i")?'selected':''); ?>><label for="<?php echo esc_attr($this->get_field_id("Europeanproject"));?>">europeanProject Id</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : 17877)','wp-hal'));?></span></option>
1314 <option id="<?php echo esc_attr($this->get_field_id("Collection"));?>" value="collCode_s" <?php echo esc_attr(($instance["select"] == "collCode_s")?'selected':''); ?>><label for="<?php echo esc_attr($this->get_field_id("Collection"));?>">Collection</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : TICE2014)','wp-hal'));?></span></option>
1315 </select>
1316 </p>
1317 <p>
1318 <label for="<?php echo esc_attr($this->get_field_id("idhal"));?>"><?php echo esc_html(__("Id",'wp-hal')) .' :'?></label>
1319 <input value="<?php echo esc_js($instance['idhal']);?>" name="<?php echo esc_attr($this->get_field_name("idhal"));?>" id="<?php echo esc_attr($this->get_field_id("idhal"));?>" type="text"/>
1320 </p>
1321 <?php
1322 }
1323 }
1324
1325
1326 function wphal_sanitize_id( $input ){
1327 if(is_numeric($input)){
1328 return $input;
1329 }
1330 }
1331
1332 function wphal_sanitize_username($input)
1333 {
1334 $allowed = array(".", "-", "_"); // you can add here more value, you want to allow.
1335 if(ctype_alnum(str_replace($allowed, '', $input ))) {
1336 return $input;
1337 }
1338 }
1339
1340 function wphal_sanitize_phone( $input ){
1341 $phone_num = $input;
1342 $phone_num = preg_replace('/[^0-9]/', '', $phone_num);
1343 if(strlen($phone_num) === 10) {
1344 //Phone is 10 characters in length
1345 return $input;
1346 }
1347 }
1348
1349
1350 function wphal_register_settings() {
1351 register_setting( 'wphal_option', 'option_choix' );
1352 register_setting( 'wphal_option', 'option_type' );
1353 register_setting( 'wphal_option', 'option_groupe' );
1354 register_setting( 'wphal_option', 'option_idhal' , array(
1355 'type' => 'string',
1356 'sanitize_callback' => 'wphal_sanitize_username',
1357 'default' => NULL,
1358 ));
1359 register_setting( 'wphal_option', 'option_lang' );
1360 register_setting( 'wphal_option', 'option_infocontact' );
1361 register_setting( 'wphal_option', 'option_email' , array(
1362 'type' => 'string',
1363 'sanitize_callback' => 'sanitize_email',
1364 'default' => NULL,
1365 ));
1366 register_setting( 'wphal_option', 'option_tel' , array(
1367 'type' => 'string',
1368 'sanitize_callback' => 'wphal_sanitize_phone',
1369 'default' => NULL,
1370 ));
1371 register_setting( 'wphal_option', 'option_social0' , array(
1372 'type' => 'string',
1373 'sanitize_callback' => 'wphal_sanitize_username',
1374 'default' => NULL,
1375 ));
1376 register_setting( 'wphal_option', 'option_social1' , array(
1377 'type' => 'string',
1378 'sanitize_callback' => 'wphal_sanitize_username',
1379 'default' => NULL,
1380 ));
1381 register_setting( 'wphal_option', 'option_social2' , array(
1382 'type' => 'string',
1383 'sanitize_callback' => 'wphal_sanitize_username',
1384 'default' => NULL,
1385 ));
1386 register_setting( 'wphal_option', 'option_social3' , array(
1387 'type' => 'string',
1388 'sanitize_callback' => 'wphal_sanitize_username',
1389 'default' => NULL,
1390 ));
1391 register_setting( 'wphal_option', 'option_cache_timeout' , array(
1392 'type' => 'string',
1393 'sanitize_callback' => 'wphal_sanitize_id',
1394 'default' => NULL,
1395 ));
1396 register_setting( 'wphal_option', 'option_erase_cache' );
1397 }
1398
1399 /**
1400 * Crée le menu d'option du plugin
1401 */
1402 function wphal_option() {
1403
1404 if (get_option('option_type')==''){
1405 update_option('option_type', 'authIdHal_s');
1406 }
1407 if (get_option('option_groupe')==''){
1408 update_option('option_groupe', 'paginer');
1409 }
1410 ?>
1411 <div class="wrap">
1412 <h2><?php echo esc_html(__('Plugin HAL','wp-hal'));?></h2>
1413 <form method="post" enctype="multipart/form-data" action="options.php">
1414 <div id="poststuff">
1415 <div id="post-body" class="metabox-holder columns-2">
1416 <div id="post-body-content">
1417 <?php settings_fields( 'wphal_option' ); ?>
1418 <?php do_settings_sections( 'wphal_option' ); ?>
1419 <table class="form-table">
1420 <tr style="vertical-align:top;">
1421 <th scope="row" style="font-size: 18px;"><?php echo esc_html(__('Paramètre de la page :','wp-hal'));?></th>
1422 </tr>
1423 <tr style="vertical-align:top;">
1424 <th scope="row"><label for="option_type"><?php echo esc_html(__('Type d\'Id','wp-hal'));?></label></th>
1425 <td><select name="option_type">
1426 <option id="Idhal" value="authIdHal_s" <?php echo esc_attr(((get_option('option_type') == "authIdHal_s")?'selected':'')); ?>><label for="Idhal">Id Hal</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : laurent-capelli)','wp-hal'));?></span></option>
1427 <option id="StructId" value="structId_i" <?php echo esc_attr(((get_option('option_type') == "structId_i")?'selected':'')); ?>><label for="StructId">Struct Id</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : 413106)','wp-hal'));?></span></option>
1428 <option id="Anrproject" value="anrProjectId_i" <?php echo esc_attr(((get_option('option_type') == "anrProjectId_i")?'selected':'')); ?>><label for="Anrproject">anrProject Id</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : 1646)','wp-hal'));?></span></option>
1429 <option id="Europeanproject" value="europeanProjectId_i" <?php echo esc_attr(((get_option('option_type') == "europeanProjectId_i")?'selected':'')); ?>><label for="Europeanproject">europeanProject Id</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : 17877)','wp-hal'));?></span></option>
1430 <option id="Collection" value="collCode_s" <?php echo esc_attr(((get_option('option_type') == "collCode_s")?'selected':'')); ?>><label for="Collection">Collection</label><span style="font-style: italic;"> <?php echo esc_html(__('(Exemple : TICE2014)','wp-hal'));?></span></option>
1431 </select>
1432 <input type="text" name="option_idhal" id="option_idhal" value="<?php echo esc_js(get_option('option_idhal')); ?>"/>
1433 </td>
1434 </tr>
1435 <tr style="vertical-align:top;">
1436 <th scope="row"><?php echo esc_html(__('Affichage des documents','wp-hal'));?></th>
1437 <td><input type="radio" name="option_groupe" id="paginer" value="paginer" <?php echo esc_attr((get_option('option_groupe') == "paginer")?'checked':''); ?>><label for="paginer"><?php echo esc_html(__('Documents avec pagination','wp-hal'));?></label><br>
1438 <input type="radio" name="option_groupe" id="grouper" value="grouper" <?php echo esc_js((get_option('option_groupe') == "grouper")?'checked':''); ?>><label for="grouper"><?php echo esc_html(__('Documents groupés par type','wp-hal'));?></label><br>
1439 </td>
1440 </tr>
1441 <tr style="vertical-align:top;">
1442 <th scope="row"><?php echo esc_html(__('Choix des éléments menu(facette)','wp-hal'));?></th>
1443 <?php $option_choix = get_option('option_choix'); ?>
1444 <td><input type="checkbox" name="option_choix[1]" id="Contact" value="contact" <?php echo esc_attr((isset($option_choix[1]) && $option_choix[1] == "contact")?'checked':''); ?>><label for="Contact"><?php echo esc_html(__('Contact','wp-hal'));?></label><br/>
1445 <input type="checkbox" name="option_choix[2]" id="Disciplines" value="disciplines" <?php echo esc_attr((isset($option_choix[2]) && $option_choix[2] == "disciplines")?'checked':''); ?>><label for="Disciplines"><?php echo esc_html(__('Disciplines','wp-hal'));?></label><br/>
1446 <input type="checkbox" name="option_choix[3]" id="Mots-clefs" value="mots-clefs" <?php echo esc_attr((isset($option_choix[3]) && $option_choix[3] == "mots-clefs")?'checked':''); ?>><label for="Mots-clefs"><?php echo esc_html(__('Mots-clefs','wp-hal'));?></label><br/>
1447 <input type="checkbox" name="option_choix[4]" id="Auteurs" value="auteurs" <?php echo esc_attr((isset($option_choix[4]) && $option_choix[4] == "auteurs")?'checked':''); ?>><label for="Auteurs"><?php echo esc_html(__('Auteurs','wp-hal'));?></label><br/>
1448 <input type="checkbox" name="option_choix[5]" id="Affiliated" value="affiliated" <?php echo esc_attr((isset($option_choix[5]) && $option_choix[5] == "affiliated")?'checked':''); ?>><label for="Affiliated"><?php echo esc_html(__('Auteurs de la structure','wp-hal'));?></label><br/>
1449 <input type="checkbox" name="option_choix[6]" id="Revues" value="revues" <?php echo esc_attr((isset($option_choix[6]) && $option_choix[6] == "revues")?'checked':''); ?>><label for="Revues"><?php echo esc_html(__('Revues','wp-hal'));?></label><br/>
1450 <input type="checkbox" name="option_choix[7]" id="Annee" value="annee" <?php echo esc_attr((isset($option_choix[7]) && $option_choix[7] == "annee")?'checked':''); ?>><label for="Annee"><?php echo esc_html(__('Année de production','wp-hal'));?></label><br/>
1451 <input type="checkbox" name="option_choix[8]" id="Institution" value="institution" <?php echo esc_attr((isset($option_choix[8]) && $option_choix[8] == "institution")?'checked':''); ?>><label for="Institution"><?php echo esc_html(__('Institutions','wp-hal'));?></label><br/>
1452 <input type="checkbox" name="option_choix[9]" id="Laboratoire" value="laboratoire" <?php echo esc_attr((isset($option_choix[9]) && $option_choix[9] == "laboratoire")?'checked':''); ?>><label for="Laboratoire"><?php echo esc_html(__('Laboratoires','wp-hal'));?></label><br/>
1453 <input type="checkbox" name="option_choix[10]" id="Departement" value="departement" <?php echo esc_attr((isset($option_choix[10]) && $option_choix[10] == "departement")?'checked':''); ?>><label for="Departement"><?php echo esc_html(__('Départements','wp-hal'));?></label><br/>
1454 <input type="checkbox" name="option_choix[11]" id="Equipe" value="equipe" <?php echo esc_attr((isset($option_choix[11]) && $option_choix[11] == "equipe")?'checked':''); ?>><label for="Equipe"><?php echo esc_html(__('Équipes de recherche','wp-hal'));?></label>
1455 </td>
1456 </tr>
1457 <tr style="vertical-align:top;">
1458 <th scope="row" style="font-size: 18px;"><?php echo esc_html(__('Contact :','wp-hal'));?></th>
1459 </tr>
1460 <tr>
1461 <th scope="row"><?php echo esc_html(__("Afficher les informations d'un chercheur ayant un IdHal ?",'wp-hal'));?></th>
1462 <td><input type="radio" name="option_infocontact" id="wphal-yes" value="yes" <?php echo esc_attr((get_option('option_infocontact') == "yes")?'checked':''); ?>><label for="wphal-yes"><?php echo esc_html(__("Oui",'wp-hal'))?></label><br>
1463 <input type="radio" name="option_infocontact" id="wphal-no" value="no" <?php echo esc_attr((get_option('option_infocontact') == "no")?'checked':''); ?>><label for="wphal-no"><?php echo esc_html(__("Non",'wp-hal'))?></label><br>
1464 </td>
1465 </tr>
1466 <tr>
1467 <th scope="row"><label for="option_cache_timeout"><?php echo esc_html(__('Expiration cache (minutes)','wp-hal'));?></label></th>
1468 <td><input type="number" min="1440" style="width:300px;" placeholder="Default(1 day) : 1440" name="option_cache_timeout" id="option_cache_timeout" value="<?php echo esc_js(get_option('option_cache_timeout')); ?>"/><img alt="cache" src="<?php echo esc_url(plugin_dir_url( __FILE__ ).'img/clock.svg'); ?>" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
1469 </tr>
1470 <tr>
1471 <th scope="row"><label for="option_erase_cache"><?php echo esc_html(__('Reinitialiser le cache','wp-hal'));?></label></th>
1472 <td><input type="checkbox" name="option_erase_cache" id="option_erase_cache" value="1"/><img alt="option_erase_cache" src="<?php echo esc_url(plugin_dir_url( __FILE__ )."img/groom.svg"); ?>" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
1473 </tr>
1474 <tr>
1475 <th scope="row"><label for="option_email"><?php echo esc_html(__('Email','wp-hal'));?></label></th>
1476 <td><input type="text" style="width:300px;" placeholder="Exemple : hi@mail.com" name="option_email" id="option_email" value="<?php echo esc_js(get_option('option_email')); ?>"/><img alt="email" src="<?php echo esc_url(plugin_dir_url( __FILE__ )."img/mail.svg"); ?>" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
1477 </tr>
1478 <tr>
1479 <th scope="row"><label for="option_tel"><?php echo esc_html(__('Téléphone','wp-hal'));?></label></th>
1480 <td><input type="text" style="width:300px;" placeholder="Exemple : 06-01-02-03-04" name="option_tel" id="option_tel" value="<?php echo esc_js(get_option('option_tel'));?>"/><img alt="phone" src="<?php echo esc_url(plugin_dir_url( __FILE__ )."img/phone.svg"); ?>" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
1481 </tr>
1482 <tr>
1483 <th><label for="option_social0">Facebook (http://www.facebook.com/)</label></th>
1484 <td><input type="text" style="width:300px;" placeholder="Exemple : fa.book" name="option_social0" id="option_social0" value="<?php echo esc_js(get_option('option_social0')); ?>"/><img alt="facebook" src="<?php echo esc_url(plugin_dir_url( __FILE__ )."img/facebook.svg"); ?>" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
1485 </tr>
1486 <tr>
1487 <th><label for="option_social1">Twitter (http://www.twitter.com/)</label></th>
1488 <td><input type="text" style="width:300px;" placeholder="Exemple : tweet_heure" name="option_social1" id="option_social1" value="<?php echo esc_js(get_option('option_social1')); ?>"/><img alt="twitter" src="<?php echo esc_url(plugin_dir_url( __FILE__ )."img/twitter.svg"); ?>" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
1489 </tr>
1490 <tr>
1491 <th><label for="option_social2">Google + (https://plus.google.com/u/0/+)</label></th>
1492 <td><input type="text" style="width:300px;" placeholder="Exemple : goo.plus" name="option_social2" id="option_social2" value="<?php echo esc_js(get_option('option_social2')); ?>"/><img alt="google" src="<?php echo esc_url(plugin_dir_url( __FILE__ )."img/google-plus.svg"); ?>" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
1493 </tr>
1494 <tr>
1495 <th><label for="option_social3">LinkedIn (https://www.linkedin.com/in/)</label></th>
1496 <td><input type="text" style="width:300px;" placeholder="Exemple : link.dine" name="option_social3" id="option_social3" value="<?php echo esc_js(get_option('option_social3')); ?>"/><img alt="linkedin" src="<?php echo esc_url(plugin_dir_url( __FILE__ )."img/linkedin.svg"); ?>" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
1497 </tr>
1498 </table>
1499 <?php
1500 submit_button(__('Enregistrer','wp-hal'), 'primary large', 'submit', true); ?>
1501 </div>
1502 <div id="postbox-container-1" class="postbox-container">
1503
1504 </div>
1505 </div>
1506 <br class="clear"><br/>
1507 </div>
1508 </form>
1509
1510 </div>
1511
1512 <?php
1513 }
1514
1515
1516 /**
1517 * Reset les données Hal
1518 */
1519 function wphal_reset_option() {
1520 delete_option('option_choix');
1521 delete_option('option_type');
1522 delete_option('option_groupe');
1523 delete_option('option_idhal');
1524 delete_option('option_lang');
1525 delete_option('option_infocontact');
1526 delete_option('option_email');
1527 delete_option('option_tel');
1528 delete_option('option_social0');
1529 delete_option('option_social1');
1530 delete_option('option_social2');
1531 delete_option('option_social3');
1532 delete_option('option_cache_timeout');
1533 delete_option('option_erase_cache');
1534 }
1535
1536 ?>
1537