diff --git a/bridges/AO3Bridge.php b/bridges/AO3Bridge.php index f55c0d45..6ca59cc5 100644 --- a/bridges/AO3Bridge.php +++ b/bridges/AO3Bridge.php @@ -34,8 +34,30 @@ class AO3Bridge extends BridgeAbstract ] ]; - // Feed for lists of works (e.g. recent works, search results, filtered tags, - // bookmarks, series, collections). + public function collectData() + { + switch ($this->queriedContext) { + case 'Bookmarks': + $user = $this->getInput('user'); + $this->title = $user; + $url = self::URI + . '/users/' . $user + . '/bookmarks?bookmark_search[sort_column]=bookmarkable_date'; + $this->collectList($url); + break; + case 'List': + $this->collectList($this->getInput('url')); + break; + case 'Work': + $this->collectWork($this->getInput('id')); + break; + } + } + + /** + * Feed for lists of works (e.g. recent works, search results, filtered tags, + * bookmarks, series, collections). + */ private function collectList($url) { $html = getSimpleHTMLDOM($url); @@ -64,11 +86,14 @@ class AO3Bridge extends BridgeAbstract } } - // Feed for recent chapters of a specific work. + /** + * Feed for recent chapters of a specific work. + */ private function collectWork($id) { $url = self::URI . "/works/$id/navigate"; - $html = getSimpleHTMLDOM($url); + $response = _http_request($url, ['useragent' => 'rss-bridge bot (https://github.com/RSS-Bridge/rss-bridge)']); + $html = \str_get_html($response['body']); $html = defaultLinkTo($html, self::URI); $this->title = $html->find('h2 a', 0)->plaintext; @@ -93,27 +118,6 @@ class AO3Bridge extends BridgeAbstract $this->items = array_reverse($this->items); } - public function collectData() - { - switch ($this->queriedContext) { - case 'Bookmarks': - $user = $this->getInput('user'); - $this->title = $user; - $url = self::URI - . '/users/' . $user - . '/bookmarks?bookmark_search[sort_column]=bookmarkable_date'; - return $this->collectList($url); - case 'List': - return $this->collectList( - $this->getInput('url') - ); - case 'Work': - return $this->collectWork( - $this->getInput('id') - ); - } - } - public function getName() { $name = parent::getName() . " $this->queriedContext"; diff --git a/lib/contents.php b/lib/contents.php index 9d452790..1d89261f 100644 --- a/lib/contents.php +++ b/lib/contents.php @@ -125,6 +125,8 @@ function getContents( $httpHeadersNormalized[$headerName] = $headerValue; } $config = [ + 'useragent' => Configuration::getConfig('http', 'useragent'), + 'timeout' => Configuration::getConfig('http', 'timeout'), 'headers' => array_merge($defaultHttpHeaders, $httpHeadersNormalized), 'curl_options' => $curlOptions, ]; @@ -215,8 +217,8 @@ function getContents( function _http_request(string $url, array $config = []): array { $defaults = [ - 'useragent' => Configuration::getConfig('http', 'useragent'), - 'timeout' => Configuration::getConfig('http', 'timeout'), + 'useragent' => null, + 'timeout' => 5, 'headers' => [], 'proxy' => null, 'curl_options' => [], @@ -236,7 +238,9 @@ function _http_request(string $url, array $config = []): array $httpHeaders[] = sprintf('%s: %s', $name, $value); } curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders); - curl_setopt($ch, CURLOPT_USERAGENT, $config['useragent']); + if ($config['useragent']) { + curl_setopt($ch, CURLOPT_USERAGENT, $config['useragent']); + } curl_setopt($ch, CURLOPT_TIMEOUT, $config['timeout']); curl_setopt($ch, CURLOPT_ENCODING, ''); curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);