| @@ -2,39 +2,32 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: HAL |
| 4 | 4 | * Plugin URI: http://www.ccsd.cnrs.fr |
| 5 | 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 | |
| 6 | + * Version: 2.7.2 | |
| 7 | 7 | * Author: CCSD |
| 8 | 8 | * Author URI: http://www.ccsd.cnrs.fr |
| 9 | 9 | * Text Domain: wp-hal |
| 10 | 10 | * Domain Path: /lang/ |
| 11 | 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 | 12 | //Récupère les constantes |
| 18 | 13 | require_once("constantes.php"); |
| 19 | 14 | |
| 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 { | |
| 15 | +$generalLang = preg_replace('/_.*/', '', wphal_locale); | |
| 16 | +switch ($generalLang) { | |
| 17 | +case 'fr': | |
| 18 | +case 'es': | |
| 19 | +case 'en': | |
| 20 | + // Known languages... | |
| 21 | + define('wphal_lang', $generalLang); | |
| 22 | + break; | |
| 23 | +default: | |
| 26 | 24 | define('wphal_lang', 'en'); |
| 27 | 25 | } |
| 28 | 26 | |
| 29 | 27 | function wphal_is_curl_installed() { |
| 30 | 28 | $loaded_extentions = get_loaded_extensions(); |
| 31 | - if (in_array ('curl', $loaded_extentions)) { | |
| 32 | - return true; | |
| 33 | - } | |
| 34 | - else { | |
| 35 | - return false; | |
| 36 | - } | |
| 29 | + return (bool) (in_array('curl', $loaded_extentions)); | |
| 37 | 30 | } |
| 38 | 31 | |
| 39 | 32 | // Création du shortcode ('nom du shortcode', 'fonction appelée') |
| 40 | 33 | add_shortcode( 'cv-hal', 'wphal_cv_hal' ); |
| @@ -39,9 +32,8 @@ | ||
| 39 | 32 | // Création du shortcode ('nom du shortcode', 'fonction appelée') |
| 40 | 33 | add_shortcode( 'cv-hal', 'wphal_cv_hal' ); |
| 41 | 34 | add_shortcode( 'nb-doc', 'wphal_nb_doc' ); |
| 42 | 35 | |
| 43 | - | |
| 44 | 36 | function wphal_charger_languages() { |
| 45 | 37 | load_plugin_textdomain('wp-hal', false, dirname(plugin_basename(__FILE__)) . '/lang/'); |
| 46 | 38 | } |
| 47 | 39 | |
| @@ -51,14 +43,13 @@ | ||
| 51 | 43 | if ( $file != plugin_basename( __FILE__ )) |
| 52 | 44 | return $links; |
| 53 | 45 | |
| 54 | 46 | $settings_link = '<a href="admin.php?page=wp-hal.php">' . __( 'Paramètres', 'wp-hal' ) . '</a>'; |
| 55 | - | |
| 56 | 47 | array_unshift( $links, $settings_link ); |
| 57 | - | |
| 58 | 48 | return $links; |
| 59 | 49 | } |
| 60 | 50 | |
| 51 | + | |
| 61 | 52 | add_filter( 'query_vars', 'wphal_query_vars' ); |
| 62 | 53 | function wphal_query_vars( $query_vars ) { |
| 63 | 54 | $query_vars[] = 'hal_page'; |
| 64 | 55 | return $query_vars; |
| @@ -86,9 +77,9 @@ | ||
| 86 | 77 | { |
| 87 | 78 | global $wpdb; |
| 88 | 79 | // delete all "hal namespace" transients |
| 89 | 80 | $sql = " |
| 90 | - DELETE | |
| 81 | + DELETE | |
| 91 | 82 | FROM {$wpdb->options} |
| 92 | 83 | WHERE option_name like '\_transient\_hal\_%' |
| 93 | 84 | OR option_name like '\_transient\_timeout\_hal\_%' |
| 94 | 85 | "; |
| @@ -110,10 +101,11 @@ | ||
| 110 | 101 | } |
| 111 | 102 | $cache_expiration = empty(get_option('option_cache_timeout')) ? 1 * DAY_IN_SECONDS : intval(get_option('option_cache_timeout')) * MINUTE_IN_SECONDS; |
| 112 | 103 | if ( false === ( $value = get_transient( $transient_id ) ) ) { |
| 113 | 104 | $json = wphal_do_common_curl_call($url); |
| 114 | - if($json) | |
| 115 | - set_transient( $transient_id, $json, $cache_expiration); | |
| 105 | + if ($json) { | |
| 106 | + set_transient($transient_id, $json, $cache_expiration); | |
| 107 | + } | |
| 116 | 108 | return $json; |
| 117 | 109 | } else{ |
| 118 | 110 | return $value; |
| 119 | 111 | } |
| @@ -143,8 +135,9 @@ | ||
| 143 | 135 | |
| 144 | 136 | $json =wphal_do_get_data($url); |
| 145 | 137 | return $json->response->numFound; |
| 146 | 138 | } |
| 139 | + | |
| 147 | 140 | /** |
| 148 | 141 | * PLUGIN SHORTCODE CV-HAL |
| 149 | 142 | * @param $param |
| 150 | 143 | * @return string |
| @@ -172,12 +165,25 @@ | ||
| 172 | 165 | // here we merge with shortcode parameters |
| 173 | 166 | extract(shortcode_atts(array( |
| 174 | 167 | 'type' => $default_type, |
| 175 | 168 | 'id' => $default_id, |
| 176 | - 'contact' => $default_contact | |
| 169 | + 'contact' => $default_contact, | |
| 170 | + 'doctype_s' => null, | |
| 171 | + 'debug' => false, | |
| 172 | + 'option_groupe' => get_option('option_groupe') | |
| 177 | 173 | ), |
| 178 | 174 | $param |
| 179 | 175 | )); |
| 176 | + if ($doctype_s && !preg_match("/^[A-Z_ ]*$/", $doctype_s)) { | |
| 177 | + // Control of shortcode doctype_s which must be a valid doctype or a valid expression for doctype_s | |
| 178 | + // can accept: "ART OR REPORT AND NOT UNDEFINED" | |
| 179 | + $doctype_s = null; | |
| 180 | + } | |
| 181 | + if (! in_array($option_groupe, ['paginer', 'grouper'])) { | |
| 182 | + $option_groupe = 'paginer'; | |
| 183 | + } | |
| 184 | + | |
| 185 | + $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>'; | |
| 180 | 186 | |
| 181 | 187 | /** @var $id : defined by extract |
| 182 | 188 | * @var string $type : defined by extract |
| 183 | 189 | * @var string $contact : defined by extract |
| @@ -184,22 +190,44 @@ | ||
| 184 | 190 | */ |
| 185 | 191 | if (!empty($id) && in_array($type, $possible_ids)) { |
| 186 | 192 | $id = wphal_verifSolr($id); |
| 187 | 193 | |
| 188 | - $facets = wphal_buildfacet($option_choix); | |
| 189 | - $facetQuery = !empty($facets) ? 'facet.field='.implode("&facet.field=", $facets).'&facet.mincount=1&facet=true':''; | |
| 194 | + // in case the type is struct we need to split in order to build facet and display it back | |
| 195 | + $structIDs =[]; | |
| 196 | + if($type=="structId_i"){ | |
| 197 | + $structIDs = explode(' OR ', $id); | |
| 198 | + } | |
| 190 | 199 | |
| 191 | - if (get_option('option_groupe') == 'grouper') { | |
| 200 | + $facets = wphal_buildfacet($option_choix, $structIDs); | |
| 201 | + $facetQuery = !empty($facets) ? 'facet.field='.implode("&facet.field=", $facets).'&facet.limit=200&facet.mincount=1&facet=true':''; | |
| 202 | + | |
| 203 | + $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')'; | |
| 204 | + if (!empty($doctype_s) && $doctype_s != "") { | |
| 205 | + $url .= '&fq=docType_s:('.$doctype_s.')'; | |
| 206 | + } | |
| 207 | + switch ($option_groupe) { | |
| 208 | + case 'grouper': | |
| 192 | 209 | //cURL sur l'API pour récupérer les données |
| 193 | - $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'; | |
| 194 | - } elseif (get_option('option_groupe') == 'paginer') { | |
| 195 | - $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&fl=docid,citationFull_s&'.$facetQuery.'&sort=' . wphal_producedDateY . '&wt=json&json.nl=arrarr'; | |
| 210 | + $url .= '&group=true&group.field=docType_s&group.limit=1000'; | |
| 211 | + break; | |
| 212 | + case 'paginer': | |
| 213 | + break; | |
| 214 | + default: | |
| 215 | + // impossible 2 cases only | |
| 196 | 216 | } |
| 217 | + $url .= '&fl=docid,citationFull_s&'.$facetQuery.'&sort=' . wphal_producedDateY . '&wt=json&json.nl=arrarr'; | |
| 197 | 218 | |
| 198 | 219 | $json = wphal_do_get_data($url); |
| 199 | - $hal_page = (get_query_var('hal_page')) ? get_query_var('hal_page') : 1; | |
| 200 | - | |
| 201 | - $content = '<div id="wphal-content">'; | |
| 220 | + if(!isset($json->error)){ | |
| 221 | + $content = ""; | |
| 222 | + $hal_page = (get_query_var('hal_page')) ? get_query_var('hal_page') : 1; | |
| 223 | + if ($debug) { | |
| 224 | + $formattedJson = str_replace(["\n", ' '], ['<br />', ' '] , json_encode($json,JSON_PRETTY_PRINT)); | |
| 225 | + $content .= sprintf('<div class="debug"><ul><li>Option groupe: %s</li><li>url=%s</li><li>doctype_s: %s</li><li>json result: %s</li></ul></div>', | |
| 226 | + $option_groupe, $url, $doctype_s, $formattedJson ); | |
| 227 | + } | |
| 228 | + | |
| 229 | + $content .= '<div id="wphal-content">'; | |
| 202 | 230 | if (is_array($option_choix) && !empty($option_choix)){ |
| 203 | 231 | $content .= '<ul id="wphal-menu">'; |
| 204 | 232 | $content .= '<li><a href="#publications" onclick="displayElem(\'publications\'); return false;" style="font-size:18px; text-decoration: none;">' . __('Publications', 'wp-hal') . '</a></li>'; |
| 205 | 233 | |
| @@ -221,8 +249,12 @@ | ||
| 221 | 249 | if ($option == 'auteurs') { |
| 222 | 250 | $content .= '<li><a href="#auteurs" onclick="displayElem(\'wphal-auteurs\'); return false;" style="margin:1px; text-decoration: none;">' . __('Auteurs', 'wp-hal'); |
| 223 | 251 | $content .= '</a></li>'; |
| 224 | 252 | } |
| 253 | + if ($option == 'affiliated') { | |
| 254 | + $content .= '<li><a href="#affiliated" onclick="displayElem(\'wphal-affiliated\'); return false;" style="margin:1px; text-decoration: none;">' . __('Auteurs de la structure', 'wp-hal'); | |
| 255 | + $content .= '</a></li>'; | |
| 256 | + } | |
| 225 | 257 | if ($option == 'revues') { |
| 226 | 258 | $content .= '<li><a href="#revues" onclick="displayElem(\'wphal-revues\'); return false;" style="margin:1px; text-decoration: none;">' . __('Revues', 'wp-hal'); |
| 227 | 259 | $content .= '</a></li>'; |
| 228 | 260 | } |
| @@ -247,9 +279,8 @@ | ||
| 247 | 279 | $content .= '</a></li>'; |
| 248 | 280 | } |
| 249 | 281 | } |
| 250 | 282 | $content .= '</ul></li>'; |
| 251 | - | |
| 252 | 283 | $content .= '</ul><br/><hr>'; |
| 253 | 284 | } |
| 254 | 285 | |
| 255 | 286 | $content .= '<div id="meta"> |
| @@ -375,15 +406,15 @@ | ||
| 375 | 406 | $r = 0; |
| 376 | 407 | // CSS Nuage de mots |
| 377 | 408 | $maxsize = 25; |
| 378 | 409 | $minsize = 10; |
| 379 | - $maxval = max(array_values($json->facet_counts->facet_fields->keyword_s[1])); | |
| 380 | - $minval = min(array_values($json->facet_counts->facet_fields->keyword_s[1])); | |
| 381 | - if(!is_numeric($minval)) {$minval = 0;} | |
| 382 | - if(!is_numeric($maxval)) {$maxval = 0;} | |
| 383 | - $spread = ($maxval - $minval); | |
| 384 | - $step = ($maxsize - $minsize) / $spread; | |
| 385 | - $tab = array(); | |
| 410 | + /** @var int[] $keywordCounts */ | |
| 411 | + $keywordCounts = array_column($json->facet_counts->facet_fields->keyword_s, 1); | |
| 412 | + $maxval = max($keywordCounts); | |
| 413 | + $minval = min($keywordCounts); | |
| 414 | + $spread = ( $maxval - $minval ); | |
| 415 | + $step = ( $spread > 0 ) ? ($maxsize - $minsize) / $spread : 0; | |
| 416 | + $tab = []; | |
| 386 | 417 | foreach ($json->facet_counts->facet_fields->keyword_s as $res) { |
| 387 | 418 | $r = $r + 1; |
| 388 | 419 | if ($r > 20) { |
| 389 | 420 | break; |
| @@ -462,8 +493,59 @@ | ||
| 462 | 493 | $content .= '</button>'; |
| 463 | 494 | } |
| 464 | 495 | } |
| 465 | 496 | $content .= '</div> |
| 497 | + <div class="display" id="wphal-affiliated" style="display: none;"> | |
| 498 | + <h3 class="wphal-titre">' . __('Auteurs de la structure', 'wp-hal') . '</h3>'; | |
| 499 | + $parsed_facetfield = isset($json->facet_counts->facet_fields) ? wphal_parse_affiliation_facet($json->facet_counts->facet_fields, $structIDs) : []; | |
| 500 | + if (!empty($parsed_facetfield)) { | |
| 501 | + $content .= '<span id="triauteurs">'; | |
| 502 | + $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>'; | |
| 503 | + $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>'; | |
| 504 | + $content .= '</span>'; | |
| 505 | + $content .= '<ul class="wphal-auteurs" style="list-style-type: none;">'; | |
| 506 | + $content .= '<div id="wphal-aff">'; | |
| 507 | + $r = 0; | |
| 508 | + foreach ($parsed_facetfield as $author=>$count) { | |
| 509 | + $r = $r + 1; | |
| 510 | + if ($r > 10) { | |
| 511 | + break; | |
| 512 | + } | |
| 513 | + $name = explode(wphal_delimiter, $author); | |
| 514 | + if($name[1] == 0){ | |
| 515 | + $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[2]."\""); | |
| 516 | + }else{ | |
| 517 | + $q = "authIdPerson_i:$name[1]"; | |
| 518 | + } | |
| 519 | + $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>'; | |
| 520 | + } | |
| 521 | + $i = 1; | |
| 522 | + $content .= '<div id="affiliateduite" style="display:none;">'; | |
| 523 | + foreach ($parsed_facetfield as $author=>$count) { | |
| 524 | + if ($r < 10) { | |
| 525 | + break; | |
| 526 | + } | |
| 527 | + if ($i < $r) { | |
| 528 | + $i = $i + 1; | |
| 529 | + } else { | |
| 530 | + $name = explode(wphal_delimiter, $author); | |
| 531 | + if($name[1] == 0){ | |
| 532 | + $q = 'authLastNameFirstName_s:'.urlencode("\"".$name[2]."\""); | |
| 533 | + }else{ | |
| 534 | + $q = "authIdPerson_i:$name[1]"; | |
| 535 | + } | |
| 536 | + $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>'; | |
| 537 | + } | |
| 538 | + } | |
| 539 | + $content .= '</div>'; | |
| 540 | + $content .= '</div>'; | |
| 541 | + $content .= '</ul>'; | |
| 542 | + if ($r > 10) { | |
| 543 | + $content .= '<button type="button" style="text-decoration: none;" id="wphal-auteur" onclick="visibilite(\'affiliateduite\'); return false;" >' . __('Liste complète', 'wp-hal'); | |
| 544 | + $content .= '</button>'; | |
| 545 | + } | |
| 546 | + } | |
| 547 | + $content .= '</div> | |
| 466 | 548 | <div class="display" id="wphal-revues" style="display: none;"> |
| 467 | 549 | <h3 class="wphal-titre">' . __('Revues', 'wp-hal') . '</h3>'; |
| 468 | 550 | 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)) { |
| 469 | 551 | $content .= '<span id="trirevues">'; |
| @@ -706,19 +788,20 @@ | ||
| 706 | 788 | } |
| 707 | 789 | } |
| 708 | 790 | $content .= '</div> |
| 709 | 791 | <div class="display" id="publications">'; |
| 710 | - if (get_option('option_groupe') == 'grouper') { | |
| 711 | - $doctype = file_get_contents(plugin_dir_path( __FILE__ ).'json'. DIRECTORY_SEPARATOR .'doctype_fr.json'); | |
| 792 | + if(null === $json || !isset($jsontype->response)) { | |
| 793 | + if ($option_groupe == 'grouper') { | |
| 794 | + $doctype = file_get_contents(plugin_dir_path(__FILE__) . 'json' . DIRECTORY_SEPARATOR . 'doctype_fr.json'); | |
| 712 | 795 | $jsontype = json_decode($doctype); |
| 713 | 796 | |
| 714 | 797 | //LISTE DES DOCUMENTS PAR GROUPE |
| 715 | 798 | |
| 716 | 799 | $content .= '<div class="counter-doc"><span class="wphal-nbtot">' . $json->grouped->docType_s->matches . ' </span>'; |
| 717 | - $content .= __('documents', 'wp-hal'). '</div><br>'; | |
| 800 | + $content .= __('documents', 'wp-hal') . '</div><br>'; | |
| 718 | 801 | for ($i = 0; !empty($jsontype->response->result->doc[$i]); $i++) { |
| 719 | 802 | for ($d = 0; !empty($json->grouped->docType_s->groups[$d]); $d++) { |
| 720 | - if ($json->grouped->docType_s->groups[$d]->groupValue == $jsontype->response->result->doc[$i]->str[0]){ | |
| 803 | + if ($json->grouped->docType_s->groups[$d]->groupValue == $jsontype->response->result->doc[$i]->str[0]) { | |
| 721 | 804 | $titre = $jsontype->response->result->doc[$i]->str[1]; |
| 722 | 805 | $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>'; |
| 723 | 806 | $content .= '<div class="grp-content">'; |
| 724 | 807 | $content .= '<ul>'; |
| @@ -730,13 +813,13 @@ | ||
| 730 | 813 | break; |
| 731 | 814 | } |
| 732 | 815 | } |
| 733 | 816 | } |
| 734 | - } elseif (get_option('option_groupe') == 'paginer') { | |
| 817 | + } elseif ($option_groupe == 'paginer') { | |
| 735 | 818 | |
| 736 | 819 | //LISTE DES DOCUMENTS AVEC PAGINATION |
| 737 | 820 | $content .= '<div class="counter-doc"><span class="wphal-nbtot">' . $json->response->numFound . ' </span>'; |
| 738 | - $content .= __('documents', 'wp-hal'). '</div><br>'; | |
| 821 | + $content .= __('documents', 'wp-hal') . '</div><br>'; | |
| 739 | 822 | |
| 740 | 823 | //--MODULE PAGINATION--// |
| 741 | 824 | $messagesParPage = 10; |
| 742 | 825 | |
| @@ -755,114 +838,118 @@ | ||
| 755 | 838 | } |
| 756 | 839 | $premiereEntree = ($pageActuelle - 1) * $messagesParPage; |
| 757 | 840 | |
| 758 | 841 | $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'; |
| 842 | + if (!empty($doctype_s) && $doctype_s != "") { | |
| 843 | + $url .= '&fq=docType_s:('.$doctype_s.')'; | |
| 844 | + } | |
| 759 | 845 | $json = wphal_do_get_data($url); |
| 760 | 846 | |
| 761 | 847 | //--MODULE PAGINATION--// |
| 762 | - $count_results = count($json->response->docs); | |
| 763 | - if($count_results>0) { | |
| 764 | - $content .= '<ul>'; | |
| 765 | - for ( $i = 0; $i <= $count_results - 1; $i ++ ) { | |
| 766 | - $content .= '<li>' . $json->response->docs[ $i ]->citationFull_s . '</li>'; | |
| 767 | - } | |
| 768 | - $content .= '</ul>'; | |
| 848 | + $count_results = is_array($json->response->docs) ? count($json->response->docs) : 0; | |
| 849 | + if ($count_results > 0) { | |
| 850 | + $content .= '<ul>'; | |
| 851 | + for ($i = 0; $i <= $count_results - 1; $i++) { | |
| 852 | + $content .= '<li>' . $json->response->docs[$i]->citationFull_s . '</li>'; | |
| 853 | + } | |
| 854 | + $content .= '</ul>'; | |
| 769 | 855 | } else { |
| 770 | - $content = '<div> no results !</div>'; | |
| 856 | + $content = '<div> no results !</div>'; | |
| 771 | 857 | } |
| 772 | - if($total> $messagesParPage) { | |
| 773 | - $base_url = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST']; | |
| 858 | + if ($total > $messagesParPage) { | |
| 859 | + $base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; | |
| 774 | 860 | $url = $base_url . $_SERVER["REQUEST_URI"]; |
| 775 | - $explodedURL= explode('?', $url); | |
| 776 | - $queryString = isset($explodedURL[1])?$explodedURL[1]:""; | |
| 861 | + $explodedURL = explode('?', $url); | |
| 862 | + $queryString = isset($explodedURL[1]) ? $explodedURL[1] : ""; | |
| 777 | 863 | $pagedHref = $explodedURL[0]; |
| 778 | - if(!empty($queryString)){ | |
| 864 | + if (!empty($queryString)) { | |
| 779 | 865 | $parsedQueryString = []; |
| 780 | 866 | parse_str($queryString, $parsedQueryString); |
| 781 | - if(isset($parsedQueryString["hal_page"])){ | |
| 867 | + if (isset($parsedQueryString["hal_page"])) { | |
| 782 | 868 | unset($parsedQueryString["hal_page"]); |
| 783 | 869 | } |
| 784 | 870 | $pagedHref .= '?'; |
| 785 | - foreach($parsedQueryString as $name => $value){ | |
| 786 | - $pagedHref .= $name.'='.$value.'&'; | |
| 871 | + foreach ($parsedQueryString as $name => $value) { | |
| 872 | + $pagedHref .= $name . '=' . $value . '&'; | |
| 787 | 873 | } |
| 788 | 874 | // we add it back.. |
| 789 | 875 | $pagedHref .= 'hal_page='; |
| 790 | - }else { | |
| 876 | + } else { | |
| 791 | 877 | $pagedHref .= '?hal_page='; |
| 792 | 878 | } |
| 793 | 879 | |
| 794 | - //--AFFICHAGE PAGINATION--// | |
| 795 | - $precedents = $pageActuelle - 2; | |
| 796 | - $suivants = $pageActuelle + 2; | |
| 797 | - $precedent = $pageActuelle - 1; | |
| 798 | - $suivant = $pageActuelle + 1; | |
| 880 | + //--AFFICHAGE PAGINATION--// | |
| 881 | + $precedents = $pageActuelle - 2; | |
| 882 | + $suivants = $pageActuelle + 2; | |
| 883 | + $precedent = $pageActuelle - 1; | |
| 884 | + $suivant = $pageActuelle + 1; | |
| 799 | 885 | $penultimate = $nombreDePages - 1; |
| 800 | 886 | |
| 801 | 887 | $content .= '<ul class="wphal-pagination">'; |
| 802 | - //--BOUTON PRECEDENT--// | |
| 803 | - if ( $pageActuelle != 1 ) { | |
| 804 | - $content .= '<li><a href="'. $pagedHref . $precedent . '">«</a></li>'; | |
| 888 | + //--BOUTON PRECEDENT--// | |
| 889 | + if ($pageActuelle != 1) { | |
| 890 | + $content .= '<li><a href="' . $pagedHref . $precedent . '">«</a></li>'; | |
| 805 | 891 | } |
| 806 | - if ( $nombreDePages <= 6 ) {// Cas 1 : 6 pages ou moins - Pas de troncature | |
| 807 | - for ( $i = 1; $i <= $nombreDePages; $i ++ ) { | |
| 808 | - if ( $i == $pageActuelle ) { | |
| 892 | + if ($nombreDePages <= 6) {// Cas 1 : 6 pages ou moins - Pas de troncature | |
| 893 | + for ($i = 1; $i <= $nombreDePages; $i++) { | |
| 894 | + if ($i == $pageActuelle) { | |
| 809 | 895 | $content .= '<li class="active"><a href="#">' . $i . '</a></li>'; |
| 810 | 896 | } else { |
| 811 | - $content .= ' <li><a href="'. $pagedHref . $i . '">' . $i . '</a></li> '; | |
| 897 | + $content .= ' <li><a href="' . $pagedHref . $i . '">' . $i . '</a></li> '; | |
| 812 | 898 | } |
| 813 | 899 | } |
| 814 | - } elseif ( $nombreDePages >= 7 ) {// Cas 2 : 7 pages ou plus - Troncature | |
| 815 | - if ( $pageActuelle <= 3 ) {// Lorsque l'on est sur les trois premières pages | |
| 816 | - for ( $i = 1; $i <= 4; $i ++ ) { | |
| 817 | - if ( $i == $pageActuelle ) { | |
| 900 | + } elseif ($nombreDePages >= 7) {// Cas 2 : 7 pages ou plus - Troncature | |
| 901 | + if ($pageActuelle <= 3) {// Lorsque l'on est sur les trois premières pages | |
| 902 | + for ($i = 1; $i <= 4; $i++) { | |
| 903 | + if ($i == $pageActuelle) { | |
| 818 | 904 | $content .= '<li class="active"><a href="#">' . $i . '</a></li>'; |
| 819 | 905 | } else { |
| 820 | - $content .= '<li><a href="'. $pagedHref . $i . '">' . $i . '</a></li>'; | |
| 906 | + $content .= '<li><a href="' . $pagedHref . $i . '">' . $i . '</a></li>'; | |
| 821 | 907 | } |
| 822 | 908 | } |
| 823 | 909 | $content .= '<li class="disabled"><a href="#">…</a></li>'; |
| 824 | - $content .= '<li><a href="'. $pagedHref . $penultimate . '">' . $penultimate . '</a></li>'; | |
| 825 | - $content .= '<li><a href="'. $pagedHref . $nombreDePages . '">' . $nombreDePages . '</a></li>'; | |
| 910 | + $content .= '<li><a href="' . $pagedHref . $penultimate . '">' . $penultimate . '</a></li>'; | |
| 911 | + $content .= '<li><a href="' . $pagedHref . $nombreDePages . '">' . $nombreDePages . '</a></li>'; | |
| 826 | 912 | } |
| 827 | - if ( $pageActuelle >= 4 && $pageActuelle <= $penultimate - 2 ) {//Lorsque l'on arrive sur la quatrième page | |
| 828 | - $content .= '<li><a href="'.$pagedHref.'1">1</a></li>'; | |
| 913 | + if ($pageActuelle >= 4 && $pageActuelle <= $penultimate - 2) {//Lorsque l'on arrive sur la quatrième page | |
| 914 | + $content .= '<li><a href="' . $pagedHref . '1">1</a></li>'; | |
| 829 | 915 | $content .= '<li class="disabled"><a href="#">…</a></li>'; |
| 830 | - $content .= '<li><a href="'. $pagedHref . $precedents . '">' . $precedents . '</a></li>'; | |
| 831 | - $content .= '<li><a href="'. $pagedHref . $precedent . '">' . $precedent . '</a></li>'; | |
| 916 | + $content .= '<li><a href="' . $pagedHref . $precedents . '">' . $precedents . '</a></li>'; | |
| 917 | + $content .= '<li><a href="' . $pagedHref . $precedent . '">' . $precedent . '</a></li>'; | |
| 832 | 918 | $content .= '<li class="active"><a href="#">' . $pageActuelle . '</a></li>'; |
| 833 | - $content .= '<li><a href="'. $pagedHref . $suivant . '">' . $suivant . '</a></li>'; | |
| 834 | - $content .= '<li><a href="'. $pagedHref . $suivants . '">' . $suivants . '</a></li>'; | |
| 919 | + $content .= '<li><a href="' . $pagedHref . $suivant . '">' . $suivant . '</a></li>'; | |
| 920 | + $content .= '<li><a href="' . $pagedHref . $suivants . '">' . $suivants . '</a></li>'; | |
| 835 | 921 | $content .= '<li class="disabled"><a href="#">…</a></li>'; |
| 836 | - $content .= '<li><a href="'. $pagedHref . $nombreDePages . '">' . $nombreDePages . '</a></li>'; | |
| 922 | + $content .= '<li><a href="' . $pagedHref . $nombreDePages . '">' . $nombreDePages . '</a></li>'; | |
| 837 | 923 | } |
| 838 | - if ( $pageActuelle >= $penultimate - 1 ) { | |
| 839 | - $content .= '<li><a href="'.$pagedHref.'1">1</a></li>'; | |
| 840 | - $content .= '<li><a href="'.$pagedHref.'2">2</a></li>'; | |
| 924 | + if ($pageActuelle >= $penultimate - 1) { | |
| 925 | + $content .= '<li><a href="' . $pagedHref . '1">1</a></li>'; | |
| 926 | + $content .= '<li><a href="' . $pagedHref . '2">2</a></li>'; | |
| 841 | 927 | $content .= '<li class="disabled"><a href="#">…</a></li>'; |
| 842 | - for ( $i = $penultimate - 2; $i <= $nombreDePages; $i ++ ) { | |
| 843 | - if ( $i == $pageActuelle ) { | |
| 928 | + for ($i = $penultimate - 2; $i <= $nombreDePages; $i++) { | |
| 929 | + if ($i == $pageActuelle) { | |
| 844 | 930 | $content .= '<li class="active"><a href="#">' . $i . '</a></li>'; |
| 845 | 931 | } else { |
| 846 | - $content .= '<li><a href="'. $pagedHref . $i . '">' . $i . '</a></li>'; | |
| 932 | + $content .= '<li><a href="' . $pagedHref . $i . '">' . $i . '</a></li>'; | |
| 847 | 933 | } |
| 848 | 934 | } |
| 849 | 935 | } |
| 850 | 936 | } |
| 851 | - //--BOUTON SUIVANT--// | |
| 852 | - if ( $pageActuelle < $nombreDePages ) { | |
| 853 | - $content .= '<li><a href="'. $pagedHref . $suivant . '">»</a></li>'; | |
| 937 | + //--BOUTON SUIVANT--// | |
| 938 | + if ($pageActuelle < $nombreDePages) { | |
| 939 | + $content .= '<li><a href="' . $pagedHref . $suivant . '">»</a></li>'; | |
| 854 | 940 | } |
| 855 | 941 | $content .= '</ul>'; |
| 856 | - //--AFFICHAGE PAGINATION--// | |
| 942 | + //--AFFICHAGE PAGINATION--// | |
| 857 | 943 | } |
| 858 | 944 | } |
| 859 | - $content .= '</div> | |
| 945 | + } else { | |
| 946 | + $content .= '<div> empty response !</div>'; | |
| 947 | + } | |
| 948 | + $content .= '</div> | |
| 860 | 949 | </div> |
| 861 | 950 | </div>'; |
| 862 | - }else{ | |
| 863 | - $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>'; | |
| 864 | - } | |
| 951 | + }} | |
| 865 | 952 | $content .= '<div class="wphal-footer">'; |
| 866 | 953 | $content .= '<p style="color:#B3B2B0">' . __("Documents récupérés de l'archive ouverte HAL", 'wp-hal') . ' <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>'; |
| 867 | 954 | $content .= '</div>'; |
| 868 | 955 | |
| @@ -945,11 +1032,12 @@ | ||
| 945 | 1032 | /** |
| 946 | 1033 | * build facet query based on the option choice |
| 947 | 1034 | * |
| 948 | 1035 | * @param array $option_choix |
| 1036 | + * @param array $structIDs to build prefixed facet | |
| 949 | 1037 | * @return array |
| 950 | 1038 | */ |
| 951 | -function wphal_buildfacet($option_choix) | |
| 1039 | +function wphal_buildfacet($option_choix, $structIDs) | |
| 952 | 1040 | { |
| 953 | 1041 | $facetQuery = []; |
| 954 | 1042 | if (is_array($option_choix) && !empty($option_choix)) { |
| 955 | 1043 | foreach ($option_choix as $option) { |
| @@ -979,12 +1067,20 @@ | ||
| 979 | 1067 | } |
| 980 | 1068 | if ($option == 'equipe') { |
| 981 | 1069 | $facetQuery[] = 'rteamStructIdName_fs'; |
| 982 | 1070 | } |
| 1071 | + if ($option == 'affiliated') { | |
| 1072 | + $facetField = 'structHasAuthIdHalPersonid_s'; | |
| 1073 | + foreach($structIDs as $k => $structID){ | |
| 1074 | + $facetPrefix = $structID . wphal_delimiter; | |
| 1075 | + $facetQuery[] = '&facet.field={!key=affiliated_' . $k . '+facet.prefix=' . urlencode($facetPrefix) . '}' . urlencode($facetField); | |
| 1076 | + } | |
| 1077 | + } | |
| 983 | 1078 | } |
| 984 | 1079 | } |
| 985 | 1080 | return $facetQuery; |
| 986 | 1081 | } |
| 1082 | + | |
| 987 | 1083 | function wphal_verifSolr($values){ |
| 988 | 1084 | $verifsolr = explode(',',$values); |
| 989 | 1085 | $numverif = count($verifsolr); |
| 990 | 1086 | $solrsql = ''; |
| @@ -1004,8 +1100,32 @@ | ||
| 1004 | 1100 | |
| 1005 | 1101 | return $solrsql; |
| 1006 | 1102 | } |
| 1007 | 1103 | |
| 1104 | + | |
| 1105 | +/** | |
| 1106 | + * parses the affiliation facet | |
| 1107 | + * | |
| 1108 | + * @return array | |
| 1109 | + */ | |
| 1110 | +function wphal_parse_affiliation_facet($facet_fields, $structIDs) | |
| 1111 | +{ | |
| 1112 | + $result=[]; | |
| 1113 | + foreach($structIDs as $k => $structID){ | |
| 1114 | + if(isset($facet_fields->{'affiliated_'.$k}) && !empty($facet_fields->{'affiliated_'.$k})){ | |
| 1115 | + foreach($facet_fields->{'affiliated_'.$k} as $r){ | |
| 1116 | + $t = explode(wphal_delimiter_join, $r[0]); | |
| 1117 | + if (!isset($result[$t[1]])){ | |
| 1118 | + $result[$t[1]] = $r[1]; | |
| 1119 | + }else { | |
| 1120 | + $result[$t[1]] += $r[1]; | |
| 1121 | + } | |
| 1122 | + } | |
| 1123 | + } | |
| 1124 | + } | |
| 1125 | + return $result; | |
| 1126 | +} | |
| 1127 | + | |
| 1008 | 1128 | function wphal_adding_style() { |
| 1009 | 1129 | wp_register_style('wp-hal-style1', plugins_url('/css/style.css', __FILE__)); |
| 1010 | 1130 | wp_register_style('wp-hal-style2', plugins_url('/css/jquery.jqplot.css', __FILE__)); |
| 1011 | 1131 | |
| @@ -1112,10 +1232,10 @@ | ||
| 1112 | 1232 | |
| 1113 | 1233 | $url = wphal_api . '?q=*:*&fq=' . $instance['select'] . ':' . urlencode($instance['idhal']) . '&fl=uri_s,' . $fieldName . '&sort=' . wphal_producedDateY . '&rows=' . $instance['nbdoc'] . '&wt=json'; |
| 1114 | 1234 | $json = wphal_do_get_data($url); |
| 1115 | 1235 | |
| 1116 | - $count_results = count($json->response->docs); | |
| 1117 | - if ($count_results > 0) { | |
| 1236 | + $count_results = is_array($json->response->docs) ? count($json->response->docs) : 0; | |
| 1237 | + if (isset($json->response->docs) && $count_results > 0) { | |
| 1118 | 1238 | $content = '<ul class="widhal-ul">'; |
| 1119 | 1239 | for ($i = 0; $i < $count_results - 1; $i++) { |
| 1120 | 1240 | if ($fieldName == 'title_s') { |
| 1121 | 1241 | $typetext = $json->response->docs[$i]->title_s[0]; |
| @@ -1340,20 +1460,21 @@ | ||
| 1340 | 1460 | <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> |
| 1341 | 1461 | </td> |
| 1342 | 1462 | </tr> |
| 1343 | 1463 | <tr style="vertical-align:top;"> |
| 1344 | - <th scope="row"><?php echo esc_html(__('Choix des éléments menu','wp-hal'));?></th> | |
| 1464 | + <th scope="row"><?php echo esc_html(__('Choix des éléments menu(facette)','wp-hal'));?></th> | |
| 1345 | 1465 | <?php $option_choix = get_option('option_choix'); ?> |
| 1346 | 1466 | <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/> |
| 1347 | 1467 | <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/> |
| 1348 | 1468 | <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/> |
| 1349 | 1469 | <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/> |
| 1350 | - <input type="checkbox" name="option_choix[5]" id="Revues" value="revues" <?php echo esc_attr((isset($option_choix[5]) && $option_choix[5] == "revues")?'checked':''); ?>><label for="Revues"><?php echo esc_html(__('Revues','wp-hal'));?></label><br/> | |
| 1351 | - <input type="checkbox" name="option_choix[6]" id="Annee" value="annee" <?php echo esc_attr((isset($option_choix[6]) && $option_choix[6] == "annee")?'checked':''); ?>><label for="Annee"><?php echo esc_html(__('Année de production','wp-hal'));?></label><br/> | |
| 1352 | - <input type="checkbox" name="option_choix[7]" id="Institution" value="institution" <?php echo esc_attr((isset($option_choix[7]) && $option_choix[7] == "institution")?'checked':''); ?>><label for="Institution"><?php echo esc_html(__('Institutions','wp-hal'));?></label><br/> | |
| 1353 | - <input type="checkbox" name="option_choix[8]" id="Laboratoire" value="laboratoire" <?php echo esc_attr((isset($option_choix[8]) && $option_choix[8] == "laboratoire")?'checked':''); ?>><label for="Laboratoire"><?php echo esc_html(__('Laboratoires','wp-hal'));?></label><br/> | |
| 1354 | - <input type="checkbox" name="option_choix[9]" id="Departement" value="departement" <?php echo esc_attr((isset($option_choix[9]) && $option_choix[9] == "departement")?'checked':''); ?>><label for="Departement"><?php echo esc_html(__('Départements','wp-hal'));?></label><br/> | |
| 1355 | - <input type="checkbox" name="option_choix[10]" id="Equipe" value="equipe" <?php echo esc_attr((isset($option_choix[10]) && $option_choix[10] == "equipe")?'checked':''); ?>><label for="Equipe"><?php echo esc_html(__('Équipes de recherche','wp-hal'));?></label> | |
| 1470 | + <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/> | |
| 1471 | + <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/> | |
| 1472 | + <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/> | |
| 1473 | + <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/> | |
| 1474 | + <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/> | |
| 1475 | + <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/> | |
| 1476 | + <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> | |
| 1356 | 1477 | </td> |
| 1357 | 1478 | </tr> |
| 1358 | 1479 | <tr style="vertical-align:top;"> |
| 1359 | 1480 | <th scope="row" style="font-size: 18px;"><?php echo esc_html(__('Contact :','wp-hal'));?></th> |