]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/openid.pm
web commit by http://edward.myopenid.com/: spelling fix and link [[hyperestraier]]
[git.ikiwiki.info.git] / IkiWiki / Plugin / openid.pm
index e8dbe964ffb2e901f759e22bb72aaf8ebec11c8a..de31f38ee3fffb7d8e9910afd5fadcf46ad41983 100644 (file)
@@ -164,4 +164,31 @@ sub getobj ($$) { #{{{
        );
 } #}}}
 
+package IkiWiki;
+
+# This is not used by this plugin, but this seems the best place to put it.
+# Used elsewhere to pretty-display the name of an openid user.
+sub openiduser ($) { #{{{
+       my $user=shift;
+
+       if ($user =~ m!^https?://! &&
+           eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
+               my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
+               my $display=$oid->display;
+               # Convert "user.somehost.com" to "user [somehost.com]".
+               if ($display !~ /\[/) {
+                       $display=~s/^(.*?)\.([^.]+\.[a-z]+)$/$1 [$2]/;
+               }
+               # Convert "http://somehost.com/user" to "user [somehost.com]".
+               if ($display !~ /\[/) {
+                       $display=~s/^https?:\/\/(.+)\/([^\/]+)$/$2 [$1]/;
+               }
+               $display=~s!^https?://!!; # make sure this is removed
+               eval q{use CGI 'escapeHTML'};
+               error($@) if $@;
+               return escapeHTML($display);
+       }
+       return;
+}
+
 1