-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigital_measures.module
465 lines (410 loc) · 17.4 KB
/
digital_measures.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<?php
/**
* Implements hook_block_info() to create blocks for assignment in admin>structure>blocks
*/
function digital_measures_block_info() {
$blocks = array();
$blocks['digital_measures_profile_data'] = array(
'info' => t('Digital Measures Profile Data'),
);
return $blocks;
}
/**
* Implements hook_menu() to create admin page and menu path.
*/
function digital_measures_menu() {
$items = array();
$items['admin/config/content/digital_measures'] = array(
'title' => 'Digital Measures',
'description' => 'Configuration for Digital Measures module',
'page callback' => 'drupal_get_form',
'page arguments' => array('digital_measures_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Page callback: Digital Measures module settings
* Save the variables as system settings always available
*/
function digital_measures_form($form, &$form_state) {
$form['digital_measures_api_url'] = array(
'#type' => 'textfield',
'#title' => t('Digital Measures API URL'),
'#default_value' => variable_get('digital_measures_api_url', 'https://beta.digitalmeasures.com/login/service/v4/SchemaData/'),
'#size' => 75,
'#maxlength' => 255,
'#description' => t('The URL of the API including the service and version. Format: https://beta.digitalmeasures.com/login/service/v4/SchemaData/'),
'#required' => TRUE,
);
$form['digital_measures_username'] = array(
'#type' => 'textfield',
'#title' => t('Digital Measures Username'),
'#default_value' => variable_get('digital_measures_username', ''),
'#size' => 50,
'#maxlength' => 255,
'#description' => t('The account with access to query the API. Include the domain if necessary.'),
'#required' => TRUE,
);
$form['digital_measures_password'] = array(
'#type' => 'password',
'#title' => t('Digital Measures Password'),
'#default_value' => variable_get('digital_measures_password', ''),
'#size' => 50,
'#maxlength' => 255,
'#description' => t('The password for the account with access to query the API.'),
'#required' => TRUE,
);
return system_settings_form($form);
}
/**
* Implements hook_block_view() to create the contents of the blocks when they are viewed.
* Currently, this module is designed to only work on user pages with the format /user/uid
*/
function digital_measures_block_view($delta = '') {
$block = array();
$dm_request = array();
$path = current_path();
$dm_request['dm_url'] = variable_get('digital_measures_api_url', '');
$dm_request['dm_username'] = variable_get('digital_measures_username', '');
$dm_request['dm_password'] = variable_get('digital_measures_password', '');
$path_parts = explode('/', drupal_get_path_alias($path));
$dm_request['user'] = $path_parts['1'];
$path_parts = explode('/', $path);
$user_id = $path_parts['1'];
switch ($delta) {
case 'digital_measures_profile_data':
$user_data = user_load($user_id);
$show_dm_content = $user_data->field_display_content_from_dm;
if ($show_dm_content && $show_dm_content['und'][0]['value'] == 1) {
$block['subject'] = 'Curriculum Vitae';
$block['content'] = _digital_measures_get_data($dm_request);
}
break;
}
return $block;
}
/**
* use CURL to get the XML from the catalog source.
*/
function digital_measures_download_page($path, $dm_request){
$before = microtime(true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0);
curl_setopt($ch, CURLOPT_USERPWD, $dm_request['dm_username'] . ":" . $dm_request['dm_password']);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_ENCODING,'gzip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//dont check the certificate, we know itrs good and we arent passing sensitive info
$retValue = curl_exec($ch);
if(curl_errno($ch)) {
$errorMessage = curl_error($ch);
// TODO: Handle cURL error
//dpm("The was an error retrieving content from Digital Measures. Error: " . $errorMessage);
}
curl_close($ch);
$after = microtime(true);
//dpm(($after-$before) . " sec: " . $path);
return $retValue;
}
/**
* get the XML data from DM and return html
*/
function _digital_measures_get_data($dm_request){
$sXML = digital_measures_download_page ($dm_request['dm_url'] . 'INDIVIDUAL-ACTIVITIES-University/USERNAME:' . $dm_request['user'] . '/PCI', $dm_request );
//dpm($sXML);
$testxml = simplexml_load_string($sXML);
if ($testxml == false) {
$output = "<div class='messages error margin-top-large'><p>The user " . $dm_request['user'] . " selected to show Curriculum Vitae data from Digital Measures but does not have a valid Digital Measures account.</p></div>";
} else {
$xml = new SimpleXMLElement($sXML);
$output = "";
//bio paragraph
if ((string)$xml->Record->PCI->BIO != ""){
$output = $output . "<h3>Brief Biography</h3>" .
"<p>" . (string)$xml->Record->PCI->BIO . "</p>";
}
//list of Education Records
if (!empty($xml->Record->PCI->PCI_EDUCATION_REF->EDUCATION)) {
$output = $output . "<h3>Education</h3>";
foreach($xml->Record->PCI->PCI_EDUCATION_REF as $item){
//save items as variables
$DEG = $item->EDUCATION->DEG;
$MAJOR = $item->EDUCATION->MAJOR;
$SCHOOL = $item->EDUCATION->SCHOOL;
$YR_COMP = $item->EDUCATION->YR_COMP;
//test if the variable has contents, then format output
$output = $output . "<p>";
if ($DEG != "") $output = $output . "" . $DEG . "";
if ($MAJOR != "") $output = $output . " " . $MAJOR;
if ($SCHOOL != "") $output = $output . " " . $SCHOOL;
if ($YR_COMP != "") $output = $output . ", " . $YR_COMP;
$output = $output . "</p>";
}
}
//teaching intererst paragraph
if ((string)$xml->Record->PCI->TEACHING_INTERESTS != ""){
$output = $output . "<h3>Teaching Interests</h3>" .
"<p>" . (string)$xml->Record->PCI->TEACHING_INTERESTS . "</p>";
}
//research intererst paragraph
if ((string)$xml->Record->PCI->RESEARCH_INTERESTS != ""){
$output = $output . "<h3>Research Interests</h3>" .
"<p>" . (string)$xml->Record->PCI->RESEARCH_INTERESTS . "</p>";
}
//professional collaborators paragraph
if ((string)$xml->Record->PCI->PROF_COLLAB != ""){
$output = $output . "<h3>Professional Collaborators</h3>" .
"<p>" . (string)$xml->Record->PCI->PROF_COLLAB . "</p>";
}
//Ordered list of References
if (!empty($xml->Record->PCI->REFERENCE->NAME)) {
$output = $output . "<h3>References</h3><ol>";
foreach($xml->Record->PCI->REFERENCE as $item){
$output = $output . "<li>Name: " . $item->NAME . "<br/>";
if (!empty($item->TITLE)) $output = $output . "Title: " . $item->TITLE . "<br/>";
if (!empty($item->ORG)) $output = $output . "Organization: " . $item->ORG . "<br/>";
if (!empty($item->ADDRESS)) $output = $output . "Address: " . $item->ADDRESS . "<br/>";
if (!empty($item->CITYSTATE)) $output = $output . "City/State: " . $item->CITYSTATE . "</li>";
}
$output = $output . "</ol>";
}
//list of Intellectual content
if (!empty($xml->Record->PCI->PCI_INTELLCONT_REF->INTELLCONT)) {
$output = $output . "<h3>Intellectual Content</h3>";
foreach($xml->Record->PCI->PCI_INTELLCONT_REF as $item){
$output = $output . "<p>";
//Output the publication authors
$authcount = count($item->INTELLCONT->INTELLCONT_AUTH);
$i = 0;
if ($authcount > 0) {
foreach($item->INTELLCONT->INTELLCONT_AUTH as $author){
//save the name parts as variables
$LNAME = $author->LNAME;
$FNAME = $author->FNAME;
$MNAME = $author->MNAME;
//if it's not the first name, add a comma seperator
if ($i != 0) $output = $output . ", ";
//make sure the name parts exist before output
if ($LNAME != "") $output = $output . $LNAME . ",";
if ($FNAME != "") $output = $output . " " . substr($FNAME, 0,1) . ".";
if ($MNAME != "") $output = $output . " " . substr($MNAME, 0,1) . ".";
$i ++;
}
//save items as variables
$DTY_PUB = $item->INTELLCONT->DTY_PUB;
$TITLE = $item->INTELLCONT->TITLE;
$JOURNAL_NAME = $item->INTELLCONT->JOURNAL_NAME;
$PUBLISHER = $item->INTELLCONT->PUBLISHER;
$VOLUME = $item->INTELLCONT->VOLUME;
$ISSUE = $item->INTELLCONT->ISSUE;
$PAGENUM = $item->INTELLCONT->PAGENUM;
$PUBCTYST = $item->INTELLCONT->PUBCTYST;
$OPEN_ACCESS_URL = $item->INTELLCONT->OPEN_ACCESS_URL;
//test if the variable has contents, then format output
if ($DTY_PUB != "") $output = $output . " (" . $DTY_PUB . ")";
if ($TITLE != "") $output = $output . " <em>" . $TITLE . "</em>";
if ($JOURNAL_NAME != "") $output = $output . ", " . $JOURNAL_NAME . "";
if ($PUBLISHER != "") $output = $output . ", " . $PUBLISHER . "";
if ($ISSUE != "" || $VOLUME != "" || $PAGENUM != "") {
$output = $output . ",";
if ($VOLUME != "") $output = $output . " " . $VOLUME . "";
if ($ISSUE != "") $output = $output . "(" . $ISSUE . ")";
if ($PAGENUM != "") $output = $output . ", " . $PAGENUM . "";
$output = $output . ".";
}
if ($PUBCTYST != "") $output = $output . ". " . $PUBCTYST . "";
if ($OPEN_ACCESS_URL != "") $output = $output .
". <a href='" . $OPEN_ACCESS_URL . "' target='_blank'>" .
$OPEN_ACCESS_URL . "</a>";
}
$output = $output . "</p>";
}
}
//list of Presentations
if (!empty($xml->Record->PCI->PCI_PRESENT_REF->PRESENT)) {
$output = $output . "<h3>Presentations</h3>";
foreach($xml->Record->PCI->PCI_PRESENT_REF as $item){
//save items as variables
$TITLE = $item->PRESENT->TITLE;
$NAME = $item->PRESENT->NAME;
$DTM_DATE = $item->PRESENT->DTM_DATE;
$DTY_DATE = $item->PRESENT->DTY_DATE;
$CITY = $item->PRESENT->CITY;
$STATE = $item->PRESENT->STATE;
$COUNTRY = $item->PRESENT->COUNTRY;
//test if the variable has contents, then format output
$output = $output . "<p>";
if ($TITLE != "") $output = $output . "<em>" . $TITLE . "</em>";
if ($NAME != "") $output = $output . ", " . $NAME . "";
if ($DTM_DATE != "") $output = $output . ", " . $DTM_DATE . "";
if ($DTY_DATE != "") $output = $output . ", " . $DTY_DATE . "";
if ($CITY != "") $output = $output . ", " . $CITY . "";
if ($STATE != "") $output = $output . ", " . $STATE . "";
if ($COUNTRY != "") $output = $output . ", " . $COUNTRY . "";
$output = $output . "</p>";
}
}
//list of Awards and Honors
if (!empty($xml->Record->PCI->PCI_AWARDHONOR_REF->AWARDHONOR)) {
$output = $output . "<h3>Awards and Honors</h3>";
foreach($xml->Record->PCI->PCI_AWARDHONOR_REF as $item){
//save items as variables
$NAME = $item->AWARDHONOR->NAME;
$ORG = $item->AWARDHONOR->ORG;
$DTY_DATE = $item->AWARDHONOR->DTY_DATE;
//test if the variable has contents, then format output
$output = $output . "<p>";
if ($NAME != "") $output = $output . $NAME;
if ($ORG != "") $output = $output . ", " . $ORG;
if ($DTY_DATE != "") $output = $output . ", " . $DTY_DATE;
$output = $output . "</p>";
}
}
//list of Patents and Copyrights
if (!empty($xml->Record->PCI->PCI_INTELLPROP_REF->INTELLPROP)) {
$output = $output . "<h3>Patents and Copyrights</h3>";
foreach($xml->Record->PCI->PCI_INTELLPROP_REF as $item){
//save items as variables
$FORMAT = $item->INTELLPROP->FORMAT;
$TITLE = $item->INTELLPROP->TITLE;
$DESC_ENGAGE = $item->INTELLPROP->DESC_ENGAGE;
$DTY_APPROVE = $item->INTELLPROP->DTY_APPROVE;
//test if the variable has contents, then format output
$output = $output . "<p>(";
if ($FORMAT != "") $output = $output . "" . $FORMAT . "";
if ($DTY_APPROVE != "") $output = $output . " " . $DTY_APPROVE;
$output = $output . ")";
if ($TITLE != "") $output = $output . " " . $TITLE;
if ($DESC_ENGAGE != "") $output = $output . " <em>" . $DESC_ENGAGE . "</em>";
$output = $output . "</p>";
}
}
//list of Licensures and Certifications
if (!empty($xml->Record->PCI->PCI_LICCERT_REF->LICCERT)) {
$output = $output . "<h3>Licensures and Certifications</h3>";
foreach($xml->Record->PCI->PCI_LICCERT_REF as $item){
//save items as variables
$DTM_START = $item->LICCERT->DTM_START;
$DTY_START = $item->LICCERT->DTY_START;
$TITLE = $item->LICCERT->TITLE;
$ORG = $item->LICCERT->ORG;
$DESC = $item->LICCERT->DESC;
//test if the variable has contents, then format output
$output = $output . "<p>";
if ($DTM_START != "") $output = $output . "" . $DTM_START . ", ";
if ($DTY_START != "") $output = $output . "" . $DTY_START . ", ";
if ($TITLE != "") $output = $output . "" . $TITLE . "";
if ($ORG != "") $output = $output . ", " . $ORG . "";
if ($DESC != "") $output = $output . ", <em>" . $DESC . "</em>";
$output = $output . "</p>";
}
}
//list of Consulting
if (!empty($xml->Record->PCI->PCI_CONSULT_REF->CONSULT)) {
$output = $output . "<h3>Consulting</h3>";
foreach($xml->Record->PCI->PCI_CONSULT_REF as $item){
//save items as variables
$DTM_START = $item->CONSULT->DTM_START;
$DTY_START = $item->CONSULT->DTY_START;
$ORG = $item->CONSULT->ORG;
$LOCATION = $item->CONSULT->LOCATION;
$DESC = $item->CONSULT->DESC;
//test if the variable has contents, then format output
$output = $output . "<p>";
if ($DTM_START != "") $output = $output . "" . $DTM_START . ", ";
if ($DTY_START != "") $output = $output . "" . $DTY_START . ", ";
if ($ORG != "") $output = $output . "" . $ORG . "";
if ($LOCATION != "") $output = $output . ", " . $LOCATION . "";
if ($DESC != "") $output = $output . ", <em>" . $DESC . "</em>";
$output = $output . "</p>";
}
}
//list of Engagement Activities
if (!empty($xml->Record->PCI->PCI_ENGAGEMENT_REF->ENGAGEMENT)) {
$output = $output . "<h3>Engagement Activities</h3>";
foreach($xml->Record->PCI->PCI_ENGAGEMENT_REF as $item){
//save items as variables
$TITLE = $item->ENGAGEMENT->TITLE;
$DTY_DATE = $item->ENGAGEMENT->DTY_DATE;
$DESC = $item->ENGAGEMENT->DESC;
//test if the variable has contents, then format output
$output = $output . "<p>";
if ($DTY_DATE != "") $output = $output . "(" . $DTY_DATE . ")";
if ($TITLE != "") $output = $output . " " . $TITLE . "";
if ($DESC != "") $output = $output . ", <em>" . $DESC . "</em>";
$output = $output . "</p>";
}
}
//list of Memberships
if (!empty($xml->Record->PCI->PCI_MEMBER_REF->MEMBER)) {
$output = $output . "<h3>Memberships</h3>";
foreach($xml->Record->PCI->PCI_MEMBER_REF as $item){
//save items as variables
$LEADERSHIP = $item->MEMBER->LEADERSHIP;
$NAME = $item->MEMBER->NAME;
$DTY_START = $item->MEMBER->DTY_START;
$DTY_END = $item->MEMBER->DTY_END;
$DESC = $item->MEMBER->DESC;
//test if the variable has contents, then format output
$output = $output . "<p>";
if ($LEADERSHIP != "") $output = $output . "" . $LEADERSHIP . "";
if ($NAME != "") $output = $output . ", " . $NAME . "";
if ($DTY_START != "" || $DTY_END != "") {
$output = $output . " (";
if ($DTY_START != "") $output = $output . "" . $DTY_START . "";
if ($DTY_END != "") $output = $output . "-" . $DTY_END . "";
$output = $output . ")";
}
$output = $output . "</p>";
}
}
//External Partnerships
//$refcount = count($xml->Record->PCI->PCI_EXTERNAL_PARTNERSHIPS_REF);
if (!empty($xml->Record->PCI->PCI_EXTERNAL_PARTNERSHIPS_REF->EXTERNAL_PARTNERSHIPS)) {
$output = $output . "<h3>External Partnerships</h3>";
foreach($xml->Record->PCI->PCI_EXTERNAL_PARTNERSHIPS_REF as $item){
//save items as variables
$TYPE = $item->EXTERNAL_PARTNERSHIPS->TYPE;
$DESC = $item->EXTERNAL_PARTNERSHIPS->DESC;
$ORG = $item->EXTERNAL_PARTNERSHIPS->ORG;
$CITY = $item->EXTERNAL_PARTNERSHIPS->CITY;
$STATE = $item->EXTERNAL_PARTNERSHIPS->STATE;
$DTM_DATE = $item->EXTERNAL_PARTNERSHIPS->DTM_DATE;
$DTY_DATE = $item->EXTERNAL_PARTNERSHIPS->DTY_DATE;
//test if the variable has contents, then format output
$output = $output . "<p>";
if ($TYPE != "") $output = $output . "" . $TYPE . "";
if ($DESC != "") $output = $output . ", <em>" . $DESC . "</em>";
if ($ORG != "") $output = $output . ", " . $ORG . "";
if ($CITY != "") $output = $output . ", " . $CITY . "";
if ($STATE != "") $output = $output . ", " . $STATE . "";
if ($DTM_DATE != "") $output = $output . " (" . $DTM_DATE . "";
if ($DTY_DATE != "") $output = $output . ", " . $DTY_DATE . ")";
$output = $output . "</p>";
}
}
//list of Websites
if (!empty($xml->Record->PCI->PCI_WEBSITE->WEBSITE)) {
$output = $output . "<h3>Links";
$output = $output . "</h3>";
foreach($xml->Record->PCI->PCI_WEBSITE as $item){
$output = $output . "<p><a href='" . $item->WEBSITE . "' target='-blank'>" . $item->WEBSITE . "</a></p>";
}
}
}
if (!empty($output)) {
//start the output by hiding all of the CV content with CSS
$intro = "<style type='text/css'>#block-quicktabs-user-profile-cv-tabs {display:none;}</style>";
$intro = $intro . "<h2>Curriculum Vitae</h2>";
$output = $intro . $output;
} else {
//if there is no data in the output display an error message.
$output = "<div class='messages error margin-top-large'><p>The user " . $dm_request['user'] . " selected to show Curriculum Vitae data from Digital Measures but no data has been added to the Digital Measures Web Profile fields.</p></div>";
}
return $output;
}