Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
florianpircher committed Mar 25, 2017
2 parents f00713c + 1c9e5b4 commit 0b67b88
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 86 deletions.
20 changes: 16 additions & 4 deletions README.md
Expand Up @@ -34,17 +34,29 @@ When updating, simply delete the old *comments* folder and replace it with the n

## Usage

The Kirby Comments plugin comes with an example snippet, `comments`, which lists all comments of a page and provides a form for submitting new ones.
Kirby Comments includes three snippets: `comments-form`, `comments-list` and `comments`. `comments-form` renders an HTML form for writing comments, `comments-list` lists all comments and `comments` is a convenience snippet for rendering the list and the form.

To use the `comments` snippet, include it on the page where the comments and the comments form should appear.
A quick and easy installation could use the following code:

```php
<div class="comments">
<?php snippet('comments') ?>
</div>
```

You are not limited to using the `comments` snipped shipped with this plugin. Feel free to learn from [the source code](https://github.com/Addpixel/KirbyComments/blob/master/snippets/comments.php) and write your own comments form if the `comments` snippet doesn’t suit your needs.
You can also place the form and list separately:

```php
<div class="comments-list">
<?php snippet('comments-list') ?>
</div>
...
<div class="comments-form">
<?php snippet('comments-form') ?>
</div>
```

You are by no means limited to the snippets shipped with Kirby Comments. If you want to create your own form or comments list, I recommend having a look at [the source code of the example snippets](https://github.com/Addpixel/KirbyComments/tree/master/snippets) and reading about [custom markup](#custom-markup) the [Kirby Comments API](#api-documentation). Custom behaviour should be configured using [Kirby Comments options](#options).

## Options

Expand Down Expand Up @@ -282,7 +294,7 @@ Whether the current preview is valid. `false`, if no preview is performed.
```php
<?php foreach ($comments as $comment): ?>
...
<?php endforeach ?>>
<?php endforeach ?>
```

#### `$comment->id() : integer`
Expand Down
12 changes: 9 additions & 3 deletions blueprints/comment.php → blueprints/comment.yml
@@ -1,33 +1,39 @@
<?php if(!defined('KIRBY')) exit ?>

title: Comment

pages: false

files: false

icon: comment

fields:
name:
label: Name
type: text
required: true
width: 1/2
icon: user

date:
label: Date
type: datetime
width: 1/2
validate:
date

email:
label: Email Address
type: email
width: 1/2
validate:
email

url:
label: Website Address
type: url
width: 1/2

text:
label: Text
required: true
type: textarea
type: textarea
9 changes: 6 additions & 3 deletions blueprints/comments.php → blueprints/comments.yml
@@ -1,15 +1,18 @@
<?php if(!defined('KIRBY')) exit ?>

title: Comments

pages: true

files: false

icon: comments

fields:
title:
label: Title
type: text
required: true

text:
label: Text
required: true
type: textarea
type: textarea
8 changes: 5 additions & 3 deletions comments.php
Expand Up @@ -8,6 +8,8 @@
/**
* The Kirby extension registry
*/
$kirby->set('blueprint', 'comments', __DIR__ . '/blueprints/comments.php');
$kirby->set('blueprint', 'comment', __DIR__ . '/blueprints/comment.php');
$kirby->set('snippet', 'comments', __DIR__ . '/snippets/comments.php');
$kirby->set('blueprint', 'comments', __DIR__.'/blueprints/comments.yml');
$kirby->set('blueprint', 'comment', __DIR__.'/blueprints/comment.yml');
$kirby->set('snippet', 'comments-form', __DIR__.'/snippets/comments-form.php');
$kirby->set('snippet', 'comments-list', __DIR__.'/snippets/comments-list.php');
$kirby->set('snippet', 'comments', __DIR__.'/snippets/comments.php');
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -3,13 +3,13 @@
"description": "File based comments stored as subpages for the Kirby CMS.",
"author": "Florian Pircher <florian@addpixel.net>",
"license": "MIT",
"version": "1.2.2",
"version": "1.3.0",
"type": "kirby-plugin",
"repository": {
"type": "git",
"url": "https://github.com/Addpixel/KirbyComments"
},
"bugs": {
"bugs": {
"url": "https://github.com/Addpixel/KirbyComments/issues"
}
}
2 changes: 1 addition & 1 deletion plugin/comments-email.php
Expand Up @@ -60,7 +60,7 @@ public function format($x)
{
$identifer = $matches[1];

if (isset($placeholders[$identifer])) {
if ($placeholders[$identifer]) {
return $placeholders[$identifer];
} else {
return Comments::option('email.undefined-value');
Expand Down
66 changes: 66 additions & 0 deletions snippets/comments-form.php
@@ -0,0 +1,66 @@
<?php

/*
* This is the example comments form snippet. Feel free to use this code as a
* reference for creating your own, custom comments snippet.
*
* Custom snippet markup guide:
* <https://github.com/Addpixel/KirbyComments#custom-markup>
*
* API documentation:
* <https://github.com/Addpixel/KirbyComments#api-documentation>
*/

if (kirby()->get('option', 'comments.runtime.comments') == null) {
// Create `Comments` object for the current page
$comments = new Comments($page);
$status = $comments->process();

// Store `Comments` object and status for `comments-list` snippet
kirby()->set('option', 'comments.runtime.comments', $comments);
kirby()->set('option', 'comments.runtime.status', $status);
} else {
// Load `Comments` object and status from
$comments = kirby()->get('option', 'comments.runtime.comments');
$status = kirby()->get('option', 'comments.runtime.status');
}

?>
<?php if ($comments->userHasSubmitted()): ?>
<p class="thank-you">Thank you for your comment!</p>
<?php else: ?>
<h2 id="comments-form-headline">Write your comment</h2>

<?php if ($status->isUserError()): ?>
<p id="comment-<?= $comments->nextCommentId() ?>" class="error">
<?= $status->getMessage() ?>
</p>
<?php endif ?>

<form action="#comment-<?= $comments->nextCommentId() ?>" method="post" accept-charset="utf-8" role="form" aria-labelledby="comments-form-headline">
<label for="name">Name<abbr title="required">*</abbr></label>
<input type="text" name="<?= $comments->nameName() ?>" value="<?= $comments->value($comments->nameName()) ?>" id="name" maxlength="<?= $comments->nameMaxLength() ?>" required>

<label for="email">Email Address<?php if ($comments->requiresEmailAddress()): ?><abbr title="required">*</abbr><?php endif ?></label>
<input type="email" name="<?= $comments->emailName() ?>" value="<?= $comments->value($comments->emailName()) ?>" id="email" maxlength="<?= $comments->emailMaxLength() ?>"<?php e($comments->requiresEmailAddress(), ' required') ?>>

<label for="website">Website</label>
<input type="url" name="<?= $comments->websiteName() ?>" value="<?= $comments->value($comments->websiteName()) ?>" id="website" maxlength="<?= $comments->websiteMaxLength() ?>">

<?php if ($comments->isUsingHoneypot()): ?>
<div style="display: none" hidden>
<input type="text" name="<?= $comments->honeypotName() ?>" value="<?= $comments->value($comments->honeypotName()) ?>">
</div>
<?php endif ?>

<label for="message">Message<abbr title="required">*</abbr></label>
<textarea name="<?= $comments->messageName() ?>" id="message" maxlength="<?= $comments->messageMaxLength() ?>" required><?= $comments->value($comments->messageName()) ?></textarea>

<input type="hidden" name="<?= $comments->sessionIdName() ?>" value="<?= $comments->sessionId() ?>">

<input type="submit" name="<?= $comments->previewName() ?>" value="Preview">
<?php if ($comments->validPreview()): ?>
<input type="submit" name="<?= $comments->submitName() ?>" value="Submit" id="submit">
<?php endif ?>
</form>
<?php endif ?>
54 changes: 54 additions & 0 deletions snippets/comments-list.php
@@ -0,0 +1,54 @@
<?php

/*
* This is the example comments list snippet. Feel free to use this code as a
* reference for creating your own, custom comments snippet.
*
* Custom snippet markup guide:
* <https://github.com/Addpixel/KirbyComments#custom-markup>
*
* API documentation:
* <https://github.com/Addpixel/KirbyComments#api-documentation>
*/

if (kirby()->get('option', 'comments.runtime.comments') == null) {
// Create `Comments` object for the current page
$comments = new Comments($page);
$status = $comments->process();

// Store `Comments` object and status for `comments-form` snippet
kirby()->set('option', 'comments.runtime.comments', $comments);
kirby()->set('option', 'comments.runtime.status', $status);
} else {
// Load `Comments` object and status from
$comments = kirby()->get('option', 'comments.runtime.comments');
$status = kirby()->get('option', 'comments.runtime.status');
}

?>
<?php if (!$comments->isEmpty()): ?>
<h2>Comments</h2>

<?php foreach ($comments as $comment): ?>
<article id="comment-<?= $comment->id() ?>" class="comment<?php e($comment->isPreview(), ' preview"') ?>">
<h3>
<?php e($comment->isLinkable(), "<a rel='nofollow noopener' href='{$comment->website()}'>") ?>
<?= $comment->name() ?>
<?php e($comment->isLinkable(), "</a>") ?>
</h3>

<aside class="comment-info">
<?php if ($comment->isPreview()): ?>
<p>This is a preview of your comment. If you’re happy with it, <a href="#submit" title="Jump to the submit button">submit</a> it to the public.</p>
<?php else: ?>
<p>
Posted on <?= $comment->date('Y-m-d') ?>.
<a href="#comment-<?= $comment->id() ?>" title="Permalink" area-label="Permalink">#</a>
</p>
<?php endif ?>
</aside>

<?= $comment->message() ?>
</article>
<?php endforeach ?>
<?php endif ?>
73 changes: 3 additions & 70 deletions snippets/comments.php
Expand Up @@ -4,79 +4,12 @@
* This is the example comments snippet. Feel free to use this code as a
* reference for creating your own, custom comments snippet.
*
* Custom snipper markup guide:
* Custom snippet markup guide:
* <https://github.com/Addpixel/KirbyComments#custom-markup>
*
* API documentation:
* <https://github.com/Addpixel/KirbyComments#api-documentation>
*/

$comments = new Comments($page);
$status = $comments->process();

?>
<?php if (!$comments->isEmpty()): ?>
<h2>Comments</h2>

<?php foreach ($comments as $comment): ?>
<article id="comment-<?= $comment->id() ?>" class="comment<?php e($comment->isPreview(), ' preview"') ?>">
<h3>
<?php e($comment->isLinkable(), "<a rel='nofollow noopener' href='{$comment->website()}'>") ?>
<?= $comment->name() ?>
<?php e($comment->isLinkable(), "</a>") ?>
</h3>

<aside class="comment-info">
<?php if ($comment->isPreview()): ?>
<p>This is a preview of your comment. If you’re happy with it, <a href="#submit" title="Jump to the submit button">submit</a> it to the public.</p>
<?php else: ?>
<p>
Posted on <?= $comment->date('Y-m-d') ?>.
<a href="#comment-<?= $comment->id() ?>" title="Permalink" area-label="Permalink">#</a>
</p>
<?php endif ?>
</aside>

<?= $comment->message() ?>
</article>
<?php endforeach ?>
<?php endif ?>

<?php if ($comments->userHasSubmitted()): ?>
<p class="thank-you">Thank you for your comment!</p>
<?php else: ?>
<h2 id="comments-form-headline">Write your comment</h2>

<?php if ($status->isUserError()): ?>
<p id="comment-<?= $comments->nextCommentId() ?>" class="error">
<?= $status->getMessage() ?>
</p>
<?php endif ?>

<form action="#comment-<?= $comments->nextCommentId() ?>" method="post" accept-charset="utf-8" role="form" aria-labelledby="comments-form-headline">
<label for="name">Name<abbr title="required">*</abbr></label>
<input type="text" name="<?= $comments->nameName() ?>" value="<?= $comments->value($comments->nameName()) ?>" id="name" maxlength="<?= $comments->nameMaxLength() ?>" required>

<label for="email">Email Address<?php if ($comments->requiresEmailAddress()): ?><abbr title="required">*</abbr><?php endif ?></label>
<input type="email" name="<?= $comments->emailName() ?>" value="<?= $comments->value($comments->emailName()) ?>" id="email" maxlength="<?= $comments->emailMaxLength() ?>"<?php e($comments->requiresEmailAddress(), ' required') ?>>

<label for="website">Website</label>
<input type="url" name="<?= $comments->websiteName() ?>" value="<?= $comments->value($comments->websiteName()) ?>" id="website" maxlength="<?= $comments->websiteMaxLength() ?>">

<?php if ($comments->isUsingHoneypot()): ?>
<div style="display: none" hidden>
<input type="text" name="<?= $comments->honeypotName() ?>" value="<?= $comments->value($comments->honeypotName()) ?>">
</div>
<?php endif ?>

<label for="message">Message<abbr title="required">*</abbr></label>
<textarea name="<?= $comments->messageName() ?>" id="message" maxlength="<?= $comments->messageMaxLength() ?>" required><?= $comments->value($comments->messageName()) ?></textarea>

<input type="hidden" name="<?= $comments->sessionIdName() ?>" value="<?= $comments->sessionId() ?>">

<input type="submit" name="<?= $comments->previewName() ?>" value="Preview">
<?php if ($comments->validPreview()): ?>
<input type="submit" name="<?= $comments->submitName() ?>" value="Submit" id="submit">
<?php endif ?>
</form>
<?php endif ?>
snippet('comments-list');
snippet('comments-form');

0 comments on commit 0b67b88

Please sign in to comment.