From 9ac494b3508625e1e28abee063f34f1bba5f1fd1 Mon Sep 17 00:00:00 2001 From: Yaman Qalieh Date: Fri, 17 Jun 2022 14:00:31 -0400 Subject: [PATCH] [AstrophysicsDataSystemBridge] Add bridge (#2796) --- bridges/AstrophysicsDataSystemBridge.php | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 bridges/AstrophysicsDataSystemBridge.php diff --git a/bridges/AstrophysicsDataSystemBridge.php b/bridges/AstrophysicsDataSystemBridge.php new file mode 100644 index 00000000..86d09be2 --- /dev/null +++ b/bridges/AstrophysicsDataSystemBridge.php @@ -0,0 +1,49 @@ + array( + 'query' => array( + 'name' => 'query', + 'title' => 'Same format as the search bar on the website', + 'exampleValue' => 'author:"huchra, john"', + 'required' => true + ) + )); + + private $feedTitle; + + public function getName() { + if ($this->queriedContext === 'Publications') { + return $this->feedTitle; + } + return parent::getName(); + } + + public function getURI() { + if ($this->queriedContext === 'Publications') { + return self::URI . '/search/?q=' . urlencode($this->getInput('query')); + } + return parent::getURI(); + } + + public function collectData() { + $headers = array ( + 'Cookie: core=always;' + ); + $html = str_get_html(defaultLinkTo(getContents($this->getURI(), $headers), self::URI)); + $this->feedTitle = html_entity_decode($html->find('title', 0)->plaintext); + foreach($html->find('div.row > ul > li') as $pub) { + $item = array(); + $item['title'] = $pub->find('h3.s-results-title', 0)->plaintext; + $item['content'] = $pub->find('div.s-results-links', 0); + $item['uri'] = $pub->find('a.abs-redirect-link', 0)->href; + $item['author'] = rtrim($pub->find('li.article-author', 0)->plaintext, ' ;'); + $item['timestamp'] = $pub->find('div[aria-label="date published"]', 0)->plaintext; + $this->items[] = $item; + } + } +}