Skip to content

Commit

Permalink
Merge branch 'release/1.7.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 23, 2021
2 parents a58298b + 7db4da4 commit 061a65f
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 53 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion system/blueprints/user/account_new.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion system/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
47 changes: 5 additions & 42 deletions system/src/Grav/Common/Flex/Types/Users/UserObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ public function getProperty($property, $default = null)
$value = parent::getProperty($property, $default);

if ($property === 'avatar') {
$value = $this->parseFileProperty($value);
$settings = $this->getMediaFieldSettings($property);
$value = $this->parseFileProperty($value, $settings);
}

return $value;
Expand All @@ -304,7 +305,9 @@ public function getProperty($property, $default = null)
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;
}
Expand Down Expand Up @@ -808,46 +811,6 @@ protected function saveUpdatedMedia(): void
$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
*/
Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -400,7 +400,7 @@ public function resetFallbackPageExtensions()
{
$this->fallback_languages = [];
$this->fallback_extensions = [];
$this->page_extesions = [];
$this->page_extensions = [];
}

/**
Expand Down
23 changes: 23 additions & 0 deletions system/src/Grav/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,29 @@ public static function arrayFilterRecursive(Array $source, $fn)
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
*
Expand Down
20 changes: 18 additions & 2 deletions system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
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;
Expand Down Expand Up @@ -141,24 +143,38 @@ protected function parseFileProperty($value, array $settings = [])
}

$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;
Expand Down
21 changes: 16 additions & 5 deletions system/src/Grav/Framework/Pagination/AbstractPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,14 +128,23 @@ public function getPage(int $page, string $label = null): ?PaginationPage
}

$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,
Expand All @@ -142,7 +153,7 @@ public function getPage(int $page, string $label = null): ?PaginationPage
'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
]
);
}
Expand Down

0 comments on commit 061a65f

Please sign in to comment.