mirror of
				https://github.com/getgrav/grav-plugin-admin.git
				synced 2025-11-03 20:05:53 +01:00 
			
		
		
		
	Switched to new Grav Yaml class
This commit is contained in:
		@@ -13,7 +13,7 @@ docs: https://github.com/getgrav/grav-plugin-admin/blob/develop/README.md
 | 
			
		||||
license: MIT
 | 
			
		||||
 | 
			
		||||
dependencies:
 | 
			
		||||
    - { name: grav, version: '>=1.4.5' }
 | 
			
		||||
    - { name: grav, version: '>=1.5.1' }
 | 
			
		||||
    - { name: form, version: '>=2.14.0' }
 | 
			
		||||
    - { name: login, version: '>=2.7.0' }
 | 
			
		||||
    - { name: email, version: '>=2.7.0' }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,9 @@
 | 
			
		||||
namespace Grav\Plugin\Admin\Twig;
 | 
			
		||||
 | 
			
		||||
use Grav\Common\Grav;
 | 
			
		||||
use Grav\Common\Yaml;
 | 
			
		||||
use Grav\Common\Language\Language;
 | 
			
		||||
use Grav\Common\Page\Page;
 | 
			
		||||
use Symfony\Component\Yaml\Yaml;
 | 
			
		||||
use Symfony\Component\Yaml\Parser;
 | 
			
		||||
 | 
			
		||||
class AdminTwigExtension extends \Twig_Extension
 | 
			
		||||
{
 | 
			
		||||
@@ -81,7 +80,7 @@ class AdminTwigExtension extends \Twig_Extension
 | 
			
		||||
        return $this->grav['admin']->translate($args, $lang);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function toYamlFilter($value, $inline = true)
 | 
			
		||||
    public function toYamlFilter($value, $inline = null)
 | 
			
		||||
    {
 | 
			
		||||
        return Yaml::dump($value, $inline);
 | 
			
		||||
 | 
			
		||||
@@ -89,8 +88,7 @@ class AdminTwigExtension extends \Twig_Extension
 | 
			
		||||
 | 
			
		||||
    public function fromYamlFilter($value)
 | 
			
		||||
    {
 | 
			
		||||
        $yaml = new Parser();
 | 
			
		||||
        return $yaml->parse($value);
 | 
			
		||||
        return Yaml::parse($value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function adminNicetimeFilter($date, $long_strings = true)
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceIterator;
 | 
			
		||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
 | 
			
		||||
use RocketTheme\Toolbox\Session\Message;
 | 
			
		||||
use RocketTheme\Toolbox\Session\Session;
 | 
			
		||||
use Symfony\Component\Yaml\Yaml;
 | 
			
		||||
use Grav\Common\Yaml;
 | 
			
		||||
use Composer\Semver\Semver;
 | 
			
		||||
use PicoFeed\Reader\Reader;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,12 +19,12 @@ use Grav\Common\Utils;
 | 
			
		||||
use Grav\Common\Backup\ZipBackup;
 | 
			
		||||
use Grav\Plugin\Admin\Twig\AdminTwigExtension;
 | 
			
		||||
use Grav\Plugin\Login\TwoFactorAuth\TwoFactorAuth;
 | 
			
		||||
use Grav\Common\Yaml;
 | 
			
		||||
use RocketTheme\Toolbox\Event\Event;
 | 
			
		||||
use RocketTheme\Toolbox\File\File;
 | 
			
		||||
use RocketTheme\Toolbox\File\JsonFile;
 | 
			
		||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
 | 
			
		||||
use Symfony\Component\Yaml\Exception\ParseException;
 | 
			
		||||
use Symfony\Component\Yaml\Yaml;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Class AdminController
 | 
			
		||||
@@ -760,16 +760,8 @@ class AdminController extends AdminBaseController
 | 
			
		||||
    public function checkValidFrontmatter($frontmatter)
 | 
			
		||||
    {
 | 
			
		||||
        try {
 | 
			
		||||
            // Try native PECL YAML PHP extension first if available.
 | 
			
		||||
            if (function_exists('yaml_parse')) {
 | 
			
		||||
                $saved = @ini_get('yaml.decode_php');
 | 
			
		||||
                @ini_set('yaml.decode_php', 0);
 | 
			
		||||
                @yaml_parse("---\n" . $frontmatter . "\n...");
 | 
			
		||||
                @ini_set('yaml.decode_php', $saved);
 | 
			
		||||
            } else {
 | 
			
		||||
                Yaml::parse($frontmatter);
 | 
			
		||||
            }
 | 
			
		||||
        } catch (ParseException $e) {
 | 
			
		||||
            Yaml::parse($frontmatter);
 | 
			
		||||
        } catch (\RuntimeException $e) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user