Skip to content

Commit

Permalink
📝 added confirm option to readme again thanks @jaro-io
Browse files Browse the repository at this point in the history
🐛 php bug fixes thanks @tristantbg
🐛 k4 icons size must be 24x24 svg thanks @tobimori
⬆️ upgraded dependencies
✨ confirm can be translated and template strings

closes #114
closes #115

Signed-off-by: bnomei <[email protected]>
  • Loading branch information
bnomei committed Oct 25, 2023
1 parent af806a7 commit 6fdc3d8
Show file tree
Hide file tree
Showing 22 changed files with 408 additions and 420 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ The button you create with the `field: janitor` in your blueprint can be configu
- `autosave`, if `true` then save before pressing the button
- `backgroundColor`, sets backgroundColor of button
- `color`, sets text color of button
- `confirm`, sets text for confirmation after clicking the button and before executing the command, can prevent the execution of the command if the user clicks `cancel` in the OS dialog
- `command`, command like you would enter it in terminal, with [query language support](https://getkirby.com/docs/guide/blueprints/query-language) and page/file/user/site/data arguments
- `cooldown`, time in milliseconds the message is flashed on the button (default: 2000)
- `error`, set message to show on all **non-200**-status returns with query language support
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby3-janitor",
"type": "kirby-plugin",
"version": "3.11.0",
"version": "3.12.0",
"license": "MIT",
"homepage": "https://github.com/bnomei/kirby3-janitor",
"description": "Kirby 3 Plugin for running commands like cleaning the cache from within the Panel, PHP code or a cronjob",
Expand Down
528 changes: 223 additions & 305 deletions composer.lock

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

@include_once __DIR__ . '/vendor/autoload.php';

if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'wb'));

