' . __( 'Paramètres', 'wp-hal' ) . ''; array_unshift( $links, $settings_link ); return $links; } add_filter( 'query_vars', 'wphal_query_vars' ); function wphal_query_vars( $query_vars ) { $query_vars[] = 'hal_page'; return $query_vars; } add_filter( 'plugin_action_links', 'wphal_action_links',10,2); /** * @param $url * @return object */ function wphal_do_common_curl_call($url) { $response = wp_remote_get($url, [ 'timeout'=>20, 'user-agent'=>"HAL Plugin Wordpress " . wphal_version, 'headers' => ['Content-type'=> 'application/json'] ]); // we could ve parsed the response but if in general if no results then we get empty content $body = wp_remote_retrieve_body($response); // Récupération du résultat JSON $json = json_decode($body); return $json; } function wphal_clear_transients() { global $wpdb; // delete all "hal namespace" transients $sql = " DELETE FROM {$wpdb->options} WHERE option_name like '\_transient\_hal\_%' OR option_name like '\_transient\_timeout\_hal\_%' "; $wpdb->query($sql); } /** * fetches data from cache or download data from HAL API * @param $url * @return object */ function wphal_do_get_data($url) { $transient_id = 'hal_'.md5($url); if(!empty(get_option('option_erase_cache'))){ // we reset cache transient for hal namespace wphal_clear_transients(); update_option('option_erase_cache', ''); } $cache_expiration = empty(get_option('option_cache_timeout')) ? 1 * DAY_IN_SECONDS : intval(get_option('option_cache_timeout')) * MINUTE_IN_SECONDS; if ( false === ( $value = get_transient( $transient_id ) ) ) { $json = wphal_do_common_curl_call($url); if($json) set_transient( $transient_id, $json, $cache_expiration); return $json; } else{ return $value; } } /** * PLUGIN SHORTCODE ND-DOC * @param $param * @return int */ function wphal_nb_doc($param) { $idhal = wphal_verifSolr(get_option('option_idhal')); extract(shortcode_atts(array( 'type' => get_option('option_type'), 'id' => $idhal ), $param )); /** * @var $id : defined by extract * @var string $type : defined by extract */ $id = wphal_verifSolr($id); $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&rows=0&wt=json'; $json =wphal_do_get_data($url); return $json->response->numFound; } /** * PLUGIN SHORTCODE CV-HAL * @param $param * @return string */ function wphal_cv_hal($param){ $content = ''; if ( !wphal_is_curl_installed() ) { $content = 'CURL not installed, please check the FAQ with the code : CURL'; } else { $possible_ids = ["authIdHal_s", "structId_i", "authStructId_i", "anrProjectId_i", "europeanProjectId_i", "collCode_s"]; $option_choix = !empty(get_option('option_choix')) ? get_option('option_choix') : []; if(in_array('disciplines', $option_choix)){ //Lance les scripts pour le Graphique wp_enqueue_style('wp-hal-style2'); wp_enqueue_script('wp-hal-script1'); wp_enqueue_script('wp-hal-script2'); wp_enqueue_script('wp-hal-script3'); } $facetdomain = null; // those parameters are configured from plusing settings $default_id = wphal_verifSolr(get_option('option_idhal')); $default_type = get_option('option_type'); $default_contact = get_option('option_infocontact'); // here we merge with shortcode parameters extract(shortcode_atts(array( 'type' => $default_type, 'id' => $default_id, 'contact' => $default_contact ), $param )); /** @var $id : defined by extract * @var string $type : defined by extract * @var string $contact : defined by extract */ if (!empty($id) && in_array($type, $possible_ids)) { $id = wphal_verifSolr($id); if (get_option('option_groupe') == 'grouper') { //cURL sur l'API pour récupérer les données $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&group=true&group.field=docType_s&group.limit=1000&fl=docid,citationFull_s&facet.field=' . wphal_lang . '_domainAllCodeLabel_fs&facet.field=keyword_s&facet.field=journalIdTitle_fs&facet.field=producedDateY_i&facet.field=authIdLastNameFirstName_fs&facet.field=instStructIdName_fs&facet.field=labStructIdName_fs&facet.field=deptStructIdName_fs&facet.field=rteamStructIdName_fs&facet.mincount=1&facet=true&sort=' . wphal_producedDateY . '&wt=json&json.nl=arrarr'; } elseif (get_option('option_groupe') == 'paginer') { $url = wphal_api . '?q=*:*&fq=' . $type . ':(' . urlencode($id) . ')&fl=docid,citationFull_s&facet.field=' . wphal_lang . '_domainAllCodeLabel_fs&facet.field=keyword_s&facet.field=journalIdTitle_fs&facet.field=producedDateY_i&facet.field=authIdLastNameFirstName_fs&facet.field=instStructIdName_fs&facet.field=labStructIdName_fs&facet.field=deptStructIdName_fs&facet.field=rteamStructIdName_fs&facet.mincount=1&facet=true&sort=' . wphal_producedDateY . '&wt=json&json.nl=arrarr'; } $json = wphal_do_get_data($url); $hal_page = (get_query_var('hal_page')) ? get_query_var('hal_page') : 1; $content = '
'; if (is_array($option_choix) && !empty($option_choix)){ $content .= '

'; } $content .= '
'; if (get_option('option_groupe') == 'grouper') { $doctype = file_get_contents(plugin_dir_path( __FILE__ ).'json'. DIRECTORY_SEPARATOR .'doctype_fr.json'); $jsontype = json_decode($doctype); //LISTE DES DOCUMENTS PAR GROUPE $content .= '
' . $json->grouped->docType_s->matches . ' '; $content .= __('documents', 'wp-hal'). '

'; for ($i = 0; !empty($jsontype->response->result->doc[$i]); $i++) { for ($d = 0; !empty($json->grouped->docType_s->groups[$d]); $d++) { if ($json->grouped->docType_s->groups[$d]->groupValue == $jsontype->response->result->doc[$i]->str[0]){ $titre = $jsontype->response->result->doc[$i]->str[1]; $content .= '

' . __($titre, 'wp-hal') . '

'; $content .= '
'; $content .= '
    '; foreach ($json->grouped->docType_s->groups[$d]->doclist->docs as $result) { $content .= '
  • ' . $result->citationFull_s . '
  • '; } $content .= '
'; $content .= '

'; break; } } } } elseif (get_option('option_groupe') == 'paginer') { //LISTE DES DOCUMENTS AVEC PAGINATION $content .= '
' . $json->response->numFound . ' '; $content .= __('documents', 'wp-hal'). '

'; //--MODULE PAGINATION--// $messagesParPage = 10; $total = $json->response->numFound; $nombreDePages = ceil($total / $messagesParPage); if (isset($hal_page)) { $pageActuelle = intval($hal_page); if ($pageActuelle > $nombreDePages) { $pageActuelle = $nombreDePages; } } else { $pageActuelle = 1; } $premiereEntree = ($pageActuelle - 1) * $messagesParPage; $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'; $json = wphal_do_get_data($url); //--MODULE PAGINATION--// $count_results = count($json->response->docs); if($count_results>0) { $content .= '
    '; for ( $i = 0; $i <= $count_results - 1; $i ++ ) { $content .= '
  • ' . $json->response->docs[ $i ]->citationFull_s . '
  • '; } $content .= '
'; } else { $content = '
no results !
'; } if($total> $messagesParPage) { $base_url = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST']; $url = $base_url . $_SERVER["REQUEST_URI"]; $explodedURL= explode('?', $url); $queryString = $explodedURL[1]; $pagedHref = $explodedURL[0]; if(!empty($queryString)){ $parsedQueryString = []; parse_str($queryString, $parsedQueryString); if(isset($parsedQueryString["hal_page"])){ unset($parsedQueryString["hal_page"]); } $pagedHref .= '?'; foreach($parsedQueryString as $name => $value){ $pagedHref .= $name.'='.$value.'&'; } // we add it back.. $pagedHref .= 'hal_page='; }else { $pagedHref .= '?hal_page='; } //--AFFICHAGE PAGINATION--// $precedents = $pageActuelle - 2; $suivants = $pageActuelle + 2; $precedent = $pageActuelle - 1; $suivant = $pageActuelle + 1; $penultimate = $nombreDePages - 1; $content .= '
    '; //--BOUTON PRECEDENT--// if ( $pageActuelle != 1 ) { $content .= '
  • «
  • '; } if ( $nombreDePages <= 6 ) {// Cas 1 : 6 pages ou moins - Pas de troncature for ( $i = 1; $i <= $nombreDePages; $i ++ ) { if ( $i == $pageActuelle ) { $content .= '
  • ' . $i . '
  • '; } else { $content .= '
  • ' . $i . '
  • '; } } } elseif ( $nombreDePages >= 7 ) {// Cas 2 : 7 pages ou plus - Troncature if ( $pageActuelle <= 3 ) {// Lorsque l'on est sur les trois premières pages for ( $i = 1; $i <= 4; $i ++ ) { if ( $i == $pageActuelle ) { $content .= '
  • ' . $i . '
  • '; } else { $content .= '
  • ' . $i . '
  • '; } } $content .= '
  • '; $content .= '
  • ' . $penultimate . '
  • '; $content .= '
  • ' . $nombreDePages . '
  • '; } if ( $pageActuelle >= 4 && $pageActuelle <= $penultimate - 2 ) {//Lorsque l'on arrive sur la quatrième page $content .= '
  • 1
  • '; $content .= '
  • '; $content .= '
  • ' . $precedents . '
  • '; $content .= '
  • ' . $precedent . '
  • '; $content .= '
  • ' . $pageActuelle . '
  • '; $content .= '
  • ' . $suivant . '
  • '; $content .= '
  • ' . $suivants . '
  • '; $content .= '
  • '; $content .= '
  • ' . $nombreDePages . '
  • '; } if ( $pageActuelle >= $penultimate - 1 ) { $content .= '
  • 1
  • '; $content .= '
  • 2
  • '; $content .= '
  • '; for ( $i = $penultimate - 2; $i <= $nombreDePages; $i ++ ) { if ( $i == $pageActuelle ) { $content .= '
  • ' . $i . '
  • '; } else { $content .= '
  • ' . $i . '
  • '; } } } } //--BOUTON SUIVANT--// if ( $pageActuelle < $nombreDePages ) { $content .= '
  • »
  • '; } $content .= '
'; //--AFFICHAGE PAGINATION--// } } $content .= '
'; }else{ $content = 'Plugin is not configured correctly or shortcode parameters are not valid, please check the documentation'; } $content .= ''; //--AFFICHAGE GRAPHIQUE DOMAINE--// if (!is_null($facetdomain)) { foreach ($facetdomain as $res) { $name = explode(wphal_delimiter, $res[0])[1]; $value = $res[1]; $array[] = array($name, $value); } wp_localize_script('wp-hal-script4', 'WPWallSettings', $array); } $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')); wp_localize_script('wp-hal-script4', 'translate', $translation); } // tags other that those will be stripped $allowed_html_tags = array( 'div' => array( 'class' => array(), 'id' => array(), 'style' => array(), ), "span"=> array( 'class' => array(), 'id' => array(), 'style' => array(), ), "img"=> array( 'alt' => array(), 'src' => array(), 'style' => array(), ), 'p' => array( 'style' => array(), 'id' => array(), ), 'h3' => array( 'id' => array(), 'class' => array(), 'style' => array() ), 'a' => array( 'href' => array(), 'target' => array(), 'title' => array(), 'id' => array(), 'class' => array(), 'style' => array(), 'onclick' => array(), ), 'ul' => array( 'class' => array(), 'id' => array(), 'style' => array(), ), 'li' => array( 'class' => array(), 'id' => array(), 'data-percentage' => array() ), 'button' => array( 'class' => array(), 'id' => array(), 'type' => array(), 'style' => array(), 'onclick' => array() ) ,'br' => array() ,'hr' => array() ,'i' => array(), ); add_filter( 'safe_style_css', function( $styles ) { $styles[] = 'display'; return $styles; } ); return wp_kses($content, $allowed_html_tags); } function wphal_verifSolr($values){ $verifsolr = explode(',',$values); $numverif = count($verifsolr); $solrsql = ''; if ($numverif<1024){ $solrsql = str_replace(',',' OR ',$values); } else { $listsolrsql = explode(',',$values); for($i=0;$i<1024;$i++){ if ($i == 0){ $solrsql = $listsolrsql[$i]; } else { $solrsql .= ' OR '; $solrsql .= $listsolrsql[$i]; } } } return $solrsql; } function wphal_adding_style() { wp_register_style('wp-hal-style1', plugins_url('/css/style.css', __FILE__)); wp_register_style('wp-hal-style2', plugins_url('/css/jquery.jqplot.css', __FILE__)); wp_enqueue_style('wp-hal-style1'); } function wphal_adding_script() { wp_register_script('wp-hal-script1',plugins_url('/js/jquery.jqplot.js', __FILE__)); wp_register_script('wp-hal-script2',plugins_url('/js/jqplot.highlighter.js', __FILE__)); wp_register_script('wp-hal-script3',plugins_url('/js/jqplot.pieRenderer.js', __FILE__)); wp_register_script('wp-hal-script4',plugins_url('/js/cv-hal.js', __FILE__)); wp_enqueue_script("jquery"); wp_enqueue_script('wp-hal-script4', false, array(), false, true); } /** * Récupère les fichiers css et js */ if ( wphal_is_curl_installed() ) { add_action('wp_enqueue_scripts', 'wphal_adding_style'); add_action('wp_enqueue_scripts', 'wphal_adding_script'); } /** * Charge lorsque le plugin est désactivé */ register_deactivation_hook( __FILE__, 'wphal_reset_option' ); /** * Ajoute le widget wphal à l'initialisation des widgets */ add_action('widgets_init','wphal_init'); /** * Ajoute le menu à l'initialisation du menu admin */ add_action( 'admin_menu', 'wphal_menu' ); /** * Fonction de création du menu */ function wphal_menu() { add_menu_page( 'Options', 'Hal', 'manage_options', 'wp-hal.php', 'wphal_option' , '', 21); add_action( 'admin_init', 'wphal_register_settings' ); } /** * Initialise le nouveau widget */ function wphal_init(){ register_widget("wphal_widget"); } /*********************************************************************************************************************** * PLUGIN WIDGET **********************************************************************************************************************/ /** * Classe du widget wphal */ class wphal_widget extends WP_widget{ /** * Défini les propriétés du widget */ function __construct(){ $options = array( "classname" => "wphal-publications", "description" => __("Afficher les dernières publications d'un auteur ou d'une structure.", 'wp-hal') ); parent::__construct( 'hal-publications', __("Publications HAL", 'wp-hal'), $options ); } /** * Crée le widget * @param $args * @param $instance */ function widget($args, $instance){ if(isset($instance['idhal']) && !empty($instance['idhal'])) { $content = ''; extract($args); /** * @var $before_widget : defined by extract * @var $before_title : defined by extract * @var $after_title : defined by extract * @var $after_widget : defined by extract */ if (!wphal_is_curl_installed()) { $content = 'Please check the FAQ with the code : CURL'; } else { $instance['idhal'] = wphal_verifSolr($instance['idhal']); $url = wphal_api . '?q=*:*&fq=' . $instance['select'] . ':' . urlencode($instance['idhal']) . '&fl=uri_s,' . $instance['typetext'] . '&sort=' . wphal_producedDateY . '&rows=' . $instance['nbdoc'] . '&wt=json'; $json = wphal_do_get_data($url); $count_results = count($json->response->docs); if ($count_results > 0) { $content = ''; } else { $content = '
no results !
'; } } // tags other that those will be stripped $allowed_html_tags = array( 'div' => array( 'class' => array(), 'id' => array(), ), 'h2' => array(), 'section' => array(), 'a' => array( 'href' => array(), 'target' => array(), 'title' => array(), 'id' => array(), 'class' => array(), ), 'ul' => array( 'class' => array(), 'id' => array(), ), 'li' => array( 'class' => array(), 'id' => array(), ) ); $widget_block = $before_widget; $widget_block .= $before_title . $instance['titre'] . $after_title; $widget_block .= $content; $widget_block .= $after_widget; echo wp_kses($widget_block, $allowed_html_tags); } } /** * Sauvegarde des données * @param $new * @param $old */ function update($new, $old){ //the id must be provided if(isset($new['idhal']) && !empty($new['idhal'])) { $new['idhal'] = wphal_sanitize_username($new['idhal']); $new['nbdoc'] = wphal_sanitize_id($new['nbdoc']); return $new; }else return false; } /** * Formulaire du widget * @param $instance */ function form($instance){ $defaut = array( 'titre' => __("Publications Hal", 'wp-hal'), 'select' => "authIdHal_s", 'typetext' => "title_s", 'idhal' => "", 'nbdoc' => 5 ); $instance = wp_parse_args($instance,$defaut); ?>

" id="get_field_id("titre"));?>" class="widefat" type="text"/>

" name="get_field_name("nbdoc"));?>" type="number" step="1" min="1" max="10" value="" size="3">

