2016-06-26 11:52:54 +02:00
|
|
|
|
<?php
|
|
|
|
|
class ElsevierBridge extends BridgeAbstract{
|
2016-08-02 21:40:22 +02:00
|
|
|
|
public function loadMetadatas() {
|
2016-06-26 11:52:54 +02:00
|
|
|
|
|
2016-08-02 21:40:22 +02:00
|
|
|
|
$this->maintainer = 'Pierre Mazière';
|
|
|
|
|
$this->name = 'Elsevier journals recent articles';
|
|
|
|
|
$this->uri = 'http://www.journals.elsevier.com';
|
|
|
|
|
$this->description = 'Returns the recent articles published in Elsevier journals';
|
2016-08-17 14:45:08 +02:00
|
|
|
|
$this->update = '2016-08-17';
|
2016-06-26 11:52:54 +02:00
|
|
|
|
|
2016-08-02 21:40:22 +02:00
|
|
|
|
$this->parameters[] =
|
|
|
|
|
'[
|
|
|
|
|
{
|
|
|
|
|
"name" : "Journal name",
|
|
|
|
|
"identifier" : "j",
|
2016-08-15 01:19:16 +02:00
|
|
|
|
"required" : true,
|
2016-08-02 21:40:22 +02:00
|
|
|
|
"exampleValue" : "academic-pediatrics",
|
|
|
|
|
"title" : "Insert html-part of your journal"
|
|
|
|
|
}
|
|
|
|
|
]';
|
|
|
|
|
}
|
2016-06-26 11:52:54 +02:00
|
|
|
|
|
2016-08-02 21:40:22 +02:00
|
|
|
|
// Extracts the list of names from an article as string
|
2016-08-06 16:00:56 +02:00
|
|
|
|
private function ExtractArticleName ($article){
|
2016-08-02 21:40:22 +02:00
|
|
|
|
$names = $article->find('small', 0);
|
|
|
|
|
if($names)
|
|
|
|
|
return trim($names->plaintext);
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2016-08-02 21:35:13 +02:00
|
|
|
|
|
2016-08-02 21:40:22 +02:00
|
|
|
|
// Extracts the timestamp from an article
|
2016-08-06 16:00:56 +02:00
|
|
|
|
private function ExtractArticleTimestamp ($article){
|
2016-08-02 21:40:22 +02:00
|
|
|
|
$time = $article->find('.article-info', 0);
|
|
|
|
|
if($time){
|
|
|
|
|
$timestring = trim($time->plaintext);
|
|
|
|
|
/*
|
|
|
|
|
The format depends on the age of an article:
|
|
|
|
|
- Available online 29 July 2016
|
|
|
|
|
- July 2016
|
|
|
|
|
- May–June 2016
|
|
|
|
|
*/
|
|
|
|
|
if(preg_match('/\S*(\d+\s\S+\s\d{4})/ims', $timestring, $matches)){
|
|
|
|
|
return strtotime($matches[0]);
|
|
|
|
|
} elseif (preg_match('/([A-Za-z]+\s\d{4})/ims', $timestring, $matches)){
|
|
|
|
|
return strtotime($matches[0]);
|
|
|
|
|
} elseif (preg_match('/[A-Za-z]+\-([A-Za-z]+\s\d{4})/ims', $timestring, $matches)){
|
|
|
|
|
return strtotime($matches[0]);
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-08-02 21:35:13 +02:00
|
|
|
|
|
2016-08-02 21:40:22 +02:00
|
|
|
|
// Extracts the content from an article
|
2016-08-06 16:00:56 +02:00
|
|
|
|
private function ExtractArticleContent ($article){
|
2016-08-02 21:40:22 +02:00
|
|
|
|
$content = $article->find('.article-content', 0);
|
|
|
|
|
if($content){
|
|
|
|
|
return trim($content->plaintext);
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2016-08-02 21:35:13 +02:00
|
|
|
|
|
2016-08-02 21:40:22 +02:00
|
|
|
|
public function collectData(array $param){
|
|
|
|
|
$uri = 'http://www.journals.elsevier.com/' . $param['j'] . '/recent-articles/';
|
2016-08-17 14:45:08 +02:00
|
|
|
|
$html = file_get_html($uri) or $this->returnServerError('No results for Elsevier journal '.$param['j']);
|
2016-06-26 11:52:54 +02:00
|
|
|
|
|
2016-08-02 21:40:22 +02:00
|
|
|
|
foreach($html->find('.pod-listing') as $article){
|
|
|
|
|
$item = new \Item();
|
|
|
|
|
$item->uri = $article->find('.pod-listing-header>a',0)->getAttribute('href').'?np=y';
|
|
|
|
|
$item->title = $article->find('.pod-listing-header>a',0)->plaintext;
|
2016-08-09 14:54:44 +02:00
|
|
|
|
$item->author = $this->ExtractArticleName($article);
|
2016-08-02 21:40:22 +02:00
|
|
|
|
$item->timestamp = $this->ExtractArticleTimestamp($article);
|
|
|
|
|
$item->content = $this->ExtractArticleContent($article);
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-26 11:52:54 +02:00
|
|
|
|
|
2016-08-02 21:40:22 +02:00
|
|
|
|
public function getCacheDuration(){
|
|
|
|
|
return 43200; // 12h
|
|
|
|
|
}
|
2016-06-26 11:52:54 +02:00
|
|
|
|
}
|
2016-08-02 21:40:22 +02:00
|
|
|
|
?>
|