PluginProbe
HAL / 1.4
HAL v1.4
trunk 1.0 1.1 1.2 1.3 1.4 1.4.2 1.4.3 1.4.4 2.0 2.0.1 2.0.10 2.0.2 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.2 2.3 2.4 2.4.1 2.4.2 2.5 All 30 releases
hal / wp-hal.php

wp-hal.php in HAL 1.4, at wp-hal.php

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