Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dist/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ parameters:
- ../fp-includes/smarty-5.8.4/**
- ../fp-content/compile/**
- ../fp-content/cache/**
- ../.setup.php (?)
- ../.setup/** (?)

paths:
- ..
Expand Down
1 change: 1 addition & 0 deletions admin/panels/uploader/admin.uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ function onupload() {
*/
if (function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
// @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x fileinfo resource arm as incompatible in ranged phpVersion analysis)
$mime = $finfo ? @finfo_file($finfo, $tmp_name) : false;
if ($finfo) {
if (!is_php85_plus()) {
Expand Down
39 changes: 21 additions & 18 deletions fp-includes/core/core.utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,26 +624,29 @@ function utils_geturl($url) {
);

$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
if (!is_php85_plus()) {
curl_close($ch);
}
if ($ch !== false) {
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
// @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x cURL resource arm as incompatible in ranged phpVersion analysis)
$header = curl_getinfo($ch);
if (!is_php85_plus()) {
curl_close($ch);
}

if (!is_array($header)) {
$header = array();
if (!is_array($header)) {
$header = array();
}
// Ensure required keys exist for callers.
$header += $default;
$header ['errno'] = $err;
$header ['errmsg'] = $errmsg;
$header ['content'] = $content;
$header ['transport'] = 'curl';

return $header;
}
// Ensure required keys exist for callers.
$header += $default;
$header ['errno'] = $err;
$header ['errmsg'] = $errmsg;
$header ['content'] = $content;
$header ['transport'] = 'curl';

return $header;
}

// Fallback transport: allow_url_fopen (common on shared hosting without cURL)
Expand Down
147 changes: 77 additions & 70 deletions fp-plugins/mastodon/plugin.mastodon.php
Original file line number Diff line number Diff line change
Expand Up @@ -9915,41 +9915,44 @@ function plugin_mastodon_http_request_multipart($method, $url, $headers, $fields
}
$responseHeaders = array();
$ch = curl_init($url);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
CURLOPT_CONNECTTIMEOUT => 15,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HEADERFUNCTION => function ($curl, $headerLine) use (&$responseHeaders) {
$len = strlen($headerLine);
$headerLine = trim($headerLine);
if ($headerLine !== '' && strpos($headerLine, ':') !== false) {
list($name, $value) = explode(':', $headerLine, 2);
$responseHeaders [strtolower(trim($name))] = trim($value);
}
return $len;
},
CURLOPT_USERAGENT => 'FlatPress-Mastodon/0.1'
);
curl_setopt_array($ch, $options);
$responseBody = curl_exec($ch);
$errorNo = curl_errno($ch);
$error = curl_error($ch);
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (!is_php85_plus()) {
curl_close($ch);
if ($ch !== false) {
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
CURLOPT_CONNECTTIMEOUT => 15,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HEADERFUNCTION => function ($curl, $headerLine) use (&$responseHeaders) {
$len = strlen($headerLine);
$headerLine = trim($headerLine);
if ($headerLine !== '' && strpos($headerLine, ':') !== false) {
list($name, $value) = explode(':', $headerLine, 2);
$responseHeaders [strtolower(trim($name))] = trim($value);
}
return $len;
},
CURLOPT_USERAGENT => 'FlatPress-Mastodon/0.1'
);
curl_setopt_array($ch, $options);
$responseBody = curl_exec($ch);
$errorNo = curl_errno($ch);
$error = curl_error($ch);
// @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x cURL resource arm as incompatible in ranged phpVersion analysis)
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (!is_php85_plus()) {
curl_close($ch);
}
return array(
'ok' => ($errorNo === 0 && $code >= 200 && $code < 300),
'code' => $code,
'headers' => $responseHeaders,
'body' => is_string($responseBody) ? $responseBody : '',
'error' => (string) $error
);
}
return array(
'ok' => ($errorNo === 0 && $code >= 200 && $code < 300),
'code' => $code,
'headers' => $responseHeaders,
'body' => is_string($responseBody) ? $responseBody : '',
'error' => (string) $error
);
}

$boundary = '----FlatPressMastodon' . md5(uniqid('', true));
Expand Down Expand Up @@ -11062,44 +11065,47 @@ function plugin_mastodon_http_request($method, $url, $headers, $body, $contentTy
if (function_exists('curl_init')) {
$responseHeaders = array();
$ch = curl_init($url);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
CURLOPT_CONNECTTIMEOUT => 15,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_HEADERFUNCTION => function ($curl, $headerLine) use (&$responseHeaders) {
$len = strlen($headerLine);
$headerLine = trim($headerLine);
if ($headerLine !== '' && strpos($headerLine, ':') !== false) {
list($name, $value) = explode(':', $headerLine, 2);
$responseHeaders [strtolower(trim($name))] = trim($value);
}
return $len;
},
CURLOPT_USERAGENT => 'FlatPress-Mastodon/0.1'
);
if ($ch !== false) {
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
CURLOPT_CONNECTTIMEOUT => 15,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_HEADERFUNCTION => function ($curl, $headerLine) use (&$responseHeaders) {
$len = strlen($headerLine);
$headerLine = trim($headerLine);
if ($headerLine !== '' && strpos($headerLine, ':') !== false) {
list($name, $value) = explode(':', $headerLine, 2);
$responseHeaders [strtolower(trim($name))] = trim($value);
}
return $len;
},
CURLOPT_USERAGENT => 'FlatPress-Mastodon/0.1'
);

if ($method === 'POST' || $method === 'PUT' || $method === 'PATCH' || $method === 'DELETE') {
$options [CURLOPT_POSTFIELDS] = $body;
}
curl_setopt_array($ch, $options);
$responseBody = curl_exec($ch);
$errorNo = curl_errno($ch);
$error = curl_error($ch);
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (!is_php85_plus()) {
curl_close($ch);
if ($method === 'POST' || $method === 'PUT' || $method === 'PATCH' || $method === 'DELETE') {
$options [CURLOPT_POSTFIELDS] = $body;
}
curl_setopt_array($ch, $options);
$responseBody = curl_exec($ch);
$errorNo = curl_errno($ch);
$error = curl_error($ch);
// @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x cURL resource arm as incompatible in ranged phpVersion analysis)
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (!is_php85_plus()) {
curl_close($ch);
}
return array(
'ok' => ($errorNo === 0 && $code >= 200 && $code < 300),
'code' => $code,
'headers' => $responseHeaders,
'body' => is_string($responseBody) ? $responseBody : '',
'error' => (string) $error
);
}
return array(
'ok' => ($errorNo === 0 && $code >= 200 && $code < 300),
'code' => $code,
'headers' => $responseHeaders,
'body' => is_string($responseBody) ? $responseBody : '',
'error' => (string) $error
);
}

if (ini_get('allow_url_fopen')) {
Expand Down Expand Up @@ -11551,6 +11557,7 @@ function plugin_mastodon_profile_avatar_type($body, $headers) {
if (function_exists('finfo_open')) {
$finfo = @finfo_open(FILEINFO_MIME_TYPE);
if ($finfo) {
// @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x fileinfo resource arm as incompatible in ranged phpVersion analysis)
$detected = @finfo_buffer($finfo, $body);
@finfo_close($finfo);
$detected = is_string($detected) ? strtolower(trim($detected)) : '';
Expand Down
1 change: 1 addition & 0 deletions fp-plugins/newsletter/plugin.newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ function plugin_newsletter_http_get(string $url, ?int &$httpCode = null, ?string
$data = curl_exec($ch);
$errno = curl_errno($ch);
$errstr = curl_error($ch);
// @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x cURL resource arm as incompatible in ranged phpVersion analysis)
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (!is_php85_plus()) {
curl_close($ch);
Expand Down