-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f289ff1
Showing
74 changed files
with
3,017 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# v0.1.0 | ||
## 07/25/2020 | ||
|
||
1. [](#new) | ||
* ChangeLog started... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 Thomas Vantuycom | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Laposta Plugin | ||
|
||
The **Laposta** Plugin is an extension for [Grav CMS](http://github.com/getgrav/grav) that adds a Laposta subscription action to your forms? | ||
|
||
## Installation | ||
|
||
Installing the Laposta 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. | ||
|
||
### GPM Installation (Preferred) | ||
|
||
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: | ||
|
||
bin/gpm install laposta | ||
|
||
This will install the Laposta plugin into your `/user/plugins`-directory within Grav. Its files can be found under `/your/site/grav/user/plugins/laposta`. | ||
|
||
### Manual Installation | ||
|
||
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 `laposta`. You can find these files on [GitHub](https://github.com/the-dancing-code/grav-plugin-laposta) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras). | ||
|
||
You should now have all the plugin files under | ||
|
||
/your/site/grav/user/plugins/laposta | ||
|
||
> 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/the-dancing-code/grav-plugin-laposta/blob/master/blueprints.yaml). | ||
### Admin Plugin | ||
|
||
If you use the Admin Plugin, you can install the plugin directly by browsing the `Plugins`-menu and clicking on the `Add` button. | ||
|
||
## Configuration | ||
|
||
Before configuring this plugin, you should copy the `user/plugins/laposta/laposta.yaml` to `user/config/plugins/laposta.yaml` and only edit that copy. | ||
|
||
Note that if you use the Admin Plugin, a file with your configuration named laposta.yaml will be saved in the `user/config/plugins/`-folder once the configuration is saved in the Admin. | ||
|
||
Here is the default configuration and an explanation of available options: | ||
|
||
```yaml | ||
enabled: true | ||
api_key: | ||
default_list_id: | ||
``` | ||
|
||
### api_key | ||
|
||
Your Laposta API key. Can be found in [your dashboard](https://app.laposta.nl/config/c.connect/s.api/). | ||
|
||
### default_list_id | ||
|
||
The ID of the list subscribers will be added to by default, when no list is specified in the form definition. Your list ID's can be found in [your dashboard](https://app.laposta.nl/c.listconfig/s.settings/t.config/). | ||
|
||
## Usage | ||
|
||
Setup a form with the laposta action: | ||
|
||
```yaml | ||
form: | ||
name: subscribe | ||
fields: | ||
firstname: | ||
label: First name | ||
type: text | ||
surname: | ||
label: Surname | ||
type: text | ||
email: | ||
label: Email | ||
type: email | ||
validate: | ||
required: true | ||
buttons: | ||
submit: | ||
type: submit | ||
value: Subscribe | ||
process: | ||
- ip: true | ||
- laposta: true | ||
- message: Thank you for subscribing! | ||
``` | ||
|
||
Add any fields from your Laposta list, but make sure to use the names as defined in [your dashboard](https://app.laposta.nl/c.listconfig/s.settings/t.fields/). | ||
|
||
It is important that the `ip` action is enabled. | ||
|
||
You can define a list ID in the laposta action if you wish to override the default list: | ||
|
||
```yaml | ||
process: | ||
- ip: true | ||
- laposta: | ||
list_id: xxxxxxxx | ||
- message: Thank you for subscribing! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Laposta | ||
version: 0.1.0 | ||
description: Adds a Laposta subscription action to your forms | ||
icon: address-card | ||
author: | ||
name: Thomas Vantuycom | ||
email: thomasvantuycom@protonmail.com | ||
homepage: https://github.com/TheDancingCode/grav-plugin-laposta | ||
keywords: grav, plugin, laposta, newsletter | ||
bugs: https://github.com/TheDancingCode/grav-plugin-laposta/issues | ||
docs: https://github.com/TheDancingCode/grav-plugin-laposta/blob/develop/README.md | ||
license: MIT | ||
|
||
dependencies: | ||
- { name: grav, version: '>=1.6.0' } | ||
|
||
form: | ||
validation: loose | ||
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 | ||
api_key: | ||
type: text | ||
label: PLUGIN_LAPOSTA.API_KEY | ||
validate: | ||
required: true | ||
default_list_id: | ||
type: text | ||
label: PLUGIN_LAPOSTA.DEFAULT_LIST_ID | ||
help: PLUGIN_LAPOSTA.DEFAULT_LIST_ID_HELP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "TheDancingCode/laposta", | ||
"type": "grav-plugin", | ||
"description": "Adds a Laposta subscription action to your forms", | ||
"keywords": ["plugin"], | ||
"homepage": "https://github.com/TheDancingCode/grav-plugin-laposta", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Thomas Vantuycom", | ||
"email": "thomasvantuycom@protonmail.com", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.1.3", | ||
"laposta/laposta-api-php": "^1.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Grav\\Plugin\\Laposta\\": "classes/" | ||
}, | ||
"classmap": ["laposta.php"] | ||
}, | ||
"config": { | ||
"platform": { | ||
"php": "7.1.3" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
en: | ||
PLUGIN_LAPOSTA: | ||
API_KEY: API key | ||
DEFAULT_LIST_ID: Default list ID | ||
DEFAULT_LIST_ID_HELP: List subscribers will be added to when no list is specified in the form definition | ||
ERROR_MESSAGE: Something went wrong. Please try again later. | ||
nl: | ||
PLUGIN_LAPOSTA: | ||
API_KEY: API key | ||
DEFAULT_LIST_ID: Standaard lijst ID | ||
DEFAULT_LIST_ID_HELP: Lijst waaraan relaties worden toegevoegd wanneer geen lijst bepaald wordt in de configuratie van het formulier | ||
ERROR_MESSAGE: Er liep iets mis. Probeer het later opnieuw. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
namespace Grav\Plugin; | ||
|
||
require_once(__DIR__ . "/vendor/laposta/laposta-api-php/lib/Laposta.php"); | ||
|
||
use Composer\Autoload\ClassLoader; | ||
use Grav\Common\Plugin; | ||
use RocketTheme\Toolbox\Event\Event; | ||
use \Laposta; | ||
use \Laposta_Member; | ||
use \Laposta_Error; | ||
|
||
/** | ||
* Class LapostaPlugin | ||
* @package Grav\Plugin | ||
*/ | ||
class LapostaPlugin 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 [ | ||
['autoload', 100000], // TODO: Remove when plugin requires Grav >=1.7 | ||
'onPluginsInitialized' => ['onPluginsInitialized', 0] | ||
]; | ||
} | ||
|
||
/** | ||
* Composer autoload. | ||
*is | ||
* @return ClassLoader | ||
*/ | ||
public function autoload(): ClassLoader | ||
{ | ||
return require __DIR__ . '/vendor/autoload.php'; | ||
} | ||
|
||
/** | ||
* Initialize the plugin | ||
*/ | ||
public function onPluginsInitialized() | ||
{ | ||
// Don't proceed if we are in the admin plugin | ||
if ($this->isAdmin()) { | ||
return; | ||
} | ||
|
||
// Enable the main events we are interested in | ||
$this->enable([ | ||
'onFormProcessed' => ['onFormProcessed', 0] | ||
]); | ||
} | ||
|
||
public function onFormProcessed($event) | ||
{ | ||
$form = $event['form']; | ||
$action = $event['action']; | ||
$params = $event['params']; | ||
|
||
switch ($action) { | ||
case 'laposta': | ||
|
||
$api_key = $this->config->get('plugins.laposta.api_key'); | ||
Laposta::setApiKey($api_key); | ||
|
||
$default_list_id = $this->config->get('plugins.laposta.default_list_id'); | ||
$list_id = is_array($params) && array_key_exists('list_id', $params) ? $params['list_id'] : $default_list_id; | ||
$member = new Laposta_Member($list_id); | ||
|
||
$data = $form['data']->toArray(); | ||
$ip = $data['ip']; | ||
$email = $data['email']; | ||
$source_url = $form['page']->url(true); | ||
$custom_fields = $data; | ||
|
||
try { | ||
$result = $member->create(array( | ||
'ip' => $ip, | ||
'email' => $email, | ||
'source_url' => $source_url, | ||
'custom_fields' => $custom_fields | ||
)); | ||
} catch (Laposta_Error $e) { | ||
$error = $e->getJsonBody()['error']; | ||
|
||
if (array_key_exists('code', $error) && $error['code'] == 204) { | ||
return; | ||
} | ||
|
||
$this->grav['log']->error($e); | ||
|
||
$message = $this->grav['language']->translate('PLUGIN_LAPOSTA.ERROR_MESSAGE'); | ||
$this->grav->fireEvent( | ||
'onFormValidationError', | ||
new Event([ | ||
'form' => $form, | ||
'message' => $message | ||
]) | ||
); | ||
$event->stopPropagation(); | ||
return; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
enabled: true | ||
api_key: | ||
default_list_id: |
Oops, something went wrong.