« prev next »

Added Commenter Profile Page to MovableType

If you check the site careful enough, you will see a small icon besides the name of the commenter. It is newly added feature - Commenter Profile:

screen-comment.png

The link on the icon will lead you to the profile page of the commenter, so you understand what comments he/she has posted before.

Since it is based on display name only, don't always take it for granted that people with same display name are the same person. If you found your name are too common, choose a more unique name.

Code?

Below are the code I used. It is very massy, since I didn't spent time to make it workable for others. It just fit the needs of this blog. I wrote it as if I were writting a blog entry. When what I try to express is completed, the code is completed. So take whatever you can take from the code, but don't expect it to work on your MovableType directly. For those who don't like tech stuff, sorry for posting techie again.

<?php

function dirify($s) {
  $s = strtolower($s);   ## lower-case.
  $s = strip_tags($s);       ## remove HTML tags.
  $s = preg_replace('!&[^;\s]+;!','',$s); ## remove HTML entities.
  $s = preg_replace('![^\w\s]!','',$s);   ## remove non-word/space chars.
  $s = preg_replace('!\s+!','_',$s);       ## change space chars to underscores.
  return $s;    
}

$mt_blog_users = "http://home.wangjianshuo.com/users/";
$mt_blog_archive = "http://home.wangjianshuo.com/archives/";

$file = '<Location of mt-config.cgi file>';
$cfg = array();
if ($fp = file($file)) {
    foreach ($fp as $line) {
    // search through the file
        if (!ereg('^\s*\#',$line)) {
            // ignore lines starting with the hash symbol
            if (preg_match('/^\s*([^ ]+)[ ](.*)(\r|n)?$/', $line, $regs)) {
                $key = trim($regs[1]);
                $value = trim($regs[2]);
                $cfg[$key] = $value;
            }
        }
    }
} else {
    die("Unable to open configuration file $file");
}

$db = mysql_connect($cfg['DBHost'], $cfg['DBUser'], 
    $cfg['DBPassword']) or die ('I cannot connect to MySQL.');

mysql_select_db($cfg['Database']);


$query = "SELECT comment_author, 
        count(comment_author) as comment_count 
        FROM mt_comment 
        GROUP BY comment_author 
        ORDER BY comment_count";
	
$result = mysql_query($query);

$comment_author_previous = "";
$comment_author_next = "";

while ($row = mysql_fetch_array($result)) {
    if($row['comment_author'] == $user) {
        $comment_author_previous = $comment_author_previous_temp;
    }
    if($comment_author_previous_temp == $user) {  
        $comment_author_next = $row['comment_author'];
    }
    $comment_author_previous_temp = $row['comment_author'];
}

echo "<small><a href='$mt_blog_users$comment_author_next.htm'>« $comment_author_next</a> |";
echo " <a href='http://home.wangjianshuo.com/scripts/mt-user/mt-all-user.php'>Commenters</a> ";
echo "| <a href='$mt_blog_users$comment_author_previous.htm'>$comment_author_previous »</a></small>";

$user or $user = 'Jian Shuo Wang';
$query = "SELECT entry_id, entry_title, 
    comment_id, comment_url, 
    entry_excerpt, comment_text, 
    comment_entry_id, 
    date_format(entry_created_on, '%Y%m%d') as comment_entry_ymd, 
    date_format(comment_created_on, '%h%i') as comment_hourmin, 
    comment_created_on 
    FROM mt_comment, mt_entry 
    WHERE comment_entry_id = entry_id 
    AND comment_author = '$user' 
    ORDER BY comment_id DESC 
    LIMIT 300";

$comment_url = "";
$comment_count = 0;

$html = "";

$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
    $comment_entry_id = $row['comment_entry_id'];
    $html = $html . "<p>" . (nl2br($row['comment_text'])) .
 "<p><small>Posted by $user at <
a href='http://home.wangjianshuo.com/users/" .
 $row['comment_id'] . ".htm' target=_blank>" . 
$row['comment_created_on'] . 
"</a> on <a target=_blank href=$mt_blog_archive" . 
$row['comment_entry_ymd'] .
 "_" . dirify($row['entry_title']) .
 ".htm#" . $row['comment_hourmin'] .
 ">" . $row['entry_title'] .
"</a></small><hr>";

    $comment_url or $comment_url = $row['comment_url'];
    $comment_count = $comment_count + 1;
}

echo "<h1>$user</h1><a href='$comment_url' target=_blank>$comment_url</a> ";
echo "Posted <b>$comment_count</b> comment(s)";
echo $html;

mysql_free_result($result);
mysql_close();

?>

by Jian Shuo Wang on February 1, 2006 under MovableType

Related Entries: MovableType
  1. Six Apart's Problem? February 22, 2009
  2. Track Click on Elements February 22, 2009
  3. Short Pause of Comment System January 20, 2009
  4. MovableType 4.2 is Disappointing June 8, 2008
  5. Subscription Enabled on This Blog April 23, 2008
  6. MovableType Dirify Change for UTF-8 December 23, 2007
  7. MovableType 4.01 and Bluehost CPU Exceeded Error November 16, 2007
  8. Wangjianshuo's Blog Template Archives 2007 November 5, 2007
  9. FeedBurner is a Useful Service August 28, 2007
Comments

Shouldn't you just enjoy your holiday and RELAX ? ! :-)

Posted by: carsten on February 1, 2006 11:17 PM

wanna check if all my comments can be seen at once

Posted by: Sekhar Sirigiri on February 2, 2006 2:30 PM

carsten, thanks. Someone enjoy sitting in the Sun. I also enjoy that, but I also enjoy coding for some time. :-) Coding is interesting fo rme.

Posted by: Jian Shuo Wang on February 2, 2006 10:49 PM
Post a comment
Name:

Email Address: (will not show)

URL: (optional)

Comments:


It may take up to 30 seconds before the server returns a result. IP address recorded.
Remember my information?
<-- Please click POST only once
© 2001 - 2009 Jian Shuo Wang. All right reserved .