Jump to content
ryan

Quick guide to the comments system

Recommended Posts

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

 

 

Share this post


Link to post
Share on other sites

And another small issue, after submitting a comment, the "waiting for approval message" shows, but even the form.
Shouldn't the form be hidden when the GET variable "comment_success" is present?

//Jasper

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
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...

Share this post


Link to post
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 

 

 

 

Share this post


Link to post
Share on other sites

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...

 

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

No worries, I already posted almost the complete solution to the other topic.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Maybe Facebook looks for the URL's og:url and therefore changes your shared URL to the official URL.

<meta property="og:url" content="http://example.com/some-category/post1"/>

 

Share this post


Link to post
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..

 

Share this post


Link to post
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.

Share this post


Link to post
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 🙂

Share this post


Link to post
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?

Share this post


Link to post
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/

Share this post


Link to post
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.

Share this post


Link to post
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...

 

Share this post


Link to post
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!

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...