PluginProbe
HAL / 2.0.10
HAL v2.0.10
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.10, at wp-hal.php

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