" id="get_field_id("idhal"));?>" type="text"/>

'string', 'sanitize_callback' => 'wphal_sanitize_username', 'default' => NULL, )); register_setting( 'wphal_option', 'option_lang' ); register_setting( 'wphal_option', 'option_infocontact' ); register_setting( 'wphal_option', 'option_email' , array( 'type' => 'string', 'sanitize_callback' => 'sanitize_email', 'default' => NULL, )); register_setting( 'wphal_option', 'option_tel' , array( 'type' => 'string', 'sanitize_callback' => 'wphal_sanitize_phone', 'default' => NULL, )); register_setting( 'wphal_option', 'option_social0' , array( 'type' => 'string', 'sanitize_callback' => 'wphal_sanitize_username', 'default' => NULL, )); register_setting( 'wphal_option', 'option_social1' , array( 'type' => 'string', 'sanitize_callback' => 'wphal_sanitize_username', 'default' => NULL, )); register_setting( 'wphal_option', 'option_social2' , array( 'type' => 'string', 'sanitize_callback' => 'wphal_sanitize_username', 'default' => NULL, )); register_setting( 'wphal_option', 'option_social3' , array( 'type' => 'string', 'sanitize_callback' => 'wphal_sanitize_username', 'default' => NULL, )); register_setting( 'wphal_option', 'option_cache_timeout' , array( 'type' => 'string', 'sanitize_callback' => 'wphal_sanitize_id', 'default' => NULL, )); register_setting( 'wphal_option', 'option_erase_cache' ); } /** * Crée le menu d'option du plugin */ function wphal_option() { if (get_option('option_type')==''){ update_option('option_type', 'authIdHal_s'); } if (get_option('option_groupe')==''){ update_option('option_groupe', 'paginer'); } ?>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
cache
option_erase_cache" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/>
email" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/>
phone" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/>
facebook" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/>
twitter" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/>
google" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/>
linkedin" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/>