Skip to content

Commit

Permalink
install auto-author plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fannymugnier committed Mar 5, 2021
1 parent e43f3ff commit 9469863
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 0 deletions.
6 changes: 6 additions & 0 deletions user/plugins/auto-author/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
.idea
vendor
composer.phar
composer.lock
phpunit.xml
5 changes: 5 additions & 0 deletions user/plugins/auto-author/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# v0.1.0
## 09/03/2017

1. [](#new)
* ChangeLog started...
21 changes: 21 additions & 0 deletions user/plugins/auto-author/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Sven Sanzenbacher

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.
62 changes: 62 additions & 0 deletions user/plugins/auto-author/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Auto Author Plugin

The **Auto Author** Plugin is for [Grav CMS](http://github.com/getgrav/grav). Automatically adds an author to frontmatter when creating a new page via Grav Admin plugin.

## Usage

Whenever you create a new page via the admin plugin, an author will be automatically inserted in the frontmatter of the page. The author name is dependent on the configuration. It can be the author name from `site.yaml` or the fullname of the current admin user.

```
user/pages/02.my-new-page/default.md
---
title: 'My new page'
author: 'Joe Bloggs'
---
```

## Installation

Installing the Auto Author plugin can be done in one of two ways. The 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 auto-author

This will install the Auto Author plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/auto-author`.

### 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 `auto-author`. You can find these files on [GitHub](https://github.com/-sven-sanzenbacher/grav-plugin-auto-author) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).

You should now have all the plugin files under

/your/site/grav/user/plugins/auto-author

> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav) and the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) to operate.
## Configuration

Before configuring this plugin, you should copy the `user/plugins/auto-author/auto-author.yaml` to `user/config/plugins/auto-author.yaml` and only edit that copy.

Here is the default configuration and an explanation of available options:

```yaml
# enables or disables the plugin
enabled: true
# true = use current admin user (fullname) or false = use site author name (default)
user: false
```
## License
The MIT License (MIT)
Copyright (c) 2015 Sven Sanzenbacher
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.
54 changes: 54 additions & 0 deletions user/plugins/auto-author/auto-author.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace Grav\Plugin;

use Grav\Common\Plugin;
use Grav\Plugin\Admin\Admin;
use RocketTheme\Toolbox\Event\Event;

/**
* Class AutoAuthorPlugin
* @package Grav\Plugin
*/
class AutoAuthorPlugin extends Plugin
{
/**
* @return array
*
* The getSubscribedEvents() gives the core a list of events
* that the plugin wants to listen to. The key of each
* array section is the event that the plugin listens to
* and the value (in the form of an array) contains the
* callable (or function) as well as the priority. The
* higher the number the higher the priority.
*/
public static function getSubscribedEvents()
{
return [
'onAdminCreatePageFrontmatter' => ['onAdminCreatePageFrontmatter', 0]
];
}

/**
* Initialize the plugin
*
* @param Event $event
*/
public function onAdminCreatePageFrontmatter(Event $event)
{
$header = $event['header'];
if (!isset($header['author'])) {
if ($this->config->get('plugins.auto-author.user')) {
/**
* @var Admin $admin
*/
$admin = $this->grav['admin'];
$author = $admin->user->get('fullname');

} else {
$author = $this->grav['config']->get('site.author.name');
}
$header['author'] = $author;
$event['header'] = $header;
}
}
}
2 changes: 2 additions & 0 deletions user/plugins/auto-author/auto-author.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
enabled: true
user: false
39 changes: 39 additions & 0 deletions user/plugins/auto-author/blueprints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Auto Author
version: 0.1.0
description: Automatically adds an author to frontmatter when creating a new page via Grav Admin plugin
icon: user-circle
author:
name: Sven Sanzenbacher
homepage: https://github.com/naucon/grav-plugin-auto-author
keywords: grav, plugin, auto-author, author, autor, frontmatter
bugs: https://github.com/naucon/grav-plugin-auto-author/issues
docs: https://github.com/naucon/grav-plugin-auto-author/blob/develop/README.md
license: MIT

dependencies:
- { name: admin, version: '>=1.2.3' }

form:
validation: strict
fields:
enabled:
type: toggle
label: Plugin status
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
user:
type: toggle
label: Current user
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
help: use current admin user (fullname) or site author

0 comments on commit 9469863

Please sign in to comment.