Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jan 6, 2016
2 parents 6a70cd7 + 4c24164 commit 36f99d0
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 23 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# v0.3.0
## 01/06/2016

1. [](#bugfix)
* Correctly add the templates path

# v0.2.2
## 11/20/2015

1. [](#bugfix)
* Only load the messages on guestbook pages, if the page exists

# v0.2.1
## 11/06/2015

1. [](#bugfix)
* Show "Guestbook" in the available page templates

# v0.2.0
## 10/27/2015

1. [](#bugfix)
* Fix loading guestbook messages on the first page load

# v0.1.0
## 10/16/2015

1. [](#new)
* ChangeLog started...
13 changes: 1 addition & 12 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Guestbook
version: 0.1.0
version: 0.3.0
description: Adds a Guestbook functionality to a page
icon: book
author:
Expand Down Expand Up @@ -30,17 +30,6 @@ form:
validate:
type: bool

use_captcha:
type: toggle
label: Use Captcha
highlight: 1
default: 0
options:
1: 'True'
0: 'False'
validate:
type: bool

filename:
type: text
label: Filename
Expand Down
78 changes: 69 additions & 9 deletions guestbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
'onFormProcessed' => ['onFormProcessed', 10],
'onDataTypeExcludeFromDataManagerPluginHook' => ['onDataTypeExcludeFromDataManagerPluginHook', 0],
'onGetPageTemplates' => ['onGetPageTemplates', 0]
];
}

Expand All @@ -30,22 +33,71 @@ public function onPluginsInitialized()
{
if (!$this->isAdmin()) {
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onPageInitialized' => ['onPageInitialized', 0],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0]
]);
}
}

/**
* Initialize configuration
*/
public function onPageInitialized()
{
/** @var Page $page */
$page = $this->grav['page'];

$page = $this->grav['uri']->param('page');
$messages = $this->getMessages($page);
if ($page->template() == 'guestbook') {
//Call this here to get the messages on the page load
$this->fetchMessages();
}
}

if ($page > 0) {
echo json_encode($messages);
exit();
}
/**
* Add page template types.
*/
public function onGetPageTemplates(Event $event)
{
/** @var Types $types */
$types = $event->types;
$types->scanTemplates('plugins://guestbook/templates');
}

$this->grav['twig']->guestbookMessages = $messages;
/**
* Handle form processing instructions.
*
* @param Event $event
*/
public function onFormProcessed(Event $event)
{
if (!$this->active) {
return;
}

//Call this here to get the messages updated after the form is processed
$this->fetchMessages();
}

private function getMessages($page = 0) {
/**
* Fetch the page messages.
*
* @param Event $event
*/
public function fetchMessages()
{
$page = $this->grav['uri']->param('page');
$messages = $this->getMessages($page);

if ($page > 0) {
echo json_encode($messages);
exit();
}

$this->grav['twig']->guestbookMessages = $messages;
}

private function getMessages($page = 0)
{
$itemsPerPage = 5;

$lang = $this->grav['language']->getActive();
Expand Down Expand Up @@ -79,4 +131,12 @@ public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}

/**
* Exclude comments from the Data Manager plugin
*/
public function onDataTypeExcludeFromDataManagerPluginHook()
{
$this->grav['admin']->dataTypesExcludedFromDataManagerPlugin[] = 'guestbook';
}
}
1 change: 0 additions & 1 deletion guestbook.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
enabled: true
use_captcha: true
filename: messages.yaml
8 changes: 7 additions & 1 deletion languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ en:
PLUGIN_GUESTBOOK:
MESSAGES: Messages
WRITTEN_ON: Written on
BY: by
BY: by

fr:
PLUGIN_GUESTBOOK:
MESSAGES: Messages
WRITTEN_ON: Ecrits le
BY: par

0 comments on commit 36f99d0

Please sign in to comment.