Addpixel / KirbyComments

[Kirby 2] File-based comments stored as subpages for the Kirby CMS.
MIT License
68 stars 5 forks source link

Preview error #34

Open jenstornell opened 7 years ago

jenstornell commented 7 years ago

I have now tried this plugin for the first time and I get an error. When I click on the preview button I am sent to an error page with this url: #comment-1

I suspect it has to do with that I use a route for the page. Instead of example.com/items/name I use example.com/name.

Any way around it?

Update

I get the same result if I just use submit directly.

Update 2

Maybe it's possible to force to send it to items/name for the comment creation and then redirect back to the name page again, or redirect to a thankyou-page.

Update 3

I changed my route to 'method' => 'GET|POST', (included POST) and I changed the form to:

<form action="<?php echo u($page->slug()); ?>#comment-<?php echo $comments->nextCommentId() ?>"

Now I got the preview to work. When I try to submit I get error 300 which seems to be "The current session is invalid."

This time it created comments.txt (the archive) but no comments folders or comments.

florianpircher commented 7 years ago

Could you please describe the file structure after submitting a comment for the first time on a page. As I understand it, it currently looks like this:

some-page/
L some-template.txt
L comments.txt

… instead of this:

some-page/
L some-template.txt
  L comments/
    L comments.txt
    L 1-comment-1/
      L comment.txt
jenstornell commented 7 years ago

My real folder structure now looks like this:

items/
L a-page/
   L comments/
      L comments.txt
   L item-template.txt

It creates comments folder and comments.txt, but no additional folder with my comment.

On the page I remove items with a route so it looks like this:

http://example.com/a-page

Because I added POST, I can now preview the comment without any trouble with the standard comments-form.php snippet without modification.

Update

I just noticed that it creates comments.txt and the folder for it when I click the preview. That explain why that works because the preview works. The issue with error 300 still remains on submit.

Update 2

I wrote a double folder in the structure above. I've corrected it now. So there seems to be nothing wrong with the folder/file structure.

Update 3

This is how my route looks like:

// Items
foreach(page('items')->children() as $item) {
    $items[] = '(' . $item->slug() . ')';
}
$kirby->set('route', [
    'pattern' => $items,
    'method' => 'GET|POST',
    'action' => function($uid) {
        return site()->visit('items/' . $uid);
    }
]);
jenstornell commented 7 years ago

I just added an invite to my private repository in case you want to test my site.

florianpircher commented 7 years ago

I’ll have a look this afternoon.

jenstornell commented 7 years ago

Did you look into it yesterday? I'm working with other issues in the meantime. If I don't get it solved I need to look for another comment system, but if I get it to work well in the end I will make a donation of 100EUR to your account, as soon as I get my first real comment from a user. :)

florianpircher commented 7 years ago

I’ve tested writing a comment on /natlan and it worked. I am using macOS 10.12.6 with PHP 7.0.8 on MAMP Pro 3.5.2. (This is an animated GIF, give it time to load.)

2017-09-20 11_12_44

jenstornell commented 7 years ago

Alright! :) If "natlan" works for you, then all of them probably work?

I'm working in a localhost environment on Windows and I guess that's the problem? Something with the localhost session?

I will try it on a test domain then and see if that works. It will be a sub domain, so I hope sub domains are supported by your plugin.

florianpircher commented 7 years ago

Yes, all of them work. Because of the 300 error it has to fail in plugin/Comments.php between line 327 and line 335. Try logging (var_dump or similar) the variables $session_id and $post_session_id on your system. (just edit the plugins core for testing’s sake)

jenstornell commented 6 years ago

Sorry about the delay. I've been doing other things. Now I have tried it on a test domain and it worked, except for the additional star rating which is saved wrong but I add a new issue about that.

jenstornell commented 6 years ago

Yes, all of them work. Because of the 300 error it has to fail in plugin/Comments.php between line 327 and line 335. Try logging (var_dump or similar) the variables $session_id and $post_session_id on your system. (just edit the plugins core for testing’s sake)

I did that now on my localhost where the problem still accur. I don't know what you can read from this but they are not equal, that's for sure.

