Plugin Directory

Changeset 3458796


Ignore:
Timestamp:
02/11/2026 09:04:22 AM (11 days ago)
Author:
ccsd
Message:

Add possibility to limit display a certains document types

Location:
hal/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • hal/trunk/constantes.php

    r3412060 r3458796  
    11<?php
    22/**
    3  * Created on: 26/05/14
    4  * Updated on: 15/11/22
     3 * Created on: 2024-05-26
     4 * Updated on: 2022-02-10
    55 */
    66
     
    3131
    3232// Constante de version du plugin
    33 define('wphal_version', '2.6.1');
     33define('wphal_version', '2.7,1');
  • hal/trunk/readme.txt

    r3412068 r3458796  
    55Tested up to: 6.9
    66PHP Version: 7.0 or higher
    7 Stable tag: 2.6
     7Stable tag: 2.7.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8181
    8282== Changelog ==
     83
     842.7.1
     85*Release Date - Feb 2026
     86
     87* add possibility to display only one docment type. (thx to R.Trouville)
    8388
    8489= 2.7 =
  • hal/trunk/wp-hal.php

    r3412068 r3458796  
    44 * Plugin URI: http://www.ccsd.cnrs.fr
    55 * Description: Crée une page qui remonte les publications d'un auteur ou d'une structure en relation avec HAL et un widget des dernières publications d'un auteur ou d'une structure.
    6  * Version: 2.6.1
     6 * Version: 2.7.1
    77 * Author: CCSD
    88 * Author URI: http://www.ccsd.cnrs.fr
     
    1818require_once("constantes.php");
    1919
    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 {
     20$generalLang = preg_replace('/_.*/', '', wphal_locale);
     21switch ($generalLang) {
     22case 'fr':
     23case 'es':
     24case 'en':
     25    // Known languages...
     26    define('wphal_lang', $generalLang);
     27    break;
     28default:
    2629    define('wphal_lang', 'en');
    2730}
     
    2932function wphal_is_curl_installed() {
    3033    $loaded_extentions = get_loaded_extensions();
    31     if  (in_array  ('curl', $loaded_extentions)) {
    32         return true;
    33     }
    34     else {
    35         return false;
    36     }
     34    return (bool) (in_array('curl', $loaded_extentions));
    3735}
    3836
     
    4139add_shortcode( 'nb-doc', 'wphal_nb_doc' );
    4240
    43 
    4441function wphal_charger_languages() {
    4542    load_plugin_textdomain('wp-hal', false, dirname(plugin_basename(__FILE__)) . '/lang/');
     
    5350
    5451    $settings_link = '<a href="admin.php?page=wp-hal.php">' . __( 'Paramètres', 'wp-hal' ) . '</a>';
    55 
    5652    array_unshift( $links, $settings_link );
    57 
    5853    return $links;
    5954}
     55
    6056
    6157add_filter( 'query_vars', 'wphal_query_vars' );
     
    8884    // delete all "hal namespace" transients
    8985    $sql = "
    90             DELETE 
     86            DELETE
    9187            FROM {$wpdb->options}
    9288            WHERE option_name like '\_transient\_hal\_%'
     
    112108    if ( false === ( $value = get_transient( $transient_id ) ) ) {
    113109        $json = wphal_do_common_curl_call($url);
    114         if($json)
    115             set_transient( $transient_id, $json, $cache_expiration);
     110        if ($json) {
     111            set_transient($transient_id, $json, $cache_expiration);
     112        }
    116113        return $json;
    117114    } else{
     
    145142    return $json->response->numFound;
    146143}
     144
    147145/**
    148146 * PLUGIN SHORTCODE CV-HAL
     
    174172            'type' => $default_type,
    175173            'id' => $default_id,
    176             'contact' => $default_contact
     174            'contact' => $default_contact,
     175            'doctype_s' => null,
     176            'debug' => false,
     177            'option_groupe' => get_option('option_groupe')
    177178        ),
    178179            $param
    179180        ));
     181        if ($doctype_s && !preg_match("/^[A-Z_ ]*$/", $doctype_s)) {
     182            // Control of shortcode doctype_s which must be a valid doctype or a valid expression for doctype_s
     183            // can accept: "ART OR REPORT AND NOT UNDEFINED"
     184            $doctype_s = null;
     185        }
     186        if (! in_array($option_groupe, ['paginer', 'grouper'])) {
     187            $option_groupe = 'paginer';
     188        }
     189           
    180190        $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>';
    181191
     
    196206            $facetQuery = !empty($facets) ? 'facet.field='.implode("&facet.field=", $facets).'&facet.limit=200&facet.mincount=1&facet=true':'';
    197207
    198             if (get_option('option_groupe') == 'grouper') {
     208            $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')';
     209            if (!empty($doctype_s) && $doctype_s != "") {
     210                    $url .= '&fq=docType_s:('.$doctype_s.')';
     211            }
     212            switch ($option_groupe) {
     213            case 'grouper':
    199214                //cURL sur l'API pour récupérer les données
    200                 $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&group=true&group.field=docType_s&group.limit=1000&fl=docid,citationFull_s&'.$facetQuery.'&sort=' . wphal_producedDateY . '&wt=json&json.nl=arrarr';
    201             } elseif (get_option('option_groupe') == 'paginer') {
    202                 $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&fl=docid,citationFull_s&'.$facetQuery.'&sort=' . wphal_producedDateY . '&wt=json&json.nl=arrarr';
    203             }
     215                $url .= '&group=true&group.field=docType_s&group.limit=1000';
     216                break;
     217            case 'paginer':
     218                break;
     219            default:
     220                // impossible 2 cases only
     221            }
     222            $url .= '&fl=docid,citationFull_s&'.$facetQuery.'&sort=' . wphal_producedDateY . '&wt=json&json.nl=arrarr';
    204223
    205224            $json = wphal_do_get_data($url);
    206225            if(!isset($json->error)){
    207             $hal_page = (get_query_var('hal_page')) ? get_query_var('hal_page') : 1;
    208 
    209             $content = '<div id="wphal-content">';
     226                $content = "";
     227                $hal_page = (get_query_var('hal_page')) ? get_query_var('hal_page') : 1;
     228                if ($debug) {
     229                    $formattedJson = str_replace(["\n", ' '], ['<br />', '&nbsp;'] , json_encode($json,JSON_PRETTY_PRINT));
     230                    $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>',
     231                                        $option_groupe, $url, $doctype_s, $formattedJson );
     232                }
     233           
     234                $content .= '<div id="wphal-content">';
    210235            if (is_array($option_choix) && !empty($option_choix)){
    211236                $content .= '<ul id="wphal-menu">';
     
    261286                }
    262287                $content .= '</ul></li>';
    263 
    264288                $content .= '</ul><br/><hr>';
    265289            }
     
    772796    <div class="display" id="publications">';
    773797        if(null === $json || !isset($jsontype->response)) {
    774             if (get_option('option_groupe') == 'grouper') {
     798            if ($option_groupe == 'grouper') {
    775799                $doctype = file_get_contents(plugin_dir_path(__FILE__) . 'json' . DIRECTORY_SEPARATOR . 'doctype_fr.json');
    776800                $jsontype = json_decode($doctype);
     
    796820                    }
    797821                }
    798             } elseif (get_option('option_groupe') == 'paginer') {
     822            } elseif ($option_groupe == 'paginer') {
    799823
    800824//LISTE DES DOCUMENTS AVEC PAGINATION
     
    821845
    822846                $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';
     847                if (!empty($doctype_s) && $doctype_s != "") {
     848                    $url .= '&fq=docType_s:('.$doctype_s.')';
     849                }
    823850                $json = wphal_do_get_data($url);
    824851
Note: See TracChangeset for help on using the changeset viewer.