First commit

This commit is contained in:
Pierre Hubert
2016-11-19 12:08:12 +01:00
commit 990540b2b9
4706 changed files with 931207 additions and 0 deletions

View File

@ -0,0 +1,45 @@
# v1.5.1
## 07/18/2016
1. [](#improved)
* Added chinese and german translations
1. [](#bugfix)
* Fixed issue with the Smartypants plugin running before Twig was processed
# v1.5.0
## 07/14/2015
1. [](#improved)
* Translate some blueprint configuration options
* Allow translating the error message
* Added french, russian, romanian, danish, italian
# v1.4.1
## 12/11/2015
1. [](#bugfix)
* Fixed CLI command for PHP 5.5 and lower
# v1.4.0
## 11/21/2015
1. [](#new)
* Implemented CLI commands for the plugin
# v1.3.0
## 08/25/2015
1. [](#improved)
* Added blueprints for Grav Admin plugin
# v1.2.2
## 01/06/2015
1. [](#new)
* Added a default `error.json.twig` file
# v1.2.1
## 11/30/2014
1. [](#new)
* ChangeLog started...

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Grav
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,89 @@
# Grav Error Plugin
![GPM Installation](assets/readme_1.png)
`error` is a [Grav](http://github.com/getgrav/grav) Plugin and allows to redirect errors to nice output pages.
This plugin is included in any package distributed that contains Grav. If you decide to clone Grav from GitHub you will most likely want to install this.
# Installation
Installing the Error plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
## GPM Installation (Preferred)
The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line). From the root of your Grav install type:
bin/gpm install error
This will install the Error plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/error`.
## Manual Installation
To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `error`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-error) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
You should now have all the plugin files under
/your/site/grav/user/plugins/error
>> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav), the [Problems](https://github.com/getgrav/grav-plugin-problems) plugin, and a theme to be installed in order to operate.
# Usage
The `error` plugin doesn't require any configuration. The moment you install it, it is ready to use.
Something you might want to do is to override the look and feel of the error page, and with Grav it is super easy.
### Template
Copy the template file [error.html.twig](templates/error.html.twig) into the `templates` folder of your custom theme and that is it.
```
/your/site/grav/user/themes/custom-theme/templates/error.html.twig
```
You can now edit the override and tweak it however you prefer.
### Page
Copy the page file [error.md](pages/error.md) into the `pages` folder of your user directory and that is it.
```
/your/site/grav/user/pages/error/error.md
```
You can now edit the override and tweak it however you prefer.
# CLI Usage
The `error` plugin comes with a CLI command that outputs the `grav.log` in a beautified way, with possibility of limiting the amount of errors displayed, as well as include the trace in the output.
### Commands
| `bin/plugin error log` | |
|------------------------|-----------------------------------------------------------------|
| [ --limit N \| -l N ] | The amount of errors to display. Default is 5 |
| [ --trace \| -t ] | When used, it will add the backtrace in the output of the error |
# Updating
As development for the Error plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating Error is easy, and can be done through Grav's GPM system, as well as manually.
## GPM Update (Preferred)
The simplest way to update this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm). You can do this with this by navigating to the root directory of your Grav install using your system's Terminal (also called command line) and typing the following:
bin/gpm update error
This command will check your Grav install to see if your Error plugin is due for an update. If a newer release is found, you will be asked whether or not you wish to update. To continue, type `y` and hit enter. The plugin will automatically update and clear Grav's cache.
## Manual Update
Manually updating Error is pretty simple. Here is what you will need to do to get this done:
* Delete the `your/site/user/plugins/error` directory.
* Download the new version of the Error plugin from either [GitHub](https://github.com/getgrav/grav-plugin-error) or [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
* Unzip the zip file in `your/site/user/plugins` and rename the resulting folder to `error`.
* Clear the Grav cache. The simplest way to do this is by going to the root Grav directory in terminal and typing `bin/grav clear-cache`.
> Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in `user/config/plugins`) will remain intact.

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

@ -0,0 +1,32 @@
name: Error
version: 1.5.1
description: Displays the error page.
icon: warning
author:
name: Team Grav
email: devs@getgrav.org
url: http://getgrav.org
homepage: https://github.com/getgrav/grav-plugin-error
keywords: error, plugin, required
bugs: https://github.com/getgrav/grav-plugin-error/issues
license: MIT
form:
validation: strict
fields:
enabled:
type: toggle
label: PLUGIN_ADMIN.PLUGIN_STATUS
highlight: 1
default: 0
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool
routes.404:
type: text
size: medium
label: 404 Route
default: '/error'

View File

@ -0,0 +1,130 @@
<?php
namespace Grav\Plugin\Console;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
/**
* Class LogCommand
*
* @package Grav\Plugin\Console
*/
class LogCommand extends ConsoleCommand
{
/**
* @var string
*/
protected $logfile;
/**
* @var array
*/
protected $options = [];
/**
* @var array
*/
protected $colors = [
'DEBUG' => 'green',
'INFO' => 'cyan',
'NOTICE' => 'yellow',
'WARNING' => 'yellow',
'ERROR' => 'red',
'CRITICAL' => 'red',
'ALERT' => 'red',
'EMERGENCY' => 'magenta'
];
/**
*
*/
protected function configure()
{
$this->logfile = LOG_DIR . 'grav.log';
$this
->setName("log")
->setDescription("Outputs the Error Log")
->addOption(
'trace',
't',
InputOption::VALUE_NONE,
'Include the errors stack trace in the output'
)
->addOption(
'limit',
'l',
InputArgument::OPTIONAL,
'Outputs only the last X amount of errors. Use as --limit 10 / -l 10 [default 5]',
5
)
->setHelp('The <info>log</info> outputs the Errors Log in Console')
;
}
/**
* @return int|null|void
*/
protected function serve()
{
$this->options = [
'trace' => $this->input->getOption('trace'),
'limit' => $this->input->getOption('limit')
];
if (!file_exists($this->logfile)) {
$this->output->writeln("\n" . "Log file not found." . "\n");
exit;
}
$log = file_get_contents($this->logfile);
$lines = explode("\n", $log);
if (!is_numeric($this->options['limit'])) {
$this->options['limit'] = 5;
}
$lines = array_slice($lines, -($this->options['limit'] + 1));
foreach ($lines as $line) {
$this->output->writeln($this->parseLine($line));
}
}
/**
* @param $line
*
* @return null|string
*/
protected function parseLine($line)
{
$bit = explode(': ', $line);
$line1 = explode('] ', $bit[0]);
if (!$line1[0]) {
return null;
}
$line2 = explode(' - ', $bit[1]);
$date = $line1[0] . ']';
$type = str_replace('grav.', '', $line1[1]);
$color = $this->colors[$type];
$error = $line2[0];
$trace = implode(': ', array_slice($bit, 2));
$output = [];
$output[] = '';
$output[] = '<cyan>' . $date . '</cyan>';
$output[] = sprintf(' <%s>%s</%s> <white>' . $error . '</white>', $color, $type, $color);
if ($this->options['trace']) {
$output[] = ' <white>TRACE:</white> ';
$output[] = ' ' . $trace;
}
$output[] = '<cyan>' . str_repeat('-', strlen($date)) . '</cyan>';
return implode("\n", $output);
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Page\Pages;
use Grav\Common\Page\Types;
use RocketTheme\Toolbox\Event\Event;
class ErrorPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onPageNotFound' => ['onPageNotFound', 0],
'onGetPageTemplates' => ['onGetPageTemplates', 0],
];
}
/**
* Display error page if no page was found for the current route.
*
* @param Event $event
*/
public function onPageNotFound(Event $event)
{
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', -10]
]);
/** @var Pages $pages */
$pages = $this->grav['pages'];
// Try to load user error page.
$page = $pages->dispatch($this->config->get('plugins.error.routes.404', '/error'), true);
if (!$page) {
// If none provided use built in error page.
$page = new Page;
$page->init(new \SplFileInfo(__DIR__ . '/pages/error.md'));
}
$event->page = $page;
$event->stopPropagation();
}
/**
* Add page template types.
*/
public function onGetPageTemplates(Event $event)
{
/** @var Types $types */
$types = $event->types;
$types->register('error');
}
/**
* Add current directory to twig lookup paths.
*/
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
}

View File

@ -0,0 +1,3 @@
enabled: true
routes:
404: '/error'

View File

@ -0,0 +1,32 @@
en:
PLUGIN_ERROR:
ERROR: "Error"
ERROR_MESSAGE: "Woops. Looks like this page doesn't exist."
de:
PLUGIN_ERROR:
ERROR: "Fehler"
ERROR_MESSAGE: "Uuups. Sieht aus als ob diese Seite nicht existiert."
ro:
PLUGIN_ERROR:
ERROR: "Eroare"
ERROR_MESSAGE: "Ooops. Se pare că pagina nu există."
fr:
PLUGIN_ERROR:
ERROR: "Erreur"
ERROR_MESSAGE: "Oups. Il semble que cette page nexiste pas."
it:
PLUGIN_ERROR:
ERROR: "Errore"
ERROR_MESSAGE: "Ooops. A quanto pare, questa pagina non esiste."
ru:
PLUGIN_ERROR:
ERROR: "Ошибка"
ERROR_MESSAGE: "Упс. Похоже, эта страница не существует."
da:
PLUGIN_ERROR:
ERROR: "Fejl"
ERROR_MESSAGE: "Ups. Det ser ud til at siden ikke eksisterer."
zh:
PLUGIN_ERROR:
ERROR: "错误"
ERROR_MESSAGE: "呃,似乎这个页面不存在。"

View File

@ -0,0 +1,13 @@
---
title: Page not Found
robots: noindex,nofollow
template: error
routable: false
http_response_code: 404
twig_first: true
process:
twig: true
---
{{ 'PLUGIN_ERROR.ERROR_MESSAGE'|t }}

View File

@ -0,0 +1,3 @@
<h1>{{ 'PLUGIN_ERROR.ERROR'|t }} {{ header.http_response_code }}</h1>
<p>{{ page.content }}</p>

View File

@ -0,0 +1 @@
{{ page.content|json_encode() }}