PluginProbe
HAL / 2.4.2
HAL v2.4.2
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.4.2, at wp-hal.php

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