Skip to content

Commit

Permalink
Merge branch 'release/1.6.21'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 12, 2020
2 parents e507300 + 432b4b1 commit addecbb
Show file tree
Hide file tree
Showing 15 changed files with 302 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ indent_style = space
indent_size = 4

# 2 space indentation
[*.{yaml,.yml}]
[*.{yaml,yml}]
indent_size = 2
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# v1.6.21
## 02/11/2020

1. [](#new)
* Added `ConsoleCommand::setLanguage()` method to set language to be used from CLI
* Added `ConsoleCommand::initializeGrav()` method to properly set up Grav instance to be used from CLI
* Added `ConsoleCommand::initializePlugins()`method to properly set up all plugins to be used from CLI
* Added `ConsoleCommand::initializeThemes()`method to properly set up current theme to be used from CLI
* Added `ConsoleCommand::initializePages()` method to properly set up pages to be used from CLI
1. [](#improved)
* Vendor updates
1. [](#bugfix)
* Fixed `bin/plugin` CLI calling `$themes->init()` way too early (removed it, use above methods instead)
* Fixed call to `$grav['page']` crashing CLI
* Fixed encoding problems when PHP INI setting `default_charset` is not `utf-8` [#2154](https://github.com/getgrav/grav/issues/2154)

# v1.6.20
## 03/02/2020
## 02/03/2020

1. [](#bugfix)
* Fixed incorrect routing caused by `str_replace()` in `Uri::init()` [#2754](https://github.com/getgrav/grav/issues/2754)
Expand Down
9 changes: 8 additions & 1 deletion bin/gpm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}

// Set internal encoding.
if (!\extension_loaded('mbstring')) {
die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
}
@ini_set('default_charset', 'UTF-8');
mb_internal_encoding('UTF-8');

if (!file_exists(GRAV_ROOT . '/index.php')) {
exit('FATAL: Must be run from ROOT directory of Grav!');
}
Expand Down Expand Up @@ -55,7 +62,7 @@ $grav->setup($environment);

$grav['config']->init();
$grav['uri']->init();
$grav['users'];
$grav['accounts'];

$app = new Application('Grav Package Manager', GRAV_VERSION);
$app->addCommands(array(
Expand Down
15 changes: 11 additions & 4 deletions bin/grav
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
}

if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}

// Set internal encoding.
if (!\extension_loaded('mbstring')) {
die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
}
@ini_set('default_charset', 'UTF-8');
mb_internal_encoding('UTF-8');

$climate = new League\CLImate\CLImate;
$climate->arguments->add([
'environment' => [
Expand All @@ -42,10 +53,6 @@ $environment = $climate->arguments->get('environment');
$grav = Grav::instance(array('loader' => $autoload));
$grav->setup($environment);

if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}

if (!file_exists(GRAV_ROOT . '/index.php')) {
exit('FATAL: Must be run from ROOT directory of Grav!');
}
Expand Down
14 changes: 8 additions & 6 deletions bin/plugin
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}

// Set internal encoding.
if (!\extension_loaded('mbstring')) {
die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
}
@ini_set('default_charset', 'UTF-8');
mb_internal_encoding('UTF-8');

if (!file_exists(GRAV_ROOT . '/index.php')) {
exit('FATAL: Must be run from ROOT directory of Grav!');
}
Expand All @@ -51,12 +58,7 @@ $environment = $climate->arguments->get('environment');

$grav = Grav::instance(array('loader' => $autoload));
$grav->setup($environment);

$grav['config']->init();
$grav['uri']->init();
$grav['users'];
$grav['plugins']->init();
$grav['themes']->init();
$grav->initializeCli();

$app = new Application('Grav Plugins Commands', GRAV_VERSION);
$pattern = '([A-Z]\w+Command\.php)';
Expand Down
38 changes: 18 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
die("PHP webserver requires a router to run Grav, please use: <pre>php -S {$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']} system/router.php</pre>");
}

// Set timezone to default, falls back to system if php.ini not set
date_default_timezone_set(@date_default_timezone_get());

// Set internal encoding.
if (!\extension_loaded('mbstring')) {
die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
}
@ini_set('default_charset', 'UTF-8');
mb_internal_encoding('UTF-8');

// Ensure vendor libraries exist
$autoload = __DIR__ . '/vendor/autoload.php';
if (!is_file($autoload)) {
Expand All @@ -32,15 +42,6 @@
use Grav\Common\Grav;
use RocketTheme\Toolbox\Event\Event;

// Set timezone to default, falls back to system if php.ini not set
date_default_timezone_set(@date_default_timezone_get());

// Set internal encoding if mbstring loaded
if (!\extension_loaded('mbstring')) {
die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
}
mb_internal_encoding('UTF-8');

// Get the Grav instance
$grav = Grav::instance(
array(
Expand Down
2 changes: 1 addition & 1 deletion system/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Some standard defines
define('GRAV', true);
define('GRAV_VERSION', '1.6.20');
define('GRAV_VERSION', '1.6.21');
define('GRAV_TESTING', false);
define('DS', '/');

Expand Down
23 changes: 23 additions & 0 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ public function setup(string $environment = null)
return $this;
}

/**
* Initialize CLI environment.
*
* Call after `$grav->setup($environment)`
*
* - Load configuration
* - Disable debugger
* - Set timezone, locale
* - Load plugins
* - Set Users type to be used in the site
*
* This method WILL NOT initialize assets, twig or pages.
*
* @param string|null $environment
* @return $this
*/
public function initializeCli()
{
InitializeProcessor::initializeCli($this);

return $this;
}

/**
* Process a request
*/
Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,12 @@ public function summary($size = null, $textOnly = false)
return $content;
}

return mb_strimwidth($content, 0, $size, '...', 'utf-8');
return mb_strimwidth($content, 0, $size, '...', 'UTF-8');
}

$summary = Utils::truncateHtml($content, $size);

return html_entity_decode($summary);
return html_entity_decode($summary, ENT_COMPAT | ENT_HTML401, 'UTF-8');
}

/**
Expand Down
48 changes: 48 additions & 0 deletions system/src/Grav/Common/Processors/InitializeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Grav\Common\Processors;

use Grav\Common\Config\Config;
use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Utils;
use Grav\Framework\Session\Exceptions\SessionException;
Expand All @@ -22,6 +23,22 @@ class InitializeProcessor extends ProcessorBase
public $id = 'init';
public $title = 'Initialize';

/** @var bool */
private static $cli_initialized = false;

/**
* @param Grav $grav
*/
public static function initializeCli(Grav $grav)
{
if (!static::$cli_initialized) {
static::$cli_initialized = true;

$instance = new static($grav);
$instance->processCli();
}
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
{
$this->startTimer();
Expand Down Expand Up @@ -77,4 +94,35 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

return $handler->handle($request);
}

public function processCli(): void
{
// Load configuration.
$this->container['config']->init();
$this->container['plugins']->setup();

// Disable debugger.
$this->container['debugger']->enabled(false);

// Set timezone, locale.
/** @var Config $config */
$config = $this->container['config'];
$timezone = $config->get('system.timezone');
if ($timezone) {
date_default_timezone_set($timezone);
}
$this->container->setLocale();

// Load plugins.
$this->container['plugins']->init();

// Initialize URI.
/** @var Uri $uri */
$uri = $this->container['uri'];
$uri->init();

// Load accounts.
// TODO: remove in 2.0.
$this->container['accounts'];
}
}
Loading

0 comments on commit addecbb

Please sign in to comment.