forked from RSS-Bridge/rss-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElsevierBridge.php
44 lines (39 loc) · 1.59 KB
/
ElsevierBridge.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
<?php
class ElsevierBridge extends BridgeAbstract
{
const MAINTAINER = 'dvikan';
const NAME = 'Elsevier journals recent articles';
const URI = 'https://www.journals.elsevier.com/';
const CACHE_TIMEOUT = 43200; //12h
const DESCRIPTION = 'Returns the recent articles published in Elsevier journals';
const PARAMETERS = [ [
'j' => [
'name' => 'Journal name',
'required' => true,
'exampleValue' => 'academic-pediatrics',
'title' => 'Insert html-part of your journal'
]
]];
public function collectData()
{
// Not all journals have the /recent-articles page
$url = sprintf('https://www.journals.elsevier.com/%s/recent-articles/', $this->getInput('j'));
$html = getSimpleHTMLDOM($url);
foreach ($html->find('article') as $recentArticle) {
$item = [];
$item['uri'] = $recentArticle->find('a', 0)->getAttribute('href');
$item['title'] = $recentArticle->find('h2', 0)->plaintext;
$item['author'] = $recentArticle->find('p > span', 0)->plaintext;
$publicationDateString = trim($recentArticle->find('p > span', 1)->plaintext);
$publicationDate = DateTimeImmutable::createFromFormat('F d, Y', $publicationDateString);
if ($publicationDate) {
$item['timestamp'] = $publicationDate->getTimestamp();
}
$this->items[] = $item;
}
}
public function getIcon(): string
{
return 'https://cdn.elsevier.io/verona/includes/favicons/favicon-32x32.png';
}
}