Skip to content

Commit

Permalink
Merge branch 'release/1.7.29'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jan 28, 2022
2 parents 5244924 + 96df7de commit 7b39a1b
Show file tree
Hide file tree
Showing 50 changed files with 387 additions and 92 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# v1.7.29
## 01/28/2022

1. [](#new)
* Added support for registering assets from `HtmlBlock`
* Added unicode-safe `Utils::basename()` and `Utils::pathinfo()` methods
2. [](#improved)
* Improved `Filesystem::basename()` and `Filesystem::pathinfo()` to be unicode-safe
* Made path handling unicode-safe, use new `Utils::basename()` and `Utils::pathinfo()` everywhere
3. [](#bugfix)
* Fixed error on thumbnail image creation
* Fixed MimeType for `gzip` (`application/x-gzip`)

# v1.7.28
## 01/24/2022

Expand Down
2 changes: 1 addition & 1 deletion system/config/media.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ types:
gz:
type: file
thumb: media/thumb-gz.png
mime: application/gzip
mime: application/x-gzip
tar:
type: file
thumb: media/thumb-tar.png
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.28');
define('GRAV_VERSION', '1.7.29');
define('GRAV_SCHEMA', '1.7.0_2020-11-20_1');
define('GRAV_TESTING', false);

Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function add($asset)
call_user_func_array([$this, 'add'], $args);
} else {
// Get extension
$extension = pathinfo(parse_url($asset, PHP_URL_PATH), PATHINFO_EXTENSION);
$extension = Utils::pathinfo(parse_url($asset, PHP_URL_PATH), PATHINFO_EXTENSION);

// JavaScript or CSS
if ($extension !== '') {
Expand Down
207 changes: 207 additions & 0 deletions system/src/Grav/Common/Assets/BlockAssets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
<?php

/**
* @package Grav\Common\Assets
*
* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/

namespace Grav\Common\Assets;

use Grav\Common\Assets;
use Grav\Common\Config\Config;
use Grav\Common\Grav;
use Grav\Framework\ContentBlock\HtmlBlock;
use function strlen;

/**
* Register block assets into Grav.
*/
class BlockAssets
{
/**
* @param HtmlBlock $block
* @return void
*/
public static function registerAssets(HtmlBlock $block): void
{
$grav = Grav::instance();

/** @var Assets $assets */
$assets = $grav['assets'];

$types = $block->getAssets();
foreach ($types as $type => $groups) {
switch ($type) {
case 'frameworks':
static::registerFrameworks($assets, $groups);
break;
case 'styles':
static::registerStyles($assets, $groups);
break;
case 'scripts':
static::registerScripts($assets, $groups);
break;
case 'links':
static::registerLinks($assets, $groups);
break;
case 'html':
static::registerHtml($assets, $groups);
break;
}
}
}

/**
* @param Assets $assets
* @param array $groups
* @return void
*/
protected static function registerFrameworks(Assets $assets, array $list): void
{
if ($list) {
throw new \RuntimeException('Not Implemented');
}
}

/**
* @param Assets $assets
* @param array $groups
* @return void
*/
protected static function registerStyles(Assets $assets, array $groups): void
{
$grav = Grav::instance();

/** @var Config $config */
$config = $grav['config'];

foreach ($groups as $group => $styles) {
foreach ($styles as $style) {
switch ($style[':type']) {
case 'file':
$options = [
'priority' => $style[':priority'],
'group' => $group,
'type' => $style['type'],
'media' => $style['media']
] + $style['element'];

$assets->addCss(static::getRelativeUrl($style['href'], $config->get('system.assets.css_pipeline')), $options);
break;
case 'inline':
$options = [
'priority' => $style[':priority'],
'group' => $group,
'type' => $style['type'],
] + $style['element'];

$assets->addInlineCss($style['content'], $options);
break;
}
}
}
}

/**
* @param Assets $assets
* @param array $groups
* @return void
*/
protected static function registerScripts(Assets $assets, array $groups): void
{
$grav = Grav::instance();

/** @var Config $config */
$config = $grav['config'];

foreach ($groups as $group => $scripts) {
$group = $group === 'footer' ? 'bottom' : $group;

foreach ($scripts as $script) {
switch ($script[':type']) {
case 'file':
$options = [
'group' => $group,
'priority' => $script[':priority'],
'src' => $script['src'],
'type' => $script['type'],
'loading' => $script['loading'],
'defer' => $script['defer'],
'async' => $script['async'],
'handle' => $script['handle']
] + $script['element'];

$assets->addJs(static::getRelativeUrl($script['src'], $config->get('system.assets.js_pipeline')), $options);
break;
case 'inline':
$options = [
'priority' => $script[':priority'],
'group' => $group,
'type' => $script['type'],
'loading' => $script['loading']
] + $script['element'];

$assets->addInlineJs($script['content'], $options);
break;
}
}
}
}

/**
* @param Assets $assets
* @param array $groups
* @return void
*/
protected static function registerLinks(Assets $assets, array $groups): void
{
foreach ($groups as $group => $links) {
foreach ($links as $link) {
$href = $link['href'];
$options = [
'group' => $group,
'priority' => $link[':priority'],
'rel' => $link['rel'],
] + $link['element'];

$assets->addLink($href, $options);
}
}
}

/**
* @param Assets $assets
* @param array $groups
* @return void
*/
protected static function registerHtml(Assets $assets, array $groups): void
{
if ($groups) {
throw new \RuntimeException('Not Implemented');
}
}

/**
* @param string $url
* @param bool $pipeline
* @return string
*/
protected static function getRelativeUrl($url, $pipeline)
{
$grav = Grav::instance();

$base = rtrim($grav['base_url'], '/') ?: '/';

if (strpos($url, $base) === 0) {
if ($pipeline) {
// Remove file timestamp if CSS pipeline has been enabled.
$url = preg_replace('|[?#].*|', '', $url);
}

return substr($url, strlen($base) - 1);
}
return $url;
}
}
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Backup/Backups.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function onSchedulerInitialized(Event $event)
public function getBackupDownloadUrl($backup, $base_url)
{
$param_sep = $param_sep = Grav::instance()['config']->get('system.param_sep', ':');
$download = urlencode(base64_encode(basename($backup)));
$download = urlencode(base64_encode(Utils::basename($backup)));
$url = rtrim(Grav::instance()['uri']->rootUrl(true), '/') . '/' . trim(
$base_url,
'/'
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function getSimpleCache()
public function purgeOldCache()
{
$cache_dir = dirname($this->cache_dir);
$current = basename($this->cache_dir);
$current = Utils::basename($this->cache_dir);
$count = 0;

foreach (new DirectoryIterator($cache_dir) as $file) {
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Config/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected function check(UniformResourceLocator $locator)
}

// Create security.yaml salt if it doesn't exist into existing configuration environment if possible.
$securityFile = basename(static::$securityFile);
$securityFile = Utils::basename(static::$securityFile);
$securityFolder = substr(static::$securityFile, 0, -\strlen($securityFile));
$securityFolder = $locator->findResource($securityFolder, true) ?: $locator->findResource($securityFolder, true, true);
$filename = "{$securityFolder}/{$securityFile}";
Expand Down
3 changes: 2 additions & 1 deletion system/src/Grav/Common/File/CompiledFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Grav\Common\File;

use Exception;
use Grav\Common\Utils;
use RocketTheme\Toolbox\File\PhpFile;
use RuntimeException;
use Throwable;
Expand Down Expand Up @@ -88,7 +89,7 @@ public function content($var = null)
$this->content = $cache['data'];
}
} catch (Exception $e) {
throw new RuntimeException(sprintf('Failed to read %s: %s', basename($this->filename), $e->getMessage()), 500, $e);
throw new RuntimeException(sprintf('Failed to read %s: %s', Utils::basename($this->filename), $e->getMessage()), 500, $e);
}

return parent::content($var);
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Flex/Types/Pages/PageCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ protected function buildSort($order_by = 'default', $order_dir = 'asc', $manual
$list[$key] = $child->slug();
break;
case 'basename':
$list[$key] = basename($key);
$list[$key] = Utils::basename($key);
break;
case 'folder':
$list[$key] = $child->folder();
Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/Flex/Types/Pages/PageIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ protected function getLevelListingRecurse(array $options): array
$payload = [
'name' => $child->menu(),
'value' => $child->rawRoute(),
'item-key' => basename($child->rawRoute() ?? ''),
'item-key' => Utils::basename($child->rawRoute() ?? ''),
'filename' => $child->folder(),
'extension' => $child->extension(),
'type' => 'dir',
Expand Down Expand Up @@ -692,7 +692,7 @@ protected function getLevelListingRecurse(array $options): array
$route = $child->getRoute();
$route = $route ? ($route->toString(false) ?: '/') : '';
$payload = [
'item-key' => htmlspecialchars(basename($child->rawRoute() ?? $child->getKey())),
'item-key' => htmlspecialchars(Utils::basename($child->rawRoute() ?? $child->getKey())),
'icon' => $icon,
'title' => htmlspecialchars($child->menu()),
'route' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
use Grav\Common\Flex\Types\Pages\PageIndex;
use Grav\Common\Grav;
use Grav\Common\Language\Language;
use Grav\Common\Utils;
use Grav\Framework\Filesystem\Filesystem;
use Grav\Framework\Flex\Storage\FolderStorage;
use RocketTheme\Toolbox\File\MarkdownFile;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use RuntimeException;
use SplFileInfo;
use function assert;
use function in_array;
use function is_string;

Expand Down Expand Up @@ -277,7 +277,7 @@ public function extractKeysFromStorageKey(string $key): array
} else {
$params = $template = $language = '';
}
$objectKey = basename($key);
$objectKey = Utils::basename($key);
if (preg_match('|^(\d+)\.(.+)$|', $objectKey, $matches)) {
[, $order, $folder] = $matches;
} else {
Expand Down Expand Up @@ -584,7 +584,7 @@ protected function getObjectMeta(string $key, bool $reload = false): array
$mark = $matches[2] ?? '';
$ext = $matches[1] ?? '';
$ext .= $this->dataExt;
$markdown[$mark][basename($k, $ext)] = $timestamp;
$markdown[$mark][Utils::basename($k, $ext)] = $timestamp;
}

$modified = max($modified, $timestamp);
Expand Down Expand Up @@ -675,7 +675,7 @@ protected function getIndexMeta(): array

/** @phpstan-var array{'storage_key': string, 'storage_timestamp': int, 'children': array<string, mixed>} $parent */
$parent = &$list[$parentKey];
$basename = basename($storage_key);
$basename = Utils::basename($storage_key);

if (isset($parent['children'][$basename])) {
$timestamp = $meta['storage_timestamp'];
Expand Down
5 changes: 3 additions & 2 deletions system/src/Grav/Common/Flex/Types/Users/UserObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Grav\Common\Flex\Types\UserGroups\UserGroupIndex;
use Grav\Common\User\Interfaces\UserInterface;
use Grav\Common\User\Traits\UserTrait;
use Grav\Common\Utils;
use Grav\Framework\File\Formatter\JsonFormatter;
use Grav\Framework\File\Formatter\YamlFormatter;
use Grav\Framework\Filesystem\Filesystem;
Expand Down Expand Up @@ -645,7 +646,7 @@ public function getMedia()
$medium = MediumFactory::fromFile($path);
if ($medium) {
$media->add($path, $medium);
$name = basename($path);
$name = Utils::basename($path);
if ($name !== $path) {
$media->add($name, $medium);
}
Expand Down Expand Up @@ -814,7 +815,7 @@ protected function setUpdatedMedia(array $files): void
}

// Calculate path without the retina scaling factor.
$realpath = $filesystem->pathname($filepath) . str_replace(['@3x', '@2x'], '', basename($filepath));
$realpath = $filesystem->pathname($filepath) . str_replace(['@3x', '@2x'], '', Utils::basename($filepath));

$list[$filename] = [$file, $settings];

Expand Down
Loading

0 comments on commit 7b39a1b

Please sign in to comment.