Merge https://github.com/codeshell/grav-plugin-comments into develop
This commit is contained in:
		
						commit
						be0eca0ff5
					
				
					 10 changed files with 1071 additions and 391 deletions
				
			
		
							
								
								
									
										37
									
								
								templates/partials/comments.form.html.twig
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								templates/partials/comments.form.html.twig
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
    <form id="comments-form" name="{{ grav.config.plugins.comments.form.name }}" class="comments-form"
 | 
			
		||||
          action="{{ grav.config.plugins.comments.form.action ?  base_url ~ grav.config.plugins.comments.form.action : page.url }}"
 | 
			
		||||
          method="{{ grav.config.plugins.comments.form.method|upper|default('POST') }}">
 | 
			
		||||
 | 
			
		||||
        {% for field in grav.config.plugins.comments.form.fields %}
 | 
			
		||||
            {% set value = form.value(field.name) %}
 | 
			
		||||
            {% if field.evaluateDefault %}
 | 
			
		||||
                {% set value = evaluate(field.evaluateDefault) %}
 | 
			
		||||
            {% endif %}
 | 
			
		||||
            {% if config.plugins.login.enabled and grav.user.authenticated %}
 | 
			
		||||
                {% if field.name == 'name' %}
 | 
			
		||||
                    <input type="hidden" name="{{ (scope ~ field.name)|fieldName }}" value="{{grav.user.fullname}}">
 | 
			
		||||
                {% elseif field.name == 'email' %}
 | 
			
		||||
                    <input type="hidden" name="{{ (scope ~ field.name)|fieldName }}" value="{{grav.user.email}}">
 | 
			
		||||
                {% else %}
 | 
			
		||||
                    <div>
 | 
			
		||||
                        {% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
 | 
			
		||||
                    </div>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            {% else %}
 | 
			
		||||
                <div>
 | 
			
		||||
                    {% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
 | 
			
		||||
                </div>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
        {% include "forms/fields/formname/formname.html.twig" %}
 | 
			
		||||
 | 
			
		||||
        <div class="buttons">
 | 
			
		||||
        {% for button in grav.config.plugins.comments.form.buttons %}
 | 
			
		||||
            <button class="button" type="{{ button.type|default('submit') }}">{{ button.value|t|default('Submit') }}</button>
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        {{ nonce_field('comments', 'form-nonce')|raw }}
 | 
			
		||||
    </form>
 | 
			
		||||
 | 
			
		||||
    <div id="comments-alert" class="alert">{{ form.message }}</div>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,135 +1,67 @@
 | 
			
		|||
{% if grav.twig.enable_comments_plugin %}
 | 
			
		||||
	{% set scope = scope ?: 'data.' %}
 | 
			
		||||
	<section id="comments-section">
 | 
			
		||||
		<h2>{{'PLUGIN_COMMENTS.COMMENTS'|t}}</h2>
 | 
			
		||||
 | 
			
		||||
	{% if grav.twig.pingbacks_enabled %}
 | 
			
		||||
		{% if grav.twig.pingbacks|length %}
 | 
			
		||||
				{% set comments_visible = false %}
 | 
			
		||||
				{% for pingback in grav.twig.pingbacks %}
 | 
			
		||||
					{% if pingback.approved == "true" %}
 | 
			
		||||
						{% set comments_visible = true %}
 | 
			
		||||
					{% endif %}
 | 
			
		||||
				{% endfor %}
 | 
			
		||||
 | 
			
		||||
				{% if comments_visible %}
 | 
			
		||||
					<h3>{{'PLUGIN_COMMENTS.COMMENTS_PINGBACKS'|t}}</h3>
 | 
			
		||||
 | 
			
		||||
					<table>
 | 
			
		||||
						{% for pingback in grav.twig.pingbacks %}
 | 
			
		||||
							{% if pingback.approved == "true" %}
 | 
			
		||||
								<tr>
 | 
			
		||||
									<td>
 | 
			
		||||
										<article id="pingback-{{loop.index0}}" class="pingback" itemtype="http://schema.org/UserComments">
 | 
			
		||||
											<header class="pingback-meta">
 | 
			
		||||
													<span class="pingback-author" itemprop="author" itemscope itemtype="http://schema.org/Person">
 | 
			
		||||
														{{'PLUGIN_COMMENTS.BY'|t}}
 | 
			
		||||
														<span itemprop="name">
 | 
			
		||||
															{% if pingback.site %}
 | 
			
		||||
																<a href="{{pingback.site}}">{{pingback.author}}</a>
 | 
			
		||||
															{% else %}
 | 
			
		||||
																{{pingback.author}}
 | 
			
		||||
															{% endif %}
 | 
			
		||||
														</span>
 | 
			
		||||
													</span>
 | 
			
		||||
													<a href="{{uri.url(true)}}#pingback-{{loop.index0}}" title="Link to this pingback" itemprop="url">
 | 
			
		||||
														<time class="pingback-date" datetime="{{pingback.date|e}}" itemprop="commentTime">
 | 
			
		||||
															{{pingback.date|nicetime(false)}}
 | 
			
		||||
														</time>
 | 
			
		||||
													</a>
 | 
			
		||||
											</header>
 | 
			
		||||
											<div class="pingback-content" itemprop="commentText">
 | 
			
		||||
												{{pingback.text}}
 | 
			
		||||
											</div>
 | 
			
		||||
										</article>
 | 
			
		||||
									</td>
 | 
			
		||||
								</tr>
 | 
			
		||||
							{% endif %}
 | 
			
		||||
						{% endfor %}
 | 
			
		||||
					</table
 | 
			
		||||
				{% endif %}
 | 
			
		||||
			</table>
 | 
			
		||||
		{% if grav.twig.commenting_enabled %}
 | 
			
		||||
			<a class="comment-add-new" href="#"><i class="fa fa-plus" title="{{'PLUGIN_COMMENTS.ADD_NEW'|t}}"></i> {{'PLUGIN_COMMENTS.ADD_NEW'|t}}</a>
 | 
			
		||||
		{% endif %}
 | 
			
		||||
	{% endif %}
 | 
			
		||||
 | 
			
		||||
	{% if grav.twig.commenting_enabled %}
 | 
			
		||||
		<h3>{{'PLUGIN_COMMENTS.ADD_COMMENT'|t}}</h3>
 | 
			
		||||
		{% include 'partials/comments.form.html.twig' %}
 | 
			
		||||
 | 
			
		||||
		<form name="{{ grav.config.plugins.comments.form.name }}"
 | 
			
		||||
			  action="{{ grav.config.plugins.comments.form.action ?  base_url ~ grav.config.plugins.comments.form.action : page.url }}"
 | 
			
		||||
			  method="{{ grav.config.plugins.comments.form.method|upper|default('POST') }}">
 | 
			
		||||
 | 
			
		||||
			{% for field in grav.config.plugins.comments.form.fields %}
 | 
			
		||||
				{% set value = form.value(field.name) %}
 | 
			
		||||
				{% if field.evaluateDefault %}
 | 
			
		||||
					{% set value = evaluate(field.evaluateDefault) %}
 | 
			
		||||
				{% endif %}
 | 
			
		||||
				{% if config.plugins.login.enabled and grav.user.authenticated %}
 | 
			
		||||
					{% if field.name == 'name' %}
 | 
			
		||||
						<input type="hidden" name="{{ (scope ~ field.name)|fieldName }}" value="{{grav.user.fullname}}">
 | 
			
		||||
					{% elseif field.name == 'email' %}
 | 
			
		||||
						<input type="hidden" name="{{ (scope ~ field.name)|fieldName }}" value="{{grav.user.email}}">
 | 
			
		||||
					{% else %}
 | 
			
		||||
						<div>
 | 
			
		||||
							{% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
 | 
			
		||||
						</div>
 | 
			
		||||
					{% endif %}
 | 
			
		||||
				{% else %}
 | 
			
		||||
					<div>
 | 
			
		||||
						{% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
 | 
			
		||||
					</div>
 | 
			
		||||
				{% endif %}
 | 
			
		||||
			{% endfor %}
 | 
			
		||||
			{% include "forms/fields/formname/formname.html.twig" %}
 | 
			
		||||
 | 
			
		||||
			<div class="buttons">
 | 
			
		||||
			{% for button in grav.config.plugins.comments.form.buttons %}
 | 
			
		||||
				<button class="button" type="{{ button.type|default('submit') }}">{{ button.value|t|default('Submit') }}</button>
 | 
			
		||||
			{% endfor %}
 | 
			
		||||
			</div>
 | 
			
		||||
 | 
			
		||||
			{{ nonce_field('form', 'form-nonce')|raw }}
 | 
			
		||||
		</form>
 | 
			
		||||
 | 
			
		||||
		<div class="alert">{{ form.message }}</div>
 | 
			
		||||
	{% endif %}
 | 
			
		||||
 | 
			
		||||
	{% if grav.twig.comments|length %}
 | 
			
		||||
 | 
			
		||||
		<h3>{{'PLUGIN_COMMENTS.COMMENTS'|t}}</h3>
 | 
			
		||||
 | 
			
		||||
		<table class="comments">
 | 
			
		||||
			{% set comments_visible = false %}
 | 
			
		||||
			{% for comment in grav.twig.comments %}
 | 
			
		||||
				{% if comment.approved == "true" %}
 | 
			
		||||
					{% set comments_visible = true %}
 | 
			
		||||
					<tr>
 | 
			
		||||
						<td>
 | 
			
		||||
							<article id="comment-{{loop.index0}}" class="comment" itemtype="http://schema.org/UserComments">
 | 
			
		||||
								<header class="comment-meta">
 | 
			
		||||
										<span class="comment-author" itemprop="author" itemscope itemtype="http://schema.org/Person">
 | 
			
		||||
											<img class="comment-avatar" itemprop="image" src="https://www.gravatar.com/avatar/{{comment.email|ltrim()|rtrim()|md5}}?size=30&d=identicon">
 | 
			
		||||
											{{'PLUGIN_COMMENTS.BY'|t}}
 | 
			
		||||
											<span itemprop="name">
 | 
			
		||||
												{% if comment.site %}
 | 
			
		||||
													<a href="{{comment.site}}">{{comment.author}}</a>
 | 
			
		||||
												{% else %}
 | 
			
		||||
													{{comment.author}}
 | 
			
		||||
												{% endif %}
 | 
			
		||||
											</span>
 | 
			
		||||
										</span>
 | 
			
		||||
										<a href="{{uri.url(true)}}#comment-{{loop.index0}}" title="Link to this comment" itemprop="url">
 | 
			
		||||
		<div id="comments" class="row comments">
 | 
			
		||||
			{% if grav.twig.comments|length %}
 | 
			
		||||
				{% set comments_visible = false %}
 | 
			
		||||
				{% for comment in grav.twig.comments %}
 | 
			
		||||
					{% if comment.approved == "true" %}
 | 
			
		||||
						<div class="comment-wrapper">
 | 
			
		||||
						{% set comments_visible = true %}
 | 
			
		||||
							{% for level in range(0, comment.level|e) %}
 | 
			
		||||
										{% if level == comment.level|e %}
 | 
			
		||||
											<div id="thread-{{level}}" class="comment-thread-top comment-thread">
 | 
			
		||||
											</div>
 | 
			
		||||
										{% else %}
 | 
			
		||||
											<div id="thread-{{level}}" class="comment-thread">
 | 
			
		||||
											</div>
 | 
			
		||||
										{% endif %}
 | 
			
		||||
							{% endfor %}
 | 
			
		||||
							<div id="comment-{{comment.id}}" class="comment comment-level-{{comment.level|e}}" data-id="{{comment.id}}" itemtype="http://schema.org/UserComments">
 | 
			
		||||
								<header class="comment-heading">
 | 
			
		||||
									<img class="comment-avatar" src="https://www.gravatar.com/avatar/{{comment.email|trim|lower|md5}}?size=20&d=identicon" alt="user icon">
 | 
			
		||||
									<span class="comment-meta">
 | 
			
		||||
										{% if comment.site %}
 | 
			
		||||
											<a href="{{comment.site}}">{{comment.author}}</a>
 | 
			
		||||
										{% else %}
 | 
			
		||||
											{{comment.author}}
 | 
			
		||||
										{% endif %}
 | 
			
		||||
										<a href="{{uri.url(true)}}#comment-{{comment.id}}" title="Link to this comment" itemprop="url">
 | 
			
		||||
											<time class="comment-date" datetime="{{comment.date|e}}" itemprop="commentTime">
 | 
			
		||||
												{{comment.date|nicetime(false)}}
 | 
			
		||||
											</time>
 | 
			
		||||
										</a>
 | 
			
		||||
									</span>
 | 
			
		||||
								</header>
 | 
			
		||||
								<div class="comment-content" itemprop="commentText">
 | 
			
		||||
									{{comment.text}}
 | 
			
		||||
								<div class="comment-body">
 | 
			
		||||
									<div class="comment-text" >
 | 
			
		||||
										{{comment.text}}
 | 
			
		||||
									</div>
 | 
			
		||||
									{{nested}}
 | 
			
		||||
									<div class="comment-footer">
 | 
			
		||||
										<span class="comment-reply">
 | 
			
		||||
											{% if grav.twig.commenting_enabled %}
 | 
			
		||||
												<a class="comment-add-reply" href="#"><i class="fa fa-reply" title="{{'PLUGIN_COMMENTS.ADD_REPLY'|t}}"></i> {{'PLUGIN_COMMENTS.REPLY'|t}}</a>
 | 
			
		||||
											{% endif %}
 | 
			
		||||
											{% if grav.user.access.admin.super %}
 | 
			
		||||
											<a class="comment-delete" href="#"><i class="fa fa-trash" title="{{'PLUGIN_COMMENTS.DELETE_COMMENT'|t}}"></i> {{'PLUGIN_COMMENTS.DELETE'|t}}</a>
 | 
			
		||||
											{% endif %}
 | 
			
		||||
										</span>
 | 
			
		||||
									</div>
 | 
			
		||||
								</div>
 | 
			
		||||
							</article>
 | 
			
		||||
						</td>
 | 
			
		||||
					</tr>
 | 
			
		||||
				{% endif %}
 | 
			
		||||
			{% endfor %}
 | 
			
		||||
							</div>
 | 
			
		||||
						</div>
 | 
			
		||||
					{% endif %}
 | 
			
		||||
				{% endfor %}
 | 
			
		||||
			{% endif %}
 | 
			
		||||
 | 
			
		||||
			{% if not comments_visible %}
 | 
			
		||||
				<tr>
 | 
			
		||||
| 
						 | 
				
			
			@ -138,6 +70,6 @@
 | 
			
		|||
					</td>
 | 
			
		||||
				</tr>
 | 
			
		||||
			{% endif %}
 | 
			
		||||
		</table>
 | 
			
		||||
	{% endif %}
 | 
			
		||||
		</div>
 | 
			
		||||
	</section>
 | 
			
		||||
{% endif %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										54
									
								
								templates/partials/recentcomments.html.twig
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								templates/partials/recentcomments.html.twig
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,54 @@
 | 
			
		|||
{# you may set options when using this partial. Example: include 'partials/recentcomments.html.twig' with {'limit': 5, 'pages_limit': 3} #}
 | 
			
		||||
{% if grav.twig.enable_comments_plugin %}
 | 
			
		||||
        <h1>{{'PLUGIN_COMMENTS.COMMENTS_STATS'|t}}</h1>
 | 
			
		||||
		{% set stats = recent_comments(limit|default(5), pages_limit|default(3)) %}
 | 
			
		||||
		{% if stats.global_stats.active_entries %}
 | 
			
		||||
			<i class="fa fa-comments" title="active_entries"></i> {{stats.global_stats.active_entries}}
 | 
			
		||||
			 (<i class="fa fa-trash" title="deleted_entries"></i> {{stats.global_stats.deleted_entries}})
 | 
			
		||||
			- <i class="fa fa-comment" title="active_comments"></i>{{stats.global_stats.active_comments}}
 | 
			
		||||
			 (<i class="fa fa-trash" title="deleted_comments"></i> {{stats.global_stats.deleted_comments}})
 | 
			
		||||
			- <i class="fa fa-commenting" title="active_replies"></i>{{stats.global_stats.active_replies}}
 | 
			
		||||
			 (<i class="fa fa-trash" title="deleted_replies"></i> {{stats.global_stats.deleted_replies}})
 | 
			
		||||
			- <i class="fa fa-files-o" title="pages_with_active_entries"></i> {{stats.global_stats.pages_with_active_entries}}
 | 
			
		||||
		{% endif %}
 | 
			
		||||
		{% for key, entry in stats.pages %}
 | 
			
		||||
			{% if loop.first %}
 | 
			
		||||
		        <h2>{{'PLUGIN_COMMENTS.RECENT_PAGES'|t}} (limit {{stats.options.pages_limit}})</h2>
 | 
			
		||||
				<ul class="fa-ul">
 | 
			
		||||
			{% endif %}
 | 
			
		||||
			<li><i class="fa-li fa fa-file" title="{{entry.route}}"></i>
 | 
			
		||||
			{% if entry.route %}
 | 
			
		||||
				<a href="{{entry.route}}#comments">
 | 
			
		||||
			{% endif %}
 | 
			
		||||
			{{entry.active_entries}}
 | 
			
		||||
			{% if entry.route %}
 | 
			
		||||
				</a>
 | 
			
		||||
			{% endif %}
 | 
			
		||||
			</li>
 | 
			
		||||
			{% if loop.last %}
 | 
			
		||||
				</ul>
 | 
			
		||||
			{% endif %}
 | 
			
		||||
		{% endfor %}
 | 
			
		||||
		{% for key, entry in stats.comments %}
 | 
			
		||||
			{% if loop.first %}
 | 
			
		||||
		        <h2>{{'PLUGIN_COMMENTS.RECENT_COMMENTS'|t}} (limit {{stats.options.comments_limit}})</h2>
 | 
			
		||||
				<ul class="fa-ul">
 | 
			
		||||
			{% endif %}
 | 
			
		||||
			{% set entry_icon = 'fa-comment' %}
 | 
			
		||||
			{% if not empty(entry.parent) %}
 | 
			
		||||
			{% set entry_icon = 'fa-commenting' %}
 | 
			
		||||
			{% endif %}
 | 
			
		||||
			<li><i class="fa-li fa {{entry_icon}}" title="{{key}}: {{entry.id}}, {{entry.parent}}"></i>
 | 
			
		||||
				{% if entry.route %}
 | 
			
		||||
					<a href="{{entry.route}}#comments">
 | 
			
		||||
				{% endif %}
 | 
			
		||||
				{{entry.date}}, {{entry.author}}, {{entry.text|truncate(15)}}
 | 
			
		||||
				{% if entry.route %}
 | 
			
		||||
					</a>
 | 
			
		||||
				{% endif %}
 | 
			
		||||
			</li>
 | 
			
		||||
			{% if loop.last %}
 | 
			
		||||
				</ul>
 | 
			
		||||
			{% endif %}
 | 
			
		||||
		{% endfor %}
 | 
			
		||||
{% endif %}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue