Skip to content

Commit

Permalink
Merge branch 'release/1.7.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jun 2, 2021
2 parents b693ed4 + 6339d9f commit ad1cf15
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 51 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# v1.7.16
## 06/02/2021

1. [](#new)
* Added 'addFrame()' method to ImageMedium [#3323](https://github.com/getgrav/grav/pull/3323)
1. [](#improved)
* Set `cache.clear_images_by_default` to `false` by default
* Improve error on bad nested form data [#3364](https://github.com/getgrav/grav/issues/3364)
1. [](#bugfix)
* Improve Plugin and Theme initialization to fix PHP8 bug [#3368](https://github.com/getgrav/grav/issues/3368)
* Fixed `pathinfo()` twig filter in PHP7
* Fixed the first visible child page getting ordering number `999999.` [#3365](https://github.com/getgrav/grav/issues/3365)
* Fixed flex pages search using only folder name [#3316](https://github.com/getgrav/grav/issues/3316)
* Fixed flex pages using wrong type in `onBlueprintCreated` event [#3157](https://github.com/getgrav/grav/issues/3157)
* Fixed wrong SRI paths invoked when Grav instance as a sub folder [#3358](https://github.com/getgrav/grav/issues/3358)
* Fixed SRI trying to calculate remote assets, only ever set integrity for local files. Use the SRI provided by the remote source and manually add it in the `addJs/addCss` call for remote support. [#3358](https://github.com/getgrav/grav/issues/3358)
* Fix for weird regex issue with latest PHP versions on Intel Macs causing params to not parse properly in URI object

# v1.7.15
## 05/19/2021

Expand Down
2 changes: 1 addition & 1 deletion system/blueprints/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ form:
type: toggle
label: PLUGIN_ADMIN.CLEAR_IMAGES_BY_DEFAULT
help: PLUGIN_ADMIN.CLEAR_IMAGES_BY_DEFAULT_HELP
highlight: 1
highlight: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
Expand Down
2 changes: 1 addition & 1 deletion system/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ cache:
purge_at: '0 4 * * *' # How often to purge old file cache (using new scheduler)
clear_at: '0 3 * * *' # How often to clear cache (using new scheduler)
clear_job_type: 'standard' # Type to clear when processing the scheduled clear job `standard`|`all`
clear_images_by_default: true # By default grav will include processed images in cache clear, this can be disabled
clear_images_by_default: false # By default grav will include processed images in cache clear, this can be disabled
cli_compatibility: false # Ensures only non-volatile drivers are used (file, redis, memcache, etc.)
lifetime: 604800 # Lifetime of cached data in seconds (0 = infinite)
gzip: false # GZip compress the page output
Expand Down
2 changes: 1 addition & 1 deletion system/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// Some standard defines
define('GRAV', true);
define('GRAV_VERSION', '1.7.15');
define('GRAV_VERSION', '1.7.16');
define('GRAV_SCHEMA', '1.7.0_2020-11-20_1');
define('GRAV_TESTING', false);

Expand Down
18 changes: 12 additions & 6 deletions system/src/Grav/Common/Assets/BaseAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Grav\Common\Uri;
use Grav\Common\Utils;
use Grav\Framework\Object\PropertyObject;
use RocketTheme\Toolbox\File\File;
use SplFileInfo;

/**
Expand Down Expand Up @@ -182,16 +183,21 @@ public function setPosition($position)
public static function integrityHash($input)
{
$grav = Grav::instance();
$uri = $grav['uri'];

$assetsConfig = $grav['config']->get('system.assets');

if ( !empty($assetsConfig['enable_asset_sri']) && $assetsConfig['enable_asset_sri'] )
{
$dataToHash = file_get_contents( GRAV_WEBROOT . $input);
if (!self::isRemoteLink($input) && !empty($assetsConfig['enable_asset_sri']) && $assetsConfig['enable_asset_sri']) {
$input = preg_replace('#^' . $uri->rootUrl() . '#', '', $input);
$asset = File::instance(GRAV_WEBROOT . $input);

$hash = hash('sha256', $dataToHash, true);
$hash_base64 = base64_encode($hash);
return ' integrity="sha256-' . $hash_base64 . '"';
if ($asset->exists()) {
$dataToHash = $asset->content();
$hash = hash('sha256', $dataToHash, true);
$hash_base64 = base64_encode($hash);

return ' integrity="sha256-' . $hash_base64 . '"';
}
}

return '';
Expand Down
4 changes: 4 additions & 0 deletions system/src/Grav/Common/Data/BlueprintSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ protected function processFormRecursive(?array $data, array $toggles, array $nes
$toggle = [];
}
// Recursively fetch the items.
$childData = $data[$key] ?? null;
if (null !== $childData && !is_array($childData)) {
throw new \RuntimeException(sprintf("Bad form data for field collection '%s': %s used instead of an array", $key, gettype($childData)));
}
$data[$key] = $this->processFormRecursive($data[$key] ?? null, $toggle, $value);
} else {
$field = $this->get($value);
Expand Down
10 changes: 7 additions & 3 deletions system/src/Grav/Common/Flex/Types/Pages/PageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ protected function reorderSiblings(array $ordering)
$filesystem = Filesystem::getInstance(false);
$oldParentKey = ltrim($filesystem->dirname("/{$storageKey}"), '/');
$newParentKey = $this->getProperty('parent_key');
$isMoved = $oldParentKey !== $newParentKey;
$isMoved = $this->exists() && $oldParentKey !== $newParentKey;
$order = !$isMoved ? $this->order() : false;
if ($order !== false) {
$order = (int)$order;
Expand All @@ -385,10 +385,12 @@ protected function reorderSiblings(array $ordering)
// Handle special case where ordering isn't given.
if ($ordering === []) {
if ($order >= 999999) {
// Set ordering to point to be the last item.
// Set ordering to point to be the last item, ignoring the object itself.
$order = 0;
foreach ($siblings as $sibling) {
$order = max($order, (int)$sibling->order());
if ($sibling->getKey() !== $this->getKey()) {
$order = max($order, (int)$sibling->order());
}
}
$this->order($order + 1);
}
Expand Down Expand Up @@ -500,6 +502,8 @@ protected function doGetBlueprint(string $name = ''): Blueprint
if ($isNew === true && $name === '') {
// Support onBlueprintCreated event just like in Pages::blueprints($template)
$blueprint->set('initialized', true);
$blueprint->setFilename($template);

Grav::instance()->fireEvent('onBlueprintCreated', new Event(['blueprint' => $blueprint, 'type' => $template]));
}

Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Media/Traits/ImageMediaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ trait ImageMediaTrait
'resize', 'forceResize', 'cropResize', 'crop', 'zoomCrop',
'negate', 'brightness', 'contrast', 'grayscale', 'emboss',
'smooth', 'sharp', 'edge', 'colorize', 'sepia', 'enableProgressive',
'rotate', 'flip', 'fixOrientation', 'gaussianBlur', 'format'
'rotate', 'flip', 'fixOrientation', 'gaussianBlur', 'format', 'create', 'fill', 'merge'
];

/** @var array */
Expand Down
32 changes: 32 additions & 0 deletions system/src/Grav/Common/Page/Medium/ImageMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,45 @@ public function cropZoom()
return $this;
}

/**
* Add a frame to image
*
* @return $this
*/
public function addFrame(int $border = 10, string $color = '0x000000')
{
if(is_int(intval($border)) && $border>0 && preg_match('/^0x[a-f0-9]{6}$/i', $color)) { // $border must be an integer and bigger than 0; $color must be formatted as an HEX value (0x??????).
$image = ImageFile::open($this->path());
}
else {
return $this;
}

$dst_width = $image->width()+2*$border;
$dst_height = $image->height()+2*$border;

$frame = ImageFile::create($dst_width, $dst_height);

$frame->__call('fill', [$color]);

$this->image = $frame;

$this->__call('merge', [$image, $border, $border]);

$this->saveImage();

return $this;

}

/**
* Forward the call to the image processing method.
*
* @param string $method
* @param mixed $args
* @return $this|mixed
*/

public function __call($method, $args)
{
if (!in_array($method, static::$magic_actions, true)) {
Expand Down
41 changes: 25 additions & 16 deletions system/src/Grav/Common/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,33 +287,42 @@ protected function loadPlugin($name)
{
// NOTE: ALL THE LOCAL VARIABLES ARE USED INSIDE INCLUDED FILE, DO NOT REMOVE THEM!
$grav = Grav::instance();
/** @var UniformResourceLocator $locator */
$locator = $grav['locator'];
$file = $locator->findResource('plugins://' . $name . DS . $name . PLUGIN_EXT);
$class = null;

// Start by attempting to load the plugin_name.php file.
$file = $locator->findResource('plugins://' . $name . DS . $name . PLUGIN_EXT);
if (is_file($file)) {
// Local variables available in the file: $grav, $name, $file
$class = include_once $file;
if (!is_object($class) || !is_subclass_of($class, Plugin::class, true)) {
$class = null;
}
}

if (!$class || !is_subclass_of($class, Plugin::class, true)) {
$className = Inflector::camelize($name);
$pluginClassFormat = [
'Grav\\Plugin\\' . ucfirst($name). 'Plugin',
'Grav\\Plugin\\' . $className . 'Plugin',
'Grav\\Plugin\\' . $className
];

foreach ($pluginClassFormat as $pluginClass) {
if (is_subclass_of($pluginClass, Plugin::class, true)) {
$class = new $pluginClass($name, $grav);
break;
}
// If the class hasn't been initialized yet, guess the class name and create a new instance.
if (null === $class) {
$className = Inflector::camelize($name);
$pluginClassFormat = [
'Grav\\Plugin\\' . ucfirst($name). 'Plugin',
'Grav\\Plugin\\' . $className . 'Plugin',
'Grav\\Plugin\\' . $className
];

foreach ($pluginClassFormat as $pluginClass) {
if (is_subclass_of($pluginClass, Plugin::class, true)) {
$class = new $pluginClass($name, $grav);
break;
}
}
} else {
}

// Log a warning if plugin cannot be found.
if (null === $class) {
$grav['log']->addWarning(
sprintf("Plugin '%s' enabled but not found! Try clearing cache with `bin/grav clearcache`", $name)
);
return null;
}

return $class;
Expand Down
40 changes: 23 additions & 17 deletions system/src/Grav/Common/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,41 +224,47 @@ public function load()
$grav = $this->grav;
$config = $this->config;
$name = $this->current();
$class = null;

/** @var UniformResourceLocator $locator */
$locator = $grav['locator'];
$file = $locator('theme://theme.php') ?: $locator("theme://{$name}.php");

// Start by attempting to load the theme.php file.
$file = $locator('theme://theme.php') ?: $locator("theme://{$name}.php");
if ($file) {
// Local variables available in the file: $grav, $config, $name, $file
$class = include $file;

if (!$class || !is_subclass_of($class, Plugin::class, true)) {
$className = Inflector::camelize($name);
$themeClassFormat = [
'Grav\\Theme\\' . $className,
'Grav\\Theme\\' . ucfirst($name)
];

foreach ($themeClassFormat as $themeClass) {
if (is_subclass_of($themeClass, Theme::class, true)) {
$class = new $themeClass($grav, $config, $name);
break;
}
}
if (!\is_object($class) || !is_subclass_of($class, Theme::class, true)) {
$class = null;
}
} elseif (!$locator('theme://') && !defined('GRAV_CLI')) {
$response = new Response(500, [], "Theme '$name' does not exist, unable to display page.");

$grav->close($response);
}

$this->config->set('theme', $config->get('themes.' . $name));
// If the class hasn't been initialized yet, guess the class name and create a new instance.
if (null === $class) {
$themeClassFormat = [
'Grav\\Theme\\' . Inflector::camelize($name),
'Grav\\Theme\\' . ucfirst($name)
];

foreach ($themeClassFormat as $themeClass) {
if (is_subclass_of($themeClass, Theme::class, true)) {
$class = new $themeClass($grav, $config, $name);
break;
}
}
}

if (empty($class)) {
// Finally if everything else fails, just create a new instance from the default Theme class.
if (null === $class) {
$class = new Theme($grav, $config, $name);
}

$this->config->set('theme', $config->get('themes.' . $name));

return $class;
}

Expand Down
8 changes: 6 additions & 2 deletions system/src/Grav/Common/Twig/Extension/FilesystemExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,15 @@ public function get_meta_tags($filename)

/**
* @param string $path
* @param int $flags
* @param int|null $flags
* @return string|string[]
*/
public function pathinfo($path, $flags = PATHINFO_ALL)
public function pathinfo($path, $flags = null)
{
if (null !== $flags) {
return pathinfo($path, (int)$flags);
}

return pathinfo($path);
}

Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public function toArray($full = false)
*/
public static function paramsRegex()
{
return '/\/([^\:\#\/\?]*' . Grav::instance()['config']->get('system.param_sep') . '[^\:\#\/\?]*)/';
return '/\/{1,}([^\:\#\/\?]*' . Grav::instance()['config']->get('system.param_sep') . '[^\:\#\/\?]*)/';
}

/**
Expand Down Expand Up @@ -1498,7 +1498,7 @@ private function buildEnvironment()
* @param string $delimiter
* @return string
*/
private function processParams($uri, $delimiter = ':')
private function processParams(string $uri, string $delimiter = ':'): string
{
if (strpos($uri, $delimiter) !== false) {
preg_match_all(static::paramsRegex(), $uri, $matches, PREG_SET_ORDER);
Expand Down
6 changes: 5 additions & 1 deletion system/src/Grav/Framework/Flex/FlexObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ public function search(string $search, $properties = null, array $options = null

$weight = 0;
foreach ($properties as $property) {
$weight += $this->searchNestedProperty($property, $search, $options);
if (strpos($property, '.')) {
$weight += $this->searchNestedProperty($property, $search, $options);
} else {
$weight += $this->searchProperty($property, $search, $options);
}
}

return $weight > 0 ? min($weight, 1) : 0;
Expand Down

0 comments on commit ad1cf15

Please sign in to comment.