mirror of
https://github.com/getgrav/grav.git
synced 2025-12-05 15:29:57 +01:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
061a65f730 | ||
|
|
7db4da4154 | ||
|
|
78b5f6ef5c | ||
|
|
340f478bfa | ||
|
|
2108af8f36 | ||
|
|
1728b6c8bf | ||
|
|
bbfd514342 | ||
|
|
e42ae65355 | ||
|
|
0e8e00ddd7 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,3 +1,15 @@
|
||||
# v1.7.7
|
||||
## 02/23/2021
|
||||
|
||||
1. [](#new)
|
||||
* Added `Utils::arrayToQueryParams()` to convert an array into query params
|
||||
1. [](#improved)
|
||||
* Added original image support for all flex objects and media fields
|
||||
* Improved `Pagination` class to allow custom pagination query parameter
|
||||
1. [](#bugfix)
|
||||
* Fixed avatar of the user not being saved [grav-plugin-flex-objects#111](https://github.com/trilbymedia/grav-plugin-flex-objects/issues/111)
|
||||
* Replaced special space character with regular space in `system/blueprints/user/account_new.yaml`
|
||||
|
||||
# v1.7.6
|
||||
## 02/17/2021
|
||||
|
||||
|
||||
@@ -13,6 +13,6 @@ form:
|
||||
label: PLUGIN_ADMIN.USERNAME
|
||||
help: PLUGIN_ADMIN.USERNAME_HELP
|
||||
unset-disabled@: true
|
||||
unset-readonly@: true
|
||||
unset-readonly@: true
|
||||
validate:
|
||||
required: true
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
// Some standard defines
|
||||
define('GRAV', true);
|
||||
define('GRAV_VERSION', '1.7.6');
|
||||
define('GRAV_VERSION', '1.7.7');
|
||||
define('GRAV_SCHEMA', '1.7.0_2020-11-20_1');
|
||||
define('GRAV_TESTING', false);
|
||||
|
||||
|
||||
@@ -290,7 +290,8 @@ class UserObject extends FlexObject implements UserInterface, Countable
|
||||
$value = parent::getProperty($property, $default);
|
||||
|
||||
if ($property === 'avatar') {
|
||||
$value = $this->parseFileProperty($value);
|
||||
$settings = $this->getMediaFieldSettings($property);
|
||||
$value = $this->parseFileProperty($value, $settings);
|
||||
}
|
||||
|
||||
return $value;
|
||||
@@ -304,7 +305,9 @@ class UserObject extends FlexObject implements UserInterface, Countable
|
||||
public function toArray()
|
||||
{
|
||||
$array = $this->jsonSerialize();
|
||||
$array['avatar'] = $this->parseFileProperty($array['avatar'] ?? null);
|
||||
|
||||
$settings = $this->getMediaFieldSettings('avatar');
|
||||
$array['avatar'] = $this->parseFileProperty($array['avatar'] ?? null, $settings);
|
||||
|
||||
return $array;
|
||||
}
|
||||
@@ -808,46 +811,6 @@ class UserObject extends FlexObject implements UserInterface, Countable
|
||||
$this->clearMediaCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|mixed $value
|
||||
* @param array $settings
|
||||
* @return array|mixed
|
||||
*/
|
||||
protected function parseFileProperty($value, array $settings = [])
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$originalMedia = $this->getOriginalMedia();
|
||||
$resizedMedia = $this->getMedia();
|
||||
|
||||
$list = [];
|
||||
foreach ($value as $filename => $info) {
|
||||
if (!is_array($info)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var Medium|null $thumbFile */
|
||||
$thumbFile = $resizedMedia[$filename];
|
||||
/** @var Medium|null $imageFile */
|
||||
$imageFile = $originalMedia[$filename] ?? $thumbFile;
|
||||
if ($thumbFile && $imageFile) {
|
||||
$list[$filename] = [
|
||||
'name' => $info['name'] ?? null,
|
||||
'type' => $info['type'] ?? null,
|
||||
'size' => $info['size'] ?? null,
|
||||
'path' => $info['path'] ?? null,
|
||||
'image_url' => $imageFile->url(),
|
||||
'thumb_url' => $thumbFile->url(),
|
||||
'cropData' => (object)($imageFile->metadata()['upload']['crop'] ?? [])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,7 @@ class Language
|
||||
/** @var array */
|
||||
protected $fallback_extensions = [];
|
||||
/** @var array */
|
||||
protected $page_extesions = [];
|
||||
protected $page_extensions = [];
|
||||
/** @var string|false */
|
||||
protected $default;
|
||||
/** @var string|false */
|
||||
@@ -400,7 +400,7 @@ class Language
|
||||
{
|
||||
$this->fallback_languages = [];
|
||||
$this->fallback_extensions = [];
|
||||
$this->page_extesions = [];
|
||||
$this->page_extensions = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1086,6 +1086,29 @@ abstract class Utils
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array into query params.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $prepend
|
||||
* @return array
|
||||
*/
|
||||
public static function arrayToQueryParams($array, $prepend = '')
|
||||
{
|
||||
$results = [];
|
||||
foreach ($array as $key => $value) {
|
||||
$name = $prepend ? $prepend . '[' . $key . ']' : $key;
|
||||
|
||||
if (is_array($value)) {
|
||||
$results = array_merge($results, static::arrayToQueryParams($value, $name));
|
||||
} else {
|
||||
$results[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an array
|
||||
*
|
||||
|
||||
@@ -25,6 +25,8 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use RuntimeException;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_callable;
|
||||
use function is_int;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function strpos;
|
||||
@@ -141,24 +143,38 @@ trait FlexMediaTrait
|
||||
}
|
||||
|
||||
$media = $this->getMedia();
|
||||
$originalMedia = is_callable([$this, 'getOriginalMedia']) ? $this->getOriginalMedia() : null;
|
||||
|
||||
$list = [];
|
||||
foreach ($value as $filename => $info) {
|
||||
if (!is_array($info)) {
|
||||
$list[$filename] = $info;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_int($filename)) {
|
||||
$filename = $info['path'] ?? $info['name'];
|
||||
}
|
||||
|
||||
/** @var Medium|null $thumbFile */
|
||||
$imageFile = $media[$filename];
|
||||
|
||||
/** @var Medium|null $thumbFile */
|
||||
$originalFile = $originalMedia ? $originalMedia[$filename] : null;
|
||||
|
||||
$url = $imageFile ? $imageFile->url() : null;
|
||||
$originalUrl = $originalFile ? $originalFile->url() : null;
|
||||
$list[$filename] = [
|
||||
'name' => $info['name'] ?? null,
|
||||
'type' => $info['type'] ?? null,
|
||||
'size' => $info['size'] ?? null,
|
||||
'path' => $filename,
|
||||
'image_url' => $url,
|
||||
'thumb_url' => $url
|
||||
'thumb_url' => $url,
|
||||
'image_url' => $originalUrl ?? $url
|
||||
];
|
||||
if ($originalFile) {
|
||||
$list[$filename]['cropData'] = (object)($originalFile->metadata()['upload']['crop'] ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
|
||||
@@ -47,7 +47,9 @@ class AbstractPagination implements PaginationInterface
|
||||
'display' => 5,
|
||||
'opening' => 0,
|
||||
'ending' => 0,
|
||||
'url' => null
|
||||
'url' => null,
|
||||
'param' => null,
|
||||
'use_query_param' => false
|
||||
];
|
||||
/** @var array */
|
||||
private $items;
|
||||
@@ -126,14 +128,23 @@ class AbstractPagination implements PaginationInterface
|
||||
}
|
||||
|
||||
$start = ($page - 1) * $this->limit;
|
||||
if ($this->getOptions()['type'] === 'page') {
|
||||
$name = 'page';
|
||||
$type = $this->getOptions()['type'];
|
||||
$param = $this->getOptions()['param'];
|
||||
$useQuery = $this->getOptions()['use_query_param'];
|
||||
if ($type === 'page') {
|
||||
$param = $param ?? 'page';
|
||||
$offset = $page;
|
||||
} else {
|
||||
$name = 'start';
|
||||
$param = $param ?? 'start';
|
||||
$offset = $start;
|
||||
}
|
||||
|
||||
if ($useQuery) {
|
||||
$route = $this->route->withQueryParam($param, $offset);
|
||||
} else {
|
||||
$route = $this->route->withGravParam($param, $offset);
|
||||
}
|
||||
|
||||
return new PaginationPage(
|
||||
[
|
||||
'label' => $label ?? (string)$page,
|
||||
@@ -142,7 +153,7 @@ class AbstractPagination implements PaginationInterface
|
||||
'offset_end' => min($start + $this->limit, $this->total) - 1,
|
||||
'enabled' => $page !== $this->page || $this->viewAll,
|
||||
'active' => $page === $this->page,
|
||||
'route' => $this->route->withGravParam($name, $offset)
|
||||
'route' => $route
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user