1
0

downgrade to kirby v3

This commit is contained in:
Philip Wagner
2024-09-01 10:47:15 +02:00
parent a4b2aece7b
commit af86acb7a1
1085 changed files with 54743 additions and 65042 deletions

View File

@@ -2,7 +2,6 @@
namespace Kirby\Filesystem;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Str;
use SimpleXMLElement;
@@ -31,7 +30,7 @@ class Mime
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'avi' => 'video/x-msvideo',
'avif' => 'image/avif',
'avif' => 'image/avif',
'bmp' => 'image/bmp',
'css' => 'text/css',
'csv' => ['text/csv', 'text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream'],
@@ -79,7 +78,6 @@ class Mime
'php' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'],
'php3' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'],
'phps' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'],
'pht' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'],
'phtml' => ['text/php', 'text/x-php', 'application/x-httpd-php', 'application/php', 'application/x-php', 'application/x-httpd-php-source'],
'png' => 'image/png',
'ppt' => ['application/powerpoint', 'application/vnd.ms-powerpoint'],
@@ -120,22 +118,24 @@ class Mime
/**
* Fixes an invalid MIME type guess for the given file
*
* @param string $file
* @param string $mime
* @param string $extension
* @return string|null
*/
public static function fix(
string $file,
string|null $mime = null,
string|null $extension = null
): string|null {
public static function fix(string $file, string $mime = null, string $extension = null)
{
// fixing map
$map = [
'text/html' => [
'svg' => [Mime::class, 'fromSvg'],
'svg' => ['Kirby\Filesystem\Mime', 'fromSvg'],
],
'text/plain' => [
'css' => 'text/css',
'json' => 'application/json',
'mjs' => 'text/javascript',
'svg' => [Mime::class, 'fromSvg'],
'svg' => ['Kirby\Filesystem\Mime', 'fromSvg'],
],
'text/x-asm' => [
'css' => 'text/css'
@@ -166,8 +166,11 @@ class Mime
/**
* Guesses a MIME type by extension
*
* @param string $extension
* @return string|null
*/
public static function fromExtension(string $extension): string|null
public static function fromExtension(string $extension): ?string
{
$mime = static::$types[$extension] ?? null;
return is_array($mime) === true ? array_shift($mime) : $mime;
@@ -175,8 +178,11 @@ class Mime
/**
* Returns the MIME type of a file
*
* @param string $file
* @return string|false
*/
public static function fromFileInfo(string $file): string|false
public static function fromFileInfo(string $file)
{
if (function_exists('finfo_file') === true && file_exists($file) === true) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
@@ -190,13 +196,13 @@ class Mime
/**
* Returns the MIME type of a file
*
* @param string $file
* @return string|false
*/
public static function fromMimeContentType(string $file): string|false
public static function fromMimeContentType(string $file)
{
if (
function_exists('mime_content_type') === true &&
file_exists($file) === true
) {
if (function_exists('mime_content_type') === true && file_exists($file) === true) {
return mime_content_type($file);
}
@@ -205,8 +211,11 @@ class Mime
/**
* Tries to detect a valid SVG and returns the MIME type accordingly
*
* @param string $file
* @return string|false
*/
public static function fromSvg(string $file): string|false
public static function fromSvg(string $file)
{
if (file_exists($file) === true) {
libxml_use_internal_errors(true);
@@ -224,6 +233,10 @@ class Mime
/**
* Tests if a given MIME type is matched by an `Accept` header
* pattern; returns true if the MIME type is contained at all
*
* @param string $mime
* @param string $pattern
* @return bool
*/
public static function isAccepted(string $mime, string $pattern): bool
{
@@ -242,6 +255,10 @@ class Mime
* Tests if a MIME wildcard pattern from an `Accept` header
* matches a given type
* @since 3.3.0
*
* @param string $test
* @param string $wildcard
* @return bool
*/
public static function matches(string $test, string $wildcard): bool
{
@@ -250,8 +267,11 @@ class Mime
/**
* Returns the extension for a given MIME type
*
* @param string|null $mime
* @return string|false
*/
public static function toExtension(string $mime = null): string|false
public static function toExtension(string $mime = null)
{
foreach (static::$types as $key => $value) {
if (is_array($value) === true && in_array($mime, $value) === true) {
@@ -268,33 +288,22 @@ class Mime
/**
* Returns all available extensions for a given MIME type
*
* @param string|null $mime
* @return array
*/
public static function toExtensions(string $mime = null, bool $matchWildcards = false): array
public static function toExtensions(string $mime = null): array
{
$extensions = [];
$testMime = fn (string $v) => static::matches($v, $mime);
foreach (static::$types as $key => $value) {
if (is_array($value) === true) {
if ($matchWildcards === true) {
if (A::some($value, $testMime)) {
$extensions[] = $key;
}
} else {
if (in_array($mime, $value) === true) {
$extensions[] = $key;
}
}
} else {
if ($matchWildcards === true) {
if ($testMime($value) === true) {
$extensions[] = $key;
}
} else {
if ($value === $mime) {
$extensions[] = $key;
}
}
if (is_array($value) === true && in_array($mime, $value) === true) {
$extensions[] = $key;
continue;
}
if ($value === $mime) {
$extensions[] = $key;
}
}
@@ -303,11 +312,13 @@ class Mime
/**
* Returns the MIME type of a file
*
* @param string $file
* @param string $extension
* @return string|false
*/
public static function type(
string $file,
string|null $extension = null
): string|null {
public static function type(string $file, string $extension = null)
{
// use the standard finfo extension
$mime = static::fromFileInfo($file);
@@ -330,6 +341,8 @@ class Mime
/**
* Returns all detectable MIME types
*
* @return array
*/
public static function types(): array
{