Update to Kirby 4.7.0
This commit is contained in:
parent
02a9ab387c
commit
ba25a9a198
509 changed files with 26604 additions and 14872 deletions
|
@ -3,6 +3,8 @@
|
|||
namespace Kirby\Cms;
|
||||
|
||||
use Kirby\Data\Data;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\NotFoundException;
|
||||
use Kirby\Filesystem\Dir;
|
||||
use Kirby\Filesystem\F;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
@ -23,14 +25,12 @@ class Media
|
|||
/**
|
||||
* Tries to find a file by model and filename
|
||||
* and to copy it to the media folder.
|
||||
*
|
||||
* @param \Kirby\Cms\Model|null $model
|
||||
* @param string $hash
|
||||
* @param string $filename
|
||||
* @return \Kirby\Cms\Response|false
|
||||
*/
|
||||
public static function link(Model $model = null, string $hash, string $filename)
|
||||
{
|
||||
public static function link(
|
||||
Page|Site|User|null $model,
|
||||
string $hash,
|
||||
string $filename
|
||||
): Response|false {
|
||||
if ($model === null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -57,15 +57,16 @@ class Media
|
|||
}
|
||||
|
||||
// try to generate a thumb for the file
|
||||
return static::thumb($model, $hash, $filename);
|
||||
try {
|
||||
return static::thumb($model, $hash, $filename);
|
||||
} catch (NotFoundException) {
|
||||
// render the error page if there is no job for this filename
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the file to the final media folder location
|
||||
*
|
||||
* @param \Kirby\Cms\File $file
|
||||
* @param string $dest
|
||||
* @return bool
|
||||
*/
|
||||
public static function publish(File $file, string $dest): bool
|
||||
{
|
||||
|
@ -87,14 +88,12 @@ class Media
|
|||
* Tries to find a job file for the
|
||||
* given filename and then calls the thumb
|
||||
* component to create a thumbnail accordingly
|
||||
*
|
||||
* @param \Kirby\Cms\Model|string $model
|
||||
* @param string $hash
|
||||
* @param string $filename
|
||||
* @return \Kirby\Cms\Response|false
|
||||
*/
|
||||
public static function thumb($model, string $hash, string $filename)
|
||||
{
|
||||
public static function thumb(
|
||||
File|Page|Site|User|string $model,
|
||||
string $hash,
|
||||
string $filename
|
||||
): Response|false {
|
||||
$kirby = App::instance();
|
||||
|
||||
$root = match (true) {
|
||||
|
@ -109,15 +108,23 @@ class Media
|
|||
=> $model->mediaRoot() . '/' . $hash
|
||||
};
|
||||
|
||||
$thumb = $root . '/' . $filename;
|
||||
$job = $root . '/.jobs/' . $filename . '.json';
|
||||
|
||||
try {
|
||||
$thumb = $root . '/' . $filename;
|
||||
$job = $root . '/.jobs/' . $filename . '.json';
|
||||
$options = Data::read($job);
|
||||
} catch (Throwable) {
|
||||
// send a customized error message to make clearer what happened here
|
||||
throw new NotFoundException('The thumbnail configuration could not be found');
|
||||
}
|
||||
|
||||
if (empty($options) === true) {
|
||||
return false;
|
||||
}
|
||||
if (empty($options['filename']) === true) {
|
||||
throw new InvalidArgumentException('Incomplete thumbnail configuration');
|
||||
}
|
||||
|
||||
try {
|
||||
// find the correct source file depending on the model
|
||||
// this adds support for custom assets
|
||||
$source = match (true) {
|
||||
is_string($model) === true
|
||||
=> $kirby->root('index') . '/' . $model . '/' . $options['filename'],
|
||||
|
@ -125,30 +132,30 @@ class Media
|
|||
=> $model->file($options['filename'])->root()
|
||||
};
|
||||
|
||||
try {
|
||||
$kirby->thumb($source, $thumb, $options);
|
||||
F::remove($job);
|
||||
return Response::file($thumb);
|
||||
} catch (Throwable) {
|
||||
F::remove($thumb);
|
||||
return Response::file($source);
|
||||
}
|
||||
} catch (Throwable) {
|
||||
return false;
|
||||
// generate the thumbnail and save it in the media folder
|
||||
$kirby->thumb($source, $thumb, $options);
|
||||
|
||||
// remove the job file once the thumbnail has been created
|
||||
F::remove($job);
|
||||
|
||||
// read the file and send it to the browser
|
||||
return Response::file($thumb);
|
||||
} catch (Throwable $e) {
|
||||
// remove potentially broken thumbnails
|
||||
F::remove($thumb);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all versions of the given file
|
||||
* within the parent directory
|
||||
*
|
||||
* @param string $directory
|
||||
* @param \Kirby\Cms\File $file
|
||||
* @param string|null $ignore
|
||||
* @return bool
|
||||
*/
|
||||
public static function unpublish(string $directory, File $file, string $ignore = null): bool
|
||||
{
|
||||
public static function unpublish(
|
||||
string $directory,
|
||||
File $file,
|
||||
string|null $ignore = null
|
||||
): bool {
|
||||
if (is_dir($directory) === false) {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue