mirror of
https://github.com/getgrav/grav.git
synced 2026-09-04 00:13:19 +02:00
More medium improvements
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user