|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +class ProjectMuseBridge extends BridgeAbstract |
| 6 | +{ |
| 7 | + const NAME = 'Project Muse'; |
| 8 | + const URI = 'https://muse.jhu.edu'; |
| 9 | + const DESCRIPTION = 'Returns the latest articles from a selected journal'; |
| 10 | + const MAINTAINER = 'tillcash'; |
| 11 | + const CACHE_TIMEOUT = 43200; // 12 hours |
| 12 | + |
| 13 | + const PARAMETERS = [ |
| 14 | + [ |
| 15 | + 'journal' => [ |
| 16 | + 'name' => 'Journal', |
| 17 | + 'type' => 'list', |
| 18 | + 'values' => [ |
| 19 | + 'Technology and Culture' => '194', |
| 20 | + ] |
| 21 | + ] |
| 22 | + ] |
| 23 | + ]; |
| 24 | + |
| 25 | + public function collectData() |
| 26 | + { |
| 27 | + $journalId = $this->getInput('journal'); |
| 28 | + $url = self::URI . '/journal/' . $journalId; |
| 29 | + |
| 30 | + $html = getSimpleHTMLDOMCached($url, self::CACHE_TIMEOUT); |
| 31 | + |
| 32 | + $latestVolumeGroup = $html->find('div.vol_group', 0); |
| 33 | + |
| 34 | + foreach ($latestVolumeGroup->find('.volume') as $issue) { |
| 35 | + $issueLink = $issue->find('a', 0); |
| 36 | + if (!$issueLink) { |
| 37 | + continue; |
| 38 | + } |
| 39 | + |
| 40 | + $issueUrl = urljoin(self::URI, $issueLink->href); |
| 41 | + $issueTitle = trim($issueLink->plaintext); |
| 42 | + |
| 43 | + $issueHtml = getSimpleHTMLDOMCached($issueUrl, self::CACHE_TIMEOUT); |
| 44 | + |
| 45 | + foreach ($issueHtml->find('#articles_list_wrap .card_text') as $article) { |
| 46 | + $titleLink = $article->find('.title h3 a', 0); |
| 47 | + if (!$titleLink) { |
| 48 | + continue; |
| 49 | + } |
| 50 | + |
| 51 | + $item = []; |
| 52 | + |
| 53 | + $fullTitle = trim($titleLink->plaintext) . ' | ' . $issueTitle; |
| 54 | + $item['title'] = html_entity_decode($fullTitle, ENT_QUOTES, 'UTF-8'); |
| 55 | + |
| 56 | + $item['uri'] = urljoin(self::URI, $titleLink->href); |
| 57 | + $item['uid'] = $item['uri']; |
| 58 | + |
| 59 | + $author = $article->find('.author span', 0); |
| 60 | + if ($author && !empty(trim($author->plaintext))) { |
| 61 | + $item['author'] = trim($author->plaintext); |
| 62 | + } |
| 63 | + |
| 64 | + $doi = $article->find('.doi', 0); |
| 65 | + $pg = $article->find('.pg', 0); |
| 66 | + |
| 67 | + $content = ''; |
| 68 | + if ($doi) { |
| 69 | + $content .= $doi->outertext; |
| 70 | + } |
| 71 | + if ($pg) { |
| 72 | + $content .= $pg->plaintext; |
| 73 | + } |
| 74 | + |
| 75 | + $item['content'] = $content; |
| 76 | + |
| 77 | + $this->items[] = $item; |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + public function getName() |
| 83 | + { |
| 84 | + $journalName = $this->getKey('journal'); |
| 85 | + if ($journalName) { |
| 86 | + return 'Project MUSE: ' . $journalName; |
| 87 | + } |
| 88 | + return parent::getName(); |
| 89 | + } |
| 90 | +} |
0 commit comments