ZenodoBridge.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class ZenodoBridge extends BridgeAbstract {
  3. const MAINTAINER = 'theradialactive';
  4. const NAME = 'Zenodo';
  5. const URI = 'https://zenodo.org';
  6. const CACHE_TIMEOUT = 10;
  7. const DESCRIPTION = 'Returns the newest content of Zenodo';
  8. public function collectData(){
  9. $html = getSimpleHTMLDOM($this->getURI())
  10. or returnServerError('zenodo.org not reachable.');
  11. foreach($html->find('div.record-elem') as $element) {
  12. $item = array();
  13. $item['uri'] = self::URI . $element->find('h4', 0)->find('a', 0)->href;
  14. $item['title'] = trim(
  15. htmlspecialchars_decode($element->find('h4', 0)->find('a', 0)->innertext,
  16. ENT_QUOTES
  17. )
  18. );
  19. foreach($element->find('p', 0)->find('span') as $authors) {
  20. $item['author'] = $item['author'] . $authors . '; ';
  21. }
  22. $content = $element->find('p.hidden-xs', 0)->find('a', 0)->innertext . '<br>';
  23. $type = '<br>Type: ' . $element->find('span.label-default', 0)->innertext;
  24. $raw_date = $element->find('small.text-muted', 0)->innertext;
  25. $clean_date = date_parse(str_replace('Uploaded on ', '', $raw_date));
  26. $content = $content . date_parse($clean_date);
  27. $item['timestamp'] = mktime(
  28. $clean_date['hour'],
  29. $clean_date['minute'],
  30. $clean_date['second'],
  31. $clean_date['month'],
  32. $clean_date['day'],
  33. $clean_date['year']
  34. );
  35. $access = '';
  36. if ($element->find('span.label-success', 0)->innertext) {
  37. $access = 'Open Access';
  38. } elseif ($element->find('span.label-warning', 0)->innertext) {
  39. $access = 'Embargoed Access';
  40. } else {
  41. $access = $element->find('span.label-error', 0)->innertext;
  42. }
  43. $access = '<br>Access: ' . $access;
  44. $publication = '<br>Publication Date: ' . $element->find('span.label-info', 0)->innertext;
  45. $item['content'] = $content . $type . $access . $publication;
  46. $this->items[] = $item;
  47. }
  48. }
  49. }