mirror of
https://github.com/getgrav/grav.git
synced 2026-03-05 12:01:37 +01:00
Added file modification timestamps for media images
This commit is contained in:
@@ -62,6 +62,22 @@ abstract class AbstractMedia extends Getters implements MediaCollectionInterface
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set file modification timestamps (query params) for all the media files.
|
||||
*
|
||||
* @param string|int|null $timestamp
|
||||
* @return $this
|
||||
*/
|
||||
public function setTimestamps($timestamp = null)
|
||||
{
|
||||
/** @var Medium $instance */
|
||||
foreach ($this->instances as $instance) {
|
||||
$instance->setTimestamp($timestamp);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all media.
|
||||
*
|
||||
|
||||
@@ -112,6 +112,35 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file modification time for the medium.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function modified()
|
||||
{
|
||||
$path = $this->get('filepath');
|
||||
|
||||
if (!file_exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return filemtime($path) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set querystring to file modification timestamp (or value provided as a parameter).
|
||||
*
|
||||
* @param string|int|null $timestamp
|
||||
* @return $this
|
||||
*/
|
||||
public function setTimestamp($timestamp = null)
|
||||
{
|
||||
$this->set('querystring', (string)($timestamp ?? $this->modified()));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing just the metadata
|
||||
*
|
||||
|
||||
@@ -73,7 +73,7 @@ trait FlexMediaTrait
|
||||
}
|
||||
}
|
||||
|
||||
return $this->media;
|
||||
return $this->media->setTimestamps();
|
||||
}
|
||||
|
||||
public function checkUploadedMediaFile(UploadedFileInterface $uploadedFile)
|
||||
|
||||
Reference in New Issue
Block a user