forked from jastreich/digital-measures-wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
profile.inc.php
599 lines (541 loc) · 14.5 KB
/
profile.inc.php
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
<?php
/**
* @file profile.inc.php
* The meat of the application happens within this file.
* @author Jeremy Streich
**/
function dm_startsWith($haystack, $needle)
{
return $needle === "" || strpos($haystack, $needle) === 0;
}
function dm_endsWith($haystack, $needle)
{
return $needle === "" || substr($haystack, -strlen($needle)) === $needle;
}
require_once('contributor.inc.php');
require_once('publication.inc.php');
require_once('presentation.inc.php');
require_once('degree.inc.php');
require_once('award.inc.php');
require_once('research.inc.php');
require_once('grant.inc.php');
/**
* @class profile
* This object represents a faculty's profile, as far as their intelectual contributions. Fetches information from Digital Measures.
**/
class profile
{
private $username;
private $password;
private $epanther;
private $school;
private $college;
private $first_name;
private $middle_name;
private $last_name;
private $email;
private $phone;
private $phone_ex;
private $room;
private $website;
private $network;
private $research;
private $pubs;
private $education;
private $awards;
private $current_research;
private $grants;
/**
* Constructor for the publications class which popluates the profile by fetching information from Digital Measures
* @param string $u the ePatherID of the user.
* @param array $config Activity Insight Configuration
**/
function __construct($u,$config = null)
{
$this->username = $config['username'];
$this->password = $config['password'];
$this->epanther = $u;
$ret = '';
$ch = curl_init('https://www.digitalmeasures.com/login/service/v4/UserSchema/USERNAME:' . $u . '/INDIVIDUAL-ACTIVITIES-' . $config['key']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$ret = curl_exec($ch);
curl_close($ch);
$this->username = '';
$this->password = '';
//Make parsing easier by removing dmd namespace
$ret = str_replace('dmd:','',$ret);
// echo $ret;
$dom = new DOMDocument;
$good = $dom->loadXML($ret);
if (!$good)
{
echo $ret;
exit;
}
$xml = simplexml_import_dom($dom);
//Get School and Department
foreach($xml->IndexEntry as $unit)
{
$attrs = $unit->attributes();
if($attrs['indexKey'] == 'COLLEGE')
{
$this->college = (string)$attrs['entryKey'];
}
else if($attrs['indexKey'] == 'DEPARTMENT')
{
$this->department = (string)$attrs['entryKey'];
}
}
//Get Contact information
$this->first_name = (string)$xml->PCI->FNAME;
$this->last_name = (string)$xml->PCI->LNAME;
$this->middle_name = (string)$xml->PCI->MNAME;
$this->email = (string)$xml->PCI->EMAIL;
$this->phone = '(' . $xml->PCI->OPHONE1 . ') ' . $xml->PCI->OPHONE1 . '-' . $xml->PCI->OPHONE3;
$this->phone_ex = (string)$xml->PCI->OPHONE3;
$this->room = (string)$xml->PCI->ROOMNUM;
$this->website = (string)$xml->PCI->WEBSITE;
$this->network = ($xml->RESEARCH_INTEREST->SHARE == 'Yes');
$this->research = (string)$xml->RESEARCH_INTEREST->INTEREST;
$this->pubs = array();
$this->presentations = array();
$this->education = array();
$this->awards = array();
$this->grants = array();
// Publications
try
{
foreach($xml->INTELLCONT as $pub)
{
$attrs = $pub->attributes();
$a = array();
foreach($pub->INTELLCONT_AUTH as $author)
{
$a[] = new contributor($author->FNAME,$author->MNAME,$author->LNAME);
}
$e = array();
foreach($pub->INTELLCONT_EDITOR as $editor)
{
$e[] = new contributor($editor->FNAME,$editor->MNAME,$editor->LNAME);
}
if(count($e) == 0 && isset($pub->EDITORS) && '' != $pub->EDITORS && null != $pub->EDITORS)
{
$e[0] = new contributor($pub->EDITORS);
}
$is_article = (strpos($pub->CONTYPE,'Journal Article') === 0) || (strpos($pub->CONTYPE,'Online Article') === 0);
// // // //
$this->pubs[] = new publication
(
$attrs['id'],
$pub->CONTYPE,
$pub->STATUS,
$pub->TITLE,
($is_article ? $pub->PUBLISHER : $pub->TITLE_SECONDARY),
(isset($pub->INCLUDE_PROFILE) ? $pub->INCLUDE_PROFILE : false), //$pub->INCLUDE_PROFILE,
$a,
$e,
($is_article ? '' : $pub->PUBLISHER),
$pub->PUBCTYST,
$pub->VOLUME,
$pub->ISSUE,
$pub->PAGENUM,
$pub->DOI,
$pub->ISBNISSN,
$pub->DTD_PUB,
$pub->DTM_PUB,
$pub->DTY_PUB,
$pub->WEB_ADDRESS
);
}
}
catch(Exception $e)
{
echo $e->message;
}
// Presentations
try
{
foreach($xml->PRESENT as $pub)
{
$attrs = $pub->attributes();
$a = array();
foreach($pub->PRESENT_AUTH as $author)
{
$a[] = new contributor($author->FNAME,$author->MNAME,$author->LNAME);
}
$this->presentations[] = new presentation
(
$pub->NAME,
$a,
$pub->TITLE,
$pub->LOCATION,
$pub->DTM_DATE,
$pub->DTY_DATE,
(isset($pub->INCLUDE_PROFILE) ? $pub->INCLUDE_PROFILE : false)
);
}
}
catch(Exception $e)
{
echo $e->message;
}
// Educatiom
try
{
foreach($xml->EDUCATION as $ed)
{
$attrs = $ed->attributes();
$this->education[] = new degree
(
($ed->DEG != 'Other' ? $ed->DEG : $ed->DEGOTHER),
$ed->MAJOR,
$ed->SCHOOL,
$ed->LOCATION,
$attrs['startDate'],
$attrs['endDate']
);
}
}
catch(Exception $e)
{
echo $e->message;
}
try
{
foreach($xml->AWARDHONOR as $aw)
{
$this->awards[] = new award
(
$aw->NAME,
$aw->ORG,
$aw->DTY_DATE,
$aw->DTM_DATE,
$aw->DTD_DATE
);
}
}
catch(Exception $e)
{
echo $e->message;
}
try
{
foreach($xml->RESPROG as $re)
{
$cols = array();
foreach($re->RESPROG_COLL as $col)
{
$cols[] = (string)$col->NAME;
}
$this->current_research[] = new research
(
$re->TITLE,
$re->DESC,
$cols
);
}
}
catch(Exception $e)
{
echo $e->message;
}
try
{
foreach($xml->CONGRANT as $gr)
{
$invest = array();
foreach($gr->CONGRANT_INVEST as $iv)
{
$invest[] = $iv->FNAME . ' ' . $iv->LNAME;
}
$this->grants[] = new grant
(
$gr->TITLE,
$gr->SPONORG,
$gr->TYPE,
$invest
);
}
}
catch(Exception $e)
{
echo $e->message;
}
if(is_array($this->pubs))
{
usort($this->pubs,"pub_cmp");
}
if(is_array($this->education))
{
usort($this->education,"ed_cmp");
$this->education = array_reverse($this->education);
}
}
/**
* Show this faculty education as HTML.
* @param bool $show_location weather or not to show the location of the shcool.
* @param string $show_dates how to show the dates.
* @return HTML of the education as as a string.
**/
public function education($show_location,$show_dates)
{
$ret = '<div id="education">';
foreach($this->education as $ed)
{
$ret .= $ed->display($show_location,$show_dates);
}
$ret .='</div>';
return $ret;
}
/**
* Show this faculty member's awards as HTML.
* @return HTML of the awards as as a string.
**/
public function awards($limit = 0)
{
$ret = '<div id="awards">';
$i = 0;
foreach($this->awards as $aw)
{
$ret .= $aw->display();
$i++;
if($limit && $i >= $limit)
{
break;
}
}
$ret .='</div>';
return $ret;
}
/**
* Show this faculty member's research as HTML.
* @return HTML of the research as as a string.
**/
public function current_research($limit = 0)
{
$ret = '<div id="current-research">';
$i = 0;
foreach($this->current_research as $re)
{
$ret .= $re->display();
$i++;
if($limit && $i >= $limit)
{
break;
}
}
$ret .='</div>';
return $ret;
}
/**
* Show this faculty member's research as HTML.
* @return HTML of the research as as a string.
**/
public function grants($limit = 0)
{
$ret = '<div id="grants">';
$i = 0;
foreach($this->grants as $gr)
{
$ret .= $gr->display();
$i++;
if($limit && $i >= $limit)
{
break;
}
}
$ret .='</div>';
return $ret;
}
/**
* Output this profile as list of mla citations of publications.
* @parma string $type 'html' or 'text' supported. This is what the output method will eventually be.
* @param bool $only_published if true then only published works will be output
* @param bool $only_profile if true then olny the publications marked to be shown on a profile page will be output.
* @param int $limit the maximum number of publications to display. limit of 0 means show all matching the previous arguments.
* @param string $unpublished The text to be shown in place of date for unpublished works.
* @param bool $strict If the mla is stict format or not.
* @return string of mla formated citations for output
**/
public function mla($type = 'html', $only_published = false,$only_profile = false,$limit = 0,$authors = null,$unpublished = '',$strict = false)
{
$ret = '';
if('array' == $type)
{
$ret = array();
}
$i = 1;
foreach($this->pubs as $p)
{
if( ( !$only_published || ($only_published && $p->is_published())) &&
( !$only_profile || ($only_profile && $p->in_profile() ))
)
{
$i++;
if('html' == $type)
{
$ret .= '<div class="publication">';
}
if('array' == $type)
{
$ret[] = $p->mla($type,$authors,$unpublished,$strict);
}
else
{
$ret .= $p->mla($type,$authors,$unpublished,$strict);
}
if('html' == $type)
{
$ret .= '</div>';
}
}
if($limit != 0 && $i > $limit)
{
break;
}
}
return $ret;
}
/**
* Output this profile as list of mla citations of presentations.
* @parma string $type 'html' or 'text' supported. This is what the output method will eventually be.
* @param bool $only_profile if true then olny the presentations marked to be shown on a profile page will be output.
* @param int $limit the maximum number of presentations to display. limit of 0 means show all matching the previous arguments.
* @return string of mla formated citations for output
**/
public function mla_presentations($type = 'html',$only_profile = false,$limit = 0)
{
$ret = '';
if('array' == $type)
{
$ret = array();
}
$i = 1;
foreach($this->presentations as $p)
{
if( !$only_profile || ($only_profile && $p->in_profile()) )
{
$i++;
if('html' == $type)
{
$ret .= '<div class="presentation">';
}
if('array' == $type)
{
$ret[] = $p->mla($type);
}
else
{
$ret .= $p->mla($type);
}
if('html' == $type)
{
$ret .= '</div>';
}
}
if($limit != 0 && $i > $limit)
{
break;
}
}
return $ret;
}
/**
* Output this profile's publications as list of APA citations of publications.
* @parma string $type 'html' or 'text' supported. This is what the output method will eventually be.
* @param bool $only_published if true then only published works will be output
* @param bool $only_profile if true then olny the publications marked to be shown on a profile page will be output.
* @param int $limit the maximum number of publications to display. limit of 0 means show all matching the previous arguments.
* @param int $authors the number of authors to display.
* @param string $unpublished The text to shown in place of date for unpublished works.
* @return string of mla formated citations for output
**/
function apa($type = 'html', $only_published = false,$only_profile = false,$limit = 0,$authors = null,$unpublished = '')
{
$ret = '';
if('array' == $type)
{
$ret = array();
}
$i = 1;
foreach($this->pubs as $p)
{
if( ( !$only_published || ($only_published && $p->is_published())) &&
( !$only_profile || ($only_profile && $p->in_profile() ))
)
{
$i++;
if('html' == $type)
{
$ret .= '<div class="publication">';
}
if('array' == $type)
{
$ret[] = $p->apa($type,$authors,$unpublished);
}
else
{
$ret .= $p->apa($type,$authors,$unpublished);
}
if('html' == $type)
{
$ret .= '</div>';
}
}
if($limit != 0 && $i > $limit)
{
break;
}
}
return $ret;
}
/**
* Output this profile as list of mla citations of presentations.
* @parma string $type 'html' or 'text' supported. This is what the output method will eventually be.
* @param bool $only_profile if true then olny the presentations marked to be shown on a profile page will be output.
* @param int $limit the maximum number of presentations to display. limit of 0 means show all matching the previous arguments.
* @return string of mla formated citations for output
**/
public function apa_presentations($type = 'html',$only_profile = false,$limit = 0)
{
$ret = '';
if('array' == $type)
{
$ret = array();
}
$i = 1;
foreach($this->presentations as $p)
{
if( !$only_profile || ($only_profile && $p->in_profile()) )
{
$i++;
if('html' == $type)
{
$ret .= '<div class="presentation">';
}
if('array' == $type)
{
$ret[] = $p->apa($type);
}
else
{
$ret .= $p->apa($type);
}
if('html' == $type)
{
$ret .= '</div>';
}
}
if($limit != 0 && $i > $limit)
{
break;
}
}
return $ret;
}
};
?>