PluginProbe
HAL / 2.0.1
HAL v2.0.1
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 2.0.1, at wp-hal.php

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