mirror of
https://github.com/getgrav/grav.git
synced 2026-07-10 11:12:17 +02:00
Merge branch 'release/1.5.1'
This commit is contained in:
11
CHANGELOG.md
11
CHANGELOG.md
@@ -1,3 +1,14 @@
|
||||
# v1.5.1
|
||||
## 08/23/2018
|
||||
|
||||
1. [](#new)
|
||||
* Added static `Grav\Common\Yaml` class which should be used instead of `Symfony\Component\Yaml\Yaml`
|
||||
1. [](#improved)
|
||||
* Updated deprecated Twig code so it works in both in Twig 1.34+ and Twig 2.4+
|
||||
* Switched to new Grav Yaml class to support Native + Fallback YAML libraries
|
||||
1. [](#bugfix)
|
||||
* Broken handling of user folder in Grav URI object [#2151](https://github.com/getgrav/grav/issues/2151)
|
||||
|
||||
# v1.5.0
|
||||
## 08/17/2018
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
// Some standard defines
|
||||
define('GRAV', true);
|
||||
define('GRAV_VERSION', '1.5.0');
|
||||
define('GRAV_VERSION', '1.5.1');
|
||||
define('GRAV_TESTING', false);
|
||||
define('DS', '/');
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ namespace Grav\Common\Data;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Grav\Common\Yaml;
|
||||
use RocketTheme\Toolbox\Compat\Yaml\Yaml as FallbackYaml;
|
||||
|
||||
class Validation
|
||||
@@ -649,19 +648,8 @@ class Validation
|
||||
return $value;
|
||||
}
|
||||
|
||||
try {
|
||||
return (array) Yaml::parse($value);
|
||||
} catch (ParseException $e) {
|
||||
// If YAML compatibility mode is set on, fall back to older YAML parser.
|
||||
if (Grav::instance()['config']->get('system.strict_mode.yaml_compat', true)) {
|
||||
try {
|
||||
return (array) FallbackYaml::parse($value);
|
||||
} catch (ParseException $e2) {
|
||||
}
|
||||
}
|
||||
return (array) Yaml::parse($value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
namespace Grav\Common\Page;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Yaml;
|
||||
use Grav\Common\Page\Medium\AbstractMedia;
|
||||
use Grav\Common\Page\Medium\GlobalMedia;
|
||||
use Grav\Common\Page\Medium\MediumFactory;
|
||||
use RocketTheme\Toolbox\File\File;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Media extends AbstractMedia
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@ use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\File\CompiledYamlFile;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Language\Language;
|
||||
use Grav\Common\Markdown\Parsedown;
|
||||
use Grav\Common\Markdown\ParsedownExtra;
|
||||
use Grav\Common\Page\Interfaces\PageInterface;
|
||||
@@ -23,10 +22,9 @@ use Grav\Common\Media\Traits\MediaTrait;
|
||||
use Grav\Common\Taxonomy;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Common\Yaml;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\File\MarkdownFile;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
define('PAGE_ORDER_PREFIX_REGEX', '/^[0-9]+\./u');
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class TwigNodeScript extends \Twig_Node implements \Twig_NodeOutputInterface
|
||||
|
||||
/**
|
||||
* TwigNodeScript constructor.
|
||||
* @param \Twig_NodeInterface|null $body
|
||||
* @param \Twig_Node|null $body
|
||||
* @param \Twig_Node_Expression|null $file
|
||||
* @param \Twig_Node_Expression|null $group
|
||||
* @param \Twig_Node_Expression|null $priority
|
||||
@@ -23,12 +23,12 @@ class TwigNodeScript extends \Twig_Node implements \Twig_NodeOutputInterface
|
||||
* @param string|null $tag
|
||||
*/
|
||||
public function __construct(
|
||||
\Twig_NodeInterface $body = null,
|
||||
\Twig_Node $body = null,
|
||||
\Twig_Node_Expression $file = null,
|
||||
\Twig_Node_Expression $group = null,
|
||||
\Twig_Node_Expression $priority = null,
|
||||
\Twig_Node_Expression $attributes = null,
|
||||
$lineno,
|
||||
$lineno = 0,
|
||||
$tag = null
|
||||
)
|
||||
{
|
||||
|
||||
@@ -14,18 +14,18 @@ class TwigNodeStyle extends \Twig_Node implements \Twig_NodeOutputInterface
|
||||
|
||||
/**
|
||||
* TwigNodeAssets constructor.
|
||||
* @param \Twig_NodeInterface|null $body
|
||||
* @param \Twig_Node|null $body
|
||||
* @param \Twig_Node_Expression|null $attributes
|
||||
* @param int $lineno
|
||||
* @param null $tag
|
||||
*/
|
||||
public function __construct(
|
||||
\Twig_NodeInterface $body = null,
|
||||
\Twig_Node $body = null,
|
||||
\Twig_Node_Expression $file = null,
|
||||
\Twig_Node_Expression $group = null,
|
||||
\Twig_Node_Expression $priority = null,
|
||||
\Twig_Node_Expression $attributes = null,
|
||||
$lineno,
|
||||
$lineno = 0,
|
||||
$tag = null
|
||||
)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,13 @@ namespace Grav\Common\Twig\Node;
|
||||
|
||||
class TwigNodeSwitch extends \Twig_Node implements \Twig_NodeOutputInterface
|
||||
{
|
||||
public function __construct(\Twig_NodeInterface $value, \Twig_NodeInterface $cases, \Twig_NodeInterface $default = null, $lineno, $tag = null)
|
||||
public function __construct(
|
||||
\Twig_Node $value,
|
||||
\Twig_Node $cases,
|
||||
\Twig_Node $default = null,
|
||||
$lineno = 0,
|
||||
$tag = null
|
||||
)
|
||||
{
|
||||
parent::__construct(array('value' => $value, 'cases' => $cases, 'default' => $default), array(), $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,12 @@ namespace Grav\Common\Twig\Node;
|
||||
|
||||
class TwigNodeTryCatch extends \Twig_Node
|
||||
{
|
||||
public function __construct(\Twig_NodeInterface $try, \Twig_NodeInterface $catch = null, $lineno, $tag = null)
|
||||
public function __construct(
|
||||
\Twig_Node $try,
|
||||
\Twig_Node $catch = null,
|
||||
$lineno = 0,
|
||||
$tag = null
|
||||
)
|
||||
{
|
||||
parent::__construct(array('try' => $try, 'catch' => $catch), array(), $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class TwigTokenParserScript extends \Twig_TokenParser
|
||||
*
|
||||
* @param \Twig_Token $token A Twig_Token instance
|
||||
*
|
||||
* @return \Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return \Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(\Twig_Token $token)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ class TwigTokenParserStyle extends \Twig_TokenParser
|
||||
*
|
||||
* @param \Twig_Token $token A Twig_Token instance
|
||||
*
|
||||
* @return \Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return \Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(\Twig_Token $token)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ class TwigTokenParserTryCatch extends \Twig_TokenParser
|
||||
*
|
||||
* @param \Twig_Token $token A Twig_Token instance
|
||||
*
|
||||
* @return \Twig_NodeInterface A Twig_NodeInterface instance
|
||||
* @return \Twig_Node A Twig_Node instance
|
||||
*/
|
||||
public function parse(\Twig_Token $token)
|
||||
{
|
||||
|
||||
@@ -125,10 +125,10 @@ class Twig
|
||||
if ($config->get('system.twig.undefined_functions')) {
|
||||
$this->twig->registerUndefinedFunctionCallback(function ($name) {
|
||||
if (function_exists($name)) {
|
||||
return new \Twig_Function_Function($name);
|
||||
return new \Twig_SimpleFunction($name, $name);
|
||||
}
|
||||
|
||||
return new \Twig_Function_Function(function () {
|
||||
return new \Twig_SimpleFunction($name, function () {
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -136,10 +136,10 @@ class Twig
|
||||
if ($config->get('system.twig.undefined_filters')) {
|
||||
$this->twig->registerUndefinedFilterCallback(function ($name) {
|
||||
if (function_exists($name)) {
|
||||
return new \Twig_Filter_Function($name);
|
||||
return new \Twig_SimpleFilter($name, $name);
|
||||
}
|
||||
|
||||
return new \Twig_Filter_Function(function () {
|
||||
return new \Twig_SimpleFilter($name, function () {
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -148,7 +148,7 @@ class Twig
|
||||
|
||||
// set default date format if set in config
|
||||
if ($config->get('system.pages.dateformat.long')) {
|
||||
$this->twig->getExtension('core')->setDateFormat($config->get('system.pages.dateformat.long'));
|
||||
$this->twig->getExtension('Twig_Extension_Core')->setDateFormat($config->get('system.pages.dateformat.long'));
|
||||
}
|
||||
// enable the debug extension if required
|
||||
if ($config->get('system.twig.debug')) {
|
||||
@@ -162,7 +162,7 @@ class Twig
|
||||
$pages = $this->grav['pages'];
|
||||
|
||||
// Set some standard variables for twig
|
||||
$this->twig_vars = $this->twig_vars + [
|
||||
$this->twig_vars += [
|
||||
'config' => $config,
|
||||
'system' => $config->get('system'),
|
||||
'theme' => $config->get('theme'),
|
||||
|
||||
@@ -18,11 +18,11 @@ use Grav\Common\Twig\TokenParser\TwigTokenParserTryCatch;
|
||||
use Grav\Common\Twig\TokenParser\TwigTokenParserMarkdown;
|
||||
use Grav\Common\User\User;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Common\Yaml;
|
||||
use Grav\Common\Markdown\Parsedown;
|
||||
use Grav\Common\Markdown\ParsedownExtra;
|
||||
use Grav\Common\Helpers\Base32;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
|
||||
{
|
||||
@@ -1297,11 +1297,12 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
* Dump/Encode data into YAML format
|
||||
*
|
||||
* @param $data
|
||||
* @param $inline integer number of levels of inline syntax
|
||||
* @return mixed
|
||||
*/
|
||||
public function yamlEncodeFilter($data)
|
||||
public function yamlEncodeFilter($data, $inline = 10)
|
||||
{
|
||||
return Yaml::dump($data, 10);
|
||||
return Yaml::dump($data, $inline);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1336,11 +1336,6 @@ class Uri
|
||||
$scriptPath = str_replace('\\', '/', $_SERVER['PHP_SELF']);
|
||||
$rootPath = str_replace(' ', '%20', rtrim(substr($scriptPath, 0, strpos($scriptPath, 'index.php')), '/'));
|
||||
|
||||
// check if userdir in the path and workaround PHP bug with PHP_SELF
|
||||
if (strpos($this->uri, '/~') !== false && strpos($scriptPath, '/~') === false) {
|
||||
$rootPath = substr($this->uri, 0, strpos($this->uri, '/', 1)) . $rootPath;
|
||||
}
|
||||
|
||||
return $rootPath;
|
||||
}
|
||||
|
||||
|
||||
47
system/src/Grav/Common/Yaml.php
Normal file
47
system/src/Grav/Common/Yaml.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Common;
|
||||
|
||||
use Grav\Framework\File\Formatter\YamlFormatter;
|
||||
|
||||
abstract class Yaml
|
||||
{
|
||||
/** @var YamlFormatter */
|
||||
private static $yaml;
|
||||
|
||||
public static function parse($data)
|
||||
{
|
||||
if (null === static::$yaml) {
|
||||
static::init();
|
||||
}
|
||||
|
||||
return static::$yaml->decode($data);
|
||||
}
|
||||
|
||||
public static function dump($data, $inline = null, $indent = null)
|
||||
{
|
||||
if (null === static::$yaml) {
|
||||
static::init();
|
||||
}
|
||||
|
||||
return static::$yaml->encode($data, $inline, $indent);
|
||||
}
|
||||
|
||||
private static function init()
|
||||
{
|
||||
$config = [
|
||||
'inline' => 5,
|
||||
'indent' => 2,
|
||||
'native' => true,
|
||||
'compat' => true
|
||||
];
|
||||
|
||||
static::$yaml = new YamlFormatter($config);
|
||||
}
|
||||
}
|
||||
@@ -58,13 +58,13 @@ class YamlFormatter implements FormatterInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data)
|
||||
public function encode($data, $inline = null, $indent = null)
|
||||
{
|
||||
try {
|
||||
return (string) YamlParser::dump(
|
||||
$data,
|
||||
$this->config['inline'],
|
||||
$this->config['indent'],
|
||||
$inline ? (int) $inline : $this->config['inline'],
|
||||
$indent ? (int) $indent : $this->config['indent'],
|
||||
YamlParser::DUMP_EXCEPTION_ON_INVALID_TYPE
|
||||
);
|
||||
} catch (DumpException $e) {
|
||||
|
||||
Reference in New Issue
Block a user