]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/comments.pm
robustness fix
[ikiwiki.git] / IkiWiki / Plugin / comments.pm
old mode 100644 (file)
new mode 100755 (executable)
index 8d46ed5..fcce6c5
@@ -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,21 @@ sub preprocess {
 
                        $commentauthor = $commentuser;
                }
+
+               eval q{use Libravatar::URL};
+               if (! $@) {
+                       if (defined $commentopenid) {
+                               eval {
+                                       $commentauthoravatar = libravatar_url(openid => $commentopenid, https => $ENV{HTTPS});
+                               }
+                       }
+                       if (! defined $commentauthoravatar &&
+                           (my $email = IkiWiki::userinfo_get($commentuser, 'email'))) {
+                               eval {
+                                       $commentauthoravatar = libravatar_url(email => $email, https => $ENV{HTTPS});
+                               }
+                       }
+               }
        }
        else {
                if (defined $params{ip}) {
@@ -200,6 +216,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;
        }
@@ -216,7 +233,7 @@ sub preprocess {
                        my $url=$params{url};
 
                        eval q{use URI::Heuristic}; 
-                       if (! $@) {
+                       if (! $@) {
                                $url=URI::Heuristic::uf_uristr($url);
                        }
 
@@ -874,6 +891,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}) {