Jump to content

Quick guide to the comments system


ryan

Recommended Posts

  • 1 month later...

Hi!

 

I tried to enable mail notification for users (guests), enabled "Allow commenter e-mail notifications":

image.thumb.png.cb62ae107a9b8b61f782388508c088cf.png

The option shows up on the page:

image.png.aa32f2e187e13d962bb07159f04777fc.png

But no e-mails are being sent. Is there something else I need to do?

Other mail notifications, like the admin notification for comments, are working just fine, so it's not a general e-mail issue.

 

Any help is appreciated.

 

//Jasper

 

 

Link to comment
Share on other sites

  • 1 month later...

Hi!

a loggedin user has access to ony specific page.
this page has th following structure:

- Part 1 ( template part )

  - subpart 1a ( template subpart )
  - subpart 1b ( template subpart )
  - subpart 1c ( template subpart )

- Part 2 ( template part )

  - subpart 2a ( template subpart )
  - subpart 2b ( template subpart )
  - subpart 2c ( template subpart )

- Part 3 ( template part )

  - subpart 3a ( template subpart )
  - subpart 3b ( template subpart )
  - subpart 3c ( template subpart )

the comments - field is implemted in the template "subpart".

Now i want to have the possibility to make specific comments to each subpart - entry. It would be just perfect to store every specific comment-threat that belongs to it's subpart-entry! The field name & e-mail address should be already filled with the data from the logged in user ( users name / users mail address ).

is this possible to manage?!
Many Thanks!

Link to comment
Share on other sites

  • 1 month later...

Hello @ all,

I have no idea, but approval via email does not work in my case. Here are all my get variables that will be submitted by clicking the link in the email:

code    gKB6jlhWTowUeahUNX6OWWvBYBxYf1D41I5LZb4ws1YsA73jmk7sQeOoU1QAy4L6f1IAnmaSKXRjINOtGFDKO92e10Y5IuTzmuHOwkGI8bWtcXaIGstDB_xzq9hhwvZx
comment_success    approve
field    comments
page_id    2006

As you can see all parameters are there.

As far as I know the file CommentNotifications.php is responsible to save the new status "approved" after clicking the link, but in my case nothing changes and I do not get any message on the frontend. Tracy does not complain about anything so I dont know how to check where the problem is.

Is there someone who could give me a hint to check out whats going on after clicking the link to find out the problem.

Best regards

 

EDIT:

Ok, I see! This doesnt work if the comments were not rendered with the render function. So using your own markup to output comments inside a foreach prevents the status change after clicking the approval link.

Solution: Copy the whole Fieldtype comments directory in site/modules and make all the markup changes there. Load comment form and list via the render function and everything is fine.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...

Hello gents. I know this topic is an year old now, however, could you please share with me how would I insert the comments rating, vote and nesting in a custom build form where I do not just modify FieldtypeComments and put a copy in /site/modules but rather use the method described by Ryan in the description of the module & API (section of Generating your own output)?

So far I was able to get the cite, email, website and text to show but it seems like using $coment->rating (or ->vote) does not do the trick.

It would be great if one could share a comment form that would have the all the fields +  vote, rating and be styled for comment replies...

Link to comment
Share on other sites

Never mind, I was able to find the answers:

// Rating
// Note, that the result comes as a number so you might need to modify the markup to make the stars appear
$rating = $comment->stars;

// Upvotes
$upvotes = $comment->upvotes;

// Downvotes
$downvotes = $comment->downvotes;

The only thing I was not able to come up with was how to check if a comment is an reply to apply the proper tags (div, ul, ol etc.) If anyone has a way to achieve that, it would be great...

Link to comment
Share on other sites

Looking at the code of the FieldtypeComments module, I found the following short codes that could be used to render the comments:

{votes} - shows the up/down votes as per the options set in the comments field (Details tab)

{stars} - shows the rating stars if the rating is allowed within the Details tab

{url} - inserts the URL link to the comment 

 

 

 

Link to comment
Share on other sites

  • 2 weeks later...

