Update all UrlHelper::fetch() calls to use the associative array approach.

The other approach (passing in individual params) was marked as deprecated a few years ago.
This commit is contained in:
wn_ 2023-12-30 15:38:41 +00:00
parent a882eb13f7
commit 90e7bf7cc3
13 changed files with 39 additions and 36 deletions

View File

@ -1145,7 +1145,7 @@ class Feeds extends Handler_Protected {
}, },
$url, $auth_login, $auth_pass); $url, $auth_login, $auth_pass);
$contents = UrlHelper::fetch($url, false, $auth_login, $auth_pass); $contents = UrlHelper::fetch(['url' => $url, 'login' => $auth_login, 'pass' => $auth_pass]);
PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_SUBSCRIBE_FEED, PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_SUBSCRIBE_FEED,
function ($result) use (&$contents) { function ($result) use (&$contents) {

View File

@ -2007,7 +2007,7 @@ class RSSUtils {
$favicon_urls = []; $favicon_urls = [];
if ($html = @UrlHelper::fetch($url)) { if ($html = @UrlHelper::fetch(['url' => $url])) {
$doc = new DOMDocument(); $doc = new DOMDocument();
if (@$doc->loadHTML($html)) { if (@$doc->loadHTML($html)) {

View File

@ -10,9 +10,10 @@ class Af_Comics_Cad extends Af_ComicFilter {
if (strpos($article["title"], "News:") === false) { if (strpos($article["title"], "News:") === false) {
$doc = new DOMDocument(); $doc = new DOMDocument();
$res = UrlHelper::fetch($article["link"], false, false, false, $res = UrlHelper::fetch([
false, false, 0, 'url' => $article['link'],
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); 'useragent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0',
]);
if (!$res && UrlHelper::$fetch_last_error_content) if (!$res && UrlHelper::$fetch_last_error_content)
$res = UrlHelper::$fetch_last_error_content; $res = UrlHelper::$fetch_last_error_content;

View File

@ -11,9 +11,10 @@ class Af_Comics_ComicClass extends Af_ComicFilter {
// lol at people who block clients by user agent // lol at people who block clients by user agent
// oh noes my ad revenue Q_Q // oh noes my ad revenue Q_Q
$res = UrlHelper::fetch($article["link"], false, false, false, $res = UrlHelper::fetch([
false, false, 0, 'url' => $article['link'],
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); 'useragent' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
]);
$doc = new DOMDocument(); $doc = new DOMDocument();

View File

@ -8,10 +8,10 @@ class Af_Comics_DarkLegacy extends Af_ComicFilter {
function process(&$article) { function process(&$article) {
if (strpos($article["guid"], "darklegacycomics.com") !== false) { if (strpos($article["guid"], "darklegacycomics.com") !== false) {
$res = UrlHelper::fetch([
$res = UrlHelper::fetch($article["link"], false, false, false, 'url' => $article['link'],
false, false, 0, 'useragent' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); ]);
if (!$res && UrlHelper::$fetch_last_error_content) if (!$res && UrlHelper::$fetch_last_error_content)
$res = UrlHelper::$fetch_last_error_content; $res = UrlHelper::$fetch_last_error_content;

View File

@ -9,10 +9,10 @@ class Af_Comics_Dilbert extends Af_ComicFilter {
function process(&$article) { function process(&$article) {
if (strpos($article["link"], "dilbert.com") !== false || if (strpos($article["link"], "dilbert.com") !== false ||
strpos($article["link"], "/DilbertDailyStrip") !== false) { strpos($article["link"], "/DilbertDailyStrip") !== false) {
$res = UrlHelper::fetch([
$res = UrlHelper::fetch($article["link"], false, false, false, 'url' => $article['link'],
false, false, 0, 'useragent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0',
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); ]);
if (!$res && UrlHelper::$fetch_last_error_content) if (!$res && UrlHelper::$fetch_last_error_content)
$res = UrlHelper::$fetch_last_error_content; $res = UrlHelper::$fetch_last_error_content;

View File

@ -11,7 +11,7 @@ class Af_Comics_Explosm extends Af_ComicFilter {
$doc = new DOMDocument(); $doc = new DOMDocument();
if (@$doc->loadHTML(UrlHelper::fetch($article["link"]))) { if (@$doc->loadHTML(UrlHelper::fetch(['url' => $article['link']]))) {
$xpath = new DOMXPath($doc); $xpath = new DOMXPath($doc);
$basenode = $xpath->query('//div[contains(@class, "MainComic__ComicImage")]//img')->item(0); $basenode = $xpath->query('//div[contains(@class, "MainComic__ComicImage")]//img')->item(0);

View File

@ -10,7 +10,7 @@ class Af_Comics_Pa extends Af_ComicFilter {
$doc = new DOMDocument(); $doc = new DOMDocument();
if ($doc->loadHTML(UrlHelper::fetch($article["link"]))) { if ($doc->loadHTML(UrlHelper::fetch(['url' => $article['link']]))) {
$xpath = new DOMXPath($doc); $xpath = new DOMXPath($doc);
$basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0); $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0);
@ -25,7 +25,7 @@ class Af_Comics_Pa extends Af_ComicFilter {
if (strpos($article["link"], "penny-arcade.com") !== false && strpos($article["title"], "News Post:") !== false) { if (strpos($article["link"], "penny-arcade.com") !== false && strpos($article["title"], "News Post:") !== false) {
$doc = new DOMDocument(); $doc = new DOMDocument();
$res = UrlHelper::fetch($article["link"]); $res = UrlHelper::fetch(['url' => $article['link']]);
if ($res && $doc->loadHTML($res)) { if ($res && $doc->loadHTML($res)) {
$xpath = new DOMXPath($doc); $xpath = new DOMXPath($doc);

View File

@ -7,10 +7,10 @@ class Af_Comics_Pvp extends Af_ComicFilter {
function process(&$article) { function process(&$article) {
if (strpos($article["guid"], "pvponline.com") !== false) { if (strpos($article["guid"], "pvponline.com") !== false) {
$res = UrlHelper::fetch([
$res = UrlHelper::fetch($article["link"], false, false, false, 'url' => $article['link'],
false, false, 0, 'useragent' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); ]);
$doc = new DOMDocument(); $doc = new DOMDocument();

View File

@ -8,15 +8,16 @@ class Af_Comics_Tfd extends Af_ComicFilter {
function process(&$article) { function process(&$article) {
if (strpos($article["link"], "toothpastefordinner.com") !== false || if (strpos($article["link"], "toothpastefordinner.com") !== false ||
strpos($article["link"], "marriedtothesea.com") !== false) { strpos($article["link"], "marriedtothesea.com") !== false) {
$res = UrlHelper::fetch($article["link"], false, false, false, $res = UrlHelper::fetch([
false, false, 0, 'url' => $article['link'],
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); 'useragent' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
]);
if (!$res) return false; if (!$res) return false;
$doc = new DOMDocument(); $doc = new DOMDocument();
$res = UrlHelper::fetch($article["link"]); $res = UrlHelper::fetch(['url' => $article["link"]]);
if ($res && $doc->loadHTML($res)) { if ($res && $doc->loadHTML($res)) {
$xpath = new DOMXPath($doc); $xpath = new DOMXPath($doc);

View File

@ -11,7 +11,7 @@ class Af_Comics_Twp extends Af_ComicFilter {
$doc = new DOMDocument(); $doc = new DOMDocument();
$res = UrlHelper::fetch($article["link"]); $res = UrlHelper::fetch(['url' => $article['link']]);
if ($res && $doc->loadHTML($res)) { if ($res && $doc->loadHTML($res)) {
$xpath = new DOMXpath($doc); $xpath = new DOMXpath($doc);

View File

@ -7,10 +7,10 @@ class Af_Comics_Whomp extends Af_ComicFilter {
function process(&$article) { function process(&$article) {
if (strpos($article["guid"], "whompcomic.com") !== false) { if (strpos($article["guid"], "whompcomic.com") !== false) {
$res = UrlHelper::fetch([
$res = UrlHelper::fetch($article["link"], false, false, false, 'url' => $article['link'],
false, false, 0, 'useragent' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); ]);
if (!$res && UrlHelper::$fetch_last_error_content) if (!$res && UrlHelper::$fetch_last_error_content)
$res = UrlHelper::$fetch_last_error_content; $res = UrlHelper::$fetch_last_error_content;

View File

@ -71,18 +71,18 @@ final class UrlHelperTest extends TestCase {
]); ]);
$mock->append(new Response(200, [], 'Hello, World')); $mock->append(new Response(200, [], 'Hello, World'));
$result = UrlHelper::fetch('https://www.example.com'); $result = UrlHelper::fetch(['url' => 'https://www.example.com']);
$this->assertEquals(200, UrlHelper::$fetch_last_error_code); $this->assertEquals(200, UrlHelper::$fetch_last_error_code);
$this->assertEquals('Hello, World', $result); $this->assertEquals('Hello, World', $result);
$mock->reset(); $mock->reset();
foreach (['ftp://ftp.example.com', 'http://127.0.0.1', 'blah', '', 42, null] as $url) { foreach (['ftp://ftp.example.com', 'http://127.0.0.1', 'blah', '', 42, null] as $url) {
$result = UrlHelper::fetch($url); $result = UrlHelper::fetch(['url' => $url]);
$this->assertFalse($result); $this->assertFalse($result);
} }
$mock->append(new Response(200, ['Content-Length' => (string) PHP_INT_MAX])); $mock->append(new Response(200, ['Content-Length' => (string) PHP_INT_MAX]));
$result = UrlHelper::fetch('https://www.example.com/very-large-content-length'); $result = UrlHelper::fetch(['url' => 'https://www.example.com/very-large-content-length']);
$this->assertFalse($result); $this->assertFalse($result);
$mock->reset(); $mock->reset();
@ -99,7 +99,7 @@ final class UrlHelperTest extends TestCase {
$mock->reset(); $mock->reset();
$mock->append(new Response(200, [], '')); $mock->append(new Response(200, [], ''));
$result = UrlHelper::fetch('https://www.example.com'); $result = UrlHelper::fetch(['url' => 'https://www.example.com']);
$this->assertFalse($result); $this->assertFalse($result);
$this->assertEquals('Successful response, but no content was received.', UrlHelper::$fetch_last_error); $this->assertEquals('Successful response, but no content was received.', UrlHelper::$fetch_last_error);
$mock->reset(); $mock->reset();