refactor: general code base refactor (#2950)

* refactor

* fix: bug in previous refactor

* chore: exclude phpcompat sniff due to bug in phpcompat

* fix: do not leak absolute paths

* refactor/fix: batch extensions checking, fix DOS issue
This commit is contained in:
Dag 2022-08-06 22:46:28 +02:00 committed by GitHub
parent b042412416
commit 2bbce8ebef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 679 additions and 827 deletions

View file

@ -25,10 +25,10 @@ class JsonFormat extends FormatAbstract
public function stringify()
{
$urlPrefix = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$urlHost = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : '';
$urlPath = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : '';
$urlRequest = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
$https = $_SERVER['HTTPS'] ?? null;
$urlPrefix = $https === 'on' ? 'https://' : 'http://';
$urlHost = $_SERVER['HTTP_HOST'] ?? '';
$urlRequest = $_SERVER['REQUEST_URI'] ?? '';
$extraInfos = $this->getExtraInfos();
@ -52,7 +52,7 @@ class JsonFormat extends FormatAbstract
$entryTitle = $item->getTitle();
$entryUri = $item->getURI();
$entryTimestamp = $item->getTimestamp();
$entryContent = $item->getContent() ? $this->sanitizeHtml($item->getContent()) : '';
$entryContent = $item->getContent() ? sanitize_html($item->getContent()) : '';
$entryEnclosures = $item->getEnclosures();
$entryCategories = $item->getCategories();
@ -76,13 +76,13 @@ class JsonFormat extends FormatAbstract
];
}
if (!empty($entryTimestamp)) {
$entry['date_modified'] = gmdate(DATE_ATOM, $entryTimestamp);
$entry['date_modified'] = gmdate(\DATE_ATOM, $entryTimestamp);
}
if (!empty($entryUri)) {
$entry['url'] = $entryUri;
}
if (!empty($entryContent)) {
if ($this->isHTML($entryContent)) {
if (is_html($entryContent)) {
$entry['content_html'] = $entryContent;
} else {
$entry['content_text'] = $entryContent;
@ -93,7 +93,7 @@ class JsonFormat extends FormatAbstract
foreach ($entryEnclosures as $enclosure) {
$entry['attachments'][] = [
'url' => $enclosure,
'mime_type' => getMimeType($enclosure)
'mime_type' => parse_mime_type($enclosure)
];
}
}
@ -121,13 +121,8 @@ class JsonFormat extends FormatAbstract
* So consider this a hack.
* Switch to JSON_INVALID_UTF8_IGNORE when PHP 7.2 is the latest platform requirement.
*/
$json = json_encode($data, JSON_PRETTY_PRINT | JSON_PARTIAL_OUTPUT_ON_ERROR);
$json = json_encode($data, \JSON_PRETTY_PRINT | \JSON_PARTIAL_OUTPUT_ON_ERROR);
return $json;
}
private function isHTML($text)
{
return (strlen(strip_tags($text)) != strlen($text));
}
}