Skip to content

Commit 2b71a97

Browse files
author
Andreas Sander
committed
Initial commit
0 parents  commit 2b71a97

File tree

8 files changed

+208
-0
lines changed

8 files changed

+208
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# v0.1.0
2+
## 09/08/2019
3+
4+
* Initial plugin release

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Andreas Sander
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Sponsoren Banner Plugin
2+
3+
**This README.md file should be modified to describe the features, installation, configuration, and general usage of the plugin.**
4+
5+
The plugin is an extension for [Grav CMS](http://github.com/getgrav/grav). Ein Banner welcher die Sponsoren zeigt
6+
7+
## Installation
8+
9+
Installing the plugin can be done in one of three ways: The GPM (Grav Package Manager) installation method lets you quickly install the plugin with a simple terminal command, the manual method lets you do so via a zip file, and the admin method lets you do so via the Admin Plugin.
10+
11+
### GPM Installation (Preferred)
12+
13+
To install the plugin via the [GPM](http://learn.getgrav.org/advanced/grav-gpm), through your system's terminal (also called the command line), navigate to the root of your Grav-installation, and enter:
14+
15+
bin/gpm install sponsoren-banner
16+
17+
This will install the Sponsoren Banner plugin into your `/user/plugins`-directory within Grav. Its files can be found under `/your/site/grav/user/plugins/sponsoren-banner`.
18+
19+
### Manual Installation
20+
21+
To install the plugin manually, download the zip-version of this repository and unzip it under `/your/site/grav/user/plugins`. Then rename the folder to `sponsoren-banner`. You can find these files on [GitHub](https://github.com/CoderDojoDeutschland/webseite-plugin-sponsoren-banner) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
22+
23+
You should now have all the plugin files under
24+
25+
/your/site/grav/user/plugins/sponsoren-banner
26+
27+
> NOTE: This plugin is a modular component for Grav which may require other plugins to operate, please see its [blueprints.yaml-file on GitHub](https://github.com/andi1984/grav-plugin-sponsoren-banner/blob/master/blueprints.yaml).
28+
29+
### Admin Plugin
30+
31+
If you use the Admin Plugin, you can install the plugin directly by browsing the `Plugins`-menu and clicking on the `Add` button.
32+
33+
## Configuration
34+
35+
Before configuring this plugin, you should copy the `user/plugins/sponsoren-banner/sponsoren-banner.yaml` to `user/config/plugins/sponsoren-banner.yaml` and only edit that copy.
36+
37+
Here is the default configuration and an explanation of available options:
38+
39+
```yaml
40+
enabled: true
41+
text_var: Sponsorenliste im JSON Format {label, image, url}
42+
```
43+
44+
Note that if you use the Admin Plugin, a file with your configuration named sponsoren-banner.yaml will be saved in the `user/config/plugins/`-folder once the configuration is saved in the Admin.
45+
46+
## Usage
47+
48+
### Save sponsors information in plugin settings (admin area)
49+
50+
You can use the text variable field in the plugin settings admin page to save a serialized JSON file in the following format
51+
52+
```json
53+
[
54+
{
55+
"label": "Sponsor #1",
56+
"image": "<image url>",
57+
"url": "<url to sponosr website>"
58+
},
59+
60+
]
61+
```
62+
63+
### Create a related twig file in your theme
64+
65+
Create a twig file in `partials/sponsors.html.twig` of your theme. The plugin will inject the `sponsors` variable as type array into the twig file and thus you can usage in whatever way you like.

blueprints.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Sponsoren Banner
2+
version: 0.1.0
3+
description: Ein Banner welcher die Sponsoren zeigt
4+
icon: plug
5+
author:
6+
name: Andreas Sander
7+
8+
homepage: https://github.com/andi1984/grav-plugin-sponsoren-banner
9+
demo: http://demo.yoursite.com
10+
keywords: grav, plugin, etc
11+
bugs: https://github.com/andi1984/grav-plugin-sponsoren-banner/issues
12+
docs: https://github.com/andi1984/grav-plugin-sponsoren-banner/blob/develop/README.md
13+
license: MIT
14+
15+
form:
16+
validation: strict
17+
fields:
18+
enabled:
19+
type: toggle
20+
label: PLUGIN_ADMIN.PLUGIN_STATUS
21+
highlight: 1
22+
default: 0
23+
options:
24+
1: PLUGIN_ADMIN.ENABLED
25+
0: PLUGIN_ADMIN.DISABLED
26+
validate:
27+
type: bool
28+
text_var:
29+
type: text
30+
label: PLUGIN_SPONSOREN_BANNER.TEXT_VARIABLE
31+
help: PLUGIN_SPONSOREN_BANNER.TEXT_VARIABLE_HELP

languages.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
en:
2+
PLUGIN_SPONSOREN_BANNER:
3+
TEXT_VARIABLE: Text Variable
4+
TEXT_VARIABLE_HELP: Text to add to the top of a page

sponsoren-banner.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Grav\Plugin;
4+
5+
use Grav\Common\Plugin;
6+
7+
/**
8+
* Class SponsorenBannerPlugin
9+
* @package Grav\Plugin
10+
*/
11+
class SponsorenBannerPlugin extends Plugin
12+
{
13+
/**
14+
* @return array
15+
*
16+
* The getSubscribedEvents() gives the core a list of events
17+
* that the plugin wants to listen to. The key of each
18+
* array section is the event that the plugin listens to
19+
* and the value (in the form of an array) contains the
20+
* callable (or function) as well as the priority. The
21+
* higher the number the higher the priority.
22+
*/
23+
public static function getSubscribedEvents()
24+
{
25+
return [
26+
'onPluginsInitialized' => ['onPluginsInitialized', 0],
27+
'onTwigExtensions' => ['onTwigExtensions', 0]
28+
];
29+
}
30+
31+
/**
32+
* Initialize the plugin
33+
*/
34+
public function onPluginsInitialized()
35+
{
36+
// Don't proceed if we are in the admin plugin
37+
if ($this->isAdmin()) {
38+
return;
39+
}
40+
}
41+
42+
public function onTwigExtensions()
43+
{
44+
if ($this->isAdmin()) {
45+
return;
46+
}
47+
require_once(__DIR__ . '/twig/Sponsoren.php');
48+
49+
$sponsors = json_decode($this->config->get('plugins.sponsoren-banner.text_var'));
50+
return $this->grav['twig']->twig->addExtension(new SponsorenTwigExtension($sponsors));
51+
}
52+
}

sponsoren-banner.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
enabled: true
2+
text_var: Sponsorenliste im JSON Format {label, image, url}

twig/Sponsoren.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Grav\Plugin;
4+
5+
class SponsorenTwigExtension extends \Twig_Extension
6+
{
7+
public function __construct($sponsors)
8+
{
9+
$this->sponsors = $sponsors;
10+
}
11+
12+
public function getName()
13+
{
14+
return 'SponsorenTwigExtension';
15+
}
16+
public function getFunctions()
17+
{
18+
return [
19+
new \Twig_SimpleFunction('sponsoren', [$this, 'renderSponsoren'], [
20+
'is_safe' => ['html'],
21+
'needs_environment' => true // Tell twig we need the environment
22+
])
23+
];
24+
}
25+
public function renderSponsoren(\Twig_Environment $env)
26+
{
27+
return $env->render("partials/sponsors.html.twig", ['sponsors' => $this->sponsors]);
28+
}
29+
}

0 commit comments

Comments
 (0)