Jump to content

Quick guide to the comments system


ryan

Recommended Posts

hi flydev

I'm not sure about your particular error. So I can't offer much advice. Sorry. But I have been spending a lot of time working on my problem.

What I have discovered is that if we use the core CommentForm.php file to generate our comment form, then threaded comments work perfectly. We also need to follow the instructions in the module and make sure we are linking to the needed js file.

But if we wish to create a much more customised comment form, then making a copy of CommentForm.php and placing it in our site directory as described a few times in this thread does not actually work the way we want!

The comment form gets displayed, and it does submit and generate comments, yes. But the threaded functionality no longer works and I'm not sure why :(

So if anyone knows how to make another copy of CommentForm.php, place it in our site directory and still get threaded comments to work, I would be most appreciative!   In version 3.0 it seems we can make a copy of the comments module and place it in /site/modules and customise our copy there. PW seems to automatically make any core module copies placed in our sites/modules folder the active copy. So we just edit our copy. Yay!

Also... does anyone know what exactly to enter into our comments date/ time format box to display our comments actual post time? I seem to be only able to show relative times :(

Link to comment
Share on other sites

About The exception Invalid email address (processwire@localhost); She is triggered when we leave empty the configuration field "Notifications From Email".

Just finished to give a try at your solution (with PW3) and everything work fine. No idea about formatting the time output atm. Have you tried editing your field in the configuration page ?

It say :

1455095378-capture.png

Link to comment
Share on other sites

  • 2 weeks later...

Hey guys,

first I want to say thanks for the best cms system ever! Great job!

 
And I love the comment system. It works great for me. But does anybody have a idea how I can echo two different versions depending on the input fields?
 
This is my code now:

<div class="content <?php if($page->isHeader == 0){echo "extraPadding";}?>">
    
<?php    
        // comment form
        echo $page->guestbook->renderForm(array(
            'headline' => "<h2>Ihr Gästebucheintrag:</h2>",
            'successMessage' => "<p class='success'>Dankschön! Ihr Eintrag wurde erfolgreich gespeichert!</p>",
            'errorMessage' => "<p class='error'>Leider gab es einen Fehler. Wahrscheinlich wurde ein Feld nicht ausgefüllt.</p>",
            'processInput' => true,
            'encoding' => 'UTF-8',
            'attrs' => array(
                'id' => 'CommentForm',
                'action' => './',
                'method' => 'post',
                'class' => '',
                'rows' => 5,
                'cols' => 50,
                ),
            'labels' => array(
                'cite' => 'Name',
                'email' => 'E-Mail',
                'website' => 'Homepage',
                'text' => 'Gästebucheintrag',
                'submit' => 'Veröffentlichen',
            ),
            // the name of a field that must be set (and have any non-blank value), typically set in Javascript to keep out spammers
            // to use it, YOU must set this with a <input hidden> field from your own javascript, somewhere in the form
            'requireSecurityField' => '', // not used by default
            )); 
    
        // comments output
        echo $page->guestbook->render(array(
            'headline' => '<h2>Einträge</h2>',
            'commentHeader' => 'Geschrieben von <a href="{website}">{cite}</a> am {created}',
            'dateFormat' => 'd/m/Y',
            'encoding' => 'UTF-8',
            'admin' => false, // shows unapproved comments if true
            ));

        ?>
    
</div>

The website of the comment author should only be a link if they have a website.

Something like this:

If (website == nothing){

    'commentHeader' => 'Geschrieben von {cite} am {created}'

}

else {

    'commentHeader' => 'Geschrieben von <a href="{website}">{cite}</a> am {created}'

}

How can I do this?

Jannis

Link to comment
Share on other sites

You can make your own array and pass it as an argument to the render() method.

A short snippet exemple for your need :


$website = "";
$options = array('headline' => '<h2>Einträge</h2>');
if (strlen($website)<=0) {
	$temp = array('commentHeader' => 'Geschrieben von {cite} am {created}');
}
else {
	$temp = array('commentHeader' => 'Geschrieben von <a href="{website}">{cite}</a> am {created}');
}
$options = array_merge($options, $temp);
$temp = array(
	'dateFormat' => 'd/m/Y',
	'encoding' => 'UTF-8',
	'admin' => false
);
$options = array_merge($options, $temp);
echo $page->guestbook->render($options); // argument as Array()
  • Like 2
Link to comment
Share on other sites

  • 1 month later...

I have tried to figure out how to change the status (spam, approved,...) via api from the email link.

I have created a custom comment form and custom comment list with my markup. Both work as expected. The only thing I could not figure out was how to change the status from pending to approved or another status via the email link if it will be clicked.

In the email link there are several GET variables which can be used to create an if statement.

F.e

if(GET->[success] == "approve"){
.....
.....
set new comment status to 1
}

There are several GET variables so this makes it a little bit tricky.

Has anyone tried to make the email activation of comments via the api.

Best regards

Link to comment
Share on other sites

No one an idea?

I have the code to check for the email approval so far.

//check for email approval GET variables
$cpageid = isset($_GET['page_id']) ? $_GET['page_id'] : '';
$ccode = isset($_GET['code']) ? $_GET['code'] : '';
$capprove = isset($_GET['comment_success']) ? $_GET['comment_success'] : '';

foreach($page->comments as $c) {
if((($page->id) == $cpageid) AND (($c->code) == $ccode) AND ($capprove == "approve")){
   
   //$c->setOutputFormatting(false);
   //$c->status = 1;
   //$c->save();
   
 echo "approved";
} else {
 echo "not approved";
}
}

The checking works and it shows me "approved" if anything is ok, but I am not able to store the new status value in the db.

As far as I know comments are pages. Therefore I have tried to save it as a page, but this code doesnt work.

$c->setOutputFormatting(false);
$c->status = 1;
$c->save();

Has anyone an idea how to save a specific comment to update the status?

Best regards

Link to comment
Share on other sites

I have found a working solution. Here is the code for others who are interested in.

//check for email approval GET variables
$cpageid = isset($_GET['page_id']) ? $_GET['page_id'] : '';
$ccode = isset($_GET['code']) ? $_GET['code'] : '';
$capprove = isset($_GET['comment_success']) ? $_GET['comment_success'] : '';
foreach($page->comments as $c) {
 if((($page->id) == $cpageid) AND (($c->code) == $ccode) AND ($capprove == "approve")){
   $page->setOutputFormatting(false);
   $c->status = 1;
   $page->save('comments');
 } 
}

Best regards

  • Like 3
Link to comment
Share on other sites

Quick and dirty way to make email approval on custom comment markup.

If you are using a custom markup for your comment list like Ryan describes in this post (https://processwire.com/talk/topic/696-quick-guide-to-the-comments-system/?p=386) the email approval wont work any longer.

You can use your own markup and then you have to include the standard markup up too.

Standard markup to render comments:

<?php echo $page->comments->render();

Wrap this line of code inside a div and set the visibility of this div with CSS to hidden.

Now only your custom markup is visible, but the email approval works (if you are logged in or not).

At the moment I havent found another solution which works well in all cases, but if anyone has a better solution please post it here.

Link to comment
Share on other sites

  • 2 weeks later...

Does anyone have experience with using the Comments fieldtype for large volumes of comments? When I say large volume I'm thinking of a couple of thousand comments per page. Is the Comments fieldtype suitable for this kind of usage?

Pagination would be important in this situation. I've seen solutions in the forums for pagination of comments on the front-end but what about pagination in page edit?

Link to comment
Share on other sites

  • 5 months later...
2 minutes ago, Sephiroth said:

is there a way to disable email field in the comment form, as in I don't want the email form to be rendered...... Client Specific request :'(, I know it sounds weird

This ancient PR (https://github.com/ryancramerdesign/ProcessWire/pull/954/files?w=1) makes several changes to the comment field for logged in users, including using local profile image, and hiding (and autofilling)  the name and the email field.

I know it doesn't really help you, but does let you know that others have similar needs :)

I should maybe resubmit the PR to the new Github repo.

  • Like 1
Link to comment
Share on other sites

1 hour ago, adrian said:

This ancient PR (https://github.com/ryancramerdesign/ProcessWire/pull/954/files?w=1) makes several changes to the comment field for logged in users, including using local profile image, and hiding (and autofilling)  the name and the email field.

I know it doesn't really help you, but does let you know that others have similar needs :)

I should maybe resubmit the PR to the new Github repo.

Thanks already altered the core code, but i am going to inform the client that disadvantage of not taking emails... really requests like this make me want to quit frontend and do Backend totally. 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hi,

I'm wondering if it's possible to change the date of the comment in backend without using the API. A customer of mine wants to adopt some comments from Facebook manually and therefore he needs to change the date?

Many greets DV-JF alias Jens.

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