3.4.0
This commit is contained in:
@@ -326,14 +326,32 @@ class File extends ModelWithContent
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a unique media hash
|
||||
* Check if the file can be read by the current user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isReadable(): bool
|
||||
{
|
||||
static $readable = [];
|
||||
|
||||
$template = $this->template();
|
||||
|
||||
if (isset($readable[$template]) === true) {
|
||||
return $readable[$template];
|
||||
}
|
||||
|
||||
return $readable[$template] = $this->permissions()->can('read');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a unique media hash
|
||||
*
|
||||
* @internal
|
||||
* @return string
|
||||
*/
|
||||
public function mediaHash(): string
|
||||
{
|
||||
return crc32($this->filename()) . '-' . $this->modifiedFile();
|
||||
return $this->mediaToken() . '-' . $this->modifiedFile();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,6 +365,18 @@ class File extends ModelWithContent
|
||||
return $this->parent()->mediaRoot() . '/' . $this->mediaHash() . '/' . $this->filename();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a non-guessable token string for this file
|
||||
*
|
||||
* @internal
|
||||
* @return string
|
||||
*/
|
||||
public function mediaToken(): string
|
||||
{
|
||||
$token = $this->kirby()->contentToken($this, $this->id());
|
||||
return substr($token, 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute Url to the file in the public media folder
|
||||
*
|
||||
@@ -375,12 +405,13 @@ class File extends ModelWithContent
|
||||
*
|
||||
* @param string $format
|
||||
* @param string|null $handler date or strftime
|
||||
* @param string|null $languageCode
|
||||
* @return mixed
|
||||
*/
|
||||
public function modified(string $format = null, string $handler = null)
|
||||
public function modified(string $format = null, string $handler = null, string $languageCode = null)
|
||||
{
|
||||
$file = $this->modifiedFile();
|
||||
$content = $this->modifiedContent();
|
||||
$content = $this->modifiedContent($languageCode);
|
||||
$modified = max($file, $content);
|
||||
|
||||
if (is_null($format) === true) {
|
||||
@@ -396,11 +427,12 @@ class File extends ModelWithContent
|
||||
* Timestamp of the last modification
|
||||
* of the content file
|
||||
*
|
||||
* @param string|null $languageCode
|
||||
* @return int
|
||||
*/
|
||||
protected function modifiedContent(): int
|
||||
protected function modifiedContent(string $languageCode = null): int
|
||||
{
|
||||
return F::modified($this->contentFile());
|
||||
return F::modified($this->contentFile($languageCode));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user