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.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
florianpircher committed May 23, 2017
2 parents 0b67b88 + b38e11a commit a161725
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ c::set('comments.pages.comments.title', function ($page) {
|---|---|---|---|---|
| `pages.comments.title` | Closure | `function ($page) { return 'Comments for “' . $page->title() . '”'; }` | Takes a `Page` on which a comment was posted and returns the title for the comments page as `string`. | |
| `pages.comments.dirname` | string | `"comments"` | Name of the folder of a comments page. | * |
| `pages.comments.template` | string | `"comments"` | Name of the template/blueprint of a comments page. | * |
| `pages.comment.dirname` | string | `"comment"` | Name of the folder of a comment page. | * |
| `pages.comment.template` | string | `"comment"` | Name of the template/blueprint of a comment page. | * |
| `pages.comment.visible` | bool | `true` | Whether comment pages are visible (have an index-prefix) .| * |
| `form.submit` | string | `"submit"` | POST name of the submit button. | |
| `form.preview` | string | `"preview"` | POST name of the preview button. | |
| `form.name` | string | `"name"` | POST name of the name field. | |
Expand Down Expand Up @@ -158,7 +161,7 @@ content/

As you can see, the comments are simply stored as subpages, grouped in a hidden comments directory. The naming scheme of the comment directories (1-comment-1, 2-comment-2, …) was chosen to provide the following functionalities:

- `#-` makes the comments **visible** and **orders it**.
- `#-` makes the comments **visible** and **orders it**. This can be disabled by setting the option `pages.comment.visible` to `false`.
- `comment-#` gives the comment a **unique address**, at which it can be located. This means, that every comment has a public URL like: www.example.org/blog/hello-world/comments/comment-1. If you would like, you can create `comments` and `comment` templates to style them. By default, both the comments list (some-page/comments) and the comment pages (some-page/comments/comment-1) are not referenced by any link, so no users will be linked to those pages.

### Handling New Comments
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "File based comments stored as subpages for the Kirby CMS.",
"author": "Florian Pircher <[email protected]>",
"license": "MIT",
"version": "1.3.0",
"version": "1.3.1",
"type": "kirby-plugin",
"repository": {
"type": "git",
Expand Down
31 changes: 25 additions & 6 deletions plugin/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class Comments implements Iterator
private static $deprecated_keys = array(
'pages.comments.title' => 'comments-page.title',
'pages.comments.dirname' => 'comments-page.dirname',
'pages.comments.template' => 'comments-page.template',
'pages.comment.dirname' => 'comment-page.dirname',
'pages.comment.template' => 'comment-page.template',
'form.email.required' => 'require.email',
'honeypot.enabled' => 'use.honeypot',
'email.enabled' => 'use.email',
Expand Down Expand Up @@ -79,7 +81,7 @@ function __construct($page)
$this->comments = array();
$this->valid_preview = false;

$comments_page_dirname = Comments::option('pages.comments.dirname', $page);
$comments_page_dirname = Comments::option('pages.comments.dirname');
$comments_page = $this->page->find($comments_page_dirname);

if ($comments_page != null) {
Expand Down Expand Up @@ -175,7 +177,7 @@ public function process()

if (!$is_send) { return $this->status; }

$comments_page_dirname = Comments::option('pages.comments.dirname', $this->page);
$comments_page_dirname = Comments::option('pages.comments.dirname');
$comments_page = $this->page->find($comments_page_dirname);

$now = new DateTime();
Expand All @@ -192,9 +194,11 @@ public function process()
if ($comments_page == null) {
// No comments page has been created yet. Create the comments subpage.
try {
$page_dirname = Comments::option('pages.comments.dirname');
$page_template = Comments::option('pages.comments.template');
$comments_page = $this->page->children()->create(
Comments::option('pages.comments.dirname', $this->page),
'comments',
$page_dirname,
$page_template,
array(
'title' => Comments::option('pages.comments.title', $this->page),
'date' => $now->format('Y-m-d H:i:s')
Expand All @@ -210,9 +214,21 @@ public function process()
// The commentator is happy with the preview and has submitted the
// comment to be published on the website.
try {
$page_dirname = Comments::option('pages.comment.dirname');
$page_uri = $page_dirname.'-'.$new_comment_id;
$page_dirname = $page_uri;

if (Comments::option('pages.comment.visible')) {
// add index-prefix to dirname
$page_index = $new_comment_id;
$page_dirname = $page_index.'-'.$page_dirname;
}

$page_template = Comments::option('pages.comment.template');

$new_comment_page = $comments_page->children()->create(
"$new_comment_id-".Comments::option('pages.comment.dirname', $this->page)."-$new_comment_id",
Comments::option('pages.comment.dirname', $this->page),
$page_dirname,
$page_template,
array(
'cid' => $new_comment_id,
'date' => $new_comment->date('Y-m-d H:i:s'),
Expand Down Expand Up @@ -423,7 +439,10 @@ function valid()
return 'Comments for “' . $page->title() . '';
},
'pages.comments.dirname' => 'comments',
'pages.comments.template' => 'comments',
'pages.comment.dirname' => 'comment',
'pages.comment.template' => 'comment',
'pages.comment.visible' => true,
'form.submit' => 'submit',
'form.preview' => 'preview',
'form.name' => 'name',
Expand Down

0 comments on commit a161725

Please sign in to comment.