Hey there mighty fellas. After a bit of a struggle with editing the comments module, I decided to simplify the things for myself (at least that's what I thought ? ) and use the alternative method suggested by @ryan in the first post of this topic - generating my own output. So I had the markup I wanted to implement in the comments and I almost achieved it, but there are a few things that I can't get my head around:

1. The votes count is working, but is not automatically refreshing so the page has to be reloaded in order to see the numbers

2. The votes allow a user to vote UP and Down at the same time which in my scenario does not make much sense as you either like a comment or don't.

3. How to implement the comment depth.

Here is the markup I have so far:

Spoiler

                            <!-- Comments Area -->
							<div class="comments-area">
							

							<?php
				
								// Comments status is as follows:
								// 1 = approved
								// 0 = pending
								// -2 = spam
								
								//Define a variable for the approved number of comments
								$comments = $page->recipe_comments;
								
								// Defining a variable for the header comment with the word in singular/pluriel
								$comment_header = '';
								
								//Check if any comments are added to the page
								if (count($comments)) {
									
									//Cycle through all comments to count the approved only
									foreach($comments as $comment) {
										
										//Check if any comments has been approved
										//besides isApproved there are other statuses:
										//$comment->status == Comment::statusPending
										//$comment->status == Comment::statusSpa,										
										if($comment->isApproved()) $comment_header++;
									}
																
								} 
								
								// Add the 'Comments' word in singular or pluriel to $comment_header output
								$comment_header .= pluriel(' Comment', ' Comments', $comment_header);								
								
								// Comments headline markup with the approved comments count
								echo "<div class='sec-title'><h2>{$comment_header}</h2></div>";
								

								foreach($page->recipe_comments as $comment) {
									
									// Skip unapproved or spam comments
									if($comment->status < 1) continue;
									
									// Make sure the Cite output is entity encoded and contains no markup
									$cite = htmlentities($comment->cite); 
									
									// Make sure the Text output is entity encoded and contains no markup
									$text = htmlentities($comment->text);
									
									// Get the comment id to insert it in the markup for reply and data values
									$comment_id = $comment->id;									
									
									// F - A full textual representation of a month, such as January or March
									// j - Day of the month without leading zeros
									// Y - A full numeric representation of a year, 4 digits
									// G - 24-hour format of an hour without leading zeros	
									// i - Minutes with leading zeros	
									// Reference: http://it2.php.net/manual/en/function.date.php
									$date = date('F j, Y G:i', $comment->created); 

									// Render comment rating (stars)
									$stars = $comment->renderStars();
									
									// Defining the gravatar
									// rating (optional) - Could be one of [ g | pg | r | x ], default is g.
									// imageset (optional) - Could be one of [ 404 | mm | identicon | monsterid | wavatar | retro | blank ], default is mm
									// size (optional) - Gravatar image size, default is 80
									$gravatar = $comment->gravatar();									
																	
									// Getting the upvotes and assigning them to $uvotes variable
									$upvotes = $comment->upvotes;
									
									// Assigning upvotes url to a variable
									$upvotes_url = $page->url . "?comment_success=upvote&amp;comment_id=" . $comment_id . "&amp;field_id=" . $fields->get("recipe_comments")->id . "#Comment" . $comment_id;
									
									// Defining the label for upvote button
									$upvoteLabel = "Like this comment";
									
									// Defining the format of the upvote button
									$upvoteFormat = "&uarr; " . $upvotes;
									
									// Getting the downvotes and assign them to $downvotes variable
									$downvotes = $comment->downvotes;
									
									//Assigning downvotes url to a variable
									$downvotes_url = $page->url . "?comment_success=downvote&amp;comment_id=" . $comment_id . "&amp;field_id=" . $fields->get("recipe_comments")->id ."#Comment" . $comment_id;
									
									// Defining the label for downvote button
									$downvoteLabel = "Dislike this comment";
									
									$downvoteFormat = "&darr; " . $downvotes;
								
							?>
							
                                <!-- Comment Box -->
                                <div class="comment-box">
                                    <div class="comment">
                                        <div class="author-thumb"><img src="<?php echo $gravatar; ?>" alt="<?php echo $cite; ?> gravatar"></div>
                                        <div class="comment-inner">
                                            <div class="comment-info"><?php echo $cite; ?> &nbsp <?php echo $stars; ?></div>
                                            <div class="post-date"><?php echo $date; ?></div>
                                            <div class="text"><?php echo $text; ?></div>
											<a href="#Comment<?php echo $comment_id; ?>" class="reply-btn CommentActionReply" data-comment-id="<?php echo $comment_id; ?>">Reply</a>
                                        </div>
										
										<a class='CommentActionUpvote' title='<?php echo $upvoteLabel; ?>' data-url='<?php echo $upvotes_url; ?>' href='#Comment<?php echo $comment_id; ?>'><?php echo $upvoteFormat; ?></a>
										
										<a class='CommentActionDownvote' title='<?php echo $downvoteLabel; ?>' data-url='<?php echo $downvotes_url ?>' href='#Comment<?php echo $comment_id; ?>'><?php echo $downvoteFormat; ?></a>
										
                                    </div>
                                </div>
                                <!-- /Comment Box -->	

							<?php 
							
								}
								
							?>
							
							</div>
							<!-- /Comments Area -->

It would be great if someone could give me a hint about how to correct those as every topic I've checked about comments is either not having votes/rating at all or does not a complete way to implement the own markup and I am a bit stuck. And I know, I should get used to just editing the FieldType Comments module which would have allowed the {votes] {stars} etc...

 

Link to comment
Share on other sites

1 hour ago, MilenKo said:

So I had the markup I wanted to implement in the comments and I almost achieved it, but there are a few things that I can't get my head around:

Please, no need to double post. You've already started a topic here:

I know there are no answers there but I've directed you to some code that can help you implement comment depth.

Please let's use your other thread. I'll make a few comments there. 

Link to comment
Share on other sites

  • 2 weeks later...

Hey all. Since I finished styling my comments and they are as I would want them to appear, I decided to add a comment sharing function so that a visitor can click a button and share the url of the comment to social medias. I did that using a popover with the social buttons and it all functions properly besides the fact that most medias nowadays omit the hashtagged content and just go with the main page. Here is my sharing url to FB :

https://www.facebook.com/sharer/sharer.php?u=http://example.com/some-category/post1/#Comment259

And the shared result:

http://example.com/some-category/post1

What would be the simplest and best way to share the URL to the comment?

So far I've tested replacing # character with %23 but that got omitted as well.

comment-sharing-url.jpg

Link to comment
Share on other sites

Hey @wbmnfktr thanks for your response. As the profile is still in mid-development I do not have any og links in my head and to push the link I changed a bit the $permalink in CommentList.php to contain the code:

<a href=\"https://www.facebook.com/sharer/sharer.php?u={$permalink}\" target=\"_blank\" rel=\"noopener\" title=\"Share on Facebook\" class=\"btn btn-social-icon btn-sm btn-facebook\"><span class=\"fa fa-facebook\"></span></a>

I've been searching this morning and there are tons of pages asking for the same thing and as it appears, Facebook is cutting down anything after the # and that is my problem. My logic is that I have two things to have this addressed:

1. Change the id of the comment and to eliminate the # in the link, however in this scenario it is used as an anchor and I am not sure yet how to achieve that

2. Use hashbang instead (#!) where it should get changed by facebook API to: ?_escaped_fragment_=/#Comment259  - that was just tested now but the URL of facebook after sharing got to:

http://example.com/some-category/post1/?fbclid=IwAR2csPtj_VAPy20XTeMm3yM6N5AnqTujXsyO7g6MFK2QCgyULp64ghL9Nco

3. Have some magic with .htaccess to change the way comments would be accessed - somethig like: 

http://example.com/some-category/post1/comments/259which should satisfy social medias as a link to share

4. Use a url shortener to cover up the #. I am not sure if this would not be an overkil to use goo.gl or bitly to encode the url and then share it.

For me, the best approach would be to change the link of accessing the comments (option 3) but how would I do that is the million dollar question ? So far by modifying quickly the url in the CommentList.php I was able to change the url as listed above, but now I have to manage the redirect from that url back to #Comment259 or apply some changes so that the comments are accessed directly by that URL..

 

Link to comment
Share on other sites

Well then... build your own URL shortener

You could build the links to your comments like this:

https://yourdomain.tld/shortener/pageID/commentID or
https://yourdomain.tld/rdrct/1123/987 

Either done with a new template using URL segments that look for a page with given ID and then redirects to the full URL:
https://yourdomain.tld/path/to/page/#Comment987

Maybe this is even already possible with Jumplink's wildcard/group feature.

Link to comment
Share on other sites

Thanks @wbmnfktr I will look into that module even though there was a comment that under php 7.3 it fails somehow.

Initially I thought it would be just a simple mod_rewrite rule redirect from /url/comment/id to /url#Comment{id} but will look at any options available which would allow me to share the comment url itself but not just a link to the main page.

I am just surprised that I did not find much info or a workaround already where the hashtag URL is not a rare thing and would not be accepted by most social medias. Well, I guess there is still a path to go for everythign ?

Link to comment
Share on other sites

OK, gents, I was able to manage to resolve the issue with the comment sharing by a simple manipulation of $permalink:

$permalink .= '%23Comment' . $comment->id;

And call the facebook sharing URL to:

<a href=\"https://www.facebook.com/sharer/sharer.php?u={$permalink}\" target=\"_blank\" rel=\"noopener\" title=\"Share on Facebook\" class=\"btn btn-social-icon btn-sm btn-facebook\"><span class=\"fa fa-facebook\"></span></a>

The only thing left is to manage to open the sharing window in a new window with specific size which would close after submission but that should be the easier part (I thnk) I just need to make the rest of the social medias I am planning to use working and will share the complete code in case someone else looks for such solution. 

The trick was to use %23 which I've tested earlier but was not working somehow and my best guess is that the cause was the cache which I must have forgotten to clear. Now it works fine so it is considered an easy to have solution ?

P.S. After trying quite  few java scripts to open the url in a popup, I am still failing to do that and I am only able to open the sharing window as a new page using target="_blank". Any suggestions for the easiest fix?

Link to comment
Share on other sites

7 hours ago, MilenKo said:

The trick was to use %23 which I've tested earlier but was not working somehow and my best guess is that the cause was the cache which I must have forgotten to clear. Now it works fine so it is considered an easy to have solution

Good to know. ? 

7 hours ago, MilenKo said:

After trying quite  few java scripts to open the url in a popup, I am still failing to do that and I am only able to open the sharing window as a new page using target="_blank". Any suggestions for the easiest fix?

If I remember correctly Twitter has had a widget which did exactly that. Maybe you could take a look at their code.

https://publish.twitter.com/

Link to comment
Share on other sites

@wbmnfktr Thanks for the shared link, however as it seems it is for embedding twitter items on your website, where I would need to share a link, but I will have a search on their website for the sharing code as I looked yesterday about FB but not TW.

Link to comment
Share on other sites

I found some javascript code that is opening properly the popup sharing window and even more - it is positioning it to the middle of the screen, however I now need to find a way to implement it in to the php with all the single and double quote escape.

Here is the javascript:

<a href="#" class="btn btn-social-icon btn-facebook" 
	onclick="window.open(
	  'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent('http://mydomain.com') +'&t=' + encodeURIComponent('Some title #hashtag1 #hashtag2'), 
	  'facebook-share-dialog', 
	  'width=626,height=436,top='+((screen.height - 436) / 2)+',left='+((screen.width - 626)/2 )); 
	return false;">
	<span class=\"fa fa-facebook\"></span>
</a>

and here is the permalink code in CommentList.php where I need to find a way to insert the javascript:

$permalink = 
	 "\n\t\t\t\t<a 
     tabindex='0' 
     role='button' 
     data-toggle='popover' 
     data-placement='left' 
     data-trigger='focus' 
     data-html='true' 
     data-content='

  <a class=\"btn btn-social-icon btn-sm btn-facebook\"><span class=\"fa fa-facebook\"></span></a>

  '>#{$comment->id}</a>";

So far I've tried to escape all the single/double quotes with a backslash ( \ ), however that causes the javascript to open the sharing window in a regular new window but not in a popup as it works if I insert it in HTML or any other template...

 

Link to comment
Share on other sites

Hello,

is it possible to have rich-text allowed in the form (including wysiwyg buttons) and output formatted by the comments module? Similarly as it in this form. I tried to look in the doc and the forum but either no one is interested, or i'm searching for wrong keywords...

Thanks!

Link to comment
Share on other sites

Hello @loukote I believe that it would be easy to add any rich text editor like CKEditor where you just have to use their code for HTML pages and then to sanitize the output ($text by default). There are different packages of the editor so you just need to pick one that fits your needs and add it to your comment form. Here is a link with some more info about CKEditor.

Link to comment
Share on other sites

Gents, as to avoid blurring the topic with issues that are not directly related to the module or its features as well as per the suggestion of @kongondo, I will continue the discussion about the sharing of comments to social medias and other implementations in my FieldType Comments topic I've opened earlier. I've had some progress so feel free to check it or help with some ideas.

Link to comment
Share on other sites

  • 1 year later...

Hello All,

How do we add a custom field to the comment form input ? For example, I need to add phone number instead of the website for a person a to insert comments. Please reply how to add such custom fields.

 

thank you 

Link to comment
Share on other sites

  • 11 months later...
On 1/31/2011 at 2:59 PM, ryan said:

6. Your comments are now ready to use. Note that any templates that use comments for posting should not use Template caching unless you configure the comments to post to another template/page. You'll see an option for this in the renderForm() options shown further down on this post.

I know: I am late to the party – but i have a question to the initial post of @ryan (see quote above):
In a current project I want to display the comments list one a cached page (ProCache) and the comments form on another, uncached page.
Unless teasered in the above quote, I didn't find an option in renderForm() to configure this usecase (posting comments to another page) – or maybe i am looking on the wrong place.

So, does anybody know how to set this up and could give me a hint in the right direction?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...