/*
janitor [noun]
one who keeps the premises of a building (such as an apartment or
Expand Down Expand Up @@ -49,7 +51,7 @@
'clipboard' => function ($clipboard = null) {
return Janitor::isTrue($clipboard);
},
'command' => function ($command = null) {
'command' => function ($command = '') {
// make lazy by default
$command = str_replace(['{{', '}}'], ['{(', ')}'], $command);

Expand Down Expand Up @@ -84,7 +86,10 @@
return $command;
},
'confirm' => function ($confirm = '') {
return $confirm;
if (kirby()->multilang()) {
$confirm = I18n::translate($confirm, $confirm, kirby()->language()->code());
}
return Janitor::query($confirm, $this->model());
},
'color' => function ($style = 'white') {
return Janitor::query($style, $this->model());
Expand Down
16 changes: 8 additions & 8 deletions snippets/maintenance.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
http_response_code(503); // Service Unavailable
/*
The Web server (running the Web site) is currently unable
to handle the HTTP request due to a temporary overloading or
maintenance of the server. The implication is that this is
a temporary condition which will be alleviated after some delay.
*/
?><!DOCTYPE html>
http_response_code(503); // Service Unavailable
/*
The Web server (running the Web site) is currently unable
to handle the HTTP request due to a temporary overloading or
maintenance of the server. The implication is that this is
a temporary condition which will be alleviated after some delay.
*/
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ window.panel.plugin("bnomei/janitor", {
},
icons: {
janitorLoader:
'<g fill="none" fill-rule="evenodd"><g transform="translate(1 1)" stroke-width="1.75"><circle cx="7" cy="7" r="7.2" stroke="#000" stroke-opacity=".2"/><path d="M14.2,7c0-4-3.2-7.2-7.2-7.2" stroke="#000"><animateTransform attributeName="transform" type="rotate" from="0 7 7" to="360 7 7" dur="1s" repeatCount="indefinite"/></path></g></g>'
'<svg viewBox="0 0 24 24" version="1.1" id="svg2" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd" id="g2" transform="matrix(1.2373578,0,0,1.2393776,2.1011378,2.0846672)"><g transform="translate(1,1)" stroke-width="1.75" id="g1"><circle cx="7" cy="7" r="7.2" stroke="#000" stroke-opacity=".2" id="circle1"/><path d="M 14.2,7 C 14.2,3 11,-0.2 7,-0.2" stroke="#000" id="path1"><animateTransform attributeName="transform" type="rotate" from="0 7 7" to="360 7 7" dur="1s" repeatCount="indefinite"/></path></g></g></svg>'
}
});
20 changes: 10 additions & 10 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php return array(
'root' => array(
'name' => 'bnomei/kirby3-janitor',
'pretty_version' => '3.11.0',
'version' => '3.11.0.0',
'pretty_version' => '3.12.0',
'version' => '3.12.0.0',
'reference' => NULL,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand All @@ -11,8 +11,8 @@
),
'versions' => array(
'bnomei/kirby3-janitor' => array(
'pretty_version' => '3.11.0',
'version' => '3.11.0.0',
'pretty_version' => '3.12.0',
'version' => '3.12.0.0',
'reference' => NULL,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand All @@ -29,18 +29,18 @@
'dev_requirement' => false,
),
'symfony/deprecation-contracts' => array(
'pretty_version' => 'v3.0.2',
'version' => '3.0.2.0',
'reference' => '26954b3d62a6c5fd0ea8a2a00c0353a14978d05c',
'pretty_version' => 'v3.3.0',
'version' => '3.3.0.0',
'reference' => '7c3aff79d10325257a001fcf92d991f24fc967cf',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/deprecation-contracts',
'aliases' => array(),
'dev_requirement' => false,
),
'symfony/finder' => array(
'pretty_version' => 'v6.0.19',
'version' => '6.0.19.0',
'reference' => '5cc9cac6586fc0c28cd173780ca696e419fefa11',
'pretty_version' => 'v6.3.5',
'version' => '6.3.5.0',
'reference' => 'a1b31d88c0e998168ca7792f222cbecee47428c4',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/finder',
'aliases' => array(),
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/platform_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

$issues = array();

if (!(PHP_VERSION_ID >= 80002)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 8.0.2". You are running ' . PHP_VERSION . '.';
if (!(PHP_VERSION_ID >= 80100)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 8.1.0". You are running ' . PHP_VERSION . '.';
}

if ($issues) {
Expand Down
22 changes: 8 additions & 14 deletions vendor/symfony/finder/Comparator/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,13 @@ public function getOperator(): string
*/
public function test(mixed $test): bool
{
switch ($this->operator) {
case '>':
return $test > $this->target;
case '>=':
return $test >= $this->target;
case '<':
return $test < $this->target;
case '<=':
return $test <= $this->target;
case '!=':
return $test != $this->target;
}

return $test == $this->target;
return match ($this->operator) {
'>' => $test > $this->target,
'>=' => $test >= $this->target,
'<' => $test < $this->target,
'<=' => $test <= $this->target,
'!=' => $test != $this->target,
default => $test == $this->target,
};
}
}
4 changes: 2 additions & 2 deletions vendor/symfony/finder/Comparator/DateComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public function __construct(string $test)
}

try {
$date = new \DateTime($matches[2]);
$date = new \DateTimeImmutable($matches[2]);
$target = $date->format('U');
} catch (\Exception $e) {
} catch (\Exception) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
}

Expand Down
2 changes: 1 addition & 1 deletion vendor/symfony/finder/Comparator/NumberComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class NumberComparator extends Comparator
{
/**
* @param string|int $test A comparison string or an integer
* @param string|null $test A comparison string or null
*
* @throws \InvalidArgumentException If the test is not understood
*/
Expand Down
60 changes: 54 additions & 6 deletions vendor/symfony/finder/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public function date(string|array $dates): static
*
* You can use patterns (delimited with / sign), globs or simple strings.
*
* $finder->name('*.php')
* $finder->name('/\.php$/') // same as above
* $finder->name('/\.php$/')
* $finder->name('*.php') // same as above, without dot files
* $finder->name('test.php')
* $finder->name(['test.py', 'test.php'])
*
Expand Down Expand Up @@ -396,6 +396,8 @@ public function ignoreVCSIgnored(bool $ignoreVCSIgnored): static
* @see ignoreVCS()
*
* @param string|string[] $pattern VCS patterns to ignore
*
* @return void
*/
public static function addVCSPattern(string|array $pattern)
{
Expand Down Expand Up @@ -424,6 +426,22 @@ public function sort(\Closure $closure): static
return $this;
}

/**
* Sorts files and directories by extension.
*
* This can be slow as all the matching files and directories must be retrieved for comparison.
*
* @return $this
*
* @see SortableIterator
*/
public function sortByExtension(): static
{
$this->sort = Iterator\SortableIterator::SORT_BY_EXTENSION;

return $this;
}

/**
* Sorts files and directories by name.
*
Expand All @@ -440,6 +458,38 @@ public function sortByName(bool $useNaturalSort = false): static
return $this;
}

/**
* Sorts files and directories by name case insensitive.
*
* This can be slow as all the matching files and directories must be retrieved for comparison.
*
* @return $this
*
* @see SortableIterator
*/
public function sortByCaseInsensitiveName(bool $useNaturalSort = false): static
{
$this->sort = $useNaturalSort ? Iterator\SortableIterator::SORT_BY_NAME_NATURAL_CASE_INSENSITIVE : Iterator\SortableIterator::SORT_BY_NAME_CASE_INSENSITIVE;

return $this;
}

/**
* Sorts files and directories by size.
*
* This can be slow as all the matching files and directories must be retrieved for comparison.
*
* @return $this
*
* @see SortableIterator
*/
public function sortBySize(): static
{
$this->sort = Iterator\SortableIterator::SORT_BY_SIZE;

return $this;
}

/**
* Sorts files and directories by type (directories before files), then by name.
*
Expand Down Expand Up @@ -585,7 +635,7 @@ public function in(string|array $dirs): static
$resolvedDirs[] = [$this->normalizeDir($dir)];
} elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? \GLOB_BRACE : 0) | \GLOB_ONLYDIR | \GLOB_NOSORT)) {
sort($glob);
$resolvedDirs[] = array_map([$this, 'normalizeDir'], $glob);
$resolvedDirs[] = array_map($this->normalizeDir(...), $glob);
} else {
throw new DirectoryNotFoundException(sprintf('The "%s" directory does not exist.', $dir));
}
Expand Down Expand Up @@ -623,9 +673,7 @@ public function getIterator(): \Iterator

$iterator = new \AppendIterator();
foreach ($this->dirs as $dir) {
$iterator->append(new \IteratorIterator(new LazyIterator(function () use ($dir) {
return $this->searchInDirectory($dir);
})));
$iterator->append(new \IteratorIterator(new LazyIterator(fn () => $this->searchInDirectory($dir))));
}

foreach ($this->iterators as $it) {
Expand Down
6 changes: 2 additions & 4 deletions vendor/symfony/finder/Gitignore.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static function buildRegex(string $gitignoreFileContent, bool $inverted)
foreach ($gitignoreLines as $line) {
$line = preg_replace('~(?<!\\\\)[ \t]+$~', '', $line);

if ('!' === substr($line, 0, 1)) {
if (str_starts_with($line, '!')) {
$line = substr($line, 1);
$isNegative = true;
} else {
Expand Down Expand Up @@ -79,9 +79,7 @@ private static function lineToRegex(string $gitignoreLine): string
}

$regex = preg_quote(str_replace('\\', '', $gitignoreLine), '~');
$regex = preg_replace_callback('~\\\\\[((?:\\\\!)?)([^\[\]]*)\\\\\]~', function (array $matches): string {
return '['.('' !== $matches[1] ? '^' : '').str_replace('\\-', '-', $matches[2]).']';
}, $regex);
$regex = preg_replace_callback('~\\\\\[((?:\\\\!)?)([^\[\]]*)\\\\\]~', fn (array $matches): string => '['.('' !== $matches[1] ? '^' : '').str_replace('\\-', '-', $matches[2]).']', $regex);
$regex = preg_replace('~(?:(?:\\\\\*){2,}(/?))+~', '(?:(?:(?!//).(?<!//))+$1)?', $regex);
$regex = preg_replace('~\\\\\*~', '[^/]*', $regex);
$regex = preg_replace('~\\\\\?~', '[^/]', $regex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@

namespace Symfony\Component\Finder\Iterator;

use Symfony\Component\Finder\SplFileInfo;

/**
* ExcludeDirectoryFilterIterator filters out directories.
*
* @author Fabien Potencier <[email protected]>
*
* @extends \FilterIterator<string, \SplFileInfo>
* @implements \RecursiveIterator<string, \SplFileInfo>
* @extends \FilterIterator<string, SplFileInfo>
*
* @implements \RecursiveIterator<string, SplFileInfo>
*/
class ExcludeDirectoryFilterIterator extends \FilterIterator implements \RecursiveIterator
{
/** @var \Iterator<string, SplFileInfo> */
private \Iterator $iterator;
private bool $isRecursive;
private array $excludedDirs = [];
private ?string $excludedPattern = null;

/**
* @param \Iterator $iterator The Iterator to filter
* @param string[] $directories An array of directories to exclude
* @param \Iterator<string, SplFileInfo> $iterator The Iterator to filter
* @param string[] $directories An array of directories to exclude
*/
public function __construct(\Iterator $iterator, array $directories)
{
Expand Down
4 changes: 2 additions & 2 deletions vendor/symfony/finder/Iterator/FileTypeFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class FileTypeFilterIterator extends \FilterIterator
private int $mode;

/**
* @param \Iterator $iterator The Iterator to filter
* @param int $mode The mode (self::ONLY_FILES or self::ONLY_DIRECTORIES)
* @param \Iterator<string, \SplFileInfo> $iterator The Iterator to filter
* @param int $mode The mode (self::ONLY_FILES or self::ONLY_DIRECTORIES)
*/
public function __construct(\Iterator $iterator, int $mode)
{
Expand Down
4 changes: 3 additions & 1 deletion vendor/symfony/finder/Iterator/FilecontentFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

namespace Symfony\Component\Finder\Iterator;

use Symfony\Component\Finder\SplFileInfo;

/**
* FilecontentFilterIterator filters files by their contents using patterns (regexps or strings).
*
* @author Fabien Potencier <[email protected]>
* @author Włodzimierz Gajda <[email protected]>
*
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
* @extends MultiplePcreFilterIterator<string, SplFileInfo>
*/
class FilecontentFilterIterator extends MultiplePcreFilterIterator
{
Expand Down
2 changes: 1 addition & 1 deletion vendor/symfony/finder/Iterator/LazyIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LazyIterator implements \IteratorAggregate

public function __construct(callable $iteratorFactory)
{
$this->iteratorFactory = $iteratorFactory instanceof \Closure ? $iteratorFactory : \Closure::fromCallable($iteratorFactory);
$this->iteratorFactory = $iteratorFactory(...);
}

public function getIterator(): \Traversable
Expand Down
6 changes: 3 additions & 3 deletions vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
protected $noMatchRegexps = [];

/**
* @param \Iterator $iterator The Iterator to filter
* @param string[] $matchPatterns An array of patterns that need to match
* @param string[] $noMatchPatterns An array of patterns that need to not match
* @param \Iterator<TKey, TValue> $iterator The Iterator to filter
* @param string[] $matchPatterns An array of patterns that need to match
* @param string[] $noMatchPatterns An array of patterns that need to not match
*/
public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
{
Expand Down
Loading

0 comments on commit 6fdc3d8

Please sign in to comment.