mirror of
https://github.com/getgrav/grav.git
synced 2026-07-06 16:08:19 +02:00
Fixed some issues with Medium querystring + timestamps
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
1. [](#bugfix)
|
||||
* Fixed environment getting port added [#2284](https://github.com/getgrav/grav/issues/2284)
|
||||
* Fixed `FlexForm::updateObject()` to update array values when they are empty in the form
|
||||
* Fixed some issues related to Medium objects losing query string attributes
|
||||
* Broke out Medium timestamp so it's not cleared on `reset()s`
|
||||
|
||||
# v1.6.0-beta.7
|
||||
## 12/14/2018
|
||||
|
||||
@@ -185,7 +185,7 @@ class ImageMedium extends Medium
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
return trim(Grav::instance()['base_url'] . '/' . ltrim($output . $this->querystring() . $this->urlHash(), '/'), '\\');
|
||||
return trim(Grav::instance()['base_url'] . '/' . $this->urlQuerystring($output), '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -358,7 +358,7 @@ class ImageMedium extends Medium
|
||||
|
||||
if ($this->image) {
|
||||
$this->image();
|
||||
$this->querystring('');
|
||||
$this->medium_querystring = [];
|
||||
$this->filter();
|
||||
$this->clearAlternatives();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use Grav\Common\Grav;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Media\Interfaces\MediaObjectInterface;
|
||||
use Grav\Common\Utils;
|
||||
|
||||
class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
{
|
||||
@@ -55,6 +56,13 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
*/
|
||||
protected $metadata = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $medium_querystring = [];
|
||||
|
||||
protected $timestamp;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
@@ -66,7 +74,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
parent::__construct($items, $blueprint);
|
||||
|
||||
if (Grav::instance()['config']->get('system.media.enable_media_timestamp', true)) {
|
||||
$this->querystring('&' . Grav::instance()['cache']->getKey());
|
||||
$this->timestamp = Grav::instance()['cache']->getKey();
|
||||
}
|
||||
|
||||
$this->def('mime', 'application/octet-stream');
|
||||
@@ -136,7 +144,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
*/
|
||||
public function setTimestamp($timestamp = null)
|
||||
{
|
||||
$this->set('querystring', (string)($timestamp ?? $this->modified()));
|
||||
$this->timestamp = (string)($timestamp ?? $this->modified());
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -246,7 +254,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
return trim(Grav::instance()['base_url'] . '/' . ltrim($output . $this->querystring() . $this->urlHash(), '/'), '\\');
|
||||
return trim(Grav::instance()['base_url'] . '/' . $this->urlQuerystring($output), '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,20 +267,40 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
public function querystring($querystring = null, $withQuestionmark = true)
|
||||
{
|
||||
if (!is_null($querystring)) {
|
||||
$this->set('querystring', ltrim($querystring, '?&'));
|
||||
|
||||
$this->medium_querystring[] = ltrim($querystring, '?&');
|
||||
foreach ($this->alternatives as $alt) {
|
||||
$alt->querystring($querystring, $withQuestionmark);
|
||||
}
|
||||
}
|
||||
|
||||
$querystring = $this->get('querystring', '');
|
||||
|
||||
if ($withQuestionmark && !empty($querystring)) {
|
||||
return '?' . $querystring;
|
||||
} else {
|
||||
return $querystring;
|
||||
if (empty($this->medium_querystring)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// join the strings
|
||||
$querystring = implode("&", $this->medium_querystring);
|
||||
// explode all strings
|
||||
$query_parts = explode("&", $querystring);
|
||||
// Join them again now ensure the elements are unique
|
||||
$querystring = implode("&", array_unique($query_parts));
|
||||
|
||||
return $withQuestionmark ? ('?' . $querystring) : $querystring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL with full querystring
|
||||
*
|
||||
* @param $url
|
||||
* @return string
|
||||
*/
|
||||
public function urlQuerystring($url)
|
||||
{
|
||||
$querystring = $this->querystring();
|
||||
if (isset($this->timestamp) && !Utils::contains($querystring, $this->timestamp)) {
|
||||
$querystring = empty($querystring) ? ('?' . $this->timestamp) : ($querystring . '&' . $this->timestamp);
|
||||
}
|
||||
|
||||
return ltrim($url . $querystring . $this->urlHash(), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,11 +318,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
|
||||
$hash = $this->get('urlHash', '');
|
||||
|
||||
if ($withHash && !empty($hash)) {
|
||||
return '#' . $hash;
|
||||
} else {
|
||||
return $hash;
|
||||
}
|
||||
return $withHash && !empty($hash) ? '#' . $hash : $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user