' . __( 'Paramètres', 'wp-hal' ) . '';
array_unshift( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links', 'hal_plugin_action_links',10,2);
/***********************************************************************************************************************
* PLUGIN SHORTCODE
**********************************************************************************************************************/
function cv_hal(){
if (get_option('option_groupe')=='grouper'){
//cURL sur l'API pour récupérer les données
$url = api . '?q=*:*&fq='.get_option('option_type').':('. urlencode(get_option('option_idhal')).')&group=true&group.field=docType_s&group.limit=1000&fl=docid,citationFull_s&facet.field=' . 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=' . producedDateY . '&wt=json&json.nl=arrarr';
} elseif (get_option('option_groupe')=='paginer'){
$url = api . '?q=*:*&fq='.get_option('option_type').':('.urlencode(get_option('option_idhal')).')&fl=docid,citationFull_s&facet.field=' . 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=' . producedDateY . '&wt=json&json.nl=arrarr';
}
$ch = curl_init($url);
// Options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_TIMEOUT => 10,
);
// Bind des options et de l'objet cURL que l'on va utiliser
curl_setopt_array($ch, $options);
// Récupération du résultat JSON
$json = json_decode(curl_exec($ch));
curl_close($ch);
//cURL sur l'API doctype pour récupérer les labels des docType
$chtype = curl_init(urltype);
// Options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_TIMEOUT => 10,
);
// Bind des options et de l'objet cURL que l'on va utiliser
curl_setopt_array($chtype, $options);
// Récupération du résultat JSON
$jsontype = json_decode(curl_exec($chtype));
curl_close($chtype);
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$choix= 0;
for ($i=1; $i<10; $i++){
if (get_option('option_choix')[$i]!=null){
$choix = $choix+1;
}
}
$content = '
';
$content .= '
' . __('Disciplines','wp-hal').' ';
if (locale == 'fr_FR') {
$facetdomain = $json->facet_counts->facet_fields->fr_domainAllCodeLabel_fs;
} elseif (locale == 'es_ES') {
$facetdomain = $json->facet_counts->facet_fields->es_domainAllCodeLabel_fs;
} else {
$facetdomain = $json->facet_counts->facet_fields->en_domainAllCodeLabel_fs;
}
if(!is_null($facetdomain) && !empty($facetdomain)){
$content .= '
';
$content .= '
';
$content .= 'Tri Alphabétique ';
$content .= 'Tri Occurrence ';
$content .= ' ';
$content .= '
';
foreach ($facetdomain as $res){
$name = explode(delimiter,$res[0]);
$content .= ''.$name[1].' ' .$res[1]. ' ';
}
$content .= ' ';
$content .= '
';
$content .= '
';
$content .= '
';
$content .= '
';
$content .= '
' . __('Graphique','wp-hal'); $content .= ' ';
}
$content .= '
' . __('Mots-clefs','wp-hal').' ';
if(!is_null($json->facet_counts->facet_fields->keyword_s) && !empty($json->facet_counts->facet_fields->keyword_s)){
$content .= '
';
$r = 0;
// CSS Nuage de mots
$maxsize=25;
$minsize=10;
$maxval=max(array_values($json->facet_counts->facet_fields->keyword_s[1]));
$minval=min(array_values($json->facet_counts->facet_fields->keyword_s[1]));
$spread=($maxval-$minval);
$step=($maxsize-$minsize)/$spread;
$tab = array();
foreach ($json->facet_counts->facet_fields->keyword_s as $res){
$r = $r+1;
if ($r > 20){
break;
}
$tab[] = $res;
}
asort($tab); // Tri du tableau par ordre alphabétique
foreach ($tab as $res){
$size= round($minsize + (($res[1]- $minval)*$step));
$content .= '
' . $res[0] . ' ';
}
$content .= '
';
$content .= '
';
$content .= '
';
$content .= 'Tri Alphabétique ';
$content .= 'Tri Occurrence ';
$content .= ' ';
$content .= '
';
$content .= '
';
$content .= '
' . __('Liste complète','wp-hal'); $content .= ' ';
}
$content .= '
' . __('Auteurs','wp-hal').' ';
if(!is_null($json->facet_counts->facet_fields->authIdLastNameFirstName_fs) && !empty($json->facet_counts->facet_fields->authIdLastNameFirstName_fs)){
$content .= '
';
$content .= '';
$content .= 'Tri Alphabétique ';
$content .= 'Tri Occurrence ';
$content .= ' ';
$content .= '';
$r = 0;
foreach ($json->facet_counts->facet_fields->authIdLastNameFirstName_fs as $res){
$r = $r+1;
if ($r > 10){
break;
}
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
$i = 1;
$content .= '
';
foreach ($json->facet_counts->facet_fields->authIdLastNameFirstName_fs as $res){
if($r < 10){
break;
}
if ($i < $r){
$i = $i+1;
} else {
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
}
$content .= '
';
$content .= '
';
$content .= ' ';
if ($r > 10){
$content .= '
' . __('Liste complète','wp-hal'); $content .= ' ';
}
}
$content .= '
' . __('Revues','wp-hal').' ';
if(!is_null($json->facet_counts->facet_fields->journalIdTitle_fs) && !empty($json->facet_counts->facet_fields->journalIdTitle_fs)){
$content .= '
';
$content .= 'Tri Alphabétique ';
$content .= 'Tri Occurrence ';
$content .= ' ';
$content .= '
';
$content .= '';
$r = 0;
foreach ($json->facet_counts->facet_fields->journalIdTitle_fs as $res){
$r = $r+1;
if ($r > 10){
break;
}
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
$i = 1;
$content .= '
';
foreach ($json->facet_counts->facet_fields->journalIdTitle_fs as $res){
if($r < 10){
break;
}
if ($i < $r){
$i = $i+1;
} else {
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
}
$content .= '
';
$content .= '
';
$content .= ' ';
if ($r > 10){
$content .= '
' . __('Liste complète','wp-hal'); $content .= ' ';
}
}
$content .= '
' . __('Année de production','wp-hal').' ';
if(!is_null($json->facet_counts->facet_fields->producedDateY_i) && !empty($json->facet_counts->facet_fields->producedDateY_i)){
$content .= '
';
$content .= 'Tri Alphabétique ';
$content .= 'Tri Occurrence ';
$content .= ' ';
$content .= '
';
$content .= '';
rsort($json->facet_counts->facet_fields->producedDateY_i);
$r = 0;
foreach ($json->facet_counts->facet_fields->producedDateY_i as $res){
$r = $r+1;
if ($r > 10){
break;
}
$content .= '
' . $res[0] . ' ' .$res[1]. ' ';
}
$i = 1;
$content .= '
';
foreach ($json->facet_counts->facet_fields->producedDateY_i as $res){
if($r < 10){
break;
}
if ($i < $r){
$i = $i+1;
} else {
$content .= '
' . $res[0] . ' ' .$res[1]. ' ';
}
}
$content .= '
';
$content .= '
';
$content .= ' ';
if ($r > 10){
$content .= '
' . __('Liste complète','wp-hal'); $content .= ' ';
}
}
$content .= '
' . __('Institutions','wp-hal').' ';
if(!is_null($json->facet_counts->facet_fields->instStructIdName_fs) && !empty($json->facet_counts->facet_fields->instStructIdName_fs)){
$content .= '
';
$content .= 'Tri Alphabétique ';
$content .= 'Tri Occurrence ';
$content .= ' ';
$content .= '
';
$content .= '';
$r = 0;
foreach ($json->facet_counts->facet_fields->instStructIdName_fs as $res){
$r = $r+1;
if ($r > 10){
break;
}
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
$i = 1;
$content .= '
';
foreach ($json->facet_counts->facet_fields->instStructIdName_fs as $res){
if($r < 10){
break;
}
if ($i < $r){
$i = $i+1;
} else {
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
}
$content .= '
';
$content .= '
';
$content .= ' ';
if ($r > 10){
$content .= '
' . __('Liste complète','wp-hal'); $content .= ' ';
}
}
$content .= '
' . __('Laboratoires','wp-hal').' ';
if(!is_null($json->facet_counts->facet_fields->labStructIdName_fs) && !empty($json->facet_counts->facet_fields->labStructIdName_fs)){
$content .= '
';
$content .= 'Tri Alphabétique ';
$content .= 'Tri Occurrence ';
$content .= ' ';
$content .= '
';
$content .= '';
$r = 0;
foreach ($json->facet_counts->facet_fields->labStructIdName_fs as $res){
$r = $r+1;
if ($r > 10){
break;
}
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
$i = 1;
$content .= '
';
foreach ($json->facet_counts->facet_fields->labStructIdName_fs as $res){
if($r < 10){
break;
}
if ($i < $r){
$i = $i+1;
} else {
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
}
$content .= '
';
$content .= '
';
$content .= ' ';
if ($r > 10){
$content .= '
' . __('Liste complète','wp-hal'); $content .= ' ';
}
}
$content .= '
' . __('Départements','wp-hal').' ';
if(!is_null($json->facet_counts->facet_fields->deptStructIdName_fs) && !empty($json->facet_counts->facet_fields->deptStructIdName_fs)){
$content .= '
';
$content .= 'Tri Alphabétique ';
$content .= 'Tri Occurrence ';
$content .= ' ';
$content .= '
';
$content .= '';
$r = 0;
foreach ($json->facet_counts->facet_fields->deptStructIdName_fs as $res){
$r = $r+1;
if ($r > 10){
break;
}
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
$i = 1;
$content .= '
';
foreach ($json->facet_counts->facet_fields->deptStructIdName_fs as $res){
if($r < 10){
break;
}
if ($i < $r){
$i = $i+1;
} else {
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
}
$content .= '
';
$content .= '
';
$content .= ' ';
if ($r > 10){
$content .= '
' . __('Liste complète','wp-hal'); $content .= ' ';
}
}
$content .= '
' . __('Équipes de recherche','wp-hal').' ';
if(!is_null($json->facet_counts->facet_fields->rteamStructIdName_fs) && !empty($json->facet_counts->facet_fields->rteamStructIdName_fs)){
$content .= '
';
$content .= 'Tri Alphabétique ';
$content .= 'Tri Occurrence ';
$content .= ' ';
$content .= '
';
$content .= '';
$r = 0;
foreach ($json->facet_counts->facet_fields->rteamStructIdName_fs as $res){
$r = $r+1;
if ($r > 10){
break;
}
$name = explode(delimiter,$res[0]);
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
$i = 1;
$content .= '
';
foreach ($json->facet_counts->facet_fields->rteamStructIdName_fs as $res){
if($r < 10){
break;
}
if ($i < $r){
$i = $i+1;
} else {
$content .= '
' . $name[1] . ' ' .$res[1]. ' ';
}
}
$content .= '
';
$content .= '
';
$content .= ' ';
if ($r > 10){
$content .= '
' . __('Liste complète','wp-hal'); $content .= ' ';
}
}
$content .= '
' . __('Publications','wp-hal').' ';
$content .= '
' . __('Nombre de documents', 'wp-hal');
if (get_option('option_groupe')=='grouper'){
//LISTE DES DOCUMENTS PAR GROUPE
$content .='
' . $json->grouped->docType_s->matches . ' ';
$content .= '
';
for($i=0; $json->grouped->docType_s->groups[$i] != null ; $i++){
for($d=0; $jsontype->response->result->doc[$d] != null; $d++ ){
if ($json->grouped->docType_s->groups[$i]->groupValue == $jsontype->response->result->doc[$d]->str[0]){
$titre=$jsontype->response->result->doc[$d]->str[1];
}
}
$content .= '' . $titre . '' . $json->grouped->docType_s->groups[$i]->doclist->numFound .' ' . _n('document','documents',$json->grouped->docType_s->groups[$i]->doclist->numFound,'wp-hal') .' ';
$content .= '
';
$content .= '
';
foreach ($json->grouped->docType_s->groups[$i]->doclist->docs as $result){
$content .= '' . $result->citationFull_s . ' ';
}
$content .= ' ';
$content .= '
';
}
$content .= ' ';
} elseif(get_option('option_groupe')=='paginer'){
//LISTE DES DOCUMENTS AVEC PAGINATION
$content .='
' . $json->response->numFound . ' ';
//--MODULE PAGINATION--//
$messagesParPage = 10;
$total = $json->response->numFound;
$nombreDePages = ceil($total / $messagesParPage);
if (isset($paged)) {
$pageActuelle = intval($paged);
if ($pageActuelle > $nombreDePages) {
$pageActuelle = $nombreDePages;
}
} else {
$pageActuelle = 1;
}
$premiereEntree = ($pageActuelle - 1) * $messagesParPage;
$url = api . '?q=*:*&fq='.get_option('option_type').':('. urlencode(get_option('option_idhal')).')&fl=docid,citationFull_s,keyword_s,bookTitle_s,producedDate_s,authFullName_s&start=' .$premiereEntree . '&rows=' . $messagesParPage . '&sort=' . producedDateY . '&wt=json';
$ch = curl_init($url);
// Options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_TIMEOUT => 10,
);
// Bind des options et de l'objet cURL que l'on va utiliser
curl_setopt_array($ch, $options);
// Récupération du résultat JSON
$json = json_decode(curl_exec($ch));
curl_close($ch);
//--MODULE PAGINATION--//
$content .= '
';
for ($i = 0; $json->response->docs[$i]!= ''; $i++){
$content .= '' . $json->response->docs[$i]->citationFull_s . ' ';
}
$content .= ' ';
//--AFFICHAGE PAGINATION--//
$precedents=$pageActuelle-2;
$suivants= $pageActuelle+2;
$precedent=$pageActuelle-1;
$suivant= $pageActuelle+1;
$penultimate = $nombreDePages - 1;
$content .= '';
//--AFFICHAGE PAGINATION--//
}
$content .='
';
$content .= '';
return $content;
}
function wp_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');
wp_enqueue_style('wp-hal-style2');
}
function wp_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-script1');
wp_enqueue_script('wp-hal-script2');
wp_enqueue_script('wp-hal-script3');
wp_enqueue_script('wp-hal-script4');
$url = api . '?q=*:*&fq='. get_option('option_type').':('. urlencode(get_option('option_idhal')).')&fl=docid,citationFull_s&facet.field='. lang .'domainAllCodeLabel_fs&facet.field=keyword_s&facet.field=journalIdTitle_fs&facet.field=producedDateY_i&facet.field=authIdLastNameFirstName_fs&facet.mincount=1&facet=true&wt=json&json.nl=arrarr';
$ch = curl_init($url);
// Options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_TIMEOUT => 10,
);
// Bind des options et de l'objet cURL que l'on va utiliser
curl_setopt_array($ch, $options);
// Récupération du résultat JSON
$json = json_decode(curl_exec($ch));
curl_close($ch);
if (locale == 'fr_FR') {
$facetdomain = $json->facet_counts->facet_fields->fr_domainAllCodeLabel_fs;
} elseif (locale == 'en_US') {
$facetdomain = $json->facet_counts->facet_fields->en_domainAllCodeLabel_fs;
} elseif (locale == 'es_ES') {
$facetdomain = $json->facet_counts->facet_fields->es_domainAllCodeLabel_fs;
} else {
$facetdomain = $json->facet_counts->facet_fields->eu_domainAllCodeLabel_fs;
}
if(!is_null($facetdomain)){
foreach ($facetdomain as $res){
$name = explode(delimiter,$res[0])[1];
$value = $res[1];
$array[] = array($name,$value);
}
}
wp_localize_script('wp-hal-script4', 'WPWallSettings', json_encode($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);
}
/**
* Récupère les fichiers css et js
*/
add_action( 'wp_enqueue_scripts', 'wp_adding_style' );
add_action( 'wp_enqueue_scripts', 'wp_adding_script' );
/**
* Charge lorsque le plugin est désactivé
*/
register_deactivation_hook( __FILE__, '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', '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 wphal_widget(){
$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 récentes", 'wp-hal'),
$options
);
}
/**
* Crée le widget
* @param $args
* @param $instance
*/
function widget($args, $instance){
$num = 5;
$url = api .'?q=*:*&fq='.$instance['select'].':' . $instance['idhal'] . '&fl=uri_s,title_s&sort=' . producedDateY . '&rows=' . $num . '&wt=json';
$ch = curl_init($url);
// Options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_TIMEOUT => 10,
);
// Bind des options et de l'objet cURL que l'on va utiliser
curl_setopt_array($ch, $options);
// Récupération du résultat JSON
$json = json_decode(curl_exec($ch));
curl_close($ch);
$content = '