string(32) "3d8a27893b41a97d1be106cf2a4c71a4" string(32) "79ae52a3259e94dcc9294c425df2fbeb"

Error 300

florianpircher commented 6 years ago

I can infer nothing from these IDs because they are just randomly generated strings. I suspect your local server modifies the PHP session during routing, that inevitably changes the session ID and invalidates the request.

jenstornell commented 6 years ago

I can confirm that these strings changes every time I save/send the form. But maybe it should, I don't know. But I can use the panel without being logged out.

Maybe we can add a option to skip the comparation of the strings? Something like if(c::get('comments.debug')) // Skip comparation

Or don't compare the strings if the user is logged in into the panel. Maybe that would be better? A logged in user is probably not a spammer.

If not, I need to hack the plugin in order to have a decent test environment.

S1SYPHOS commented 6 years ago

Got the same problem as @jenstornell - I omit the 'home' directory (as described in the cookbook) and land on an error page, when previewing and / or submitting a comment.

Any ideas where to look?

BTW upon disabling the route, I receive "Too few arguments to function Kirby\Component\Smartypants::parse()" error, coming from the <?= $comment->message() ?> call in the comments-list.php file, line 38.

// Edit: The smartypants error is related to this bug, which will be fixed in the next Kirby version.

// Update: Yep, I may now comment stuff, but only when disabling my route:

c::set('routes', array(
  array(
    'pattern' => '(:any)',
    'action'  => function($uid) {

      $page = page($uid);

      if(!$page) $page = page('home/' . $uid);
      if(!$page) $page = site()->errorPage();

      return site()->visit($page);

    }
  ),
  array(
    'pattern' => 'home/(:any)',
    'action'  => function($uid) {
      go($uid);
    }
  )
));
florianpircher commented 6 years ago

@S1SYPHOS I suspect the $uid variable includes some extra information (most probably the fragment identifier) that irritates the page($uri) function (line 6 and 8 in your code). I will try recreating your use-case. In the meantime, try removing the action-attribute in site/plugins/comments/snippets/comments-form.php on your local installation and see if that fixes the routing problem.

S1SYPHOS commented 6 years ago

Hey there, removing it doesn't do much (except throwing 404). If you like, inspect the project in question (comments branch).

Thank you so far!

// Offtopic: Are there any known examples for (theoretically infinitely stacked) nested comments?

florianpircher commented 6 years ago

I have cloned your project, switched to the comments branch and tried commenting on /home/review-macbook-air-13-2013. Both preview and submission work as suspected. Could you please send me a summary of your development setup? My setup: PHP 7.1.8 – no special extensions – on Apache.

florianpircher commented 6 years ago

Are there any known examples for (theoretically infinitely stacked) nested comments?

No examples come to mind … maybe a long back-and-forth-discussion between two commentators? Kirby Comments can be used to nest comments theoretically infinitely deep if that is a feature that you require.

S1SYPHOS commented 6 years ago

I meant if you could provide an example on how to implement it 👍

florianpircher commented 6 years ago

@S1SYPHOS For an example implementation of nested comments you can try and download the Replies demo. It includes a snippet called nested-comments which renders both a comments list and a comments form.

S1SYPHOS commented 6 years ago

I'm currently trying out your snippet, but somehow it doesn't work, all comments are nested-comment level-1 .. maybe the downloadable file is not the one being used on the live demo?

florianpircher commented 6 years ago

From the demo page:

This demo shows the nesting feature in conjunction with custom fields. The reply-to field stores the ID of the comment you are replying to. This information is used to nest comments based on their reply-to-to-comment-id relationship.

You need a custom field to store the reference value. Something like this:

c::set('comments.custom-fields', array(
  array('name' => 'reply-to')
));

You can find out more about custom fields in the Custom Fields guide.

S1SYPHOS commented 6 years ago

Silly me, totally forgot about that - codesaver!

// Edit: How could I go about if I wanted to reply via <a href="" / onclick=""> next to each comment?

florianpircher commented 6 years ago

In the demo the nesting relationship is established using radio buttons with a name attribute of reply-to. I use radio buttons for the demo because they do not require any JavaScript. If you want to use a different control (custom button, link, …) you could – for example – use a hidden field to store the reply-to value and set it using JavaScript.