Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement showcase (ajax, gravatar, nested, delete) #65

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from

Conversation

codeshell
Copy link

Hi there,

added some functionality for my own use. Since some of it is listed in #22 you might be able to reuse some of it, namely:

  • ajax submission
  • gravatar support
  • styling
  • nested comments
  • delete comments as admin,super (from frontend)

Two things to be aware of:

  • I don't care about the backend presentation (admin panel) so that's most likely broken.
  • I changed the save logic to use the current page folder which is my personal preference. Comments are stored with the markdown file they belong to, Mainly because of three reasons:
    1. changing routes doesn't orphan comments
    2. deleting pages physically deletes the corresponding comments
    3. comments are git-synced

Should be seen as WIP as it is not heavily tested.

Regards,
Thorsten

Screenshot 1:
image

Screenshot 2:
image

@nickbroon
Copy link

This appears to also help with #51 by moving the comments to the page folder.

@dotvhs
Copy link

dotvhs commented Oct 28, 2017

This is epic. Thank you @codeshell for this, I was looking for something like this for a long time and I'm not skilled enough to write my own.

add recent comments widget as twig function
add save authentication and admin status with comments
@codeshell
Copy link
Author

codeshell commented Oct 29, 2017

Thanks for your kind words. Anybody experimenting with the code feel free to notify me of any issues you run into. Meanwhile I will update this PR from time to time as I see fit for my current use case.

It might help as an alternative to #60 and seems to tackle #51 indeed. I really like the suggestions #48 and #49 by Salvatos so I added variants of them to the backend with the recent commit to be used in twig templates as needed. Example usage:
image

@foufrix
Copy link

foufrix commented Jan 11, 2018

super nice ! thanks for that ! i'm gonna take a look right away.

Why no merge from the author ?

@codeshell i tried to clone your git and put it in plugin, it does not render as what i can see on your picture.

Also i only have the comment box and not mail name

@codeshell
Copy link
Author

Hi @foufrix, sorry for the delay. Somehow I missed the reply.

Would you mind posting a screenshot with the wrong rendering - here or over there? I am running this enhancement on my site for several months now and haven't had any problems so far.

@codeshell
Copy link
Author

codeshell commented Feb 22, 2018

Shot in the dark: Maybe the theme you are using does not include FontAwesome by default? I use FontAwesome v4 to render all the symbols within my preconfigured templates and css.
Make sure, <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" rel="stylesheet" /> is included before <link href="[CUSTOMPATH]/user/plugins/comments/assets/comments.css" type="text/css" rel="stylesheet" />.

@alorszut
Copy link

alorszut commented Mar 1, 2018

Hi all,

I haven't seen any commit including a good admin for comments, based ont codeshell enhancements to the backend. I just added my code modification to following files to get something in the backend Admin :

\user\plugins\comments\admin\templates\comments.html.twig
change line 92 :
<td class="details"><strong>Page</strong>: <a href="{{ base_url_simple }}/{{comment.pageTitleURL}}" target="_blank">{{comment.pageTitle}}</a><br>
\user\plugins\comments\comments.php :
line 718 & 719
$data['comments'][$i]['pageTitle'] = $data['comments'][$i]['title']; $data['comments'][$i]['pageTitleURL'] = $data['comments'][$i]['lang'].$data['comments'][$i]['page'];
line 814 to 833

    $pages = [];
	$title_page=[];
	$count_title_page=[];
    foreach($files as $file) {
		for ($i=0; $i <count($file->data['comments']);$i++)
		{
			$title_page[$i]= $file->data['comments'][$i]['title'];
			$pages[$file->data['comments'][$i]['title']] = [
				'title' => $file->data['comments'][$i]['title'],
				'commentsCount' => count($file->data['comments']),
				'lastCommentDate' => $file->data['comments'][$i]['date']
			];
		}		
    }
	$count_title_page=array_count_values ($title_page);
	
	foreach ($count_title_page as $key => $value) {
		$pages[$key]['commentsCount'] = $value;
	}

