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

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