mirror of
https://github.com/getgrav/grav.git
synced 2026-07-10 11:12:17 +02:00
Code cleanup
This commit is contained in:
@@ -14,7 +14,6 @@ use Grav\Common\Grav;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Framework\Object\PropertyObject;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
|
||||
abstract class BaseAsset extends PropertyObject
|
||||
{
|
||||
|
||||
@@ -141,7 +141,7 @@ class Pipeline extends PropertyObject
|
||||
}
|
||||
|
||||
// Write file
|
||||
if (\strlen(trim($buffer)) > 0) {
|
||||
if (trim($buffer) !== '') {
|
||||
file_put_contents($this->assets_dir . $file, $buffer);
|
||||
}
|
||||
}
|
||||
@@ -214,16 +214,16 @@ class Pipeline extends PropertyObject
|
||||
}
|
||||
|
||||
// Write file
|
||||
if (\strlen(trim($buffer)) > 0) {
|
||||
if (trim($buffer) !== '') {
|
||||
file_put_contents($this->assets_dir . $file, $buffer);
|
||||
}
|
||||
}
|
||||
|
||||
if ($inline_group) {
|
||||
$output = "<script" . $this->renderAttributes(). ">\n" . $buffer . "\n</script>\n";
|
||||
$output = '<script' . $this->renderAttributes(). ">\n" . $buffer . "\n</script>\n";
|
||||
} else {
|
||||
$this->asset = $relative_path;
|
||||
$output = "<script src=\"" . $relative_path . $this->renderQueryString() . "\"" . $this->renderAttributes() . "></script>\n";
|
||||
$output = '<script src="' . $relative_path . $this->renderQueryString() . '"' . $this->renderAttributes() . "></script>\n";
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
@@ -58,7 +58,7 @@ trait AssetUtilsTrait
|
||||
if (0 === strpos($link, '//')) {
|
||||
$link = 'http:' . $link;
|
||||
}
|
||||
$relative_dir = dirname($relative_path);
|
||||
$relative_dir = \dirname($relative_path);
|
||||
} else {
|
||||
// Fix to remove relative dir if grav is in one
|
||||
if (($this->base_url !== '/') && Utils::startsWith($relative_path, $this->base_url)) {
|
||||
@@ -66,7 +66,7 @@ trait AssetUtilsTrait
|
||||
$relative_path = ltrim(preg_replace($base_url, '/', $link, 1), '/');
|
||||
}
|
||||
|
||||
$relative_dir = dirname($relative_path);
|
||||
$relative_dir = \dirname($relative_path);
|
||||
$link = ROOT_DIR . $relative_path;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class Backups
|
||||
|
||||
public function setup()
|
||||
{
|
||||
if (is_null(static::$backup_dir)) {
|
||||
if (null === static::$backup_dir) {
|
||||
static::$backup_dir = Grav::instance()['locator']->findResource('backup://', true, true);
|
||||
Folder::create(static::$backup_dir);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class Backups
|
||||
|
||||
public static function getAvailableBackups($force = false)
|
||||
{
|
||||
if ($force || is_null(static::$backups)) {
|
||||
if ($force || null === static::$backups) {
|
||||
static::$backups = [];
|
||||
$backups_itr = new \GlobIterator(static::$backup_dir . '/*.zip', \FilesystemIterator::KEY_AS_FILENAME);
|
||||
$inflector = Grav::instance()['inflector'];
|
||||
@@ -166,7 +166,7 @@ class Backups
|
||||
}
|
||||
|
||||
if (!file_exists($backup_root)) {
|
||||
throw new \RuntimeException("Backup location: " . $backup_root . ' does not exist...');
|
||||
throw new \RuntimeException("Backup location: {$backup_root} does not exist...");
|
||||
}
|
||||
|
||||
$options = [
|
||||
@@ -246,6 +246,6 @@ class Backups
|
||||
protected static function convertExclude($exclude)
|
||||
{
|
||||
$lines = preg_split("/[\s,]+/", $exclude);
|
||||
return array_map('trim', $lines, array_fill(0,count($lines),'/'));
|
||||
return array_map('trim', $lines, array_fill(0, \count($lines), '/'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class Browser
|
||||
{
|
||||
$version = explode('.', $this->getLongVersion());
|
||||
|
||||
return intval($version[0]);
|
||||
return (int)$version[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,10 +144,6 @@ class Browser
|
||||
*/
|
||||
public function isTrackable(): bool
|
||||
{
|
||||
if (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] === '1') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !(isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] === '1');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@ namespace Grav\Common;
|
||||
use \Doctrine\Common\Cache as DoctrineCache;
|
||||
use Grav\Common\Config\Config;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\Scheduler\Scheduler;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\Event\EventDispatcher;
|
||||
|
||||
/**
|
||||
* The GravCache object is used throughout Grav to store and retrieve cached data.
|
||||
@@ -118,7 +120,7 @@ class Cache extends Getters
|
||||
$this->config = $grav['config'];
|
||||
$this->now = time();
|
||||
|
||||
if (is_null($this->enabled)) {
|
||||
if (null === $this->enabled) {
|
||||
$this->enabled = (bool)$this->config->get('system.cache.enabled');
|
||||
}
|
||||
|
||||
@@ -148,7 +150,7 @@ class Cache extends Getters
|
||||
|
||||
foreach (new \DirectoryIterator($cache_dir) as $file) {
|
||||
$dir = $file->getBasename();
|
||||
if ($file->isDot() || $file->isFile() || $dir === $current) {
|
||||
if ($dir === $current || $file->isDot() || $file->isFile()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -166,7 +168,7 @@ class Cache extends Getters
|
||||
*/
|
||||
public function setEnabled($enabled)
|
||||
{
|
||||
$this->enabled = (bool) $enabled;
|
||||
$this->enabled = (bool)$enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,11 +205,11 @@ class Cache extends Getters
|
||||
|
||||
// CLI compatibility requires a non-volatile cache driver
|
||||
if ($this->config->get('system.cache.cli_compatibility') && (
|
||||
$setting == 'auto' || $this->isVolatileDriver($setting))) {
|
||||
$setting === 'auto' || $this->isVolatileDriver($setting))) {
|
||||
$setting = $driver_name;
|
||||
}
|
||||
|
||||
if (!$setting || $setting == 'auto') {
|
||||
if (!$setting || $setting === 'auto') {
|
||||
if (extension_loaded('apcu')) {
|
||||
$driver_name = 'apcu';
|
||||
} elseif (extension_loaded('apc')) {
|
||||
@@ -296,9 +298,9 @@ class Cache extends Getters
|
||||
{
|
||||
if ($this->enabled) {
|
||||
return $this->driver->fetch($id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -463,7 +465,7 @@ class Cache extends Getters
|
||||
|
||||
$output[] = '';
|
||||
|
||||
if (($remove == 'all' || $remove == 'standard') && file_exists($user_config)) {
|
||||
if (($remove === 'all' || $remove === 'standard') && file_exists($user_config)) {
|
||||
touch($user_config);
|
||||
|
||||
$output[] = '<red>Touched: </red>' . $user_config;
|
||||
@@ -544,17 +546,17 @@ class Cache extends Getters
|
||||
{
|
||||
if (in_array($setting, ['apc', 'apcu', 'xcache', 'wincache'])) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function purgeJob()
|
||||
{
|
||||
$cache = Grav::instance()['cache'];
|
||||
$deleted_folders = $cache->purgeOldCache();
|
||||
$msg = 'Purged ' . $deleted_folders . ' old cache folders...';
|
||||
return $msg;
|
||||
|
||||
return 'Purged ' . $deleted_folders . ' old cache folders...';
|
||||
}
|
||||
|
||||
public function onSchedulerInitialized(Event $event)
|
||||
|
||||
@@ -199,9 +199,7 @@ abstract class CompiledBase
|
||||
$cache = include $filename;
|
||||
if (
|
||||
!\is_array($cache)
|
||||
|| !isset($cache['checksum'])
|
||||
|| !isset($cache['data'])
|
||||
|| !isset($cache['@class'])
|
||||
|| !isset($cache['checksum'], $cache['data'], $cache['@class'])
|
||||
|| $cache['@class'] !== \get_class($this)
|
||||
) {
|
||||
return false;
|
||||
|
||||
@@ -13,17 +13,18 @@ use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Data\BlueprintSchema;
|
||||
use Grav\Common\Grav;
|
||||
|
||||
/**
|
||||
* Class CompiledBlueprints
|
||||
* @package Grav\Common\Config
|
||||
*/
|
||||
class CompiledBlueprints extends CompiledBase
|
||||
{
|
||||
/**
|
||||
* @var int Version number for the compiled file.
|
||||
*/
|
||||
public $version = 2;
|
||||
public function __construct($cacheFolder, array $files, $path)
|
||||
{
|
||||
parent::__construct($cacheFolder, $files, $path);
|
||||
|
||||
/**
|
||||
* @var BlueprintSchema Blueprints object.
|
||||
*/
|
||||
protected $object;
|
||||
$this->version = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns checksum from the configuration files.
|
||||
|
||||
@@ -13,16 +13,6 @@ use Grav\Common\File\CompiledYamlFile;
|
||||
|
||||
class CompiledConfig extends CompiledBase
|
||||
{
|
||||
/**
|
||||
* @var int Version number for the compiled file.
|
||||
*/
|
||||
public $version = 1;
|
||||
|
||||
/**
|
||||
* @var Config Configuration object.
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* @var callable Blueprints loader.
|
||||
*/
|
||||
@@ -33,6 +23,13 @@ class CompiledConfig extends CompiledBase
|
||||
*/
|
||||
protected $withDefaults;
|
||||
|
||||
public function __construct($cacheFolder, array $files, $path)
|
||||
{
|
||||
parent::__construct($cacheFolder, $files, $path);
|
||||
|
||||
$this->version = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set blueprints for the configuration.
|
||||
*
|
||||
|
||||
@@ -13,15 +13,12 @@ use Grav\Common\File\CompiledYamlFile;
|
||||
|
||||
class CompiledLanguages extends CompiledBase
|
||||
{
|
||||
/**
|
||||
* @var int Version number for the compiled file.
|
||||
*/
|
||||
public $version = 1;
|
||||
public function __construct($cacheFolder, array $files, $path)
|
||||
{
|
||||
parent::__construct($cacheFolder, $files, $path);
|
||||
|
||||
/**
|
||||
* @var Languages Configuration object.
|
||||
*/
|
||||
protected $object;
|
||||
$this->version = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create configuration object.
|
||||
|
||||
@@ -12,8 +12,8 @@ namespace Grav\Common\Config;
|
||||
use Grav\Common\File\CompiledYamlFile;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Framework\Psr7\ServerRequest;
|
||||
use Pimple\Container;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
|
||||
class Setup extends Data
|
||||
@@ -158,7 +158,7 @@ class Setup extends Data
|
||||
if (\defined('GRAV_CLI')) {
|
||||
static::$environment = 'cli';
|
||||
} else {
|
||||
/** @var ServerRequest $request */
|
||||
/** @var ServerRequestInterface $request */
|
||||
$request = $container['request'];
|
||||
$host = $request->getUri()->getHost();
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace Grav\Common\Data;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Common\Yaml;
|
||||
use RocketTheme\Toolbox\Compat\Yaml\Yaml as FallbackYaml;
|
||||
|
||||
class Validation
|
||||
{
|
||||
@@ -90,7 +89,7 @@ class Validation
|
||||
*/
|
||||
public static function filter($value, array $field)
|
||||
{
|
||||
$validate = isset($field['validate']) ? (array) $field['validate'] : [];
|
||||
$validate = (array)($field['validate'] ?? null);
|
||||
|
||||
// If value isn't required, we will return null if empty value is given.
|
||||
if (($value === null || $value === '') && empty($validate['required'])) {
|
||||
@@ -262,8 +261,8 @@ class Validation
|
||||
*/
|
||||
public static function typeCheckbox($value, array $params, array $field)
|
||||
{
|
||||
$value = (string) $value;
|
||||
$field_value = (string) ($field['value'] ?? '1');
|
||||
$value = (string)$value;
|
||||
$field_value = (string)($field['value'] ?? '1');
|
||||
|
||||
return $value === $field_value;
|
||||
}
|
||||
@@ -304,12 +303,12 @@ class Validation
|
||||
*/
|
||||
public static function typeFile($value, array $params, array $field)
|
||||
{
|
||||
return self::typeArray((array) $value, $params, $field);
|
||||
return self::typeArray((array)$value, $params, $field);
|
||||
}
|
||||
|
||||
protected static function filterFile($value, array $params, array $field)
|
||||
{
|
||||
return (array) $value;
|
||||
return (array)$value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -759,7 +758,7 @@ class Validation
|
||||
|
||||
public static function validateInt($value, $params)
|
||||
{
|
||||
return is_numeric($value) && (int) $value == $value;
|
||||
return is_numeric($value) && (int)$value == $value;
|
||||
}
|
||||
|
||||
protected static function filterInt($value, $params)
|
||||
|
||||
@@ -270,7 +270,7 @@ class Debugger
|
||||
*/
|
||||
public function startTimer($name, $description = null)
|
||||
{
|
||||
if ($name[0] === '_' || $this->enabled()) {
|
||||
if (strpos($name, '_') === 0 || $this->enabled()) {
|
||||
$this->debugbar['time']->startMeasure($name, $description);
|
||||
$this->timers[] = $name;
|
||||
}
|
||||
@@ -287,7 +287,7 @@ class Debugger
|
||||
*/
|
||||
public function stopTimer($name)
|
||||
{
|
||||
if (\in_array($name, $this->timers, true) && ($name[0] === '_' || $this->enabled())) {
|
||||
if (\in_array($name, $this->timers, true) && (strpos($name, '_') === 0 || $this->enabled())) {
|
||||
$this->debugbar['time']->stopMeasure($name);
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ class Debugger
|
||||
*/
|
||||
public function addException(\Exception $e)
|
||||
{
|
||||
if ($this->enabled() && $this->initialized) {
|
||||
if ($this->initialized && $this->enabled()) {
|
||||
$this->debugbar['exceptions']->addException($e);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ class Errors
|
||||
{
|
||||
$grav = Grav::instance();
|
||||
$config = $grav['config']->get('system.errors');
|
||||
$jsonRequest = $_SERVER && isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/json';
|
||||
$jsonRequest = $_SERVER && isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] === 'application/json';
|
||||
|
||||
// Setup Whoops-based error handler
|
||||
$system = new SystemFacade;
|
||||
$whoops = new \Whoops\Run($system);
|
||||
$whoops = new Whoops\Run($system);
|
||||
|
||||
$verbosity = 1;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class SimplePageHandler extends Handler
|
||||
public function __construct()
|
||||
{
|
||||
// Add the default, local resource search path:
|
||||
$this->searchPaths[] = __DIR__ . "/Resources";
|
||||
$this->searchPaths[] = __DIR__ . '/Resources';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,8 +32,8 @@ class SimplePageHandler extends Handler
|
||||
$inspector = $this->getInspector();
|
||||
|
||||
$helper = new TemplateHelper();
|
||||
$templateFile = $this->getResource("layout.html.php");
|
||||
$cssFile = $this->getResource("error.css");
|
||||
$templateFile = $this->getResource('layout.html.php');
|
||||
$cssFile = $this->getResource('error.css');
|
||||
|
||||
$code = $inspector->getException()->getCode();
|
||||
if ( ($code >= 400) && ($code < 600) )
|
||||
@@ -47,9 +47,9 @@ class SimplePageHandler extends Handler
|
||||
}
|
||||
|
||||
$vars = array(
|
||||
"stylesheet" => file_get_contents($cssFile),
|
||||
"code" => $code,
|
||||
"message" => filter_var(rawurldecode($message), FILTER_SANITIZE_STRING),
|
||||
'stylesheet' => file_get_contents($cssFile),
|
||||
'code' => $code,
|
||||
'message' => filter_var(rawurldecode($message), FILTER_SANITIZE_STRING),
|
||||
);
|
||||
|
||||
$helper->setVariables($vars);
|
||||
@@ -75,7 +75,7 @@ class SimplePageHandler extends Handler
|
||||
// Search through available search paths, until we find the
|
||||
// resource we're after:
|
||||
foreach ($this->searchPaths as $path) {
|
||||
$fullPath = $path . "/$resource";
|
||||
$fullPath = "{$path}/{$resource}";
|
||||
|
||||
if (is_file($fullPath)) {
|
||||
// Cache the result:
|
||||
|
||||
@@ -24,6 +24,6 @@ class CompiledJsonFile extends JsonFile
|
||||
*/
|
||||
protected function decode($var, $assoc = true)
|
||||
{
|
||||
return (array) json_decode($var, $assoc);
|
||||
return (array)json_decode($var, $assoc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ abstract class Archiver
|
||||
|
||||
public static function create($compression)
|
||||
{
|
||||
if ($compression == 'zip') {
|
||||
return new ZipArchiver();
|
||||
} else {
|
||||
if ($compression === 'zip') {
|
||||
return new ZipArchiver();
|
||||
}
|
||||
|
||||
return new ZipArchiver();
|
||||
}
|
||||
|
||||
public function setArchive($archive_file)
|
||||
|
||||
@@ -166,7 +166,7 @@ abstract class Folder
|
||||
$path = str_repeat('../', count($baseParts)) . implode('/', $pathParts);
|
||||
|
||||
return '' === $path
|
||||
|| '/' === $path[0]
|
||||
|| strpos($path, '/') === 0
|
||||
|| false !== ($colonPos = strpos($path, ':')) && ($colonPos < ($slashPos = strpos($path, '/')) || false === $slashPos)
|
||||
? "./$path" : $path;
|
||||
}
|
||||
@@ -201,14 +201,14 @@ abstract class Folder
|
||||
}
|
||||
|
||||
$compare = isset($params['compare']) ? 'get' . $params['compare'] : null;
|
||||
$pattern = isset($params['pattern']) ? $params['pattern'] : null;
|
||||
$filters = isset($params['filters']) ? $params['filters'] : null;
|
||||
$recursive = isset($params['recursive']) ? $params['recursive'] : true;
|
||||
$levels = isset($params['levels']) ? $params['levels'] : -1;
|
||||
$pattern = $params['pattern'] ?? null;
|
||||
$filters = $params['filters'] ?? null;
|
||||
$recursive = $params['recursive'] ?? true;
|
||||
$levels = $params['levels'] ?? -1;
|
||||
$key = isset($params['key']) ? 'get' . $params['key'] : null;
|
||||
$value = isset($params['value']) ? 'get' . $params['value'] : ($recursive ? 'getSubPathname' : 'getFilename');
|
||||
$folders = isset($params['folders']) ? $params['folders'] : true;
|
||||
$files = isset($params['files']) ? $params['files'] : true;
|
||||
$value = 'get' . ($params['value'] ?? ($recursive ? 'SubPathname' : 'Filename'));
|
||||
$folders = $params['folders'] ?? true;
|
||||
$files = $params['files'] ?? true;
|
||||
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = Grav::instance()['locator'];
|
||||
@@ -235,7 +235,7 @@ abstract class Folder
|
||||
/** @var \RecursiveDirectoryIterator $file */
|
||||
foreach ($iterator as $file) {
|
||||
// Ignore hidden files.
|
||||
if ($file->getFilename()[0] === '.') {
|
||||
if (strpos($file->getFilename(), '.') === 0) {
|
||||
continue;
|
||||
}
|
||||
if (!$folders && $file->isDir()) {
|
||||
@@ -257,7 +257,7 @@ abstract class Folder
|
||||
if (isset($filters['value'])) {
|
||||
$filter = $filters['value'];
|
||||
if (is_callable($filter)) {
|
||||
$filePath = call_user_func($filter, $file);
|
||||
$filePath = $filter($file);
|
||||
} else {
|
||||
$filePath = preg_replace($filter, '', $filePath);
|
||||
}
|
||||
|
||||
@@ -42,9 +42,6 @@ class RecursiveFolderFilterIterator extends \RecursiveFilterIterator
|
||||
/** @var $current \SplFileInfo */
|
||||
$current = $this->current();
|
||||
|
||||
if ($current->isDir() && !in_array($current->getFilename(), $this::$ignore_folders, true)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return $current->isDir() && !in_array($current->getFilename(), $this::$ignore_folders, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ class CachedCollection extends Iterator {
|
||||
public function __construct($items)
|
||||
{
|
||||
// local cache to speed things up
|
||||
if (!isset(self::$cache[get_called_class().__METHOD__])) {
|
||||
self::$cache[get_called_class().__METHOD__] = $items;
|
||||
if (!isset(self::$cache[get_called_class() . __METHOD__])) {
|
||||
self::$cache[get_called_class() . __METHOD__] = $items;
|
||||
}
|
||||
|
||||
foreach (self::$cache[get_called_class().__METHOD__] as $name => $item) {
|
||||
foreach (self::$cache[get_called_class() . __METHOD__] as $name => $item) {
|
||||
$this->append([$name => $item]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ class Package {
|
||||
|
||||
protected $data;
|
||||
|
||||
public function __construct(Data $package, $type = null) {
|
||||
public function __construct(Data $package, $type = null)
|
||||
{
|
||||
$this->data = $package;
|
||||
|
||||
if ($type) {
|
||||
@@ -23,27 +24,38 @@ class Package {
|
||||
}
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function __get($key) {
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->data->get($key);
|
||||
}
|
||||
|
||||
public function __isset($key) {
|
||||
return isset($this->data->$key);
|
||||
public function __set($key, $value)
|
||||
{
|
||||
throw new $this->data->set($key, $value);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
public function __isset($key)
|
||||
{
|
||||
return isset($this->data->{$key});
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toJson();
|
||||
}
|
||||
|
||||
public function toJson() {
|
||||
public function toJson()
|
||||
{
|
||||
return $this->data->toJson();
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
public function toArray()
|
||||
{
|
||||
return $this->data->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ class GPM extends Iterator
|
||||
continue;
|
||||
}
|
||||
|
||||
$local_version = $plugin->version ? $plugin->version : 'Unknown';
|
||||
$local_version = $plugin->version ?: 'Unknown';
|
||||
$remote_version = $repository[$slug]->version;
|
||||
|
||||
if (version_compare($local_version, $remote_version) < 0) {
|
||||
@@ -565,31 +565,33 @@ class GPM extends Iterator
|
||||
file_exists($source . 'system/config/system.yaml')
|
||||
) {
|
||||
return 'grav';
|
||||
} else {
|
||||
// must have a blueprint
|
||||
if (!file_exists($source . 'blueprints.yaml')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// either theme or plugin
|
||||
$name = basename($source);
|
||||
if (Utils::contains($name, 'theme')) {
|
||||
return 'theme';
|
||||
} elseif (Utils::contains($name, 'plugin')) {
|
||||
return 'plugin';
|
||||
}
|
||||
foreach (glob($source . "*.php") as $filename) {
|
||||
$contents = file_get_contents($filename);
|
||||
if (preg_match($theme_regex, $contents)) {
|
||||
return 'theme';
|
||||
} elseif (preg_match($plugin_regex, $contents)) {
|
||||
return 'plugin';
|
||||
}
|
||||
}
|
||||
// must have a blueprint
|
||||
if (!file_exists($source . 'blueprints.yaml')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Assume it's a theme
|
||||
// either theme or plugin
|
||||
$name = basename($source);
|
||||
if (Utils::contains($name, 'theme')) {
|
||||
return 'theme';
|
||||
}
|
||||
if (Utils::contains($name, 'plugin')) {
|
||||
return 'plugin';
|
||||
}
|
||||
foreach (glob($source . '*.php') as $filename) {
|
||||
$contents = file_get_contents($filename);
|
||||
if (preg_match($theme_regex, $contents)) {
|
||||
return 'theme';
|
||||
}
|
||||
if (preg_match($plugin_regex, $contents)) {
|
||||
return 'plugin';
|
||||
}
|
||||
}
|
||||
|
||||
// Assume it's a theme
|
||||
return 'theme';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -602,7 +604,7 @@ class GPM extends Iterator
|
||||
{
|
||||
$ignore_yaml_files = ['blueprints', 'languages'];
|
||||
|
||||
foreach (glob($source . "*.yaml") as $filename) {
|
||||
foreach (glob($source . '*.yaml') as $filename) {
|
||||
$name = strtolower(basename($filename, '.yaml'));
|
||||
if (in_array($name, $ignore_yaml_files)) {
|
||||
continue;
|
||||
@@ -846,7 +848,7 @@ class GPM extends Iterator
|
||||
$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");
|
||||
throw new \RuntimeException("<red>One of the packages require PHP {$dependencies['php']}. Please update PHP to resolve this");
|
||||
} else {
|
||||
unset($dependencies[$dependency_slug]);
|
||||
continue;
|
||||
@@ -859,7 +861,7 @@ class GPM extends Iterator
|
||||
GRAV_VERSION) === 1
|
||||
) {
|
||||
//Needs a Grav update first
|
||||
throw new \Exception("<red>One of the packages require Grav " . $dependencies['grav'] . ". Please update Grav to the latest release.");
|
||||
throw new \RuntimeException("<red>One of the packages require Grav {$dependencies['grav']}. Please update Grav to the latest release.");
|
||||
} else {
|
||||
unset($dependencies[$dependency_slug]);
|
||||
continue;
|
||||
@@ -889,7 +891,7 @@ class GPM extends Iterator
|
||||
$currentlyInstalledVersion);
|
||||
|
||||
if (!$compatible) {
|
||||
throw new \Exception('Dependency <cyan>' . $dependency_slug . '</cyan> is required in an older version than the one installed. This package must be updated. Please get in touch with its developer.',
|
||||
throw new \RuntimeException('Dependency <cyan>' . $dependency_slug . '</cyan> is required in an older version than the one installed. This package must be updated. Please get in touch with its developer.',
|
||||
2);
|
||||
}
|
||||
}
|
||||
@@ -900,7 +902,7 @@ class GPM extends Iterator
|
||||
|
||||
if ($this->firstVersionIsLower($latestRelease, $dependencyVersion)) {
|
||||
//throw an exception if a required version cannot be found in the GPM yet
|
||||
throw new \Exception('Dependency <cyan>' . $package_yaml['name'] . '</cyan> is required in version <cyan>' . $dependencyVersion . '</cyan> which is higher than the latest release, <cyan>' . $latestRelease . '</cyan>. Try running `bin/gpm -f index` to force a refresh of the GPM cache',
|
||||
throw new \RuntimeException('Dependency <cyan>' . $package_yaml['name'] . '</cyan> is required in version <cyan>' . $dependencyVersion . '</cyan> which is higher than the latest release, <cyan>' . $latestRelease . '</cyan>. Try running `bin/gpm -f index` to force a refresh of the GPM cache',
|
||||
1);
|
||||
}
|
||||
|
||||
@@ -1006,7 +1008,7 @@ class GPM extends Iterator
|
||||
|
||||
$current_package_version_number = $this->calculateVersionNumberFromDependencyVersion($current_package_version_information);
|
||||
if (!$current_package_version_number) {
|
||||
throw new \Exception('Bad format for version of dependency ' . $current_package_name . ' for package ' . $packageName,
|
||||
throw new \RuntimeException('Bad format for version of dependency ' . $current_package_name . ' for package ' . $packageName,
|
||||
1);
|
||||
}
|
||||
|
||||
@@ -1030,7 +1032,7 @@ class GPM extends Iterator
|
||||
$compatible = $this->checkNextSignificantReleasesAreCompatible($currently_stored_version_number,
|
||||
$current_package_version_number);
|
||||
if (!$compatible) {
|
||||
throw new \Exception('Dependency ' . $current_package_name . ' is required in two incompatible versions',
|
||||
throw new \RuntimeException('Dependency ' . $current_package_name . ' is required in two incompatible versions',
|
||||
2);
|
||||
}
|
||||
}
|
||||
@@ -1077,17 +1079,19 @@ class GPM extends Iterator
|
||||
*/
|
||||
public function calculateVersionNumberFromDependencyVersion($version)
|
||||
{
|
||||
if ($version == '*') {
|
||||
if ($version === '*') {
|
||||
return null;
|
||||
} elseif ($version == '') {
|
||||
return null;
|
||||
} elseif ($this->versionFormatIsNextSignificantRelease($version)) {
|
||||
return trim(substr($version, 1));
|
||||
} elseif ($this->versionFormatIsEqualOrHigher($version)) {
|
||||
return trim(substr($version, 2));
|
||||
} else {
|
||||
return $version;
|
||||
}
|
||||
if ($version === '') {
|
||||
return null;
|
||||
}
|
||||
if ($this->versionFormatIsNextSignificantRelease($version)) {
|
||||
return trim(substr($version, 1));
|
||||
}
|
||||
if ($this->versionFormatIsEqualOrHigher($version)) {
|
||||
return trim(substr($version, 2));
|
||||
}
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1101,7 +1105,7 @@ class GPM extends Iterator
|
||||
*/
|
||||
public function versionFormatIsNextSignificantRelease($version)
|
||||
{
|
||||
return substr($version, 0, 1) == '~';
|
||||
return strpos($version, '~') === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1115,7 +1119,7 @@ class GPM extends Iterator
|
||||
*/
|
||||
public function versionFormatIsEqualOrHigher($version)
|
||||
{
|
||||
return substr($version, 0, 2) == '>=';
|
||||
return strpos($version, '>=') === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1136,12 +1140,12 @@ class GPM extends Iterator
|
||||
$version1array = explode('.', $version1);
|
||||
$version2array = explode('.', $version2);
|
||||
|
||||
if (count($version1array) > count($version2array)) {
|
||||
if (\count($version1array) > \count($version2array)) {
|
||||
list($version1array, $version2array) = [$version2array, $version1array];
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
while ($i < count($version1array) - 1) {
|
||||
while ($i < \count($version1array) - 1) {
|
||||
if ($version1array[$i] != $version2array[$i]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -15,23 +15,23 @@ use Grav\Common\Grav;
|
||||
class Installer
|
||||
{
|
||||
/** @const No error */
|
||||
const OK = 0;
|
||||
public const OK = 0;
|
||||
/** @const Target already exists */
|
||||
const EXISTS = 1;
|
||||
public const EXISTS = 1;
|
||||
/** @const Target is a symbolic link */
|
||||
const IS_LINK = 2;
|
||||
public const IS_LINK = 2;
|
||||
/** @const Target doesn't exist */
|
||||
const NOT_FOUND = 4;
|
||||
public const NOT_FOUND = 4;
|
||||
/** @const Target is not a directory */
|
||||
const NOT_DIRECTORY = 8;
|
||||
public const NOT_DIRECTORY = 8;
|
||||
/** @const Target is not a Grav instance */
|
||||
const NOT_GRAV_ROOT = 16;
|
||||
public const NOT_GRAV_ROOT = 16;
|
||||
/** @const Error while trying to open the ZIP package */
|
||||
const ZIP_OPEN_ERROR = 32;
|
||||
public const ZIP_OPEN_ERROR = 32;
|
||||
/** @const Error while trying to extract the ZIP package */
|
||||
const ZIP_EXTRACT_ERROR = 64;
|
||||
public const ZIP_EXTRACT_ERROR = 64;
|
||||
/** @const Invalid source file */
|
||||
const INVALID_SOURCE = 128;
|
||||
public const INVALID_SOURCE = 128;
|
||||
|
||||
/**
|
||||
* Destination folder on which validation checks are applied
|
||||
@@ -190,9 +190,8 @@ class Installer
|
||||
|
||||
$package_folder_name = preg_replace('#\./$#', '', $zip->getNameIndex(0));
|
||||
$zip->close();
|
||||
$extracted_folder = $destination . '/' . $package_folder_name;
|
||||
|
||||
return $extracted_folder;
|
||||
return $destination . '/' . $package_folder_name;
|
||||
}
|
||||
|
||||
self::$error = self::ZIP_EXTRACT_ERROR;
|
||||
@@ -217,7 +216,7 @@ class Installer
|
||||
$install_file = $installer_file_folder . DS . 'install.php';
|
||||
|
||||
if (file_exists($install_file)) {
|
||||
require_once($install_file);
|
||||
require_once $install_file;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -280,10 +279,10 @@ class Installer
|
||||
{
|
||||
if (empty($source_path)) {
|
||||
throw new \RuntimeException("Directory $source_path is missing");
|
||||
} else {
|
||||
Folder::rcopy($source_path, $install_path);
|
||||
}
|
||||
|
||||
Folder::rcopy($source_path, $install_path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -297,7 +296,7 @@ class Installer
|
||||
{
|
||||
foreach (new \DirectoryIterator($source_path) as $file) {
|
||||
|
||||
if ($file->isLink() || $file->isDot() || in_array($file->getFilename(), $ignores)) {
|
||||
if ($file->isLink() || $file->isDot() || \in_array($file->getFilename(), $ignores, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -390,7 +389,7 @@ class Installer
|
||||
return true;
|
||||
}
|
||||
|
||||
return !(self::$error);
|
||||
return !self::$error;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -470,23 +469,23 @@ class Installer
|
||||
if (self::$error_zip) {
|
||||
switch(self::$error_zip) {
|
||||
case \ZipArchive::ER_EXISTS:
|
||||
$msg .= "File already exists.";
|
||||
$msg .= 'File already exists.';
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_INCONS:
|
||||
$msg .= "Zip archive inconsistent.";
|
||||
$msg .= 'Zip archive inconsistent.';
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_MEMORY:
|
||||
$msg .= "Malloc failure.";
|
||||
$msg .= 'Memory allocation failure.';
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_NOENT:
|
||||
$msg .= "No such file.";
|
||||
$msg .= 'No such file.';
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_NOZIP:
|
||||
$msg .= "Not a zip archive.";
|
||||
$msg .= 'Not a zip archive.';
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_OPEN:
|
||||
@@ -494,11 +493,11 @@ class Installer
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_READ:
|
||||
$msg .= "Read error.";
|
||||
$msg .= 'Read error.';
|
||||
break;
|
||||
|
||||
case \ZipArchive::ER_SEEK:
|
||||
$msg .= "Seek error.";
|
||||
$msg .= 'Seek error.';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ class Licenses
|
||||
public static function set($slug, $license)
|
||||
{
|
||||
$licenses = self::getLicenseFile();
|
||||
$data = $licenses->content();
|
||||
$data = (array)$licenses->content();
|
||||
$slug = strtolower($slug);
|
||||
|
||||
if ($license && !self::validate($license)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_string($license)) {
|
||||
if (!\is_string($license)) {
|
||||
if (isset($data['licenses'][$slug])) {
|
||||
unset($data['licenses'][$slug]);
|
||||
} else {
|
||||
@@ -74,19 +74,15 @@ class Licenses
|
||||
public static function get($slug = null)
|
||||
{
|
||||
$licenses = self::getLicenseFile();
|
||||
$data = $licenses->content();
|
||||
$data = (array)$licenses->content();
|
||||
$licenses->free();
|
||||
$slug = strtolower($slug);
|
||||
|
||||
if (!$slug) {
|
||||
return isset($data['licenses']) ? $data['licenses'] : [];
|
||||
return $data['licenses'] ?? [];
|
||||
}
|
||||
|
||||
if (!isset($data['licenses']) || !isset($data['licenses'][$slug])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $data['licenses'][$slug];
|
||||
return $data['licenses'][$slug] ?? '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ class GravCore extends AbstractPackageCollection
|
||||
public function getMinPHPVersion()
|
||||
{
|
||||
// If non min set, assume current PHP version
|
||||
if (is_null($this->min_php)) {
|
||||
if (null === $this->min_php) {
|
||||
$this->min_php = phpversion();
|
||||
}
|
||||
return $this->min_php;
|
||||
|
||||
@@ -12,8 +12,10 @@ namespace Grav\Common\GPM\Remote;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\GPM\Common\Package as BasePackage;
|
||||
|
||||
class Package extends BasePackage {
|
||||
public function __construct($package, $package_type = null) {
|
||||
class Package extends BasePackage
|
||||
{
|
||||
public function __construct($package, $package_type = null)
|
||||
{
|
||||
$data = new Data($package);
|
||||
parent::__construct($data, $package_type);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class Response
|
||||
*/
|
||||
public static function setMethod($method = 'auto')
|
||||
{
|
||||
if (!in_array($method, ['auto', 'curl', 'fopen'])) {
|
||||
if (!\in_array($method, ['auto', 'curl', 'fopen'], true)) {
|
||||
$method = 'auto';
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ class Response
|
||||
$overrides['curl'][CURLOPT_PROXYPORT] = $proxy['port'];
|
||||
}
|
||||
|
||||
if (isset($proxy['user']) && isset($proxy['pass'])) {
|
||||
if (isset($proxy['user'], $proxy['pass'])) {
|
||||
$fopen_auth = $auth = base64_encode($proxy['user'] . ':' . $proxy['pass']);
|
||||
$overrides['curl'][CURLOPT_PROXYUSERPWD] = $proxy['user'] . ':' . $proxy['pass'];
|
||||
$overrides['fopen']['header'] = "Proxy-Authorization: Basic $fopen_auth";
|
||||
@@ -220,7 +220,7 @@ class Response
|
||||
static $filesize = null;
|
||||
|
||||
$args = func_get_args();
|
||||
$isCurlResource = is_resource($args[0]) && get_resource_type($args[0]) == 'curl';
|
||||
$isCurlResource = is_resource($args[0]) && get_resource_type($args[0]) === 'curl';
|
||||
|
||||
$notification_code = !$isCurlResource ? $args[0] : false;
|
||||
$bytes_transferred = $isCurlResource ? $args[2] : $args[4];
|
||||
@@ -242,7 +242,7 @@ class Response
|
||||
];
|
||||
|
||||
if (self::$callback !== null) {
|
||||
call_user_func_array(self::$callback, [$progress]);
|
||||
call_user_func(self::$callback, $progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ class Response
|
||||
*/
|
||||
private static function getFopen()
|
||||
{
|
||||
if (count($args = func_get_args()) == 1) {
|
||||
if (\count($args = func_get_args()) === 1) {
|
||||
$args = $args[0];
|
||||
}
|
||||
|
||||
@@ -308,11 +308,11 @@ class Response
|
||||
|
||||
switch ($code) {
|
||||
case '404':
|
||||
throw new \RuntimeException("Page not found");
|
||||
throw new \RuntimeException('Page not found');
|
||||
case '401':
|
||||
throw new \RuntimeException("Invalid LICENSE");
|
||||
throw new \RuntimeException('Invalid LICENSE');
|
||||
default:
|
||||
throw new \RuntimeException("Error while trying to download (code: $code): $uri \n");
|
||||
throw new \RuntimeException("Error while trying to download (code: {$code}): {$uri}\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ class Response
|
||||
return curl_exec($ch);
|
||||
}
|
||||
|
||||
$max_redirects = isset($options['curl'][CURLOPT_MAXREDIRS]) ? $options['curl'][CURLOPT_MAXREDIRS] : 5;
|
||||
$max_redirects = $options['curl'][CURLOPT_MAXREDIRS] ?? 5;
|
||||
$options['curl'][CURLOPT_FOLLOWLOCATION] = false;
|
||||
|
||||
// open_basedir set but no redirects to follow, we can disable followlocation and proceed normally
|
||||
@@ -406,8 +406,8 @@ class Response
|
||||
if (curl_errno($rch)) {
|
||||
$code = 0;
|
||||
} else {
|
||||
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
|
||||
if ($code == 301 || $code == 302 || $code == 303) {
|
||||
$code = (int)curl_getinfo($rch, CURLINFO_HTTP_CODE);
|
||||
if ($code === 301 || $code === 302 || $code === 303) {
|
||||
preg_match('/Location:(.*?)\n/', $header, $matches);
|
||||
$uri = trim(array_pop($matches));
|
||||
} else {
|
||||
|
||||
@@ -113,7 +113,7 @@ class Upgrader
|
||||
*/
|
||||
public function minPHPVersion()
|
||||
{
|
||||
if (is_null($this->min_php)) {
|
||||
if (null === $this->min_php) {
|
||||
$this->min_php = $this->remote->getMinPHPVersion();
|
||||
}
|
||||
return $this->min_php;
|
||||
@@ -126,7 +126,7 @@ class Upgrader
|
||||
*/
|
||||
public function isUpgradable()
|
||||
{
|
||||
return version_compare($this->getLocalVersion(), $this->getRemoteVersion(), "<");
|
||||
return version_compare($this->getLocalVersion(), $this->getRemoteVersion(), '<');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,9 +74,9 @@ abstract class Getters implements \ArrayAccess, \Countable
|
||||
$var = $this->gettersVariable;
|
||||
|
||||
return isset($this->{$var}[$offset]);
|
||||
} else {
|
||||
return isset($this->{$offset});
|
||||
}
|
||||
|
||||
return isset($this->{$offset});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,10 +89,10 @@ abstract class Getters implements \ArrayAccess, \Countable
|
||||
if ($this->gettersVariable) {
|
||||
$var = $this->gettersVariable;
|
||||
|
||||
return isset($this->{$var}[$offset]) ? $this->{$var}[$offset] : null;
|
||||
} else {
|
||||
return isset($this->{$offset}) ? $this->{$offset} : null;
|
||||
return $this->{$var}[$offset] ?? null;
|
||||
}
|
||||
|
||||
return $this->{$offset} ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,10 +129,10 @@ abstract class Getters implements \ArrayAccess, \Countable
|
||||
{
|
||||
if ($this->gettersVariable) {
|
||||
$var = $this->gettersVariable;
|
||||
count($this->{$var});
|
||||
} else {
|
||||
count($this->toArray());
|
||||
return \count($this->{$var});
|
||||
}
|
||||
|
||||
return \count($this->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,16 +146,16 @@ abstract class Getters implements \ArrayAccess, \Countable
|
||||
$var = $this->gettersVariable;
|
||||
|
||||
return $this->{$var};
|
||||
} else {
|
||||
$properties = (array)$this;
|
||||
$list = [];
|
||||
foreach ($properties as $property => $value) {
|
||||
if ($property[0] != "\0") {
|
||||
$list[$property] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
$properties = (array)$this;
|
||||
$list = [];
|
||||
foreach ($properties as $property => $value) {
|
||||
if ($property[0] !== "\0") {
|
||||
$list[$property] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class Base32
|
||||
*/
|
||||
public static function encode($bytes)
|
||||
{
|
||||
$i = 0; $index = 0; $digit = 0;
|
||||
$i = 0; $index = 0;
|
||||
$base32 = '';
|
||||
$bytesLen = \strlen($bytes);
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ class Excerpts
|
||||
$filename = null;
|
||||
|
||||
if (!empty($url_parts['stream'])) {
|
||||
$filename = $url_parts['scheme'] . '://' . (isset($url_parts['path']) ? $url_parts['path'] : '');
|
||||
$filename = $url_parts['scheme'] . '://' . ($url_parts['path'] ?? '');
|
||||
|
||||
$media = $page->media();
|
||||
|
||||
@@ -248,10 +248,10 @@ class Excerpts
|
||||
$medium = static::processMediaActions($medium, $url_parts);
|
||||
$element_excerpt = $excerpt['element']['attributes'];
|
||||
|
||||
$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'] : '';
|
||||
$alt = $element_excerpt['alt'] ?? '';
|
||||
$title = $element_excerpt['title'] ?? '';
|
||||
$class = $element_excerpt['class'] ?? '';
|
||||
$id = $element_excerpt['id'] ?? '';
|
||||
|
||||
$excerpt['element'] = $medium->parsedownElement($title, $alt, $class, $id, true);
|
||||
|
||||
@@ -284,7 +284,7 @@ class Excerpts
|
||||
if (isset($url_parts['query'])) {
|
||||
$actions = array_reduce(explode('&', $url_parts['query']), function ($carry, $item) {
|
||||
$parts = explode('=', $item, 2);
|
||||
$value = isset($parts[1]) ? $parts[1] : null;
|
||||
$value = $parts[1] ?? null;
|
||||
$carry[] = ['method' => $parts[0], 'params' => $value];
|
||||
|
||||
return $carry;
|
||||
@@ -358,6 +358,10 @@ class Excerpts
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = Grav::instance()['locator'];
|
||||
|
||||
return $locator->isStream($url) ? ($locator->findResource($url, false) ?: $locator->findResource($url, false, true)) : $url;
|
||||
if ($locator->isStream($url)) {
|
||||
return $locator->findResource($url, false) ?: $locator->findResource($url, false, true);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
namespace Grav\Common\Helpers;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use SebastianBergmann\GlobalState\RuntimeException;
|
||||
|
||||
class Exif
|
||||
{
|
||||
|
||||
@@ -44,7 +44,7 @@ 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 words.
|
||||
$words = new DOMWordsIterator($body);
|
||||
@@ -82,9 +82,9 @@ class Truncator {
|
||||
// Return original HTML if not truncated.
|
||||
if ($truncated) {
|
||||
return self::innerHTML($body);
|
||||
} else {
|
||||
return $html;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ class Truncator {
|
||||
* @param string $ellipsis String to use as ellipsis (if any).
|
||||
* @return string Safe truncated HTML.
|
||||
*/
|
||||
public static function truncateLetters($html, $limit = 0, $ellipsis = "")
|
||||
public static function truncateLetters($html, $limit = 0, $ellipsis = '')
|
||||
{
|
||||
if ($limit <= 0) {
|
||||
return $html;
|
||||
@@ -130,9 +130,9 @@ class Truncator {
|
||||
// Return original HTML if not truncated.
|
||||
if ($truncated) {
|
||||
return self::innerHTML($body);
|
||||
} else {
|
||||
return $html;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
namespace Grav\Common;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
|
||||
/**
|
||||
* This file was originally part of the Akelos Framework
|
||||
*/
|
||||
@@ -47,7 +45,7 @@ class Inflector
|
||||
{
|
||||
static::init();
|
||||
|
||||
if ($count == 1) {
|
||||
if ((int)$count === 1) {
|
||||
return $word;
|
||||
}
|
||||
|
||||
@@ -87,7 +85,7 @@ class Inflector
|
||||
{
|
||||
static::init();
|
||||
|
||||
if ($count != 1) {
|
||||
if ((int)$count !== 1) {
|
||||
return $word;
|
||||
}
|
||||
|
||||
@@ -132,7 +130,7 @@ class Inflector
|
||||
*/
|
||||
public static function titleize($word, $uppercase = '')
|
||||
{
|
||||
$uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords';
|
||||
$uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords';
|
||||
|
||||
return $uppercase(static::humanize(static::underscorize($word)));
|
||||
}
|
||||
@@ -216,7 +214,7 @@ class Inflector
|
||||
*/
|
||||
public static function humanize($word, $uppercase = '')
|
||||
{
|
||||
$uppercase = $uppercase == 'all' ? 'ucwords' : 'ucfirst';
|
||||
$uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst';
|
||||
|
||||
return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word)));
|
||||
}
|
||||
@@ -290,21 +288,17 @@ class Inflector
|
||||
|
||||
if (in_array(($number % 100), range(11, 13))) {
|
||||
return $number . static::$ordinals['default'];
|
||||
} else {
|
||||
switch (($number % 10)) {
|
||||
case 1:
|
||||
return $number . static::$ordinals['first'];
|
||||
break;
|
||||
case 2:
|
||||
return $number . static::$ordinals['second'];
|
||||
break;
|
||||
case 3:
|
||||
return $number . static::$ordinals['third'];
|
||||
break;
|
||||
default:
|
||||
return $number . static::$ordinals['default'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($number % 10) {
|
||||
case 1:
|
||||
return $number . static::$ordinals['first'];
|
||||
case 2:
|
||||
return $number . static::$ordinals['second'];
|
||||
case 3:
|
||||
return $number . static::$ordinals['third'];
|
||||
default:
|
||||
return $number . static::$ordinals['default'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +320,7 @@ class Inflector
|
||||
|
||||
// handle years
|
||||
if ($diff->y > 0) {
|
||||
$diff->m = $diff->m + 12 * $diff->y;
|
||||
$diff->m += 12 * $diff->y;
|
||||
}
|
||||
|
||||
return $diff->m;
|
||||
|
||||
@@ -106,7 +106,7 @@ class Language
|
||||
*/
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->active ? $this->active : $this->default;
|
||||
return $this->active ?: $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,7 +315,8 @@ class Language
|
||||
* $this->grav['pages']->init();
|
||||
* ```
|
||||
*/
|
||||
public function resetFallbackPageExtensions() {
|
||||
public function resetFallbackPageExtensions()
|
||||
{
|
||||
$this->page_extensions = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -180,10 +180,7 @@ class LanguageCodes
|
||||
|
||||
public static function isRtl($code)
|
||||
{
|
||||
if (static::getOrientation($code) === 'rtl') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return static::getOrientation($code) === 'rtl';
|
||||
}
|
||||
|
||||
public static function getNames(array $keys)
|
||||
|
||||
@@ -204,7 +204,7 @@ class Collection extends Iterator
|
||||
if ($key instanceof Page) {
|
||||
$key = $key->path();
|
||||
} elseif (null === $key) {
|
||||
$key = key($this->items);
|
||||
$key = (string)key($this->items);
|
||||
}
|
||||
if (!\is_string($key)) {
|
||||
throw new \InvalidArgumentException('Invalid argument $key.');
|
||||
|
||||
@@ -89,21 +89,21 @@ class Media extends AbstractMedia
|
||||
/** @var \DirectoryIterator $info */
|
||||
foreach ($iterator as $path => $info) {
|
||||
// Ignore folders and Markdown files.
|
||||
if (!$info->isFile() || $info->getExtension() === 'md' || $info->getFilename()[0] === '.') {
|
||||
if (!$info->isFile() || $info->getExtension() === 'md' || strpos($info->getFilename(), '.') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find out what type we're dealing with
|
||||
list($basename, $ext, $type, $extra) = $this->getFileParts($info->getFilename());
|
||||
|
||||
if (!in_array(strtolower($ext), $media_types)) {
|
||||
if (!\in_array(strtolower($ext), $media_types, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($type === 'alternative') {
|
||||
$media["{$basename}.{$ext}"][$type][$extra] = [ 'file' => $path, 'size' => $info->getSize() ];
|
||||
$media["{$basename}.{$ext}"][$type][$extra] = ['file' => $path, 'size' => $info->getSize()];
|
||||
} else {
|
||||
$media["{$basename}.{$ext}"][$type] = [ 'file' => $path, 'size' => $info->getSize() ];
|
||||
$media["{$basename}.{$ext}"][$type] = ['file' => $path, 'size' => $info->getSize()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class Media extends AbstractMedia
|
||||
|
||||
if (file_exists($meta_path)) {
|
||||
$types['meta']['file'] = $meta_path;
|
||||
} elseif ($file_path && $medium->get('mime') === 'image/jpeg' && empty($types['meta']) && $config->get('system.media.auto_metadata_exif') && $exif_reader) {
|
||||
} elseif ($file_path && $exif_reader && $medium->get('mime') === 'image/jpeg' && empty($types['meta']) && $config->get('system.media.auto_metadata_exif')) {
|
||||
|
||||
$meta = $exif_reader->read($file_path);
|
||||
|
||||
|
||||
@@ -39,14 +39,12 @@ class AudioMedium extends Medium
|
||||
*/
|
||||
public function controls($display = true)
|
||||
{
|
||||
if($display)
|
||||
{
|
||||
if($display) {
|
||||
$this->attributes['controls'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
unset($this->attributes['controls']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -58,12 +56,12 @@ class AudioMedium extends Medium
|
||||
*/
|
||||
public function preload($preload)
|
||||
{
|
||||
$validPreloadAttrs = array('auto','metadata','none');
|
||||
$validPreloadAttrs = ['auto', 'metadata', 'none'];
|
||||
|
||||
if (in_array($preload, $validPreloadAttrs))
|
||||
{
|
||||
if (\in_array($preload, $validPreloadAttrs, true)) {
|
||||
$this->attributes['preload'] = $preload;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -78,6 +76,7 @@ class AudioMedium extends Medium
|
||||
{
|
||||
$controlsList = str_replace('-', ' ', $controlsList);
|
||||
$this->attributes['controlsList'] = $controlsList;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -89,14 +88,12 @@ class AudioMedium extends Medium
|
||||
*/
|
||||
public function muted($status = false)
|
||||
{
|
||||
if($status)
|
||||
{
|
||||
if($status) {
|
||||
$this->attributes['muted'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
unset($this->attributes['muted']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -108,14 +105,12 @@ class AudioMedium extends Medium
|
||||
*/
|
||||
public function loop($status = false)
|
||||
{
|
||||
if($status)
|
||||
{
|
||||
if($status) {
|
||||
$this->attributes['loop'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
unset($this->attributes['loop']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -127,14 +122,12 @@ class AudioMedium extends Medium
|
||||
*/
|
||||
public function autoplay($status = false)
|
||||
{
|
||||
if($status)
|
||||
{
|
||||
if($status) {
|
||||
$this->attributes['autoplay'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
unset($this->attributes['autoplay']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -149,6 +142,7 @@ class AudioMedium extends Medium
|
||||
parent::reset();
|
||||
|
||||
$this->attributes['controls'] = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +267,8 @@ class ImageMedium extends Medium
|
||||
* @param int [$step=200]
|
||||
* @return $this
|
||||
*/
|
||||
public function derivatives($min_width, $max_width = 2500, $step = 200) {
|
||||
public function derivatives($min_width, $max_width = 2500, $step = 200)
|
||||
{
|
||||
if (!empty($this->alternatives)) {
|
||||
$max = max(array_keys($this->alternatives));
|
||||
$base = $this->alternatives[$max];
|
||||
@@ -347,7 +348,7 @@ class ImageMedium extends Medium
|
||||
$attributes['sizes'] = $this->sizes();
|
||||
}
|
||||
|
||||
return [ 'name' => 'img', 'attributes' => $attributes ];
|
||||
return ['name' => 'img', 'attributes' => $attributes];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -483,10 +484,12 @@ class ImageMedium extends Medium
|
||||
*/
|
||||
public function width($value = 'auto')
|
||||
{
|
||||
if (!$value || $value === 'auto')
|
||||
if (!$value || $value === 'auto') {
|
||||
$this->attributes['width'] = $this->get('width');
|
||||
else
|
||||
} else {
|
||||
$this->attributes['width'] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -504,10 +507,12 @@ class ImageMedium extends Medium
|
||||
*/
|
||||
public function height($value = 'auto')
|
||||
{
|
||||
if (!$value || $value === 'auto')
|
||||
if (!$value || $value === 'auto') {
|
||||
$this->attributes['height'] = $this->get('height');
|
||||
else
|
||||
} else {
|
||||
$this->attributes['height'] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $thumbnailTypes = [ 'page', 'default' ];
|
||||
protected $thumbnailTypes = ['page', 'default'];
|
||||
|
||||
protected $thumbnailType = null;
|
||||
|
||||
@@ -267,7 +267,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
*/
|
||||
public function querystring($querystring = null, $withQuestionmark = true)
|
||||
{
|
||||
if (!is_null($querystring)) {
|
||||
if (null !== $querystring) {
|
||||
$this->medium_querystring[] = ltrim($querystring, '?&');
|
||||
foreach ($this->alternatives as $alt) {
|
||||
$alt->querystring($querystring, $withQuestionmark);
|
||||
@@ -279,11 +279,11 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
}
|
||||
|
||||
// join the strings
|
||||
$querystring = implode("&", $this->medium_querystring);
|
||||
$querystring = implode('&', $this->medium_querystring);
|
||||
// explode all strings
|
||||
$query_parts = explode("&", $querystring);
|
||||
$query_parts = explode('&', $querystring);
|
||||
// Join them again now ensure the elements are unique
|
||||
$querystring = implode("&", array_unique($query_parts));
|
||||
$querystring = implode('&', array_unique($query_parts));
|
||||
|
||||
return $withQuestionmark ? ('?' . $querystring) : $querystring;
|
||||
}
|
||||
@@ -561,7 +561,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
{
|
||||
$classes = func_get_args();
|
||||
if (!empty($classes)) {
|
||||
$this->attributes['class'] = implode(',', (array)$classes);
|
||||
$this->attributes['class'] = implode(',', $classes);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -606,7 +606,7 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$qs = $method;
|
||||
if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) {
|
||||
if (\count($args) > 1 || (\count($args) === 1 && !empty($args[0]))) {
|
||||
$qs .= '=' . implode(',', array_map(function ($a) {
|
||||
if (is_array($a)) {
|
||||
$a = '[' . implode(',', $a) . ']';
|
||||
|
||||
@@ -132,23 +132,17 @@ class MediumFactory
|
||||
switch ($type) {
|
||||
case 'image':
|
||||
return new ImageMedium($items, $blueprint);
|
||||
break;
|
||||
case 'thumbnail':
|
||||
return new ThumbnailImageMedium($items, $blueprint);
|
||||
break;
|
||||
case 'animated':
|
||||
case 'vector':
|
||||
return new StaticImageMedium($items, $blueprint);
|
||||
break;
|
||||
case 'video':
|
||||
return new VideoMedium($items, $blueprint);
|
||||
break;
|
||||
case 'audio':
|
||||
return new AudioMedium($items, $blueprint);
|
||||
break;
|
||||
default:
|
||||
return new Medium($items, $blueprint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ trait ParsedownHtmlTrait
|
||||
/**
|
||||
* @var \Grav\Common\Markdown\Parsedown
|
||||
*/
|
||||
protected $parsedown = null;
|
||||
protected $parsedown;
|
||||
|
||||
/**
|
||||
* Return HTML markup from the medium.
|
||||
|
||||
@@ -24,6 +24,6 @@ class StaticImageMedium extends Medium
|
||||
{
|
||||
empty($attributes['src']) && $attributes['src'] = $this->url($reset);
|
||||
|
||||
return [ 'name' => 'img', 'attributes' => $attributes ];
|
||||
return ['name' => 'img', 'attributes' => $attributes];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace Grav\Common\Page;
|
||||
|
||||
use Exception;
|
||||
use Grav\Common\Cache;
|
||||
use Grav\Common\Config\Config;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
@@ -27,6 +26,7 @@ use Grav\Common\Yaml;
|
||||
use Negotiation\Negotiator;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\File\MarkdownFile;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
|
||||
define('PAGE_ORDER_PREFIX_REGEX', '/^[0-9]+\./u');
|
||||
|
||||
@@ -143,7 +143,7 @@ class Page implements PageInterface
|
||||
|
||||
$this->hide_home_route = $config->get('system.home.hide_in_urls', false);
|
||||
$this->home_route = $this->adjustRouteCase($config->get('system.home.alias'));
|
||||
$this->filePath($file->getPathName());
|
||||
$this->filePath($file->getPathname());
|
||||
$this->modified($file->getMTime());
|
||||
$this->id($this->modified() . md5($this->filePath()));
|
||||
$this->routable(true);
|
||||
@@ -198,7 +198,7 @@ class Page implements PageInterface
|
||||
$aPage = new Page();
|
||||
$aPage->init(new \SplFileInfo($path), $language . '.md');
|
||||
|
||||
$route = isset($aPage->header()->routes['default']) ? $aPage->header()->routes['default'] : $aPage->rawRoute();
|
||||
$route = $aPage->header()->routes['default'] ?? $aPage->rawRoute();
|
||||
if (!$route) {
|
||||
$route = $aPage->route();
|
||||
}
|
||||
@@ -223,7 +223,7 @@ class Page implements PageInterface
|
||||
*/
|
||||
public function untranslatedLanguages($includeUnpublished = false)
|
||||
{
|
||||
$filename = substr($this->name, 0, -(strlen($this->extension())));
|
||||
$filename = substr($this->name, 0, -strlen($this->extension()));
|
||||
$config = Grav::instance()['config'];
|
||||
$languages = $config->get('system.languages.supported', []);
|
||||
$untranslatedLanguages = [];
|
||||
@@ -365,10 +365,10 @@ class Page implements PageInterface
|
||||
|
||||
if ($var) {
|
||||
if (isset($this->header->slug)) {
|
||||
$this->slug(($this->header->slug));
|
||||
$this->slug($this->header->slug);
|
||||
}
|
||||
if (isset($this->header->routes)) {
|
||||
$this->routes = (array)($this->header->routes);
|
||||
$this->routes = (array)$this->header->routes;
|
||||
}
|
||||
if (isset($this->header->title)) {
|
||||
$this->title = trim($this->header->title);
|
||||
@@ -418,7 +418,7 @@ class Page implements PageInterface
|
||||
}
|
||||
}
|
||||
if (isset($this->header->max_count)) {
|
||||
$this->max_count = intval($this->header->max_count);
|
||||
$this->max_count = (int)$this->header->max_count;
|
||||
}
|
||||
if (isset($this->header->process)) {
|
||||
foreach ((array)$this->header->process as $process => $status) {
|
||||
@@ -435,7 +435,7 @@ class Page implements PageInterface
|
||||
$this->unpublishDate($this->header->unpublish_date);
|
||||
}
|
||||
if (isset($this->header->expires)) {
|
||||
$this->expires = intval($this->header->expires);
|
||||
$this->expires = (int)$this->header->expires;
|
||||
}
|
||||
if (isset($this->header->cache_control)) {
|
||||
$this->cache_control = $this->header->cache_control;
|
||||
@@ -612,7 +612,7 @@ class Page implements PageInterface
|
||||
return mb_strimwidth($content, 0, $size, '...', 'utf-8');
|
||||
}
|
||||
|
||||
$summary = Utils::truncateHTML($content, $size);
|
||||
$summary = Utils::truncateHtml($content, $size);
|
||||
|
||||
return html_entity_decode($summary);
|
||||
}
|
||||
@@ -674,13 +674,13 @@ class Page implements PageInterface
|
||||
$process_markdown = $this->shouldProcess('markdown');
|
||||
$process_twig = $this->shouldProcess('twig') || $this->modularTwig();
|
||||
|
||||
$cache_enable = isset($this->header->cache_enable) ? $this->header->cache_enable : $config->get('system.cache.enabled',
|
||||
$cache_enable = $this->header->cache_enable ?? $config->get('system.cache.enabled',
|
||||
true);
|
||||
$twig_first = isset($this->header->twig_first) ? $this->header->twig_first : $config->get('system.pages.twig_first',
|
||||
$twig_first = $this->header->twig_first ?? $config->get('system.pages.twig_first',
|
||||
true);
|
||||
|
||||
// never cache twig means it's always run after content
|
||||
$never_cache_twig = isset($this->header->never_cache_twig) ? $this->header->never_cache_twig : $config->get('system.pages.never_cache_twig',
|
||||
$never_cache_twig = $this->header->never_cache_twig ?? $config->get('system.pages.never_cache_twig',
|
||||
false);
|
||||
|
||||
// if no cached-content run everything
|
||||
@@ -877,9 +877,7 @@ class Page implements PageInterface
|
||||
*/
|
||||
public function setRawContent($content)
|
||||
{
|
||||
$content = $content === null ? '': $content;
|
||||
|
||||
$this->content = $content;
|
||||
$this->content = $content ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1037,10 +1035,10 @@ class Page implements PageInterface
|
||||
$this->_action = 'move';
|
||||
|
||||
if ($this->route() === $parent->route()) {
|
||||
throw new Exception('Failed: Cannot set page parent to self');
|
||||
throw new \RuntimeException('Failed: Cannot set page parent to self');
|
||||
}
|
||||
if (Utils::startsWith($parent->rawRoute(), $this->rawRoute())) {
|
||||
throw new Exception('Failed: Cannot set page parent to a child of current page');
|
||||
throw new \RuntimeException('Failed: Cannot set page parent to a child of current page');
|
||||
}
|
||||
|
||||
$this->parent($parent);
|
||||
@@ -1123,7 +1121,7 @@ class Page implements PageInterface
|
||||
/**
|
||||
* Validate page header.
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
@@ -1465,7 +1463,7 @@ class Page implements PageInterface
|
||||
$this->expires = $var;
|
||||
}
|
||||
|
||||
return !isset($this->expires) ? Grav::instance()['config']->get('system.pages.expires') : $this->expires;
|
||||
return $this->expires ?? Grav::instance()['config']->get('system.pages.expires');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1481,7 +1479,7 @@ class Page implements PageInterface
|
||||
$this->cache_control = $var;
|
||||
}
|
||||
|
||||
return !isset($this->cache_control) ? Grav::instance()['config']->get('system.pages.cache_control') : $this->cache_control;
|
||||
return $this->cache_control ?? Grav::instance()['config']->get('system.pages.cache_control');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1653,11 +1651,7 @@ class Page implements PageInterface
|
||||
*/
|
||||
public function debugger()
|
||||
{
|
||||
if (isset($this->debugger) && $this->debugger === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !(isset($this->debugger) && $this->debugger === false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1772,7 +1766,7 @@ class Page implements PageInterface
|
||||
public function order($var = null)
|
||||
{
|
||||
if ($var !== null) {
|
||||
$order = !empty($var) ? sprintf('%02d.', (int)$var) : '';
|
||||
$order = $var ? sprintf('%02d.', (int)$var) : '';
|
||||
$this->folder($order . preg_replace(PAGE_ORDER_PREFIX_REGEX, '', $this->folder));
|
||||
|
||||
return $order;
|
||||
@@ -1780,7 +1774,7 @@ class Page implements PageInterface
|
||||
|
||||
preg_match(PAGE_ORDER_PREFIX_REGEX, $this->folder, $order);
|
||||
|
||||
return isset($order[0]) ? $order[0] : false;
|
||||
return $order[0] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1914,8 +1908,7 @@ class Page implements PageInterface
|
||||
*/
|
||||
public function unsetRouteSlug()
|
||||
{
|
||||
unset($this->route);
|
||||
unset($this->slug);
|
||||
unset($this->route, $this->slug);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2087,7 +2080,7 @@ class Page implements PageInterface
|
||||
// Folder of the page.
|
||||
$this->folder = basename(dirname($var));
|
||||
// Path to the page.
|
||||
$this->path = dirname(dirname($var));
|
||||
$this->path = dirname($var, 2);
|
||||
}
|
||||
|
||||
return $this->path . '/' . $this->folder . '/' . ($this->name ?: '');
|
||||
@@ -2100,9 +2093,7 @@ class Page implements PageInterface
|
||||
*/
|
||||
public function filePathClean()
|
||||
{
|
||||
$path = str_replace(ROOT_DIR, '', $this->filePath());
|
||||
|
||||
return $path;
|
||||
return str_replace(ROOT_DIR, '', $this->filePath());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2110,9 +2101,7 @@ class Page implements PageInterface
|
||||
*/
|
||||
public function relativePagePath()
|
||||
{
|
||||
$path = str_replace('/' . $this->name(), '', $this->filePathClean());
|
||||
|
||||
return $path;
|
||||
return str_replace('/' . $this->name(), '', $this->filePathClean());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2328,7 +2317,7 @@ class Page implements PageInterface
|
||||
*/
|
||||
public function shouldProcess($process)
|
||||
{
|
||||
return isset($this->process[$process]) ? (bool)$this->process[$process] : false;
|
||||
return (bool)($this->process[$process] ?? false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2485,14 +2474,7 @@ class Page implements PageInterface
|
||||
$uri_path = rtrim(urldecode(Grav::instance()['uri']->path()), '/') ?: '/';
|
||||
$routes = Grav::instance()['pages']->routes();
|
||||
|
||||
if (isset($routes[$uri_path])) {
|
||||
if ($routes[$uri_path] === $this->path()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
return isset($routes[$uri_path]) && $routes[$uri_path] === $this->path();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2532,9 +2514,8 @@ class Page implements PageInterface
|
||||
public function home()
|
||||
{
|
||||
$home = Grav::instance()['config']->get('system.home.alias');
|
||||
$is_home = ($this->route() === $home || $this->rawRoute() === $home);
|
||||
|
||||
return $is_home;
|
||||
return $this->route() === $home || $this->rawRoute() === $home;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2544,11 +2525,7 @@ class Page implements PageInterface
|
||||
*/
|
||||
public function root()
|
||||
{
|
||||
if (!$this->parent && !$this->name && !$this->visible) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return !$this->parent && !$this->name && !$this->visible;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2677,7 +2654,7 @@ class Page implements PageInterface
|
||||
/** @var Config $config */
|
||||
$config = Grav::instance()['config'];
|
||||
|
||||
$process_taxonomy = isset($params['url_taxonomy_filters']) ? $params['url_taxonomy_filters'] : $config->get('system.pages.url_taxonomy_filters');
|
||||
$process_taxonomy = $params['url_taxonomy_filters'] ?? $config->get('system.pages.url_taxonomy_filters');
|
||||
|
||||
if ($process_taxonomy) {
|
||||
foreach ((array)$config->get('site.taxonomies') as $taxonomy) {
|
||||
@@ -2774,17 +2751,17 @@ class Page implements PageInterface
|
||||
}
|
||||
|
||||
if (isset($params['dateRange'])) {
|
||||
$start = isset($params['dateRange']['start']) ? $params['dateRange']['start'] : 0;
|
||||
$end = isset($params['dateRange']['end']) ? $params['dateRange']['end'] : false;
|
||||
$field = isset($params['dateRange']['field']) ? $params['dateRange']['field'] : false;
|
||||
$start = $params['dateRange']['start'] ?? 0;
|
||||
$end = $params['dateRange']['end'] ?? false;
|
||||
$field = $params['dateRange']['field'] ?? false;
|
||||
$collection->dateRange($start, $end, $field);
|
||||
}
|
||||
|
||||
if (isset($params['order'])) {
|
||||
$by = isset($params['order']['by']) ? $params['order']['by'] : 'default';
|
||||
$dir = isset($params['order']['dir']) ? $params['order']['dir'] : 'asc';
|
||||
$custom = isset($params['order']['custom']) ? $params['order']['custom'] : null;
|
||||
$sort_flags = isset($params['order']['sort_flags']) ? $params['order']['sort_flags'] : null;
|
||||
$by = $params['order']['by'] ?? 'default';
|
||||
$dir = $params['order']['dir'] ?? 'asc';
|
||||
$custom = $params['order']['custom'] ?? null;
|
||||
$sort_flags = $params['order']['sort_flags'] ?? null;
|
||||
|
||||
if (is_array($sort_flags)) {
|
||||
$sort_flags = array_map('constant', $sort_flags); //transform strings to constant value
|
||||
@@ -2806,7 +2783,7 @@ class Page implements PageInterface
|
||||
if ($pagination) {
|
||||
$params = $collection->params();
|
||||
|
||||
$limit = isset($params['limit']) ? $params['limit'] : 0;
|
||||
$limit = $params['limit'] ?? 0;
|
||||
$start = !empty($params['pagination']) ? ($uri->currentPage() - 1) * $limit : 0;
|
||||
|
||||
if ($limit && $collection->count() > $limit) {
|
||||
@@ -3132,11 +3109,7 @@ class Page implements PageInterface
|
||||
{
|
||||
$case_insensitive = Grav::instance()['config']->get('system.force_lowercase_urls');
|
||||
|
||||
if ($case_insensitive) {
|
||||
return mb_strtolower($route);
|
||||
} else {
|
||||
return $route;
|
||||
}
|
||||
return $case_insensitive ? mb_strtolower($route) : $route;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -181,7 +181,13 @@ class Pages
|
||||
*/
|
||||
public function baseUrl($lang = null, $absolute = null)
|
||||
{
|
||||
$type = $absolute === null ? 'base_url' : ($absolute ? 'base_url_absolute' : 'base_url_relative');
|
||||
if ($absolute === null) {
|
||||
$type = 'base_url';
|
||||
} elseif ($absolute) {
|
||||
$type = 'base_url_absolute';
|
||||
} else {
|
||||
$type = 'base_url_relative';
|
||||
}
|
||||
|
||||
return $this->grav[$type] . $this->baseRoute($lang);
|
||||
}
|
||||
@@ -311,7 +317,7 @@ class Pages
|
||||
}
|
||||
|
||||
$path = $page->path();
|
||||
$children = isset($this->children[$path]) ? $this->children[$path] : [];
|
||||
$children = $this->children[$path] ?? [];
|
||||
|
||||
if (!$children) {
|
||||
return $children;
|
||||
@@ -372,7 +378,7 @@ class Pages
|
||||
*/
|
||||
public function get($path)
|
||||
{
|
||||
return isset($this->instances[(string)$path]) ? $this->instances[(string)$path] : null;
|
||||
return $this->instances[(string)$path] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,7 +390,7 @@ class Pages
|
||||
*/
|
||||
public function children($path)
|
||||
{
|
||||
$children = isset($this->children[(string)$path]) ? $this->children[(string)$path] : [];
|
||||
$children = $this->children[(string)$path] ?? [];
|
||||
|
||||
return new Collection($children, [], $this);
|
||||
}
|
||||
@@ -500,7 +506,7 @@ class Pages
|
||||
$source_url = $uri->uri(false);
|
||||
|
||||
// Try Regex style redirects
|
||||
$site_redirects = $config->get("site.redirects");
|
||||
$site_redirects = $config->get('site.redirects');
|
||||
if (is_array($site_redirects)) {
|
||||
foreach ((array)$site_redirects as $pattern => $replace) {
|
||||
$pattern = '#^' . str_replace('/', '\/', ltrim($pattern, '^')) . '#';
|
||||
@@ -516,7 +522,7 @@ class Pages
|
||||
}
|
||||
|
||||
// Try Regex style routes
|
||||
$site_routes = $config->get("site.routes");
|
||||
$site_routes = $config->get('site.routes');
|
||||
if (is_array($site_routes)) {
|
||||
foreach ((array)$site_routes as $pattern => $replace) {
|
||||
$pattern = '#^' . str_replace('/', '\/', ltrim($pattern, '^')) . '#';
|
||||
@@ -825,19 +831,18 @@ class Pages
|
||||
$accessLevels = [];
|
||||
foreach ($this->all() as $page) {
|
||||
if (isset($page->header()->access)) {
|
||||
if (is_array($page->header()->access)) {
|
||||
if (\is_array($page->header()->access)) {
|
||||
foreach ($page->header()->access as $index => $accessLevel) {
|
||||
if (is_array($accessLevel)) {
|
||||
if (\is_array($accessLevel)) {
|
||||
foreach ($accessLevel as $innerIndex => $innerAccessLevel) {
|
||||
array_push($accessLevels, $innerIndex);
|
||||
$accessLevels[] = $innerIndex;
|
||||
}
|
||||
} else {
|
||||
array_push($accessLevels, $index);
|
||||
$accessLevels[] = $index;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
array_push($accessLevels, $page->header()->access);
|
||||
$accessLevels[] = $page->header()->access;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1016,13 +1021,10 @@ class Pages
|
||||
/** @var Language $language */
|
||||
$language = $this->grav['language'];
|
||||
|
||||
// stuff to do at root page
|
||||
if ($parent === null) {
|
||||
|
||||
// Fire event for memory and time consuming plugins...
|
||||
if ($config->get('system.pages.events.page')) {
|
||||
$this->grav->fireEvent('onBuildPagesInitialized');
|
||||
}
|
||||
// Stuff to do at root page
|
||||
// Fire event for memory and time consuming plugins...
|
||||
if ($parent === null && $config->get('system.pages.events.page')) {
|
||||
$this->grav->fireEvent('onBuildPagesInitialized');
|
||||
}
|
||||
|
||||
$page->path($directory);
|
||||
@@ -1063,7 +1065,7 @@ class Pages
|
||||
$filename = $file->getFilename();
|
||||
|
||||
// Ignore all hidden files if set.
|
||||
if ($this->ignore_hidden && $filename && $filename[0] === '.') {
|
||||
if ($this->ignore_hidden && $filename && strpos($filename, '.') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1216,9 +1218,10 @@ class Pages
|
||||
}
|
||||
|
||||
// Alias and set default route to home page.
|
||||
if ($home && isset($this->routes['/' . $home])) {
|
||||
$this->routes['/'] = $this->routes['/' . $home];
|
||||
$this->get($this->routes['/' . $home])->route('/');
|
||||
$homeRoute = '/' . $home;
|
||||
if ($home && isset($this->routes[$homeRoute])) {
|
||||
$this->routes['/'] = $this->routes[$homeRoute];
|
||||
$this->get($this->routes[$homeRoute])->route('/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1247,7 +1250,7 @@ class Pages
|
||||
}
|
||||
|
||||
foreach ($pages as $key => $info) {
|
||||
$child = isset($this->instances[$key]) ? $this->instances[$key] : null;
|
||||
$child = $this->instances[$key] ?? null;
|
||||
if (!$child) {
|
||||
throw new \RuntimeException("Page does not exist: {$key}");
|
||||
}
|
||||
|
||||
@@ -136,8 +136,6 @@ class Types implements \ArrayAccess, \Iterator, \Countable
|
||||
$options['value'] = 'Url';
|
||||
}
|
||||
|
||||
$list = Folder::all($uri, $options);
|
||||
|
||||
return $list;
|
||||
return Folder::all($uri, $options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ use Grav\Common\Config\Config;
|
||||
use RocketTheme\Toolbox\Event\EventDispatcher;
|
||||
use RocketTheme\Toolbox\Event\EventSubscriberInterface;
|
||||
use RocketTheme\Toolbox\File\YamlFile;
|
||||
use Symfony\Component\Console\Exception\LogicException;
|
||||
|
||||
class Plugin implements EventSubscriberInterface, \ArrayAccess
|
||||
{
|
||||
@@ -218,22 +217,22 @@ class Plugin implements EventSubscriberInterface, \ArrayAccess
|
||||
*
|
||||
* @param mixed $offset The offset to assign the value to.
|
||||
* @param mixed $value The value to set.
|
||||
* @throws LogicException
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
throw new LogicException(__CLASS__ . ' blueprints cannot be modified.');
|
||||
throw new \LogicException(__CLASS__ . ' blueprints cannot be modified.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets an offset.
|
||||
*
|
||||
* @param mixed $offset The offset to unset.
|
||||
* @throws LogicException
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
throw new LogicException(__CLASS__ . ' blueprints cannot be modified.');
|
||||
throw new \LogicException(__CLASS__ . ' blueprints cannot be modified.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -168,7 +168,7 @@ class Plugins extends Iterator
|
||||
return null;
|
||||
}
|
||||
|
||||
$obj = new Data($file->content(), $blueprint);
|
||||
$obj = new Data((array)$file->content(), $blueprint);
|
||||
|
||||
// Override with user configuration.
|
||||
$obj->merge(Grav::instance()['config']->get('plugins.' . $name) ?: []);
|
||||
|
||||
@@ -45,20 +45,21 @@ namespace Grav\Common\Scheduler;
|
||||
* var_dump($cron->matchWithMargin(new \DateTime('2012-07-01 12:32:50'), -3, 5));
|
||||
* // bool(true)
|
||||
*/
|
||||
class Cron {
|
||||
const TYPE_UNDEFINED = '';
|
||||
const TYPE_MINUTE = 'minute';
|
||||
const TYPE_HOUR = 'hour';
|
||||
const TYPE_DAY = 'day';
|
||||
const TYPE_WEEK = 'week';
|
||||
const TYPE_MONTH = 'month';
|
||||
const TYPE_YEAR = 'year';
|
||||
class Cron
|
||||
{
|
||||
public const TYPE_UNDEFINED = '';
|
||||
public const TYPE_MINUTE = 'minute';
|
||||
public const TYPE_HOUR = 'hour';
|
||||
public const TYPE_DAY = 'day';
|
||||
public const TYPE_WEEK = 'week';
|
||||
public const TYPE_MONTH = 'month';
|
||||
public const TYPE_YEAR = 'year';
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $texts = array(
|
||||
'fr' => array(
|
||||
protected $texts = [
|
||||
'fr' => [
|
||||
'empty' => '-tout-',
|
||||
'name_minute' => 'minute',
|
||||
'name_hour' => 'heure',
|
||||
@@ -72,10 +73,10 @@ class Cron {
|
||||
'text_dow' => 'le %s',
|
||||
'text_month' => 'de %s',
|
||||
'text_dom' => 'le %s',
|
||||
'weekdays' => array('lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'),
|
||||
'months' => array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'),
|
||||
),
|
||||
'en' => array(
|
||||
'weekdays' => ['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'],
|
||||
'months' => ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
|
||||
],
|
||||
'en' => [
|
||||
'empty' => '-all-',
|
||||
'name_minute' => 'minute',
|
||||
'name_hour' => 'hour',
|
||||
@@ -89,10 +90,11 @@ class Cron {
|
||||
'text_dow' => 'on %s',
|
||||
'text_month' => 'of %s',
|
||||
'text_dom' => 'on the %s',
|
||||
'weekdays' => array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'),
|
||||
'months' => array('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'),
|
||||
),
|
||||
);
|
||||
'weekdays' => ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'],
|
||||
'months' => ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* min hour dom month dow
|
||||
* @var string
|
||||
@@ -102,48 +104,52 @@ class Cron {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $minutes = array();
|
||||
protected $minutes = [];
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hours = array();
|
||||
protected $hours = [];
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $months = array();
|
||||
protected $months = [];
|
||||
/**
|
||||
* 0-7 : sunday, monday, ... saturday, sunday
|
||||
* @var array
|
||||
*/
|
||||
protected $dow = array();
|
||||
protected $dow = [];
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dom = array();
|
||||
protected $dom = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $cron
|
||||
*/
|
||||
public function __construct($cron = null) {
|
||||
if (!empty($cron)) {
|
||||
public function __construct($cron = null)
|
||||
{
|
||||
if (null !== $cron) {
|
||||
$this->setCron($cron);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCron() {
|
||||
return implode(' ', array(
|
||||
public function getCron()
|
||||
{
|
||||
return implode(' ', [
|
||||
$this->getCronMinutes(),
|
||||
$this->getCronHours(),
|
||||
$this->getCronDaysOfMonth(),
|
||||
$this->getCronMonths(),
|
||||
$this->getCronDaysOfWeek(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,20 +157,23 @@ class Cron {
|
||||
* @param string $lang 'fr' or 'en'
|
||||
* @return string
|
||||
*/
|
||||
public function getText($lang) {
|
||||
public function getText($lang)
|
||||
{
|
||||
// check lang
|
||||
if (!isset($this->texts[$lang])) {
|
||||
return $this->getCron();
|
||||
}
|
||||
|
||||
$texts = $this->texts[$lang];
|
||||
// check type
|
||||
|
||||
$type = $this->getType();
|
||||
if ($type == self::TYPE_UNDEFINED) {
|
||||
return $this->getCron();
|
||||
}
|
||||
|
||||
// init
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
$elements[] = sprintf($texts['text_period'], $texts['name_' . $type]);
|
||||
|
||||
// hour
|
||||
@@ -207,26 +216,33 @@ class Cron {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType() {
|
||||
$mask = preg_replace('/[^\* ]/si', '-', $this->getCron());
|
||||
$mask = preg_replace('/-+/si', '-', $mask);
|
||||
$mask = preg_replace('/[^-\*]/si', '', $mask);
|
||||
if ($mask == '*****') {
|
||||
public function getType()
|
||||
{
|
||||
$mask = preg_replace('/[^\* ]/', '-', $this->getCron());
|
||||
$mask = preg_replace('/-+/', '-', $mask);
|
||||
$mask = preg_replace('/[^-\*]/', '', $mask);
|
||||
|
||||
if ($mask === '*****') {
|
||||
return self::TYPE_MINUTE;
|
||||
}
|
||||
elseif ($mask == '-****') {
|
||||
|
||||
if ($mask === '-****') {
|
||||
return self::TYPE_HOUR;
|
||||
}
|
||||
elseif (substr($mask, -3) == '***') {
|
||||
|
||||
if (substr($mask, -3) === '***') {
|
||||
return self::TYPE_DAY;
|
||||
}
|
||||
elseif (substr($mask, -3) == '-**') {
|
||||
|
||||
if (substr($mask, -3) === '-**') {
|
||||
return self::TYPE_MONTH;
|
||||
}
|
||||
elseif (substr($mask, -3) == '**-') {
|
||||
|
||||
if (substr($mask, -3) === '**-') {
|
||||
return self::TYPE_WEEK;
|
||||
}
|
||||
elseif (substr($mask, -2) == '-*') {
|
||||
|
||||
if (substr($mask, -2) === '-*') {
|
||||
return self::TYPE_YEAR;
|
||||
}
|
||||
|
||||
@@ -238,14 +254,15 @@ class Cron {
|
||||
* @param string $cron
|
||||
* @return Cron
|
||||
*/
|
||||
public function setCron($cron) {
|
||||
public function setCron($cron)
|
||||
{
|
||||
// sanitize
|
||||
$cron = trim($cron);
|
||||
$cron = preg_replace('/\s+/', ' ', $cron);
|
||||
// explode
|
||||
$elements = explode(' ', $cron);
|
||||
if (count($elements) != 5) {
|
||||
throw new Exception('Bad number of elements');
|
||||
if (\count($elements) !== 5) {
|
||||
throw new \RuntimeException('Bad number of elements');
|
||||
}
|
||||
|
||||
$this->cron = $cron;
|
||||
@@ -262,7 +279,8 @@ class Cron {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCronMinutes() {
|
||||
public function getCronMinutes()
|
||||
{
|
||||
return $this->arrayToCron($this->minutes);
|
||||
}
|
||||
|
||||
@@ -270,7 +288,8 @@ class Cron {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCronHours() {
|
||||
public function getCronHours()
|
||||
{
|
||||
return $this->arrayToCron($this->hours);
|
||||
}
|
||||
|
||||
@@ -278,7 +297,8 @@ class Cron {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCronDaysOfMonth() {
|
||||
public function getCronDaysOfMonth()
|
||||
{
|
||||
return $this->arrayToCron($this->dom);
|
||||
}
|
||||
|
||||
@@ -286,7 +306,8 @@ class Cron {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCronMonths() {
|
||||
public function getCronMonths()
|
||||
{
|
||||
return $this->arrayToCron($this->months);
|
||||
}
|
||||
|
||||
@@ -294,7 +315,8 @@ class Cron {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCronDaysOfWeek() {
|
||||
public function getCronDaysOfWeek()
|
||||
{
|
||||
return $this->arrayToCron($this->dow);
|
||||
}
|
||||
|
||||
@@ -302,7 +324,8 @@ class Cron {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMinutes() {
|
||||
public function getMinutes()
|
||||
{
|
||||
return $this->minutes;
|
||||
}
|
||||
|
||||
@@ -310,7 +333,8 @@ class Cron {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHours() {
|
||||
public function getHours()
|
||||
{
|
||||
return $this->hours;
|
||||
}
|
||||
|
||||
@@ -318,7 +342,8 @@ class Cron {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDaysOfMonth() {
|
||||
public function getDaysOfMonth()
|
||||
{
|
||||
return $this->dom;
|
||||
}
|
||||
|
||||
@@ -326,7 +351,8 @@ class Cron {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMonths() {
|
||||
public function getMonths()
|
||||
{
|
||||
return $this->months;
|
||||
}
|
||||
|
||||
@@ -334,7 +360,8 @@ class Cron {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDaysOfWeek() {
|
||||
public function getDaysOfWeek()
|
||||
{
|
||||
return $this->dow;
|
||||
}
|
||||
|
||||
@@ -343,7 +370,8 @@ class Cron {
|
||||
* @param string|array $minutes
|
||||
* @return Cron
|
||||
*/
|
||||
public function setMinutes($minutes) {
|
||||
public function setMinutes($minutes)
|
||||
{
|
||||
$this->minutes = $this->cronToArray($minutes, 0, 59);
|
||||
|
||||
return $this;
|
||||
@@ -354,7 +382,8 @@ class Cron {
|
||||
* @param string|array $hours
|
||||
* @return Cron
|
||||
*/
|
||||
public function setHours($hours) {
|
||||
public function setHours($hours)
|
||||
{
|
||||
$this->hours = $this->cronToArray($hours, 0, 23);
|
||||
|
||||
return $this;
|
||||
@@ -365,7 +394,8 @@ class Cron {
|
||||
* @param string|array $months
|
||||
* @return Cron
|
||||
*/
|
||||
public function setMonths($months) {
|
||||
public function setMonths($months)
|
||||
{
|
||||
$this->months = $this->cronToArray($months, 1, 12);
|
||||
|
||||
return $this;
|
||||
@@ -376,7 +406,8 @@ class Cron {
|
||||
* @param string|array $dow
|
||||
* @return Cron
|
||||
*/
|
||||
public function setDaysOfWeek($dow) {
|
||||
public function setDaysOfWeek($dow)
|
||||
{
|
||||
$this->dow = $this->cronToArray($dow, 0, 7);
|
||||
|
||||
return $this;
|
||||
@@ -387,7 +418,8 @@ class Cron {
|
||||
* @param string|array $dom
|
||||
* @return Cron
|
||||
*/
|
||||
public function setDaysOfMonth($dom) {
|
||||
public function setDaysOfMonth($dom)
|
||||
{
|
||||
$this->dom = $this->cronToArray($dom, 1, 31);
|
||||
|
||||
return $this;
|
||||
@@ -403,22 +435,23 @@ class Cron {
|
||||
* @param int $weekday
|
||||
* @return \DateTime
|
||||
*/
|
||||
protected function parseDate($date, &$min, &$hour, &$day, &$month, &$weekday) {
|
||||
if (is_numeric($date) && intval($date) == $date) {
|
||||
protected function parseDate($date, &$min, &$hour, &$day, &$month, &$weekday)
|
||||
{
|
||||
if (is_numeric($date) && (int)$date == $date) {
|
||||
$date = new \DateTime('@' . $date);
|
||||
}
|
||||
elseif (is_string($date)) {
|
||||
$date = new \DateTime('@' . strtotime($date));
|
||||
}
|
||||
if ($date instanceof \DateTime) {
|
||||
$min = intval($date->format('i'));
|
||||
$hour = intval($date->format('H'));
|
||||
$day = intval($date->format('d'));
|
||||
$month = intval($date->format('m'));
|
||||
$weekday = intval($date->format('w')); // 0-6
|
||||
$min = (int)$date->format('i');
|
||||
$hour = (int)$date->format('H');
|
||||
$day = (int)$date->format('d');
|
||||
$month = (int)$date->format('m');
|
||||
$weekday = (int)$date->format('w'); // 0-6
|
||||
}
|
||||
else {
|
||||
throw new Exception('Date format not supported');
|
||||
throw new \RuntimeException('Date format not supported');
|
||||
}
|
||||
|
||||
return new \DateTime($date->format('Y-m-d H:i:sP'));
|
||||
@@ -428,7 +461,8 @@ class Cron {
|
||||
*
|
||||
* @param int|string|\Datetime $date
|
||||
*/
|
||||
public function matchExact($date) {
|
||||
public function matchExact($date)
|
||||
{
|
||||
$date = $this->parseDate($date, $min, $hour, $day, $month, $weekday);
|
||||
|
||||
return
|
||||
@@ -446,12 +480,13 @@ class Cron {
|
||||
* @param int $minuteBefore
|
||||
* @param int $minuteAfter
|
||||
*/
|
||||
public function matchWithMargin($date, $minuteBefore = 0, $minuteAfter = 0) {
|
||||
public function matchWithMargin($date, $minuteBefore = 0, $minuteAfter = 0)
|
||||
{
|
||||
if ($minuteBefore > 0) {
|
||||
throw new Exception('MinuteBefore parameter cannot be positive !');
|
||||
throw new \RuntimeException('MinuteBefore parameter cannot be positive !');
|
||||
}
|
||||
if ($minuteAfter < 0) {
|
||||
throw new Exception('MinuteAfter parameter cannot be negative !');
|
||||
throw new \RuntimeException('MinuteAfter parameter cannot be negative !');
|
||||
}
|
||||
|
||||
$date = $this->parseDate($date, $min, $hour, $day, $month, $weekday);
|
||||
@@ -475,17 +510,19 @@ class Cron {
|
||||
* @param array $array
|
||||
* @return string
|
||||
*/
|
||||
protected function arrayToCron($array) {
|
||||
$n = count($array);
|
||||
if (!is_array($array) || $n == 0) {
|
||||
protected function arrayToCron($array)
|
||||
{
|
||||
$n = \count($array);
|
||||
if (!\is_array($array) || $n === 0) {
|
||||
return '*';
|
||||
}
|
||||
$cron = array($array[0]);
|
||||
|
||||
$cron = [$array[0]];
|
||||
$s = $c = $array[0];
|
||||
for ($i = 1; $i < $n; $i++) {
|
||||
if ($array[$i] == $c + 1) {
|
||||
$c = $array[$i];
|
||||
$cron[count($cron) - 1] = $s . '-' . $c;
|
||||
$cron[\count($cron) - 1] = $s . '-' . $c;
|
||||
}
|
||||
else {
|
||||
$s = $c = $array[$i];
|
||||
@@ -503,29 +540,29 @@ class Cron {
|
||||
* @param int $max
|
||||
* @return array
|
||||
*/
|
||||
protected function cronToArray($string, $min, $max) {
|
||||
$array = array();
|
||||
if (is_array($string)) {
|
||||
protected function cronToArray($string, $min, $max)
|
||||
{
|
||||
$array = [];
|
||||
if (\is_array($string)) {
|
||||
foreach ($string as $val) {
|
||||
if (is_numeric($val) && intval($val) == $val && $val >= $min && $val <= $max) {
|
||||
$array[] = intval($val);
|
||||
if (is_numeric($val) && (int)$val == $val && $val >= $min && $val <= $max) {
|
||||
$array[] = (int)$val;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($string !== '*') {
|
||||
while ($string != '') {
|
||||
} elseif ($string !== '*') {
|
||||
while ($string !== '') {
|
||||
// test "*/n" expression
|
||||
if (preg_match('/^\*\/([0-9]+),?/', $string, $m)) {
|
||||
for ($i = max(0, $min); $i <= min(59, $max); $i+=$m[1]) {
|
||||
$array[] = intval($i);
|
||||
for ($i = max(0, $min); $i <= min(59, $max); $i += $m[1]) {
|
||||
$array[] = (int)$i;
|
||||
}
|
||||
$string = substr($string, strlen($m[0]));
|
||||
continue;
|
||||
}
|
||||
// test "a-b/n" expression
|
||||
if (preg_match('/^([0-9]+)-([0-9]+)\/([0-9]+),?/', $string, $m)) {
|
||||
for ($i = max($m[1], $min); $i <= min($m[2], $max); $i+=$m[3]) {
|
||||
$array[] = intval($i);
|
||||
for ($i = max($m[1], $min); $i <= min($m[2], $max); $i += $m[3]) {
|
||||
$array[] = (int)$i;
|
||||
}
|
||||
$string = substr($string, strlen($m[0]));
|
||||
continue;
|
||||
@@ -533,7 +570,7 @@ class Cron {
|
||||
// test "a-b" expression
|
||||
if (preg_match('/^([0-9]+)-([0-9]+),?/', $string, $m)) {
|
||||
for ($i = max($m[1], $min); $i <= min($m[2], $max); $i++) {
|
||||
$array[] = intval($i);
|
||||
$array[] = (int)$i;
|
||||
}
|
||||
$string = substr($string, strlen($m[0]));
|
||||
continue;
|
||||
@@ -541,14 +578,14 @@ class Cron {
|
||||
// test "c" expression
|
||||
if (preg_match('/^([0-9]+),?/', $string, $m)) {
|
||||
if ($m[1] >= $min && $m[1] <= $max) {
|
||||
$array[] = intval($m[1]);
|
||||
$array[] = (int)$m[1];
|
||||
}
|
||||
$string = substr($string, strlen($m[0]));
|
||||
continue;
|
||||
}
|
||||
|
||||
// something goes wrong in the expression
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
sort($array);
|
||||
|
||||
@@ -59,10 +59,10 @@ trait IntervalTrait
|
||||
*/
|
||||
public function daily($hour = 0, $minute = 0)
|
||||
{
|
||||
if (is_string($hour)) {
|
||||
if (\is_string($hour)) {
|
||||
$parts = explode(':', $hour);
|
||||
$hour = $parts[0];
|
||||
$minute = isset($parts[1]) ? $parts[1] : '0';
|
||||
$minute = $parts[1] ?? '0';
|
||||
}
|
||||
$c = $this->validateCronSequence($minute, $hour);
|
||||
|
||||
@@ -79,10 +79,10 @@ trait IntervalTrait
|
||||
*/
|
||||
public function weekly($weekday = 0, $hour = 0, $minute = 0)
|
||||
{
|
||||
if (is_string($hour)) {
|
||||
if (\is_string($hour)) {
|
||||
$parts = explode(':', $hour);
|
||||
$hour = $parts[0];
|
||||
$minute = isset($parts[1]) ? $parts[1] : '0';
|
||||
$minute = $parts[1] ?? '0';
|
||||
}
|
||||
$c = $this->validateCronSequence($minute, $hour, null, null, $weekday);
|
||||
|
||||
@@ -100,10 +100,10 @@ trait IntervalTrait
|
||||
*/
|
||||
public function monthly($month = '*', $day = 1, $hour = 0, $minute = 0)
|
||||
{
|
||||
if (is_string($hour)) {
|
||||
if (\is_string($hour)) {
|
||||
$parts = explode(':', $hour);
|
||||
$hour = $parts[0];
|
||||
$minute = isset($parts[1]) ? $parts[1] : '0';
|
||||
$minute = $parts[1] ?? '0';
|
||||
}
|
||||
$c = $this->validateCronSequence($minute, $hour, $day, $month);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class Job
|
||||
$this->args = $args;
|
||||
// Set enabled state
|
||||
$status = Grav::instance()['config']->get('scheduler.status');
|
||||
$this->enabled = isset($status[$id]) && $status[$id] === 'disabled' ? false : true;
|
||||
$this->enabled = !(isset($status[$id]) && $status[$id] === 'disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,10 +106,11 @@ class Job
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
if (is_string($this->args)) {
|
||||
if (\is_string($this->args)) {
|
||||
return $this->args;
|
||||
}
|
||||
return;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCronExpression()
|
||||
@@ -152,7 +153,9 @@ class Job
|
||||
if (!$this->executionTime) {
|
||||
$this->at('* * * * *');
|
||||
}
|
||||
$date = $date !== null ? $date : $this->creationTime;
|
||||
|
||||
$date = $date ?? $this->creationTime;
|
||||
|
||||
return $this->executionTime->isDue($date);
|
||||
}
|
||||
|
||||
@@ -187,10 +190,7 @@ class Job
|
||||
*/
|
||||
public function runInBackground()
|
||||
{
|
||||
if (is_callable($this->command) || $this->runInBackground === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !(is_callable($this->command) || $this->runInBackground === false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,7 +282,7 @@ class Job
|
||||
$this->output = $this->exec();
|
||||
} else {
|
||||
/** @var Process process */
|
||||
$args = is_string($this->args) ? $this->args : implode(' ', $this->args);
|
||||
$args = \is_string($this->args) ? $this->args : implode(' ', $this->args);
|
||||
$command = $this->command . ' ' . $args;
|
||||
$process = new Process($command);
|
||||
|
||||
@@ -358,7 +358,7 @@ class Job
|
||||
private function createLockFile($content = null)
|
||||
{
|
||||
if ($this->lockFile) {
|
||||
if ($content === null || !is_string($content)) {
|
||||
if ($content === null || !\is_string($content)) {
|
||||
$content = $this->getId();
|
||||
}
|
||||
file_put_contents($this->lockFile, $content);
|
||||
@@ -380,7 +380,7 @@ class Job
|
||||
/**
|
||||
* Execute a callable job.
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \RuntimeException
|
||||
* @return string
|
||||
*/
|
||||
private function exec()
|
||||
@@ -390,7 +390,7 @@ class Job
|
||||
try {
|
||||
$return_data = call_user_func_array($this->command, $this->args);
|
||||
$this->successful = true;
|
||||
} catch (Exception $e) {
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->successful = false;
|
||||
}
|
||||
$this->output = ob_get_clean() . (is_string($return_data) ? $return_data : '');
|
||||
|
||||
@@ -56,7 +56,7 @@ class Scheduler
|
||||
$saved_jobs = (array) Grav::instance()['config']->get('scheduler.custom_jobs', []);
|
||||
|
||||
foreach ($saved_jobs as $id => $j) {
|
||||
$args = isset($j['args']) ? $j['args'] : [];
|
||||
$args = $j['args'] ?? [];
|
||||
$id = Grav::instance()['inflector']->hyphenize($id);
|
||||
$job = $this->addCommand($j['command'], $args, $id);
|
||||
|
||||
@@ -161,7 +161,7 @@ class Scheduler
|
||||
list($background, $foreground) = $this->getQueuedJobs(false);
|
||||
$alljobs = array_merge($background, $foreground);
|
||||
|
||||
if (is_null($runTime)) {
|
||||
if (null === $runTime) {
|
||||
$runTime = new \DateTime('now');
|
||||
}
|
||||
|
||||
@@ -254,19 +254,12 @@ class Scheduler
|
||||
if ($process->isSuccessful()) {
|
||||
$output = $process->getOutput();
|
||||
|
||||
if (preg_match('$bin\/grav schedule$', $output)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
$error = $process->getErrorOutput();
|
||||
if (Utils::startsWith($error, 'crontab: no crontab')) {
|
||||
return 0;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
return preg_match('$bin\/grav schedule$', $output) ? 1 : 0;
|
||||
}
|
||||
|
||||
$error = $process->getErrorOutput();
|
||||
|
||||
return Utils::startsWith($error, 'crontab: no crontab') ? 0 : 2;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,8 +269,7 @@ class Scheduler
|
||||
*/
|
||||
public function getJobStates()
|
||||
{
|
||||
$file = YamlFile::instance($this->status_path . '/status.yaml');
|
||||
return $file;
|
||||
return YamlFile::instance($this->status_path . '/status.yaml');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,7 +334,7 @@ class Scheduler
|
||||
$args = $job->getArguments();
|
||||
// If callable, log the string Closure
|
||||
if (is_callable($command)) {
|
||||
$command = is_string($command) ? $command : 'Closure';
|
||||
$command = \is_string($command) ? $command : 'Closure';
|
||||
}
|
||||
$this->addSchedulerVerboseOutput("<green>Success</green>: <white>{$command} {$args}</white>");
|
||||
|
||||
@@ -361,7 +353,7 @@ class Scheduler
|
||||
$command = $job->getCommand();
|
||||
// If callable, log the string Closure
|
||||
if (is_callable($command)) {
|
||||
$command = is_string($command) ? $command : 'Closure';
|
||||
$command = \is_string($command) ? $command : 'Closure';
|
||||
}
|
||||
$output = trim($job->getOutput());
|
||||
$this->addSchedulerVerboseOutput("<red>Error</red>: <white>{$command}</white> → <normal>{$output}</normal>");
|
||||
|
||||
@@ -59,7 +59,7 @@ class Taxonomy
|
||||
$page_taxonomy = $page->taxonomy();
|
||||
}
|
||||
|
||||
if (!$page->published() || empty($page_taxonomy)) {
|
||||
if (empty($page_taxonomy) || !$page->published()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ class Taxonomy
|
||||
}
|
||||
}
|
||||
|
||||
if (strtolower($operator) == 'or') {
|
||||
if (strtolower($operator) === 'or') {
|
||||
foreach ($matches as $match) {
|
||||
$results = array_merge($results, $match);
|
||||
}
|
||||
@@ -137,14 +137,8 @@ class Taxonomy
|
||||
*
|
||||
* @return array keys of this taxonomy
|
||||
*/
|
||||
public function getTaxonomyItemKeys($taxonomy) {
|
||||
if (isset($this->taxonomy_map[$taxonomy])) {
|
||||
|
||||
$results = array_keys($this->taxonomy_map[$taxonomy]);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
return [];
|
||||
public function getTaxonomyItemKeys($taxonomy)
|
||||
{
|
||||
return isset($this->taxonomy_map[$taxonomy]) ? array_keys($this->taxonomy_map[$taxonomy]) : [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,8 @@ class Theme extends Plugin
|
||||
/**
|
||||
* Override the mergeConfig method to work for themes
|
||||
*/
|
||||
protected function mergeConfig(Page $page, $deep = 'merge', $params = [], $type = 'themes') {
|
||||
protected function mergeConfig(Page $page, $deep = 'merge', $params = [], $type = 'themes')
|
||||
{
|
||||
return parent::mergeConfig($page, $deep, $params, $type);
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ class Themes extends Iterator
|
||||
$blueprint->set('thumbnail', $this->grav['base_url'] . '/' . $path);
|
||||
}
|
||||
|
||||
$obj = new Data($file->content(), $blueprint);
|
||||
$obj = new Data((array)$file->content(), $blueprint);
|
||||
|
||||
// Override with user configuration.
|
||||
$obj->merge($this->config->get('themes.' . $name) ?: []);
|
||||
@@ -250,7 +250,7 @@ class Themes extends Iterator
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($scheme, $registered)) {
|
||||
if (\in_array($scheme, $registered, true)) {
|
||||
stream_wrapper_unregister($scheme);
|
||||
}
|
||||
$type = !empty($config['type']) ? $config['type'] : 'ReadOnlyStream';
|
||||
@@ -290,12 +290,12 @@ class Themes extends Iterator
|
||||
$locator = $this->grav['locator'];
|
||||
|
||||
if ($config->get('system.languages.translations', true)) {
|
||||
$language_file = $locator->findResource("theme://languages" . YAML_EXT);
|
||||
$language_file = $locator->findResource('theme://languages' . YAML_EXT);
|
||||
if ($language_file) {
|
||||
$language = CompiledYamlFile::instance($language_file)->content();
|
||||
$this->grav['languages']->mergeRecursive($language);
|
||||
}
|
||||
$languages_folder = $locator->findResource("theme://languages/");
|
||||
$languages_folder = $locator->findResource('theme://languages');
|
||||
if (file_exists($languages_folder)) {
|
||||
$languages = [];
|
||||
$iterator = new \DirectoryIterator($languages_folder);
|
||||
|
||||
@@ -76,7 +76,7 @@ class Twig
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (!isset($this->twig)) {
|
||||
if (null === $this->twig) {
|
||||
/** @var Config $config */
|
||||
$config = $this->grav['config'];
|
||||
/** @var UniformResourceLocator $locator */
|
||||
@@ -256,7 +256,7 @@ class Twig
|
||||
*/
|
||||
public function processPage(Page $item, $content = null)
|
||||
{
|
||||
$content = $content !== null ? $content : $item->content();
|
||||
$content = $content ?? $item->content();
|
||||
|
||||
// override the twig header vars for local resolution
|
||||
$this->grav->fireEvent('onTwigPageVariables', new Event(['page' => $item]));
|
||||
@@ -266,7 +266,7 @@ class Twig
|
||||
$twig_vars['media'] = $item->media();
|
||||
$twig_vars['header'] = $item->header();
|
||||
|
||||
$local_twig = clone($this->twig);
|
||||
$local_twig = clone $this->twig;
|
||||
|
||||
try {
|
||||
// Process Modular Twig
|
||||
@@ -370,7 +370,7 @@ class Twig
|
||||
$twig_vars['header'] = $page->header();
|
||||
$twig_vars['media'] = $page->media();
|
||||
$twig_vars['content'] = $content;
|
||||
$ext = '.' . ($format ? $format : 'html') . TWIG_EXT;
|
||||
$ext = '.' . ($format ?: 'html') . TWIG_EXT;
|
||||
|
||||
// determine if params are set, if so disable twig cache
|
||||
$params = $this->grav['uri']->params(null, true);
|
||||
@@ -386,7 +386,7 @@ class Twig
|
||||
} catch (\Twig_Error_Loader $e) {
|
||||
$error_msg = $e->getMessage();
|
||||
// Try html version of this template if initial template was NOT html
|
||||
if ($ext != '.html' . TWIG_EXT) {
|
||||
if ($ext !== '.html' . TWIG_EXT) {
|
||||
try {
|
||||
$page->templateFormat('html');
|
||||
$output = $this->twig->render($page->template() . '.html' . TWIG_EXT, $vars + $twig_vars);
|
||||
@@ -431,11 +431,7 @@ class Twig
|
||||
*/
|
||||
public function template($template)
|
||||
{
|
||||
if (isset($this->template)) {
|
||||
return $this->template;
|
||||
} else {
|
||||
return $template;
|
||||
}
|
||||
return $this->template ?? $template;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
public function __construct()
|
||||
{
|
||||
$this->grav = Grav::instance();
|
||||
$this->debugger = isset($this->grav['debugger']) ? $this->grav['debugger'] : null;
|
||||
$this->debugger = $this->grav['debugger'] ?? null;
|
||||
$this->config = $this->grav['config'];
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
}
|
||||
}
|
||||
|
||||
return str_replace( '@', '@', $email );
|
||||
return str_replace('@', '@', $email);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +234,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
*/
|
||||
public function randomizeFilter($original, $offset = 0)
|
||||
{
|
||||
if (!is_array($original)) {
|
||||
if (!\is_array($original)) {
|
||||
return $original;
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
$random = array_slice($original, $offset);
|
||||
shuffle($random);
|
||||
|
||||
$sizeOf = count($original);
|
||||
$sizeOf = \count($original);
|
||||
for ($x = 0; $x < $sizeOf; $x++) {
|
||||
if ($x < $offset) {
|
||||
$sorted[] = $original[$x];
|
||||
@@ -269,19 +269,15 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
*/
|
||||
public function modulusFilter($number, $divider, $items = null)
|
||||
{
|
||||
if (is_string($number)) {
|
||||
if (\is_string($number)) {
|
||||
$number = strlen($number);
|
||||
}
|
||||
|
||||
$remainder = $number % $divider;
|
||||
|
||||
if (is_array($items)) {
|
||||
if (isset($items[$remainder])) {
|
||||
return $items[$remainder];
|
||||
}
|
||||
|
||||
return $items[0];
|
||||
}
|
||||
if (\is_array($items)) {
|
||||
return $items[$remainder] ?? $items[0];
|
||||
}
|
||||
|
||||
return $remainder;
|
||||
}
|
||||
@@ -307,7 +303,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
*/
|
||||
public function inflectorFilter($action, $data, $count = null)
|
||||
{
|
||||
$action = $action . 'ize';
|
||||
$action .= 'ize';
|
||||
|
||||
$inflector = $this->grav['inflector'];
|
||||
|
||||
@@ -316,18 +312,14 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
['titleize', 'camelize', 'underscorize', 'hyphenize', 'humanize', 'ordinalize', 'monthize'],
|
||||
true
|
||||
)) {
|
||||
return $inflector->$action($data);
|
||||
return $inflector->{$action}($data);
|
||||
}
|
||||
|
||||
if (\in_array($action, ['pluralize', 'singularize'], true)) {
|
||||
if ($count) {
|
||||
return $inflector->$action($data, $count);
|
||||
}
|
||||
return $count ? $inflector->{$action}($data, $count) : $inflector->{$action}($data);
|
||||
}
|
||||
|
||||
return $inflector->$action($data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -459,8 +451,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
*/
|
||||
public function cronFunc($at)
|
||||
{
|
||||
$cron = CronExpression::factory($at);
|
||||
return $cron;
|
||||
return CronExpression::factory($at);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,29 +471,29 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
|
||||
if ($long_strings) {
|
||||
$periods = [
|
||||
"NICETIME.SECOND",
|
||||
"NICETIME.MINUTE",
|
||||
"NICETIME.HOUR",
|
||||
"NICETIME.DAY",
|
||||
"NICETIME.WEEK",
|
||||
"NICETIME.MONTH",
|
||||
"NICETIME.YEAR",
|
||||
"NICETIME.DECADE"
|
||||
'NICETIME.SECOND',
|
||||
'NICETIME.MINUTE',
|
||||
'NICETIME.HOUR',
|
||||
'NICETIME.DAY',
|
||||
'NICETIME.WEEK',
|
||||
'NICETIME.MONTH',
|
||||
'NICETIME.YEAR',
|
||||
'NICETIME.DECADE'
|
||||
];
|
||||
} else {
|
||||
$periods = [
|
||||
"NICETIME.SEC",
|
||||
"NICETIME.MIN",
|
||||
"NICETIME.HR",
|
||||
"NICETIME.DAY",
|
||||
"NICETIME.WK",
|
||||
"NICETIME.MO",
|
||||
"NICETIME.YR",
|
||||
"NICETIME.DEC"
|
||||
'NICETIME.SEC',
|
||||
'NICETIME.MIN',
|
||||
'NICETIME.HR',
|
||||
'NICETIME.DAY',
|
||||
'NICETIME.WK',
|
||||
'NICETIME.MO',
|
||||
'NICETIME.YR',
|
||||
'NICETIME.DEC'
|
||||
];
|
||||
}
|
||||
|
||||
$lengths = ["60", "60", "24", "7", "4.35", "12", "10"];
|
||||
$lengths = ['60', '60', '24', '7', '4.35', '12', '10'];
|
||||
|
||||
$now = time();
|
||||
|
||||
@@ -523,7 +514,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
$difference = $now - $unix_date;
|
||||
$tense = $this->grav['language']->translate('GRAV.NICETIME.AGO', null, true);
|
||||
|
||||
} else if ($now == $unix_date) {
|
||||
} elseif ($now == $unix_date) {
|
||||
$difference = $now - $unix_date;
|
||||
$tense = $this->grav['language']->translate('GRAV.NICETIME.JUST_NOW', null, false);
|
||||
|
||||
@@ -553,13 +544,13 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
$periods[$j] = $this->grav['language']->translate('GRAV.'.$periods[$j], null, true);
|
||||
|
||||
if ($now == $unix_date) {
|
||||
return "{$tense}";
|
||||
return $tense;
|
||||
}
|
||||
|
||||
$time = "$difference $periods[$j]";
|
||||
$time = $time . ($show_tense ? " {$tense}" : "");
|
||||
$time = "{$difference} {$periods[$j]}";
|
||||
$time .= $show_tense ? " {$tense}" : '';
|
||||
|
||||
return $time;
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -570,7 +561,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
*/
|
||||
public function xssFunc($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
if (\is_array($data)) {
|
||||
$results = Security::detectXssFromArray($data);
|
||||
} else {
|
||||
return Security::detectXss($data);
|
||||
@@ -580,7 +571,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
return $key.': \''.$value . '\'';
|
||||
}, array_values($results), array_keys($results));
|
||||
|
||||
return implode(', ', $results_parts);
|
||||
return implode(', ', $results_parts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -885,7 +876,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function padFilter($input, $pad_length, $pad_string = " ", $pad_type = STR_PAD_RIGHT)
|
||||
public static function padFilter($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT)
|
||||
{
|
||||
return str_pad($input, (int)$pad_length, $pad_string, $pad_type);
|
||||
}
|
||||
@@ -1053,7 +1044,8 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
* @param int $flags
|
||||
* @return array
|
||||
*/
|
||||
public function regexFilter($array, $regex, $flags = 0) {
|
||||
public function regexFilter($array, $regex, $flags = 0)
|
||||
{
|
||||
return preg_grep($regex, $array, $flags);
|
||||
}
|
||||
|
||||
@@ -1240,7 +1232,8 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
public function themeVarFunc($var, $default = null)
|
||||
{
|
||||
$header = $this->grav['page']->header();
|
||||
$header_classes = isset($header->$var) ? $header->$var : null;
|
||||
$header_classes = $header->{$var} ?? null;
|
||||
|
||||
return $header_classes ?: $this->config->get('theme.' . $var, $default);
|
||||
}
|
||||
|
||||
@@ -1255,7 +1248,7 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
{
|
||||
|
||||
$header = $this->grav['page']->header();
|
||||
$body_classes = isset($header->body_classes) ? $header->body_classes : '';
|
||||
$body_classes = $header->body_classes ?? '';
|
||||
|
||||
foreach ((array)$classes as $class) {
|
||||
if (!empty($body_classes) && Utils::contains($body_classes, $class)) {
|
||||
@@ -1283,20 +1276,20 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
}
|
||||
|
||||
// Make sure pages are an array
|
||||
if (!is_array($pages)) {
|
||||
$pages = array($pages);
|
||||
if (!\is_array($pages)) {
|
||||
$pages = [$pages];
|
||||
}
|
||||
|
||||
// Loop over pages and look for header vars
|
||||
foreach ($pages as $page) {
|
||||
if (is_string($page)) {
|
||||
if (\is_string($page)) {
|
||||
$page = $this->grav['pages']->find($page);
|
||||
}
|
||||
|
||||
if ($page) {
|
||||
$header = $page->header();
|
||||
if (isset($header->$var)) {
|
||||
return $header->$var;
|
||||
if (isset($header->{$var})) {
|
||||
return $header->{$var};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1044,7 +1044,7 @@ class Uri
|
||||
*/
|
||||
public static function addNonce($url, $action, $nonceParamName = 'nonce')
|
||||
{
|
||||
$fake = $url && $url[0] === '/';
|
||||
$fake = $url && strpos($url, '/') === 0;
|
||||
|
||||
if ($fake) {
|
||||
$url = 'http://domain.com' . $url;
|
||||
|
||||
@@ -38,7 +38,7 @@ class Group extends Data
|
||||
$groups = [];
|
||||
|
||||
foreach(static::groups() as $groupname => $group) {
|
||||
$groups[$groupname] = isset($group['readableName']) ? $group['readableName'] : $groupname;
|
||||
$groups[$groupname] = $group['readableName'] ?? $groupname;
|
||||
}
|
||||
|
||||
return $groups;
|
||||
@@ -67,7 +67,7 @@ class Group extends Data
|
||||
{
|
||||
$groups = self::groups();
|
||||
|
||||
$content = isset($groups[$groupname]) ? $groups[$groupname] : [];
|
||||
$content = $groups[$groupname] ?? [];
|
||||
$content += ['groupname' => $groupname];
|
||||
|
||||
$blueprints = new Blueprints;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace Grav\Common;
|
||||
|
||||
use DateTime;
|
||||
use Grav\Common\Helpers\Truncator;
|
||||
use Grav\Common\Page\Page;
|
||||
use Grav\Common\Markdown\Parsedown;
|
||||
@@ -226,9 +225,7 @@ abstract class Utils
|
||||
$startString = mb_substr($original, 0, $position, "UTF-8");
|
||||
$endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8");
|
||||
|
||||
$out = $startString . $replacement . $endString;
|
||||
|
||||
return $out;
|
||||
return $startString . $replacement . $endString;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -320,7 +317,10 @@ abstract class Utils
|
||||
*/
|
||||
public static function arrayIsAssociative($arr)
|
||||
{
|
||||
if (array() === $arr) return false;
|
||||
if ([] === $arr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return array_keys($arr) !== range(0, count($arr) - 1);
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ abstract class Utils
|
||||
*/
|
||||
public static function dateFormats()
|
||||
{
|
||||
$now = new DateTime();
|
||||
$now = new \DateTime();
|
||||
|
||||
$date_formats = [
|
||||
'd-m-Y H:i' => 'd-m-Y H:i (e.g. '.$now->format('d-m-Y H:i').')',
|
||||
@@ -359,7 +359,7 @@ abstract class Utils
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function truncate($string, $limit = 150, $up_to_break = false, $break = " ", $pad = "…")
|
||||
public static function truncate($string, $limit = 150, $up_to_break = false, $break = ' ', $pad = '…')
|
||||
{
|
||||
// return with no change if string is shorter than $limit
|
||||
if (mb_strlen($string) <= $limit) {
|
||||
@@ -735,7 +735,7 @@ abstract class Utils
|
||||
*/
|
||||
public static function normalizePath($path)
|
||||
{
|
||||
$root = ($path[0] === '/') ? '/' : '';
|
||||
$root = strpos($path, '/') === 0 ? '/' : '';
|
||||
|
||||
$segments = explode('/', trim($path, '/'));
|
||||
$ret = [];
|
||||
@@ -762,7 +762,7 @@ abstract class Utils
|
||||
*/
|
||||
public static function isFunctionDisabled($function)
|
||||
{
|
||||
return in_array($function, explode(',', ini_get('disable_functions')), true);
|
||||
return \in_array($function, explode(',', ini_get('disable_functions')), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -774,7 +774,7 @@ abstract class Utils
|
||||
{
|
||||
$timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL);
|
||||
$offsets = [];
|
||||
$testDate = new \DateTime;
|
||||
$testDate = new \DateTime();
|
||||
|
||||
foreach ($timezones as $zone) {
|
||||
$tz = new \DateTimeZone($zone);
|
||||
@@ -830,7 +830,7 @@ abstract class Utils
|
||||
public static function arrayFlatten($array)
|
||||
{
|
||||
$flatten = array();
|
||||
foreach ($array as $key => $inner){
|
||||
foreach ($array as $key => $inner) {
|
||||
if (is_array($inner)) {
|
||||
foreach ($inner as $inner_key => $value) {
|
||||
$flatten[$inner_key] = $value;
|
||||
@@ -853,14 +853,10 @@ abstract class Utils
|
||||
public static function arrayFlattenDotNotation($array, $prepend = '')
|
||||
{
|
||||
$results = array();
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
if (is_array($value))
|
||||
{
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$results = array_merge($results, static::arrayFlattenDotNotation($value, $prepend.$key.'.'));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$results[$prepend.$key] = $value;
|
||||
}
|
||||
}
|
||||
@@ -875,14 +871,17 @@ abstract class Utils
|
||||
* @param string $separator
|
||||
* @return array
|
||||
*/
|
||||
public static function arrayUnflattenDotNotation($array, $separator = '.') {
|
||||
$newArray = array();
|
||||
foreach($array as $key => $value) {
|
||||
public static function arrayUnflattenDotNotation($array, $separator = '.')
|
||||
{
|
||||
$newArray = [];
|
||||
foreach ($array as $key => $value) {
|
||||
$dots = explode($separator, $key);
|
||||
if(count($dots) > 1) {
|
||||
$last = &$newArray[ $dots[0] ];
|
||||
foreach($dots as $k => $dot) {
|
||||
if($k == 0) continue;
|
||||
if (\count($dots) > 1) {
|
||||
$last = &$newArray[$dots[0]];
|
||||
foreach ($dots as $k => $dot) {
|
||||
if ($k === 0) {
|
||||
continue;
|
||||
}
|
||||
$last = &$last[$dot];
|
||||
}
|
||||
$last = $value;
|
||||
@@ -909,7 +908,7 @@ abstract class Utils
|
||||
|
||||
$languages_enabled = Grav::instance()['config']->get('system.languages.supported', []);
|
||||
|
||||
if ($string[0] === '/' && $string[3] === '/' && in_array(substr($string, 1, 2), $languages_enabled)) {
|
||||
if ($string[0] === '/' && $string[3] === '/' && \in_array(substr($string, 1, 2), $languages_enabled, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -931,9 +930,9 @@ abstract class Utils
|
||||
|
||||
// try to use DateTime and default format
|
||||
if ($dateformat) {
|
||||
$datetime = DateTime::createFromFormat($dateformat, $date);
|
||||
$datetime = \DateTime::createFromFormat($dateformat, $date);
|
||||
} else {
|
||||
$datetime = new DateTime($date);
|
||||
$datetime = new \DateTime($date);
|
||||
}
|
||||
|
||||
// fallback to strtotime() if DateTime approach failed
|
||||
@@ -1057,12 +1056,8 @@ abstract class Utils
|
||||
|
||||
//Nonce generated 12-24 hours ago
|
||||
$previousTick = true;
|
||||
if ($nonce === self::getNonce($action, $previousTick)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Invalid nonce
|
||||
return false;
|
||||
return $nonce === self::getNonce($action, $previousTick);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1196,7 +1191,7 @@ abstract class Utils
|
||||
* @param int $sort_flags
|
||||
* @return array
|
||||
*/
|
||||
public static function sortArrayByKey($array, $array_key, $direction = SORT_DESC, $sort_flags = SORT_REGULAR )
|
||||
public static function sortArrayByKey($array, $array_key, $direction = SORT_DESC, $sort_flags = SORT_REGULAR)
|
||||
{
|
||||
$output = [];
|
||||
|
||||
@@ -1295,13 +1290,14 @@ abstract class Utils
|
||||
* @return integer Returns only the number of units, not the type letter. Returns 0 if the $to unit type is out of scope.
|
||||
*
|
||||
*/
|
||||
public static function convertSize($bytes, $to, $decimal_places = 1) {
|
||||
public static function convertSize($bytes, $to, $decimal_places = 1)
|
||||
{
|
||||
$formulas = array(
|
||||
'K' => number_format($bytes / 1024, $decimal_places),
|
||||
'M' => number_format($bytes / 1048576, $decimal_places),
|
||||
'G' => number_format($bytes / 1073741824, $decimal_places)
|
||||
);
|
||||
return isset($formulas[$to]) ? $formulas[$to] : 0;
|
||||
return $formulas[$to] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1311,7 +1307,8 @@ abstract class Utils
|
||||
* @param int $precision
|
||||
* @return string
|
||||
*/
|
||||
public static function prettySize($bytes, $precision = 2) {
|
||||
public static function prettySize($bytes, $precision = 2)
|
||||
{
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
|
||||
$bytes = max($bytes, 0);
|
||||
|
||||
@@ -103,7 +103,7 @@ class BackupCommand extends ConsoleCommand
|
||||
switch ($args['type']) {
|
||||
case 'count':
|
||||
$steps = $args['steps'];
|
||||
$freq = intval($steps > 100 ? round($steps / 100) : $steps);
|
||||
$freq = (int)($steps > 100 ? round($steps / 100) : $steps);
|
||||
$this->progress->setMaxSteps($steps);
|
||||
$this->progress->setRedrawFrequency($freq);
|
||||
$this->progress->setMessage('Adding files...');
|
||||
|
||||
@@ -190,7 +190,7 @@ class IndexCommand extends ConsoleCommand
|
||||
*/
|
||||
private function installed($package)
|
||||
{
|
||||
$package = isset($list[$package->slug]) ? $list[$package->slug] : $package;
|
||||
$package = $list[$package->slug] ?? $package;
|
||||
$type = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
$method = 'is' . $type . 'Installed';
|
||||
$installed = $this->gpm->{$method}($package->slug);
|
||||
|
||||
Reference in New Issue
Block a user