aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/ConnectivityAction.php4
-rw-r--r--bridges/BadDragonBridge.php3
-rw-r--r--bridges/BandcampBridge.php11
-rw-r--r--bridges/CubariBridge.php4
-rw-r--r--bridges/DemosBerlinBridge.php3
-rw-r--r--bridges/DerpibooruBridge.php10
-rw-r--r--bridges/EZTVBridge.php4
-rw-r--r--bridges/ElloBridge.php8
-rw-r--r--bridges/FDroidBridge.php2
-rw-r--r--bridges/FunkBridge.php2
-rw-r--r--bridges/GlowficBridge.php6
-rw-r--r--bridges/InternationalInstituteForStrategicStudiesBridge.php2
-rw-r--r--bridges/ItakuBridge.php4
-rw-r--r--bridges/KilledbyGoogleBridge.php3
-rw-r--r--bridges/LegoIdeasBridge.php3
-rw-r--r--bridges/OpenCVEBridge.php13
-rw-r--r--bridges/PepperBridgeAbstract.php7
-rw-r--r--bridges/PixivBridge.php17
-rw-r--r--bridges/RainbowSixSiegeBridge.php2
-rw-r--r--bridges/RedditBridge.php2
-rw-r--r--bridges/ReutersBridge.php4
-rw-r--r--bridges/RoadAndTrackBridge.php5
-rw-r--r--bridges/SpotifyBridge.php4
-rw-r--r--bridges/SummitsOnTheAirBridge.php8
-rw-r--r--bridges/TwitterV2Bridge.php2
-rw-r--r--bridges/UnogsBridge.php2
-rw-r--r--bridges/VkBridge.php6
-rw-r--r--lib/contents.php12
28 files changed, 69 insertions, 84 deletions
diff --git a/actions/ConnectivityAction.php b/actions/ConnectivityAction.php
index 09d9c6c6..eb9edeb1 100644
--- a/actions/ConnectivityAction.php
+++ b/actions/ConnectivityAction.php
@@ -54,8 +54,8 @@ class ConnectivityAction implements ActionInterface
];
try {
$response = getContents($bridge::URI, [], $curl_opts, true);
- $result['http_code'] = $response['code'];
- if (in_array($response['code'], [200])) {
+ $result['http_code'] = $response->getCode();
+ if (in_array($result['http_code'], [200])) {
$result['successful'] = true;
}
} catch (\Exception $e) {
diff --git a/bridges/BadDragonBridge.php b/bridges/BadDragonBridge.php
index d38e3408..2249d6f7 100644
--- a/bridges/BadDragonBridge.php
+++ b/bridges/BadDragonBridge.php
@@ -284,8 +284,7 @@ class BadDragonBridge extends BridgeAbstract
case 'Clearance':
$toyData = json_decode(getContents($this->inputToURL(true)));
- $productList = json_decode(getContents(self::URI
- . 'api/inventory-toy/product-list'));
+ $productList = json_decode(getContents(self::URI . 'api/inventory-toy/product-list'));
foreach ($toyData->toys as $toy) {
$item = [];
diff --git a/bridges/BandcampBridge.php b/bridges/BandcampBridge.php
index a9bd2ea1..80bb7fd0 100644
--- a/bridges/BandcampBridge.php
+++ b/bridges/BandcampBridge.php
@@ -111,12 +111,12 @@ class BandcampBridge extends BridgeAbstract
$url = self::URI . 'api/hub/1/dig_deeper';
$data = $this->buildRequestJson();
$header = [
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data)
+ 'Content-Type: application/json',
+ 'Content-Length: ' . strlen($data),
];
$opts = [
- CURLOPT_CUSTOMREQUEST => 'POST',
- CURLOPT_POSTFIELDS => $data
+ CURLOPT_CUSTOMREQUEST => 'POST',
+ CURLOPT_POSTFIELDS => $data,
];
$content = getContents($url, $header, $opts);
@@ -314,7 +314,8 @@ class BandcampBridge extends BridgeAbstract
{
$url = self::URI . 'api/' . $endpoint . '?' . http_build_query($query_data);
// todo: 429 Too Many Requests happens a lot
- $data = json_decode(getContents($url));
+ $response = getContents($url);
+ $data = json_decode($response);
return $data;
}
diff --git a/bridges/CubariBridge.php b/bridges/CubariBridge.php
index a7b6d69d..72fadf6e 100644
--- a/bridges/CubariBridge.php
+++ b/bridges/CubariBridge.php
@@ -47,8 +47,10 @@ class CubariBridge extends BridgeAbstract
*/
public function collectData()
{
+ // TODO: fix trivial SSRF
$json = getContents($this->getInput('gist'));
- $jsonFile = json_decode($json, true);
+
+ $jsonFile = Json::decode($json);
$this->mangaTitle = $jsonFile['title'];
diff --git a/bridges/DemosBerlinBridge.php b/bridges/DemosBerlinBridge.php
index 05fd2335..cc44a7cf 100644
--- a/bridges/DemosBerlinBridge.php
+++ b/bridges/DemosBerlinBridge.php
@@ -24,7 +24,8 @@ class DemosBerlinBridge extends BridgeAbstract
public function collectData()
{
- $json = getContents('https://www.berlin.de/polizei/service/versammlungsbehoerde/versammlungen-aufzuege/index.php/index/all.json');
+ $url = 'https://www.berlin.de/polizei/service/versammlungsbehoerde/versammlungen-aufzuege/index.php/index/all.json';
+ $json = getContents($url);
$jsonFile = json_decode($json, true);
$daysInterval = DateInterval::createFromDateString($this->getInput('days') . ' day');
diff --git a/bridges/DerpibooruBridge.php b/bridges/DerpibooruBridge.php
index e06e0eff..2d650d57 100644
--- a/bridges/DerpibooruBridge.php
+++ b/bridges/DerpibooruBridge.php
@@ -78,13 +78,9 @@ class DerpibooruBridge extends BridgeAbstract
public function collectData()
{
- $queryJson = json_decode(getContents(
- self::URI
- . 'api/v1/json/search/images?filter_id='
- . urlencode($this->getInput('f'))
- . '&q='
- . urlencode($this->getInput('q'))
- ));
+ $url = self::URI . 'api/v1/json/search/images?filter_id=' . urlencode($this->getInput('f')) . '&q=' . urlencode($this->getInput('q'));
+
+ $queryJson = json_decode(getContents($url));
foreach ($queryJson->images as $post) {
$item = [];
diff --git a/bridges/EZTVBridge.php b/bridges/EZTVBridge.php
index 25a88124..556bd39e 100644
--- a/bridges/EZTVBridge.php
+++ b/bridges/EZTVBridge.php
@@ -50,7 +50,9 @@ class EZTVBridge extends BridgeAbstract
$eztv_uri = $this->getEztvUri();
$ids = explode(',', trim($this->getInput('ids')));
foreach ($ids as $id) {
- $data = json_decode(getContents(sprintf('%s/api/get-torrents?imdb_id=%s', $eztv_uri, $id)));
+ $url = sprintf('%s/api/get-torrents?imdb_id=%s', $eztv_uri, $id);
+ $json = getContents($url);
+ $data = json_decode($json);
if (!isset($data->torrents)) {
// No results
continue;
diff --git a/bridges/ElloBridge.php b/bridges/ElloBridge.php
index 42c88a06..a9e69cfe 100644
--- a/bridges/ElloBridge.php
+++ b/bridges/ElloBridge.php
@@ -34,11 +34,9 @@ class ElloBridge extends BridgeAbstract
];
if (!empty($this->getInput('u'))) {
- $postData = getContents(self::URI . 'api/v2/users/~' . urlencode($this->getInput('u')) . '/posts', $header) or
- returnServerError('Unable to query Ello API.');
+ $postData = getContents(self::URI . 'api/v2/users/~' . urlencode($this->getInput('u')) . '/posts', $header);
} else {
- $postData = getContents(self::URI . 'api/v2/posts?terms=' . urlencode($this->getInput('s')), $header) or
- returnServerError('Unable to query Ello API.');
+ $postData = getContents(self::URI . 'api/v2/posts?terms=' . urlencode($this->getInput('s')), $header);
}
$postData = json_decode($postData);
@@ -117,7 +115,7 @@ class ElloBridge extends BridgeAbstract
$apiKey = $this->cache->get($cacheKey);
if (!$apiKey) {
- $keyInfo = getContents(self::URI . 'api/webapp-token') or returnServerError('Unable to get token.');
+ $keyInfo = getContents(self::URI . 'api/webapp-token');
$apiKey = json_decode($keyInfo)->token->access_token;
$ttl = 60 * 60 * 20;
$this->cache->set($cacheKey, $apiKey, $ttl);
diff --git a/bridges/FDroidBridge.php b/bridges/FDroidBridge.php
index 8d3b7808..fdf0262f 100644
--- a/bridges/FDroidBridge.php
+++ b/bridges/FDroidBridge.php
@@ -31,7 +31,7 @@ class FDroidBridge extends BridgeAbstract
CURLOPT_NOBODY => true,
];
$reponse = getContents($url, [], $curlOptions, true);
- $lastModified = $reponse['headers']['last-modified'][0] ?? null;
+ $lastModified = $reponse->getHeader('last-modified');
$timestamp = strtotime($lastModified ?? 'today');
return $timestamp;
}
diff --git a/bridges/FunkBridge.php b/bridges/FunkBridge.php
index df499035..e4935ffb 100644
--- a/bridges/FunkBridge.php
+++ b/bridges/FunkBridge.php
@@ -32,7 +32,7 @@ class FunkBridge extends BridgeAbstract
$url .= '?size=' . $this->getInput('max');
}
- $jsonString = getContents($url) or returnServerError('No contents received!');
+ $jsonString = getContents($url);
$json = json_decode($jsonString, true);
foreach ($json['list'] as $element) {
diff --git a/bridges/GlowficBridge.php b/bridges/GlowficBridge.php
index b51ead8d..0e4b8d93 100644
--- a/bridges/GlowficBridge.php
+++ b/bridges/GlowficBridge.php
@@ -41,8 +41,7 @@ class GlowficBridge extends BridgeAbstract
$first_page = 1;
}
for ($page_offset = $first_page; $page_offset <= $metadata['Last-Page']; $page_offset++) {
- $jsonContents = getContents($url . '/replies?page=' . $page_offset) or
- returnClientError('Could not retrieve replies for page ' . $page_offset . '.');
+ $jsonContents = getContents($url . '/replies?page=' . $page_offset);
$replies = json_decode($jsonContents);
foreach ($replies as $reply) {
$item = [];
@@ -75,8 +74,9 @@ class GlowficBridge extends BridgeAbstract
private function getPost()
{
$url = $this->getAPIURI();
- $jsonPost = getContents($url) or returnClientError('Could not retrieve post metadata.');
+ $jsonPost = getContents($url);
$post = json_decode($jsonPost);
+
return $post;
}
diff --git a/bridges/InternationalInstituteForStrategicStudiesBridge.php b/bridges/InternationalInstituteForStrategicStudiesBridge.php
index b5b589ab..9b82dbd5 100644
--- a/bridges/InternationalInstituteForStrategicStudiesBridge.php
+++ b/bridges/InternationalInstituteForStrategicStudiesBridge.php
@@ -30,7 +30,7 @@ class InternationalInstituteForStrategicStudiesBridge extends BridgeAbstract
];
$headers = [
'Accept: application/json, text/plain, */*',
- 'Content-Type: application/json;charset=UTF-8'
+ 'Content-Type: application/json;charset=UTF-8',
];
$json = getContents($url, $headers, $opts);
$data = json_decode($json);
diff --git a/bridges/ItakuBridge.php b/bridges/ItakuBridge.php
index 4f414574..506805f7 100644
--- a/bridges/ItakuBridge.php
+++ b/bridges/ItakuBridge.php
@@ -669,11 +669,11 @@ class ItakuBridge extends BridgeAbstract
if ($cache) {
$data = $this->loadCacheValue($url);
if (is_null($data)) {
- $data = getContents($url, $httpHeaders, $curlOptions) or returnServerError("Could not load $url");
+ $data = getContents($url, $httpHeaders, $curlOptions);
$this->saveCacheValue($url, $data);
}
} else {
- $data = getContents($url, $httpHeaders, $curlOptions) or returnServerError("Could not load $url");
+ $data = getContents($url, $httpHeaders, $curlOptions);
}
return json_decode($data, true);
} else { //get simpleHTMLDOM object
diff --git a/bridges/KilledbyGoogleBridge.php b/bridges/KilledbyGoogleBridge.php
index 54c5b59f..7b8f7f6e 100644
--- a/bridges/KilledbyGoogleBridge.php
+++ b/bridges/KilledbyGoogleBridge.php
@@ -12,8 +12,7 @@ class KilledbyGoogleBridge extends BridgeAbstract
public function collectData()
{
- $json = getContents(self::URI . '/graveyard.json')
- or returnServerError('Could not request: ' . self::URI . '/graveyard.json');
+ $json = getContents(self::URI . '/graveyard.json');
$this->handleJson($json);
$this->orderItems();
diff --git a/bridges/LegoIdeasBridge.php b/bridges/LegoIdeasBridge.php
index c4361f1f..e983e56d 100644
--- a/bridges/LegoIdeasBridge.php
+++ b/bridges/LegoIdeasBridge.php
@@ -52,8 +52,7 @@ Once a project reaches 10,000 supporters, it gets reviewed by the lego experts.'
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $this->getHttpPostData()
];
- $responseData = getContents($this->getHttpPostURI(), $header, $opts) or
- returnServerError('Unable to query Lego Ideas API.');
+ $responseData = getContents($this->getHttpPostURI(), $header, $opts);
foreach (json_decode($responseData)->results as $project) {
preg_match('/datetime=\"(\S+)\"/', $project->entity->published_at, $date_matches);
diff --git a/bridges/OpenCVEBridge.php b/bridges/OpenCVEBridge.php
index 594bb9ec..b5fc852b 100644
--- a/bridges/OpenCVEBridge.php
+++ b/bridges/OpenCVEBridge.php
@@ -147,10 +147,9 @@ class OpenCVEBridge extends BridgeAbstract
for ($i = 1; $i <= $this->getInput('pages'); $i++) {
$queryPaginated = array_merge($query, ['page' => $i]);
$url = $instance . '/api/cve?' . http_build_query($queryPaginated);
- $response = getContents(
- $url,
- [$authHeader]
- );
+
+ $response = getContents($url, [$authHeader]);
+
$titlePrefix = '';
if (count($queries) > 1) {
$titlePrefix = '[' . $queryName . '] ';
@@ -205,10 +204,8 @@ class OpenCVEBridge extends BridgeAbstract
private function fetchContents($cveItem, $titlePrefix, $instance, $authHeader)
{
$url = $instance . '/api/cve/' . $cveItem->id;
- $response = getContents(
- $url,
- [$authHeader]
- );
+
+ $response = getContents($url, [$authHeader]);
$datum = json_decode($response);
$title = $this->getTitleFromDatum($datum, $titlePrefix);
diff --git a/bridges/PepperBridgeAbstract.php b/bridges/PepperBridgeAbstract.php
index 6e41cf20..4e9ab0b5 100644
--- a/bridges/PepperBridgeAbstract.php
+++ b/bridges/PepperBridgeAbstract.php
@@ -191,15 +191,12 @@ HEREDOC;
}
}
- /**
- * Extract the cookies obtained from the URL
- * @return array the array containing the cookies set by the URL
- */
private function getCookiesHeaderValue($url)
{
$response = getContents($url, [], [], true);
- $setCookieHeaders = $response['headers']['set-cookie'] ?? [];
+ $setCookieHeaders = $response->getHeader('set-cookie', true);
$cookies = array_map(fn($c): string => explode(';', $c)[0], $setCookieHeaders);
+
return implode('; ', $cookies);
}
diff --git a/bridges/PixivBridge.php b/bridges/PixivBridge.php
index 604b5d4b..820b3a7c 100644
--- a/bridges/PixivBridge.php
+++ b/bridges/PixivBridge.php
@@ -332,21 +332,20 @@ class PixivBridge extends BridgeAbstract
}
if ($cache) {
- $data = $this->loadCacheValue($url);
- if (!$data) {
- $data = getContents($url, $httpHeaders, $curlOptions, true);
- $this->saveCacheValue($url, $data);
+ $response = $this->loadCacheValue($url);
+ if (!$response || is_array($response)) {
+ $response = getContents($url, $httpHeaders, $curlOptions, true);
+ $this->saveCacheValue($url, $response);
}
} else {
- $data = getContents($url, $httpHeaders, $curlOptions, true);
+ $response = getContents($url, $httpHeaders, $curlOptions, true);
}
- $this->checkCookie($data['headers']);
+ $this->checkCookie($response->getHeaders());
if ($getJSON) {
- return json_decode($data['content'], true);
- } else {
- return $data['content'];
+ return json_decode($response->getBody(), true);
}
+ return $response->getBody();
}
}
diff --git a/bridges/RainbowSixSiegeBridge.php b/bridges/RainbowSixSiegeBridge.php
index 77495a3c..d725e3e9 100644
--- a/bridges/RainbowSixSiegeBridge.php
+++ b/bridges/RainbowSixSiegeBridge.php
@@ -22,7 +22,7 @@ class RainbowSixSiegeBridge extends BridgeAbstract
$dlUrl = $dlUrl . '&limit=6&mediaFilter=all&skip=0&startIndex=0&tags=BR-rainbow-six%20GA-siege';
$dlUrl = $dlUrl . '&locale=en-us&fallbackLocale=en-us&environment=master';
$jsonString = getContents($dlUrl, [
- 'Authorization: ' . self::NIMBUS_API_KEY
+ 'Authorization: ' . self::NIMBUS_API_KEY,
]);
$json = json_decode($jsonString, true);
diff --git a/bridges/RedditBridge.php b/bridges/RedditBridge.php
index 434ae74a..ef74fdcd 100644
--- a/bridges/RedditBridge.php
+++ b/bridges/RedditBridge.php
@@ -149,7 +149,7 @@ class RedditBridge extends BridgeAbstract
$response = getContents($url, ['User-Agent: ' . $useragent], [], true);
- $json = $response['content'];
+ $json = $response->getBody();
$parsedJson = Json::decode($json, false);
diff --git a/bridges/ReutersBridge.php b/bridges/ReutersBridge.php
index fdf4e2a9..07b3061c 100644
--- a/bridges/ReutersBridge.php
+++ b/bridges/ReutersBridge.php
@@ -417,9 +417,11 @@ class ReutersBridge extends BridgeAbstract
$get_embed_url = 'https://publish.twitter.com/oembed?url='
. urlencode($tweet_url) .
'&partner=&hide_thread=false';
+
$oembed_json = json_decode(getContents($get_embed_url), true);
$embed .= $oembed_json['html'];
- } catch (Exception $e) { // In case not found any tweet.
+ } catch (\Exception $e) {
+ // In case not found any tweet.
$embed .= '';
}
break;
diff --git a/bridges/RoadAndTrackBridge.php b/bridges/RoadAndTrackBridge.php
index c236036c..eb2dcc53 100644
--- a/bridges/RoadAndTrackBridge.php
+++ b/bridges/RoadAndTrackBridge.php
@@ -68,9 +68,4 @@ class RoadAndTrackBridge extends BridgeAbstract
$item['content'] = $content;
return $item;
}
-
- private function getArticleContent($article)
- {
- return getContents($article->contentUrl);
- }
}
diff --git a/bridges/SpotifyBridge.php b/bridges/SpotifyBridge.php
index 25948011..e03d43a1 100644
--- a/bridges/SpotifyBridge.php
+++ b/bridges/SpotifyBridge.php
@@ -286,9 +286,9 @@ class SpotifyBridge extends BridgeAbstract
} else {
$basicAuth = base64_encode(sprintf('%s:%s', $this->getInput('clientid'), $this->getInput('clientsecret')));
$json = getContents('https://accounts.spotify.com/api/token', [
- "Authorization: Basic $basicAuth"
+ "Authorization: Basic $basicAuth",
], [
- CURLOPT_POSTFIELDS => 'grant_type=client_credentials'
+ CURLOPT_POSTFIELDS => 'grant_type=client_credentials',
]);
$data = Json::decode($json);
$this->token = $data['access_token'];
diff --git a/bridges/SummitsOnTheAirBridge.php b/bridges/SummitsOnTheAirBridge.php
index 53bba7ab..17431214 100644
--- a/bridges/SummitsOnTheAirBridge.php
+++ b/bridges/SummitsOnTheAirBridge.php
@@ -20,8 +20,12 @@ class SummitsOnTheAirBridge extends BridgeAbstract
public function collectData()
{
- $header = ['Content-type:application/json'];
- $opts = [CURLOPT_HTTPGET => 1];
+ $header = [
+ 'Content-type:application/json',
+ ];
+ $opts = [
+ CURLOPT_HTTPGET => 1,
+ ];
$json = getContents($this->getURI() . $this->getInput('c'), $header, $opts);
$spots = json_decode($json, true);
diff --git a/bridges/TwitterV2Bridge.php b/bridges/TwitterV2Bridge.php
index 83bfae29..07af8301 100644
--- a/bridges/TwitterV2Bridge.php
+++ b/bridges/TwitterV2Bridge.php
@@ -598,7 +598,7 @@ EXTERNAL;
private function makeApiCall($api, $authHeaders, $params)
{
$uri = self::API_URI . $api . '?' . http_build_query($params);
- $result = getContents($uri, $authHeaders, [], false);
+ $result = getContents($uri, $authHeaders);
$data = json_decode($result);
return $data;
}
diff --git a/bridges/UnogsBridge.php b/bridges/UnogsBridge.php
index 486bac3d..7aff10c6 100644
--- a/bridges/UnogsBridge.php
+++ b/bridges/UnogsBridge.php
@@ -92,7 +92,7 @@ class UnogsBridge extends BridgeAbstract
{
$header = [
'Referer: https://unogs.com/',
- 'referrer: http://unogs.com'
+ 'referrer: http://unogs.com',
];
$raw = getContents($url, $header);
diff --git a/bridges/VkBridge.php b/bridges/VkBridge.php
index 980b4154..22957f26 100644
--- a/bridges/VkBridge.php
+++ b/bridges/VkBridge.php
@@ -511,11 +511,11 @@ class VkBridge extends BridgeAbstract
while ($redirects < 2) {
$response = getContents($uri, $httpHeaders, [CURLOPT_FOLLOWLOCATION => false], true);
- if (in_array($response['code'], [200, 304])) {
- return $response['content'];
+ if (in_array($response->getCode(), [200, 304])) {
+ return $response->getBody();
}
- $headers = $response['headers'];
+ $headers = $response->getHeaders();
$uri = urljoin(self::URI, $headers['location'][0]);
if (str_contains($uri, '/429.html')) {
diff --git a/lib/contents.php b/lib/contents.php
index ba6dd531..893a3512 100644
--- a/lib/contents.php
+++ b/lib/contents.php
@@ -5,8 +5,8 @@
*
* @param array $httpHeaders E.g. ['Content-type: text/plain']
* @param array $curlOptions Associative array e.g. [CURLOPT_MAXREDIRS => 3]
- * @param bool $returnFull Whether to return an array: ['code' => int, 'headers' => array, 'content' => string]
- * @return string|array
+ * @param bool $returnFull Whether to return Response object
+ * @return string|Response
*/
function getContents(
string $url,
@@ -113,13 +113,7 @@ function getContents(
throw $e;
}
if ($returnFull === true) {
- // todo: return the actual response object
- return [
- 'code' => $response->getCode(),
- 'headers' => $response->getHeaders(),
- // For legacy reasons, use 'content' instead of 'body'
- 'content' => $response->getBody(),
- ];
+ return $response;
}
return $response->getBody();
}