2016-06-26 12:52:54 +03:00
|
|
|
|
<?php
|
2017-02-11 18:16:56 +03:00
|
|
|
|
class ElsevierBridge extends BridgeAbstract {
|
|
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
|
const MAINTAINER = 'Pierre Mazière';
|
|
|
|
|
const NAME = 'Elsevier journals recent articles';
|
|
|
|
|
const URI = 'http://www.journals.elsevier.com/';
|
2016-09-25 18:04:28 +03:00
|
|
|
|
const CACHE_TIMEOUT = 43200; //12h
|
2016-08-30 12:23:55 +03:00
|
|
|
|
const DESCRIPTION = 'Returns the recent articles published in Elsevier journals';
|
2016-06-26 12:52:54 +03:00
|
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
|
const PARAMETERS = array( array(
|
|
|
|
|
'j' => array(
|
|
|
|
|
'name' => 'Journal name',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'exampleValue' => 'academic-pediactrics',
|
|
|
|
|
'title' => 'Insert html-part of your journal'
|
|
|
|
|
)
|
|
|
|
|
));
|
2016-06-26 12:52:54 +03:00
|
|
|
|
|
2016-08-02 22:40:22 +03:00
|
|
|
|
// Extracts the list of names from an article as string
|
2017-02-11 18:16:56 +03:00
|
|
|
|
private function extractArticleName($article){
|
2016-08-02 22:40:22 +03:00
|
|
|
|
$names = $article->find('small', 0);
|
|
|
|
|
if($names)
|
|
|
|
|
return trim($names->plaintext);
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2016-08-02 22:35:13 +03:00
|
|
|
|
|
2016-08-02 22:40:22 +03:00
|
|
|
|
// Extracts the timestamp from an article
|
2017-02-11 18:16:56 +03:00
|
|
|
|
private function extractArticleTimestamp($article){
|
2016-08-02 22:40:22 +03:00
|
|
|
|
$time = $article->find('.article-info', 0);
|
2017-07-29 20:28:00 +03:00
|
|
|
|
if($time) {
|
2016-08-02 22:40:22 +03:00
|
|
|
|
$timestring = trim($time->plaintext);
|
2016-07-08 20:06:35 +03:00
|
|
|
|
/*
|
2016-08-02 22:40:22 +03:00
|
|
|
|
The format depends on the age of an article:
|
|
|
|
|
- Available online 29 July 2016
|
|
|
|
|
- July 2016
|
|
|
|
|
- May–June 2016
|
|
|
|
|
*/
|
2017-07-29 20:28:00 +03:00
|
|
|
|
if(preg_match('/\S*(\d+\s\S+\s\d{4})/ims', $timestring, $matches)) {
|
2016-08-02 22:40:22 +03:00
|
|
|
|
return strtotime($matches[0]);
|
2017-07-29 20:28:00 +03:00
|
|
|
|
} elseif (preg_match('/[A-Za-z]+\-([A-Za-z]+\s\d{4})/ims', $timestring, $matches)) {
|
2016-08-02 22:40:22 +03:00
|
|
|
|
return strtotime($matches[0]);
|
2017-07-29 20:28:00 +03:00
|
|
|
|
} elseif (preg_match('/([A-Za-z]+\s\d{4})/ims', $timestring, $matches)) {
|
2016-08-19 19:50:50 +03:00
|
|
|
|
return strtotime($matches[0]);
|
2016-08-02 22:40:22 +03:00
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-08-02 22:35:13 +03:00
|
|
|
|
|
2016-08-02 22:40:22 +03:00
|
|
|
|
// Extracts the content from an article
|
2017-02-11 18:16:56 +03:00
|
|
|
|
private function extractArticleContent($article){
|
2016-08-02 22:40:22 +03:00
|
|
|
|
$content = $article->find('.article-content', 0);
|
2017-07-29 20:28:00 +03:00
|
|
|
|
if($content) {
|
2016-08-02 22:40:22 +03:00
|
|
|
|
return trim($content->plaintext);
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2016-08-02 22:35:13 +03:00
|
|
|
|
|
2018-10-26 19:07:34 +03:00
|
|
|
|
public function getIcon() {
|
|
|
|
|
return 'https://cdn.elsevier.io/verona/includes/favicons/favicon-32x32.png';
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
|
public function collectData(){
|
2016-08-30 12:23:55 +03:00
|
|
|
|
$uri = self::URI . $this->getInput('j') . '/recent-articles/';
|
2017-02-11 18:16:56 +03:00
|
|
|
|
$html = getSimpleHTMLDOM($uri)
|
|
|
|
|
or returnServerError('No results for Elsevier journal ' . $this->getInput('j'));
|
2016-06-26 12:52:54 +03:00
|
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
|
foreach($html->find('.pod-listing') as $article) {
|
2016-08-22 19:55:59 +03:00
|
|
|
|
$item = array();
|
2017-02-11 18:16:56 +03:00
|
|
|
|
$item['uri'] = $article->find('.pod-listing-header>a', 0)->getAttribute('href') . '?np=y';
|
|
|
|
|
$item['title'] = $article->find('.pod-listing-header>a', 0)->plaintext;
|
|
|
|
|
$item['author'] = $this->extractArticleName($article);
|
|
|
|
|
$item['timestamp'] = $this->extractArticleTimestamp($article);
|
|
|
|
|
$item['content'] = $this->extractArticleContent($article);
|
2016-08-02 22:40:22 +03:00
|
|
|
|
$this->items[] = $item;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-26 12:52:54 +03:00
|
|
|
|
}
|