mirror of
https://github.com/getgrav/grav.git
synced 2026-07-04 16:07:49 +02:00
Merge branch 'develop' into feature/gpm
This commit is contained in:
@@ -40,8 +40,7 @@ schemes:
|
||||
paths:
|
||||
- user/data
|
||||
|
||||
theme:
|
||||
themes:
|
||||
type: ReadOnlyStream
|
||||
prefixes:
|
||||
'/':
|
||||
- user/themes
|
||||
paths:
|
||||
- user/themes
|
||||
|
||||
@@ -47,3 +47,5 @@ debugger:
|
||||
log:
|
||||
enabled: true # Enable logging
|
||||
timing: false # Enable timing logging
|
||||
shutdown:
|
||||
close_connection: true # Close the connection before calling onShutdown(). disable for debugging
|
||||
|
||||
@@ -54,12 +54,17 @@ class Grav extends Container
|
||||
|
||||
$container['grav'] = $container;
|
||||
|
||||
$container['events'] = function ($c) {
|
||||
return new EventDispatcher;
|
||||
};
|
||||
$container['uri'] = function ($c) {
|
||||
return new Uri($c);
|
||||
};
|
||||
|
||||
$container['task'] = function ($c) {
|
||||
return !empty($_POST['task']) ? $_POST['task'] : $c['uri']->param('task');
|
||||
};
|
||||
|
||||
$container['events'] = function ($c) {
|
||||
return new EventDispatcher;
|
||||
};
|
||||
$container['config'] = function ($c) {
|
||||
return Config::instance($c);
|
||||
};
|
||||
@@ -122,6 +127,15 @@ class Grav extends Container
|
||||
|
||||
$this->fireEvent('onPluginsInitialized');
|
||||
|
||||
$this['themes']->init();
|
||||
|
||||
$this->fireEvent('onThemeInitialized');
|
||||
|
||||
$task = $this['task'];
|
||||
if ($task) {
|
||||
$this->fireEvent('onTask.' . $task);
|
||||
}
|
||||
|
||||
$this['assets']->init();
|
||||
|
||||
$this->fireEvent('onAssetsInitialized');
|
||||
@@ -215,17 +229,18 @@ class Grav extends Container
|
||||
*/
|
||||
public function shutdown()
|
||||
{
|
||||
set_time_limit(0);
|
||||
ignore_user_abort(true);
|
||||
if($this['config']->get('system.debugger.shutdown.close_connection')) {
|
||||
set_time_limit(0);
|
||||
ignore_user_abort(true);
|
||||
session_write_close();
|
||||
|
||||
header('Content-length: ' . ob_get_length());
|
||||
header("Connection: close\r\n");
|
||||
header('Content-length: ' . ob_get_length());
|
||||
header("Connection: close\r\n");
|
||||
|
||||
ob_end_flush();
|
||||
ob_flush();
|
||||
flush();
|
||||
|
||||
session_write_close();
|
||||
ob_end_flush();
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
|
||||
$this->fireEvent('onShutdown');
|
||||
}
|
||||
|
||||
@@ -60,14 +60,6 @@ class Plugins extends Iterator
|
||||
}
|
||||
}
|
||||
|
||||
/** @var Themes $themes */
|
||||
$themes = $this->grav['themes'];
|
||||
$themes->configure();
|
||||
$instance = $themes->load();
|
||||
if ($instance instanceof EventSubscriberInterface) {
|
||||
$events->addSubscriber($instance);
|
||||
}
|
||||
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<?php
|
||||
namespace Grav\Common;
|
||||
|
||||
use Grav\Common\Data\Blueprints;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Filesystem\File;
|
||||
use Grav\Component\EventDispatcher\EventDispatcher;
|
||||
use Grav\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Grav\Component\Filesystem\ResourceLocator;
|
||||
|
||||
/**
|
||||
@@ -12,23 +16,44 @@ use Grav\Component\Filesystem\ResourceLocator;
|
||||
*/
|
||||
class Themes extends Iterator
|
||||
{
|
||||
/** @var Grav */
|
||||
protected $grav;
|
||||
|
||||
/** @var Config */
|
||||
protected $config;
|
||||
|
||||
public function __construct(Grav $grav) {
|
||||
public function __construct(Grav $grav)
|
||||
{
|
||||
$this->grav = $grav;
|
||||
$this->config = $grav['config'];
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
/** @var EventDispatcher $events */
|
||||
$events = $this->grav['events'];
|
||||
|
||||
/** @var Themes $themes */
|
||||
$themes = $this->grav['themes'];
|
||||
$themes->configure();
|
||||
$instance = $themes->load();
|
||||
|
||||
if ($instance instanceof EventSubscriberInterface) {
|
||||
$events->addSubscriber($instance);
|
||||
}
|
||||
|
||||
$this->grav['theme'] = $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of all theme data with their blueprints.
|
||||
*
|
||||
* @return array|Data[]
|
||||
* @return array
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$list = array();
|
||||
$iterator = new \DirectoryIterator('theme:///');
|
||||
$iterator = new \DirectoryIterator('themes://');
|
||||
|
||||
/** @var \DirectoryIterator $directory */
|
||||
foreach ($iterator as $directory) {
|
||||
@@ -46,7 +71,7 @@ class Themes extends Iterator
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme or throw exception if it cannot be found.
|
||||
* Get theme configuration or throw exception if it cannot be found.
|
||||
*
|
||||
* @param string $name
|
||||
* @return Data
|
||||
@@ -58,20 +83,20 @@ class Themes extends Iterator
|
||||
throw new \RuntimeException('Theme name not provided.');
|
||||
}
|
||||
|
||||
$blueprints = new Data\Blueprints("theme:///{$name}");
|
||||
$blueprints = new Blueprints("themes://{$name}");
|
||||
$blueprint = $blueprints->get('blueprints');
|
||||
$blueprint->name = $name;
|
||||
|
||||
// Find thumbnail.
|
||||
$thumb = "theme:///{$name}/thumbnail.jpg";
|
||||
$thumb = "themes://{$name}/thumbnail.jpg";
|
||||
|
||||
if (file_exists($thumb)) {
|
||||
$blueprint->set('thumbnail', $this->config->get('system.base_url_relative') . "/user/themes/{$name}/thumbnail.jpg");
|
||||
}
|
||||
|
||||
// Load default configuration.
|
||||
$file = File\Yaml::instance("theme:///{$name}/{$name}" . YAML_EXT);
|
||||
$obj = new Data\Data($file->content(), $blueprint);
|
||||
$file = File\Yaml::instance("themes://{$name}/{$name}" . YAML_EXT);
|
||||
$obj = new Data($file->content(), $blueprint);
|
||||
|
||||
// Override with user configuration.
|
||||
$file = File\Yaml::instance("user://config/themes/{$name}" . YAML_EXT);
|
||||
@@ -83,52 +108,64 @@ class Themes extends Iterator
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function current($name = null)
|
||||
/**
|
||||
* Return name of the current theme.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
|
||||
if (!$name) {
|
||||
$name = $this->config->get('system.pages.theme');
|
||||
}
|
||||
|
||||
return $name;
|
||||
return (string) $this->config->get('system.pages.theme');
|
||||
}
|
||||
|
||||
function load($name = null)
|
||||
/**
|
||||
* Load current theme.
|
||||
*
|
||||
* @return Theme|object
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$name = $this->current($name);
|
||||
// NOTE: ALL THE LOCAL VARIABLES ARE USED INSIDE INCLUDED FILE, DO NOT REMOVE THEM!
|
||||
$grav = $this->grav;
|
||||
$config = $this->config;
|
||||
$name = $this->current();
|
||||
|
||||
/** @var ResourceLocator $locator */
|
||||
$locator = $grav['locator'];
|
||||
|
||||
$file = $locator("theme://theme.php") ?: $locator("theme://{$name}.php");
|
||||
|
||||
if ($file) {
|
||||
// Local variables available in the file: $grav, $config, $name, $path, $file
|
||||
// Local variables available in the file: $grav, $config, $name, $file
|
||||
$class = include $file;
|
||||
|
||||
if (!is_object($class)) {
|
||||
$className = '\\Grav\\Theme\\' . ucfirst($name);
|
||||
|
||||
if (class_exists($className)) {
|
||||
$class = new $className($grav, $this->config, $name);
|
||||
$class = new $className($grav, $config, $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($class)) {
|
||||
$class = new Theme($grav, $this->config, $name);
|
||||
$class = new Theme($grav, $config, $name);
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
public function configure($name = null) {
|
||||
$name = $this->current($name);
|
||||
/**
|
||||
* Configure and prepare streams for current template.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function configure() {
|
||||
$name = $this->current();
|
||||
|
||||
/** @var Config $config */
|
||||
$config = $this->config;
|
||||
|
||||
$themeConfig = File\Yaml::instance("theme://{$name}/{$name}" . YAML_EXT)->content();
|
||||
$themeConfig = File\Yaml::instance("themes://{$name}/{$name}" . YAML_EXT)->content();
|
||||
|
||||
$config->merge(['themes' => [$name => $themeConfig]]);
|
||||
|
||||
@@ -163,7 +200,6 @@ class Themes extends Iterator
|
||||
if (!stream_wrapper_register($scheme, $type)) {
|
||||
throw new \InvalidArgumentException("Stream '{$type}' could not be initialized.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ class Twig
|
||||
|
||||
// Set some standard variables for twig
|
||||
$this->twig_vars = array(
|
||||
'grav' => $this->grav,
|
||||
'grav_version' => GRAV_VERSION,
|
||||
'config' => $config,
|
||||
'uri' => $this->grav['uri'],
|
||||
|
||||
@@ -213,6 +213,6 @@ class TwigExtension extends \Twig_Extension
|
||||
/** @var Uri $uri */
|
||||
$uri = $grav['uri'];
|
||||
|
||||
return $uri->rootUrl($domain) . $locator->findResource($input, false);
|
||||
return $uri->rootUrl($domain) .'/'. $locator->findResource($input, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,4 +301,30 @@ class Uri
|
||||
// Return relative path.
|
||||
return substr($referrer, strlen($root));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrun the IP address of the current user
|
||||
*
|
||||
* @return string ip address
|
||||
*/
|
||||
public function ip()
|
||||
{
|
||||
$ipaddress = '';
|
||||
if (getenv('HTTP_CLIENT_IP'))
|
||||
$ipaddress = getenv('HTTP_CLIENT_IP');
|
||||
else if(getenv('HTTP_X_FORWARDED_FOR'))
|
||||
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
|
||||
else if(getenv('HTTP_X_FORWARDED'))
|
||||
$ipaddress = getenv('HTTP_X_FORWARDED');
|
||||
else if(getenv('HTTP_FORWARDED_FOR'))
|
||||
$ipaddress = getenv('HTTP_FORWARDED_FOR');
|
||||
else if(getenv('HTTP_FORWARDED'))
|
||||
$ipaddress = getenv('HTTP_FORWARDED');
|
||||
else if(getenv('REMOTE_ADDR'))
|
||||
$ipaddress = getenv('REMOTE_ADDR');
|
||||
else
|
||||
$ipaddress = 'UNKNOWN';
|
||||
return $ipaddress;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user