Compare commits

...

26 Commits

Author SHA1 Message Date
Andy Miller
505661404b Merge branch 'release/1.6.13' 2019-08-16 09:53:21 -06:00
Andy Miller
ce51491b4d prepare for release 2019-08-16 09:53:12 -06:00
Andy Miller
d241223aa3 update changelog 2019-08-16 07:45:40 -06:00
Andy Miller
d16f83fdd8 Merge tag '1.6.12' into develop
Release v1.6.12
2019-08-14 16:19:44 -06:00
Andy Miller
02e10ff8fe Merge branch 'release/1.6.12' 2019-08-14 16:19:43 -06:00
Andy Miller
6a44d8f286 prepare for release 2019-08-14 16:19:21 -06:00
Andy Miller
4b614d871f update changelog 2019-08-14 16:18:38 -06:00
Matias Griese
3286d70092 Lock Grav user class once GRAV_USER_INSTANCE has been defined 2019-08-14 10:12:00 +03:00
Thomas Threadgold
9fc37e46fa check if GRAV_USER_INSTANCE constants are already defined (#2621) 2019-08-13 15:30:20 -06:00
Matias Griese
f304f429c5 Fix bad check in CSV escaping 2019-08-13 18:19:28 +03:00
Andy Miller
65c73f639f Update changelog 2019-08-12 16:06:16 -06:00
Aaron Dalton
d2833a1997 Allow users to override plugin handler priorities (#2165) 2019-08-12 15:22:21 -06:00
ale rimoldi
aa8f764436 run route.php when grav is not at the root of the server (#2541) 2019-08-12 15:11:41 -06:00
Andy Miller
618a59921a make markdown more page context aware 2019-08-09 18:23:05 -06:00
Andy Miller
039f71dc61 fix for var order in Validation.php 2019-08-09 17:16:31 -06:00
Andy Miller
27b8db4c10 Updated vendor libs 2019-08-09 13:33:35 -06:00
Matias Griese
afd53d76c2 Fixed CSV formatter not encoding strings with " and , properly 2019-07-18 16:11:46 +03:00
Matias Griese
57c65ad881 Fixed FlexObject::exists() failing sometimes just after the object has been saved 2019-07-16 09:50:30 +03:00
Matias Griese
a372ae90c2 Fixed an error when trying to delete a file from non-existing Flex Object 2019-07-16 09:11:11 +03:00
Andy Miller
c8739c40a5 Fixed collections using page@.self: should allow modular pages if requested 2019-07-12 12:02:28 -06:00
Andy Miller
00ff9ac42d fix 2019-07-11 08:50:09 -06:00
Andy Miller
e13a8304e6 Added arrayLower() method 2019-07-10 11:01:17 -06:00
Matias Griese
3c2b17853c Fixed non-existing Flex object having a bad media folder 2019-07-10 12:30:59 +03:00
Matias Griese
288b2a1953 Fixed fatal error 'Expiration date must be an integer, a DateInterval or null, "double" given' [#2529] 2019-07-09 13:43:51 +03:00
Matias Griese
86b1f1fbac Workaround bug in flex forms 2019-07-02 22:01:38 +03:00
Matias Griese
b5e26133a7 Fixed new Flex User creation not being possible because of username could not be given 2019-07-02 20:27:12 +03:00
17 changed files with 487 additions and 265 deletions

View File

@@ -1,10 +1,22 @@
# v1.6.13
## 08/12/2019
1. [](#bugfix)
* Regression fix for `system\router.php` [#2627](https://github.com/getgrav/grav/issues/2627)
# v1.6.12
## mm/dd/2019
## 08/11/2019
1. [](#new)
* Added support for custom `FormFlash` save locations
* Added a new `Utils::arrayLower()` method for lowercasing arrays
* Support new GRAV_BASEDIR environment variable [#2541](https://github.com/getgrav/grav/pull/2541)
* Allow users to override plugin handler priorities [#2165](https://github.com/getgrav/grav/pull/2165)
1. [](#improved)
* Use new `Utils::getSupportedPageTypes()` to enforce `html,htm` at the front of the list [#2531](https://github.com/getgrav/grav/issues/2531)
* Updated vendor libraries
* Markdown filter is now page-aware so that it works with modular references [admin#1731](https://github.com/getgrav/grav-plugin-admin/issues/1731)
* Check of `GRAV_USER_INSTANCE` constant is already defined [#2621](https://github.com/getgrav/grav/pull/2621)
1. [](#bugfix)
* Fixed some potential issues when `$grav['user']` is not set
* Fixed error when calling `Media::add($name, null)`
@@ -12,6 +24,14 @@
* Fixed `url()` not returning a path to non-existing file (`user-data://shop` => `/user/data/shop`) if it is set to fail gracefully
* Fixed `url()` returning false on unknown streams, such as `ftp://domain.com`, they should be treated as external URL
* Fixed Flex User to have permissions to save and delete his own user
* Fixed new Flex User creation not being possible because of username could not be given
* Fixed fatal error 'Expiration date must be an integer, a DateInterval or null, "double" given' [#2529](https://github.com/getgrav/grav/issues/2529)
* Fixed non-existing Flex object having a bad media folder
* Fixed collections using `page@.self:` should allow modular pages if requested
* Fixed an error when trying to delete a file from non-existing Flex Object
* Fixed `FlexObject::exists()` failing sometimes just after the object has been saved
* Fixed CSV formatter not encoding strings with `"` and `,` properly
* Fixed var order in `Validation.php` [#2610](https://github.com/getgrav/grav/issues/2610)
# v1.6.11
## 06/21/2019

549
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -12,5 +12,7 @@ form:
type: text
label: PLUGIN_ADMIN.USERNAME
help: PLUGIN_ADMIN.USERNAME_HELP
unset-disabled@: true
unset-readonly@: true
validate:
required: true

View File

@@ -27,3 +27,13 @@ config:
title: Accounts
icon: fa-users
authorize: ['admin.users', 'admin.accounts', 'admin.super']
form:
fields:
username:
flex-disabled@: exists
disabled: false
flex-readonly@: exists
readonly: false
validate:
required: true

View File

@@ -8,7 +8,7 @@
// Some standard defines
define('GRAV', true);
define('GRAV_VERSION', '1.6.11');
define('GRAV_VERSION', '1.6.13');
define('GRAV_TESTING', false);
define('DS', '/');

View File

@@ -17,11 +17,22 @@ if (is_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $_SERVER['SCRIPT_N
return false;
}
$grav_index = 'index.php';
/* Check the GRAV_BASEDIR environment variable and use if set */
$grav_basedir = getenv('GRAV_BASEDIR') ?: '';
if (isset($grav_basedir)) {
$grav_index = ltrim($grav_basedir, '/') . DIRECTORY_SEPARATOR . $grav_index;
$grav_basedir = DIRECTORY_SEPARATOR . trim($grav_basedir, DIRECTORY_SEPARATOR);
define('GRAV_ROOT', str_replace(DIRECTORY_SEPARATOR, '/', getcwd()) . $grav_basedir);
}
$_SERVER = array_merge($_SERVER, $_ENV);
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'index.php';
$_SERVER['SCRIPT_NAME'] = DIRECTORY_SEPARATOR . 'index.php';
$_SERVER['PHP_SELF'] = DIRECTORY_SEPARATOR . 'index.php';
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . $grav_basedir .DIRECTORY_SEPARATOR . 'index.php';
$_SERVER['SCRIPT_NAME'] = $grav_basedir . DIRECTORY_SEPARATOR . 'index.php';
$_SERVER['PHP_SELF'] = $grav_basedir . DIRECTORY_SEPARATOR . 'index.php';
error_log(sprintf('%s:%d [%d]: %s', $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], http_response_code(), $_SERVER['REQUEST_URI']), 4);
require 'index.php';
require $grav_index;

View File

@@ -531,7 +531,6 @@ class Cache extends Getters
}
/**
* Set the cache lifetime programmatically
*
@@ -543,7 +542,7 @@ class Cache extends Getters
return;
}
$interval = $future - $this->now;
$interval = (int)($future - $this->now);
if ($interval > 0 && $interval < $this->getLifetime()) {
$this->lifetime = $interval;
}
@@ -558,7 +557,7 @@ class Cache extends Getters
public function getLifetime()
{
if ($this->lifetime === null) {
$this->lifetime = $this->config->get('system.cache.lifetime') ?: 604800; // 1 week default
$this->lifetime = (int)($this->config->get('system.cache.lifetime') ?: 604800); // 1 week default
}
return $this->lifetime;

View File

@@ -27,8 +27,9 @@ class Validation
if (!isset($field['type'])) {
$field['type'] = 'text';
}
$type = $validate['type'] ?? $field['type'];
$validate = (array)($field['validate'] ?? null);
$type = $validate['type'] ?? $field['type'];
$required = $validate['required'] ?? false;
// If value isn't required, we will stop validation if empty value is given.

View File

@@ -2938,7 +2938,7 @@ class Page implements PageInterface
case 'page':
case 'self':
$results = new Collection();
$results = $results->addPage($page)->nonModular();
$results = $results->addPage($page);
break;
case 'descendants':

View File

@@ -151,15 +151,32 @@ class Plugin implements EventSubscriberInterface, \ArrayAccess
if (\is_string($params)) {
$dispatcher->addListener($eventName, [$this, $params]);
} elseif (\is_string($params[0])) {
$dispatcher->addListener($eventName, [$this, $params[0]], $params[1] ?? 0);
$dispatcher->addListener($eventName, [$this, $params[0]], $this->getPriority($params, $eventName));
} else {
foreach ($params as $listener) {
$dispatcher->addListener($eventName, [$this, $listener[0]], $listener[1] ?? 0);
$dispatcher->addListener($eventName, [$this, $listener[0]], $this->getPriority($listener, $eventName));
}
}
}
}
/**
* @param array $params
* @param string $eventName
*/
private function getPriority($params, $eventName)
{
$grav = Grav::instance();
$override = implode('.', ["priorities", $this->name, $eventName, $params[0]]);
if ($grav['config']->get($override) !== null)
{
return $grav['config']->get($override);
} elseif (isset($params[1])) {
return $params[1];
}
return 0;
}
/**
* @param array $events
*/

View File

@@ -27,9 +27,10 @@ class AccountsServiceProvider implements ServiceProviderInterface
public function register(Container $container)
{
$container['accounts'] = function (Container $container) {
/** @var Debugger $debugger */
$debugger = $container['debugger'];
if ($container['config']->get('system.accounts.type') === 'flex') {
$type = strtolower(defined('GRAV_USER_INSTANCE') ? GRAV_USER_INSTANCE : $container['config']->get('system.accounts.type', 'data'));
if ($type === 'flex') {
/** @var Debugger $debugger */
$debugger = $container['debugger'];
$debugger->addMessage('User Accounts: Flex Directory');
return $this->flexAccounts($container);
}
@@ -46,7 +47,9 @@ class AccountsServiceProvider implements ServiceProviderInterface
protected function dataAccounts(Container $container)
{
define('GRAV_USER_INSTANCE', 'DATA');
if (!defined('GRAV_USER_INSTANCE')) {
define('GRAV_USER_INSTANCE', 'DATA');
}
// Use User class for backwards compatibility.
return new DataUser\UserCollection(User::class);
@@ -54,7 +57,9 @@ class AccountsServiceProvider implements ServiceProviderInterface
protected function flexAccounts(Container $container)
{
define('GRAV_USER_INSTANCE', 'FLEX');
if (!defined('GRAV_USER_INSTANCE')) {
define('GRAV_USER_INSTANCE', 'FLEX');
}
/** @var Config $config */
$config = $container['config'];

View File

@@ -84,7 +84,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
new \Twig_SimpleFilter('fieldName', [$this, 'fieldNameFilter']),
new \Twig_SimpleFilter('ksort', [$this, 'ksortFilter']),
new \Twig_SimpleFilter('ltrim', [$this, 'ltrimFilter']),
new \Twig_SimpleFilter('markdown', [$this, 'markdownFunction'], ['is_safe' => ['html']]),
new \Twig_SimpleFilter('markdown', [$this, 'markdownFunction'], ['needs_context' => true, 'is_safe' => ['html']]),
new \Twig_SimpleFilter('md5', [$this, 'md5Filter']),
new \Twig_SimpleFilter('base32_encode', [$this, 'base32EncodeFilter']),
new \Twig_SimpleFilter('base32_decode', [$this, 'base32DecodeFilter']),
@@ -616,9 +616,10 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
* @param bool $block Block or Line processing
* @return mixed|string
*/
public function markdownFunction($string, $block = true)
public function markdownFunction($context = false, $string, $block = true)
{
return Utils::processMarkdown($string, $block);
$page = $context['page'] ?? null;
return Utils::processMarkdown($string, $block, $page);
}
/**

View File

@@ -9,6 +9,7 @@
namespace Grav\Common\User\FlexUser;
use Grav\Common\Data\Blueprint;
use Grav\Common\Grav;
use Grav\Common\Media\Interfaces\MediaCollectionInterface;
use Grav\Common\Page\Media;
@@ -381,6 +382,31 @@ class User extends FlexObject implements UserInterface, MediaManipulationInterfa
return $this->getBlueprint()->extra($this->toArray());
}
/**
* @param string $name
* @return Blueprint
*/
public function getBlueprint(string $name = '')
{
$blueprint = clone parent::getBlueprint($name);
$blueprint->addDynamicHandler('flex', function (array &$field, $property, array &$call) {
$params = (array)$call['params'];
$method = array_shift($params);
if (method_exists($this, $method)) {
$value = $this->{$method}(...$params);
if (\is_array($value) && isset($field[$property]) && \is_array($field[$property])) {
$field[$property] = array_merge_recursive($field[$property], $value);
} else {
$field[$property] = $value;
}
}
});
return $blueprint->init();
}
/**
* Return unmodified data as raw string.
*

View File

@@ -323,6 +323,17 @@ abstract class Utils
return (object)array_merge((array)$obj1, (array)$obj2);
}
/**
* Lowercase an entire array. Useful when combined with `in_array()`
*
* @param array $a
* @return array|false
*/
public static function arrayLower(Array $a)
{
return array_map('mb_strtolower', $a);
}
/**
* Simple function to remove item/s in an array by value
*
@@ -1515,13 +1526,15 @@ abstract class Utils
*
* @param string $string
*
* @param bool $block Block or Line processing
* @param bool $block Block or Line processing
* @param null $page
* @return string
* @throws \Exception
*/
public static function processMarkdown($string, $block = true)
public static function processMarkdown($string, $block = true, $page = null)
{
$grav = Grav::instance();
$page = $grav['page'] ?? null;
$page = $page ?? $grav['page'] ?? null;
$defaults = [
'markdown' => $grav['config']->get('system.pages.markdown', []),
'images' => $grav['config']->get('system.images', [])

View File

@@ -53,11 +53,11 @@ class CsvFormatter extends AbstractFormatter
$header = array_keys(reset($data));
// Encode the field names
$string = implode($delimiter, $header). "\n";
$string = $this->encodeLine($header, $delimiter);
// Encode the data
foreach ($data as $row) {
$string .= implode($delimiter, $row). "\n";
$string .= $this->encodeLine($row, $delimiter);
}
return $string;
@@ -87,4 +87,23 @@ class CsvFormatter extends AbstractFormatter
return $list;
}
protected function encodeLine(array $line, $delimiter = null): string
{
foreach ($line as $key => &$value) {
$value = $this->escape((string)$value);
}
unset($value);
return implode($delimiter, $line). "\n";
}
protected function escape(string $value)
{
if (preg_match('/[,"\r\n]/u', $value)) {
$value = '"' . preg_replace('/"/', '""', $value) . '"';
}
return $value;
}
}

View File

@@ -550,6 +550,15 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
}
}
// FIXME: For some reason locator caching isn't cleared for the file, investigate!
$locator = Grav::instance()['locator'];
$locator->clearCache();
// Make sure that the object exists before continuing (just in case).
if (!$this->exists()) {
throw new \RuntimeException('Saving failed: Object does not exist!');
}
if (method_exists($this, 'saveUpdatedMedia')) {
$this->saveUpdatedMedia();
}

View File

@@ -49,7 +49,7 @@ trait FlexMediaTrait
*/
public function getStorageFolder()
{
return $this->getFlexDirectory()->getStorageFolder($this->getStorageKey());
return $this->exists() ? $this->getFlexDirectory()->getStorageFolder($this->getStorageKey()) : '';
}
/**
@@ -57,7 +57,7 @@ trait FlexMediaTrait
*/
public function getMediaFolder()
{
return $this->getFlexDirectory()->getMediaFolder($this->getStorageKey());
return $this->exists() ? $this->getFlexDirectory()->getMediaFolder($this->getStorageKey()) : '';
}
/**
@@ -153,6 +153,12 @@ trait FlexMediaTrait
/** @var UniformResourceLocator $locator */
$locator = $grav['locator'];
$path = $media->getPath();
if (!$path) {
$language = $grav['language'];
throw new RuntimeException($language->translate('PLUGIN_ADMIN.FAILED_TO_MOVE_UPLOADED_FILE'), 400);
}
if ($locator->isStream($path)) {
$path = $locator->findResource($path, true, true);
$locator->clearCache($path);
@@ -202,12 +208,16 @@ trait FlexMediaTrait
}
$media = $this->getMedia();
$path = $media->getPath();
if (!$path) {
return;
}
/** @var UniformResourceLocator $locator */
$locator = $grav['locator'];
$targetPath = $media->getPath() . '/' . $dirname;
$targetFile = $media->getPath() . '/' . $filename;
$targetPath = $path . '/' . $dirname;
$targetFile = $path . '/' . $filename;
if ($locator->isStream($targetFile)) {
$targetPath = $locator->findResource($targetPath, true, true);
$targetFile = $locator->findResource($targetFile, true, true);