PluginProbe
HAL / 1.0
HAL v1.0
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 1.0, at wp-hal.php

1,028 lines 61.0 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: 1.0
7 * Author: Baptiste Blondelle
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 (locale == 'fr_FR') {
22 define('lang', 'fr_');
23 } elseif (locale == 'es_ES') {
24 define('lang', 'es_');
25 } else {
26 define('lang', 'en_');
27 }
28
29 // Création du shortcode ('nom du shortcode', 'fonction appelée')
30 add_shortcode( 'cv-hal', 'cv_hal' );
31
32
33 function charger_languages() {
34 load_plugin_textdomain('wp-hal', false, dirname(plugin_basename(__FILE__)) . '/lang/');
35 }
36
37 add_action('plugins_loaded', 'charger_languages');
38
39 function hal_plugin_action_links( $links, $file ) {
40 if ( $file != plugin_basename( __FILE__ ))
41 return $links;
42
43 $settings_link = '<a href="admin.php?page=wp-hal.php">' . __( 'Paramètres', 'wp-hal' ) . '</a>';
44
45 array_unshift( $links, $settings_link );
46
47 return $links;
48 }
49
50
51 add_filter( 'plugin_action_links', 'hal_plugin_action_links',10,2);
52
53
54 /***********************************************************************************************************************
55 * PLUGIN SHORTCODE
56 **********************************************************************************************************************/
57 function cv_hal(){
58
59 if (get_option('option_groupe')=='grouper'){
60 //cURL sur l'API pour récupérer les données
61 $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';
62 } elseif (get_option('option_groupe')=='paginer'){
63 $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';
64 }
65
66 $ch = curl_init($url);
67 // Options
68 $options = array(
69 CURLOPT_RETURNTRANSFER => true,
70 CURLOPT_HTTPHEADER => array('Content-type: application/json'),
71 CURLOPT_TIMEOUT => 10,
72 );
73
74 // Bind des options et de l'objet cURL que l'on va utiliser
75 curl_setopt_array($ch, $options);
76 // Récupération du résultat JSON
77 $json = json_decode(curl_exec($ch));
78 curl_close($ch);
79
80 //cURL sur l'API doctype pour récupérer les labels des docType
81 $chtype = curl_init(urltype);
82 // Options
83 $options = array(
84 CURLOPT_RETURNTRANSFER => true,
85 CURLOPT_HTTPHEADER => array('Content-type: application/json'),
86 CURLOPT_TIMEOUT => 10,
87 );
88
89 // Bind des options et de l'objet cURL que l'on va utiliser
90 curl_setopt_array($chtype, $options);
91 // Récupération du résultat JSON
92 $jsontype = json_decode(curl_exec($chtype));
93 curl_close($chtype);
94
95 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
96
97 $content = '
98 <div id="content-plugin">
99 <ul id="tabs" class="nav nav-pills">';
100 $content .= '<li class="active"><a href="#publications" data-toggle="tab" style="font-size:18px; text-decoration: none;">' . __('Publications', 'wp-hal'). '</a></li>';
101 $content .= '<li><a href="#filtres" data-toggle="collapse" style="font-size:18px; text-decoration: none;">' . __('Filtres', 'wp-hal'). '<span class="caret"></span></a></li><li>';
102 $content .= '<ul class="nav nav-pills collapse" id="filtres">';
103 if (get_option('option_choix')[1] == 'contact') {
104 $content .= '<li><a class="subnavtab" href="#contact" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Contact', 'wp-hal');
105 $content .= '</a></li>';}
106 if (get_option('option_choix')[2] == 'disciplines') {
107 $content .= '<li><a class="subnavtab" href="#disciplines" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Disciplines', 'wp-hal');
108 $content .= '</a></li>';}
109 if (get_option('option_choix')[3] == 'mots-clefs') {
110 $content .= '<li><a class="subnavtab" href="#keywords" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Mots-clefs', 'wp-hal');
111 $content .= '</a></li>';}
112 if (get_option('option_choix')[4] == 'auteurs') {
113 $content .= '<li><a class="subnavtab" href="#auteurs" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Auteurs', 'wp-hal');
114 $content .= '</a></li>';}
115 if (get_option('option_choix')[5] == 'revues') {
116 $content .= '<li><a class="subnavtab" href="#revues" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Revues', 'wp-hal');
117 $content .= '</a></li>';}
118 if (get_option('option_choix')[6] == 'annee') {
119 $content .= '<li><a class="subnavtab" href="#annees" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Année de production', 'wp-hal');
120 $content .= '</a></li>';}
121 if (get_option('option_choix')[7] == 'institution') {
122 $content .= '<li><a class="subnavtab" href="#insts" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Institutions', 'wp-hal');
123 $content .= '</a></li>';}
124 if (get_option('option_choix')[8] == 'laboratoire') {
125 $content .= '<li><a class="subnavtab" href="#labs" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Laboratoires', 'wp-hal');
126 $content .= '</a></li>';}
127 if (get_option('option_choix')[9] == 'departement') {
128 $content .= '<li><a class="subnavtab" href="#depts" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Départements', 'wp-hal');
129 $content .= '</a></li>';}
130 if (get_option('option_choix')[10] == 'equipe') {
131 $content .= '<li><a class="subnavtab" href="#equipes" data-toggle="tab" style="margin:1px; text-decoration: none;">' . __('Équipes de recherche', 'wp-hal');
132 $content .= '</a></li>';}
133 $content .= '</ul></li>';
134 $content .= '</ul><br/><hr>';
135
136 $content .= '<div id="my-tab-content" class="tab-content">
137 <div class="tab-pane" id="contact">
138 <h3>' . __('Contact','wp-hal'); $content .= '</h3>
139
140 <ul style="list-style-type: none;">';
141 if (get_option('option_email') != ''){
142 $content .= '<li><img alt="mail" src=" ' . plugin_dir_url( __FILE__ ) . 'img/mail.svg" style=" width:16px; margin-left:2px; margin-right:2px;"/><a href="mailto:' . get_option('option_email') . '" target="_blank">' . get_option('option_email') . '</a></li>';
143 }
144 if (get_option('option_tel') != ''){
145 $content .= '<li><img alt="phone" src=" ' . plugin_dir_url( __FILE__ ) . 'img/phone.svg" style="width:16px; margin-left:2px; margin-right:2px;"/>' . get_option('option_tel') . '</li>';
146 }
147 if (get_option('option_social0') != ''){
148 $content .= '<li><a href="http://www.facebook.com/' . get_option('option_social0') . '" target="_blank"><img src=" ' . plugin_dir_url( __FILE__ ) . 'img/facebook.svg" style="width:32px; margin:4px;"/></a>';
149 }
150 if (get_option('option_social1') != ''){
151 $content .= '<a href="http://www.twitter.com/' . get_option('option_social1') . '" target="_blank"><img src=" ' . plugin_dir_url( __FILE__ ) . 'img/twitter.svg" style="width:32px; margin:4px;"/></a>';
152 }
153 if (get_option('option_social2') != ''){
154 $content .= '<a href="https://plus.google.com/u/0/+' . get_option('option_social2') . '" target="_blank"><img src=" ' . plugin_dir_url( __FILE__ ) . 'img/google-plus.svg" style="width:32px; margin:4px;"/></a>';
155 }
156 if (get_option('option_social3') != ''){
157 $content .= '<a href="http://sa.linkedin.com/pub/' . get_option('option_social3') . '" target="_blank"><img src=" ' . plugin_dir_url( __FILE__ ) . 'img/linkedin.svg" style="width:32px; margin:4px;"/></a></li>';
158 }
159 $content .= '</ul>
160 </div>
161 <div class="tab-pane" id="disciplines">
162 <h3>' . __('Disciplines','wp-hal').'</h3>';
163
164 if (locale == 'fr_FR') {
165 $facetdomain = $json->facet_counts->facet_fields->fr_domainAllCodeLabel_fs;
166 } elseif (locale == 'es_ES') {
167 $facetdomain = $json->facet_counts->facet_fields->es_domainAllCodeLabel_fs;
168 } else {
169 $facetdomain = $json->facet_counts->facet_fields->en_domainAllCodeLabel_fs;
170 }
171
172 if(!is_null($facetdomain) && !empty($facetdomain)){
173
174 $content .= '<div id="listdisci">';
175 $content .= '<ul class="discipline list-group">';
176 $content .= '<li class="list-group-item">';
177 $content .= '<span id="tridisciplines">';
178 $content .= '<a class="btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri Alphabétique" href="" id="tridisci" onclick="javascript:toggleSort(this, true, \'discipline\', \'discipline\', \'tridisci\'); return false;" style="font-size:16px; text-decoration: none;" ><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>';
179 $content .= '<a class="pull-right btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri par Nombre d\'Occurences" href="" id="trinbdisci" onclick="javascript:toggleSort(this, false, \'discipline\', \'discipline\', \'trinbdisci\'); return false;" style="font-size:16px; text-decoration: none;"><span class="glyphicon glyphicon-sort-by-order"></span></a>';
180 $content .= '</span>';
181 $content .= '</li>';
182 $content .= '<div id="discipline">';
183 foreach ($facetdomain as $res){
184 $name = explode(delimiter,$res[0]);
185 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=domainAllCode_s:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">'.$name[1].'</a><span class="badge badge-default">' .$res[1]. '</span></li>';
186 }
187 $content .= '</div>';
188 $content .= '</ul>';
189 $content .= '</div>';
190
191 $content .= '<div id="graph" style="display:none;">';
192 $content .= '<div id="toto"></div>';
193 $content .= '</div>';
194 $content .= '<a class="btn btn-default btn-sm" href="" style="text-decoration: none;" id="disci" onclick="javascript:visibilitedisci(\'listdisci\',\'graph\',\'tridisciplines\'); return false;" >' . __('Graphique','wp-hal'); $content .= '</a> ';
195 }
196 $content .= '</div>
197 <div class="tab-pane" id="keywords">
198 <h3>' . __('Mots-clefs','wp-hal').'</h3>';
199 if(!is_null($json->facet_counts->facet_fields->keyword_s) && !empty($json->facet_counts->facet_fields->keyword_s)){
200 $content .= '<div id="keys">';
201 $r = 0;
202 // CSS Nuage de mots
203 $maxsize=25;
204 $minsize=10;
205 $maxval=max(array_values($json->facet_counts->facet_fields->keyword_s[1]));
206 $minval=min(array_values($json->facet_counts->facet_fields->keyword_s[1]));
207 $spread=($maxval-$minval);
208 $step=($maxsize-$minsize)/$spread;
209 $tab = array();
210 foreach ($json->facet_counts->facet_fields->keyword_s as $res){
211 $r = $r+1;
212 if ($r > 20){
213 break;
214 }
215 $tab[] = $res;
216 }
217 asort($tab); // Tri du tableau par ordre alphabétique
218 foreach ($tab as $res){
219 $size= round($minsize + (($res[1]- $minval)*$step));
220 $content .= '<a style="display: inline-block; font-size:'.$size.'px" href="'. halv3 .'?q=keyword_s:' . urlencode('"'.$res[0].'"') . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $res[0] . '</a>&nbsp;';
221 }
222 $content .= '</div>';
223 $content .= '<div id="keysuite" style="display:none;">';
224 $content .= '<ul class="keyword list-group">';
225 $content .= '<li class="list-group-item">';
226 $content .= '<span id="trikeywords">';
227 $content .= '<a class="btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri Alphabétique" href="" id="trikey" onclick="javascript:toggleSort(this, true, \'keyw\', \'keyword\', \'trikey\'); return false;" style="font-size:16px; text-decoration: none;" ><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>';
228 $content .= '<a class="pull-right btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri par Nombre d\'Occurences" href="" id="trinbkey" onclick="javascript:toggleSort(this, false, \'keyw\', \'keyword\', \'trinbkey\'); return false;" style="font-size:16px; text-decoration: none;"><span class="glyphicon glyphicon-sort-by-order"></span></a>';
229 $content .= '</span>';
230 $content .= '</li>';
231 $content .= '<div id="keyw">';
232 foreach ($json->facet_counts->facet_fields->keyword_s as $res){
233 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=keyword_s:'.urlencode('"'.$res[0].'"'). "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $res[0] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
234 }
235 $content .= '</div>';
236 $content .= '</ul>';
237 $content .= '</div>';
238 $content .= '<a class="btn btn-default btn-sm" href="" style="text-decoration: none;" id="key" onclick="javascript:visibilitekey(\'keys\',\'keysuite\', \'trikeywords\'); return false;" >' . __('Liste complète','wp-hal'); $content .= '</a> ';
239 }
240 $content .= '</div>
241 <div class="tab-pane" id="auteurs">
242 <h3>' . __('Auteurs','wp-hal').'</h3>';
243 if(!is_null($json->facet_counts->facet_fields->authIdLastNameFirstName_fs) && !empty($json->facet_counts->facet_fields->authIdLastNameFirstName_fs)){
244 $content .= '<ul class="auteurs list-group" style="list-style-type: none;">';
245 $content .= '<li class="list-group-item">';
246 $content .= '<span id="triauteurs">';
247 $content .= '<a class="btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri Alphabétique" href="" id="triaut" onclick="javascript:toggleSort(this, true, \'aut\', \'auteursuite\', \'triaut\'); return false;" style="font-size:16px; text-decoration: none;" ><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>';
248 $content .= '<a class="pull-right btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri par Nombre d\'Occurences" href="" id="trinbaut" onclick="javascript:toggleSort(this, false, \'aut\', \'auteursuite\', \'trinbaut\'); return false;" style="font-size:16px; text-decoration: none;"><span class="glyphicon glyphicon-sort-by-order"></span></a>';
249 $content .= '</span>';
250 $content .= '</li>';
251 $content .= '<div id="aut">';
252 $r = 0;
253 foreach ($json->facet_counts->facet_fields->authIdLastNameFirstName_fs as $res){
254 $r = $r+1;
255 if ($r > 10){
256 break;
257 }
258 $name = explode(delimiter,$res[0]);
259 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><img alt="user" src=" ' . plugin_dir_url( __FILE__ ) . '/img/user.svg" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="'. halv3 .'?q=authId_i:' . $name[0] . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
260 }
261 $i = 1;
262 $content .= '<div id="auteursuite" style="display:none;">';
263 foreach ($json->facet_counts->facet_fields->authIdLastNameFirstName_fs as $res){
264 if($r < 10){
265 break;
266 }
267 if ($i < $r){
268 $i = $i+1;
269 } else {
270 $name = explode(delimiter,$res[0]);
271 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><img alt="user" src=" ' . plugin_dir_url( __FILE__ ) . '/img/user.svg" style="width:16px; margin-left:2px; margin-right:2px;"/><a href="'. halv3 .'?q=authId_i:' . $name[0] . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
272 }
273 }
274 $content .= '</div>';
275 $content .= '</div>';
276 $content .= '</ul>';
277 if ($r > 10){
278 $content .= '<a class="btn btn-default btn-sm" href="" style="text-decoration: none;" id="auteur" onclick="javascript:visibilite(\'auteursuite\'); return false;" >' . __('Liste complète','wp-hal'); $content .= '</a> ';
279 }
280 }
281 $content .= '</div>
282 <div class="tab-pane" id="revues">
283 <h3>' . __('Revues','wp-hal').'</h3>';
284 if(!is_null($json->facet_counts->facet_fields->journalIdTitle_fs) && !empty($json->facet_counts->facet_fields->journalIdTitle_fs)){
285 $content .= '<ul class="revues list-group">';
286 $content .= '<li class="list-group-item">';
287 $content .= '<span id="trirevues">';
288 $content .= '<a class="btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri Alphabétique" href="" id="trirev" onclick="javascript:toggleSort(this, true, \'rev\', \'revuesuite\', \'trirev\'); return false;" style="font-size:16px; text-decoration: none;" ><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>';
289 $content .= '<a class="pull-right btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri par Nombre d\'Occurences" href="" id="trinbrev" onclick="javascript:toggleSort(this, false, \'rev\', \'revuesuite\', \'trinbrev\'); return false;" style="font-size:16px; text-decoration: none;"><span class="glyphicon glyphicon-sort-by-order"></span></a>';
290 $content .= '</span>';
291 $content .= '</li>';
292 $content .= '<div id="rev">';
293 $r = 0;
294 foreach ($json->facet_counts->facet_fields->journalIdTitle_fs as $res){
295 $r = $r+1;
296 if ($r > 10){
297 break;
298 }
299 $name = explode(delimiter,$res[0]);
300 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=journalId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
301 }
302 $i = 1;
303 $content .= '<div id="revuesuite" style="display:none;">';
304 foreach ($json->facet_counts->facet_fields->journalIdTitle_fs as $res){
305 if($r < 10){
306 break;
307 }
308 if ($i < $r){
309 $i = $i+1;
310 } else {
311 $name = explode(delimiter,$res[0]);
312 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=journalId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
313 }
314 }
315 $content .= '</div>';
316 $content .= '</div>';
317 $content .= '</ul>';
318 if ($r > 10){
319 $content .= '<a class="btn btn-default btn-sm" href="" style="text-decoration: none;" id="revue" onclick="javascript:visibiliterevues(\'revuesuite\'); return false;" >' . __('Liste complète','wp-hal'); $content .= '</a> ';
320 }
321 }
322 $content .= '</div>
323 <div class="tab-pane" id="annees">
324 <h3>' . __('Année de production','wp-hal').'</h3>';
325 if(!is_null($json->facet_counts->facet_fields->producedDateY_i) && !empty($json->facet_counts->facet_fields->producedDateY_i)){
326 $content .= '<ul class="annees list-group">';
327 $content .= '<li class="list-group-item">';
328 $content .= '<span id="triannees">';
329 $content .= '<a class="btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri Chronologique" href="" id="trian" onclick="javascript:toggleSort(this, true, \'an\', \'annees\', \'trian\'); return false;" style="font-size:16px; text-decoration: none;" ><span class="glyphicon glyphicon-sort-by-order"></span></a>';
330 $content .= '<a class="pull-right btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri par Nombre d\'Occurences" href="" id="trinban" onclick="javascript:toggleSort(this, false, \'an\', \'annees\', \'trinban\'); return false;" style="font-size:16px; text-decoration: none;"><span class="glyphicon glyphicon-sort-by-order"></span></a>';
331 $content .= '</span>';
332 $content .= '</li>';
333 $content .= '<div id="an">';
334
335 rsort($json->facet_counts->facet_fields->producedDateY_i);
336 $r = 0;
337 foreach ($json->facet_counts->facet_fields->producedDateY_i as $res){
338 $r = $r+1;
339 if ($r > 10){
340 break;
341 }
342 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=producedDateY_i:' . urlencode($res[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $res[0] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
343 }
344 $i = 1;
345 $content .= '<div id="anneesuite" style="display:none;">';
346 foreach ($json->facet_counts->facet_fields->producedDateY_i as $res){
347 if($r < 10){
348 break;
349 }
350 if ($i < $r){
351 $i = $i+1;
352 } else {
353 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=producedDateY_i:' . urlencode($res[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $res[0] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
354 }
355 }
356 $content .= '</div>';
357 $content .= '</div>';
358 $content .= '</ul>';
359 if ($r > 10){
360 $content .= '<a class="btn btn-default btn-sm" href="" style="text-decoration: none;" id="annee" onclick="javascript:visibiliteannee(\'anneesuite\'); return false;" >' . __('Liste complète','wp-hal'); $content .= '</a> ';
361 }
362 }
363 $content .= '</div>
364 <div class="tab-pane" id="insts">
365 <h3>' . __('Institutions','wp-hal').'</h3>';
366 if(!is_null($json->facet_counts->facet_fields->instStructIdName_fs) && !empty($json->facet_counts->facet_fields->instStructIdName_fs)){
367 $content .= '<ul class="insts list-group">';
368 $content .= '<li class="list-group-item">';
369 $content .= '<span id="triinsts">';
370 $content .= '<a class="btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri Alphabétique" href="" id="triinst" onclick="javascript:toggleSort(this, true, \'institu\', \'instsuite\', \'triinst\'); return false;" style="font-size:16px; text-decoration: none;" ><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>';
371 $content .= '<a class="pull-right btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri par Nombre d\'Occurences" href="" id="trinbinst" onclick="javascript:toggleSort(this, false, \'institu\', \'instsuite\', \'trinbinst\'); return false;" style="font-size:16px; text-decoration: none;"><span class="glyphicon glyphicon-sort-by-order"></span></a>';
372 $content .= '</span>';
373 $content .= '</li>';
374 $content .= '<div id="institu">';
375 $r = 0;
376 foreach ($json->facet_counts->facet_fields->instStructIdName_fs as $res){
377 $r = $r+1;
378 if ($r > 10){
379 break;
380 }
381 $name = explode(delimiter,$res[0]);
382 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=instStructId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
383 }
384 $i = 1;
385 $content .= '<div id="instsuite" style="display:none;">';
386 foreach ($json->facet_counts->facet_fields->instStructIdName_fs as $res){
387 if($r < 10){
388 break;
389 }
390 if ($i < $r){
391 $i = $i+1;
392 } else {
393 $name = explode(delimiter,$res[0]);
394 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=instStructId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
395 }
396 }
397 $content .= '</div>';
398 $content .= '</div>';
399 $content .= '</ul>';
400 if ($r > 10){
401 $content .= '<a class="btn btn-default btn-sm" href="" style="text-decoration: none;" id="inst" onclick="javascript:visibiliteinst(\'instsuite\'); return false;" >' . __('Liste complète','wp-hal'); $content .= '</a> ';
402 }
403 }
404 $content .= '</div>
405 <div class="tab-pane" id="labs">
406 <h3>' . __('Laboratoires','wp-hal').'</h3>';
407 if(!is_null($json->facet_counts->facet_fields->labStructIdName_fs) && !empty($json->facet_counts->facet_fields->labStructIdName_fs)){
408 $content .= '<ul class="labs list-group">';
409 $content .= '<li class="list-group-item">';
410 $content .= '<span id="trilabs">';
411 $content .= '<a class="btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri Alphabétique" href="" id="trilab" onclick="javascript:toggleSort(this, true, \'labo\', \'labsuite\', \'trilab\'); return false;" style="font-size:16px; text-decoration: none;" ><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>';
412 $content .= '<a class="pull-right btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri par Nombre d\'Occurences" href="" id="trinblab" onclick="javascript:toggleSort(this, false, \'labo\', \'labsuite\', \'trinblab\'); return false;" style="font-size:16px; text-decoration: none;"><span class="glyphicon glyphicon-sort-by-order"></span></a>';
413 $content .= '</span>';
414 $content .= '</li>';
415 $content .= '<div id="labo">';
416
417 $r = 0;
418 foreach ($json->facet_counts->facet_fields->labStructIdName_fs as $res){
419 $r = $r+1;
420 if ($r > 10){
421 break;
422 }
423 $name = explode(delimiter,$res[0]);
424 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=labStructId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
425 }
426 $i = 1;
427 $content .= '<div id="labsuite" style="display:none;">';
428 foreach ($json->facet_counts->facet_fields->labStructIdName_fs as $res){
429 if($r < 10){
430 break;
431 }
432 if ($i < $r){
433 $i = $i+1;
434 } else {
435 $name = explode(delimiter,$res[0]);
436 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=labStructId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
437 }
438 }
439 $content .= '</div>';
440 $content .= '</div>';
441 $content .= '</ul>';
442 if ($r > 10){
443 $content .= '<a class="btn btn-default btn-sm" href="" style="text-decoration: none;" id="lab" onclick="javascript:visibilitelab(\'labsuite\'); return false;" >' . __('Liste complète','wp-hal'); $content .= '</a> ';
444 }
445 }
446 $content .= '</div>
447 <div class="tab-pane" id="depts">
448 <h3>' . __('Départements','wp-hal').'</h3>';
449 if(!is_null($json->facet_counts->facet_fields->deptStructIdName_fs) && !empty($json->facet_counts->facet_fields->deptStructIdName_fs)){
450 $content .= '<ul class="depts list-group">';
451 $content .= '<li class="list-group-item">';
452 $content .= '<span id="tridept">';
453 $content .= '<a class="btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri Alphabétique" href="" id="tridept" onclick="javascript:toggleSort(this, true, \'dpt\', \'deptsuite\', \'tridept\'); return false;" style="font-size:16px; text-decoration: none;" ><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>';
454 $content .= '<a class="pull-right btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri par Nombre d\'Occurences" href="" id="trinbdept" onclick="javascript:toggleSort(this, false, \'dpt\', \'deptsuite\', \'trinbdept\'); return false;" style="font-size:16px; text-decoration: none;"><span class="glyphicon glyphicon-sort-by-order"></span></a>';
455 $content .= '</span>';
456 $content .= '</li>';
457 $content .= '<div id="dpt">';
458 $r = 0;
459 foreach ($json->facet_counts->facet_fields->deptStructIdName_fs as $res){
460 $r = $r+1;
461 if ($r > 10){
462 break;
463 }
464 $name = explode(delimiter,$res[0]);
465 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=deptStructId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
466 }
467 $i = 1;
468 $content .= '<div id="deptsuite" style="display:none;">';
469 foreach ($json->facet_counts->facet_fields->deptStructIdName_fs as $res){
470 if($r < 10){
471 break;
472 }
473 if ($i < $r){
474 $i = $i+1;
475 } else {
476 $name = explode(delimiter,$res[0]);
477 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=deptStructId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
478 }
479 }
480 $content .= '</div>';
481 $content .= '</div>';
482 $content .= '</ul>';
483 if ($r > 10){
484 $content .= '<a class="btn btn-default btn-sm" href="" style="text-decoration: none;" id="dept" onclick="javascript:visibilitedept(\'deptsuite\'); return false;" >' . __('Liste complète','wp-hal'); $content .= '</a> ';
485 }
486 }
487 $content .= '</div>
488 <div class="tab-pane" id="equipes">
489 <h3>' . __('Équipes de recherche','wp-hal').'</h3>';
490 if(!is_null($json->facet_counts->facet_fields->rteamStructIdName_fs) && !empty($json->facet_counts->facet_fields->rteamStructIdName_fs)){
491 $content .= '<ul class="equipes list-group">';
492 $content .= '<li class="list-group-item">';
493 $content .= '<span id="triequipe">';
494 $content .= '<a class="btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri Alphabétique" href="" id="triequipe" onclick="javascript:toggleSort(this, true, \'rteam\', \'equipesuite\', \'triequipe\'); return false;" style="font-size:16px;text-decoration: none;" ><span class="glyphicon glyphicon-sort-by-alphabet"></span></a>';
495 $content .= '<a class="pull-right btn btn-default btn-xs" data-placement="bottom" data-toggle="tooltip" data-original-title="Tri par Nombre d\'Occurences" href="" id="trinbequipe" onclick="javascript:toggleSort(this, false, \'rteam\', \'equipesuite\', \'trinbequipe\'); return false;" style="font-size:16px; text-decoration: none;"><span class="glyphicon glyphicon-sort-by-order"></span></a>';
496 $content .= '</span>';
497 $content .= '</li>';
498 $content .= '<div id="rteam">';
499
500 $r = 0;
501 foreach ($json->facet_counts->facet_fields->rteamStructIdName_fs as $res){
502 $r = $r+1;
503 if ($r > 10){
504 break;
505 }
506 $name = explode(delimiter,$res[0]);
507 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=rteamStructId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
508 }
509 $i = 1;
510 $content .= '<div id="equipesuite" style="display:none;">';
511 foreach ($json->facet_counts->facet_fields->rteamStructIdName_fs as $res){
512 if($r < 10){
513 break;
514 }
515 if ($i < $r){
516 $i = $i+1;
517 } else {
518 $content .= '<li class="test list-group-item" data-percentage="'.$res[1].'"><a href="'. halv3 .'?q=rteamStructId_i:' . urlencode($name[0]) . "+AND+" .get_option('option_type').':'.get_option('option_idhal').'" target="_blank">' . $name[1] . '</a><span class="badge badge-default">' .$res[1]. '</span></li>';
519 }
520 }
521 $content .= '</div>';
522 $content .= '</div>';
523 $content .= '</ul>';
524 if ($r > 10){
525 $content .= '<a class="btn btn-default btn-sm" href="" style="text-decoration: none;" id="equipe" onclick="javascript:visibiliteequipe(\'equipesuite\'); return false;" >' . __('Liste complète','wp-hal'); $content .= '</a> ';
526 }
527 }
528 $content .= '</div>
529 <div class="tab-pane active" id="publications">
530 <h3>' . __('Publications','wp-hal'); $content .= '</h3>';
531
532 if (get_option('option_groupe')=='grouper'){
533
534 //LISTE DES DOCUMENTS PAR GROUPE
535
536 $content .= '<div class="counter-doc">
537 ' . __('Nombre de documents', 'wp-hal') . '
538 <h2 class="nbdoc"><span class="label label-primary">' . $json->grouped->docType_s->matches . '</span></h2><br/>
539 </div>';
540
541 $content .= '<ul style="list-style-type: none;">';
542 for($i=0; $json->grouped->docType_s->groups[$i] != null ; $i++){
543 for($d=0; $jsontype->response->result->doc[$d] != null; $d++ ){
544 if ($json->grouped->docType_s->groups[$i]->groupValue == $jsontype->response->result->doc[$d]->str[0]){
545 $titre=$jsontype->response->result->doc[$d]->str[1];
546 }
547 }
548 $content .= '<li><div class="doc-group"><h3 class="doc-header">' . $titre . '<small class="doc-nb">' . $json->grouped->docType_s->groups[$i]->doclist->numFound .' ' . _n('document','documents',$json->grouped->docType_s->groups[$i]->doclist->numFound,'wp-hal') .'</small></h3>';
549 $content .= '<div class="doc-content">';
550 $content .= '<ul>';
551 foreach ($json->grouped->docType_s->groups[$i]->doclist->docs as $result){
552 $content .= '<li>' . $result->citationFull_s . '</li>';
553 }
554 $content .= '</ul></div>';
555 $content .= '</div></li>';
556 }
557 $content .= '</ul>';
558 } elseif(get_option('option_groupe')=='paginer'){
559
560 //LISTE DES DOCUMENTS AVEC PAGINATION
561
562 $content .= '<div class="counter-doc">
563 ' . __('Nombre de documents', 'wp-hal');
564 $content .='<h2 class="nbdoc"><span class="label label-primary">' . $json->response->numFound . '</span></h2><br/>
565 </div>';
566
567 //--MODULE PAGINATION--//
568 $messagesParPage = 10;
569
570 $total = $json->response->numFound;
571
572 $nombreDePages = ceil($total / $messagesParPage);
573
574 if (isset($paged)) {
575 $pageActuelle = intval($paged);
576
577 if ($pageActuelle > $nombreDePages) {
578 $pageActuelle = $nombreDePages;
579 }
580 } else {
581 $pageActuelle = 1;
582 }
583 $premiereEntree = ($pageActuelle - 1) * $messagesParPage;
584
585 $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';
586 $ch = curl_init($url);
587 // Options
588 $options = array(
589 CURLOPT_RETURNTRANSFER => true,
590 CURLOPT_HTTPHEADER => array('Content-type: application/json'),
591 CURLOPT_TIMEOUT => 10,
592 );
593
594 // Bind des options et de l'objet cURL que l'on va utiliser
595 curl_setopt_array($ch, $options);
596 // Récupération du résultat JSON
597 $json = json_decode(curl_exec($ch));
598 curl_close($ch);
599
600
601 //--MODULE PAGINATION--//
602
603 $content .= '<ul>';
604 for ($i = 0; $json->response->docs[$i]!= ''; $i++){
605 $content .= '<li>' . $json->response->docs[$i]->citationFull_s . '</li>';
606 }
607 $content .= '</ul>';
608
609 //--AFFICHAGE PAGINATION--//
610 $precedents=$pageActuelle-2;
611 $suivants= $pageActuelle+2;
612 $precedent=$pageActuelle-1;
613 $suivant= $pageActuelle+1;
614 $penultimate = $nombreDePages - 1;
615
616 $content .= '<div class="pagination_module">';
617 $content .= '<ul class="pagination">';
618 //--BOUTON PRECEDENT--//
619 if($pageActuelle == 1){
620 $content .= '<li class="disabled"><a href="#">&laquo;</a></li>';
621 }
622 else{
623 $content .= '<li><a href="?paged='.$precedent.'">&laquo;</a></li>';
624 }
625 if($nombreDePages <= 6){// Cas 1 : 6 pages ou moins - Pas de troncature
626 for ($i = 1; $i <= $nombreDePages; $i++) {
627 if ($i == $pageActuelle) {
628 $content .= '<li class="active"><a href="#">'.$i.'</a></li>';
629 }
630 else {
631 $content .= ' <li><a href="?paged='.$i.'">' . $i . '</a></li> ';
632 }
633 }
634 }
635 elseif($nombreDePages >= 7){// Cas 2 : 7 pages ou plus - Troncature
636 if($pageActuelle <= 3){// Lorsque l'on est sur les trois premières pages
637 for($i = 1; $i <= 4; $i++){
638 if ($i == $pageActuelle) {
639 $content .= '<li class="active"><a href="#">'.$i.'</a></li>';
640 }
641 else {
642 $content .= '<li><a href="?paged='.$i.'">'.$i.'</a></li>';
643 }
644 }
645 $content .= '<li class="disabled"><a href="#">&hellip;</a></li>';
646 $content .= '<li><a href="?paged='.$penultimate.'">'.$penultimate.'</a></li>';
647 $content .= '<li><a href="?paged='.$nombreDePages.'">'.$nombreDePages.'</a></li>';
648 }
649 if($pageActuelle >=4 && $pageActuelle <= $penultimate-2){//Lorsque l'on arrive sur la quatrième page
650 $content .= '<li><a href="?paged=">1</a></li>';
651 $content .= '<li class="disabled"><a href="#">&hellip;</a></li>';
652 $content .= '<li><a href="?paged='.$precedents.'">'.$precedents.'</a></li>';
653 $content .= '<li><a href="?paged='.$precedent.'">'.$precedent.'</a></li>';
654 $content .= '<li class="active"><a href="#">'.$pageActuelle.'</a></li>';
655 $content .= '<li><a href="?paged='.$suivant.'">'.$suivant.'</a></li>';
656 $content .= '<li><a href="?paged='.$suivants.'">'.$suivants.'</a></li>';
657 $content .= '<li class="disabled"><a href="#">&hellip;</a></li>';
658 $content .= '<li><a href="?paged='.$nombreDePages.'">'.$nombreDePages.'</a></li>';
659 }
660 if($pageActuelle >= $penultimate-1){
661 $content .= '<li><a href="?paged=1">1</a></li>';
662 $content .= '<li><a href="?paged=2">2</a></li>';
663 $content .= '<li class="disabled"><a href="#">&hellip;</a></li>';
664 for($i = $penultimate-2; $i <= $nombreDePages; $i++){
665 if ($i == $pageActuelle) {
666 $content .= '<li class="active"><a href="#">'.$i.'</a></li>';
667 }
668 else {
669 $content .= '<li><a href="?paged='.$i.'">'.$i.'</a></li>';
670 }
671 }
672 }
673 }
674 //--BOUTON SUIVANT--//
675 if($pageActuelle<$nombreDePages){
676 $content .= '<li><a href="?paged='.$suivant.'">&raquo;</a></li>';
677 }
678 else{
679 $content .= '<li class="disabled"><a href="#">&raquo;</a></li>';
680 }
681 $content .= '</ul>';
682 $content .= '</div>';
683 //--AFFICHAGE PAGINATION--//
684 }
685 $content .='</div>
686 </div>
687 </div>';
688
689 $content .= '<div class="modal-footer">';
690 $content .= '<p style="color:#B3B2B0">' . __("Documents récupérés de l'archive ouverte HAL",'wp-hal') . '&nbsp;<a href="' . site . '" target="_blank"><img alt="logo" src=" ' . plugin_dir_url( __FILE__ ) . 'img/logo-hal.svg" style="width:32px;"></a></p>';
691 $content .= '</div>';
692
693 return $content;
694 }
695
696 function wp_adding_style() {
697 wp_register_style('wp-hal-style1', plugins_url('/css/bootstrap.css', __FILE__));
698 wp_register_style('wp-hal-style2', plugins_url('/css/style.css', __FILE__));
699 wp_register_style('wp-hal-style3', plugins_url('/css/jquery.jqplot.css', __FILE__));
700
701 wp_enqueue_style('wp-hal-style1');
702 wp_enqueue_style('wp-hal-style2');
703 wp_enqueue_style('wp-hal-style3');
704 }
705
706 function wp_adding_script() {
707 wp_register_script('wp-hal-script1', plugins_url('/js/bootstrap.js', __FILE__));
708 wp_register_script('wp-hal-script2',plugins_url('/js/highcharts.js', __FILE__));
709 wp_register_script('wp-hal-script3',plugins_url('/js/jquery.jqplot.js', __FILE__));
710 wp_register_script('wp-hal-script4',plugins_url('/js/jqplot.pieRenderer.js', __FILE__));
711 wp_register_script('wp-hal-script5',plugins_url('/js/cv-hal.js', __FILE__));
712
713 wp_enqueue_script("jquery");
714 wp_enqueue_script('wp-hal-script1');
715 wp_enqueue_script('wp-hal-script2');
716 wp_enqueue_script('wp-hal-script3');
717 wp_enqueue_script('wp-hal-script4');
718 wp_enqueue_script('wp-hal-script5');
719
720
721 $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';
722 $ch = curl_init($url);
723 // Options
724 $options = array(
725 CURLOPT_RETURNTRANSFER => true,
726 CURLOPT_HTTPHEADER => array('Content-type: application/json'),
727 CURLOPT_TIMEOUT => 10,
728 );
729
730 // Bind des options et de l'objet cURL que l'on va utiliser
731 curl_setopt_array($ch, $options);
732 // Récupération du résultat JSON
733 $json = json_decode(curl_exec($ch));
734 curl_close($ch);
735 if (locale == 'fr_FR') {
736 $facetdomain = $json->facet_counts->facet_fields->fr_domainAllCodeLabel_fs;
737 } elseif (locale == 'en_US') {
738 $facetdomain = $json->facet_counts->facet_fields->en_domainAllCodeLabel_fs;
739 } elseif (locale == 'es_ES') {
740 $facetdomain = $json->facet_counts->facet_fields->es_domainAllCodeLabel_fs;
741 } else {
742 $facetdomain = $json->facet_counts->facet_fields->eu_domainAllCodeLabel_fs;
743 }
744 if(!is_null($facetdomain)){
745 foreach ($facetdomain as $res){
746 $name = explode(delimiter,$res[0])[1];
747 $value = $res[1];
748 $array[] = array($name,$value);
749 }
750 }
751 wp_localize_script('wp-hal-script5', 'WPWallSettings', json_encode($array));
752 $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'));
753 wp_localize_script('wp-hal-script5', 'translate', $translation);
754 }
755
756 /**
757 * Récupère les fichiers css et js
758 */
759 add_action( 'wp_enqueue_scripts', 'wp_adding_style' );
760 add_action( 'wp_enqueue_scripts', 'wp_adding_script' );
761
762 /**
763 * Charge lorsque le plugin est désactivé
764 */
765 register_deactivation_hook( __FILE__, 'reset_option' );
766
767 /**
768 * Ajoute le widget wphal à l'initialisation des widgets
769 */
770 add_action('widgets_init','wphal_init');
771
772 /**
773 * Ajoute le menu à l'initialisation du menu admin
774 */
775 add_action( 'admin_menu', 'wphal_menu' );
776
777 /**
778 * Fonction de création du menu
779 */
780 function wphal_menu() {
781 add_menu_page( 'Options', 'Hal', 'manage_options', 'wp-hal.php', 'wphal_option' , '', 21);
782
783 add_action( 'admin_init', 'register_settings' );
784 }
785
786
787 /**
788 * Initialise le nouveau widget
789 */
790 function wphal_init(){
791 register_widget("wphal_widget");
792 }
793
794 /***********************************************************************************************************************
795 * PLUGIN WIDGET
796 **********************************************************************************************************************/
797
798 /**
799 * Classe du widget wphal
800 */
801
802 class wphal_widget extends WP_widget{
803
804
805 /**
806 * Défini les propriétés du widget
807 */
808 function wphal_widget(){
809 $options = array(
810 "classname" => "wphal-publications",
811 "description" => __("Afficher les dernières publications d'un auteur ou d'une structure.", 'wp-hal')
812 );
813
814 $this->WP_widget("hal-publications", __("Publications récentes", 'wp-hal'), $options);
815 }
816
817 /**
818 * Crée le widget
819 * @param $args
820 * @param $instance
821 */
822 function widget($args, $instance){
823 $num = 5;
824 $url = api .'?q=*:*&fq='.$instance['select'].':' . $instance['idhal'] . '&fl=uri_s,title_s&sort=' . producedDateY . '&rows=' . $num . '&wt=json';
825
826 $ch = curl_init($url);
827 // Options
828 $options = array(
829 CURLOPT_RETURNTRANSFER => true,
830 CURLOPT_HTTPHEADER => array('Content-type: application/json'),
831 CURLOPT_TIMEOUT => 10,
832 );
833
834 // Bind des options et de l'objet cURL que l'on va utiliser
835 curl_setopt_array($ch, $options);
836 // Récupération du résultat JSON
837 $json = json_decode(curl_exec($ch));
838 curl_close($ch);
839
840 $content = '<ul>';
841 for ($i = 0; $i < $num; $i++){
842 $content .= '<li><a href="' . $json->response->docs[$i]->uri_s . '" target="_blank">' . $json->response->docs[$i]->title_s[0] . '</a></li>';
843 }
844 $content .= '</ul>';
845
846 extract($args);
847 echo $before_widget;
848 echo $before_title.$instance['titre'].$after_title;
849 echo $content;
850 echo $after_widget;
851 }
852
853 /**
854 * Sauvegarde des données
855 * @param $new
856 * @param $old
857 */
858 function update($new, $old){
859 return $new;
860 }
861
862 /**
863 * Formulaire du widget
864 * @param $instance
865 */
866 function form($instance){
867
868 $defaut = array(
869 'titre' => __("Publications récentes", 'wp-hal'),
870 'select' => "authIdHal_s"
871 );
872 $instance = wp_parse_args($instance,$defaut);
873 ?>
874 <p>
875 <label for="<?php echo $this->get_field_id("titre");?>"><?php echo __('Titre :','wp-hal')?></label>
876 <input value="<?php echo $instance['titre'];?>" name="<?php echo $this->get_field_name("titre");?>" id="<?php echo $this->get_field_id("titre");?>" class="widefat" type="text"/>
877 </p>
878 <p>
879 <select id="<?php echo $this->get_field_id("select");?>" name="<?php echo $this->get_field_name("select");?>">
880 <option id="<?php echo $this->get_field_id("Idhal");?>" value="authIdHal_s" <?php echo ($instance["select"] == "authIdHal_s")?'selected':''; ?>><label for="<?php echo $this->get_field_id("Idhal");?>">Id Hal</label><span style="font-style: italic;"> <?php echo __('(Exemple : laurent-capelli)','wp-hal');?></span></option>
881 <option id="<?php echo $this->get_field_id("Structid");?>" value="authStructId_i" <?php echo ($instance["select"] == "authStructId_i")?'selected':''; ?>><label for="<?php echo $this->get_field_id("Structid");?>">Struct Id</label><span style="font-style: italic;"> <?php echo __('(Exemple : 129)','wp-hal');?></span></option>
882 <option id="<?php echo $this->get_field_id("Anrproject");?>" value="anrProjectId_i" <?php echo ($instance["select"] == "anrProjectId_i")?'selected':''; ?>><label for="<?php echo $this->get_field_id("Anrproject");?>">anrProject Id</label><span style="font-style: italic;"> <?php echo __('(Exemple : 1646)','wp-hal');?></span></option>
883 <option id="<?php echo $this->get_field_id("Europeanproject");?>" value="europeanProjectId_i" <?php echo ($instance["select"] == "europeanProjectId_i")?'selected':''; ?>><label for="<?php echo $this->get_field_id("Europeanproject");?>">europeanProject Id</label><span style="font-style: italic;"> <?php echo __('(Exemple : 17877)','wp-hal');?></span></option>
884 <option id="<?php echo $this->get_field_id("Collection");?>" value="collCode_s" <?php echo ($instance["select"] == "collCode_s")?'selected':''; ?>><label for="<?php echo $this->get_field_id("Collection");?>">Collection</label><span style="font-style: italic;"> <?php echo __('(Exemple : TICE2014)','wp-hal');?></span></option>
885 </select>
886 </p>
887 <p>
888 <label for="<?php echo $this->get_field_id("idhal");?>">Id :</label>
889 <input value="<?php echo $instance['idhal'];?>" name="<?php echo $this->get_field_name("idhal");?>" id="<?php echo $this->get_field_id("idhal");?>" class="widefat" type="text"/>
890 </p>
891 <?php
892 }
893 }
894
895
896 function register_settings() {
897 register_setting( 'wphal_option', 'option_choix' );
898 register_setting( 'wphal_option', 'option_type' );
899 register_setting( 'wphal_option', 'option_groupe' );
900 register_setting( 'wphal_option', 'option_idhal' );
901 register_setting( 'wphal_option', 'option_lang' );
902 register_setting( 'wphal_option', 'option_email' );
903 register_setting( 'wphal_option', 'option_tel' );
904 register_setting( 'wphal_option', 'option_social0' );
905 register_setting( 'wphal_option', 'option_social1' );
906 register_setting( 'wphal_option', 'option_social2' );
907 register_setting( 'wphal_option', 'option_social3' );
908 }
909
910 /**
911 * Crée le menu d'option du plugin
912 */
913 function wphal_option() {
914
915 if (get_option('option_type')==''){
916 update_option('option_type', 'authIdHal_s');
917 }
918 if (get_option('option_groupe')==''){
919 update_option('option_groupe', 'paginer');
920 }
921 ?>
922 <div class="wrap">
923 <h2><?php echo __('Plugin HAL','wp-hal');?></h2>
924 <form method="post" enctype="multipart/form-data" action="options.php">
925 <div id="poststuff">
926 <div id="post-body" class="metabox-holder columns-2">
927 <div id="post-body-content">
928 <?php settings_fields( 'wphal_option' ); ?>
929 <?php do_settings_sections( 'wphal_option' ); ?>
930 <table class="form-table">
931 <tr valign="top">
932 <th scope="row" style="font-size: 18px;"><?php echo __('Paramètre de la page :','wp-hal');?></th>
933 </tr>
934 <tr valign="top">
935 <th scope="row"><?php echo __('Type d\'Id','wp-hal');?></th>
936 <td><select name="option_type">
937 <option id="Idhal" value="authIdHal_s" <?php echo (get_option('option_type') == "authIdHal_s")?'selected':''; ?>><label for="Idhal">Id Hal</label><span style="font-style: italic;"> <?php echo __('(Exemple : laurent-capelli)','wp-hal');?></span></option>
938 <option id="Structid" value="authStructId_i" <?php echo (get_option('option_type') == "authStructId_i")?'selected':''; ?>><label for="Structid">Struct Id</label><span style="font-style: italic;"> <?php echo __('(Exemple : 129)','wp-hal');?></span></option>
939 <option id="Anrproject" value="anrProjectId_i" <?php echo (get_option('option_type') == "anrProjectId_i")?'selected':''; ?>><label for="Anrproject">anrProject Id</label><span style="font-style: italic;"> <?php echo __('(Exemple : 1646)','wp-hal');?></span></option>
940 <option id="Europeanproject" value="europeanProjectId_i" <?php echo (get_option('option_type') == "europeanProjectId_i")?'selected':''; ?>><label for="Europeanproject">europeanProject Id</label><span style="font-style: italic;"> <?php echo __('(Exemple : 17877)','wp-hal');?></span></option>
941 <option id="Collection" value="collCode_s" <?php echo (get_option('option_type') == "collCode_s")?'selected':''; ?>><label for="Collection">Collection</label><span style="font-style: italic;"> <?php echo __('(Exemple : TICE2014)','wp-hal');?></span></option>
942 </select>
943 <input type="text" name="option_idhal" id="option_idhal" value="<?php echo get_option('option_idhal'); ?>"/>
944 </td>
945 </tr>
946 <tr valign="top">
947 <th scope="row"><?php echo __('Affichage des documents','wp-hal');?></th>
948 <td><input type="radio" name="option_groupe" id="paginer" value="paginer" <?php echo (get_option('option_groupe') == "paginer")?'checked':''; ?>><label for="paginer"><?php echo __('Documents avec pagination','wp-hal');?></label><br>
949 <input type="radio" name="option_groupe" id="grouper" value="grouper" <?php echo (get_option('option_groupe') == "grouper")?'checked':''; ?>><label for="grouper"><?php echo __('Documents groupés par type','wp-hal');?></label><br>
950 </td>
951 </tr>
952 <tr valign="top">
953 <th scope="row"><?php echo __('Choix des éléments menu','wp-hal');?></th>
954 <td><input type="checkbox" name="option_choix[1]" id="Contact" value="contact" <?php echo (get_option('option_choix')[1] == "contact")?'checked':''; ?>><label for="Contact"><?php echo __('Contact','wp-hal');?></label><br/>
955 <input type="checkbox" name="option_choix[2]" id="Disciplines" value="disciplines" <?php echo (get_option('option_choix')[2] == "disciplines")?'checked':''; ?>><label for="Disciplines"><?php echo __('Disciplines','wp-hal');?></label><br/>
956 <input type="checkbox" name="option_choix[3]" id="Mots-clefs" value="mots-clefs" <?php echo (get_option('option_choix')[3] == "mots-clefs")?'checked':''; ?>><label for="Mots-clefs"><?php echo __('Mots-clefs','wp-hal');?></label><br/>
957 <input type="checkbox" name="option_choix[4]" id="Auteurs" value="auteurs" <?php echo (get_option('option_choix')[4] == "auteurs")?'checked':''; ?>><label for="Auteurs"><?php echo __('Auteurs','wp-hal');?></label><br/>
958 <input type="checkbox" name="option_choix[5]" id="Revues" value="revues" <?php echo (get_option('option_choix')[5] == "revues")?'checked':''; ?>><label for="Revues"><?php echo __('Revues','wp-hal');?></label><br/>
959 <input type="checkbox" name="option_choix[6]" id="Annee" value="annee" <?php echo (get_option('option_choix')[6] == "annee")?'checked':''; ?>><label for="Annee"><?php echo __('Année de production','wp-hal');?></label><br/>
960 <input type="checkbox" name="option_choix[7]" id="Institution" value="institution" <?php echo (get_option('option_choix')[7] == "institution")?'checked':''; ?>><label for="Institution"><?php echo __('Institutions','wp-hal');?></label><br/>
961 <input type="checkbox" name="option_choix[8]" id="Laboratoire" value="laboratoire" <?php echo (get_option('option_choix')[8] == "laboratoire")?'checked':''; ?>><label for="Laboratoire"><?php echo __('Laboratoires','wp-hal');?></label><br/>
962 <input type="checkbox" name="option_choix[9]" id="Departement" value="departement" <?php echo (get_option('option_choix')[9] == "departement")?'checked':''; ?>><label for="Departement"><?php echo __('Départements','wp-hal');?></label><br/>
963 <input type="checkbox" name="option_choix[10]" id="Equipe" value="equipe" <?php echo (get_option('option_choix')[10] == "equipe")?'checked':''; ?>><label for="Equipe"><?php echo __('Équipes de recherche','wp-hal');?></label>
964 </td>
965 </tr>
966 <tr valign="top">
967 <th scope="row" style="font-size: 18px;"><?php echo __('Contact :','wp-hal');?></th>
968 </tr>
969 <tr valign="top">
970 <th scope="row"><?php echo __('Email','wp-hal');?></th>
971 <td><input type="text" name="option_email" id="option_email" value="<?php echo get_option('option_email'); ?>"/><img alt="email" src="<?php echo plugin_dir_url( __FILE__ ) ?>img/mail.svg" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
972 </tr>
973 <tr valign="top">
974 <th scope="row"><?php echo __('Téléphone','wp-hal');?></th>
975 <td><input type="text" name="option_tel" id="option_tel" value="<?php echo get_option('option_tel');?>"/><img alt="phone" src="<?php echo plugin_dir_url( __FILE__ ) ?>img/phone.svg" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
976 </tr>
977 <tr>
978 <th>Facebook</th>
979 <td>http://www.facebook.com/<input type="text" name="option_social0" id="option_social0" value="<?php echo get_option('option_social0'); ?>"/><img alt="facebook" src="<?php echo plugin_dir_url( __FILE__ ) ?>img/facebook.svg" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
980 </tr>
981 <tr>
982 <th>Twitter</th>
983 <td>http://www.twitter.com/<input type="text" name="option_social1" id="option_social1" value="<?php echo get_option('option_social1'); ?>"/><img alt="twitter" src="<?php echo plugin_dir_url( __FILE__ ) ?>img/twitter.svg" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
984 </tr>
985 <tr>
986 <th>Google +</th>
987 <td>https://plus.google.com/u/0/+<input type="text" name="option_social2" id="option_social2" value="<?php echo get_option('option_social2'); ?>"/><img alt="google" src="<?php echo plugin_dir_url( __FILE__ ) ?>img/google-plus.svg" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
988 </tr>
989 <tr>
990 <th>LinkedIn</th>
991 <td>http://sa.linkedin.com/pub/<input type="text" name="option_social3" id="option_social3" value="<?php echo get_option('option_social3'); ?>"/><img alt="linkedin" src="<?php echo plugin_dir_url( __FILE__ ) ?>img/linkedin.svg" style="vertical-align:middle; width:32px; margin-left:2px; margin-right:2px;"/></td>
992 </tr>
993 </table>
994 <?php
995 update_option('option_idhal', str_replace(',',' OR ',get_option('option_idhal')));
996 submit_button(__('Enregistrer','wp-hal'), 'primary large', 'submit', true); ?>
997 </div>
998 <div id="postbox-container-1" class="postbox-container">
999
1000 </div>
1001 </div>
1002 <br class="clear"><br/>
1003 </div>
1004 </form>
1005
1006 </div>
1007
1008 <?php
1009 }
1010
1011
1012 /**
1013 * Reset les données Hal
1014 */
1015 function reset_option() {
1016 delete_option('option_choix');
1017 delete_option('option_type');
1018 delete_option('option_groupe');
1019 delete_option('option_idhal');
1020 delete_option('option_lang');
1021 delete_option('option_email');
1022 delete_option('option_tel');
1023 delete_option('option_social0');
1024 delete_option('option_social1');
1025 delete_option('option_social2');
1026 delete_option('option_social3');
1027 }
1028