mirror of
https://github.com/getgrav/grav.git
synced 2026-03-03 19:11:35 +01:00
Merge branch 'develop' of github.com:getgrav/grav into feature/multilang
# Conflicts: # CHANGELOG.md
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
|
||||
1. [](#new)
|
||||
* Added support for custom `FormFlash` save locations
|
||||
* Added new configuration option `system.languages.include_default_lang_file_extension` to keep default language in `.md` files if set to `false`
|
||||
1. [](#improved)
|
||||
* Use new `Utils::getSupportedPageTypes()` to enforce `html,htm` at the front of the list [#2531](https://github.com/getgrav/grav/issues/2531)
|
||||
1. [](#bugfix)
|
||||
* Fixed some potential issues when `$grav['user']` is not set
|
||||
* Added new configuration option `system.languages.include_default_lang_file_extension` to keep default language in `.md` files if set to `false`
|
||||
* Fixed `.md` page to be assigned to the default language and to be listed in translated/untranslated page list
|
||||
* Fixed `Language::getFallbackPageExtensions()` to append `.md` file after the default language extension
|
||||
|
||||
|
||||
@@ -378,14 +378,12 @@ class Blueprint extends BlueprintForm
|
||||
$grav = Grav::instance();
|
||||
$actions = (array)$call['params'];
|
||||
|
||||
/** @var UserInterface $user */
|
||||
if (isset($grav['user'])) {
|
||||
$user = Grav::instance()['user'];
|
||||
foreach ($actions as $action) {
|
||||
if (!$user->authorize($action)) {
|
||||
$this->addPropertyRecursive($field, 'validate', ['ignore' => true]);
|
||||
return;
|
||||
}
|
||||
/** @var UserInterface|null $user */
|
||||
$user = $grav['user'] ?? null;
|
||||
foreach ($actions as $action) {
|
||||
if (!$user || !$user->authorize($action)) {
|
||||
$this->addPropertyRecursive($field, 'validate', ['ignore' => true]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class Licenses
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's the License File object
|
||||
* Get the License File object
|
||||
*
|
||||
* @return \RocketTheme\Toolbox\File\FileInterface
|
||||
*/
|
||||
|
||||
@@ -234,7 +234,7 @@ class Language
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's a URL prefix based on configuration
|
||||
* Get a URL prefix based on configuration
|
||||
*
|
||||
* @param string|null $lang
|
||||
* @return string
|
||||
|
||||
@@ -232,7 +232,7 @@ class ImageMedium extends Medium
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the ability to override the Inmage's Pretty name stored in cache
|
||||
* Allows the ability to override the image's pretty name stored in cache
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
|
||||
@@ -1457,7 +1457,7 @@ class Page implements PageInterface
|
||||
if (is_string($http_accept)) {
|
||||
$negotiator = new Negotiator();
|
||||
|
||||
$supported_types = Grav::instance()['config']->get('system.pages.types', ['html', 'json']);
|
||||
$supported_types = Utils::getSupportPageTypes(['html', 'json']);
|
||||
$priorities = Utils::getMimeTypes($supported_types);
|
||||
|
||||
$media_type = $negotiator->getBest($http_accept, $priorities);
|
||||
|
||||
@@ -455,7 +455,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a human readable output for cron sytnax
|
||||
* Gets a human readable output for cron syntax
|
||||
*
|
||||
* @param $at
|
||||
* @return string
|
||||
@@ -1004,10 +1004,10 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
*/
|
||||
public function authorize($action)
|
||||
{
|
||||
/** @var UserInterface $user */
|
||||
$user = $this->grav['user'];
|
||||
/** @var UserInterface|null $user */
|
||||
$user = $this->grav['user'] ?? null;
|
||||
|
||||
if (!$user->authenticated || (isset($user->authorized) && !$user->authorized)) {
|
||||
if (!$user || !$user->authenticated || (isset($user->authorized) && !$user->authorized)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1136,7 +1136,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's the Exif data for a file
|
||||
* Get the Exif data for a file
|
||||
*
|
||||
* @param string $image
|
||||
* @param bool $raw
|
||||
|
||||
@@ -1286,7 +1286,7 @@ class Uri
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's post from either $_POST or JSON response object
|
||||
* Get post from either $_POST or JSON response object
|
||||
* By default returns all data, or can return a single item
|
||||
*
|
||||
* @param string $element
|
||||
@@ -1345,7 +1345,7 @@ class Uri
|
||||
*/
|
||||
public function isValidExtension($extension)
|
||||
{
|
||||
$valid_page_types = implode('|', Grav::instance()['config']->get('system.pages.types'));
|
||||
$valid_page_types = implode('|', Utils::getSupportPageTypes());
|
||||
|
||||
// Strip the file extension for valid page types
|
||||
if (preg_match('/(' . $valid_page_types . ')/', $extension)) {
|
||||
|
||||
@@ -28,7 +28,7 @@ abstract class Utils
|
||||
/**
|
||||
* Simple helper method to make getting a Grav URL easier
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|object $input
|
||||
* @param bool $domain
|
||||
* @param bool $fail_gracefully
|
||||
* @return bool|null|string
|
||||
@@ -68,11 +68,7 @@ abstract class Utils
|
||||
try {
|
||||
$resource = $locator->findResource("{$parts['scheme']}://{$parts['host']}{$parts['path']}", false);
|
||||
} catch (\Exception $e) {
|
||||
if ($fail_gracefully) {
|
||||
return $input;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return $fail_gracefully ? $input : false;
|
||||
}
|
||||
|
||||
if ($resource && isset($parts['query'])) {
|
||||
@@ -288,6 +284,24 @@ abstract class Utils
|
||||
return (object)array_merge((array)$obj1, (array)$obj2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple function to remove item/s in an array by value
|
||||
*
|
||||
* @param $search array
|
||||
* @param $value string|array
|
||||
* @return array
|
||||
*/
|
||||
public static function arrayRemoveValue(Array $search, $value)
|
||||
{
|
||||
foreach ((array) $value as $val) {
|
||||
$key = array_search($val, $search);
|
||||
if ($key !== false) {
|
||||
unset($search[$key]);
|
||||
}
|
||||
}
|
||||
return $search;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive Merge with uniqueness
|
||||
*
|
||||
@@ -1070,12 +1084,9 @@ abstract class Utils
|
||||
*/
|
||||
private static function generateNonceString($action, $previousTick = false)
|
||||
{
|
||||
$username = '';
|
||||
if (isset(Grav::instance()['user'])) {
|
||||
$user = Grav::instance()['user'];
|
||||
$username = $user->username;
|
||||
}
|
||||
$grav = Grav::instance();
|
||||
|
||||
$username = isset($grav['user']) ? $grav['user']->username : '';
|
||||
$token = session_id();
|
||||
$i = self::nonceTick();
|
||||
|
||||
@@ -1083,7 +1094,7 @@ abstract class Utils
|
||||
$i--;
|
||||
}
|
||||
|
||||
return ($i . '|' . $action . '|' . $username . '|' . $token . '|' . Grav::instance()['config']->get('security.salt'));
|
||||
return ($i . '|' . $action . '|' . $username . '|' . $token . '|' . $grav['config']->get('security.salt'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1297,7 +1308,7 @@ abstract class Utils
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's path based on a token
|
||||
* Get path based on a token
|
||||
*
|
||||
* @param string $path
|
||||
* @param PageInterface|null $page
|
||||
@@ -1534,4 +1545,23 @@ abstract class Utils
|
||||
|
||||
return $subnet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to ensure html, htm in the front of the supported page types
|
||||
*
|
||||
* @param array|null $defaults
|
||||
* @return array|mixed
|
||||
*/
|
||||
public static function getSupportPageTypes(array $defaults = null)
|
||||
{
|
||||
$types = Grav::instance()['config']->get('system.pages.types', $defaults);
|
||||
|
||||
// remove html/htm
|
||||
$types = static::arrayRemoveValue($types, ['html', 'htm']);
|
||||
|
||||
// put them back at the front
|
||||
$types = array_merge(['html', 'htm'], $types);
|
||||
|
||||
return $types;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,7 +437,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementes JsonSerializable interface.
|
||||
* Implements JsonSerializable interface.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -84,7 +84,7 @@ class ArrayCollection extends BaseArrayCollection implements CollectionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementes JsonSerializable interface.
|
||||
* Implements JsonSerializable interface.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -97,7 +97,7 @@ class YamlFormatter extends AbstractFormatter
|
||||
@ini_set('yaml.decode_php', $saved);
|
||||
|
||||
if ($decoded !== false) {
|
||||
return $decoded;
|
||||
return (array) $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,10 +27,10 @@ trait FlexAuthorizeTrait
|
||||
{
|
||||
if (null === $user) {
|
||||
/** @var UserInterface $user */
|
||||
$user = Grav::instance()['user'];
|
||||
$user = Grav::instance()['user'] ?? null;
|
||||
}
|
||||
|
||||
return $this->isAuthorizedAction($user, $action, $scope) || $this->isAuthorizedSuperAdmin($user);
|
||||
return $user && ($this->isAuthorizedAction($user, $action, $scope) || $this->isAuthorizedSuperAdmin($user));
|
||||
}
|
||||
|
||||
protected function isAuthorizedSuperAdmin(UserInterface $user): bool
|
||||
|
||||
Reference in New Issue
Block a user