`

Hopefully it helps.
Everybody is looking for something to delete comments from Admin, and I was guessing why not doing the same thing as done for GUESTBOOK plugin with a moderation capability and deletion/approval from admin ?

Cheers,
Alorszut

@leetNightshade
Copy link

leetNightshade commented Jul 16, 2018

Nice changes! I was working on my own branch when I saw your changes. So I merged them, and am still testing them out. I started to update your stuff to look more like Reddit comments, and it's looking promising. I'm still working on changes, and evaluating. But it looks good so far. Commenting currently disabled for testing, which is something I added in my own (would be cool to add support per post), so I haven't updated add/delete visuals and ajax version.

image

Sample here. Time link is broken with horizontal scroll, not sure when that happened. [Update] Removing your comment-body width: 10000px; fixed that issue for me.

I was considering making threads collapsable with javascript, but I'll probably not spend any time on that, I just want it to look nice for now and be basically functional. What you can't see here is that people can enter their website/social link and clicking on name when provided will redirect to where you can find that person online. Also I added support for spam detection with Akismet.

Big thing I'm not a fan of is switch to YAML for storing comments. I don't think it adds anything, and I'm trying to make sure my site does as little processing as possible on my server. YAML is useful for human authored files, in this case comments are all processed with script, there's no reason not to pick the fastest most convenient serialization format; which is not YAML. JSON works well.

[Edit] I've been trying to figure out how to get new field in comments.yaml to show up for entering website, but I haven't been able to get it to work. Any ideas? Starting to dig through docs to see if I find out any reason why it's not showing up.

@abooks23
Copy link

Hi
please attach edited files or edited all plugin(plugin it is better)

@leetNightshade
Copy link

Hi
please attach edited files or edited all plugin(plugin it is better)

If you're talking to me, abook23, my files are here.

@abooks23
Copy link

thanks!

@abooks23
Copy link

Hi
how to count page comments?
{{page.commentsCount}} not working

@codeshell
Copy link
Author

if you use leetNightshades code, {{page.commentsCount}} should work when derived from grav.twig.pages ( demo template: http://git.leetnightshade.com/leetNightshade/grav-plugin-comments/src/branch/develop/admin/templates/comments.html.twig )

stats in my PR are different and can be used with {{stats.global_stats.active_entries}}, {{stats.global_stats.active_comments}}, etc when derived from stats = recent_comments(limit|default(5), pages_limit|default(3)) (demo template: https://github.com/getgrav/grav-plugin-comments/blob/bd1799cc7e377d9770fab3e1ba2ca71b9209679b/templates/partials/recentcomments.html.twig)

@codeshell
Copy link
Author

Big thing I'm not a fan of is switch to YAML for storing comments. I don't think it adds anything, and I'm trying to make sure my site does as little processing as possible on my server. YAML is useful for human authored files, in this case comments are all processed with script, there's no reason not to pick the fastest most convenient serialization format; which is not YAML. JSON works well.

[Edit] I've been trying to figure out how to get new field in comments.yaml to show up for entering website, but I haven't been able to get it to work. Any ideas? Starting to dig through docs to see if I find out any reason why it's not showing up.

You were right that YAML is a difficult choice. However I don't think, I changed it from JSON to YAML. It has always been YAML.

What I did was changing from File Facade to CompiledYamlFile.

use Grav\Common\File\CompiledJsonFile;
use Grav\Common\File\CompiledYamlFile;
use RocketTheme\Toolbox\File\File;

That means encoding and decoding/parsing is done behind the scenes. Just replace CompiledYamlFile with CompiledJsonFile and everything will be treated and saved as JSON.

As for the locations: Have a look at e8417c6
The original behaviour was that all comments were stored within DATA_DIR /comments/$lang/$path.yaml That code is still active (see line 265) to not break the admin panel. I think that location is a bad choice (for reasons pointed out in my original post) and decided to save comments with the page instead (see line 188). And I added a global index file containing all comments (see line 228). That one is for administrative and backup reasons. No comment is ever deleted from that index file. Just marked as deleted (soft delete). In case you delete pages and loose comments you didn't mean to delete.

To add additional fields just look at public function onFormProcessed(Event $event) and public function saveComment($route, $path, $parent_id, $lang, $text, $name, $email, $title).

Performance shouldn't be too much of an issue for the per-page-comment-files. Index files on the other hand are convenience and can be ditched.

@abooks23
Copy link

abooks23 commented Jun 13, 2019

{{stats.global_stats.active_comments}}

Hi
yes its work but it render number of ALL COMMENTS in all post, how render comments for current post?
--------update--------
do this
```
{% for key, entry in stats.pages %}
{% if entry.route == post.route %}
{{entry.active_entries}}
{% endif %}
{% endfor %}

render count post comment in blog-list-item.twig,
in main blog list card

-----update-----
realy count render after clear grav cache....

@abooks23
Copy link

why
Screenshot_2019-06-13 My new Blog post Grav
after reload ok

@leetNightshade
Copy link

Ajax inline reply doesn't work, idk if I broke that or if it was already like that. It's something I've had to fix. Sorry I didn't mention it. It's why my websites comments are displayed, and commenting is disabled. I haven't found the time to fix it. o.o;

@abooks23
Copy link

thanks

@codeshell
Copy link
Author

Comments and Ajax are still working for me. Using my adjustments with grav v1.6.10.

@rhukster
Copy link
Member

BTW, this is very cool, but because it changes some default stuff, including the location of comments, I can't merge as folks will lose their comments.

I suggest you fork, and release your own version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants