From 523b6376bb2deee9e37b51a6f8acbace848e2498 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 12 Oct 2014 13:49:20 -0600 Subject: [PATCH 01/58] fix for username field --- system/blueprints/user/account.yaml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/system/blueprints/user/account.yaml b/system/blueprints/user/account.yaml index 9bfef3f03..821d5d7bc 100644 --- a/system/blueprints/user/account.yaml +++ b/system/blueprints/user/account.yaml @@ -9,7 +9,17 @@ form: fields: username: - type: unset + type: text + size: large + label: Username + readonly: true + + email: + type: text + size: large + label: Email + validate: + required: true password: type: password @@ -18,12 +28,7 @@ form: validate: required: true - email: - type: text - size: large - label: Email - validate: - required: true + fullname: type: text From 48b02b0f05326ba29fb48dc9ec14b8cce02e770d Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Sun, 12 Oct 2014 18:54:27 -0700 Subject: [PATCH 02/58] Selfupgrade command now clears cache after a successful upgrade --- system/src/Grav/Console/ConsoleTrait.php | 9 +++++++++ system/src/Grav/Console/Gpm/SelfupgradeCommand.php | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 3fc01c7f0..1067331ee 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -2,7 +2,9 @@ namespace Grav\Console; use Grav\Common\GravTrait; +use Grav\Console\Cli\ClearCacheCommand; use Symfony\Component\Console\Formatter\OutputFormatterStyle; +use Symfony\Component\Console\Input\ArrayInput; trait ConsoleTrait { @@ -61,4 +63,11 @@ trait ConsoleTrait exit; } } + + public function clearCache() + { + $command = new ClearCacheCommand(); + $input = new ArrayInput(array('--all' => true)); + return $command->run($input, $this->output); + } } diff --git a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php index 929d1684e..3cb0f423b 100644 --- a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php +++ b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php @@ -7,6 +7,7 @@ use Grav\Common\GPM\Installer; use Grav\Common\GPM\Response; use Grav\Console\ConsoleTrait; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -114,6 +115,9 @@ class SelfupgradeCommand extends Command $this->output->writeln(" '- Success! "); $this->output->writeln(''); } + + // clear cache after successful upgrade + $this->clearCache(); } private function download($package) From 6c912d126ad45465e1eb65f2457c7f613582e6e1 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 13 Oct 2014 11:07:33 -0600 Subject: [PATCH 03/58] Fixed error messages relating to plugins --- system/src/Grav/Common/Plugins.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Plugins.php b/system/src/Grav/Common/Plugins.php index 895dbc17c..d7a8f6ff5 100644 --- a/system/src/Grav/Common/Plugins.php +++ b/system/src/Grav/Common/Plugins.php @@ -46,7 +46,7 @@ class Plugins extends Iterator $filePath = $this->grav['locator']('plugins://' . $plugin . DS . $plugin . PLUGIN_EXT); if (!is_file($filePath)) { - throw new \RuntimeException(sprintf("Plugin '%s' enabled but not found!", $filePath, $plugin)); + throw new \RuntimeException(sprintf("Plugin '%s' enabled but not found! Try clearing cache with `bin/grav clear-cache`", $plugin)); } require_once $filePath; @@ -54,7 +54,7 @@ class Plugins extends Iterator $pluginClass = 'Grav\\Plugin\\'.ucfirst($plugin).'Plugin'; if (!class_exists($pluginClass)) { - throw new \RuntimeException(sprintf("Plugin '%s' class not found!", $plugin)); + throw new \RuntimeException(sprintf("Plugin '%s' class not found! Try reinstalling this plugin.", $plugin)); } $instance = new $pluginClass($this->grav, $config); From 3d983d8377b6e499d91fbbb04437beb7e900406c Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Mon, 13 Oct 2014 10:38:11 -0700 Subject: [PATCH 04/58] Forcing a hard clear-cache for self upgrade only and soft clear-cache for install/update of themes/plugins --- system/src/Grav/Console/ConsoleTrait.php | 8 ++++++-- system/src/Grav/Console/Gpm/InstallCommand.php | 3 +++ system/src/Grav/Console/Gpm/SelfupgradeCommand.php | 3 +-- system/src/Grav/Console/Gpm/UpdateCommand.php | 3 +++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 1067331ee..7770ecbbd 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -64,10 +64,14 @@ trait ConsoleTrait } } - public function clearCache() + public function clearCache($all = []) { + if ($all) { + $all = ['--all' => true]; + } + $command = new ClearCacheCommand(); - $input = new ArrayInput(array('--all' => true)); + $input = new ArrayInput($all); return $command->run($input, $this->output); } } diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php index 6c5a124fa..aacfd3c86 100644 --- a/system/src/Grav/Console/Gpm/InstallCommand.php +++ b/system/src/Grav/Console/Gpm/InstallCommand.php @@ -114,6 +114,9 @@ class InstallCommand extends Command } } } + + // clear cache after successful upgrade + $this->clearCache(); } private function downloadPackage($package) diff --git a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php index 3cb0f423b..455eea9b9 100644 --- a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php +++ b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php @@ -7,7 +7,6 @@ use Grav\Common\GPM\Installer; use Grav\Common\GPM\Response; use Grav\Console\ConsoleTrait; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -117,7 +116,7 @@ class SelfupgradeCommand extends Command } // clear cache after successful upgrade - $this->clearCache(); + $this->clearCache(true); } private function download($package) diff --git a/system/src/Grav/Console/Gpm/UpdateCommand.php b/system/src/Grav/Console/Gpm/UpdateCommand.php index 87c91c36e..451a3e79a 100644 --- a/system/src/Grav/Console/Gpm/UpdateCommand.php +++ b/system/src/Grav/Console/Gpm/UpdateCommand.php @@ -128,6 +128,9 @@ class UpdateCommand extends Command $this->output->writeln("Error: An error occured while trying to install the extensions"); exit; } + + // clear cache after successful upgrade + $this->clearCache(); } private function userInputPackages($onlyPackages) From d18f0bf7517eeee65b682e877232d49553be019d Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Mon, 13 Oct 2014 14:24:55 -0700 Subject: [PATCH 05/58] Removed is_file check on the else statement as files with no extensions aren't recognized as files by PHP, preventing .htaccess or LICENSE to get copied over --- system/src/Grav/Common/GPM/Installer.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/GPM/Installer.php b/system/src/Grav/Common/GPM/Installer.php index dc2d563c2..36cce7867 100644 --- a/system/src/Grav/Common/GPM/Installer.php +++ b/system/src/Grav/Common/GPM/Installer.php @@ -150,10 +150,8 @@ class Installer } } } else { - if (is_file($path)) { - @unlink($path); - @copy($tmp . DS . $filename, $path); - } + @unlink($path); + @copy($tmp . DS . $filename, $path); } } } From 2bfcd88bfd53c3096fad0359234484b6f158e37a Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 13 Oct 2014 22:23:13 -0600 Subject: [PATCH 06/58] Initial commit with PHP Debug Bar instead of Tracy --- .htaccess | 2 +- composer.json | 1 + index.php | 5 +- system/src/Grav/Common/Assets.php | 21 ++- system/src/Grav/Common/Debugger.php | 202 +++++++++++++++++++++------- system/src/Grav/Common/Grav.php | 40 ++++-- 6 files changed, 199 insertions(+), 72 deletions(-) diff --git a/.htaccess b/.htaccess index 82978114e..0419abea4 100755 --- a/.htaccess +++ b/.htaccess @@ -31,7 +31,7 @@ RewriteRule ^bin/(.*)$ error [R=301,L] RewriteRule ^system/(.*)$ error [R=301,L] # Block vendor/ -RewriteRule ^vendor/(.*)$ error [R=301,L] +# RewriteRule ^vendor/(.*)$ error [R=301,L] diff --git a/composer.json b/composer.json index 814430144..69bdbafd0 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "symfony/event-dispatcher": "~2.5", "doctrine/cache": "~1.3", "tracy/tracy": "2.3.*@dev", + "maximebf/debugbar": ">=1.0.0", "gregwar/image": "~2.0", "ircmaxell/password-compat": "1.0.*", "mrclay/minify": "dev-master", diff --git a/index.php b/index.php index 2133f6219..bc1c6b310 100644 --- a/index.php +++ b/index.php @@ -22,13 +22,12 @@ if (!ini_get('date.timezone')) { $grav = Grav::instance( array( - 'loader' => $loader, - 'debugger' => new Debugger(Debugger::PRODUCTION) + 'loader' => $loader ) ); try { - $grav['debugger']->init(); + $grav['debugger']; $grav->process(); } catch (\Exception $e) { diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 81de19219..44aa8a83c 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -249,7 +249,7 @@ class Assets } if( !array_key_exists($asset, $this->css)) { - $this->css[$asset] = ['asset'=>$asset, 'priority'=>$priority, 'pipeline'=>$pipeline]; + $this->css[$asset] = ['asset'=>$asset, 'priority'=>$priority, 'order' => count($this->css), 'pipeline'=>$pipeline]; } return $this; @@ -300,7 +300,8 @@ class Assets } if( !array_key_exists($asset, $this->js)) { - $this->js[$asset] = ['asset' => $asset, 'priority' => $priority, 'pipeline' => $pipeline]; + + $this->js[$asset] = ['asset' => $asset, 'priority' => $priority, 'order' => count($this->js), 'pipeline' => $pipeline]; } return $this; @@ -317,8 +318,15 @@ class Assets if( ! $this->css) return null; + if (self::$grav) + // Sort array by priorities (larger priority first) - usort($this->css, function ($a, $b) {return $a['priority'] - $b['priority'];}); + usort($this->css, function ($a, $b) { + if ($a['priority'] == $b['priority']) { + return $b['order'] - $a['order']; + } + return $a['priority'] - $b['priority']; + }); $this->css = array_reverse($this->css); $attributes = $this->attributes(array_merge([ 'type' => 'text/css', 'rel' => 'stylesheet' ], $attributes)); @@ -363,7 +371,12 @@ class Assets return null; // Sort array by priorities (larger priority first) - usort($this->js, function ($a, $b) {return $a['priority'] - $b['priority'];}); + usort($this->js, function ($a, $b) { + if ($a['priority'] == $b['priority']) { + return $b['order'] - $a['order']; + } + return $a['priority'] - $b['priority']; + }); $this->js = array_reverse($this->js); $attributes = $this->attributes(array_merge([ 'type' => 'text/javascript' ], $attributes)); diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index 93aafee67..f29c63a7a 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -1,7 +1,10 @@ grav = Grav::instance(); + $this->debugbar = new StandardDebugBar(); } public function init() { - $grav = Grav::instance(); - - /** @var Config $config */ - $config = $grav['config']; - - TracyDebugger::$logDirectory = $config->get('system.debugger.log.enabled') ? LOG_DIR : null; - TracyDebugger::$maxDepth = $config->get('system.debugger.max_depth'); - - // Switch debugger into development mode if configured + $config = $this->grav['config']; if ($config->get('system.debugger.enabled')) { - if ($config->get('system.debugger.strict')) { - TracyDebugger::$strictMode = true; - } - - $mode = $config->get('system.debugger.mode'); - - if (function_exists('ini_set')) { - ini_set('display_errors', !($mode === 'production')); - } - - if ($mode === 'detect') { - TracyDebugger::$productionMode = self::DETECT; - } elseif ($mode === 'production') { - TracyDebugger::$productionMode = self::PRODUCTION; - } else { - TracyDebugger::$productionMode = self::DEVELOPMENT; - } - + $this->enabled = true; + $this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array)$config->get('system'))); } - } - - /** - * Log a message. - * - * @param string $message - */ - public function log($message) - { - if (TracyDebugger::$logDirectory) { - TracyDebugger::log(sprintf($message, TracyDebugger::timer() * 1000)); + if ($config->get('system.debugger.timing')) { + $this->timing = true; } + if ($config->get('system.debugger.twig')) { + $this->twig = true; + } + return $this; } - public static function dump($var) + public function addAssets() { - TracyDebugger::dump($var); + if ($this->enabled) { + + $assets = $this->grav['assets']; + + $this->renderer = $this->debugbar->getJavascriptRenderer(); + $this->renderer->setIncludeVendors(false); + + // Get the required CSS files + list($css_files, $js_files) = $this->renderer->getAssets(null, JavascriptRenderer::RELATIVE_URL); + foreach ($css_files as $css) { + $assets->addCss($css); + } + + foreach ($js_files as $js) { + $assets->addJs($js); + } + } + return $this; } - public static function barDump($var, $title = NULL, array $options = NULL) + public function addCollector($collector) { - TracyDebugger::barDump($var, $title, $options); + $this->debugbar->addCollector($collector); + return $this; } + + public function getCollector($collector) + { + return $this->debugbar->getCollector($collector); + } + + public function render() + { + if ($this->enabled) { + echo $this->renderer->render(); + } + return $this; + } + + public function startTimer($name, $desription = null) + { + if ($this->enabled || $name == 'config' || $name == 'debugger') { + $this->debugbar['time']->startMeasure($name, $desription); + } + return $this; + } + + public function stopTimer($name) + { + if ($this->enabled || $name == 'config' || $name == 'debugger') { + $this->debugbar['time']->stopMeasure($name); + } + return $this; + } + + + public function addMessage($message) + { + if ($this->enabled) { + $this->debugbar['messages']->addMessage($message); + } + return $this; + } + + +// const PRODUCTION = TracyDebugger::PRODUCTION; +// const DEVELOPMENT = TracyDebugger::DEVELOPMENT; +// const DETECT = TracyDebugger::DETECT; + +// public function __construct($mode = self::PRODUCTION) +// { +// // Start the timer and enable debugger in production mode as we do not have system configuration yet. +// // Debugger catches all errors and logs them, for example if the script doesn't have write permissions. +//// TracyDebugger::timer(); +//// TracyDebugger::enable($mode, is_dir(LOG_DIR) ? LOG_DIR : null); +// } +// +// public function init() +// { +// +// +// /** @var Config $config */ +// $config = $grav['config']; +// +// TracyDebugger::$logDirectory = $config->get('system.debugger.log.enabled') ? LOG_DIR : null; +// TracyDebugger::$maxDepth = $config->get('system.debugger.max_depth'); +// +// // Switch debugger into development mode if configured +// if ($config->get('system.debugger.enabled')) { +// if ($config->get('system.debugger.strict')) { +// TracyDebugger::$strictMode = true; +// } +// +// $mode = $config->get('system.debugger.mode'); +// +// if (function_exists('ini_set')) { +// ini_set('display_errors', !($mode === 'production')); +// } +// +// if ($mode === 'detect') { +// TracyDebugger::$productionMode = self::DETECT; +// } elseif ($mode === 'production') { +// TracyDebugger::$productionMode = self::PRODUCTION; +// } else { +// TracyDebugger::$productionMode = self::DEVELOPMENT; +// } +// +// } +// } +// +// /** +// * Log a message. +// * +// * @param string $message +// */ +// public function log($message) +// { +// if (TracyDebugger::$logDirectory) { +// TracyDebugger::log(sprintf($message, TracyDebugger::timer() * 1000)); +// } +// } +// +// public static function dump($var) +// { +// TracyDebugger::dump($var); +// } +// +// public static function barDump($var, $title = NULL, array $options = NULL) +// { +// TracyDebugger::barDump($var, $title, $options); +// } } diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index c04d4f784..d24e05cd3 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -15,9 +15,7 @@ use Grav\Common\Page\Medium; * @author Andy Miller * @link http://www.rockettheme.com * @license http://opensource.org/licenses/MIT - * @version 0.8.0 * - * Originally based on Pico by Gilbert Pellegrom - http://pico.dev7studios.com * Influenced by Pico, Stacey, Kirby, PieCrust and other great platforms... */ class Grav extends Container @@ -55,6 +53,10 @@ class Grav extends Container $container['grav'] = $container; + $container['debugger'] = function ($c) { + return new Debugger($c); + }; + $container['uri'] = function ($c) { return new Uri($c); }; @@ -147,15 +149,23 @@ class Grav extends Container ob_start(); // Initialize configuration. + $this['debugger']->startTimer('config', 'Configuration'); $this['config']->init(); + $this['debugger']->stopTimer('config'); + $this['debugger']->startTimer('debugger', 'Debugger'); + $this['debugger']->init(); + $this['debugger']->stopTimer('debugger'); + + $this['debugger']->startTimer('plugins', 'Plugins'); $this['plugins']->init(); - $this->fireEvent('onPluginsInitialized'); + $this['debugger']->stopTimer('plugins'); + $this['debugger']->startTimer('themes', 'Themes'); $this['themes']->init(); - $this->fireEvent('onThemeInitialized'); + $this['debugger']->stopTimer('themes'); $task = $this['task']; if ($task) { @@ -163,28 +173,36 @@ class Grav extends Container } $this['assets']->init(); - + $this['debugger']->addAssets(); $this->fireEvent('onAssetsInitialized'); + $this['debugger']->startTimer('twig', 'Twig'); $this['twig']->init(); - $this['pages']->init(); + $this['debugger']->stopTimer('twig'); + $this['debugger']->startTimer('pages', 'Pages'); + $this['pages']->init(); $this->fireEvent('onPagesInitialized'); + $this['debugger']->stopTimer('pages'); $this->fireEvent('onPageInitialized'); - // Process whole page as required - $this->output = $this['output']; + + // Process whole page as required + $this['debugger']->startTimer('render', 'Render'); + $this->output = $this['output']; $this->fireEvent('onOutputGenerated'); + $this['debugger']->stopTimer('render'); // Set the header type $this->header(); - echo $this->output; + $this['debugger']->render(); $this->fireEvent('onOutputRendered'); + register_shutdown_function([$this, 'shutdown']); } @@ -235,9 +253,7 @@ class Grav extends Container */ public function header() { - /** @var Uri $uri */ - $uri = $this['uri']; - header('Content-type: ' . $this->mime($uri->extension())); + header('Content-type: ' . $this->mime($this['uri']->extension())); } /** From bdd0c1f4c718582c6696069b0913ad79afbe731c Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 13 Oct 2014 23:27:54 -0600 Subject: [PATCH 07/58] tidy up.. --- system/src/Grav/Common/Debugger.php | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index f29c63a7a..cc2913f9d 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -13,9 +13,6 @@ use DebugBar\StandardDebugBar; class Debugger { protected $grav; - protected $enabled = false; - protected $timing = false; - protected $twig = false; protected $debugbar; protected $renderer; @@ -28,21 +25,15 @@ class Debugger { $config = $this->grav['config']; if ($config->get('system.debugger.enabled')) { - $this->enabled = true; $this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array)$config->get('system'))); } - if ($config->get('system.debugger.timing')) { - $this->timing = true; - } - if ($config->get('system.debugger.twig')) { - $this->twig = true; - } return $this; } public function addAssets() { - if ($this->enabled) { + $config = $this->grav['config']; + if ($config->get('system.debugger.enabled')) { $assets = $this->grav['assets']; @@ -75,7 +66,8 @@ class Debugger public function render() { - if ($this->enabled) { + $config = $this->grav['config']; + if ($config->get('system.debugger.enabled')) { echo $this->renderer->render(); } return $this; @@ -83,7 +75,8 @@ class Debugger public function startTimer($name, $desription = null) { - if ($this->enabled || $name == 'config' || $name == 'debugger') { + $config = $this->grav['config']; + if ($config->get('system.debugger.enabled') || $name == 'config' || $name == 'debugger') { $this->debugbar['time']->startMeasure($name, $desription); } return $this; @@ -91,7 +84,8 @@ class Debugger public function stopTimer($name) { - if ($this->enabled || $name == 'config' || $name == 'debugger') { + $config = $this->grav['config']; + if ($config->get('system.debugger.enabled') || $name == 'config' || $name == 'debugger') { $this->debugbar['time']->stopMeasure($name); } return $this; @@ -100,7 +94,8 @@ class Debugger public function addMessage($message) { - if ($this->enabled) { + $config = $this->grav['config']; + if ($config->get('system.debugger.enabled')) { $this->debugbar['messages']->addMessage($message); } return $this; From 45e79f88a3c5a5e21f3f0fbe67250dce195b226c Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 14 Oct 2014 09:32:16 +0300 Subject: [PATCH 08/58] Fix potential double // in assets (breaks assets loading in FF) --- system/src/Grav/Common/Assets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 44aa8a83c..c89a6282f 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -662,10 +662,10 @@ class Assets protected function buildLocalLink($asset) { try { - return $this->base_url . self::$grav['locator']->findResource($asset, false); + $asset = self::$grav['locator']->findResource($asset, false); } catch (\Exception $e) {} - return $this->base_url . $asset; + return $this->base_url . ltrim($asset, '/'); } From c89f683b8c86e41bff2ac85395f73a887eb4708c Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 14 Oct 2014 09:51:55 +0300 Subject: [PATCH 09/58] Load debugger as early as possible --- index.php | 2 -- system/src/Grav/Common/Debugger.php | 10 ++++++---- system/src/Grav/Common/Grav.php | 4 +--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/index.php b/index.php index bc1c6b310..cf2644f6c 100644 --- a/index.php +++ b/index.php @@ -11,7 +11,6 @@ if (!is_file($autoload)) { } use Grav\Common\Grav; -use Grav\Common\Debugger; // Register the auto-loader. $loader = require_once $autoload; @@ -27,7 +26,6 @@ $grav = Grav::instance( ); try { - $grav['debugger']; $grav->process(); } catch (\Exception $e) { diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index cc2913f9d..fa1bd509a 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -16,13 +16,15 @@ class Debugger protected $debugbar; protected $renderer; - public function __construct() { - $this->grav = Grav::instance(); + public function __construct() + { $this->debugbar = new StandardDebugBar(); } public function init() { + $this->grav = Grav::instance(); + $config = $this->grav['config']; if ($config->get('system.debugger.enabled')) { $this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array)$config->get('system'))); @@ -76,7 +78,7 @@ class Debugger public function startTimer($name, $desription = null) { $config = $this->grav['config']; - if ($config->get('system.debugger.enabled') || $name == 'config' || $name == 'debugger') { + if ($name == 'config' || $name == 'debugger' || $config->get('system.debugger.enabled')) { $this->debugbar['time']->startMeasure($name, $desription); } return $this; @@ -85,7 +87,7 @@ class Debugger public function stopTimer($name) { $config = $this->grav['config']; - if ($config->get('system.debugger.enabled') || $name == 'config' || $name == 'debugger') { + if ($name == 'config' || $name == 'debugger' || $config->get('system.debugger.enabled')) { $this->debugbar['time']->stopMeasure($name); } return $this; diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index d24e05cd3..46625bcfd 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -53,9 +53,7 @@ class Grav extends Container $container['grav'] = $container; - $container['debugger'] = function ($c) { - return new Debugger($c); - }; + $container['debugger'] = new Debugger(); $container['uri'] = function ($c) { return new Uri($c); From a1362419525763c26efe356828a4d04b8c37bf5d Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 14 Oct 2014 10:10:17 +0300 Subject: [PATCH 10/58] Add support for system timers, allowing to time initialization --- system/src/Grav/Common/Debugger.php | 6 ++---- system/src/Grav/Common/Grav.php | 11 +++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index fa1bd509a..c2c09a2ac 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -77,8 +77,7 @@ class Debugger public function startTimer($name, $desription = null) { - $config = $this->grav['config']; - if ($name == 'config' || $name == 'debugger' || $config->get('system.debugger.enabled')) { + if ($name[0] == '_' || $this->grav['config']->get('system.debugger.enabled')) { $this->debugbar['time']->startMeasure($name, $desription); } return $this; @@ -86,8 +85,7 @@ class Debugger public function stopTimer($name) { - $config = $this->grav['config']; - if ($name == 'config' || $name == 'debugger' || $config->get('system.debugger.enabled')) { + if ($name[0] == '_' || $this->grav['config']->get('system.debugger.enabled')) { $this->debugbar['time']->stopMeasure($name); } return $this; diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 46625bcfd..db5392e4b 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -54,6 +54,7 @@ class Grav extends Container $container['grav'] = $container; $container['debugger'] = new Debugger(); + $container['debugger']->startTimer('_init', 'Init'); $container['uri'] = function ($c) { return new Uri($c); @@ -138,6 +139,8 @@ class Grav extends Container $container->register(new StreamsServiceProvider); $container->register(new ConfigServiceProvider); + $container['debugger']->stopTimer('_init'); + return $container; } @@ -147,13 +150,13 @@ class Grav extends Container ob_start(); // Initialize configuration. - $this['debugger']->startTimer('config', 'Configuration'); + $this['debugger']->startTimer('_config', 'Configuration'); $this['config']->init(); - $this['debugger']->stopTimer('config'); + $this['debugger']->stopTimer('_config'); - $this['debugger']->startTimer('debugger', 'Debugger'); + $this['debugger']->startTimer('_debugger', 'Debugger'); $this['debugger']->init(); - $this['debugger']->stopTimer('debugger'); + $this['debugger']->stopTimer('_debugger'); $this['debugger']->startTimer('plugins', 'Plugins'); $this['plugins']->init(); From 74d25d240a754a8cc0ee00e38d673374a253525b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Oct 2014 12:47:47 -0600 Subject: [PATCH 11/58] Admin check --- system/src/Grav/Common/Plugin.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system/src/Grav/Common/Plugin.php b/system/src/Grav/Common/Plugin.php index 1b4a42769..e7b6bc481 100644 --- a/system/src/Grav/Common/Plugin.php +++ b/system/src/Grav/Common/Plugin.php @@ -23,6 +23,8 @@ class Plugin implements EventSubscriberInterface */ protected $config; + protected $active = true; + /** * By default assign all methods as listeners using the default priority. * @@ -53,6 +55,14 @@ class Plugin implements EventSubscriberInterface $this->config = $config; } + public function isAdmin() + { + if (isset($this->grav['admin'])) { + return true; + } + return false; + } + /** * @param array $events */ From 9fa92b504f47a51c24a51be1b96b7bbbc2ad7452 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Oct 2014 12:47:47 -0600 Subject: [PATCH 12/58] Admin check --- system/src/Grav/Common/Plugin.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system/src/Grav/Common/Plugin.php b/system/src/Grav/Common/Plugin.php index 1b4a42769..e7b6bc481 100644 --- a/system/src/Grav/Common/Plugin.php +++ b/system/src/Grav/Common/Plugin.php @@ -23,6 +23,8 @@ class Plugin implements EventSubscriberInterface */ protected $config; + protected $active = true; + /** * By default assign all methods as listeners using the default priority. * @@ -53,6 +55,14 @@ class Plugin implements EventSubscriberInterface $this->config = $config; } + public function isAdmin() + { + if (isset($this->grav['admin'])) { + return true; + } + return false; + } + /** * @param array $events */ From 002902c9d970a83fadebe68fe59ac016ba5b4ab6 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Tue, 14 Oct 2014 12:17:29 -0700 Subject: [PATCH 13/58] Cleanup --- system/src/Grav/Common/GPM/GPM.php | 16 +- system/src/Grav/Console/Cli/BackupCommand.php | 100 ++++--- system/src/Grav/Console/Cli/CleanCommand.php | 37 ++- .../Grav/Console/Cli/ClearCacheCommand.php | 62 ++-- .../src/Grav/Console/Cli/InstallCommand.php | 89 ++++-- .../Grav/Console/Cli/NewProjectCommand.php | 69 +++-- .../src/Grav/Console/Cli/SandboxCommand.php | 267 +++++++++++------- system/src/Grav/Console/ConsoleTrait.php | 29 +- system/src/Grav/Console/Gpm/IndexCommand.php | 44 ++- system/src/Grav/Console/Gpm/InfoCommand.php | 38 ++- .../src/Grav/Console/Gpm/InstallCommand.php | 78 ++++- .../Grav/Console/Gpm/SelfupgradeCommand.php | 92 ++++-- system/src/Grav/Console/Gpm/UpdateCommand.php | 76 +++-- 13 files changed, 715 insertions(+), 282 deletions(-) diff --git a/system/src/Grav/Common/GPM/GPM.php b/system/src/Grav/Common/GPM/GPM.php index 98cee2dae..fd82f3642 100644 --- a/system/src/Grav/Common/GPM/GPM.php +++ b/system/src/Grav/Common/GPM/GPM.php @@ -7,13 +7,13 @@ class GPM extends Iterator { /** * Local installed Packages - * @var Packages + * @var Local\Packages */ private $installed; /** * Remote available Packages - * @var Packages + * @var Remote\Packages */ private $repository; @@ -24,7 +24,7 @@ class GPM extends Iterator /** * Internal cache - * @var Iterator + * @var */ protected $cache; @@ -63,7 +63,7 @@ class GPM extends Iterator /** * Return the instance of a specific Plugin * @param string $slug The slug of the Plugin - * @return Package The instance of the Plugin + * @return Local\Package The instance of the Plugin */ public function getInstalledPlugin($slug) { @@ -92,7 +92,7 @@ class GPM extends Iterator /** * Return the instance of a specific Theme * @param string $slug The slug of the Theme - * @return Package The instance of the Theme + * @return Local\Package The instance of the Theme */ public function getInstalledTheme($slug) { @@ -204,7 +204,7 @@ class GPM extends Iterator */ public function isPluginUpdatable($plugin) { - return array_key_exists($plugin, $this->getUpdatablePlugins()); + return array_key_exists($plugin, (array) $this->getUpdatablePlugins()); } /** @@ -249,7 +249,7 @@ class GPM extends Iterator */ public function isThemeUpdatable($theme) { - return array_key_exists($theme, $this->getUpdatableThemes()); + return array_key_exists($theme, (array) $this->getUpdatableThemes()); } /** @@ -303,7 +303,7 @@ class GPM extends Iterator /** * Searches for a Package in the repository * @param string $search Can be either the slug or the name - * @return Package Package if found, FALSE if not + * @return Remote\Package Package if found, FALSE if not */ public function findPackage($search) { diff --git a/system/src/Grav/Console/Cli/BackupCommand.php b/system/src/Grav/Console/Cli/BackupCommand.php index d6bb7757d..4f7194b0a 100644 --- a/system/src/Grav/Console/Cli/BackupCommand.php +++ b/system/src/Grav/Console/Cli/BackupCommand.php @@ -2,70 +2,98 @@ namespace Grav\Console\Cli; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Formatter\OutputFormatterStyle; -use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Yaml\Yaml; -class BackupCommand extends Command { +/** + * Class BackupCommand + * @package Grav\Console\Cli + */ +class BackupCommand extends Command +{ + /** + * @var + */ protected $source; + /** + * @var + */ protected $progress; - protected function configure() { + /** + * + */ + protected function configure() + { $this - ->setName("backup") - ->addArgument( - 'destination', - InputArgument::OPTIONAL, - 'Where to store the backup' + ->setName("backup") + ->addArgument( + 'destination', + InputArgument::OPTIONAL, + 'Where to store the backup' - ) - ->setDescription("Creates a backup of the Grav instance") - ->setHelp('The backup creates a zipped backup. Optionally can be saved in a different destination.'); + ) + ->setDescription("Creates a backup of the Grav instance") + ->setHelp('The backup creates a zipped backup. Optionally can be saved in a different destination.'); $this->source = getcwd(); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { - $output->getFormatter()->setStyle('red', new OutputFormatterStyle('red')); - $output->getFormatter()->setStyle('cyan', new OutputFormatterStyle('cyan')); - $output->getFormatter()->setStyle('green', new OutputFormatterStyle('green')); - $output->getFormatter()->setStyle('magenta', new OutputFormatterStyle('magenta')); + $output->getFormatter()->setStyle('red', new OutputFormatterStyle('red')); + $output->getFormatter()->setStyle('cyan', new OutputFormatterStyle('cyan')); + $output->getFormatter()->setStyle('green', new OutputFormatterStyle('green')); + $output->getFormatter()->setStyle('magenta', new OutputFormatterStyle('magenta')); - $this->progress = new ProgressBar($output); - $this->progress->setFormat('Archiving %current% files [%bar%] %elapsed:6s% %memory:6s%'); + $this->progress = new ProgressBar($output); + $this->progress->setFormat('Archiving %current% files [%bar%] %elapsed:6s% %memory:6s%'); - $name = basename($this->source); - $dir = dirname($this->source); - $date = date('YmdHis', time()); - $filename = $name . '-' . $date . '.zip'; + $name = basename($this->source); + $dir = dirname($this->source); + $date = date('YmdHis', time()); + $filename = $name . '-' . $date . '.zip'; - $destination = ($input->getArgument('destination')) ? $input->getArgument('destination') : ROOT_DIR; - $destination = rtrim($destination, DS) . DS . $filename; + $destination = ($input->getArgument('destination')) ? $input->getArgument('destination') : ROOT_DIR; + $destination = rtrim($destination, DS) . DS . $filename; - $output->writeln(''); - $output->writeln('Creating new Backup "'.$destination.'"'); - $this->progress->start(); + $output->writeln(''); + $output->writeln('Creating new Backup "' . $destination . '"'); + $this->progress->start(); - $zip = new \ZipArchive(); - $zip->open($destination, \ZipArchive::CREATE); - $zip->addEmptyDir($name); + $zip = new \ZipArchive(); + $zip->open($destination, \ZipArchive::CREATE); + $zip->addEmptyDir($name); - $this->folderToZip($this->source, $zip, strlen($dir.DS), $this->progress); - $zip->close(); - $this->progress->finish(); - $output->writeln(''); - $output->writeln(''); + $this->folderToZip($this->source, $zip, strlen($dir . DS), $this->progress); + $zip->close(); + $this->progress->finish(); + $output->writeln(''); + $output->writeln(''); } - private static function folderToZip($folder, &$zipFile, $exclusiveLength, $progress) { + /** + * @param $folder + * @param $zipFile + * @param $exclusiveLength + * @param $progress + */ + private static function folderToZip($folder, \ZipArchive &$zipFile, $exclusiveLength, ProgressBar $progress) + { $handle = opendir($folder); while (false !== $f = readdir($handle)) { if ($f != '.' && $f != '..') { diff --git a/system/src/Grav/Console/Cli/CleanCommand.php b/system/src/Grav/Console/Cli/CleanCommand.php index 95da029f7..9f5d71d9d 100644 --- a/system/src/Grav/Console/Cli/CleanCommand.php +++ b/system/src/Grav/Console/Cli/CleanCommand.php @@ -3,14 +3,22 @@ namespace Grav\Console\Cli; use Grav\Common\Filesystem\Folder; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Formatter\OutputFormatterStyle; -class CleanCommand extends Command { +/** + * Class CleanCommand + * @package Grav\Console\Cli + */ +class CleanCommand extends Command +{ + /** + * @var array + */ protected $paths_to_remove = [ 'user/plugins/email/vendor/swiftmailer/swiftmailer/.travis.yml', 'user/plugins/email/vendor/swiftmailer/swiftmailer/build.xml', @@ -128,13 +136,23 @@ class CleanCommand extends Command { 'vendor/twig/twig/test', ]; - protected function configure() { + /** + * + */ + protected function configure() + { $this - ->setName("clean") - ->setDescription("Handles cleaning chores for Grav distribution") - ->setHelp('The clean clean extraneous folders and data'); + ->setName("clean") + ->setDescription("Handles cleaning chores for Grav distribution") + ->setHelp('The clean clean extraneous folders and data'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -151,14 +169,17 @@ class CleanCommand extends Command { } // loops over the array of paths and deletes the files/folders - private function cleanPaths($output) + /** + * @param OutputInterface $output + */ + private function cleanPaths(OutputInterface $output) { $output->writeln(''); $output->writeln('DELETING'); $anything = false; - foreach($this->paths_to_remove as $path) { + foreach ($this->paths_to_remove as $path) { $path = ROOT_DIR . $path; if (is_dir($path) && @Folder::delete($path)) { diff --git a/system/src/Grav/Console/Cli/ClearCacheCommand.php b/system/src/Grav/Console/Cli/ClearCacheCommand.php index 532cb137b..aaad55c9a 100644 --- a/system/src/Grav/Console/Cli/ClearCacheCommand.php +++ b/system/src/Grav/Console/Cli/ClearCacheCommand.php @@ -3,15 +3,23 @@ namespace Grav\Console\Cli; use Grav\Common\Filesystem\Folder; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Formatter\OutputFormatterStyle; -use \Symfony\Component\Yaml\Yaml; +use Symfony\Component\Yaml\Yaml; -class ClearCacheCommand extends Command { +/** + * Class ClearCacheCommand + * @package Grav\Console\Cli + */ +class ClearCacheCommand extends Command +{ + /** + * @var array + */ protected $standard_remove = [ 'cache/twig/', 'cache/doctrine/', @@ -21,20 +29,33 @@ class ClearCacheCommand extends Command { 'assets/', ]; + /** + * @var array + */ protected $all_remove = [ 'cache/', 'images/', 'assets/' ]; - protected function configure() { + /** + * + */ + protected function configure() + { $this - ->setName("clear-cache") - ->setDescription("Clears Grav cache") - ->addOption('all', null, InputOption::VALUE_NONE, 'If set will remove all') - ->setHelp('The clear-cache deletes all cache files'); + ->setName("clear-cache") + ->setDescription("Clears Grav cache") + ->addOption('all', null, InputOption::VALUE_NONE, 'If set will remove all') + ->setHelp('The clear-cache deletes all cache files'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { // Create a red output option @@ -47,7 +68,11 @@ class ClearCacheCommand extends Command { } // loops over the array of paths and deletes the files/folders - private function cleanPaths($input, $output) + /** + * @param InputInterface $input + * @param OutputInterface $output + */ + private function cleanPaths(InputInterface $input, OutputInterface $output) { $output->writeln(''); $output->writeln('Clearing cache'); @@ -63,24 +88,29 @@ class ClearCacheCommand extends Command { $remove_paths = $this->standard_remove; } - foreach($remove_paths as $path) { + foreach ($remove_paths as $path) { $files = glob(ROOT_DIR . $path . '*'); foreach ($files as $file) { if (is_file($file)) { - if (@unlink($file)) $anything = true; - } - elseif (is_dir($file)) { - if (@Folder::delete($file)) $anything = true; + if (@unlink($file)) { + $anything = true; + } + } elseif (is_dir($file)) { + if (@Folder::delete($file)) { + $anything = true; + } } } - if ($anything) $output->writeln('Cleared: ' . $path . '*'); + if ($anything) { + $output->writeln('Cleared: ' . $path . '*'); + } } if (file_exists($user_config)) { - touch ($user_config); + touch($user_config); $output->writeln(''); $output->writeln('Touched: ' . $user_config); $output->writeln(''); diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php index 38664d9a3..01f5809c7 100644 --- a/system/src/Grav/Console/Cli/InstallCommand.php +++ b/system/src/Grav/Console/Cli/InstallCommand.php @@ -2,39 +2,66 @@ namespace Grav\Console\Cli; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Formatter\OutputFormatterStyle; -use \Symfony\Component\Yaml\Yaml; +use Symfony\Component\Yaml\Yaml; -class InstallCommand extends Command { +/** + * Class InstallCommand + * @package Grav\Console\Cli + */ +class InstallCommand extends Command +{ + /** + * @var + */ protected $config; + /** + * @var + */ protected $local_config; + /** + * @var + */ protected $destination; + /** + * @var + */ protected $user_path; - protected function configure() { + /** + * + */ + protected function configure() + { $this - ->setName("install") - ->addOption( - 'symlink', - 's', - InputOption::VALUE_NONE, - 'Symlink the required bits' - ) - ->addArgument( - 'destination', - InputArgument::OPTIONAL, - 'Where to install the required bits (default to current project)' + ->setName("install") + ->addOption( + 'symlink', + 's', + InputOption::VALUE_NONE, + 'Symlink the required bits' + ) + ->addArgument( + 'destination', + InputArgument::OPTIONAL, + 'Where to install the required bits (default to current project)' - ) - ->setDescription("Installs the dependencies needed by Grav. Optionally can create symbolic links") - ->setHelp('The install command installs the dependencies needed by Grav. Optionally can create symbolic links'); + ) + ->setDescription("Installs the dependencies needed by Grav. Optionally can create symbolic links") + ->setHelp('The install command installs the dependencies needed by Grav. Optionally can create symbolic links'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -44,7 +71,7 @@ class InstallCommand extends Command { // fix trailing slash $this->destination = rtrim($this->destination, DS) . DS; - $this->user_path = $this->destination . USER_PATH; + $this->user_path = $this->destination . USER_PATH; // Create a red output option $output->getFormatter()->setStyle('red', new OutputFormatterStyle('red')); @@ -60,7 +87,7 @@ class InstallCommand extends Command { // Look for dependencies file in ROOT and USER dir if (file_exists($this->user_path . $dependencies_file)) { $this->config = Yaml::parse($this->user_path . $dependencies_file); - } elseif (file_exists($this->destination . $dependencies_file )) { + } elseif (file_exists($this->destination . $dependencies_file)) { $this->config = Yaml::parse($this->destination . $dependencies_file); } else { $output->writeln('ERROR Missing .dependencies file in user/ folder'); @@ -68,7 +95,7 @@ class InstallCommand extends Command { // Updates composer first $output->writeln("\nInstalling vendor dependencies"); - $output->writeln(system('php bin/composer.phar --working-dir="'.$this->destination.'" --no-interaction update')); + $output->writeln(system('php bin/composer.phar --working-dir="' . $this->destination . '" --no-interaction update')); // If yaml config, process if ($this->config) { @@ -78,21 +105,24 @@ class InstallCommand extends Command { $this->symlink($output); } } else { - $output->writeln('ERROR invalid YAML in '. $dependencies_file); + $output->writeln('ERROR invalid YAML in ' . $dependencies_file); } } // loops over the array of paths and deletes the files/folders - private function gitclone($output) + /** + * @param OutputInterface $output + */ + private function gitclone(OutputInterface $output) { $output->writeln(''); $output->writeln('Cloning Bits'); $output->writeln('============'); $output->writeln(''); - foreach($this->config['git'] as $repo => $data) { + foreach ($this->config['git'] as $repo => $data) { $path = $this->destination . DS . $data['path']; if (!file_exists($path)) { exec('cd ' . $this->destination . ' && git clone -b ' . $data['branch'] . ' ' . $data['url'] . ' ' . $data['path']); @@ -107,7 +137,10 @@ class InstallCommand extends Command { } // loops over the array of paths and deletes the files/folders - private function symlink($output) + /** + * @param OutputInterface $output + */ + private function symlink(OutputInterface $output) { $output->writeln(''); $output->writeln('Symlinking Bits'); @@ -121,13 +154,13 @@ class InstallCommand extends Command { } exec('cd ' . $this->destination); - foreach($this->config['links'] as $repo => $data) { - $from = $this->local_config[$data['scm'].'_repos'] . $data['src']; + foreach ($this->config['links'] as $repo => $data) { + $from = $this->local_config[$data['scm'] . '_repos'] . $data['src']; $to = $this->destination . $data['path']; if (file_exists($from)) { if (!file_exists($to)) { - symlink ($from, $to); + symlink($from, $to); $output->writeln('SUCCESS symlinked ' . $data['src'] . ' -> ' . $data['path'] . ''); $output->writeln(''); } else { diff --git a/system/src/Grav/Console/Cli/NewProjectCommand.php b/system/src/Grav/Console/Cli/NewProjectCommand.php index 7d49704a3..021e8f9bb 100644 --- a/system/src/Grav/Console/Cli/NewProjectCommand.php +++ b/system/src/Grav/Console/Cli/NewProjectCommand.php @@ -2,51 +2,66 @@ namespace Grav\Console\Cli; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Formatter\OutputFormatterStyle; -use \Symfony\Component\Yaml\Yaml; +use Symfony\Component\Yaml\Yaml; -class NewProjectCommand extends Command { +/** + * Class NewProjectCommand + * @package Grav\Console\Cli + */ +class NewProjectCommand extends Command +{ - protected function configure() { + /** + * + */ + protected function configure() + { $this - ->setName("new-project") - ->addArgument( - 'destination', - InputArgument::REQUIRED, - 'The destination directory of your new Grav project' - ) - ->addOption( - 'symlink', - 's', - InputOption::VALUE_NONE, - 'Symlink the required bits' - ) - ->setDescription("Creates a new Grav project with all the dependencies installed") - ->setHelp("The new-project command is a combination of the `setup` and `install` commands.\nCreates a new Grav instance and performs the installation of all the required dependencies."); + ->setName("new-project") + ->addArgument( + 'destination', + InputArgument::REQUIRED, + 'The destination directory of your new Grav project' + ) + ->addOption( + 'symlink', + 's', + InputOption::VALUE_NONE, + 'Symlink the required bits' + ) + ->setDescription("Creates a new Grav project with all the dependencies installed") + ->setHelp("The new-project command is a combination of the `setup` and `install` commands.\nCreates a new Grav instance and performs the installation of all the required dependencies."); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { - $sandboxCommand = $this->getApplication()->find('sandbox'); + $sandboxCommand = $this->getApplication()->find('sandbox'); $installCommand = $this->getApplication()->find('install'); $sandboxArguments = new ArrayInput(array( - 'command' => 'sandbox', - 'destination' => $input->getArgument('destination'), - '-s' => $input->getOption('symlink') - )); + 'command' => 'sandbox', + 'destination' => $input->getArgument('destination'), + '-s' => $input->getOption('symlink') + )); $installArguments = new ArrayInput(array( - 'command' => 'install', - 'destination' => $input->getArgument('destination'), - '-s' => $input->getOption('symlink') - )); + 'command' => 'install', + 'destination' => $input->getArgument('destination'), + '-s' => $input->getOption('symlink') + )); $sandboxCommand->run($sandboxArguments, $output); $installCommand->run($installArguments, $output); diff --git a/system/src/Grav/Console/Cli/SandboxCommand.php b/system/src/Grav/Console/Cli/SandboxCommand.php index f564b349b..404970880 100644 --- a/system/src/Grav/Console/Cli/SandboxCommand.php +++ b/system/src/Grav/Console/Cli/SandboxCommand.php @@ -3,98 +3,146 @@ namespace Grav\Console\Cli; use Grav\Common\Filesystem\Folder; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Formatter\OutputFormatterStyle; +/** + * Class SandboxCommand + * @package Grav\Console\Cli + */ class SandboxCommand extends Command { - protected $directories = array('/cache', - '/logs', - '/images', - '/assets', - '/user/accounts', - '/user/config', - '/user/pages', - '/user/data', - '/user/plugins', - '/user/themes', - ); + /** + * @var array + */ + protected $directories = array( + '/cache', + '/logs', + '/images', + '/assets', + '/user/accounts', + '/user/config', + '/user/pages', + '/user/data', + '/user/plugins', + '/user/themes', + ); - protected $files = array('/.dependencies', - '/.htaccess', - '/user/config/site.yaml', - '/user/config/system.yaml', - ); + /** + * @var array + */ + protected $files = array( + '/.dependencies', + '/.editorconfig', + '/.htaccess', + '/user/config/site.yaml', + '/user/config/system.yaml', + ); - protected $mappings = array('/index.php' => '/index.php', - '/composer.json' => '/composer.json', - '/bin' => '/bin', - '/system' => '/system' - ); + /** + * @var array + */ + protected $mappings = array( + '/index.php' => '/index.php', + '/composer.json' => '/composer.json', + '/bin' => '/bin', + '/system' => '/system' + ); + /** + * @var string + */ protected $default_file = "---\ntitle: HomePage\n---\n# HomePage\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porttitor eu felis sed ornare. Sed a mauris venenatis, pulvinar velit vel, dictum enim. Phasellus ac rutrum velit. Nunc lorem purus, hendrerit sit amet augue aliquet, iaculis ultricies nisl. Suspendisse tincidunt euismod risus, quis feugiat arcu tincidunt eget. Nulla eros mi, commodo vel ipsum vel, aliquet congue odio. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque velit orci, laoreet at adipiscing eu, interdum quis nibh. Nunc a accumsan purus."; + /** + * @var + */ protected $source; + /** + * @var + */ protected $destination; + /** + * @var InputInterface $input + */ + protected $input; + /** + * @var OutputInterface $output + */ + protected $output; + /** + * + */ protected function configure() { $this - ->setName('sandbox') - ->setDescription('Setup of a base Grav system in your webroot, good for development, playing around or starting fresh') - ->addArgument( - 'destination', - InputArgument::REQUIRED, - 'The destination directory to symlink into' - ) - ->addOption( - 'symlink', - 's', - InputOption::VALUE_NONE, - 'Symlink the base grav system' - ) - ->setHelp("The sandbox command help create a development environment that can optionally use symbolic links to link the core of grav to the git cloned repository.\nGood for development, playing around or starting fresh"); + ->setName('sandbox') + ->setDescription('Setup of a base Grav system in your webroot, good for development, playing around or starting fresh') + ->addArgument( + 'destination', + InputArgument::REQUIRED, + 'The destination directory to symlink into' + ) + ->addOption( + 'symlink', + 's', + InputOption::VALUE_NONE, + 'Symlink the base grav system' + ) + ->setHelp("The sandbox command help create a development environment that can optionally use symbolic links to link the core of grav to the git cloned repository.\nGood for development, playing around or starting fresh"); $this->source = getcwd(); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { $this->destination = $input->getArgument('destination'); + $this->input = $input; + $this->output = $output; // Create a red output option - $output->getFormatter()->setStyle('red', new OutputFormatterStyle('red')); - $output->getFormatter()->setStyle('cyan', new OutputFormatterStyle('cyan')); - $output->getFormatter()->setStyle('magenta', new OutputFormatterStyle('magenta')); + $this->output->getFormatter()->setStyle('red', new OutputFormatterStyle('red')); + $this->output->getFormatter()->setStyle('cyan', new OutputFormatterStyle('cyan')); + $this->output->getFormatter()->setStyle('magenta', new OutputFormatterStyle('magenta')); // Symlink the Core Stuff if ($input->getOption('symlink')) { // Create Some core stuff if it doesn't exist - $this->createDirectories($output); + $this->createDirectories(); // Loop through the symlink mappings and create the symlinks - $this->symlink($output); + $this->symlink(); - // Copy the Core STuff + // Copy the Core STuff } else { // Create Some core stuff if it doesn't exist - $this->createDirectories($output); + $this->createDirectories(); // Loop through the symlink mappings and copy what otherwise would be symlinks - $this->copy($output); + $this->copy(); } - $this->pages($output); - $this->initFiles($output); - $this->perms($output); + $this->pages(); + $this->initFiles(); + $this->perms(); } - private function createDirectories($output) + /** + * + */ + private function createDirectories() { - $output->writeln(''); - $output->writeln('Creating Directories'); + $this->output->writeln(''); + $this->output->writeln('Creating Directories'); $dirs_created = false; if (!file_exists($this->destination)) { @@ -104,50 +152,56 @@ class SandboxCommand extends Command foreach ($this->directories as $dir) { if (!file_exists($this->destination . $dir)) { $dirs_created = true; - $output->writeln(' ' . $dir . ''); + $this->output->writeln(' ' . $dir . ''); mkdir($this->destination . $dir, 0777, true); } } if (!$dirs_created) { - $output->writeln(' Directories already exist'); + $this->output->writeln(' Directories already exist'); } } - private function copy($output) + /** + * + */ + private function copy() { - $output->writeln(''); - $output->writeln('Copying Files'); + $this->output->writeln(''); + $this->output->writeln('Copying Files'); foreach ($this->mappings as $source => $target) { - if ((int) $source == $source) { + if ((int)$source == $source) { $source = $target; } $from = $this->source . $source; $to = $this->destination . $target; - $output->writeln(' ' . $source . ' -> ' . $to); + $this->output->writeln(' ' . $source . ' -> ' . $to); $this->rcopy($from, $to); } } - private function symlink($output) + /** + * + */ + private function symlink() { - $output->writeln(''); - $output->writeln('Resetting Symbolic Links'); + $this->output->writeln(''); + $this->output->writeln('Resetting Symbolic Links'); foreach ($this->mappings as $source => $target) { - if ((int) $source == $source) { + if ((int)$source == $source) { $source = $target; } $from = $this->source . $source; $to = $this->destination . $target; - $output->writeln(' ' . $source . ' -> ' . $to); + $this->output->writeln(' ' . $source . ' -> ' . $to); if (is_dir($to)) { @Folder::delete($to); @@ -158,17 +212,20 @@ class SandboxCommand extends Command } } - private function initFiles($output) + /** + * + */ + private function initFiles() { - $this->check($output); + $this->check($this->output); - $output->writeln(''); - $output->writeln('File Initializing'); + $this->output->writeln(''); + $this->output->writeln('File Initializing'); $files_init = false; // Copy files if they do not exist - foreach ($this->files as $source => $target) { - if ((int) $source == $source) { + foreach ($this->files as $source => $target) { + if ((int)$source == $source) { $source = $target; } @@ -178,21 +235,24 @@ class SandboxCommand extends Command if (!file_exists($to)) { $files_init = true; copy($from, $to); - $output->writeln(' '.$target.' -> Created'); + $this->output->writeln(' ' . $target . ' -> Created'); } } if (!$files_init) { - $output->writeln(' Files already exist'); + $this->output->writeln(' Files already exist'); } } - private function pages($output) + /** + * + */ + private function pages() { - $output->writeln(''); - $output->writeln('Pages Initializing'); + $this->output->writeln(''); + $this->output->writeln('Pages Initializing'); // get pages files and initialize if no pages exist $pages_dir = $this->destination . '/user/pages'; @@ -201,70 +261,83 @@ class SandboxCommand extends Command if (count($pages_files) == 0) { $destination = $this->source . '/user/pages'; $this->rcopy($destination, $pages_dir); - $output->writeln(' '.$destination.' -> Created'); + $this->output->writeln(' ' . $destination . ' -> Created'); } } - private function perms($output) + /** + * + */ + private function perms() { - $output->writeln(''); - $output->writeln('Permisions Initializing'); + $this->output->writeln(''); + $this->output->writeln('Permisions Initializing'); $dir_perms = 0755; - $binaries = glob($this->destination . DS .'bin' . DS . '*'); + $binaries = glob($this->destination . DS . 'bin' . DS . '*'); - foreach($binaries as $bin) { + foreach ($binaries as $bin) { chmod($bin, $dir_perms); - $output->writeln(' bin/' . basename($bin) . ' permissions reset to '. decoct($dir_perms)); + $this->output->writeln(' bin/' . basename($bin) . ' permissions reset to ' . decoct($dir_perms)); } - $output->writeln(""); + $this->output->writeln(""); } - private function check($output) + /** + * + */ + private function check() { $success = true; if (!file_exists($this->destination)) { - $output->writeln(' file: $this->destination does not exist!'); + $this->output->writeln(' file: $this->destination does not exist!'); $success = false; } foreach ($this->directories as $dir) { if (!file_exists($this->destination . $dir)) { - $output->writeln(' directory: ' . $dir . ' does not exist!'); + $this->output->writeln(' directory: ' . $dir . ' does not exist!'); $success = false; } } foreach ($this->mappings as $target => $link) { if (!file_exists($this->destination . $target)) { - $output->writeln(' mappings: ' . $target . ' does not exist!'); + $this->output->writeln(' mappings: ' . $target . ' does not exist!'); $success = false; } } if (!$success) { - $output->writeln(''); - $output->writeln('install should be run with --symlink|--s to symlink first'); + $this->output->writeln(''); + $this->output->writeln('install should be run with --symlink|--s to symlink first'); exit; } } - private function rcopy($src, $dest){ + /** + * @param $src + * @param $dest + * + * @return bool + */ + private function rcopy($src, $dest) + { // If the src is not a directory do a simple file copy - if(!is_dir($src)) { + if (!is_dir($src)) { copy($src, $dest); return true; } // If the destination directory does not exist create it - if(!is_dir($dest)) { - if(!mkdir($dest)) { - // If the destination directory could not be created stop processing + if (!is_dir($dest)) { + if (!mkdir($dest)) { + // If the destination directory could not be created stop processing return false; } } @@ -272,11 +345,13 @@ class SandboxCommand extends Command // Open the source directory to read in files $i = new \DirectoryIterator($src); /** @var \DirectoryIterator $f */ - foreach($i as $f) { - if($f->isFile()) { + foreach ($i as $f) { + if ($f->isFile()) { copy($f->getRealPath(), "$dest/" . $f->getFilename()); - } else if(!$f->isDot() && $f->isDir()) { - $this->rcopy($f->getRealPath(), "$dest/$f"); + } else { + if (!$f->isDot() && $f->isDir()) { + $this->rcopy($f->getRealPath(), "$dest/$f"); + } } } return true; diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 7770ecbbd..4ad07bc4b 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -5,19 +5,35 @@ use Grav\Common\GravTrait; use Grav\Console\Cli\ClearCacheCommand; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +/** + * Class ConsoleTrait + * @package Grav\Console + */ trait ConsoleTrait { use GravTrait; + /** + * @var + */ protected $argv; + + /* @var InputInterface $output */ protected $input; + + /* @var OutputInterface $output */ protected $output; /** * Set colors style definition for the formatter. + * + * @param InputInterface $input + * @param OutputInterface $output */ - public function setupConsole($input, $output) + public function setupConsole(InputInterface $input, OutputInterface $output) { if (self::$grav) { self::$grav['config']->set('system.cache.driver', 'default'); @@ -37,7 +53,10 @@ trait ConsoleTrait $this->output->getFormatter()->setStyle('white', new OutputFormatterStyle('white', null, array('bold'))); } - private function isGravInstance($path) + /** + * @param $path + */ + public function isGravInstance($path) { if (!file_exists($path)) { $this->output->writeln(''); @@ -64,6 +83,12 @@ trait ConsoleTrait } } + /** + * @param array $all + * + * @return int + * @throws \Exception + */ public function clearCache($all = []) { if ($all) { diff --git a/system/src/Grav/Console/Gpm/IndexCommand.php b/system/src/Grav/Console/Gpm/IndexCommand.php index 7f8b9a24a..12ac9a6b5 100644 --- a/system/src/Grav/Console/Gpm/IndexCommand.php +++ b/system/src/Grav/Console/Gpm/IndexCommand.php @@ -8,13 +8,26 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +/** + * Class IndexCommand + * @package Grav\Console\Gpm + */ class IndexCommand extends Command { use ConsoleTrait; + /** + * @var + */ protected $data; + /** + * @var + */ protected $gpm; + /** + * + */ protected function configure() { $this @@ -29,11 +42,17 @@ class IndexCommand extends Command ->setHelp('The index command lists the plugins and themes available for installation'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { $this->setupConsole($input, $output); - $this->gpm = new GPM($this->input->getOption('force')); + $this->gpm = new GPM($this->input->getOption('force')); $this->data = $this->gpm->getRepository(); @@ -45,8 +64,8 @@ class IndexCommand extends Command $index = 0; foreach ($packages as $slug => $package) { $this->output->writeln( - // index - str_pad($index+++1, 2, '0', STR_PAD_LEFT) . ". " . + // index + str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . ". " . // package name "" . str_pad($package->name, 15) . " " . // slug @@ -67,17 +86,22 @@ class IndexCommand extends Command $this->output->writeln(''); } + /** + * @param $package + * + * @return string + */ private function versionDetails($package) { - $list = $this->gpm->{'getUpdatable' . ucfirst($package->package_type)}(); - $package = isset($list[$package->slug]) ? $list[$package->slug] : $package; - $type = ucfirst(preg_replace("/s$/", '', $package->package_type)); + $list = $this->gpm->{'getUpdatable' . ucfirst($package->package_type)}(); + $package = isset($list[$package->slug]) ? $list[$package->slug] : $package; + $type = ucfirst(preg_replace("/s$/", '', $package->package_type)); $updatable = $this->gpm->{'is' . $type . 'Updatable'}($package->slug); $installed = $this->gpm->{'is' . $type . 'Installed'}($package->slug); - $local = $this->gpm->{'getInstalled' . $type}($package->slug); + $local = $this->gpm->{'getInstalled' . $type}($package->slug); if (!$installed || !$updatable) { - $version = $installed ? $local->version : $package->version; + $version = $installed ? $local->version : $package->version; $installed = !$installed ? ' (not installed)' : ' (installed)'; return str_pad(" [v" . $version . "]", 35) . $installed; @@ -86,8 +110,10 @@ class IndexCommand extends Command if ($updatable) { $installed = !$installed ? ' (not installed)' : ' (installed)'; - return str_pad(" [v" . $package->version . " ➜ v" . $package->available . "]", 61) . $installed; + return str_pad(" [v" . $package->version . " ➜ v" . $package->available . "]", + 61) . $installed; } + return ''; } } diff --git a/system/src/Grav/Console/Gpm/InfoCommand.php b/system/src/Grav/Console/Gpm/InfoCommand.php index 891ef1f01..721583032 100644 --- a/system/src/Grav/Console/Gpm/InfoCommand.php +++ b/system/src/Grav/Console/Gpm/InfoCommand.php @@ -9,13 +9,26 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +/** + * Class InfoCommand + * @package Grav\Console\Gpm + */ class InfoCommand extends Command { use ConsoleTrait; + /** + * @var + */ protected $data; + /** + * @var + */ protected $gpm; + /** + * + */ protected function configure() { $this @@ -35,6 +48,12 @@ class InfoCommand extends Command ->setHelp('The info shows more informations about a package'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { $this->setupConsole($input, $output); @@ -63,9 +82,22 @@ class InfoCommand extends Command $packageURL = '<' . $foundPackage->author->url . '>'; } - $this->output->writeln("".str_pad("Author", 12).": " . $foundPackage->author->name . ' <' . $foundPackage->author->email . '> '.$packageURL); + $this->output->writeln("" . str_pad("Author", + 12) . ": " . $foundPackage->author->name . ' <' . $foundPackage->author->email . '> ' . $packageURL); - foreach (array('version', 'keywords', 'date', 'homepage', 'demo', 'docs', 'guide', 'repository', 'bugs', 'zipball_url', 'license') as $info) { + foreach (array( + 'version', + 'keywords', + 'date', + 'homepage', + 'demo', + 'docs', + 'guide', + 'repository', + 'bugs', + 'zipball_url', + 'license' + ) as $info) { if (isset($foundPackage->$info)) { $name = ucfirst($info); $data = $foundPackage->$info; @@ -80,7 +112,7 @@ class InfoCommand extends Command } $name = str_pad($name, 12); - $this->output->writeln("".$name.": " . $data); + $this->output->writeln("" . $name . ": " . $data); } } diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php index aacfd3c86..bfccd68d6 100644 --- a/system/src/Grav/Console/Gpm/InstallCommand.php +++ b/system/src/Grav/Console/Gpm/InstallCommand.php @@ -13,16 +13,38 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; +/** + * Class InstallCommand + * @package Grav\Console\Gpm + */ class InstallCommand extends Command { use ConsoleTrait; + /** + * @var + */ protected $data; + /** + * @var + */ protected $gpm; + /** + * @var + */ protected $destination; + /** + * @var + */ protected $file; + /** + * @var + */ protected $tmp; + /** + * + */ protected function configure() { $this @@ -48,21 +70,27 @@ class InstallCommand extends Command ) ->addArgument( 'package', - InputArgument::IS_ARRAY|InputArgument::REQUIRED, + InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'The package of which more informations are desired. Use the "index" command for a list of packages' ) ->setDescription("Performs the installation of plugins and themes") ->setHelp('The install command allows to install plugins and themes'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { $this->setupConsole($input, $output); - $this->gpm = new GPM($this->input->getOption('force')); + $this->gpm = new GPM($this->input->getOption('force')); $this->destination = realpath($this->input->getOption('destination')); - $packages = array_map('strtolower', $this->input->getArgument('package')); + $packages = array_map('strtolower', $this->input->getArgument('package')); $this->data = $this->gpm->findPackages($packages); if ( @@ -82,7 +110,8 @@ class InstallCommand extends Command } if (count($this->data['not_found'])) { - $this->output->writeln("These packages were not found on Grav: " . implode(', ', $this->data['not_found']) . ""); + $this->output->writeln("These packages were not found on Grav: " . implode(', ', + $this->data['not_found']) . ""); } unset($this->data['not_found']); @@ -119,11 +148,16 @@ class InstallCommand extends Command $this->clearCache(); } + /** + * @param $package + * + * @return string + */ private function downloadPackage($package) { $this->tmp = CACHE_DIR . DS . 'tmp/Grav-' . uniqid(); $filename = $package->slug . basename($package->zipball_url); - $output = Response::get($package->zipball_url, [], [$this, 'progress']); + $output = Response::get($package->zipball_url, [], [$this, 'progress']); Folder::mkdir($this->tmp); @@ -136,10 +170,15 @@ class InstallCommand extends Command return $this->tmp . DS . $filename; } + /** + * @param $package + * + * @return bool + */ private function checkDestination($package) { $questionHelper = $this->getHelper('question'); - $skipPrompt = $this->input->getOption('all-yes'); + $skipPrompt = $this->input->getOption('all-yes'); Installer::isValidDestination($this->destination . DS . $package->install_path); @@ -148,8 +187,9 @@ class InstallCommand extends Command $this->output->write("\x0D"); $this->output->writeln(" |- Checking destination... exists"); - $question = new ConfirmationQuestion(" | '- The package has been detected as installed already, do you want to overwrite it? [y|N] ", false); - $answer = $questionHelper->ask($this->input, $this->output, $question); + $question = new ConfirmationQuestion(" | '- The package has been detected as installed already, do you want to overwrite it? [y|N] ", + false); + $answer = $questionHelper->ask($this->input, $this->output, $question); if (!$answer) { $this->output->writeln(" | '- You decided to not overwrite the already installed package."); @@ -169,8 +209,9 @@ class InstallCommand extends Command return false; } - $question = new ConfirmationQuestion(" | '- Destination has been detected as symlink, delete symbolic link first? [y|N] ", false); - $answer = $questionHelper->ask($this->input, $this->output, $question); + $question = new ConfirmationQuestion(" | '- Destination has been detected as symlink, delete symbolic link first? [y|N] ", + false); + $answer = $questionHelper->ask($this->input, $this->output, $question); if (!$answer) { $this->output->writeln(" | '- You decided to not delete the symlink automatically."); @@ -185,17 +226,22 @@ class InstallCommand extends Command return true; } + /** + * @param $package + * + * @return bool + */ private function installPackage($package) { - $installer = Installer::install($this->file, $this->destination, ['install_path' => $package->install_path]); - $errorCode = Installer::lastErrorCode(); + Installer::install($this->file, $this->destination, ['install_path' => $package->install_path]); + $errorCode = Installer::lastErrorCode(); Folder::delete($this->tmp); if ($errorCode & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) { $this->output->write("\x0D"); // extra white spaces to clear out the buffer properly $this->output->writeln(" |- Installing package... error "); - $this->output->writeln(" | '- " . $installer->lastErrorMsg()); + $this->output->writeln(" | '- " . Installer::lastErrorMsg()); return false; } @@ -207,9 +253,13 @@ class InstallCommand extends Command return true; } + /** + * @param $progress + */ public function progress($progress) { $this->output->write("\x0D"); - $this->output->write(" |- Downloading package... " . str_pad($progress['percent'], 5, " ", STR_PAD_LEFT) . '%'); + $this->output->write(" |- Downloading package... " . str_pad($progress['percent'], 5, " ", + STR_PAD_LEFT) . '%'); } } diff --git a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php index 455eea9b9..a6cd5b743 100644 --- a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php +++ b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php @@ -2,9 +2,9 @@ namespace Grav\Console\Gpm; use Grav\Common\Filesystem\Folder; -use Grav\Common\GPM\Upgrader; use Grav\Common\GPM\Installer; use Grav\Common\GPM\Response; +use Grav\Common\GPM\Upgrader; use Grav\Console\ConsoleTrait; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -12,16 +12,46 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; +/** + * Class SelfupgradeCommand + * @package Grav\Console\Gpm + */ class SelfupgradeCommand extends Command { use ConsoleTrait; + /** + * @var + */ protected $data; + /** + * @var + */ protected $extensions; + /** + * @var + */ protected $updatable; + /** + * @var + */ protected $file; + /** + * @var array + */ protected $types = array('plugins', 'themes'); + /** + * @var + */ + private $tmp; + /** + * @var + */ + private $upgrader; + /** + * + */ protected function configure() { $this @@ -43,14 +73,20 @@ class SelfupgradeCommand extends Command ->setHelp('The update command updates plugins and themes when a new version is available'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { $this->setupConsole($input, $output); $this->upgrader = new Upgrader($this->input->getOption('force')); - $local = $this->upgrader->getLocalVersion(); - $remote = $this->upgrader->getRemoteVersion(); - $update = $this->upgrader->getAssets()->{'grav-update'}; + $local = $this->upgrader->getLocalVersion(); + $remote = $this->upgrader->getRemoteVersion(); + $update = $this->upgrader->getAssets()->{'grav-update'}; $release = strftime('%c', strtotime($this->upgrader->getReleaseDate())); if (!$this->upgrader->isUpgradable()) { @@ -59,14 +95,15 @@ class SelfupgradeCommand extends Command } $questionHelper = $this->getHelper('question'); - $skipPrompt = $this->input->getOption('all-yes'); + $skipPrompt = $this->input->getOption('all-yes'); $this->output->writeln("Grav v$remote is now available [release date: $release]."); - $this->output->writeln("You are currently using v".GRAV_VERSION."."); + $this->output->writeln("You are currently using v" . GRAV_VERSION . "."); if (!$skipPrompt) { - $question = new ConfirmationQuestion("Would you like to read the changelog before proceeding? [y|N] ", false); - $answer = $questionHelper->ask($this->input, $this->output, $question); + $question = new ConfirmationQuestion("Would you like to read the changelog before proceeding? [y|N] ", + false); + $answer = $questionHelper->ask($this->input, $this->output, $question); if ($answer) { $changelog = $this->upgrader->getChangelog(GRAV_VERSION); @@ -74,8 +111,8 @@ class SelfupgradeCommand extends Command $this->output->writeln(""); foreach ($changelog as $version => $log) { $title = $version . ' [' . $log->date . ']'; - $content = preg_replace_callback("/\d\.\s\[\]\(#(.*)\)/", function($match){ - return "\n".ucfirst($match[1]).":"; + $content = preg_replace_callback("/\d\.\s\[\]\(#(.*)\)/", function ($match) { + return "\n" . ucfirst($match[1]) . ":"; }, $log->content); $this->output->writeln($title); @@ -89,7 +126,7 @@ class SelfupgradeCommand extends Command } $question = new ConfirmationQuestion("Would you like to upgrade now? [y|N] ", false); - $answer = $questionHelper->ask($this->input, $this->output, $question); + $answer = $questionHelper->ask($this->input, $this->output, $question); if (!$answer) { $this->output->writeln("Aborting..."); @@ -116,13 +153,18 @@ class SelfupgradeCommand extends Command } // clear cache after successful upgrade - $this->clearCache(true); + $this->clearCache('all'); } + /** + * @param $package + * + * @return string + */ private function download($package) { $this->tmp = CACHE_DIR . DS . 'tmp/Grav-' . uniqid(); - $output = Response::get($package->download, [], [$this, 'progress']); + $output = Response::get($package->download, [], [$this, 'progress']); Folder::mkdir($this->tmp); @@ -135,17 +177,21 @@ class SelfupgradeCommand extends Command return $this->tmp . DS . $package->name; } + /** + * @return bool + */ private function upgrade() { - $installer = Installer::install($this->file, GRAV_ROOT, ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true]); - $errorCode = Installer::lastErrorCode(); + Installer::install($this->file, GRAV_ROOT, + ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true]); + $errorCode = Installer::lastErrorCode(); Folder::delete($this->tmp); if ($errorCode & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) { $this->output->write("\x0D"); // extra white spaces to clear out the buffer properly $this->output->writeln(" |- Installing upgrade... error "); - $this->output->writeln(" | '- " . $installer->lastErrorMsg()); + $this->output->writeln(" | '- " . Installer::lastErrorMsg()); return false; } @@ -157,17 +203,27 @@ class SelfupgradeCommand extends Command return true; } + /** + * @param $progress + */ public function progress($progress) { $this->output->write("\x0D"); - $this->output->write(" |- Downloading upgrade [" . $this->formatBytes($progress["filesize"]) . "]... " . str_pad($progress['percent'], 5, " ", STR_PAD_LEFT) . '%'); + $this->output->write(" |- Downloading upgrade [" . $this->formatBytes($progress["filesize"]) . "]... " . str_pad($progress['percent'], + 5, " ", STR_PAD_LEFT) . '%'); } + /** + * @param $size + * @param int $precision + * + * @return string + */ public function formatBytes($size, $precision = 2) { $base = log($size) / log(1024); $suffixes = array('', 'k', 'M', 'G', 'T'); - return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)]; + return round(pow(1024, $base - floor($base)), $precision) . $suffixes[(int)floor($base)]; } } diff --git a/system/src/Grav/Console/Gpm/UpdateCommand.php b/system/src/Grav/Console/Gpm/UpdateCommand.php index 451a3e79a..bc987d52e 100644 --- a/system/src/Grav/Console/Gpm/UpdateCommand.php +++ b/system/src/Grav/Console/Gpm/UpdateCommand.php @@ -12,17 +12,46 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; +/** + * Class UpdateCommand + * @package Grav\Console\Gpm + */ class UpdateCommand extends Command { use ConsoleTrait; + /** + * @var + */ protected $data; + /** + * @var + */ protected $extensions; + /** + * @var + */ protected $updatable; + /** + * @var + */ protected $destination; + /** + * @var + */ protected $file; + /** + * @var array + */ protected $types = array('plugins', 'themes'); + /** + * @var GPM $gpm + */ + protected $gpm; + /** + * + */ protected function configure() { $this @@ -42,18 +71,24 @@ class UpdateCommand extends Command ) ->addArgument( 'package', - InputArgument::IS_ARRAY|InputArgument::OPTIONAL, + InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'The package or packages that is desired to update. By default all available updates will be applied.' ) ->setDescription("Detects and performs an update of plugins and themes when available") ->setHelp('The update command updates plugins and themes when a new version is available'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ protected function execute(InputInterface $input, OutputInterface $output) { $this->setupConsole($input, $output); - $this->gpm = new GPM($this->input->getOption('force')); + $this->gpm = new GPM($this->input->getOption('force')); $this->destination = realpath($this->input->getOption('destination')); if (!Installer::isGravInstance($this->destination)) { @@ -61,7 +96,7 @@ class UpdateCommand extends Command exit; } - $this->data = $this->gpm->getUpdatable(); + $this->data = $this->gpm->getUpdatable(); $onlyPackages = array_map('strtolower', $this->input->getArgument('package')); if (!$this->data['total']) { @@ -90,7 +125,7 @@ class UpdateCommand extends Command } $this->output->writeln( - // index + // index str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . ". " . // name "" . str_pad($package->name, 15) . " " . @@ -104,8 +139,8 @@ class UpdateCommand extends Command // prompt to continue $this->output->writeln(""); $questionHelper = $this->getHelper('question'); - $question = new ConfirmationQuestion("Continue with the update process? [Y|n] ", true); - $answer = $questionHelper->ask($this->input, $this->output, $question); + $question = new ConfirmationQuestion("Continue with the update process? [Y|n] ", true); + $answer = $questionHelper->ask($this->input, $this->output, $question); if (!$answer) { $this->output->writeln("Update aborted. Exiting..."); @@ -115,13 +150,13 @@ class UpdateCommand extends Command // finally update $installCommand = $this->getApplication()->find('install'); - $args = new ArrayInput(array( - 'command' => 'install', - 'package' => $slugs, - '-f' => $this->input->getOption('force'), - '-d' => $this->destination, - '-y' => true - )); + $args = new ArrayInput(array( + 'command' => 'install', + 'package' => $slugs, + '-f' => $this->input->getOption('force'), + '-d' => $this->destination, + '-y' => true + )); $commandExec = $installCommand->run($args, $this->output); if ($commandExec != 0) { @@ -133,9 +168,14 @@ class UpdateCommand extends Command $this->clearCache(); } + /** + * @param $onlyPackages + * + * @return array + */ private function userInputPackages($onlyPackages) { - $found = ['total' => 0]; + $found = ['total' => 0]; $ignore = []; if (!count($onlyPackages)) { @@ -159,15 +199,17 @@ class UpdateCommand extends Command $list = array_keys($list); if ($found['total'] !== $this->data['total']) { - $this->output->write(", only ".$found['total']." will be updated"); + $this->output->write(", only " . $found['total'] . " will be updated"); } $this->output->writeln(''); - $this->output->writeln("Limiting updates for only ".implode(', ', $list).""); + $this->output->writeln("Limiting updates for only " . implode(', ', + $list) . ""); } if (count($ignore)) { - $this->output->writeln("Packages not found or not requiring updates: ".implode(', ', $ignore).""); + $this->output->writeln("Packages not found or not requiring updates: " . implode(', ', + $ignore) . ""); } } From 3f6b5e35de73fdf63f7efdefbdce50c3b60ddc49 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Tue, 14 Oct 2014 12:45:10 -0700 Subject: [PATCH 14/58] Added new GPM version command that allows to ask for the version of the Grav instance as well as any installed package. It also supports multiple arguments and if an update is available it will be shown --- bin/gpm | 1 + .../src/Grav/Console/Gpm/VersionCommand.php | 95 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 system/src/Grav/Console/Gpm/VersionCommand.php diff --git a/bin/gpm b/bin/gpm index 9a5ad34c2..11d66ac99 100755 --- a/bin/gpm +++ b/bin/gpm @@ -34,6 +34,7 @@ $grav['themes']->init(); $app = new Application('Grav Package Manager', GRAV_VERSION); $app->addCommands(array( new \Grav\Console\Gpm\IndexCommand(), + new \Grav\Console\Gpm\VersionCommand(), new \Grav\Console\Gpm\InfoCommand(), new \Grav\Console\Gpm\InstallCommand(), new \Grav\Console\Gpm\UpdateCommand(), diff --git a/system/src/Grav/Console/Gpm/VersionCommand.php b/system/src/Grav/Console/Gpm/VersionCommand.php new file mode 100644 index 000000000..44b31efba --- /dev/null +++ b/system/src/Grav/Console/Gpm/VersionCommand.php @@ -0,0 +1,95 @@ +setName("version") + ->addOption( + 'force', + 'f', + InputOption::VALUE_NONE, + 'Force re-fetching the data from remote' + ) + ->addArgument( + 'package', + InputArgument::IS_ARRAY | InputArgument::OPTIONAL, + 'The package or packages that is desired to know the version of. By default and if not specified this would be grav' + ) + ->setDescription("Shows the version of an installed package. If available also shows pending updates.") + ->setHelp('The version command displays the current version of a package installed and, if available, the available version of pending updates'); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->setupConsole($input, $output); + + $this->gpm = new GPM($this->input->getOption('force')); + $packages = $this->input->getArgument('package'); + + if (!count($packages)) { + $packages = ['grav']; + } + + foreach ($packages as $package) { + $package = strtolower($package); + $name = null; + $version = null; + $updatable = false; + + if ($package == 'grav') { + $name = 'Grav'; + $version = GRAV_VERSION; + $upgrader = new Upgrader(); + + if ($upgrader->isUpgradable()) { + $updatable = ' [upgradable: v' . $upgrader->getRemoteVersion() . ']'; + } + + } else { + if ($installed = $this->gpm->findPackage($package)) { + $name = $installed->name; + $version = $installed->version; + + if ($this->gpm->isUpdatable($package)) { + $updatable = ' [updatable: v' . $installed->available . ']'; + } + } + } + + $updatable = $updatable ?: ''; + $this->output->writeln('You are running ' . $name . ' v' . $version . '' . $updatable); + } + } +} From 19bbfd0a50127012a8b4620049df6d5364c8ace5 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Tue, 14 Oct 2014 13:13:55 -0700 Subject: [PATCH 15/58] Cleanup --- system/src/Grav/Common/Page/Pages.php | 6 ++---- system/src/Grav/Common/TwigExtension.php | 7 ++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 4570fde09..23e30792f 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -62,7 +62,7 @@ class Pages /** * Constructor * - * @params Grav $c + * @param Grav $c */ public function __construct(Grav $c) { @@ -391,8 +391,6 @@ class Pages /** @var Taxonomy $taxonomy */ $taxonomy = $this->grav['taxonomy']; - $last_modified = 0; - // how should we check for last modified? Default is by file switch (strtolower($config->get('system.cache.check.method', 'file'))) { case 'none': @@ -432,7 +430,7 @@ class Pages * Recursive function to load & build page relationships. * * @param string $directory - * @param null $parent + * @param Page|null $parent * @return Page * @throws \RuntimeException * @internal diff --git a/system/src/Grav/Common/TwigExtension.php b/system/src/Grav/Common/TwigExtension.php index 3fec76e60..7ef453a97 100644 --- a/system/src/Grav/Common/TwigExtension.php +++ b/system/src/Grav/Common/TwigExtension.php @@ -225,9 +225,10 @@ class TwigExtension extends \Twig_Extension /** * Sorts a collection by key * - * @param string $input - * @param string $filter - * @param string $direction + * @param array $input + * @param string $filter + * @param array|int $direction + * * @return string */ public function sortByKeyFilter($input, $filter, $direction = SORT_ASC) From c10882f290a93eaa28c4639a7d4bab043c8c65e0 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Oct 2014 15:42:25 -0600 Subject: [PATCH 16/58] Added Whoops --- composer.json | 2 +- index.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 69bdbafd0..91f24f6bf 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ "symfony/console": "~2.5", "symfony/event-dispatcher": "~2.5", "doctrine/cache": "~1.3", - "tracy/tracy": "2.3.*@dev", "maximebf/debugbar": ">=1.0.0", + "filp/whoops": "1.2.*@dev", "gregwar/image": "~2.0", "ircmaxell/password-compat": "1.0.*", "mrclay/minify": "dev-master", diff --git a/index.php b/index.php index cf2644f6c..a2964ed9f 100644 --- a/index.php +++ b/index.php @@ -15,6 +15,12 @@ use Grav\Common\Grav; // Register the auto-loader. $loader = require_once $autoload; +// Setup Whoops error handler +$whoops = new \Whoops\Run; +$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); +$whoops->register(); + + if (!ini_get('date.timezone')) { date_default_timezone_set('UTC'); } From 5134b28bad2447d5bbadaab33c163536490ff2cb Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Oct 2014 15:45:17 -0600 Subject: [PATCH 17/58] Potential improvement of .htaccess --- .htaccess | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.htaccess b/.htaccess index 0419abea4..d772e8f0d 100755 --- a/.htaccess +++ b/.htaccess @@ -11,27 +11,27 @@ RewriteEngine On # RewriteBase / -# Access site +# access site RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php [L] -# Block various user files from being accessed directly -RewriteRule ^user/accounts/(.*)$ error [R=301,L] -RewriteRule ^user/config/(.*)$ error [R=301,L] -RewriteRule ^user/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ error [R=301,L] +# block various user files from being accessed directly +RewriteRule ^user/accounts/(.*)$ error [L] +RewriteRule ^user/config/(.*)$ error [L] +RewriteRule ^user/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ error [L] -# Block cache/ -RewriteRule ^cache/(.*) error [R=301,L] +# block cache +RewriteRule ^cache/(.*) error [L] -# Block bin/ -RewriteRule ^bin/(.*)$ error [R=301,L] +# block bin +RewriteRule ^bin/(.*)$ error [L] -# Block system/ -RewriteRule ^system/(.*)$ error [R=301,L] +# block system +RewriteRule ^system/(.*)\.(txt|md|html|php|sh|bat|yaml)$ error [L] -# Block vendor/ -# RewriteRule ^vendor/(.*)$ error [R=301,L] +# block vendor (non CSS/JS) +RewriteRule ^vendor/(.*)\.(txt|md|htmlphp|sh|bat|yaml)$ error [L] From 783d1485513397c5358b3148e97688716bbde3c6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Oct 2014 17:26:14 -0600 Subject: [PATCH 18/58] Debugger style overrides --- system/assets/debugger.css | 47 ++++++++++++++++++++++++++++ system/assets/grav.png | Bin 0 -> 548 bytes system/src/Grav/Common/Debugger.php | 2 ++ 3 files changed, 49 insertions(+) create mode 100644 system/assets/debugger.css create mode 100644 system/assets/grav.png diff --git a/system/assets/debugger.css b/system/assets/debugger.css new file mode 100644 index 000000000..a53eff71e --- /dev/null +++ b/system/assets/debugger.css @@ -0,0 +1,47 @@ +div.phpdebugbar { + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; +} + +.phpdebugbar div.phpdebugbar-header > div > * { + padding: 5px 15px; +} + +.phpdebugbar div.phpdebugbar-header > div.phpdebugbar-header-right > * { + padding: 5px 8px; +} + +.phpdebugbar div.phpdebugbar-header, .phpdebugbar a.phpdebugbar-restore-btn { + background-image: url(grav.png); +} + +.phpdebugbar a.phpdebugbar-restore-btn { + width: 13px; +} + +.phpdebugbar a.phpdebugbar-tab.phpdebugbar-active { + background: #3DB9EC; + color: #fff; + margin-top: -1px; + padding-top: 6px; +} + +.phpdebugbar .phpdebugbar-widgets-toolbar { + padding-left: 5px; +} + +.phpdebugbar input[type=text] { + padding: 0; + display: inline; +} + +.phpdebugbar dl.phpdebugbar-widgets-varlist, ul.phpdebugbar-widgets-timeline li span.phpdebugbar-widgets-label { + font-family: "DejaVu Sans Mono", Menlo, Monaco, Consolas, Courier, monospace; + font-size: 12px; +} + + + +.phpdebugbar pre, .phpdebugbar code { + margin: 0; + font-size: 14px; +} diff --git a/system/assets/grav.png b/system/assets/grav.png new file mode 100644 index 0000000000000000000000000000000000000000..3379934675630df9f249bb6740691f1480d13e78 GIT binary patch literal 548 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+3?vf;>QaFebFq_W2nPqp?T7vkfZU1zpAgso z|NsB~{rmIh&#zv+di3bgy?ghrUAuPa(xp?UP8~gZbno81TeogqyLRn@1qN}=VxbUr>CbUCnv|p$45m)g@uLr`T2QydAYf{ zIXOAm+1XiHS(%!e8X6kv>gob5y?LQs1?UEik|4ieAeR`xuy2)~1W*rWfk$L90|Vb2 z5N2eb5_}gZC{yAZQ4*Y=R#Ki=l*-_klAn~S;FejGTAp8&U98|7Z1!T$rXHX=5s*6P zqSVBa%=|oskj&gv26KH&eM6HKs@j%7`Qx50jv*3Lb0^#_YcddMaSxmrbkL0LsJzi^ z-cSGXU$EVZ`(hz(X?fo>EnV#Lnp5o$RzK~lnX?*6-$d`l z8H2YcuH+|Z?dyHZQ+ez**XsVNX0?fRPNFMRyN+9Y@;;**@bP0l+XkKVe0xy literal 0 HcmV?d00001 diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index c2c09a2ac..6f485d396 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -48,6 +48,8 @@ class Debugger $assets->addCss($css); } + $assets->addCss('/system/assets/debugger.css'); + foreach ($js_files as $js) { $assets->addJs($js); } From 67484a1a90ad032b73b5ac9a250cd70001298817 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Oct 2014 17:27:14 -0600 Subject: [PATCH 19/58] typo in .htaccess --- .htaccess | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.htaccess b/.htaccess index d772e8f0d..f5c4adce4 100755 --- a/.htaccess +++ b/.htaccess @@ -31,7 +31,7 @@ RewriteRule ^bin/(.*)$ error [L] RewriteRule ^system/(.*)\.(txt|md|html|php|sh|bat|yaml)$ error [L] # block vendor (non CSS/JS) -RewriteRule ^vendor/(.*)\.(txt|md|htmlphp|sh|bat|yaml)$ error [L] +RewriteRule ^vendor/(.*)\.(txt|md|html|php|sh|bat|yaml)$ error [L] From a7176c4a6eae2dfb13182a4cd2b482c700419e9f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Oct 2014 19:05:42 -0600 Subject: [PATCH 20/58] color styling for whoops --- index.php | 9 +++- system/assets/whoops.css | 95 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 system/assets/whoops.css diff --git a/index.php b/index.php index a2964ed9f..f624b2e6a 100644 --- a/index.php +++ b/index.php @@ -17,7 +17,14 @@ $loader = require_once $autoload; // Setup Whoops error handler $whoops = new \Whoops\Run; -$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); + +$error_page = new \Whoops\Handler\PrettyPageHandler; +$error_page->setPageTitle('Crikey! There was an error...'); +$error_page->setEditor('sublime'); +$error_page->addResourcePath(__DIR__ .'/system/assets'); +$error_page->addCustomCss('whoops.css'); + +$whoops->pushHandler($error_page); $whoops->register(); diff --git a/system/assets/whoops.css b/system/assets/whoops.css new file mode 100644 index 000000000..599e8e039 --- /dev/null +++ b/system/assets/whoops.css @@ -0,0 +1,95 @@ +body { + background-color: #eee; +} + +body header { + background: #349886; + border-left: 8px solid #29796B; +} + +body .exc-title-primary { + color: #1C3631; + text-shadow: none; +} + +body .exc-title { + color: #2F5B52; + text-shadow: none; +} + +body .data-table-container label, body .frame-class { + color: #0082BA; +} + +body .active .frame-class { + color: #E1F0F4; +} + +body .frame { + border: 0; +} + +body .frame.active { + border: 0; + box-shadow: none; + background-color: #2693B7; +} + +body .frame:not(.active):hover { + background: #D4E3E7; +} + +body .frame-file, body .data-table tbody { + font-family: "DejaVu Sans Mono", Menlo, Monaco, Consolas, Courier, monospace; + font-size: 13px; +} + +body .frame-code { + background: #305669; + border-left: 8px solid #253A47; + padding: 1rem; +} + +body .frame-code .frame-file { + background: #253A47; + color: #eee; + text-shadow: none; + box-shadow: none; + font-family: inherit; +} + +body .frame-code .frame-file strong { + color: #fff; + font-weight: normal; +} + +body .frame-comments { + background: #283E4D; + + box-shadow: none; +} + +body .frame-comments.empty:before { + color: #789AAB; +} + +body .details-container { + border: 0; +} + +body .details { + background-color: #eee; + border-left: 8px solid #ddd; + padding: 1rem; +} + +body .code-block { + background: #2C4454; + box-shadow: none; + font-family: "DejaVu Sans Mono", Menlo, Monaco, Consolas, Courier, monospace; + font-size: 13px; +} + +body .handler.active { + background: #666; +} From 6be04d64061bede053d412744100047d0cf410f3 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Oct 2014 21:46:51 -0600 Subject: [PATCH 21/58] Fix for non-transparent clipboard icon --- system/assets/whoops.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/system/assets/whoops.css b/system/assets/whoops.css index 599e8e039..2f31227e2 100644 --- a/system/assets/whoops.css +++ b/system/assets/whoops.css @@ -7,6 +7,12 @@ body header { border-left: 8px solid #29796B; } +body .clipboard { + width: 28px; + height: 28px; + background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcAQMAAABIw03XAAAAA3NCSVQICAjb4U/gAAAABlBMVEX///////9VfPVsAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAAcdEVYdFNvZnR3YXJlAEFkb2JlIEZpcmV3b3JrcyBDUzbovLKMAAAAFnRFWHRDcmVhdGlvbiBUaW1lADEwLzE1LzE0xr/LJAAAADhJREFUCJlj+P///wcGBPGDQR5E8OMi2IEEczOIaAQRHSCioQBGHAAR/7AT/z+DiA8MMALVXhABAJf9Sr5aY+UFAAAAAElFTkSuQmCC); +} + body .exc-title-primary { color: #1C3631; text-shadow: none; From 01467e1b325f830670335aa5fef5f472ef28eaa6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 14 Oct 2014 21:54:39 -0600 Subject: [PATCH 22/58] side panel now purple --- system/assets/whoops.css | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/system/assets/whoops.css b/system/assets/whoops.css index 2f31227e2..4e90ffc70 100644 --- a/system/assets/whoops.css +++ b/system/assets/whoops.css @@ -23,26 +23,30 @@ body .exc-title { text-shadow: none; } -body .data-table-container label, body .frame-class { +body .data-table-container label { color: #0082BA; } -body .active .frame-class { - color: #E1F0F4; -} - body .frame { border: 0; } +body .active .frame-class { + color: #E3D8E9; +} + +body .frame-class { + color: #9055AF; +} + body .frame.active { border: 0; box-shadow: none; - background-color: #2693B7; + background-color: #9055AF; } body .frame:not(.active):hover { - background: #D4E3E7; + background: #e9e9e9; } body .frame-file, body .data-table tbody { From 5586c1923ca34ed7e5fcdb0c6ca4514b1435fc3e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 15 Oct 2014 11:56:09 +0300 Subject: [PATCH 23/58] Move Whoops code into its proper place and implement ajax support for json files --- index.php | 13 -------- system/src/Grav/Common/Grav.php | 3 ++ .../Common/Service/ErrorServiceProvider.php | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 system/src/Grav/Common/Service/ErrorServiceProvider.php diff --git a/index.php b/index.php index f624b2e6a..cf2644f6c 100644 --- a/index.php +++ b/index.php @@ -15,19 +15,6 @@ use Grav\Common\Grav; // Register the auto-loader. $loader = require_once $autoload; -// Setup Whoops error handler -$whoops = new \Whoops\Run; - -$error_page = new \Whoops\Handler\PrettyPageHandler; -$error_page->setPageTitle('Crikey! There was an error...'); -$error_page->setEditor('sublime'); -$error_page->addResourcePath(__DIR__ .'/system/assets'); -$error_page->addCustomCss('whoops.css'); - -$whoops->pushHandler($error_page); -$whoops->register(); - - if (!ini_get('date.timezone')) { date_default_timezone_set('UTC'); } diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index db5392e4b..eaa4e2da0 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -3,6 +3,7 @@ namespace Grav\Common; use Grav\Common\Page\Pages; use Grav\Common\Service\ConfigServiceProvider; +use Grav\Common\Service\ErrorServiceProvider; use Grav\Common\Service\StreamsServiceProvider; use RocketTheme\Toolbox\DI\Container; use RocketTheme\Toolbox\Event\Event; @@ -56,6 +57,8 @@ class Grav extends Container $container['debugger'] = new Debugger(); $container['debugger']->startTimer('_init', 'Init'); + $container->register(new ErrorServiceProvider); + $container['uri'] = function ($c) { return new Uri($c); }; diff --git a/system/src/Grav/Common/Service/ErrorServiceProvider.php b/system/src/Grav/Common/Service/ErrorServiceProvider.php new file mode 100644 index 000000000..085fe6c0d --- /dev/null +++ b/system/src/Grav/Common/Service/ErrorServiceProvider.php @@ -0,0 +1,32 @@ +setPageTitle('Crikey! There was an error...'); + $error_page->setEditor('sublime'); + $error_page->addResourcePath(GRAV_ROOT . '/system/assets'); + $error_page->addCustomCss('whoops.css'); + + $json_page = new JsonResponseHandler; + $json_page->onlyForAjaxRequests(true); + + $whoops->pushHandler($error_page); + $whoops->pushHandler($json_page); + $whoops->register(); + + $container['whoops'] = $whoops; + } +} From a66fede72d88f7f6eb88718bdac11ac31b91fbe0 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 15 Oct 2014 21:34:32 -0600 Subject: [PATCH 24/58] wrapping fix --- system/assets/whoops.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/system/assets/whoops.css b/system/assets/whoops.css index 4e90ffc70..6362d527c 100644 --- a/system/assets/whoops.css +++ b/system/assets/whoops.css @@ -31,6 +31,11 @@ body .frame { border: 0; } +body .frames-container { + overflow-y: auto; + overflow-x: hidden; +} + body .active .frame-class { color: #E3D8E9; } From 8aec9f7c15353351ac694a72f32e2949fa02bd66 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 16 Oct 2014 11:34:17 +0300 Subject: [PATCH 25/58] Improve and optimize configuration loading --- system/config/streams.yaml | 5 - system/src/Grav/Common/Config/Config.php | 235 ++++-------------- .../src/Grav/Common/Config/ConfigFinder.php | 146 +++++++++++ system/src/Grav/Common/File/CompiledFile.php | 5 + system/src/Grav/Common/Grav.php | 6 + .../Common/Service/StreamsServiceProvider.php | 32 ++- 6 files changed, 219 insertions(+), 210 deletions(-) create mode 100644 system/src/Grav/Common/Config/ConfigFinder.php diff --git a/system/config/streams.yaml b/system/config/streams.yaml index e7ac27c5b..a38b5805e 100644 --- a/system/config/streams.yaml +++ b/system/config/streams.yaml @@ -18,8 +18,3 @@ schemes: type: ReadOnlyStream paths: - user://accounts - - data: - type: ReadOnlyStream - paths: - - user://data diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index 2584e9df5..67762e0b6 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -80,10 +80,14 @@ class Config extends Data protected $blueprintLookup; protected $pluginLookup; + protected $finder; + + protected $messages = []; public function __construct(array $items = array(), Grav $grav = null) { $this->grav = $grav ?: Grav::instance(); + $this->finder = new ConfigFinder; if (isset($items['@class'])) { if ($items['@class'] != get_class($this)) { @@ -91,7 +95,7 @@ class Config extends Data } // Loading pre-compiled configuration. $this->timestamp = (int) $items['timestamp']; - $this->checksum = (string) $items['checksum']; + $this->checksum = $items['checksum']; $this->items = (array) $items['data']; } else { // Make sure that @@ -132,6 +136,13 @@ class Config extends Data } } + public function debug() + { + foreach ($this->messages as $message) { + $this->grav['debugger']->addMessage($message); + } + } + public function init() { /** @var UniformResourceLocator $locator */ @@ -141,13 +152,15 @@ class Config extends Data $this->blueprintLookup = $locator->findResources('blueprints://config'); $this->pluginLookup = $locator->findResources('plugins://'); - $checksum = $this->checksum(); - if ($checksum == $this->checksum) { + if (!isset($this->checksum)) { + $this->messages[] = 'No cached configuration, compiling new configuration..'; + } elseif ($this->checksum() != $this->checksum) { + $this->messages[] = 'Configuration checksum mismatch, reloading configuration..'; + } else { + $this->messages[] = 'Configuration checksum matches, using cached version.'; return; } - $this->checksum = $checksum; - /** @var Uri $uri */ $uri = $this->grav['uri']; @@ -166,18 +179,27 @@ class Config extends Data $checkSystem = $this->get('system.cache.check.system', true); if (!$checkBlueprints && !$checkConfig && !$checkSystem) { + $this->messages[] = 'Skip configuration timestamp check.'; return false; } // Generate checksum according to the configuration settings. if (!$checkConfig) { + $this->messages[] = 'Check configuration timestamps from system.yaml files.'; // Just check changes in system.yaml files and ignore all the other files. - $cc = $checkSystem ? $this->detectFile($this->configLookup, 'system') : []; + $cc = $checkSystem ? $this->finder->locateConfigFile($this->configLookup, 'system') : []; } else { + $this->messages[] = 'Check configuration timestamps from all configuration files.'; // Check changes in all configuration files. - $cc = $this->getConfigFiles($this->configLookup, $this->pluginLookup); + $cc = $this->finder->locateConfigFiles($this->configLookup, $this->pluginLookup); + } + + if ($checkBlueprints) { + $this->messages[] = 'Check blueprint timestamps from all blueprint files.'; + $cb = $this->finder->locateBlueprintFiles($this->blueprintLookup, $this->pluginLookup); + } else { + $cb = []; } - $cb = $checkBlueprints ? $this->getBlueprintFiles($this->blueprintLookup, $this->pluginLookup) : []; return md5(json_encode([$cc, $cb])); } @@ -189,14 +211,8 @@ class Config extends Data ? CACHE_DIR . 'compiled/blueprints/' . $filename .'.php' : CACHE_DIR . 'compiled/blueprints/' . $checksum .'.php'; $file = PhpFile::instance($filename); - - if ($file->exists()) { - $cache = $file->exists() ? $file->content() : null; - } else { - $cache = null; - } - - $blueprintFiles = $this->getBlueprintFiles($blueprints, $plugins); + $cache = $file->exists() ? $file->content() : null; + $blueprintFiles = $this->finder->locateBlueprintFiles($blueprints, $plugins); $checksum .= ':'.md5(json_encode($blueprintFiles)); $class = get_class($this); @@ -213,8 +229,8 @@ class Config extends Data // Load blueprints. $this->blueprints = new Blueprints; - foreach ($blueprintFiles as $key => $files) { - $this->loadBlueprints($key); + foreach ($blueprintFiles as $files) { + $this->loadBlueprintFiles($files); } $cache = [ @@ -226,6 +242,7 @@ class Config extends Data // If compiled file wasn't already locked by another process, save it. if ($file->locked() !== false) { + $this->messages[] = 'Saving compiled blueprints.'; $file->save($cache); $file->unlock(); } @@ -241,14 +258,8 @@ class Config extends Data ? CACHE_DIR . 'compiled/config/' . $filename .'.php' : CACHE_DIR . 'compiled/config/' . $checksum .'.php'; $file = PhpFile::instance($filename); - - if ($file->exists()) { - $cache = $file->exists() ? $file->content() : null; - } else { - $cache = null; - } - - $configFiles = $this->getConfigFiles($configs, $plugins); + $cache = $file->exists() ? $file->content() : null; + $configFiles = $this->finder->locateConfigFiles($configs, $plugins); $checksum .= ':'.md5(json_encode($configFiles)); $class = get_class($this); @@ -262,18 +273,19 @@ class Config extends Data $file->lock(false); // Load configuration. - foreach ($configFiles as $key => $files) { - $this->loadConfig($key); + foreach ($configFiles as $files) { + $this->loadConfigFiles($files); } $cache = [ '@class' => $class, 'timestamp' => time(), - 'checksum' => $this->checksum, + 'checksum' => $this->checksum(), 'data' => $this->toArray() ]; // If compiled file wasn't already locked by another process, save it. if ($file->locked() !== false) { + $this->messages[] = 'Saving compiled configuration.'; $file->save($cache); $file->unlock(); } @@ -283,16 +295,12 @@ class Config extends Data } /** - * Load global blueprints. + * Load blueprints. * - * @param string $key - * @param array $files + * @param array $files */ - public function loadBlueprints($key, array $files = null) + public function loadBlueprintFiles(array $files) { - if (is_null($files)) { - $files = $this->blueprintFiles[$key]; - } foreach ($files as $name => $item) { $file = CompiledYamlFile::instance($item['file']); $this->blueprints->embed($name, $file->content(), '/'); @@ -300,164 +308,15 @@ class Config extends Data } /** - * Load global configuration. + * Load configuration. * - * @param string $key - * @param array $files + * @param array $files */ - public function loadConfig($key, array $files = null) + public function loadConfigFiles(array $files) { - if (is_null($files)) { - $files = $this->configFiles[$key]; - } foreach ($files as $name => $item) { $file = CompiledYamlFile::instance($item['file']); $this->join($name, $file->content(), '/'); } } - - /** - * Get all blueprint files (including plugins). - * - * @param array $blueprints - * @param array $plugins - * @return array - */ - protected function getBlueprintFiles(array $blueprints, array $plugins) - { - $list = []; - foreach (array_reverse($plugins) as $folder) { - $list += $this->detectPlugins($folder, true); - } - foreach (array_reverse($blueprints) as $folder) { - $list += $this->detectConfig($folder, true); - } - return $list; - } - - /** - * Get all configuration files. - * - * @param array $configs - * @param array $plugins - * @return array - */ - protected function getConfigFiles(array $configs, array $plugins) - { - $list = []; - foreach (array_reverse($plugins) as $folder) { - $list += $this->detectPlugins($folder); - } - foreach (array_reverse($configs) as $folder) { - $list += $this->detectConfig($folder); - } - return $list; - } - - /** - * Detects all plugins with a configuration file and returns last modification time. - * - * @param string $lookup Location to look up from. - * @param bool $blueprints - * @return array - * @internal - */ - protected function detectPlugins($lookup = SYSTEM_DIR, $blueprints = false) - { - $find = $blueprints ? 'blueprints.yaml' : '.yaml'; - $location = $blueprints ? 'blueprintFiles' : 'configFiles'; - $path = trim(Folder::getRelativePath($lookup), '/'); - if (isset($this->{$location}[$path])) { - return [$path => $this->{$location}[$path]]; - } - - $list = []; - - if (is_dir($lookup)) { - $iterator = new \DirectoryIterator($lookup); - - /** @var \DirectoryIterator $directory */ - foreach ($iterator as $directory) { - if (!$directory->isDir() || $directory->isDot()) { - continue; - } - - $name = $directory->getBasename(); - $filename = "{$path}/{$name}/" . ($find && $find[0] != '.' ? $find : $name . $find); - - if (file_exists($filename)) { - $list["plugins/{$name}"] = ['file' => $filename, 'modified' => filemtime($filename)]; - } - } - } - - $this->{$location}[$path] = $list; - - return [$path => $list]; - } - - /** - * Detects all plugins with a configuration file and returns last modification time. - * - * @param string $lookup Location to look up from. - * @param bool $blueprints - * @return array - * @internal - */ - protected function detectConfig($lookup = SYSTEM_DIR, $blueprints = false) - { - $location = $blueprints ? 'blueprintFiles' : 'configFiles'; - $path = trim(Folder::getRelativePath($lookup), '/'); - if (isset($this->{$location}[$path])) { - return [$path => $this->{$location}[$path]]; - } - - if (is_dir($lookup)) { - // Find all system and user configuration files. - $options = [ - 'compare' => 'Filename', - 'pattern' => '|\.yaml$|', - 'filters' => [ - 'key' => '|\.yaml$|', - 'value' => function (\RecursiveDirectoryIterator $file) use ($path) { - return ['file' => "{$path}/{$file->getSubPathname()}", 'modified' => $file->getMTime()]; - }], - 'key' => 'SubPathname' - ]; - - $list = Folder::all($lookup, $options); - } else { - $list = []; - } - - $this->{$location}[$path] = $list; - - return [$path => $list]; - } - - /** - * Detects all instances of the file and returns last modification time. - * - * @param array $lookups Locations to look up from. - * @param string $name - * @return array - * @internal - */ - protected function detectFile(array $lookups, $name) - { - $list = []; - $filename = "{$name}.yaml"; - foreach ($lookups as $lookup) { - $path = trim(Folder::getRelativePath($lookup), '/'); - - if (is_file("{$lookup}/{$filename}")) { - $modified = filemtime("{$lookup}/{$filename}"); - } else { - $modified = 0; - } - $list[$path] = [$name => ['file' => "{$path}/{$filename}", 'modified' => $modified]]; - } - - return $list; - } } diff --git a/system/src/Grav/Common/Config/ConfigFinder.php b/system/src/Grav/Common/Config/ConfigFinder.php new file mode 100644 index 000000000..243ddc5aa --- /dev/null +++ b/system/src/Grav/Common/Config/ConfigFinder.php @@ -0,0 +1,146 @@ +detectInFolder($folder, 'blueprints'); + } + foreach (array_reverse($blueprints) as $folder) { + $list += $this->detectRecursive($folder); + } + return $list; + } + + /** + * Get all locations for configuration files (including plugins). + * + * @param array $configs + * @param array $plugins + * @return array + */ + public function locateConfigFiles(array $configs, array $plugins) + { + $list = []; + foreach (array_reverse($plugins) as $folder) { + $list += $this->detectInFolder($folder); + } + foreach (array_reverse($configs) as $folder) { + $list += $this->detectRecursive($folder); + } + return $list; + } + + /** + * Get all locations for a single configuration file. + * + * @param array $folders Locations to look up from. + * @param string $name Filename to be located. + * @return array + */ + public function locateConfigFile(array $folders, $name) + { + $filename = "{$name}.yaml"; + + $list = []; + foreach ($folders as $folder) { + $path = trim(Folder::getRelativePath($folder), '/'); + + if (is_file("{$folder}/{$filename}")) { + $modified = filemtime("{$folder}/{$filename}"); + } else { + $modified = 0; + } + $list[$path] = [$name => ['file' => "{$path}/{$filename}", 'modified' => $modified]]; + } + + return $list; + } + + /** + * Detects all plugins with a configuration file and returns them with last modification time. + * + * @param string $folder Location to look up from. + * @param string $lookup Filename to be located. + * @return array + * @internal + */ + protected function detectInFolder($folder, $lookup = null) + { + $path = trim(Folder::getRelativePath($folder), '/'); + + $list = []; + + if (is_dir($folder)) { + $iterator = new \DirectoryIterator($folder); + + /** @var \DirectoryIterator $directory */ + foreach ($iterator as $directory) { + if (!$directory->isDir() || $directory->isDot()) { + continue; + } + + $name = $directory->getBasename(); + $find = ($lookup ?: $name) . '.yaml'; + $filename = "{$path}/{$name}/$find"; + + if (file_exists($filename)) { + $list["plugins/{$name}"] = ['file' => $filename, 'modified' => filemtime($filename)]; + } + } + } + + return [$path => $list]; + } + + /** + * Detects all plugins with a configuration file and returns them with last modification time. + * + * @param string $folder Location to look up from. + * @return array + * @internal + */ + protected function detectRecursive($folder) + { + $path = trim(Folder::getRelativePath($folder), '/'); + + if (is_dir($folder)) { + // Find all system and user configuration files. + $options = [ + 'compare' => 'Filename', + 'pattern' => '|\.yaml$|', + 'filters' => [ + 'key' => '|\.yaml$|', + 'value' => function (\RecursiveDirectoryIterator $file) use ($path) { + return ['file' => "{$path}/{$file->getSubPathname()}", 'modified' => $file->getMTime()]; + } + ], + 'key' => 'SubPathname' + ]; + + $list = Folder::all($folder, $options); + } else { + $list = []; + } + + return [$path => $list]; + } +} diff --git a/system/src/Grav/Common/File/CompiledFile.php b/system/src/Grav/Common/File/CompiledFile.php index 3caed214c..d9cf58d42 100644 --- a/system/src/Grav/Common/File/CompiledFile.php +++ b/system/src/Grav/Common/File/CompiledFile.php @@ -27,6 +27,11 @@ trait CompiledFile $key = md5($this->filename); $file = PhpFile::instance(CACHE_DIR . "/compiled/files/{$key}{$this->extension}.php"); $modified = $this->modified(); + + if (!$modified) { + return $this->decode($this->raw()); + } + $class = get_class($this); $cache = $file->exists() ? $file->content() : null; diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index eaa4e2da0..c4dca02f4 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -161,6 +161,12 @@ class Grav extends Container $this['debugger']->init(); $this['debugger']->stopTimer('_debugger'); + $this['config']->debug(); + + $this['debugger']->startTimer('streams', 'Streams'); + $this['streams']; + $this['debugger']->stopTimer('streams'); + $this['debugger']->startTimer('plugins', 'Plugins'); $this['plugins']->init(); $this->fireEvent('onPluginsInitialized'); diff --git a/system/src/Grav/Common/Service/StreamsServiceProvider.php b/system/src/Grav/Common/Service/StreamsServiceProvider.php index 4f19c831f..7cfa187eb 100644 --- a/system/src/Grav/Common/Service/StreamsServiceProvider.php +++ b/system/src/Grav/Common/Service/StreamsServiceProvider.php @@ -7,9 +7,12 @@ use RocketTheme\Toolbox\DI\ServiceProviderInterface; use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; use RocketTheme\Toolbox\StreamWrapper\ReadOnlyStream; use RocketTheme\Toolbox\StreamWrapper\Stream; +use RocketTheme\Toolbox\StreamWrapper\StreamBuilder; class StreamsServiceProvider implements ServiceProviderInterface { + protected $schemes = []; + public function register(Container $container) { $self = $this; @@ -20,23 +23,23 @@ class StreamsServiceProvider implements ServiceProviderInterface return $locator; }; + + $container['streams'] = function($c) use ($self) { + $locator = $c['locator']; + + // Set locator to both streams. + Stream::setLocator($locator); + ReadOnlyStream::setLocator($locator); + + return new StreamBuilder($this->schemes); + }; } protected function init(Container $container, UniformResourceLocator $locator) { /** @var Config $config */ $config = $container['config']; - $schemes = $config->get('streams.schemes'); - - if (!$schemes) { - return; - } - - // Set locator to both streams. - Stream::setLocator($locator); - ReadOnlyStream::setLocator($locator); - - $registered = stream_get_wrappers(); + $schemes = (array) $config->get('streams.schemes', []); foreach ($schemes as $scheme => $config) { if (isset($config['paths'])) { @@ -48,17 +51,12 @@ class StreamsServiceProvider implements ServiceProviderInterface } } - if (in_array($scheme, $registered)) { - stream_wrapper_unregister($scheme); - } $type = !empty($config['type']) ? $config['type'] : 'ReadOnlyStream'; if ($type[0] != '\\') { $type = '\\RocketTheme\\Toolbox\\StreamWrapper\\' . $type; } - if (!stream_wrapper_register($scheme, $type)) { - throw new \InvalidArgumentException("Stream '{$type}' could not be initialized."); - } + $this->schemes[$scheme] = $type; } } } From 767ac573af453f8eef538430f828ef0779b7fb93 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 16 Oct 2014 12:42:34 +0300 Subject: [PATCH 26/58] Add initial loading time to debugger timeline --- system/src/Grav/Common/Debugger.php | 1 + system/src/Grav/Common/Grav.php | 45 +++++++++++++++-------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index 6f485d396..cc494bd82 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -19,6 +19,7 @@ class Debugger public function __construct() { $this->debugbar = new StandardDebugBar(); + $this->debugbar['time']->addMeasure('Loading', $this->debugbar['time']->getRequestStartTime(), microtime(true)); } public function init() diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index c4dca02f4..c3bf5bc3b 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -152,30 +152,33 @@ class Grav extends Container // Use output buffering to prevent headers from being sent too early. ob_start(); - // Initialize configuration. - $this['debugger']->startTimer('_config', 'Configuration'); - $this['config']->init(); - $this['debugger']->stopTimer('_config'); + /** @var Debugger $debugger */ + $debugger = $this['debugger']; - $this['debugger']->startTimer('_debugger', 'Debugger'); - $this['debugger']->init(); - $this['debugger']->stopTimer('_debugger'); + // Initialize configuration. + $debugger->startTimer('_config', 'Configuration'); + $this['config']->init(); + $debugger->stopTimer('_config'); + + $debugger->startTimer('_debugger', 'Debugger'); + $debugger->init(); + $debugger->stopTimer('_debugger'); $this['config']->debug(); - $this['debugger']->startTimer('streams', 'Streams'); + $debugger->startTimer('streams', 'Streams'); $this['streams']; - $this['debugger']->stopTimer('streams'); + $debugger->stopTimer('streams'); - $this['debugger']->startTimer('plugins', 'Plugins'); + $debugger->startTimer('plugins', 'Plugins'); $this['plugins']->init(); $this->fireEvent('onPluginsInitialized'); - $this['debugger']->stopTimer('plugins'); + $debugger->stopTimer('plugins'); - $this['debugger']->startTimer('themes', 'Themes'); + $debugger->startTimer('themes', 'Themes'); $this['themes']->init(); $this->fireEvent('onThemeInitialized'); - $this['debugger']->stopTimer('themes'); + $debugger->stopTimer('themes'); $task = $this['task']; if ($task) { @@ -183,32 +186,32 @@ class Grav extends Container } $this['assets']->init(); - $this['debugger']->addAssets(); + $debugger->addAssets(); $this->fireEvent('onAssetsInitialized'); - $this['debugger']->startTimer('twig', 'Twig'); + $debugger->startTimer('twig', 'Twig'); $this['twig']->init(); - $this['debugger']->stopTimer('twig'); + $debugger->stopTimer('twig'); - $this['debugger']->startTimer('pages', 'Pages'); + $debugger->startTimer('pages', 'Pages'); $this['pages']->init(); $this->fireEvent('onPagesInitialized'); - $this['debugger']->stopTimer('pages'); + $debugger->stopTimer('pages'); $this->fireEvent('onPageInitialized'); // Process whole page as required - $this['debugger']->startTimer('render', 'Render'); + $debugger->startTimer('render', 'Render'); $this->output = $this['output']; $this->fireEvent('onOutputGenerated'); - $this['debugger']->stopTimer('render'); + $debugger->stopTimer('render'); // Set the header type $this->header(); echo $this->output; - $this['debugger']->render(); + $debugger->render(); $this->fireEvent('onOutputRendered'); From 0711875200ef9cd4393ce91a7c023602ba05f591 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 16 Oct 2014 14:47:26 +0300 Subject: [PATCH 27/58] Add {{ debug() }} and {{ dump() }} calls to twig --- system/src/Grav/Common/Grav.php | 5 +- system/src/Grav/Common/TwigExtension.php | 86 ++++++++++++++++++------ 2 files changed, 67 insertions(+), 24 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index c3bf5bc3b..99f9a0954 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -55,7 +55,7 @@ class Grav extends Container $container['grav'] = $container; $container['debugger'] = new Debugger(); - $container['debugger']->startTimer('_init', 'Init'); + $container['debugger']->startTimer('_init', 'Initialize'); $container->register(new ErrorServiceProvider); @@ -160,10 +160,7 @@ class Grav extends Container $this['config']->init(); $debugger->stopTimer('_config'); - $debugger->startTimer('_debugger', 'Debugger'); $debugger->init(); - $debugger->stopTimer('_debugger'); - $this['config']->debug(); $debugger->startTimer('streams', 'Streams'); diff --git a/system/src/Grav/Common/TwigExtension.php b/system/src/Grav/Common/TwigExtension.php index 3fec76e60..3c1ceaeeb 100644 --- a/system/src/Grav/Common/TwigExtension.php +++ b/system/src/Grav/Common/TwigExtension.php @@ -12,6 +12,15 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; */ class TwigExtension extends \Twig_Extension { + protected $grav; + protected $debugger; + + public function __construct() + { + $this->grav = Grav::instance(); + $this->debugger = isset($this->grav['debugger']) ? $this->grav['debugger'] : null; + } + /** * Returns extension name. * @@ -29,15 +38,15 @@ class TwigExtension extends \Twig_Extension */ public function getFilters() { - return array( - new \Twig_SimpleFilter('fieldName', array($this,'fieldNameFilter')), - new \Twig_SimpleFilter('safe_email', array($this,'safeEmailFilter')), - new \Twig_SimpleFilter('randomize', array($this,'randomizeFilter')), - new \Twig_SimpleFilter('truncate', array($this,'truncateFilter')), - new \Twig_SimpleFilter('*ize', array($this,'inflectorFilter')), - new \Twig_SimpleFilter('md5', array($this,'md5Filter')), - new \Twig_SimpleFilter('sort_by_key', array($this,'sortByKeyFilter')), - ); + return [ + new \Twig_SimpleFilter('fieldName', [$this,'fieldNameFilter']), + new \Twig_SimpleFilter('safe_email', [$this,'safeEmailFilter']), + new \Twig_SimpleFilter('randomize', [$this,'randomizeFilter']), + new \Twig_SimpleFilter('truncate', [$this,'truncateFilter']), + new \Twig_SimpleFilter('*ize', [$this,'inflectorFilter']), + new \Twig_SimpleFilter('md5', [$this,'md5Filter']), + new \Twig_SimpleFilter('sort_by_key',[$this,'sortByKeyFilter']), + ]; } /** @@ -47,10 +56,12 @@ class TwigExtension extends \Twig_Extension */ public function getFunctions() { - return array( - new \Twig_SimpleFunction('repeat', array($this, 'repeatFunc')), - new \Twig_SimpleFunction('url', array($this, 'urlFunc')) - ); + return [ + new \Twig_SimpleFunction('repeat', [$this, 'repeatFunc']), + new \Twig_SimpleFunction('url', [$this, 'urlFunc']), + new \Twig_SimpleFunction('dump', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]), + new \Twig_SimpleFunction('debug', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]), + ]; } /** @@ -125,7 +136,7 @@ class TwigExtension extends \Twig_Extension $original = iterator_to_array($original, false); } - $sorted = array(); + $sorted = []; $random = array_slice($original, $offset); shuffle($random); @@ -165,10 +176,10 @@ class TwigExtension extends \Twig_Extension if (in_array( $action, - array('titleize','camelize','underscorize','hyphenize', 'humanize','ordinalize','monthize') + ['titleize','camelize','underscorize','hyphenize', 'humanize','ordinalize','monthize'] )) { return Inflector::$action($data); - } elseif (in_array($action, array('pluralize','singularize'))) { + } elseif (in_array($action, ['pluralize','singularize'])) { if ($count) { return Inflector::$action($data, $count); } else { @@ -225,12 +236,12 @@ class TwigExtension extends \Twig_Extension /** * Sorts a collection by key * - * @param string $input + * @param array $input * @param string $filter - * @param string $direction - * @return string + * @param int $direction + * @return array */ - public function sortByKeyFilter($input, $filter, $direction = SORT_ASC) + public function sortByKeyFilter(array $input, $filter, $direction = SORT_ASC) { $output = []; @@ -246,4 +257,39 @@ class TwigExtension extends \Twig_Extension return $input; } + + /** + * Based on Twig_Extension_Debug / twig_var_dump + * (c) 2011 Fabien Potencier + * + * @param \Twig_Environment $env + * @param $context + */ + public function dump(\Twig_Environment $env, $context) + { + if (!$env->isDebug() || !$this->debugger) { + return; + } + + $count = func_num_args(); + if (2 === $count) { + $data = []; + foreach ($context as $key => $value) { + if (is_object($value)) { + if (method_exists($value, 'toArray')) { + $data[$key] = $value->toArray(); + } else { + $data[$key] = "Object (" . get_class($value) . ")"; + } + } else { + $data[$key] = $value; + } + } + $this->debugger->addMessage($data); + } else { + for ($i = 2; $i < $count; $i++) { + $this->debugger->addMessage(func_get_arg($i)); + } + } + } } From b379b38fff82ace0894db8f83b71b8e4d4c5ed11 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 17 Oct 2014 22:16:02 -0700 Subject: [PATCH 28/58] Set Twig debug() method to use 'debug' notice level --- system/src/Grav/Common/Debugger.php | 4 ++-- system/src/Grav/Common/TwigExtension.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index cc494bd82..6090a2356 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -95,11 +95,11 @@ class Debugger } - public function addMessage($message) + public function addMessage($message, $label = 'info', $isString = true) { $config = $this->grav['config']; if ($config->get('system.debugger.enabled')) { - $this->debugbar['messages']->addMessage($message); + $this->debugbar['messages']->addMessage($message, $label, $isString); } return $this; } diff --git a/system/src/Grav/Common/TwigExtension.php b/system/src/Grav/Common/TwigExtension.php index 3c1ceaeeb..2ee794ef7 100644 --- a/system/src/Grav/Common/TwigExtension.php +++ b/system/src/Grav/Common/TwigExtension.php @@ -285,10 +285,10 @@ class TwigExtension extends \Twig_Extension $data[$key] = $value; } } - $this->debugger->addMessage($data); + $this->debugger->addMessage($data, 'debug'); } else { for ($i = 2; $i < $count; $i++) { - $this->debugger->addMessage(func_get_arg($i)); + $this->debugger->addMessage(func_get_arg($i), 'debug'); } } } From 458f6cb55dd4e4befe2a32febcc591dfa8b666cd Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 17 Oct 2014 23:16:24 -0700 Subject: [PATCH 29/58] Monolog added and logging exceptions --- composer.json | 1 + system/src/Grav/Common/Grav.php | 3 +++ .../Common/Service/ErrorServiceProvider.php | 6 ++++++ .../Common/Service/LoggerServiceProvider.php | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 system/src/Grav/Common/Service/LoggerServiceProvider.php diff --git a/composer.json b/composer.json index 91f24f6bf..6a7b66a7d 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "doctrine/cache": "~1.3", "maximebf/debugbar": ">=1.0.0", "filp/whoops": "1.2.*@dev", + "monolog/monolog": "~1.1", "gregwar/image": "~2.0", "ircmaxell/password-compat": "1.0.*", "mrclay/minify": "dev-master", diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 99f9a0954..9d4298e1b 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -4,6 +4,7 @@ namespace Grav\Common; use Grav\Common\Page\Pages; use Grav\Common\Service\ConfigServiceProvider; use Grav\Common\Service\ErrorServiceProvider; +use Grav\Common\Service\LoggerServiceProvider; use Grav\Common\Service\StreamsServiceProvider; use RocketTheme\Toolbox\DI\Container; use RocketTheme\Toolbox\Event\Event; @@ -57,6 +58,8 @@ class Grav extends Container $container['debugger'] = new Debugger(); $container['debugger']->startTimer('_init', 'Initialize'); + $container->register(new LoggerServiceProvider); + $container->register(new ErrorServiceProvider); $container['uri'] = function ($c) { diff --git a/system/src/Grav/Common/Service/ErrorServiceProvider.php b/system/src/Grav/Common/Service/ErrorServiceProvider.php index 085fe6c0d..78afdf2c8 100644 --- a/system/src/Grav/Common/Service/ErrorServiceProvider.php +++ b/system/src/Grav/Common/Service/ErrorServiceProvider.php @@ -25,6 +25,12 @@ class ErrorServiceProvider implements ServiceProviderInterface $whoops->pushHandler($error_page); $whoops->pushHandler($json_page); + + $logger = $container['log']; + $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) { + $logger->addCritical($exception->getMessage(). ' - Trace: '. $exception->getTraceAsString()); + }); + $whoops->register(); $container['whoops'] = $whoops; diff --git a/system/src/Grav/Common/Service/LoggerServiceProvider.php b/system/src/Grav/Common/Service/LoggerServiceProvider.php new file mode 100644 index 000000000..8f8ed9398 --- /dev/null +++ b/system/src/Grav/Common/Service/LoggerServiceProvider.php @@ -0,0 +1,19 @@ +pushHandler(new StreamHandler(LOG_DIR.'info.log', Logger::WARNING)); + + $container['log'] = $log; + } +} From 5025a430b6ad09934cf01d24e4aa786278396072 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 18 Oct 2014 09:34:11 -0700 Subject: [PATCH 30/58] Tested log rotation --- system/config/system.yaml | 7 +- system/src/Grav/Common/Debugger.php | 68 ------------------- .../Common/Service/LoggerServiceProvider.php | 8 ++- 3 files changed, 7 insertions(+), 76 deletions(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index b0b341a84..27714836f 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -42,10 +42,5 @@ assets: # Configuration for Assets Manager (JS, C debugger: enabled: false # Enable Grav debugger and following settings - mode: detect # Mode tracy Debugger should be set to when enabled: detect|development|production - strict: false # Throw fatal error also on PHP warnings and notices - max_depth: 10 # How many nested levels to display for objects or arrays - log: - enabled: true # Enable logging shutdown: - close_connection: true # Close the connection before calling onShutdown(). disable for debugging + close_connection: true # Close the connection before calling onShutdown(). false for debugging diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index 6090a2356..a7169ab6e 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -103,72 +103,4 @@ class Debugger } return $this; } - - -// const PRODUCTION = TracyDebugger::PRODUCTION; -// const DEVELOPMENT = TracyDebugger::DEVELOPMENT; -// const DETECT = TracyDebugger::DETECT; - -// public function __construct($mode = self::PRODUCTION) -// { -// // Start the timer and enable debugger in production mode as we do not have system configuration yet. -// // Debugger catches all errors and logs them, for example if the script doesn't have write permissions. -//// TracyDebugger::timer(); -//// TracyDebugger::enable($mode, is_dir(LOG_DIR) ? LOG_DIR : null); -// } -// -// public function init() -// { -// -// -// /** @var Config $config */ -// $config = $grav['config']; -// -// TracyDebugger::$logDirectory = $config->get('system.debugger.log.enabled') ? LOG_DIR : null; -// TracyDebugger::$maxDepth = $config->get('system.debugger.max_depth'); -// -// // Switch debugger into development mode if configured -// if ($config->get('system.debugger.enabled')) { -// if ($config->get('system.debugger.strict')) { -// TracyDebugger::$strictMode = true; -// } -// -// $mode = $config->get('system.debugger.mode'); -// -// if (function_exists('ini_set')) { -// ini_set('display_errors', !($mode === 'production')); -// } -// -// if ($mode === 'detect') { -// TracyDebugger::$productionMode = self::DETECT; -// } elseif ($mode === 'production') { -// TracyDebugger::$productionMode = self::PRODUCTION; -// } else { -// TracyDebugger::$productionMode = self::DEVELOPMENT; -// } -// -// } -// } -// -// /** -// * Log a message. -// * -// * @param string $message -// */ -// public function log($message) -// { -// if (TracyDebugger::$logDirectory) { -// TracyDebugger::log(sprintf($message, TracyDebugger::timer() * 1000)); -// } -// } -// -// public static function dump($var) -// { -// TracyDebugger::dump($var); -// } -// -// public static function barDump($var, $title = NULL, array $options = NULL) -// { -// TracyDebugger::barDump($var, $title, $options); -// } } diff --git a/system/src/Grav/Common/Service/LoggerServiceProvider.php b/system/src/Grav/Common/Service/LoggerServiceProvider.php index 8f8ed9398..7f4e46c27 100644 --- a/system/src/Grav/Common/Service/LoggerServiceProvider.php +++ b/system/src/Grav/Common/Service/LoggerServiceProvider.php @@ -5,14 +5,18 @@ use Pimple\Container; use Pimple\ServiceProviderInterface; use \Monolog\Logger; use \Monolog\Handler\StreamHandler; +use \Monolog\Handler\RotatingFileHandler; class LoggerServiceProvider implements ServiceProviderInterface { public function register(Container $container) { - // create a log channel $log = new Logger('grav'); - $log->pushHandler(new StreamHandler(LOG_DIR.'info.log', Logger::WARNING)); + $log_file = LOG_DIR.'grav.log'; + $log_days = 14; + + // $log->pushHandler(new RotatingFileHandler($log_file, $log_days, Logger::WARNING)); + $log->pushHandler(new StreamHandler($log_file, Logger::WARNING)); $container['log'] = $log; } From ce9e955f21b225390d4590fcabf8c03a59d4caf7 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 18 Oct 2014 23:03:06 -0700 Subject: [PATCH 31/58] Added support for auto detecting environment configurations --- system/src/Grav/Common/Config/Config.php | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index 67762e0b6..0167c905f 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -104,6 +104,11 @@ class Config extends Data } $items['streams']['schemes'] += $this->streams; + // var_dump ($items['streams']['schemes']['config']['prefixes']['']); + $items = $this->autoDetectEnvironmentConfig($items); + + $this->messages[] = $items['streams']['schemes']['config']['prefixes']['']; + parent::__construct($items); } $this->check(); @@ -204,6 +209,26 @@ class Config extends Data return md5(json_encode([$cc, $cb])); } + protected function autoDetectEnvironmentConfig($items) + { + $address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : php_uname('n'); + + // check for localhost variations + if ($address == '::1' || $address == '127.0.0.1') { + $address = 'localhost'; + } + + $this->messages[] = 'Environment Name: ' . $address; + + $env_stream = 'user://'.$address.'/config'; + + if (file_exists(USER_DIR.$address.'/config')) { + array_unshift($items['streams']['schemes']['config']['prefixes'][''], $env_stream); + } + + return $items; + } + protected function loadCompiledBlueprints($blueprints, $plugins, $filename = null) { $checksum = md5(json_encode($blueprints)); From e6bf5d9ea52808d2bd5a4ede2e24cbd6ffc01e23 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 19 Oct 2014 18:21:21 -0700 Subject: [PATCH 32/58] css text outline fix --- system/assets/debugger.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/assets/debugger.css b/system/assets/debugger.css index a53eff71e..d56660c9c 100644 --- a/system/assets/debugger.css +++ b/system/assets/debugger.css @@ -39,7 +39,9 @@ div.phpdebugbar { font-size: 12px; } - +ul.phpdebugbar-widgets-timeline li span.phpdebugbar-widgets-label { + text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff; +} .phpdebugbar pre, .phpdebugbar code { margin: 0; From 9426b42a337f63fa7b8b9dacbbea3d585e3206f8 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 19 Oct 2014 18:47:14 -0700 Subject: [PATCH 33/58] other css tweaks --- system/assets/debugger.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/system/assets/debugger.css b/system/assets/debugger.css index d56660c9c..556da6a0a 100644 --- a/system/assets/debugger.css +++ b/system/assets/debugger.css @@ -2,6 +2,10 @@ div.phpdebugbar { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } +.phpdebugbar pre { + padding: 1rem; +} + .phpdebugbar div.phpdebugbar-header > div > * { padding: 5px 15px; } @@ -41,6 +45,7 @@ div.phpdebugbar { ul.phpdebugbar-widgets-timeline li span.phpdebugbar-widgets-label { text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff; + top: 0; } .phpdebugbar pre, .phpdebugbar code { From 112dd6f4ae2851ee1709a233a26b9dec89148cb4 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 20 Oct 2014 10:37:41 -0700 Subject: [PATCH 34/58] more stuff --- system/src/Grav/Common/Debugger.php | 33 ++++++++++++++----- system/src/Grav/Common/Grav.php | 12 ++++++- .../Common/Service/ErrorServiceProvider.php | 4 +++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/system/src/Grav/Common/Debugger.php b/system/src/Grav/Common/Debugger.php index a7169ab6e..ad1bef70c 100644 --- a/system/src/Grav/Common/Debugger.php +++ b/system/src/Grav/Common/Debugger.php @@ -15,6 +15,7 @@ class Debugger protected $grav; protected $debugbar; protected $renderer; + protected $enabled; public function __construct() { @@ -26,17 +27,27 @@ class Debugger { $this->grav = Grav::instance(); - $config = $this->grav['config']; - if ($config->get('system.debugger.enabled')) { - $this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array)$config->get('system'))); + if ($this->enabled()) { + $this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array)$this->grav['config']->get('system'))); } return $this; } + public function enabled($state = null) + { + if (isset($state)) { + $this->enabled = $state; + } else { + if (!isset($this->enabled)) { + $this->enabled = $this->grav['config']->get('system.debugger.enabled'); + } + } + return $this->enabled; + } + public function addAssets() { - $config = $this->grav['config']; - if ($config->get('system.debugger.enabled')) { + if ($this->enabled()) { $assets = $this->grav['assets']; @@ -71,13 +82,18 @@ class Debugger public function render() { - $config = $this->grav['config']; - if ($config->get('system.debugger.enabled')) { + if ($this->enabled()) { echo $this->renderer->render(); } return $this; } + public function sendDataInHeaders() + { + $this->debugbar->sendDataInHeaders(); + return $this; + } + public function startTimer($name, $desription = null) { if ($name[0] == '_' || $this->grav['config']->get('system.debugger.enabled')) { @@ -97,8 +113,7 @@ class Debugger public function addMessage($message, $label = 'info', $isString = true) { - $config = $this->grav['config']; - if ($config->get('system.debugger.enabled')) { + if ($this->enabled()) { $this->debugbar['messages']->addMessage($message, $label, $isString); } return $this; diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 9d4298e1b..0e114ffe2 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -266,7 +266,17 @@ class Grav extends Container */ public function header() { - header('Content-type: ' . $this->mime($this['uri']->extension())); + $extension = $this['uri']->extension(); + header('Content-type: ' . $this->mime($extension)); + + $header_extensions = ['json','xml','rss','atom']; + + // Set debugger data in headers + if (in_array($extension, $header_extensions)) { + $this['debugger']->enabled(false); + // $this['debugger']->sendDataInHeaders(); + + } } /** diff --git a/system/src/Grav/Common/Service/ErrorServiceProvider.php b/system/src/Grav/Common/Service/ErrorServiceProvider.php index 78afdf2c8..2a3602b21 100644 --- a/system/src/Grav/Common/Service/ErrorServiceProvider.php +++ b/system/src/Grav/Common/Service/ErrorServiceProvider.php @@ -5,6 +5,7 @@ use Pimple\Container; use Pimple\ServiceProviderInterface; use Whoops\Handler\JsonResponseHandler; use Whoops\Handler\PrettyPageHandler; +use Whoops\Handler\PlainTextHandler; use Whoops\Run; class ErrorServiceProvider implements ServiceProviderInterface @@ -23,9 +24,12 @@ class ErrorServiceProvider implements ServiceProviderInterface $json_page = new JsonResponseHandler; $json_page->onlyForAjaxRequests(true); + $whoops->pushHandler($error_page); + $whoops->pushHandler(new PlainTextHandler); $whoops->pushHandler($json_page); + $logger = $container['log']; $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) { $logger->addCritical($exception->getMessage(). ' - Trace: '. $exception->getTraceAsString()); From 8950e6661f549599742ea92a81ba2da78662592f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 20 Oct 2014 10:42:57 -0700 Subject: [PATCH 35/58] check for html explicitly --- system/src/Grav/Common/Grav.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 0e114ffe2..2d2d61282 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -269,13 +269,10 @@ class Grav extends Container $extension = $this['uri']->extension(); header('Content-type: ' . $this->mime($extension)); - $header_extensions = ['json','xml','rss','atom']; - // Set debugger data in headers - if (in_array($extension, $header_extensions)) { + if (!($extension == null || $extension == 'html')) { $this['debugger']->enabled(false); // $this['debugger']->sendDataInHeaders(); - } } From bb0ee34082e717179aa4821673c5e56077509751 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 22 Oct 2014 21:14:11 -0600 Subject: [PATCH 36/58] Tentatively added twig panel to debugbar - currently has issues with "processpage" twig calls used by modular --- system/config/system.yaml | 1 + system/src/Grav/Common/Grav.php | 4 +++- system/src/Grav/Common/Twig.php | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/system/config/system.yaml b/system/config/system.yaml index 27714836f..f2011c695 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -42,5 +42,6 @@ assets: # Configuration for Assets Manager (JS, C debugger: enabled: false # Enable Grav debugger and following settings + twig: true # Enable debugging of Twig templates shutdown: close_connection: true # Close the connection before calling onShutdown(). false for debugging diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 2d2d61282..8f24a4593 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -186,7 +186,7 @@ class Grav extends Container } $this['assets']->init(); - $debugger->addAssets(); + $this->fireEvent('onAssetsInitialized'); $debugger->startTimer('twig', 'Twig'); @@ -201,6 +201,7 @@ class Grav extends Container $this->fireEvent('onPageInitialized'); + $debugger->addAssets(); // Process whole page as required $debugger->startTimer('render', 'Render'); @@ -208,6 +209,7 @@ class Grav extends Container $this->fireEvent('onOutputGenerated'); $debugger->stopTimer('render'); + // Set the header type $this->header(); echo $this->output; diff --git a/system/src/Grav/Common/Twig.php b/system/src/Grav/Common/Twig.php index d42ee3bbe..636e9b578 100644 --- a/system/src/Grav/Common/Twig.php +++ b/system/src/Grav/Common/Twig.php @@ -70,6 +70,7 @@ class Twig $config = $this->grav['config']; /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; + $debugger = $this->grav['debugger']; $this->twig_paths = $locator->findResources('theme://templates'); $this->grav->fireEvent('onTwigTemplatePaths'); @@ -84,6 +85,11 @@ class Twig } $this->twig = new \Twig_Environment($loader_chain, $params); + if ($debugger->enabled() && $config->get('system.debugger.twig')) { + $this->twig = new \DebugBar\Bridge\Twig\TraceableTwigEnvironment($this->twig); + $collector = new \DebugBar\Bridge\Twig\TwigCollector($this->twig); + $debugger->addCollector($collector); + } $this->grav->fireEvent('onTwigInitialized'); // set default date format if set in config @@ -95,6 +101,8 @@ class Twig $this->twig->addExtension(new \Twig_Extension_Debug()); } $this->twig->addExtension(new TwigExtension()); + + $this->grav->fireEvent('onTwigExtensions'); $baseUrlAbsolute = $config->get('system.base_url_absolute'); @@ -117,7 +125,6 @@ class Twig 'taxonomy' => $this->grav['taxonomy'], 'browser' => $this->grav['browser'], ); - } } @@ -170,15 +177,17 @@ class Twig $twig_vars['media'] = $item->media(); $twig_vars['header'] = $item->header(); + $local_twig = clone($this->twig); + // Get Twig template layout if ($item->modularTwig()) { $twig_vars['content'] = $content; $template = $item->template() . TEMPLATE_EXT; - $output = $this->twig->render($template, $twig_vars); + $output = $local_twig->render($template, $twig_vars); } else { $name = '@Page:' . $item->path(); $this->setTemplate($name, $content); - $output = $this->twig->render($name, $twig_vars); + $output = $local_twig->render($name, $twig_vars); } return $output; From 7046c104d6d8934a41379df52aeff70260a2f2e1 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 22 Oct 2014 22:03:36 -0600 Subject: [PATCH 37/58] additional vendor cleanups --- system/src/Grav/Console/Cli/CleanCommand.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/system/src/Grav/Console/Cli/CleanCommand.php b/system/src/Grav/Console/Cli/CleanCommand.php index 95da029f7..9499c2be8 100644 --- a/system/src/Grav/Console/Cli/CleanCommand.php +++ b/system/src/Grav/Console/Cli/CleanCommand.php @@ -51,6 +51,16 @@ class CleanCommand extends Command { 'vendor/erusev/parsedown-extra/.travis.yml', 'vendor/erusev/parsedown-extra/.git', 'vendor/erusev/parsedown-extra/test', + 'vendor/filp/whoops/composer.json', + 'vendor/filp/whoops/docs', + 'vendor/filp/whoops/examples', + 'vendor/filp/whoops/tests', + 'vendor/filp/whoops/.git', + 'vendor/filp/whoops/.gitignore', + 'vendor/filp/whoops/.scrutinizer.yml', + 'vendor/filp/whoops/.travis.yml', + 'vendor/filp/whoops/phpunit.xml.dist', + 'vendor/filp/whoops/src/deprecated', 'vendor/gregwar/image/Gregwar/Image/composer.json', 'vendor/gregwar/image/Gregwar/Image/phpunit.xml', 'vendor/gregwar/image/Gregwar/Image/.gitignore', @@ -68,6 +78,13 @@ class CleanCommand extends Command { 'vendor/ircmaxell/password-compat/version-test.php', 'vendor/ircmaxell/password-compat/.travis.yml', 'vendor/ircmaxell/password-compat/test', + 'vendor/maximebf/debugbar/bower.json', + 'vendor/maximebf/debugbar/composer.json', + 'vendor/maximebf/debugbar/.bowerrc', + 'vendor/monolog/monolog/composer.json', + 'vendor/monolog/monolog/doc', + 'vendor/monolog/monolog/phpunit.xml.dist', + 'vendor/monolog/monolog/tests', 'vendor/mrclay/minify/.editorconfig', 'vendor/mrclay/minify/.git', 'vendor/mrclay/minify/.gitignore', @@ -89,6 +106,8 @@ class CleanCommand extends Command { 'vendor/pimple/pimple/ext', 'vendor/pimple/pimple/phpunit.xml.dist', 'vendor/pimple/pimple/src/Pimple/Tests', + 'vendor/psr/log/composer.json', + 'vendor/psr/log/.gitignore', 'vendor/rockettheme/toolbox/.git', 'vendor/rockettheme/toolbox/.gitignore', 'vendor/rockettheme/toolbox/.scrutinizer.yml', From a54d116be309c49edb85b5f7db21992f82a5a5f6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 22 Oct 2014 22:12:50 -0600 Subject: [PATCH 38/58] removed unused vendor libs --- system/src/Grav/Console/Cli/CleanCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/src/Grav/Console/Cli/CleanCommand.php b/system/src/Grav/Console/Cli/CleanCommand.php index 9499c2be8..bf5026fb2 100644 --- a/system/src/Grav/Console/Cli/CleanCommand.php +++ b/system/src/Grav/Console/Cli/CleanCommand.php @@ -81,6 +81,7 @@ class CleanCommand extends Command { 'vendor/maximebf/debugbar/bower.json', 'vendor/maximebf/debugbar/composer.json', 'vendor/maximebf/debugbar/.bowerrc', + 'vendor/maximebf/debugbar/src/Debugbar/Resources/vendor', 'vendor/monolog/monolog/composer.json', 'vendor/monolog/monolog/doc', 'vendor/monolog/monolog/phpunit.xml.dist', From 9928b75d0d1ee5032a949e228c4668cb6d49ddb5 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 26 Oct 2014 19:20:07 -0600 Subject: [PATCH 39/58] Fix for debugbar with in-page Twig rendering --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6a7b66a7d..21ab9f100 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "symfony/console": "~2.5", "symfony/event-dispatcher": "~2.5", "doctrine/cache": "~1.3", - "maximebf/debugbar": ">=1.0.0", + "maximebf/debugbar": "dev-master", "filp/whoops": "1.2.*@dev", "monolog/monolog": "~1.1", "gregwar/image": "~2.0", @@ -31,6 +31,10 @@ { "type": "vcs", "url": "https://github.com/rhukster/minify" + }, + { + "type": "vcs", + "url": "https://github.com/getgrav/php-debugbar" } ], "autoload": { From fc863c560fbe6bae3eff7461638e010955f93328 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 26 Oct 2014 19:23:34 -0600 Subject: [PATCH 40/58] moved composer update into non-symlink block --- system/src/Grav/Console/Cli/InstallCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php index 38664d9a3..58fdd6690 100644 --- a/system/src/Grav/Console/Cli/InstallCommand.php +++ b/system/src/Grav/Console/Cli/InstallCommand.php @@ -66,13 +66,13 @@ class InstallCommand extends Command { $output->writeln('ERROR Missing .dependencies file in user/ folder'); } - // Updates composer first - $output->writeln("\nInstalling vendor dependencies"); - $output->writeln(system('php bin/composer.phar --working-dir="'.$this->destination.'" --no-interaction update')); - // If yaml config, process if ($this->config) { if (!$input->getOption('symlink')) { + // Updates composer first + $output->writeln("\nInstalling vendor dependencies"); + $output->writeln(system('php bin/composer.phar --working-dir="'.$this->destination.'" --no-interaction update')); + $this->gitclone($output); } else { $this->symlink($output); From 046a50ffcd61776c55e0a89736e620d91dd149d9 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 26 Oct 2014 19:24:02 -0600 Subject: [PATCH 41/58] Added vendor to the mappings for copy/symlink --- system/src/Grav/Console/Cli/SandboxCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Console/Cli/SandboxCommand.php b/system/src/Grav/Console/Cli/SandboxCommand.php index f564b349b..c2f1cc5be 100644 --- a/system/src/Grav/Console/Cli/SandboxCommand.php +++ b/system/src/Grav/Console/Cli/SandboxCommand.php @@ -32,7 +32,8 @@ class SandboxCommand extends Command protected $mappings = array('/index.php' => '/index.php', '/composer.json' => '/composer.json', '/bin' => '/bin', - '/system' => '/system' + '/system' => '/system', + '/vendor' => '/vendor' ); protected $default_file = "---\ntitle: HomePage\n---\n# HomePage\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porttitor eu felis sed ornare. Sed a mauris venenatis, pulvinar velit vel, dictum enim. Phasellus ac rutrum velit. Nunc lorem purus, hendrerit sit amet augue aliquet, iaculis ultricies nisl. Suspendisse tincidunt euismod risus, quis feugiat arcu tincidunt eget. Nulla eros mi, commodo vel ipsum vel, aliquet congue odio. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque velit orci, laoreet at adipiscing eu, interdum quis nibh. Nunc a accumsan purus."; From 2d4eb6d36411efb0fdacc7829140d8703ab49fb3 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 27 Oct 2014 17:17:22 -0600 Subject: [PATCH 42/58] removed redundant debugger fork reference --- composer.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/composer.json b/composer.json index 21ab9f100..70ad4cbc6 100644 --- a/composer.json +++ b/composer.json @@ -31,10 +31,6 @@ { "type": "vcs", "url": "https://github.com/rhukster/minify" - }, - { - "type": "vcs", - "url": "https://github.com/getgrav/php-debugbar" } ], "autoload": { From ac8887129c0cb2308a8484684e6731db2866dd36 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 27 Oct 2014 17:33:45 -0600 Subject: [PATCH 43/58] added some missing files --- system/src/Grav/Console/Cli/SandboxCommand.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Console/Cli/SandboxCommand.php b/system/src/Grav/Console/Cli/SandboxCommand.php index c2f1cc5be..024ef4b4d 100644 --- a/system/src/Grav/Console/Cli/SandboxCommand.php +++ b/system/src/Grav/Console/Cli/SandboxCommand.php @@ -25,11 +25,18 @@ class SandboxCommand extends Command protected $files = array('/.dependencies', '/.htaccess', + '/nginx.conf', + '/web.config', '/user/config/site.yaml', '/user/config/system.yaml', ); - protected $mappings = array('/index.php' => '/index.php', + protected $mappings = array('/.editorconfig' => '/.editorconfig', + '/.gitignore' => '/.gitignore', + '/CHANGELOG.md' => '/CHANGELOG.md', + '/LICENSE' => '/LICENSE', + '/README.md' => '/README.md', + '/index.php' => '/index.php', '/composer.json' => '/composer.json', '/bin' => '/bin', '/system' => '/system', From 9bd62558c171da48b2657d39c819dcada1db28ab Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 27 Oct 2014 18:46:51 -0600 Subject: [PATCH 44/58] permissions --- .gitignore | 0 .htaccess | 0 nginx.conf | 0 web.config | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 .gitignore mode change 100755 => 100644 .htaccess mode change 100755 => 100644 nginx.conf mode change 100755 => 100644 web.config diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/.htaccess b/.htaccess old mode 100755 new mode 100644 diff --git a/nginx.conf b/nginx.conf old mode 100755 new mode 100644 diff --git a/web.config b/web.config old mode 100755 new mode 100644 From 7202766cb5579726a73545950c77992864bc68e1 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 27 Oct 2014 21:36:29 -0600 Subject: [PATCH 45/58] Several hatches improvements and unifications --- .htaccess | 55 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/.htaccess b/.htaccess index f5c4adce4..4fd10f335 100644 --- a/.htaccess +++ b/.htaccess @@ -2,7 +2,24 @@ RewriteEngine On -## +## Begin - Exploits +# If you experience problems on your site block out the operations listed below +# This attempts to block the most common type of exploit `attempts` to Grav +# +# Block out any script trying to base64_encode data within the URL. +RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR] +# Block out any script that includes a