fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-02-28 08:34 am

[dw-free] User tag should allow Twitter as an option

[commit: http://hg.dwscoalition.org/dw-free/rev/b7d1369e7005]

http://bugs.dwscoalition.org/show_bug.cgi?id=3500

Add twitter to the list of sites you can link to, e.g., <user
name="exampleuser" site="twitter"<

Patch by [staff profile] denise.

Files modified:
  • cgi-bin/DW/External/Site.pm
  • cgi-bin/DW/External/Site/Twitter.pm
--------------------------------------------------------------------------------
diff -r 258723db2949 -r b7d1369e7005 cgi-bin/DW/External/Site.pm
--- a/cgi-bin/DW/External/Site.pm	Mon Feb 28 16:25:56 2011 +0800
+++ b/cgi-bin/DW/External/Site.pm	Mon Feb 28 16:33:50 2011 +0800
@@ -36,6 +36,7 @@ my %idtosite;
 $domaintosite{"journalfen.net"} = DW::External::Site->new("6", "www.journalfen.net", "journalfen.net", "JournalFen", "lj");
 $domaintosite{"dreamwidth.org"} = DW::External::Site->new("7", "www.dreamwidth.org", "dreamwidth.org", "Dreamwidth", "lj");
 $domaintosite{"archiveofourown.org"} = DW::External::Site->new("8", "www.archiveofourown.org", "archiveofourown.org", "ArchiveofOurOwn", "AO3");
+$domaintosite{"twitter.com"} = DW::External::Site->new("9", "twitter.com", "twitter.com", "Twitter", "Twitter");
 
 foreach my $value (values %domaintosite) {
     $idtosite{$value->{siteid}} = $value;
diff -r 258723db2949 -r b7d1369e7005 cgi-bin/DW/External/Site/Twitter.pm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/External/Site/Twitter.pm	Mon Feb 28 16:33:50 2011 +0800
@@ -0,0 +1,73 @@
+#!/usr/bin/perl
+#
+# DW::External::Site::Twitter
+#
+# Class to support Twitter linking.
+#
+# Authors:
+#      Mark Smith <mark@dreamwidth.org>
+#
+# Copyright (c) 2011 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+
+package DW::External::Site::Twitter;
+
+use strict;
+use base 'DW::External::Site';
+use Carp qw/ croak /;
+
+
+# new does nothing for these classes
+sub new { croak 'cannot build with new'; }
+
+
+# returns an object if we allow this domain; else undef
+sub accepts {
+    my ( $class, $parts ) = @_;
+
+    # let's just assume the last two parts are good if we have them
+    return undef unless scalar( @$parts ) >= 2;
+
+    return bless { hostname => "$parts->[-2].$parts->[-1]" }, $class;
+}
+
+
+# argument: DW::External::User
+# returns URL to this account's journal
+sub journal_url {
+    my ( $self, $u ) = @_;
+    croak 'need a DW::External::User'
+        unless $u && ref $u eq 'DW::External::User';
+
+    return 'http://' . $self->{hostname} . '/' . $u->user;
+}
+
+
+# argument: DW::External::User
+# returns URL to this account's journal
+sub profile_url {
+    my ( $self, $u ) = @_;
+    croak 'need a DW::External::User'
+        unless $u && ref $u eq 'DW::External::User';
+
+    return 'http://' . $self->{hostname} . '/' . $u->user;
+}
+
+
+# argument: DW::External::User
+# returns URL to the badge image (head icon) for this user
+sub badge_image_url {
+    my ( $self, $u ) = @_;
+    croak 'need a DW::External::User'
+        unless $u && ref $u eq 'DW::External::User';
+
+    # for lack of anything better, let's use the favicon
+    return "http://twitter.com/favicon.ico";
+}
+
+
+1;
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org