upgrade grav
This commit is contained in:
parent
c87ac3e07b
commit
8fc889fc17
|
@ -1,6 +1,6 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Grav
|
||||
Copyright (c) 2018 Grav
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
Binary file not shown.
1
bin/grav
1
bin/grav
|
@ -41,5 +41,6 @@ $app->addCommands(array(
|
|||
new \Grav\Console\Cli\ClearCacheCommand(),
|
||||
new \Grav\Console\Cli\BackupCommand(),
|
||||
new \Grav\Console\Cli\NewProjectCommand(),
|
||||
new \Grav\Console\Cli\SecurityCommand(),
|
||||
));
|
||||
$app->run();
|
||||
|
|
|
@ -6,29 +6,33 @@
|
|||
"homepage": "http://getgrav.org",
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"php": ">=5.6.4",
|
||||
"twig/twig": "~1.24",
|
||||
"erusev/parsedown": "~1.6",
|
||||
"erusev/parsedown": "1.6.4",
|
||||
"erusev/parsedown-extra": "~0.7",
|
||||
"symfony/yaml": "~2.8",
|
||||
"symfony/console": "~2.8",
|
||||
"symfony/event-dispatcher": "~2.8",
|
||||
"symfony/var-dumper": "~2.8",
|
||||
"symfony/yaml": "~3.4",
|
||||
"symfony/console": "~3.4",
|
||||
"symfony/event-dispatcher": "~3.4",
|
||||
"symfony/var-dumper": "~3.4",
|
||||
"symfony/polyfill-iconv": "~1.0",
|
||||
"doctrine/cache": "1.6.*",
|
||||
"doctrine/collections": "1.3",
|
||||
"doctrine/cache": "^1.6",
|
||||
"doctrine/collections": "^1.4",
|
||||
"psr/simple-cache": "^1.0",
|
||||
"psr/http-message": "^1.0",
|
||||
"guzzlehttp/psr7": "^1.4",
|
||||
"filp/whoops": "~2.0",
|
||||
"matthiasmullie/minify": "^1.3",
|
||||
"monolog/monolog": "~1.0",
|
||||
"gregwar/image": "2.*",
|
||||
"donatj/phpuseragentparser": "~0.3",
|
||||
"pimple/pimple": "~3.0",
|
||||
"rockettheme/toolbox": "~1.0",
|
||||
"pimple/pimple": "~3.2",
|
||||
"rockettheme/toolbox": "~1.4",
|
||||
"maximebf/debugbar": "~1.10",
|
||||
"ext-mbstring": "*",
|
||||
"ext-openssl": "*",
|
||||
"ext-curl": "*",
|
||||
"ext-zip": "*",
|
||||
"ext-json": "*",
|
||||
"league/climate": "^3.2",
|
||||
"antoligy/dom-string-iterators": "^1.0",
|
||||
"miljar/php-exif": "^0.6.3",
|
||||
|
@ -40,6 +44,11 @@
|
|||
"fzaninotto/faker": "^1.5",
|
||||
"victorjonsson/markdowndocs": "dev-master"
|
||||
},
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "5.6.4"
|
||||
}
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
|
|
1089
composer.lock
generated
1089
composer.lock
generated
File diff suppressed because it is too large
Load diff
12
index.php
12
index.php
|
@ -1,13 +1,15 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Core
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav;
|
||||
define('GRAV_PHP_MIN', '5.5.9');
|
||||
|
||||
define('GRAV_PHP_MIN', '5.6.4');
|
||||
|
||||
// Ensure vendor libraries exist
|
||||
$autoload = __DIR__ . '/vendor/autoload.php';
|
||||
|
@ -15,9 +17,9 @@ if (!is_file($autoload)) {
|
|||
die("Please run: <i>bin/grav install</i>");
|
||||
}
|
||||
|
||||
if (PHP_SAPI == 'cli-server') {
|
||||
if (PHP_SAPI === 'cli-server') {
|
||||
if (!isset($_SERVER['PHP_CLI_ROUTER'])) {
|
||||
die("PHP webserver requires a router to run Grav, please use: <pre>php -S {$_SERVER["SERVER_NAME"]}:{$_SERVER["SERVER_PORT"]} system/router.php</pre>");
|
||||
die("PHP webserver requires a router to run Grav, please use: <pre>php -S {$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']} system/router.php</pre>");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +31,7 @@ if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
|
|||
}
|
||||
|
||||
// Register the auto-loader.
|
||||
$loader = require_once $autoload;
|
||||
$loader = require $autoload;
|
||||
|
||||
// Set timezone to default, falls back to system if php.ini not set
|
||||
date_default_timezone_set(@date_default_timezone_get());
|
||||
|
|
6
system/assets/jquery/jquery-3.x.min.js
vendored
6
system/assets/jquery/jquery-3.x.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,5 @@
|
|||
body header {
|
||||
background: #8552A2;
|
||||
background: #3085EE;
|
||||
}
|
||||
|
||||
body .left-panel {
|
||||
|
|
99
system/blueprints/config/security.yaml
Normal file
99
system/blueprints/config/security.yaml
Normal file
|
@ -0,0 +1,99 @@
|
|||
title: PLUGIN_ADMIN.SECURITY
|
||||
|
||||
form:
|
||||
validation: loose
|
||||
fields:
|
||||
|
||||
xss_section:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.XSS_SECURITY
|
||||
underline: true
|
||||
|
||||
xss_whitelist:
|
||||
type: selectize
|
||||
size: large
|
||||
label: PLUGIN_ADMIN.XSS_WHITELIST_PERMISSIONS
|
||||
help: PLUGIN_ADMIN.XSS_WHITELIST_PERMISSIONS_HELP
|
||||
placeholder: 'admin.super'
|
||||
classes: fancy
|
||||
validate:
|
||||
type: commalist
|
||||
|
||||
xss_enabled.on_events:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.XSS_ON_EVENTS
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
default: true
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
xss_enabled.invalid_protocols:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.XSS_INVALID_PROTOCOLS
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
default: true
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
xss_enabled.moz_binding:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.XSS_MOZ_BINDINGS
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
default: true
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
xss_enabled.html_inline_styles:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.XSS_HTML_INLINE_STYLES
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
default: true
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
xss_enabled.dangerous_tags:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.XSS_DANGEROUS_TAGS
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
default: true
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
xss_dangerous_tags:
|
||||
type: selectize
|
||||
size: large
|
||||
label: PLUGIN_ADMIN.XSS_DANGEROUS_TAGS_LIST
|
||||
classes: fancy
|
||||
validate:
|
||||
type: commalist
|
||||
|
||||
uploads_section:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.UPLOADS_SECURITY
|
||||
underline: true
|
||||
|
||||
|
||||
uploads_dangerous_extensions:
|
||||
type: selectize
|
||||
size: large
|
||||
label: PLUGIN_ADMIN.UPLOADS_DANGEROUS_EXTENSIONS
|
||||
help: PLUGIN_ADMIN.UPLOADS_DANGEROUS_EXTENSIONS_HELP
|
||||
classes: fancy
|
||||
validate:
|
||||
type: commalist
|
||||
|
|
@ -835,6 +835,8 @@ form:
|
|||
-1: PLUGIN_ADMIN.ERROR_SYSTEM
|
||||
0: PLUGIN_ADMIN.ERROR_SIMPLE
|
||||
1: PLUGIN_ADMIN.ERROR_FULL_BACKTRACE
|
||||
validate:
|
||||
type: int
|
||||
|
||||
|
||||
errors.log:
|
||||
|
@ -994,6 +996,18 @@ form:
|
|||
validate:
|
||||
type: bool
|
||||
|
||||
session.initialize:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.SESSION_INITIALIZE
|
||||
help: PLUGIN_ADMIN.SESSION_INITIALIZE_HELP
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
default: true
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
session.timeout:
|
||||
type: text
|
||||
size: small
|
||||
|
@ -1204,3 +1218,27 @@ form:
|
|||
placeholder: "e.g. http://yoursite.com/yourpath"
|
||||
label: PLUGIN_ADMIN.CUSTOM_BASE_URL
|
||||
help: PLUGIN_ADMIN.CUSTOM_BASE_URL_HELP
|
||||
|
||||
strict_mode.yaml_compat:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.STRICT_YAML_COMPAT
|
||||
highlight: 1
|
||||
default: 1
|
||||
help: PLUGIN_ADMIN.STRICT_YAML_COMPAT_HELP
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
strict_mode.twig_compat:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.STRICT_TWIG_COMPAT
|
||||
highlight: 1
|
||||
default: 1
|
||||
help: PLUGIN_ADMIN.STRICT_TWIG_COMPAT_HELP
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
validate:
|
||||
type: bool
|
||||
|
|
|
@ -21,6 +21,9 @@ form:
|
|||
title: PLUGIN_ADMIN.CONTENT
|
||||
|
||||
fields:
|
||||
xss_check:
|
||||
type: xss
|
||||
|
||||
header.title:
|
||||
type: text
|
||||
autofocus: true
|
||||
|
@ -310,6 +313,31 @@ form:
|
|||
toggleable: true
|
||||
help: PLUGIN_ADMIN.APPEND_URL_EXT_HELP
|
||||
|
||||
routes_only:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.ROUTE_OVERRIDES
|
||||
underline: true
|
||||
|
||||
fields:
|
||||
|
||||
header.routes.default:
|
||||
type: text
|
||||
toggleable: true
|
||||
label: PLUGIN_ADMIN.ROUTE_DEFAULT
|
||||
|
||||
header.routes.canonical:
|
||||
type: text
|
||||
toggleable: true
|
||||
label: PLUGIN_ADMIN.ROUTE_CANONICAL
|
||||
|
||||
header.routes.aliases:
|
||||
type: array
|
||||
toggleable: true
|
||||
value_only: true
|
||||
size: large
|
||||
label: PLUGIN_ADMIN.ROUTE_ALIASES
|
||||
|
||||
|
||||
admin_only:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.ADMIN_SPECIFIC_OVERRIDES
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
title: PLUGIN_ADMIN:EXTERNAL
|
||||
@extends:
|
||||
extends@:
|
||||
type: default
|
||||
context: blueprints://pages
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
title: PLUGIN_ADMIN.MODULAR
|
||||
@extends:
|
||||
type: default
|
||||
context: blueprints://pages
|
||||
extends@: default
|
||||
|
||||
form:
|
||||
fields:
|
||||
|
@ -13,35 +11,28 @@ form:
|
|||
content:
|
||||
fields:
|
||||
|
||||
modular_title:
|
||||
type: spacer
|
||||
title: PLUGIN_ADMIN.MODULAR_SETUP
|
||||
|
||||
header.content.items:
|
||||
type: select
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.ITEMS
|
||||
default: '@self.modular'
|
||||
options:
|
||||
'@self.modular': Modular Children
|
||||
size: medium
|
||||
|
||||
header.content.order.by:
|
||||
type: select
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.ORDER_BY
|
||||
default: date
|
||||
options:
|
||||
folder: PLUGIN_ADMIN.FOLDER
|
||||
title: PLUGIN_ADMIN.TITLE
|
||||
date: PLUGIN_ADMIN.DATE
|
||||
default: PLUGIN_ADMIN.DEFAULT
|
||||
placeholder: date
|
||||
help:
|
||||
size: small
|
||||
|
||||
header.content.order.dir:
|
||||
type: select
|
||||
type: text
|
||||
label: PLUGIN_ADMIN.ORDER
|
||||
default: desc
|
||||
options:
|
||||
asc: PLUGIN_ADMIN.ASCENDING
|
||||
desc: PLUGIN_ADMIN.DESCENDING
|
||||
help: '"desc" or "asc" are valid values'
|
||||
placeholder: desc
|
||||
size: small
|
||||
|
||||
header.process:
|
||||
type: ignore
|
||||
content:
|
||||
type: ignore
|
||||
header.media_order:
|
||||
type: ignore
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ form:
|
|||
type: password
|
||||
size: large
|
||||
label: PLUGIN_ADMIN.PASSWORD
|
||||
autocomplete: new-password
|
||||
validate:
|
||||
required: false
|
||||
message: PLUGIN_ADMIN.PASSWORD_VALIDATION_MESSAGE
|
||||
|
@ -93,6 +94,7 @@ form:
|
|||
twofa_secret:
|
||||
type: 2fa_secret
|
||||
outerclasses: 'twofa-secret'
|
||||
markdown: true
|
||||
label: PLUGIN_ADMIN.2FA_SECRET
|
||||
sublabel: PLUGIN_ADMIN.2FA_SECRET_HELP
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ types:
|
|||
thumb: media/thumb-flv.png
|
||||
mime: video/x-flv
|
||||
webm:
|
||||
type: file
|
||||
type: video
|
||||
thumb: media/thumb-webm.png
|
||||
mime: video/webm
|
||||
ogv:
|
||||
|
|
31
system/config/security.yaml
Normal file
31
system/config/security.yaml
Normal file
|
@ -0,0 +1,31 @@
|
|||
xss_whitelist: [admin.super] # Whitelist of user access that should 'skip' XSS checking
|
||||
xss_enabled:
|
||||
on_events: true
|
||||
invalid_protocols: true
|
||||
moz_binding: true
|
||||
html_inline_styles: true
|
||||
dangerous_tags: true
|
||||
xss_dangerous_tags:
|
||||
- applet
|
||||
- meta
|
||||
- xml
|
||||
- blink
|
||||
- link
|
||||
- style
|
||||
- script
|
||||
- embed
|
||||
- object
|
||||
- iframe
|
||||
- frame
|
||||
- frameset
|
||||
- ilayer
|
||||
- layer
|
||||
- bgsound
|
||||
- title
|
||||
- base
|
||||
uploads_dangerous_extensions:
|
||||
- php
|
||||
- html
|
||||
- htm
|
||||
- js
|
||||
- exe
|
|
@ -3,7 +3,7 @@ default_lang: en # Default language for site (potenti
|
|||
|
||||
author:
|
||||
name: John Appleseed # Default author name
|
||||
email: 'john@email.com' # Default author email
|
||||
email: 'john@example.com' # Default author email
|
||||
|
||||
taxonomies: [category,tag] # Arbitrary list of taxonomy types
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ home:
|
|||
hide_in_urls: false # Hide the home route in URLs
|
||||
|
||||
pages:
|
||||
theme: antimatter # Default theme (defaults to "antimatter" theme)
|
||||
theme: quark # Default theme (defaults to "quark" theme)
|
||||
order:
|
||||
by: default # Order pages by "default", "alpha" or "date"
|
||||
dir: asc # Default ordering direction, "asc" or "desc"
|
||||
|
@ -88,7 +88,7 @@ twig:
|
|||
cache: true # Set to true to enable Twig caching
|
||||
debug: true # Enable Twig debug
|
||||
auto_reload: true # Refresh cache on changes
|
||||
autoescape: false # Autoescape Twig vars
|
||||
autoescape: false # Autoescape Twig vars (DEPRECATED, always enabled in strict mode)
|
||||
undefined_functions: true # Allow undefined functions
|
||||
undefined_filters: true # Allow undefined filters
|
||||
umask_fix: false # By default Twig creates cached files as 755, fix switches this to 775
|
||||
|
@ -132,6 +132,7 @@ media:
|
|||
|
||||
session:
|
||||
enabled: true # Enable Session support
|
||||
initialize: true # Initialize session from Grav (if false, plugin needs to start the session)
|
||||
timeout: 1800 # Timeout in seconds
|
||||
name: grav-site # Name prefix of the session cookie. Use alphanumeric, dashes or underscores only. Do not use dots in the session name
|
||||
secure: false # Set session secure. If true, indicates that communication for this cookie must be over an encrypted transmission. Enable this only on sites that run exclusively on HTTPS
|
||||
|
@ -145,3 +146,7 @@ gpm:
|
|||
method: 'auto' # Either 'curl', 'fopen' or 'auto'. 'auto' will try fopen first and if not available cURL
|
||||
verify_peer: true # Sometimes on some systems (Windows most commonly) GPM is unable to connect because the SSL certificate cannot be verified. Disabling this setting might help.
|
||||
official_gpm_only: true # By default GPM direct-install will only allow URLs via the official GPM proxy to ensure security
|
||||
|
||||
strict_mode:
|
||||
yaml_compat: true # Grav 1.5+: Enables YAML backwards compatibility
|
||||
twig_compat: true # Grav 1.5+: Enables deprecated Twig autoescape setting (autoescape: false)
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
/**
|
||||
* @package Grav.Core
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
// Some standard defines
|
||||
define('GRAV', true);
|
||||
define('GRAV_VERSION', '1.3.10');
|
||||
//define('GRAV_TESTING', true);
|
||||
define('GRAV_VERSION', '1.5.5');
|
||||
define('GRAV_TESTING', false);
|
||||
define('DS', '/');
|
||||
|
||||
if (!defined('GRAV_PHP_MIN')) {
|
||||
define('GRAV_PHP_MIN', '5.5.9');
|
||||
define('GRAV_PHP_MIN', '5.6.4');
|
||||
}
|
||||
|
||||
// Directories and Paths
|
||||
|
|
|
@ -72,7 +72,6 @@ NICETIME:
|
|||
SEC: sec
|
||||
MIN: min
|
||||
HR: hr
|
||||
DAY: day
|
||||
WK: wk
|
||||
MO: mo
|
||||
YR: yr
|
||||
|
@ -88,7 +87,6 @@ NICETIME:
|
|||
SEC_PLURAL: secs
|
||||
MIN_PLURAL: mins
|
||||
HR_PLURAL: hrs
|
||||
DAY_PLURAL: days
|
||||
WK_PLURAL: wks
|
||||
MO_PLURAL: mos
|
||||
YR_PLURAL: yrs
|
||||
|
|
|
@ -30,7 +30,6 @@ NICETIME:
|
|||
SEC: 秒
|
||||
MIN: 分
|
||||
HR: 時
|
||||
DAY: 日
|
||||
WK: 週
|
||||
MO: 月
|
||||
YR: 年
|
||||
|
@ -46,7 +45,6 @@ NICETIME:
|
|||
SEC_PLURAL: 秒
|
||||
MIN_PLURAL: 分
|
||||
HR_PLURAL: 時
|
||||
DAY_PLURAL: 日
|
||||
WK_PLURAL: 週
|
||||
MO_PLURAL: 月
|
||||
YR_PLURAL: 年
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Core
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -617,7 +617,7 @@ class Assets
|
|||
|
||||
$inlineGroup = array_key_exists('loading', $attributes) && $attributes['loading'] === 'inline';
|
||||
|
||||
$attributes = $this->attributes(array_merge(['type' => 'text/javascript'], $attributes));
|
||||
$attributes = $this->attributes($attributes);
|
||||
|
||||
$output = '';
|
||||
$inline_js = '';
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Backup
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -32,7 +32,7 @@ class ZipBackup
|
|||
/**
|
||||
* Backup
|
||||
*
|
||||
* @param null $destination
|
||||
* @param string|null $destination
|
||||
* @param callable|null $messager
|
||||
*
|
||||
* @return null|string
|
||||
|
@ -107,18 +107,19 @@ class ZipBackup
|
|||
* @param $exclusiveLength
|
||||
* @param $messager
|
||||
*/
|
||||
private static function folderToZip($folder, \ZipArchive &$zipFile, $exclusiveLength, callable $messager = null)
|
||||
private static function folderToZip($folder, \ZipArchive $zipFile, $exclusiveLength, callable $messager = null)
|
||||
{
|
||||
$handle = opendir($folder);
|
||||
while (false !== $f = readdir($handle)) {
|
||||
if ($f != '.' && $f != '..') {
|
||||
if ($f !== '.' && $f !== '..') {
|
||||
$filePath = "$folder/$f";
|
||||
// Remove prefix from file path before add to zip.
|
||||
$localPath = substr($filePath, $exclusiveLength);
|
||||
|
||||
if (in_array($f, static::$ignoreFolders)) {
|
||||
continue;
|
||||
} elseif (in_array($localPath, static::$ignorePaths)) {
|
||||
}
|
||||
if (in_array($localPath, static::$ignorePaths)) {
|
||||
$zipFile->addEmptyDir($f);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -429,6 +429,14 @@ class Cache extends Getters
|
|||
$output[] = '';
|
||||
}
|
||||
|
||||
// Clear stat cache
|
||||
@clearstatcache();
|
||||
|
||||
// Clear opcache
|
||||
if (function_exists('opcache_reset')) {
|
||||
@opcache_reset();
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Config
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Config
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
namespace Grav\Common\Config;
|
||||
|
@ -32,7 +32,7 @@ class CompiledBlueprints extends CompiledBase
|
|||
*/
|
||||
public function checksum()
|
||||
{
|
||||
if (!isset($this->checksum)) {
|
||||
if (null === $this->checksum) {
|
||||
$this->checksum = md5(json_encode($this->files) . json_encode($this->getTypes()) . $this->version);
|
||||
}
|
||||
|
||||
|
@ -92,6 +92,7 @@ class CompiledBlueprints extends CompiledBase
|
|||
|
||||
// Convert file list into parent list.
|
||||
$list = [];
|
||||
/** @var array $files */
|
||||
foreach ($this->files as $files) {
|
||||
foreach ($files as $name => $item) {
|
||||
$list[$name][] = $this->path . $item['file'];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Config
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Config
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -60,7 +60,7 @@ class CompiledLanguages extends CompiledBase
|
|||
{
|
||||
$file = CompiledYamlFile::instance($filename);
|
||||
if (preg_match('|languages\.yaml$|', $filename)) {
|
||||
$this->object->mergeRecursive($file->content());
|
||||
$this->object->mergeRecursive((array) $file->content());
|
||||
} else {
|
||||
$this->object->mergeRecursive([$name => $file->content()]);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Config
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -16,6 +16,7 @@ use Grav\Common\Utils;
|
|||
|
||||
class Config extends Data
|
||||
{
|
||||
/** @var string */
|
||||
protected $checksum;
|
||||
protected $modified = false;
|
||||
protected $timestamp = 0;
|
||||
|
@ -108,6 +109,8 @@ class Config extends Data
|
|||
*/
|
||||
public function getLanguages()
|
||||
{
|
||||
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use Grav::instance()[\'languages\'] instead', E_USER_DEPRECATED);
|
||||
|
||||
return Grav::instance()['languages'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Config
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -207,7 +207,7 @@ class ConfigFileFinder
|
|||
continue;
|
||||
}
|
||||
|
||||
$name = $directory->getBasename();
|
||||
$name = $directory->getFilename();
|
||||
$find = ($lookup ?: $name) . '.yaml';
|
||||
$filename = "{$path}/{$name}/{$find}";
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Config
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Config
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -133,11 +133,12 @@ class Setup extends Data
|
|||
*/
|
||||
public function __construct($container)
|
||||
{
|
||||
$environment = isset(static::$environment) ? static::$environment : ($container['uri']->environment() ?: 'localhost');
|
||||
$environment = null !== static::$environment ? static::$environment : ($container['uri']->environment() ?: 'localhost');
|
||||
|
||||
// Pre-load setup.php which contains our initial configuration.
|
||||
// Configuration may contain dynamic parts, which is why we need to always load it.
|
||||
$file = GRAV_ROOT . '/setup.php';
|
||||
// If "GRAVE_SETUP_PATH" has been defined, use it, otherwise use defaults.
|
||||
$file = defined('GRAV_SETUP_PATH') ? GRAV_SETUP_PATH : GRAV_ROOT . '/setup.php';
|
||||
$setup = is_file($file) ? (array) include $file : [];
|
||||
|
||||
// Add default streams defined in beginning of the class.
|
||||
|
@ -151,11 +152,13 @@ class Setup extends Data
|
|||
|
||||
// Set up environment.
|
||||
$this->def('environment', $environment ?: 'cli');
|
||||
$this->def('streams.schemes.environment.prefixes', ['' => ($environment ? ["user://{$this->environment}"] : [])]);
|
||||
$this->def('streams.schemes.environment.prefixes', ['' => $environment ? ["user://{$this->environment}"] : []]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
|
@ -175,7 +178,7 @@ class Setup extends Data
|
|||
// Update streams.
|
||||
foreach (array_reverse($files) as $path) {
|
||||
$file = CompiledYamlFile::instance($path);
|
||||
$content = $file->content();
|
||||
$content = (array)$file->content();
|
||||
if (!empty($content['schemes'])) {
|
||||
$this->items['streams']['schemes'] = $content['schemes'] + $this->items['streams']['schemes'];
|
||||
}
|
||||
|
@ -196,6 +199,7 @@ class Setup extends Data
|
|||
* Initialize resource locator by using the configuration.
|
||||
*
|
||||
* @param UniformResourceLocator $locator
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function initializeLocator(UniformResourceLocator $locator)
|
||||
{
|
||||
|
@ -212,7 +216,7 @@ class Setup extends Data
|
|||
$force = isset($config['force']) ? $config['force'] : false;
|
||||
|
||||
if (isset($config['prefixes'])) {
|
||||
foreach ($config['prefixes'] as $prefix => $paths) {
|
||||
foreach ((array)$config['prefixes'] as $prefix => $paths) {
|
||||
$locator->addPath($scheme, $prefix, $paths, $override, $force);
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +233,7 @@ class Setup extends Data
|
|||
$schemes = [];
|
||||
foreach ((array) $this->get('streams.schemes') as $scheme => $config) {
|
||||
$type = !empty($config['type']) ? $config['type'] : 'ReadOnlyStream';
|
||||
if ($type[0] != '\\') {
|
||||
if ($type[0] !== '\\') {
|
||||
$type = '\\RocketTheme\\Toolbox\\StreamWrapper\\' . $type;
|
||||
}
|
||||
|
||||
|
@ -242,6 +246,8 @@ class Setup extends Data
|
|||
/**
|
||||
* @param UniformResourceLocator $locator
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \BadMethodCallException
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected function check(UniformResourceLocator $locator)
|
||||
{
|
||||
|
@ -256,18 +262,22 @@ class Setup extends Data
|
|||
);
|
||||
}
|
||||
|
||||
if (!$locator->findResource('environment://config', true)) {
|
||||
// If environment does not have its own directory, remove it from the lookup.
|
||||
$this->set('streams.schemes.environment.prefixes', ['config' => []]);
|
||||
$this->initializeLocator($locator);
|
||||
}
|
||||
try {
|
||||
if (!$locator->findResource('environment://config', true)) {
|
||||
// If environment does not have its own directory, remove it from the lookup.
|
||||
$this->set('streams.schemes.environment.prefixes', ['config' => []]);
|
||||
$this->initializeLocator($locator);
|
||||
}
|
||||
|
||||
// Create security.yaml if it doesn't exist.
|
||||
$filename = $locator->findResource('config://security.yaml', true, true);
|
||||
$file = YamlFile::instance($filename);
|
||||
if (!$file->exists()) {
|
||||
$file->save(['salt' => Utils::generateRandomString(14)]);
|
||||
$file->free();
|
||||
// Create security.yaml if it doesn't exist.
|
||||
$filename = $locator->findResource('config://security.yaml', true, true);
|
||||
$file = YamlFile::instance($filename);
|
||||
if (!$file->exists()) {
|
||||
$file->save(['salt' => Utils::generateRandomString(14)]);
|
||||
$file->free();
|
||||
}
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new \RuntimeException(sprintf('Grav failed to initialize: %s', $e->getMessage()), 500, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Data
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Data
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -78,7 +78,7 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
|||
} elseif (is_array($field) && is_array($val)) {
|
||||
// Array has been defined in blueprints.
|
||||
$messages += $this->validateArray($field, $val);
|
||||
} elseif (isset($rules['validation']) && $rules['validation'] == 'strict') {
|
||||
} elseif (isset($rules['validation']) && $rules['validation'] === 'strict') {
|
||||
// Undefined/extra item.
|
||||
throw new \RuntimeException(sprintf('%s is not defined in blueprints', $key));
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
|||
} elseif (is_array($field) && is_array($val)) {
|
||||
// Array has been defined in blueprints.
|
||||
$field = $this->filterArray($field, $val);
|
||||
} elseif (isset($rules['validation']) && $rules['validation'] == 'strict') {
|
||||
} elseif (isset($rules['validation']) && $rules['validation'] === 'strict') {
|
||||
$field = null;
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
|||
if (isset($data[$name])) {
|
||||
continue;
|
||||
}
|
||||
if ($field['type'] == 'file' && isset($data['data']['name'][$name])) { //handle case of file input fields required
|
||||
if ($field['type'] === 'file' && isset($data['data']['name'][$name])) { //handle case of file input fields required
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
|||
$default = isset($field[$property]) ? $field[$property] : null;
|
||||
$config = Grav::instance()['config']->get($value, $default);
|
||||
|
||||
if (!is_null($config)) {
|
||||
if (null !== $config) {
|
||||
$field[$property] = $config;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Data
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -65,11 +65,11 @@ class Blueprints
|
|||
|
||||
/** @var \DirectoryIterator $file */
|
||||
foreach ($iterator as $file) {
|
||||
if (!$file->isFile() || '.' . $file->getExtension() != YAML_EXT) {
|
||||
if (!$file->isFile() || '.' . $file->getExtension() !== YAML_EXT) {
|
||||
continue;
|
||||
}
|
||||
$name = $file->getBasename(YAML_EXT);
|
||||
$this->types[$name] = ucfirst(strtr($name, '_', ' '));
|
||||
$this->types[$name] = ucfirst(str_replace('_', ' ', $name));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Data
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -233,6 +233,7 @@ class Data implements DataInterface, \ArrayAccess, \Countable, ExportInterface
|
|||
|
||||
/**
|
||||
* Save data if storage has been defined.
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Data
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Data
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -10,9 +10,8 @@ namespace Grav\Common\Data;
|
|||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Parser;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Grav\Common\Yaml;
|
||||
use RocketTheme\Toolbox\Compat\Yaml\Yaml as FallbackYaml;
|
||||
|
||||
class Validation
|
||||
{
|
||||
|
@ -33,7 +32,7 @@ class Validation
|
|||
$method = 'type'.strtr($type, '-', '_');
|
||||
|
||||
// If value isn't required, we will stop validation if empty value is given.
|
||||
if ((empty($validate['required']) || (isset($validate['required']) && $validate['required'] !== true)) && ($value === null || $value === '' || ($field['type'] === 'checkbox' && $value == false))) {
|
||||
if ((empty($validate['required']) || (isset($validate['required']) && $validate['required'] !== true)) && ($value === null || $value === '' || (($field['type'] === 'checkbox' || $field['type'] === 'switch') && $value == false))) {
|
||||
return $messages;
|
||||
}
|
||||
|
||||
|
@ -41,11 +40,6 @@ class Validation
|
|||
$field['type'] = 'text';
|
||||
}
|
||||
|
||||
// If this is a YAML field, stop validation
|
||||
if (isset($field['yaml']) && $field['yaml'] === true) {
|
||||
return $messages;
|
||||
}
|
||||
|
||||
// Get language class.
|
||||
$language = Grav::instance()['language'];
|
||||
|
||||
|
@ -54,6 +48,12 @@ class Validation
|
|||
? $language->translate($field['validate']['message'])
|
||||
: $language->translate('FORM.INVALID_INPUT', null, true) . ' "' . $language->translate($name) . '"';
|
||||
|
||||
|
||||
// If this is a YAML field validate/filter as such
|
||||
if ($type != 'yaml' && isset($field['yaml']) && $field['yaml'] === true) {
|
||||
$method = 'typeYaml';
|
||||
}
|
||||
|
||||
if (method_exists(__CLASS__, $method)) {
|
||||
$success = self::$method($value, $validate, $field);
|
||||
} else {
|
||||
|
@ -100,15 +100,16 @@ class Validation
|
|||
$field['type'] = 'text';
|
||||
}
|
||||
|
||||
// If this is a YAML field, simply parse it and return the value.
|
||||
if (isset($field['yaml']) && $field['yaml'] === true) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
// Validate type with fallback type text.
|
||||
$type = (string) isset($field['validate']['type']) ? $field['validate']['type'] : $field['type'];
|
||||
$method = 'filter' . ucfirst(strtr($type, '-', '_'));
|
||||
|
||||
// If this is a YAML field validate/filter as such
|
||||
if ($type !== 'yaml' && isset($field['yaml']) && $field['yaml'] === true) {
|
||||
$method = 'filterYaml';
|
||||
}
|
||||
|
||||
if (!method_exists(__CLASS__, $method)) {
|
||||
$method = 'filterText';
|
||||
}
|
||||
|
@ -126,10 +127,12 @@ class Validation
|
|||
*/
|
||||
public static function typeText($value, array $params, array $field)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
if (!is_string($value) && !is_numeric($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$value = (string)$value;
|
||||
|
||||
if (isset($params['min']) && strlen($value) < $params['min']) {
|
||||
return false;
|
||||
}
|
||||
|
@ -639,23 +642,14 @@ class Validation
|
|||
return (array) $value;
|
||||
}
|
||||
|
||||
public static function typeYaml($value, $params)
|
||||
{
|
||||
try {
|
||||
Yaml::parse($value);
|
||||
return true;
|
||||
} catch (ParseException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function filterYaml($value, $params)
|
||||
{
|
||||
try {
|
||||
return (array) Yaml::parse($value);
|
||||
} catch (ParseException $e) {
|
||||
return null;
|
||||
if (!is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return (array) Yaml::parse($value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Data
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Common;
|
||||
|
||||
use DebugBar\DataCollector\ConfigCollector;
|
||||
use DebugBar\DataCollector\MessagesCollector;
|
||||
use DebugBar\JavascriptRenderer;
|
||||
use DebugBar\StandardDebugBar;
|
||||
use Grav\Common\Config\Config;
|
||||
|
@ -31,13 +32,24 @@ class Debugger
|
|||
|
||||
protected $timers = [];
|
||||
|
||||
/** @var string[] $deprecations */
|
||||
protected $deprecations = [];
|
||||
|
||||
protected $errorHandler;
|
||||
|
||||
/**
|
||||
* Debugger constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Enable debugger until $this->init() gets called.
|
||||
$this->enabled = true;
|
||||
|
||||
$this->debugbar = new StandardDebugBar();
|
||||
$this->debugbar['time']->addMeasure('Loading', $this->debugbar['time']->getRequestStartTime(), microtime(true));
|
||||
|
||||
// Set deprecation collector.
|
||||
$this->setErrorHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,9 +63,19 @@ class Debugger
|
|||
$this->grav = Grav::instance();
|
||||
$this->config = $this->grav['config'];
|
||||
|
||||
// Enable/disable debugger based on configuration.
|
||||
$this->enabled = $this->config->get('system.debugger.enabled');
|
||||
|
||||
if ($this->enabled()) {
|
||||
|
||||
$plugins_config = (array)$this->config->get('plugins');
|
||||
|
||||
ksort($plugins_config);
|
||||
|
||||
|
||||
$this->debugbar->addCollector(new ConfigCollector((array)$this->config->get('system'), 'Config'));
|
||||
$this->debugbar->addCollector(new ConfigCollector((array)$this->config->get('plugins'), 'Plugins'));
|
||||
$this->debugbar->addCollector(new ConfigCollector($plugins_config, 'Plugins'));
|
||||
$this->addMessage('Grav v' . GRAV_VERSION);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -68,12 +90,8 @@ class Debugger
|
|||
*/
|
||||
public function enabled($state = null)
|
||||
{
|
||||
if (isset($state)) {
|
||||
if ($state !== null) {
|
||||
$this->enabled = $state;
|
||||
} else {
|
||||
if (!isset($this->enabled)) {
|
||||
$this->enabled = $this->config->get('system.debugger.enabled');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->enabled;
|
||||
|
@ -90,8 +108,7 @@ class Debugger
|
|||
|
||||
// Only add assets if Page is HTML
|
||||
$page = $this->grav['page'];
|
||||
if ($page->templateFormat() != 'html') {
|
||||
$this->enabled = false;
|
||||
if ($page->templateFormat() !== 'html') {
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -106,13 +123,13 @@ class Debugger
|
|||
|
||||
// Get the required CSS files
|
||||
list($css_files, $js_files) = $this->renderer->getAssets(null, JavascriptRenderer::RELATIVE_URL);
|
||||
foreach ($css_files as $css) {
|
||||
foreach ((array)$css_files as $css) {
|
||||
$assets->addCss($css);
|
||||
}
|
||||
|
||||
$assets->addCss('/system/assets/debugger.css');
|
||||
|
||||
foreach ($js_files as $js) {
|
||||
foreach ((array)$js_files as $js) {
|
||||
$assets->addJs($js);
|
||||
}
|
||||
}
|
||||
|
@ -120,9 +137,9 @@ class Debugger
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getCaller($ignore = 2)
|
||||
public function getCaller($limit = 2)
|
||||
{
|
||||
$trace = debug_backtrace(false, $ignore);
|
||||
$trace = debug_backtrace(false, $limit);
|
||||
|
||||
return array_pop($trace);
|
||||
}
|
||||
|
@ -163,6 +180,14 @@ class Debugger
|
|||
public function render()
|
||||
{
|
||||
if ($this->enabled()) {
|
||||
// Only add assets if Page is HTML
|
||||
$page = $this->grav['page'];
|
||||
if (!$this->renderer || $page->templateFormat() !== 'html') {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->addDeprecations();
|
||||
|
||||
echo $this->renderer->render();
|
||||
}
|
||||
|
||||
|
@ -176,11 +201,31 @@ class Debugger
|
|||
*/
|
||||
public function sendDataInHeaders()
|
||||
{
|
||||
$this->debugbar->sendDataInHeaders();
|
||||
if ($this->enabled()) {
|
||||
$this->addDeprecations();
|
||||
$this->debugbar->sendDataInHeaders();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns collected debugger data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
if (!$this->enabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->addDeprecations();
|
||||
$this->timers = [];
|
||||
|
||||
return $this->debugbar->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a timer with an associated name and description
|
||||
*
|
||||
|
@ -191,7 +236,7 @@ class Debugger
|
|||
*/
|
||||
public function startTimer($name, $description = null)
|
||||
{
|
||||
if ($name[0] == '_' || $this->config->get('system.debugger.enabled')) {
|
||||
if ($name[0] === '_' || $this->enabled()) {
|
||||
$this->debugbar['time']->startMeasure($name, $description);
|
||||
$this->timers[] = $name;
|
||||
}
|
||||
|
@ -208,7 +253,7 @@ class Debugger
|
|||
*/
|
||||
public function stopTimer($name)
|
||||
{
|
||||
if (in_array($name, $this->timers) && ($name[0] == '_' || $this->config->get('system.debugger.enabled'))) {
|
||||
if (in_array($name, $this->timers, true) && ($name[0] === '_' || $this->enabled())) {
|
||||
$this->debugbar['time']->stopMeasure($name);
|
||||
}
|
||||
|
||||
|
@ -247,4 +292,152 @@ class Debugger
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setErrorHandler()
|
||||
{
|
||||
$this->errorHandler = set_error_handler(
|
||||
[$this, 'deprecatedErrorHandler']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $errno
|
||||
* @param string $errstr
|
||||
* @param string $errfile
|
||||
* @param int $errline
|
||||
* @return bool
|
||||
*/
|
||||
public function deprecatedErrorHandler($errno, $errstr, $errfile, $errline)
|
||||
{
|
||||
if ($errno !== E_USER_DEPRECATED) {
|
||||
if ($this->errorHandler) {
|
||||
return \call_user_func($this->errorHandler, $errno, $errstr, $errfile, $errline);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$this->enabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$backtrace = debug_backtrace(false);
|
||||
|
||||
// Skip current call.
|
||||
array_shift($backtrace);
|
||||
|
||||
// Skip vendor libraries and the method where error was triggered.
|
||||
while ($current = array_shift($backtrace)) {
|
||||
if (isset($current['file']) && strpos($current['file'], 'vendor') !== false) {
|
||||
continue;
|
||||
}
|
||||
if (isset($current['function']) && ($current['function'] === 'user_error' || $current['function'] === 'trigger_error')) {
|
||||
$current = array_shift($backtrace);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Add back last call.
|
||||
array_unshift($backtrace, $current);
|
||||
|
||||
// Filter arguments.
|
||||
foreach ($backtrace as &$current) {
|
||||
if (isset($current['args'])) {
|
||||
$args = [];
|
||||
foreach ($current['args'] as $arg) {
|
||||
if (\is_string($arg)) {
|
||||
$args[] = "'" . $arg . "'";
|
||||
} elseif (\is_bool($arg)) {
|
||||
$args[] = $arg ? 'true' : 'false';
|
||||
} elseif (\is_scalar($arg)) {
|
||||
$args[] = $arg;
|
||||
} elseif (\is_object($arg)) {
|
||||
$args[] = get_class($arg) . ' $object';
|
||||
} elseif (\is_array($arg)) {
|
||||
$args[] = '$array';
|
||||
} else {
|
||||
$args[] = '$object';
|
||||
}
|
||||
}
|
||||
$current['args'] = $args;
|
||||
}
|
||||
}
|
||||
unset($current);
|
||||
|
||||
$this->deprecations[] = [
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'trace' => $backtrace,
|
||||
];
|
||||
|
||||
// Do not pass forward.
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function addDeprecations()
|
||||
{
|
||||
if (!$this->deprecations) {
|
||||
return;
|
||||
}
|
||||
|
||||
$collector = new MessagesCollector('deprecated');
|
||||
$this->addCollector($collector);
|
||||
$collector->addMessage('Your site is using following deprecated features:');
|
||||
|
||||
/** @var array $deprecated */
|
||||
foreach ($this->deprecations as $deprecated) {
|
||||
list($message, $scope) = $this->getDepracatedMessage($deprecated);
|
||||
|
||||
$collector->addMessage($message, $scope);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getDepracatedMessage($deprecated)
|
||||
{
|
||||
$scope = 'unknown';
|
||||
if (stripos($deprecated['message'], 'grav') !== false) {
|
||||
$scope = 'grav';
|
||||
} elseif (!isset($deprecated['file'])) {
|
||||
$scope = 'unknown';
|
||||
} elseif (stripos($deprecated['file'], 'twig') !== false) {
|
||||
$scope = 'twig';
|
||||
} elseif (stripos($deprecated['file'], 'yaml') !== false) {
|
||||
$scope = 'yaml';
|
||||
} elseif (stripos($deprecated['file'], 'vendor') !== false) {
|
||||
$scope = 'vendor';
|
||||
}
|
||||
|
||||
$trace = [];
|
||||
foreach ($deprecated['trace'] as $current) {
|
||||
$class = isset($current['class']) ? $current['class'] : '';
|
||||
$type = isset($current['type']) ? $current['type'] : '';
|
||||
$function = $this->getFunction($current);
|
||||
if (isset($current['file'])) {
|
||||
$current['file'] = str_replace(GRAV_ROOT . '/', '', $current['file']);
|
||||
}
|
||||
|
||||
unset($current['class'], $current['type'], $current['function'], $current['args']);
|
||||
|
||||
$trace[] = ['call' => $class . $type . $function] + $current;
|
||||
}
|
||||
|
||||
return [
|
||||
[
|
||||
'message' => $deprecated['message'],
|
||||
'trace' => $trace
|
||||
],
|
||||
$scope
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFunction($trace)
|
||||
{
|
||||
if (!isset($trace['function'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $trace['function'] . '(' . implode(', ', $trace['args']) . ')';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Errors
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -18,6 +18,13 @@ class BareHandler extends Handler
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$inspector = $this->getInspector();
|
||||
$code = $inspector->getException()->getCode();
|
||||
if ( ($code >= 400) && ($code < 600) )
|
||||
{
|
||||
$this->getRun()->sendHttpCode($code);
|
||||
}
|
||||
|
||||
return Handler::QUIT;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Errors
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -74,5 +74,8 @@ class Errors
|
|||
}
|
||||
|
||||
$whoops->register();
|
||||
|
||||
// Re-register deprecation handler.
|
||||
$grav['debugger']->setErrorHandler();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Errors
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -35,6 +35,10 @@ class SimplePageHandler extends Handler
|
|||
$cssFile = $this->getResource("error.css");
|
||||
|
||||
$code = $inspector->getException()->getCode();
|
||||
if ( ($code >= 400) && ($code < 600) )
|
||||
{
|
||||
$this->getRun()->sendHttpCode($code);
|
||||
}
|
||||
$message = $inspector->getException()->getMessage();
|
||||
|
||||
if ($inspector->getException() instanceof \ErrorException) {
|
||||
|
@ -57,6 +61,7 @@ class SimplePageHandler extends Handler
|
|||
* @param $resource
|
||||
*
|
||||
* @return string
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected function getResource($resource)
|
||||
{
|
||||
|
@ -80,8 +85,7 @@ class SimplePageHandler extends Handler
|
|||
|
||||
// If we got this far, nothing was found.
|
||||
throw new \RuntimeException(
|
||||
"Could not find resource '$resource' in any resource paths."
|
||||
. "(searched: " . join(", ", $this->searchPaths). ")"
|
||||
"Could not find resource '{$resource}' in any resource paths (searched: " . implode(', ', $this->searchPaths). ')'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -89,7 +93,7 @@ class SimplePageHandler extends Handler
|
|||
{
|
||||
if (!is_dir($path)) {
|
||||
throw new \InvalidArgumentException(
|
||||
"'$path' is not a valid directory"
|
||||
"'{$path}' is not a valid directory"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Errors
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.File
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -20,9 +20,6 @@ trait CompiledFile
|
|||
*/
|
||||
public function content($var = null)
|
||||
{
|
||||
// Set some options
|
||||
$this->settings(['native' => true, 'compat' => true]);
|
||||
|
||||
try {
|
||||
// If nothing has been loaded, attempt to get pre-compiled version of the file first.
|
||||
if ($var === null && $this->raw === null && $this->content === null) {
|
||||
|
@ -42,9 +39,9 @@ trait CompiledFile
|
|||
// Load real file if cache isn't up to date (or is invalid).
|
||||
if (
|
||||
!isset($cache['@class'])
|
||||
|| $cache['@class'] != $class
|
||||
|| $cache['modified'] != $modified
|
||||
|| $cache['filename'] != $this->filename
|
||||
|| $cache['@class'] !== $class
|
||||
|| $cache['modified'] !== $modified
|
||||
|| $cache['filename'] !== $this->filename
|
||||
) {
|
||||
// Attempt to lock the file for writing.
|
||||
try {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.File
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.File
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.File
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.FileSystem
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -108,8 +108,7 @@ abstract class Folder
|
|||
$files[] = $file->getPathname() . '?'. $file->getMTime();
|
||||
}
|
||||
|
||||
$hash = md5(serialize($files));
|
||||
return $hash;
|
||||
return md5(serialize($files));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,7 +233,7 @@ abstract class Folder
|
|||
/** @var \RecursiveDirectoryIterator $file */
|
||||
foreach ($iterator as $file) {
|
||||
// Ignore hidden files.
|
||||
if ($file->getFilename()[0] == '.') {
|
||||
if ($file->getFilename()[0] === '.') {
|
||||
continue;
|
||||
}
|
||||
if (!$folders && $file->isDir()) {
|
||||
|
@ -339,7 +338,7 @@ abstract class Folder
|
|||
}
|
||||
|
||||
// Don't do anything if the source is the same as the new target
|
||||
if ($source == $target) {
|
||||
if ($source === $target) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -377,6 +376,7 @@ abstract class Folder
|
|||
* @param string $target
|
||||
* @param bool $include_target
|
||||
* @return bool
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function delete($target, $include_target = true)
|
||||
{
|
||||
|
@ -435,6 +435,7 @@ abstract class Folder
|
|||
* @param $dest
|
||||
*
|
||||
* @return bool
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function rcopy($src, $dest)
|
||||
{
|
||||
|
@ -447,7 +448,7 @@ abstract class Folder
|
|||
|
||||
// If the destination directory does not exist create it
|
||||
if (!is_dir($dest)) {
|
||||
Folder::mkdir($dest);
|
||||
static::mkdir($dest);
|
||||
}
|
||||
|
||||
// Open the source directory to read in files
|
||||
|
@ -455,10 +456,10 @@ abstract class Folder
|
|||
/** @var \DirectoryIterator $f */
|
||||
foreach ($i as $f) {
|
||||
if ($f->isFile()) {
|
||||
copy($f->getRealPath(), "$dest/" . $f->getFilename());
|
||||
copy($f->getRealPath(), "{$dest}/" . $f->getFilename());
|
||||
} else {
|
||||
if (!$f->isDot() && $f->isDir()) {
|
||||
static::rcopy($f->getRealPath(), "$dest/$f");
|
||||
static::rcopy($f->getRealPath(), "{$dest}/{$f}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -479,10 +480,10 @@ abstract class Folder
|
|||
}
|
||||
|
||||
// Go through all items in filesystem and recursively remove everything.
|
||||
$files = array_diff(scandir($folder), array('.', '..'));
|
||||
$files = array_diff(scandir($folder, SCANDIR_SORT_NONE), array('.', '..'));
|
||||
foreach ($files as $file) {
|
||||
$path = "{$folder}/{$file}";
|
||||
(is_dir($path)) ? self::doDelete($path) : @unlink($path);
|
||||
is_dir($path) ? self::doDelete($path) : @unlink($path);
|
||||
}
|
||||
|
||||
return $include_target ? @rmdir($folder) : true;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.FileSystem
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -37,7 +37,7 @@ class RecursiveFolderFilterIterator extends \RecursiveFilterIterator
|
|||
/** @var $current \SplFileInfo */
|
||||
$current = $this->current();
|
||||
|
||||
if ($current->isDir() && !in_array($current->getFilename(), $this::$folder_ignores)) {
|
||||
if ($current->isDir() && !in_array($current->getFilename(), $this::$folder_ignores, true)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -13,7 +13,7 @@ use Grav\Common\Filesystem\Folder;
|
|||
use Grav\Common\Inflector;
|
||||
use Grav\Common\Iterator;
|
||||
use Grav\Common\Utils;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use RocketTheme\Toolbox\File\YamlFile;
|
||||
|
||||
class GPM extends Iterator
|
||||
{
|
||||
|
@ -624,7 +624,10 @@ class GPM extends Iterator
|
|||
return false;
|
||||
}
|
||||
|
||||
$blueprint = (array)Yaml::parse(file_get_contents($blueprint_file));
|
||||
$file = YamlFile::instance($blueprint_file);
|
||||
$blueprint = (array)$file->content();
|
||||
$file->free();
|
||||
|
||||
return $blueprint;
|
||||
}
|
||||
|
||||
|
@ -719,8 +722,8 @@ class GPM extends Iterator
|
|||
foreach ($packages as $package_name => $package) {
|
||||
if (isset($package['dependencies'])) {
|
||||
foreach ($package['dependencies'] as $dependency) {
|
||||
if (is_array($dependency)) {
|
||||
$dependency = array_keys($dependency)[0];
|
||||
if (is_array($dependency) && isset($dependency['name'])) {
|
||||
$dependency = $dependency['name'];
|
||||
}
|
||||
|
||||
if ($dependency == $slug) {
|
||||
|
@ -835,6 +838,20 @@ class GPM extends Iterator
|
|||
continue;
|
||||
}
|
||||
|
||||
// Check PHP version
|
||||
if ($dependency_slug == 'php') {
|
||||
$current_php_version = phpversion();
|
||||
if (version_compare($this->calculateVersionNumberFromDependencyVersion($dependencyVersionWithOperator),
|
||||
$current_php_version) === 1
|
||||
) {
|
||||
//Needs a Grav update first
|
||||
throw new \Exception("<red>One of the packages require PHP " . $dependencies['php'] . ". Please update PHP to resolve this");
|
||||
} else {
|
||||
unset($dependencies[$dependency_slug]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//First, check for Grav dependency. If a dependency requires Grav > the current version, abort and tell.
|
||||
if ($dependency_slug == 'grav') {
|
||||
if (version_compare($this->calculateVersionNumberFromDependencyVersion($dependencyVersionWithOperator),
|
||||
|
@ -859,7 +876,9 @@ class GPM extends Iterator
|
|||
// get currently installed version
|
||||
$locator = Grav::instance()['locator'];
|
||||
$blueprints_path = $locator->findResource('plugins://' . $dependency_slug . DS . 'blueprints.yaml');
|
||||
$package_yaml = Yaml::parse(file_get_contents($blueprints_path));
|
||||
$file = YamlFile::instance($blueprints_path);
|
||||
$package_yaml = $file->content();
|
||||
$file->free();
|
||||
$currentlyInstalledVersion = $package_yaml['version'];
|
||||
|
||||
// if requirement is next significant release, check is compatible with currently installed version, might not be
|
||||
|
@ -1062,9 +1081,9 @@ class GPM extends Iterator
|
|||
} elseif ($version == '') {
|
||||
return null;
|
||||
} elseif ($this->versionFormatIsNextSignificantRelease($version)) {
|
||||
return substr($version, 1);
|
||||
return trim(substr($version, 1));
|
||||
} elseif ($this->versionFormatIsEqualOrHigher($version)) {
|
||||
return substr($version, 2);
|
||||
return trim(substr($version, 2));
|
||||
} else {
|
||||
return $version;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -43,6 +43,11 @@ class Installer
|
|||
*/
|
||||
protected static $error = 0;
|
||||
|
||||
/**
|
||||
* @var integer Zip Error Code
|
||||
*/
|
||||
protected static $error_zip = 0;
|
||||
|
||||
/**
|
||||
* @var string Post install message
|
||||
*/
|
||||
|
@ -190,10 +195,10 @@ class Installer
|
|||
}
|
||||
|
||||
self::$error = self::ZIP_EXTRACT_ERROR;
|
||||
self::$error_zip = $archive;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates and returns the package installer class
|
||||
*
|
||||
|
@ -291,17 +296,17 @@ class Installer
|
|||
{
|
||||
foreach (new \DirectoryIterator($source_path) as $file) {
|
||||
|
||||
if ($file->isLink() || $file->isDot() || in_array($file->getBasename(),$ignores)) {
|
||||
if ($file->isLink() || $file->isDot() || in_array($file->getFilename(), $ignores)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $install_path . DS . $file->getBasename();
|
||||
$path = $install_path . DS . $file->getFilename();
|
||||
|
||||
if ($file->isDir()) {
|
||||
Folder::delete($path);
|
||||
Folder::move($file->getPathname(), $path);
|
||||
|
||||
if ($file->getBasename() == 'bin') {
|
||||
if ($file->getFilename() === 'bin') {
|
||||
foreach (glob($path . DS . '*') as $bin_file) {
|
||||
@chmod($bin_file, 0755);
|
||||
}
|
||||
|
@ -460,7 +465,42 @@ class Installer
|
|||
break;
|
||||
|
||||
case self::ZIP_EXTRACT_ERROR:
|
||||
$msg = 'An error occurred while extracting the package';
|
||||
$msg = 'Unable to extract the package. ';
|
||||
if (self::$error_zip) {
|
||||
switch(self::$error_zip) {
|
||||
case \ZipArchive::ER_EXISTS:
|
||||
$msg .= "File already exists.";
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_INCONS:
|
||||
$msg .= "Zip archive inconsistent.";
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_MEMORY:
|
||||
$msg .= "Malloc failure.";
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_NOENT:
|
||||
$msg .= "No such file.";
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_NOZIP:
|
||||
$msg .= "Not a zip archive.";
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_OPEN:
|
||||
$msg .= "Can't open file.";
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_READ:
|
||||
$msg .= "Read error.";
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_SEEK:
|
||||
$msg .= "Seek error.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -114,7 +114,7 @@ class Licenses
|
|||
|
||||
{
|
||||
if (!isset(self::$file)) {
|
||||
$path = Grav::instance()['locator']->findResource('user://data') . '/licenses.yaml';;
|
||||
$path = Grav::instance()['locator']->findResource('user://data') . '/licenses.yaml';
|
||||
if (!file_exists($path)) {
|
||||
touch($path);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -18,10 +18,12 @@ class GravCore extends AbstractPackageCollection
|
|||
|
||||
private $version;
|
||||
private $date;
|
||||
private $min_php;
|
||||
|
||||
/**
|
||||
* @param bool $refresh
|
||||
* @param null $callback
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($refresh = false, $callback = null)
|
||||
{
|
||||
|
@ -36,9 +38,10 @@ class GravCore extends AbstractPackageCollection
|
|||
$this->data = json_decode($this->raw, true);
|
||||
$this->version = isset($this->data['version']) ? $this->data['version'] : '-';
|
||||
$this->date = isset($this->data['date']) ? $this->data['date'] : '-';
|
||||
$this->min_php = isset($this->data['min_php']) ? $this->data['min_php'] : null;
|
||||
|
||||
if (isset($this->data['assets'])) {
|
||||
foreach ($this->data['assets'] as $slug => $data) {
|
||||
foreach ((array)$this->data['assets'] as $slug => $data) {
|
||||
$this->items[$slug] = new Package($data);
|
||||
}
|
||||
}
|
||||
|
@ -68,10 +71,10 @@ class GravCore extends AbstractPackageCollection
|
|||
}
|
||||
|
||||
$diffLog = [];
|
||||
foreach ($this->data['changelog'] as $version => $changelog) {
|
||||
foreach ((array)$this->data['changelog'] as $version => $changelog) {
|
||||
preg_match("/[\w-\.]+/", $version, $cleanVersion);
|
||||
|
||||
if (!$cleanVersion || version_compare($diff, $cleanVersion[0], ">=")) {
|
||||
if (!$cleanVersion || version_compare($diff, $cleanVersion[0], '>=')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -91,6 +94,11 @@ class GravCore extends AbstractPackageCollection
|
|||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this version of Grav is eligible to be updated
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function isUpdatable()
|
||||
{
|
||||
return version_compare(GRAV_VERSION, $this->getVersion(), '<');
|
||||
|
@ -106,6 +114,25 @@ class GravCore extends AbstractPackageCollection
|
|||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum PHP version
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getMinPHPVersion()
|
||||
{
|
||||
// If non min set, assume current PHP version
|
||||
if (is_null($this->min_php)) {
|
||||
$this->min_php = phpversion();
|
||||
}
|
||||
return $this->min_php;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this installation symlinked?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSymlink()
|
||||
{
|
||||
return is_link(GRAV_ROOT . DS . 'index.php');
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.GPM
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -24,11 +24,14 @@ class Upgrader
|
|||
*/
|
||||
private $remote;
|
||||
|
||||
private $min_php;
|
||||
|
||||
/**
|
||||
* Creates a new GPM instance with Local and Remote packages available
|
||||
*
|
||||
* @param boolean $refresh Applies to Remote Packages only and forces a refetch of data
|
||||
* @param callable $callback Either a function or callback in array notation
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($refresh = false, $callback = null)
|
||||
{
|
||||
|
@ -88,17 +91,33 @@ class Upgrader
|
|||
}
|
||||
|
||||
/**
|
||||
* Make sure this meets minimum PHP requirements
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function meetsRequirements()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, GRAV_PHP_MIN, '<')) {
|
||||
$current_php_version = phpversion();
|
||||
if (version_compare($current_php_version, $this->minPHPVersion(), '<')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimum PHP version from remote
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function minPHPVersion()
|
||||
{
|
||||
if (is_null($this->min_php)) {
|
||||
$this->min_php = $this->remote->getMinPHPVersion();
|
||||
}
|
||||
return $this->min_php;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the currently installed Grav is upgradable to a newer version
|
||||
*
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Common;
|
||||
|
||||
use Grav\Common\Config\Config;
|
||||
use Grav\Common\Language\Language;
|
||||
use Grav\Common\Page\Medium\ImageMedium;
|
||||
use Grav\Common\Page\Medium\Medium;
|
||||
use Grav\Common\Page\Page;
|
||||
use RocketTheme\Toolbox\DI\Container;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\Event\EventDispatcher;
|
||||
|
||||
class Grav extends Container
|
||||
{
|
||||
|
@ -38,8 +38,7 @@ class Grav extends Container
|
|||
'uri' => 'Grav\Common\Uri',
|
||||
'events' => 'RocketTheme\Toolbox\Event\EventDispatcher',
|
||||
'cache' => 'Grav\Common\Cache',
|
||||
'session' => 'Grav\Common\Session',
|
||||
'Grav\Common\Service\MessagesServiceProvider',
|
||||
'Grav\Common\Service\SessionServiceProvider',
|
||||
'plugins' => 'Grav\Common\Plugins',
|
||||
'themes' => 'Grav\Common\Themes',
|
||||
'twig' => 'Grav\Common\Twig\Twig',
|
||||
|
@ -205,11 +204,8 @@ class Grav extends Container
|
|||
*/
|
||||
public function redirectLangSafe($route, $code = null)
|
||||
{
|
||||
/** @var Language $language */
|
||||
$language = $this['language'];
|
||||
|
||||
if (!$this['uri']->isExternal($route) && $language->enabled() && $language->isIncludeDefaultLanguage()) {
|
||||
$this->redirect($language->getLanguage() . $route, $code);
|
||||
if (!$this['uri']->isExternal($route)) {
|
||||
$this->redirect($this['pages']->route($route), $code);
|
||||
} else {
|
||||
$this->redirect($route, $code);
|
||||
}
|
||||
|
@ -256,11 +252,6 @@ class Grav extends Container
|
|||
header('ETag: "' . md5($page->raw() . $page->modified()).'"');
|
||||
}
|
||||
|
||||
// Set debugger data in headers
|
||||
if (!($format === null || $format == 'html')) {
|
||||
$this['debugger']->enabled(false);
|
||||
}
|
||||
|
||||
// Set HTTP response code
|
||||
if (isset($this['page']->header()->http_response_code)) {
|
||||
http_response_code($this['page']->header()->http_response_code);
|
||||
|
@ -440,7 +431,7 @@ class Grav extends Container
|
|||
*/
|
||||
public function fallbackUrl($path)
|
||||
{
|
||||
$this->fireEvent('onPageFallBackUrl');
|
||||
$this->fireEvent('onPageFallBackUrl');
|
||||
|
||||
/** @var Uri $uri */
|
||||
$uri = $this['uri'];
|
||||
|
@ -448,15 +439,16 @@ class Grav extends Container
|
|||
/** @var Config $config */
|
||||
$config = $this['config'];
|
||||
|
||||
$uri_extension = $uri->extension();
|
||||
$uri_extension = strtolower($uri->extension());
|
||||
$fallback_types = $config->get('system.media.allowed_fallback_types', null);
|
||||
$supported_types = $config->get('media.types');
|
||||
|
||||
// Check whitelist first, then ensure extension is a valid media type
|
||||
if (!empty($fallback_types) && !in_array($uri_extension, $fallback_types)) {
|
||||
return;
|
||||
} elseif (!array_key_exists($uri_extension, $supported_types)) {
|
||||
return;
|
||||
if (!empty($fallback_types) && !\in_array($uri_extension, $fallback_types, true)) {
|
||||
return false;
|
||||
}
|
||||
if (!array_key_exists($uri_extension, $supported_types)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$path_parts = pathinfo($path);
|
||||
|
|
|
@ -2,12 +2,15 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Common;
|
||||
|
||||
/**
|
||||
* @deprecated 1.4 Use Grav::instance() instead
|
||||
*/
|
||||
trait GravTrait
|
||||
{
|
||||
protected static $grav;
|
||||
|
@ -21,7 +24,8 @@ trait GravTrait
|
|||
self::$grav = Grav::instance();
|
||||
}
|
||||
|
||||
user_error(__TRAIT__ . ' is deprecated since Grav 1.4, use Grav::instance() instead', E_USER_DEPRECATED);
|
||||
|
||||
return self::$grav;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Helpers
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -32,7 +32,7 @@ class Base32 {
|
|||
*/
|
||||
public static function encode( $bytes ) {
|
||||
$i = 0; $index = 0; $digit = 0;
|
||||
$base32 = "";
|
||||
$base32 = '';
|
||||
$bytes_len = strlen($bytes);
|
||||
while( $i < $bytes_len ) {
|
||||
$currByte = ord($bytes{$i});
|
||||
|
@ -51,7 +51,7 @@ class Base32 {
|
|||
} else {
|
||||
$digit = ($currByte >> (8 - ($index + 5))) & 0x1F;
|
||||
$index = ($index + 5) % 8;
|
||||
if( $index == 0 ) $i++;
|
||||
if( $index === 0 ) $i++;
|
||||
}
|
||||
$base32 .= self::$base32Chars{$digit};
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class Base32 {
|
|||
$bytes[$offset] |= $digit << (8 - $index);
|
||||
}
|
||||
}
|
||||
$bites = "";
|
||||
$bites = '';
|
||||
foreach( $bytes as $byte ) $bites .= chr($byte);
|
||||
return $bites;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Helpers
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -56,7 +56,7 @@ class Excerpts
|
|||
public static function getExcerptFromHtml($html, $tag)
|
||||
{
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHtml($html);
|
||||
$doc->loadHTML($html);
|
||||
$images = $doc->getElementsByTagName($tag);
|
||||
$excerpt = null;
|
||||
|
||||
|
@ -117,7 +117,7 @@ class Excerpts
|
|||
*/
|
||||
public static function processLinkExcerpt($excerpt, Page $page, $type = 'link')
|
||||
{
|
||||
$url = htmlspecialchars_decode(urldecode($excerpt['element']['attributes']['href']));
|
||||
$url = htmlspecialchars_decode(rawurldecode($excerpt['element']['attributes']['href']));
|
||||
|
||||
$url_parts = static::parseUrl($url);
|
||||
|
||||
|
@ -142,9 +142,9 @@ class Excerpts
|
|||
foreach ($actions as $attrib => $value) {
|
||||
$key = $attrib;
|
||||
|
||||
if (in_array($attrib, $valid_attributes)) {
|
||||
if (in_array($attrib, $valid_attributes, true)) {
|
||||
// support both class and classes.
|
||||
if ($attrib == 'classes') {
|
||||
if ($attrib === 'classes') {
|
||||
$attrib = 'class';
|
||||
}
|
||||
$excerpt['element']['attributes'][$attrib] = str_replace(',', ' ', $value);
|
||||
|
@ -172,10 +172,9 @@ class Excerpts
|
|||
if ($type !== 'image' && !empty($url_parts['stream']) && !empty($url_parts['path'])) {
|
||||
$url_parts['path'] = Grav::instance()['base_url_relative'] . '/' . static::resolveStream("{$url_parts['scheme']}://{$url_parts['path']}");
|
||||
unset($url_parts['stream'], $url_parts['scheme']);
|
||||
|
||||
$excerpt['element']['attributes']['href'] = Uri::buildUrl($url_parts);
|
||||
}
|
||||
|
||||
$excerpt['element']['attributes']['href'] = Uri::buildUrl($url_parts);
|
||||
return $excerpt;
|
||||
}
|
||||
|
||||
|
@ -211,8 +210,8 @@ class Excerpts
|
|||
} else {
|
||||
// File is also local if scheme is http(s) and host matches.
|
||||
$local_file = isset($url_parts['path'])
|
||||
&& (empty($url_parts['scheme']) || in_array($url_parts['scheme'], ['http', 'https']))
|
||||
&& (empty($url_parts['host']) || $url_parts['host'] == Grav::instance()['uri']->host());
|
||||
&& (empty($url_parts['scheme']) || in_array($url_parts['scheme'], ['http', 'https'], true))
|
||||
&& (empty($url_parts['host']) || $url_parts['host'] === Grav::instance()['uri']->host());
|
||||
|
||||
if ($local_file) {
|
||||
$filename = basename($url_parts['path']);
|
||||
|
@ -246,13 +245,14 @@ class Excerpts
|
|||
|
||||
// Process operations
|
||||
$medium = static::processMediaActions($medium, $url_parts);
|
||||
$element_excerpt = $excerpt['element']['attributes'];
|
||||
|
||||
$alt = isset($excerpt['element']['attributes']['alt']) ? $excerpt['element']['attributes']['alt'] : '';
|
||||
$title = isset($excerpt['element']['attributes']['title']) ? $excerpt['element']['attributes']['title'] : '';
|
||||
$class = isset($excerpt['element']['attributes']['class']) ? $excerpt['element']['attributes']['class'] : '';
|
||||
$id = isset($excerpt['element']['attributes']['id']) ? $excerpt['element']['attributes']['id'] : '';
|
||||
$alt = isset($element_excerpt['alt']) ? $element_excerpt['alt'] : '';
|
||||
$title = isset($element_excerpt['title']) ? $element_excerpt['title'] : '';
|
||||
$class = isset($element_excerpt['class']) ? $element_excerpt['class'] : '';
|
||||
$id = isset($element_excerpt['id']) ? $element_excerpt['id'] : '';
|
||||
|
||||
$excerpt['element'] = $medium->parseDownElement($title, $alt, $class, $id, true);
|
||||
$excerpt['element'] = $medium->parsedownElement($title, $alt, $class, $id, true);
|
||||
|
||||
} else {
|
||||
// Not a current page media file, see if it needs converting to relative.
|
||||
|
@ -293,6 +293,15 @@ class Excerpts
|
|||
if (Grav::instance()['config']->get('system.images.auto_fix_orientation')) {
|
||||
$actions[] = ['method' => 'fixOrientation', 'params' => ''];
|
||||
}
|
||||
$defaults = Grav::instance()['config']->get('system.images.defaults');
|
||||
if (is_array($defaults) && count($defaults)) {
|
||||
foreach ($defaults as $method => $params) {
|
||||
$actions[] = [
|
||||
'method' => $method,
|
||||
'params' => $params,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// loop through actions for the image and call them
|
||||
foreach ($actions as $action) {
|
||||
|
|
|
@ -2,25 +2,30 @@
|
|||
/**
|
||||
* @package Grav.Common.Helpers
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Common\Helpers;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use SebastianBergmann\GlobalState\RuntimeException;
|
||||
|
||||
class Exif
|
||||
{
|
||||
public $reader;
|
||||
|
||||
/**
|
||||
* Exif constructor.
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (Grav::instance()['config']->get('system.media.auto_metadata_exif')) {
|
||||
if (function_exists('exif_read_data') && class_exists('\PHPExif\Reader\Reader')) {
|
||||
$this->reader = \PHPExif\Reader\Reader::factory(\PHPExif\Reader\Reader::TYPE_NATIVE);
|
||||
} else {
|
||||
throw new \Exception('Please enable the Exif extension for PHP or disable Exif support in Grav system configuration');
|
||||
throw new \RuntimeException('Please enable the Exif extension for PHP or disable Exif support in Grav system configuration');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Helpers
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -34,7 +34,7 @@ class Truncator {
|
|||
* @param string $ellipsis String to use as ellipsis (if any).
|
||||
* @return string Safe truncated HTML.
|
||||
*/
|
||||
public static function truncateWords($html, $limit = 0, $ellipsis = "")
|
||||
public static function truncateWords($html, $limit = 0, $ellipsis = '')
|
||||
{
|
||||
if ($limit <= 0) {
|
||||
return $html;
|
||||
|
@ -47,6 +47,7 @@ class Truncator {
|
|||
|
||||
// Iterate over words.
|
||||
$words = new DOMWordsIterator($body);
|
||||
$truncated = false;
|
||||
foreach ($words as $word) {
|
||||
|
||||
// If we have exceeded the limit, we delete the remainder of the content.
|
||||
|
@ -70,12 +71,19 @@ class Truncator {
|
|||
self::insertEllipsis($curNode, $ellipsis);
|
||||
}
|
||||
|
||||
$truncated = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return self::innerHTML($body);
|
||||
// Return original HTML if not truncated.
|
||||
if ($truncated) {
|
||||
return self::innerHTML($body);
|
||||
} else {
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,28 +102,36 @@ class Truncator {
|
|||
$dom = self::htmlToDomDocument($html);
|
||||
|
||||
// Grab the body of our DOM.
|
||||
$body = $dom->getElementsByTagName("body")->item(0);
|
||||
$body = $dom->getElementsByTagName('body')->item(0);
|
||||
|
||||
// Iterate over letters.
|
||||
$letters = new DOMLettersIterator($body);
|
||||
$truncated = false;
|
||||
foreach ($letters as $letter) {
|
||||
|
||||
// If we have exceeded the limit, we want to delete the remainder of this document.
|
||||
if ($letters->key() >= $limit) {
|
||||
|
||||
$currentText = $letters->currentTextPosition();
|
||||
$currentText[0]->nodeValue = substr($currentText[0]->nodeValue, 0, $currentText[1] + 1);
|
||||
$currentText[0]->nodeValue = mb_substr($currentText[0]->nodeValue, 0, $currentText[1] + 1);
|
||||
self::removeProceedingNodes($currentText[0], $body);
|
||||
|
||||
if (!empty($ellipsis)) {
|
||||
self::insertEllipsis($currentText[0], $ellipsis);
|
||||
}
|
||||
|
||||
$truncated = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return self::innerHTML($body);
|
||||
// Return original HTML if not truncated.
|
||||
if ($truncated) {
|
||||
return self::innerHTML($body);
|
||||
} else {
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,7 +197,7 @@ class Truncator {
|
|||
{
|
||||
$avoid = array('a', 'strong', 'em', 'h1', 'h2', 'h3', 'h4', 'h5'); //html tags to avoid appending the ellipsis to
|
||||
|
||||
if (in_array($domNode->parentNode->nodeName, $avoid) && $domNode->parentNode->parentNode !== null) {
|
||||
if ($domNode->parentNode->parentNode !== null && in_array($domNode->parentNode->nodeName, $avoid, true)) {
|
||||
// Append as text node to parent instead
|
||||
$textNode = new DOMText($ellipsis);
|
||||
|
||||
|
@ -204,7 +220,7 @@ class Truncator {
|
|||
* @return string
|
||||
*/
|
||||
private static function innerHTML($element) {
|
||||
$innerHTML = "";
|
||||
$innerHTML = '';
|
||||
$children = $element->childNodes;
|
||||
foreach ($children as $child)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -190,10 +190,11 @@ class Inflector
|
|||
public function hyphenize($word)
|
||||
{
|
||||
$regex1 = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\1-\2', $word);
|
||||
$regex2 = preg_replace('/([a-zd])([A-Z])/', '\1-\2', $regex1);
|
||||
$regex3 = preg_replace('/[^A-Z^a-z^0-9]+/', '-', $regex2);
|
||||
$regex2 = preg_replace('/([a-z])([A-Z])/', '\1-\2', $regex1);
|
||||
$regex3 = preg_replace('/([0-9])([A-Z])/', '\1-\2', $regex2);
|
||||
$regex4 = preg_replace('/[^A-Z^a-z^0-9]+/', '-', $regex3);
|
||||
|
||||
return strtolower($regex3);
|
||||
return strtolower($regex4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Language
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -174,23 +174,23 @@ class Language
|
|||
|
||||
// if languages set
|
||||
if ($this->enabled()) {
|
||||
// try setting from prefix of URL (/en/blah/blah)
|
||||
// Try setting language from prefix of URL (/en/blah/blah).
|
||||
if (preg_match($regex, $uri, $matches)) {
|
||||
$this->lang_in_url = true;
|
||||
$this->active = $matches[2];
|
||||
$uri = preg_replace("/\\" . $matches[1] . "/", '', $uri, 1);
|
||||
$uri = preg_replace("/\\" . $matches[1] . '/', '', $uri, 1);
|
||||
|
||||
// store in session if different
|
||||
if ($this->config->get('system.session.enabled', false)
|
||||
// Store in session if language is different.
|
||||
if (isset($this->grav['session']) && $this->grav['session']->isStarted()
|
||||
&& $this->config->get('system.languages.session_store_active', true)
|
||||
&& $this->grav['session']->active_language != $this->active
|
||||
) {
|
||||
$this->grav['session']->active_language = $this->active;
|
||||
}
|
||||
} else {
|
||||
// try getting from session, else no active
|
||||
if ($this->config->get('system.session.enabled', false) &&
|
||||
$this->config->get('system.languages.session_store_active', true)) {
|
||||
// Try getting language from the session, else no active.
|
||||
if (isset($this->grav['session']) && $this->grav['session']->isStarted()
|
||||
&& $this->config->get('system.languages.session_store_active', true)) {
|
||||
$this->active = $this->grav['session']->active_language ?: null;
|
||||
}
|
||||
// if still null, try from http_accept_language header
|
||||
|
@ -203,8 +203,8 @@ class Language
|
|||
}
|
||||
}
|
||||
|
||||
// repeat if not found, try base language only - fixes Safari sending the language code always
|
||||
// with a locale (e.g. it-it or fr-fr)
|
||||
// Repeat if not found, try base language only - fixes Safari sending the language code always
|
||||
// with a locale (e.g. it-it or fr-fr).
|
||||
foreach ($preferred as $lang) {
|
||||
$lang = substr($lang, 0, 2);
|
||||
if ($this->validate($lang)) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Language
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -22,6 +22,7 @@ class LanguageCodes
|
|||
'bn-BD' => [ 'name' => 'Bengali (Bangladesh)', 'nativeName' => 'বাংলা (বাংলাদেশ)' ],
|
||||
'bn-IN' => [ 'name' => 'Bengali (India)', 'nativeName' => 'বাংলা (ভারত)' ],
|
||||
'br' => [ 'name' => 'Breton', 'nativeName' => 'Brezhoneg' ],
|
||||
'bs' => [ 'name' => 'Bosnian', 'nativeName' => 'Bosanski' ],
|
||||
'ca' => [ 'name' => 'Catalan', 'nativeName' => 'Català' ],
|
||||
'ca-valencia'=> [ 'name' => 'Catalan (Valencian)', 'nativeName' => 'Català (valencià)' ], // not iso-639-1. a=l10n-drivers
|
||||
'cs' => [ 'name' => 'Czech', 'nativeName' => 'Čeština' ],
|
||||
|
@ -157,14 +158,13 @@ class LanguageCodes
|
|||
{
|
||||
if (isset(static::$codes[$code])) {
|
||||
return static::get($code, 'nativeName');
|
||||
} else {
|
||||
if (preg_match('/[a-zA-Z]{2}-[a-zA-Z]{2}/', $code)) {
|
||||
return static::get(substr($code, 0, 2), 'nativeName') . ' (' . substr($code, -2) . ')';
|
||||
} else {
|
||||
return $code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preg_match('/[a-zA-Z]{2}-[a-zA-Z]{2}/', $code)) {
|
||||
return static::get(substr($code, 0, 2), 'nativeName') . ' (' . substr($code, -2) . ')';
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public static function getOrientation($code)
|
||||
|
@ -179,7 +179,7 @@ class LanguageCodes
|
|||
|
||||
public static function isRtl($code)
|
||||
{
|
||||
if (static::getOrientation($code) == 'rtl') {
|
||||
if (static::getOrientation($code) === 'rtl') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -192,7 +192,6 @@ class LanguageCodes
|
|||
if (isset(static::$codes[$key])) {
|
||||
$results[$key] = static::$codes[$key];
|
||||
}
|
||||
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
@ -201,8 +200,8 @@ class LanguageCodes
|
|||
{
|
||||
if (isset(static::$codes[$code][$type])) {
|
||||
return static::$codes[$code][$type];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Markdown
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Markdown
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -17,10 +17,12 @@ class ParsedownExtra extends \ParsedownExtra
|
|||
*
|
||||
* @param $page
|
||||
* @param $defaults
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($page, $defaults)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->init($page, $defaults);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Markdown
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -35,7 +35,7 @@ trait ParsedownGravTrait
|
|||
$grav = Grav::instance();
|
||||
|
||||
$this->page = $page;
|
||||
$this->BlockTypes['{'] [] = "TwigTag";
|
||||
$this->BlockTypes['{'] [] = 'TwigTag';
|
||||
$this->special_chars = ['>' => 'gt', '<' => 'lt', '"' => 'quot'];
|
||||
|
||||
if ($defaults === null) {
|
||||
|
@ -56,6 +56,9 @@ trait ParsedownGravTrait
|
|||
*
|
||||
* @param $type
|
||||
* @param $tag
|
||||
* @param bool $continuable
|
||||
* @param bool $completable
|
||||
* @param $index
|
||||
*/
|
||||
public function addBlockType($type, $tag, $continuable = false, $completable = false, $index = null)
|
||||
{
|
||||
|
@ -67,7 +70,7 @@ trait ParsedownGravTrait
|
|||
$block = &$this->BlockTypes[$type];
|
||||
}
|
||||
|
||||
if (!isset($index)) {
|
||||
if (null === $index) {
|
||||
$block[] = $tag;
|
||||
} else {
|
||||
array_splice($block, $index, 0, [$tag]);
|
||||
|
@ -86,10 +89,11 @@ trait ParsedownGravTrait
|
|||
*
|
||||
* @param $type
|
||||
* @param $tag
|
||||
* @param $index
|
||||
*/
|
||||
public function addInlineType($type, $tag, $index = null)
|
||||
{
|
||||
if (!isset($index) || !isset($this->InlineTypes[$type])) {
|
||||
if (null === $index || !isset($this->InlineTypes[$type])) {
|
||||
$this->InlineTypes[$type] [] = $tag;
|
||||
} else {
|
||||
array_splice($this->InlineTypes[$type], $index, 0, [$tag]);
|
||||
|
@ -109,7 +113,7 @@ trait ParsedownGravTrait
|
|||
*/
|
||||
protected function isBlockContinuable($Type)
|
||||
{
|
||||
$continuable = in_array($Type, $this->continuable_blocks) || method_exists($this, 'block' . $Type . 'Continue');
|
||||
$continuable = \in_array($Type, $this->continuable_blocks) || method_exists($this, 'block' . $Type . 'Continue');
|
||||
|
||||
return $continuable;
|
||||
}
|
||||
|
@ -123,7 +127,7 @@ trait ParsedownGravTrait
|
|||
*/
|
||||
protected function isBlockCompletable($Type)
|
||||
{
|
||||
$completable = in_array($Type, $this->completable_blocks) || method_exists($this, 'block' . $Type . 'Complete');
|
||||
$completable = \in_array($Type, $this->completable_blocks) || method_exists($this, 'block' . $Type . 'Complete');
|
||||
|
||||
return $completable;
|
||||
}
|
||||
|
@ -157,32 +161,31 @@ trait ParsedownGravTrait
|
|||
|
||||
/**
|
||||
* Ensure Twig tags are treated as block level items with no <p></p> tags
|
||||
*
|
||||
* @param array $line
|
||||
* @return array|null
|
||||
*/
|
||||
protected function blockTwigTag($Line)
|
||||
protected function blockTwigTag($line)
|
||||
{
|
||||
if (preg_match('/(?:{{|{%|{#)(.*)(?:}}|%}|#})/', $Line['body'], $matches)) {
|
||||
$Block = [
|
||||
'markup' => $Line['body'],
|
||||
];
|
||||
|
||||
return $Block;
|
||||
if (preg_match('/(?:{{|{%|{#)(.*)(?:}}|%}|#})/', $line['body'], $matches)) {
|
||||
return ['markup' => $line['body']];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function inlineSpecialCharacter($Excerpt)
|
||||
protected function inlineSpecialCharacter($excerpt)
|
||||
{
|
||||
if ($Excerpt['text'][0] === '&' && !preg_match('/^&#?\w+;/', $Excerpt['text'])) {
|
||||
if ($excerpt['text'][0] === '&' && !preg_match('/^&#?\w+;/', $excerpt['text'])) {
|
||||
return [
|
||||
'markup' => '&',
|
||||
'extent' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->special_chars[$Excerpt['text'][0]])) {
|
||||
if (isset($this->special_chars[$excerpt['text'][0]])) {
|
||||
return [
|
||||
'markup' => '&' . $this->special_chars[$Excerpt['text'][0]] . ';',
|
||||
'markup' => '&' . $this->special_chars[$excerpt['text'][0]] . ';',
|
||||
'extent' => 1,
|
||||
];
|
||||
}
|
||||
|
@ -199,11 +202,11 @@ trait ParsedownGravTrait
|
|||
$excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1;
|
||||
|
||||
return $excerpt;
|
||||
} else {
|
||||
$excerpt['type'] = 'image';
|
||||
$excerpt = parent::inlineImage($excerpt);
|
||||
}
|
||||
|
||||
$excerpt['type'] = 'image';
|
||||
$excerpt = parent::inlineImage($excerpt);
|
||||
|
||||
// if this is an image process it
|
||||
if (isset($excerpt['element']['attributes']['src'])) {
|
||||
$excerpt = Excerpts::processImageExcerpt($excerpt, $this->page);
|
||||
|
@ -228,10 +231,10 @@ trait ParsedownGravTrait
|
|||
$excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1;
|
||||
|
||||
return $excerpt;
|
||||
} else {
|
||||
$excerpt = parent::inlineLink($excerpt);
|
||||
}
|
||||
|
||||
$excerpt = parent::inlineLink($excerpt);
|
||||
|
||||
// if this is a link
|
||||
if (isset($excerpt['element']['attributes']['href'])) {
|
||||
$excerpt = Excerpts::processLinkExcerpt($excerpt, $this->page, $type);
|
||||
|
@ -243,10 +246,10 @@ trait ParsedownGravTrait
|
|||
// For extending this class via plugins
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (isset($this->$method) === true) {
|
||||
$func = $this->$method;
|
||||
if (isset($this->{$method}) === true) {
|
||||
$func = $this->{$method};
|
||||
|
||||
return call_user_func_array($func, $args);
|
||||
return \call_user_func_array($func, $args);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Grav\Common\Media\Interfaces;
|
||||
|
||||
/**
|
||||
* Class implements media collection interface.
|
||||
*/
|
||||
interface MediaCollectionInterface
|
||||
{
|
||||
}
|
29
system/src/Grav/Common/Media/Interfaces/MediaInterface.php
Normal file
29
system/src/Grav/Common/Media/Interfaces/MediaInterface.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
namespace Grav\Common\Media\Interfaces;
|
||||
|
||||
/**
|
||||
* Class implements media interface.
|
||||
*/
|
||||
interface MediaInterface
|
||||
{
|
||||
/**
|
||||
* Gets the associated media collection.
|
||||
*
|
||||
* @return MediaCollectionInterface Collection of associated media.
|
||||
*/
|
||||
public function getMedia();
|
||||
|
||||
/**
|
||||
* Get filesystem path to the associated media.
|
||||
*
|
||||
* @return string|null Media path or null if the object doesn't have media folder.
|
||||
*/
|
||||
public function getMediaFolder();
|
||||
|
||||
/**
|
||||
* Get display order for the associated media.
|
||||
*
|
||||
* @return array Empty array means default ordering.
|
||||
*/
|
||||
public function getMediaOrder();
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Grav\Common\Media\Interfaces;
|
||||
|
||||
/**
|
||||
* Class implements media object interface.
|
||||
*/
|
||||
interface MediaObjectInterface
|
||||
{
|
||||
}
|
112
system/src/Grav/Common/Media/Traits/MediaTrait.php
Normal file
112
system/src/Grav/Common/Media/Traits/MediaTrait.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
namespace Grav\Common\Media\Traits;
|
||||
|
||||
use Grav\Common\Cache;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Media\Interfaces\MediaCollectionInterface;
|
||||
use Grav\Common\Page\Media;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
|
||||
trait MediaTrait
|
||||
{
|
||||
protected $media;
|
||||
|
||||
/**
|
||||
* Get filesystem path to the associated media.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
abstract public function getMediaFolder();
|
||||
|
||||
/**
|
||||
* Get display order for the associated media.
|
||||
*
|
||||
* @return array Empty array means default ordering.
|
||||
*/
|
||||
abstract public function getMediaOrder();
|
||||
|
||||
/**
|
||||
* Get URI ot the associated media. Method will return null if path isn't URI.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getMediaUri()
|
||||
{
|
||||
$folder = $this->getMediaFolder();
|
||||
|
||||
if (strpos($folder, '://')) {
|
||||
return $folder;
|
||||
}
|
||||
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = Grav::instance()['locator'];
|
||||
$user = $locator->findResource('user://');
|
||||
if (strpos($folder, $user) === 0) {
|
||||
return 'user://' . substr($folder, strlen($user)+1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the associated media collection.
|
||||
*
|
||||
* @return MediaCollectionInterface Representation of associated media.
|
||||
*/
|
||||
public function getMedia()
|
||||
{
|
||||
$cache = $this->getMediaCache();
|
||||
|
||||
if ($this->media === null) {
|
||||
// Use cached media if possible.
|
||||
$cacheKey = md5('media' . $this->getCacheKey());
|
||||
if (!$media = $cache->fetch($cacheKey)) {
|
||||
$media = new Media($this->getMediaFolder(), $this->getMediaOrder());
|
||||
$cache->save($cacheKey, $media);
|
||||
}
|
||||
$this->media = $media;
|
||||
}
|
||||
|
||||
return $this->media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the associated media collection.
|
||||
*
|
||||
* @param MediaCollectionInterface $media Representation of associated media.
|
||||
* @return $this
|
||||
*/
|
||||
protected function setMedia(MediaCollectionInterface $media)
|
||||
{
|
||||
$cache = $this->getMediaCache();
|
||||
$cacheKey = md5('media' . $this->getCacheKey());
|
||||
$cache->save($cacheKey, $media);
|
||||
|
||||
$this->media = $media;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear media cache.
|
||||
*/
|
||||
protected function clearMediaCache()
|
||||
{
|
||||
$cache = $this->getMediaCache();
|
||||
$cacheKey = md5('media' . $this->getCacheKey());
|
||||
$cache->delete($cacheKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Cache
|
||||
*/
|
||||
protected function getMediaCache()
|
||||
{
|
||||
return Grav::instance()['cache'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getCacheKey();
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Page
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -610,4 +610,23 @@ class Collection extends Iterator
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extended version of this Collection with each page keyed by route
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function toExtendedArray()
|
||||
{
|
||||
$items = [];
|
||||
foreach ($this->items as $path => $slug) {
|
||||
$page = $this->pages->get($path);
|
||||
|
||||
if ($page !== null) {
|
||||
$items[$page->route()] = $page->toArray();
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Page
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
9
system/src/Grav/Common/Page/Interfaces/PageInterface.php
Normal file
9
system/src/Grav/Common/Page/Interfaces/PageInterface.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Grav\Common\Page\Interfaces;
|
||||
|
||||
/**
|
||||
* Class implements page interface.
|
||||
*/
|
||||
interface PageInterface
|
||||
{
|
||||
}
|
|
@ -2,18 +2,18 @@
|
|||
/**
|
||||
* @package Grav.Common.Page
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -24,11 +24,13 @@ class Media extends AbstractMedia
|
|||
protected $standard_exif = ['FileSize', 'MimeType', 'height', 'width'];
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param string $path
|
||||
* @param array $media_order
|
||||
*/
|
||||
public function __construct($path)
|
||||
public function __construct($path, array $media_order = null)
|
||||
{
|
||||
$this->path = $path;
|
||||
$this->media_order = $media_order;
|
||||
|
||||
$this->__wakeup();
|
||||
$this->init();
|
||||
|
@ -86,7 +88,7 @@ class Media extends AbstractMedia
|
|||
/** @var \DirectoryIterator $info */
|
||||
foreach ($iterator as $path => $info) {
|
||||
// Ignore folders and Markdown files.
|
||||
if (!$info->isFile() || $info->getExtension() === 'md' || $info->getBasename()[0] === '.') {
|
||||
if (!$info->isFile() || $info->getExtension() === 'md' || $info->getFilename()[0] === '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Page
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -10,9 +10,11 @@ namespace Grav\Common\Page\Medium;
|
|||
|
||||
use Grav\Common\Getters;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Media\Interfaces\MediaCollectionInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaObjectInterface;
|
||||
use Grav\Common\Utils;
|
||||
|
||||
abstract class AbstractMedia extends Getters
|
||||
abstract class AbstractMedia extends Getters implements MediaCollectionInterface
|
||||
{
|
||||
protected $gettersVariable = 'instances';
|
||||
|
||||
|
@ -21,6 +23,7 @@ abstract class AbstractMedia extends Getters
|
|||
protected $videos = [];
|
||||
protected $audios = [];
|
||||
protected $files = [];
|
||||
protected $media_order;
|
||||
|
||||
/**
|
||||
* Get medium by filename.
|
||||
|
@ -44,10 +47,25 @@ abstract class AbstractMedia extends Getters
|
|||
return $this->offsetGet($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $offset
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
$object = parent::offsetGet($offset);
|
||||
|
||||
// It would be nice if previous image modification would not affect the later ones.
|
||||
//$object = $object ? clone($object) : null;
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all media.
|
||||
*
|
||||
* @return array|Medium[]
|
||||
* @return array|MediaObjectInterface[]
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
|
@ -59,7 +77,7 @@ abstract class AbstractMedia extends Getters
|
|||
/**
|
||||
* Get a list of all image media.
|
||||
*
|
||||
* @return array|Medium[]
|
||||
* @return array|MediaObjectInterface[]
|
||||
*/
|
||||
public function images()
|
||||
{
|
||||
|
@ -70,7 +88,7 @@ abstract class AbstractMedia extends Getters
|
|||
/**
|
||||
* Get a list of all video media.
|
||||
*
|
||||
* @return array|Medium[]
|
||||
* @return array|MediaObjectInterface[]
|
||||
*/
|
||||
public function videos()
|
||||
{
|
||||
|
@ -81,7 +99,7 @@ abstract class AbstractMedia extends Getters
|
|||
/**
|
||||
* Get a list of all audio media.
|
||||
*
|
||||
* @return array|Medium[]
|
||||
* @return array|MediaObjectInterface[]
|
||||
*/
|
||||
public function audios()
|
||||
{
|
||||
|
@ -92,7 +110,7 @@ abstract class AbstractMedia extends Getters
|
|||
/**
|
||||
* Get a list of all file media.
|
||||
*
|
||||
* @return array|Medium[]
|
||||
* @return array|MediaObjectInterface[]
|
||||
*/
|
||||
public function files()
|
||||
{
|
||||
|
@ -102,7 +120,7 @@ abstract class AbstractMedia extends Getters
|
|||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param Medium $file
|
||||
* @param MediaObjectInterface $file
|
||||
*/
|
||||
protected function add($name, $file)
|
||||
{
|
||||
|
@ -130,14 +148,20 @@ abstract class AbstractMedia extends Getters
|
|||
*/
|
||||
protected function orderMedia($media)
|
||||
{
|
||||
$page = Grav::instance()['pages']->get($this->path);
|
||||
if (null === $this->media_order) {
|
||||
$page = Grav::instance()['pages']->get($this->path);
|
||||
|
||||
if ($page && isset($page->header()->media_order)) {
|
||||
$media_order = array_map('trim', explode(',', $page->header()->media_order));
|
||||
$media = Utils::sortArrayByArray($media, $media_order);
|
||||
if ($page && isset($page->header()->media_order)) {
|
||||
$this->media_order = array_map('trim', explode(',', $page->header()->media_order));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->media_order) && is_array($this->media_order)) {
|
||||
$media = Utils::sortArrayByArray($media, $this->media_order);
|
||||
} else {
|
||||
ksort($media, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
}
|
||||
|
||||
return $media;
|
||||
}
|
||||
|
||||
|
@ -168,8 +192,8 @@ abstract class AbstractMedia extends Getters
|
|||
$type = 'base';
|
||||
|
||||
while (($part = array_shift($fileParts)) !== null) {
|
||||
if ($part != 'meta' && $part != 'thumb') {
|
||||
if (isset($extension)) {
|
||||
if ($part !== 'meta' && $part !== 'thumb') {
|
||||
if (null !== $extension) {
|
||||
$name .= '.' . $extension;
|
||||
}
|
||||
$extension = $part;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Page
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Page
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Page
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -11,10 +11,16 @@ namespace Grav\Common\Page\Medium;
|
|||
use Grav\Common\Grav;
|
||||
use Gregwar\Image\Exceptions\GenerationError;
|
||||
use Gregwar\Image\Image;
|
||||
use Gregwar\Image\Source;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
|
||||
class ImageFile extends Image
|
||||
{
|
||||
public function __destruct()
|
||||
{
|
||||
$this->getAdapter()->deinit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear previously applied operations
|
||||
*/
|
||||
|
@ -30,15 +36,15 @@ class ImageFile extends Image
|
|||
* @param int $quality the quality (for JPEG)
|
||||
* @param bool $actual
|
||||
*
|
||||
* @return mixed|string
|
||||
* @return string
|
||||
*/
|
||||
public function cacheFile($type = 'jpg', $quality = 80, $actual = false)
|
||||
{
|
||||
if ($type == 'guess') {
|
||||
if ($type === 'guess') {
|
||||
$type = $this->guessType();
|
||||
}
|
||||
|
||||
if (!count($this->operations) && $type == $this->guessType() && !$this->forceCache) {
|
||||
if (!$this->forceCache && !count($this->operations) && $type === $this->guessType()) {
|
||||
return $this->getFilename($this->getFilePath());
|
||||
}
|
||||
|
||||
|
@ -60,8 +66,7 @@ class ImageFile extends Image
|
|||
$cacheFile .= $this->prettyName;
|
||||
}
|
||||
|
||||
|
||||
$cacheFile .= '.'.$type;
|
||||
$cacheFile .= '.' . $type;
|
||||
|
||||
// If the files does not exists, save it
|
||||
$image = $this;
|
||||
|
@ -76,7 +81,7 @@ class ImageFile extends Image
|
|||
$generate = function ($target) use ($image, $type, $quality) {
|
||||
$result = $image->save($target, $type, $quality);
|
||||
|
||||
if ($result != $target) {
|
||||
if ($result !== $target) {
|
||||
throw new GenerationError($result);
|
||||
}
|
||||
|
||||
|
@ -87,15 +92,19 @@ class ImageFile extends Image
|
|||
try {
|
||||
$perms = Grav::instance()['config']->get('system.images.cache_perms', '0755');
|
||||
$perms = octdec($perms);
|
||||
$file = $this->cache->setDirectoryMode($perms)->getOrCreateFile($cacheFile, $conditions, $generate, $actual);
|
||||
$file = $this->getCacheSystem()->setDirectoryMode($perms)->getOrCreateFile($cacheFile, $conditions, $generate, $actual);
|
||||
} catch (GenerationError $e) {
|
||||
$file = $e->getNewFile();
|
||||
}
|
||||
|
||||
// Nulling the resource
|
||||
$this->getAdapter()->setSource(new Source\File($file));
|
||||
$this->getAdapter()->deinit();
|
||||
|
||||
if ($actual) {
|
||||
return $file;
|
||||
} else {
|
||||
return $this->getFilename($file);
|
||||
}
|
||||
|
||||
return $this->getFilename($file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @package Grav.Common.Page
|
||||
*
|
||||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
@ -11,6 +11,7 @@ namespace Grav\Common\Page\Medium;
|
|||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
|
||||
class ImageMedium extends Medium
|
||||
{
|
||||
|
@ -103,6 +104,18 @@ class ImageMedium extends Medium
|
|||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
unset($this->image);
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->image = $this->image ? clone $this->image : null;
|
||||
|
||||
parent::__clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta file for the medium.
|
||||
*
|
||||
|
@ -152,14 +165,20 @@ class ImageMedium extends Medium
|
|||
*/
|
||||
public function url($reset = true)
|
||||
{
|
||||
$image_path = Grav::instance()['locator']->findResource('cache://images', true);
|
||||
$image_dir = Grav::instance()['locator']->findResource('cache://images', false);
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = Grav::instance()['locator'];
|
||||
$image_path = $locator->findResource('cache://images', true);
|
||||
$image_dir = $locator->findResource('cache://images', false);
|
||||
$saved_image_path = $this->saveImage();
|
||||
|
||||
$output = preg_replace('|^' . preg_quote(GRAV_ROOT) . '|', '', $saved_image_path);
|
||||
$output = preg_replace('|^' . preg_quote(GRAV_ROOT, '|') . '|', '', $saved_image_path);
|
||||
|
||||
if ($locator->isStream($output)) {
|
||||
$output = $locator->findResource($output, false);
|
||||
}
|
||||
|
||||
if (Utils::startsWith($output, $image_path)) {
|
||||
$output = '/' . $image_dir . preg_replace('|^' . preg_quote($image_path) . '|', '', $output);
|
||||
$output = '/' . $image_dir . preg_replace('|^' . preg_quote($image_path, '|') . '|', '', $output);
|
||||
}
|
||||
|
||||
if ($reset) {
|
||||
|
@ -226,13 +245,13 @@ class ImageMedium extends Medium
|
|||
{
|
||||
if ($this->get('prettyname')) {
|
||||
return $this->get('prettyname');
|
||||
} else {
|
||||
$basename = $this->get('basename');
|
||||
if (preg_match('/[a-z0-9]{40}-(.*)/', $basename, $matches)) {
|
||||
$basename = $matches[1];
|
||||
}
|
||||
return $basename;
|
||||
}
|
||||
|
||||
$basename = $this->get('basename');
|
||||
if (preg_match('/[a-z0-9]{40}-(.*)/', $basename, $matches)) {
|
||||
$basename = $matches[1];
|
||||
}
|
||||
return $basename;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,7 +299,7 @@ class ImageMedium extends Medium
|
|||
// It's possible that MediumFactory::fromFile returns null if the
|
||||
// original image file no longer exists and this class instance was
|
||||
// retrieved from the page cache
|
||||
if (isset($derivative)) {
|
||||
if (null !== $derivative) {
|
||||
$index = 2;
|
||||
$alt_widths = array_keys($this->alternatives);
|
||||
sort($alt_widths);
|
||||
|
@ -339,7 +358,6 @@ class ImageMedium extends Medium
|
|||
|
||||
if ($this->image) {
|
||||
$this->image();
|
||||
$this->image->clearOperations(); // Clear previously applied operations
|
||||
$this->querystring('');
|
||||
$this->filter();
|
||||
$this->clearAlternatives();
|
||||
|
@ -432,7 +450,7 @@ class ImageMedium extends Medium
|
|||
* Set or get sizes parameter for srcset media action
|
||||
*
|
||||
* @param string $sizes
|
||||
* @return $this
|
||||
* @return string
|
||||
*/
|
||||
public function sizes($sizes = null)
|
||||
{
|
||||
|
@ -459,7 +477,7 @@ class ImageMedium extends Medium
|
|||
*/
|
||||
public function width($value = 'auto')
|
||||
{
|
||||
if (!$value || $value == 'auto')
|
||||
if (!$value || $value === 'auto')
|
||||
$this->attributes['width'] = $this->get('width');
|
||||
else
|
||||
$this->attributes['width'] = $value;
|
||||
|
@ -480,7 +498,7 @@ class ImageMedium extends Medium
|
|||
*/
|
||||
public function height($value = 'auto')
|
||||
{
|
||||
if (!$value || $value == 'auto')
|
||||
if (!$value || $value === 'auto')
|
||||
$this->attributes['height'] = $this->get('height');
|
||||
else
|
||||
$this->attributes['height'] = $value;
|
||||
|
@ -496,11 +514,11 @@ class ImageMedium extends Medium
|
|||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if ($method == 'cropZoom') {
|
||||
if ($method === 'cropZoom') {
|
||||
$method = 'zoomCrop';
|
||||
}
|
||||
|
||||
if (!in_array($method, self::$magic_actions)) {
|
||||
if (!\in_array($method, self::$magic_actions, true)) {
|
||||
return parent::__call($method, $args);
|
||||
}
|
||||
|
||||
|
@ -551,6 +569,9 @@ class ImageMedium extends Medium
|
|||
// Use existing cache folder or if it doesn't exist, create it.
|
||||
$cacheDir = $locator->findResource('cache://images', true) ?: $locator->findResource('cache://images', true, true);
|
||||
|
||||
// Make sure we free previous image.
|
||||
unset($this->image);
|
||||
|
||||
$this->image = ImageFile::open($file)
|
||||
->setCacheDir($cacheDir)
|
||||
->setActualCacheDir($cacheDir)
|
||||
|
@ -562,7 +583,7 @@ class ImageMedium extends Medium
|
|||
/**
|
||||
* Save the image with cache.
|
||||
*
|
||||
* @return mixed|string
|
||||
* @return string
|
||||
*/
|
||||
protected function saveImage()
|
||||
{
|
||||
|
@ -576,7 +597,7 @@ class ImageMedium extends Medium
|
|||
return $this->result;
|
||||
}
|
||||
|
||||
if ($this->get('debug') && !$this->debug_watermarked) {
|
||||
if (!$this->debug_watermarked && $this->get('debug')) {
|
||||
$ratio = $this->get('ratio');
|
||||
if (!$ratio) {
|
||||
$ratio = 1;
|
||||
|
@ -623,9 +644,9 @@ class ImageMedium extends Medium
|
|||
}
|
||||
|
||||
return $max;
|
||||
} else {
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue