More medium improvements

This commit is contained in:
Matias Griese
2022-02-12 17:11:13 +02:00
parent a9c4d2b770
commit 37d3a18d3c
3 changed files with 18 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ use Grav\Common\Media\Traits\ImageMediaTrait;
use Grav\Common\Utils;
use Gregwar\Image\Image;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use function array_key_exists;
use function func_get_args;
use function in_array;
@@ -239,7 +240,9 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
*/
public function sourceParsedownElement(array $attributes, $reset = true)
{
empty($attributes['src']) && $attributes['src'] = $this->url(false);
if (empty($attributes['src'])) {
$attributes['src'] = $this->url(false);
}
$srcset = $this->srcset($reset);
if ($srcset) {

View File

@@ -53,14 +53,19 @@ class Medium extends Data implements RenderableInterface, MediaFileInterface
$this->def('mime', 'application/octet-stream');
$path = $this->get('filepath');
if ($path && file_exists($path)) {
if (!$this->offsetExists('size')) {
$this->set('size', filesize($path));
}
if (!$this->offsetExists('modified')) {
$this->set('modified', filemtime($path));
$sizeMissing = !$this->offsetExists('size');
$modifiedMissing = !$this->offsetExists('modified');
if ($sizeMissing || $modifiedMissing) {
$path = $this->get('filepath');
if ($path && file_exists($path)) {
if ($sizeMissing) {
$this->set('size', filesize($path));
}
if ($modifiedMissing) {
$this->set('modified', filemtime($path));
}
}
}
$this->reset();

View File

@@ -992,7 +992,8 @@ abstract class Utils
*
* @param string $path
* @param int|null $flags
* @return array|string
* @return string[]|string
* @phpstan-return array{dirname: string, basename: string, extension: string|null, filename: string}|string
*/
public static function pathinfo(string $path, int $flags = null)
{