HOWTO: User comments
Enabling article-specific commenting is quite simple, yet needs a bit
of work. I was requested for this feature by Robert Guerra of Privaterra. Since I had seen the feature in use by Bergie and Midgard Project, I consulted Bergie.
His advice came with a price, which was to write a howto of it. Not bad, since I am working slowly with my own helps anyway.
First, we need a user account to use for postings. Preferably we should
create a user group as well in name of security. In this we will call
the group as "commenters" and create a guest account (username: guest, password: password). You of course won't be using this simple and predictable user account, right?
Second, we create a net.nemein.discussion topic. In this, we will give it URI name "comments" and we will it in the root folder of our website.
Edit this topic so that the owner group is the one, which has our guest user as a member. Then edit component configuration and check the "Allow thread creation by URI" checkbox.
You might want to set the comments folder hidden from navigation in the process as well.
Third, we create (or edit) the component style we want to use the commenting feature with. Here it will be de.linkm.newsticker,
but virtually any component will do - all you need to is to be able to
get GUID (Globally Unique Identificator) of the current article.
In the component style (here: show-detail) we will add the following lines:
<?php
$leaf = $nap->get_leaf($nap->get_current_leaf());
$guid = $leaf[MIDCOM_NAV_GUID];
if (!empty($guid) && !$_MIDGARD["user"]) {
mgd_auth_midgard("guest", "password", 0);
$GLOBALS["midgard"] = mgd_get_midgard();
}
$midcom->dynamic_load("/comments/{$guid}");
?>
Case specific settings are written in italics.
Update: Bergie also passed me a snippet to load Gravatars:
<?php
if ($view["poster_email"]) {
$size = 50;
$grav_url = "http://www.gravatar.com/avatar.php? gravatar_id="
.md5($view["poster_email"])
."&size=".$size;
?>
<img src="&(grav_url);" class="avatar" alt="&(view ["poster"]);"
title="&(view["poster"]);" />
<?php
} ?>
Add this in style element <(view-reply-item)> of your discussion topic.
Update: this tutorial is updated from this point onwards in Midgard Project documentation entry of "Enabling user commenting on a page"