]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
comments: add avatar picture of comment author
authorFrancois Marier <francois@debian.org>
Sat, 5 Mar 2011 07:33:07 +0000 (20:33 +1300)
committerFrancois Marier <francois@debian.org>
Wed, 30 Mar 2011 07:59:17 +0000 (20:59 +1300)
Use Libravatar::URL to pull the avatar picture for the comment
author if we have an email address for him/her.

IkiWiki/Plugin/comments.pm [changed mode: 0644->0755]
doc/style.css
templates/comment.tmpl

old mode 100644 (file)
new mode 100755 (executable)
index 8d46ed5..00ab1c8
@@ -167,6 +167,7 @@ sub preprocess {
        my $commentip;
        my $commentauthor;
        my $commentauthorurl;
+       my $commentauthoravatar;
        my $commentopenid;
        if (defined $params{username}) {
                $commentuser = $params{username};
@@ -187,6 +188,16 @@ sub preprocess {
 
                        $commentauthor = $commentuser;
                }
+
+                eval 'use Libravatar::URL';
+
+                if (! $@) {
+                    my $email = IkiWiki::userinfo_get($commentuser, 'email');
+
+                    if (defined $email) {
+                        $commentauthoravatar = libravatar_url(email => $email);
+                    }
+                }
        }
        else {
                if (defined $params{ip}) {
@@ -200,6 +211,7 @@ sub preprocess {
        $commentstate{$page}{commentip} = $commentip;
        $commentstate{$page}{commentauthor} = $commentauthor;
        $commentstate{$page}{commentauthorurl} = $commentauthorurl;
+       $commentstate{$page}{commentauthoravatar} = $commentauthoravatar;
        if (! defined $pagestate{$page}{meta}{author}) {
                $pagestate{$page}{meta}{author} = $commentauthor;
        }
@@ -874,6 +886,11 @@ sub pagetemplate (@) {
                        $commentstate{$page}{commentauthorurl});
        }
 
+       if ($template->query(name => 'commentauthoravatar')) {
+               $template->param(commentauthoravatar =>
+                       $commentstate{$page}{commentauthoravatar});
+       }
+
        if ($template->query(name => 'removeurl') &&
            IkiWiki::Plugin::remove->can("check_canremove") &&
            length $config{cgiurl}) {
index fa413cf24a20432cb5a5221d47fe0032b93216bc..fcf39be6a74aa6a0569a0d1b66068d4ca5936547 100644 (file)
@@ -247,6 +247,9 @@ span.color {
 .comment-subject {
        font-weight: bold;
 }
+.comment-avatar {
+       float: right;
+}
 .comment {
        border: 1px solid #aaa;
        padding: 3px;
index c2ee5a37133107cc2461fa8d36e58f1e778afe30..c16ca7c810c78f6cabac99bfed6b5bfb19c8b72c 100644 (file)
@@ -1,6 +1,10 @@
 <TMPL_IF HTML5><article class="comment" id="<TMPL_VAR COMMENTID>">
 <TMPL_ELSE><div class="comment" id="<TMPL_VAR COMMENTID>"></TMPL_IF>
 
+<TMPL_IF COMMENTAUTHORAVATAR><div class="comment-avatar">
+<img src="<TMPL_VAR COMMENTAUTHORAVATAR>" alt="" />
+</div></TMPL_IF>
+
 <TMPL_IF HTML5><header class="comment-subject"><TMPL_ELSE><div class="comment-subject"></TMPL_IF>
 <TMPL_IF PERMALINK>
 <a href="<TMPL_VAR PERMALINK>"><TMPL_VAR TITLE></a>
@@ -58,4 +62,5 @@ Comment by
 <TMPL_IF HTML5></nav><TMPL_ELSE></div></TMPL_IF>
 </TMPL_IF>
 
+<div style="clear: both"></div>
 <TMPL_IF HTML5></article><TMPL_ELSE></div></TMPL_IF>