summaryrefslogtreecommitdiff
path: root/IkiWiki.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-01-28 22:58:31 -0500
committerJoey Hess <joey@kodama.kitenet.net>2008-01-28 22:58:31 -0500
commit29f3082772095030895111f199d6420ef1835250 (patch)
treea9eb0af660c02665b482eb8e390a97223ee45056 /IkiWiki.pm
parent9f25e3436b2b918845acbd8cf2ff2d358e0ea105 (diff)
move userlink to IkiWiki.pm
I have a plugin that needs to use userlink.
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r--IkiWiki.pm28
1 files changed, 28 insertions, 0 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 46060c1b2..15402211f 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -609,6 +609,34 @@ sub htmllink ($$$;@) { #{{{
return "<a href=\"$bestlink\"@attrs>$linktext</a>";
} #}}}
+sub userlink ($) { #{{{
+ my $user=shift;
+
+ eval q{use CGI 'escapeHTML'};
+ error($@) if $@;
+ if ($user =~ m!^https?://! &&
+ eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
+ # Munge user-urls, as used by eg, OpenID.
+ 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
+ return "<a href=\"$user\">".escapeHTML($display)."</a>";
+ }
+ else {
+ return htmllink("", "", escapeHTML(
+ length $config{userdir} ? $config{userdir}."/".$user : $user
+ ), noimageinline => 1);
+ }
+} #}}}
+
sub htmlize ($$$) { #{{{
my $page=shift;
my $type=shift;