mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-03-04 08:08 am

[dw-free] Use common logic for user link bar on profile page and in S2

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

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

Nice cleanup of S2 linkbar functionality.

Patch by [personal profile] afuna.

Files modified:
  • bin/upgrading/en.dat
  • cgi-bin/DW/Logic/ProfilePage.pm
  • cgi-bin/LJ/S2.pm
  • htdocs/userinfo.bml.text
--------------------------------------------------------------------------------
diff -r 3bd415c4b16c -r 535e170916f2 bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Wed Mar 04 08:04:40 2009 +0000
+++ b/bin/upgrading/en.dat	Wed Mar 04 08:08:06 2009 +0000
@@ -2998,6 +2998,92 @@ tos.haveread=I have read and agree to th
 
 tos.mustread=Before continuing you must read and agree to the <a [[aopts]]>Terms of Service.</a>
 
+userlinkbar.addsub=Subscribe
+
+userlinkbar.addsub.title.loggedout=You must be logged in to subscribe to this account
+
+userlinkbar.addsub.title.other=Subscribe to this account
+
+userlinkbar.addsub.title.self=Subscribe to your account
+
+userlinkbar.addtrust=Grant Access
+
+userlinkbar.addtrust.title.other=Grant access to this user
+
+userlinkbar.addtrust.title.loggedout=You must be logged in to grant access to this user
+
+userlinkbar.joincomm=Join
+
+userlinkbar.joincomm.title.cantjoin=You cannot join this community
+
+userlinkbar.joincomm.title.closed=Membership for this community is closed
+
+userlinkbar.joincomm.title.loggedout=You must be logged in to join this community
+
+userlinkbar.joincomm.title.open=Join this community
+
+userlinkbar.leavecomm=Leave
+
+userlinkbar.leavecomm.title=Leave this community
+
+userlinkbar.memories=Memories
+
+userlinkbar.memories.title.other=View this user's memories
+
+userlinkbar.memories.title.self=View your memories
+
+userlinkbar.modifysub=Modify Subscription
+
+userlinkbar.modifysub.title.other=Modify/remove subscription for this account
+
+userlinkbar.modifysub.title.self=Modify/remove subscription for your account
+
+userlinkbar.modifytrust=Modify Access
+
+userlinkbar.modifytrust.title.other=Modify/remove access from this user
+
+userlinkbar.tellafriend=Tell a Friend
+
+userlinkbar.tellafriend.title.other=Tell a friend about this journal
+
+userlinkbar.tellafriend.title.self=Tell a friend about your journal
+
+userlinkbar.post=Post
+
+userlinkbar.post.title=Post to this community
+
+userlinkbar.post.title.cantpost=You cannot post to this community
+
+userlinkbar.post.title.loggedout=You must be logged in to post to this community
+
+userlinkbar.postentry=Post an Entry
+
+userlinkbar.postentry.title=Post to your journal
+
+userlinkbar.sendmessage=Send Message
+
+userlinkbar.sendmessage.title=Send a private message to this user
+
+userlinkbar.sendmessage.title.cantsendmessage=You cannot send a private message to this user
+
+userlinkbar.sendmessage.title.loggedout=You must be logged in to send a private message to this user
+
+userlinkbar.track=Track
+
+userlinkbar.track.title=Receive notifications of updates to this community
+
+userlinkbar.tracksyn=Track Feed
+
+userlinkbar.tracksyn.title=Receive notifications of updates to this feed
+
+userlinkbar.trackuser=Track User
+
+userlinkbar.trackuser.title=Receive notifications of updates from this user
+
+userlinkbar.trackuser.title.cantuseesn=You cannot manage notifications
+
+userlinkbar.trackuser.title.loggedout=You must be logged in to manage notifications
+
 username=Username
 
 userpic.inactive=Inactive
diff -r 3bd415c4b16c -r 535e170916f2 cgi-bin/DW/Logic/ProfilePage.pm
--- a/cgi-bin/DW/Logic/ProfilePage.pm	Wed Mar 04 08:04:40 2009 +0000
+++ b/cgi-bin/DW/Logic/ProfilePage.pm	Wed Mar 04 08:08:06 2009 +0000
@@ -19,7 +19,7 @@ package DW::Logic::ProfilePage;
 package DW::Logic::ProfilePage;
 
 use strict;
-
+use DW::Logic::UserLinkBar;
 
 # returns a new profile page object
 sub profile_page {
@@ -40,7 +40,6 @@ sub profile_page {
 *LJ::User::profile_page = \&profile_page;
 *DW::User::profile_page = \&profile_page;
 
-
 # returns array of hashrefs
 #   (
 #       { url => "http://...",
@@ -56,216 +55,10 @@ sub action_links {
     my $self = $_[0];
 
     my $u = $self->{u};
-    my $user = $u->user;
     my $remote = $self->{remote};
-    my @ret;
-
-### JOIN/LEAVE COMMUNITY
-
-    if ( $u->is_community ) {
-        # if logged in and a member of the community $u
-        if ( $remote && $remote->member_of( $u ) ) {
-            push @ret, {
-                url      => "community/leave.bml?comm=$user",
-                title_ml => '.optionlinks.leavecomm.title',
-                image    => 'leave-comm.gif',
-                text_ml  => '.optionlinks.leavecomm',
-                class    => 'profile_leave',
-            };
-
-        # if logged out, OR, not a member
-        } else {
-            my @comm_settings = LJ::get_comm_settings($u);
-
-            my $link = {
-                text_ml => '.optionlinks.joincomm',
-            };
-
-            # if they're not allowed to join at this moment (many reasons)
-            if ($comm_settings[0] eq 'closed' || !$remote || $remote->is_identity || !$u->is_visible) {
-                $link->{title_ml} = $comm_settings[0] eq 'closed' ?
-                                        '.optionlinks.joincomm.title.closed' :
-                                        '.optionlinks.joincomm.title.loggedout';
-                $link->{title_ml} = '.optionlinks.joincomm.title.cantjoin'
-                    if $remote && $remote->is_identity;
-                $link->{image}    = 'join-comm-disabled.gif';
-                $link->{class}    = 'profile_join_disabled';
-
-            # allowed to join
-            } else {
-                $link->{url}      = "community/join.bml?comm=$user";
-                $link->{title_ml} = '.optionlinks.joincomm.title.open';
-                $link->{image}    = 'join-comm.gif';
-                $link->{class}    = 'profile_join';
-            }
-
-            push @ret, $link;
-        }
-    }
-
-### ADD TRUST
-
-    # can add/modify trust for the user if they are a person and not the same as the remote user, and remote is a personal account
-    if ( ( $u->is_personal || $u->is_identity ) && ( !$remote || ( $remote && !$remote->equals( $u ) && $remote->is_personal ) ) ) {
-        my $link = {};
-
-        my $remote_trusts = $remote && $remote->trusts( $u ) ? 1 : 0;
-        $link->{text_ml} = $remote_trusts ? '.optionlinks.modifytrust' : '.optionlinks.addtrust';
-        if ( $remote && ( $remote_trusts || $u->is_visible ) ) {
-            $link->{url} = "manage/circle/add.bml?user=$user&action=access";
-            $link->{title_ml} = $remote_trusts ? '.optionlinks.modifytrust.title.other' : '.optionlinks.addtrust.title.other';
-            $link->{class} = 'profile_addtrust';
-            $link->{image} = 'add-friend.gif';
-        } else {
-            $link->{title_ml} = '.optionlinks.addtrust.title.loggedout';
-            $link->{class} = 'profile_addtrust_disabled';
-            $link->{image} = 'add-friend-disabled.gif';
-        }
-
-        push @ret, $link;
-    }
-
-### ADD WATCH
-
-    {
-        my $link = {};
-
-        my $remote_watches = $remote && $remote->watches( $u ) ? 1 : 0;
-        $link->{text_ml} = $remote_watches ? '.optionlinks.modifysub' : '.optionlinks.addsub';
-        if ( $remote && ( $remote_watches || $u->is_visible ) ) {
-            $link->{url} = "manage/circle/add.bml?user=$user&action=subscribe";
-
-            if ( $remote->equals( $u ) ) {
-                $link->{title_ml} = $remote_watches ? '.optionlinks.modifysub.title.self' : '.optionlinks.addsub.title.self';
-            } else {
-                $link->{title_ml} = $remote_watches ? '.optionlinks.modifysub.title.other' : '.optionlinks.addsub.title.other';
-            }
-
-            if ( $u->is_community ) {
-                $link->{class} = 'profile_addsub_comm';
-                $link->{image} = 'watch-comm.gif';
-            } elsif ( $u->is_syndicated ) {
-                $link->{class} = 'profile_addsub_feed';
-                $link->{image} = 'add-feed.gif';
-            } else {
-                $link->{class} = 'profile_addsub_person';
-                $link->{image} = 'add-friend.gif';
-            }
-        } else {
-            $link->{title_ml} = '.optionlinks.addsub.title.loggedout';
-            if ( $u->is_community ) {
-                $link->{class} = 'profile_addsub_comm_disabled';
-                $link->{image} = 'watch-comm-disabled.gif';
-            } elsif ( $u->is_syndicated ) {
-                $link->{class} = 'profile_addsub_feed_disabled';
-                $link->{image} = 'add-feed-disabled.gif';
-            } else {
-                $link->{class} = 'profile_addsub_person_disabled';
-                $link->{image} = 'add-friend-disabled.gif';
-            }
-        }
-
-        push @ret, $link;
-    }
-
-### POST ENTRY
-
-    if ( $remote && $remote->is_personal && ( $u->is_personal || $u->is_community ) && $remote->can_post_to( $u ) ) {
-        my $link = {
-            url => "update.bml?usejournal=$user",
-            class => 'profile_postentry',
-            image => 'post-entry.gif',
-        };
-
-        if ( $u->is_community ) {
-            $link->{text_ml} = '.optionlinks.post';
-            $link->{title_ml} = '.optionlinks.post.title';
-        } else {
-            $link->{text_ml} = '.optionlinks.postentry';
-            $link->{title_ml} = '.optionlinks.postentry.title';
-        }
-
-        push @ret, $link;
-    } elsif ( $u->is_community ) {
-        push @ret, {
-            text_ml => '.optionlinks.post',
-            title_ml => $remote ? '.optionlinks.post.title.cantpost' : '.optionlinks.post.title.loggedout',
-            class => 'profile_postentry_disabled',
-            image => 'post-entry-disabled.gif',
-        };
-    }
-
-### TRACK
-
-    if ( LJ::is_enabled( 'esn' ) ) {
-        my $link = {
-            text_ml => '.optionlinks.trackuser',
-            title_ml => '.optionlinks.trackuser.title',
-        };
-
-        if ( $remote && $remote->equals( $u ) ) {
-            $link->{text_ml} = '.optionlinks.tracking';
-            $link->{title_ml} = '.optionlinks.tracking.title';
-        } elsif ( $u->is_community ) {
-            $link->{text_ml} = '.optionlinks.track';
-            $link->{title_ml} = '.optionlinks.track.title';
-        } elsif ( $u->is_syndicated ) {
-            $link->{text_ml} = '.optionlinks.tracksyn';
-            $link->{title_ml} = '.optionlinks.tracksyn.title';
-        }
-
-        if ( $remote && $remote->can_use_esn ) {
-            $link->{url} = "manage/subscriptions/user.bml?journal=$user";
-            $link->{class} = 'profile_trackuser';
-            $link->{image} = 'track.gif';
-        } else {
-            $link->{title_ml} = $remote ? '.optionlinks.trackuser.title.cantuseesn' : '.optionlinks.trackuser.title.loggedout';
-            $link->{class} = 'profile_trackuser_disabled';
-            $link->{image} = 'track-disabled.gif';
-        }
-
-        push @ret, $link;
-    }
-
-### PRIVATE MESSAGE
-
-    if ( ( $u->is_personal || $u->is_identity ) && !$u->equals( $remote ) ) {
-        my $link = {
-            text_ml => '.optionlinks.sendmessage',
-            title_ml => '.optionlinks.sendmessage.title',
-        };
-
-        if ( $remote && $u->can_receive_message( $remote ) ) {
-            $link->{url} = "inbox/compose.bml?user=$user";
-            $link->{class} = 'profile_sendmessage';
-            $link->{image} = 'send-message.gif';
-        } else {
-            $link->{title_ml} = $remote ? '.optionlinks.sendmessage.title.cantsendmessage' : '.optionlinks.sendmessage.title.loggedout';
-            $link->{class} = 'profile_sendmessage_disabled';
-            $link->{image} = 'send-message-disabled.gif';
-        }
-
-        push @ret, $link;
-    }
-
-### EXTRA
-
-    # fix up image links and URLs and language
-    foreach my $link ( @ret ) {
-        $link->{image} = "$LJ::IMGPREFIX/profile_icons/$link->{image}"
-            if $link->{image} && $link->{image} !~ /^$LJ::IMGPREFIX/;
-        $link->{url} = "$LJ::SITEROOT/$link->{url}"
-            if $link->{url} && $link->{url} !~ /^$LJ::SITEROOT/;
-
-        if ( my $ml = delete $link->{title_ml} ) {
-            $link->{title} = LJ::Lang::ml( $ml );
-        }
-        if ( my $ml = delete $link->{text_ml} ) {
-            $link->{text} = LJ::Lang::ml( $ml );
-        }
-    }
-
-    return @ret;
+    
+    my $user_link_bar = $u->user_link_bar( $remote, class_prefix => "profile" );
+    my @ret = $user_link_bar->get_links( "manage_membership", "trust", "watch", "post", "track", "message" );
 }
 
 
diff -r 3bd415c4b16c -r 535e170916f2 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm	Wed Mar 04 08:04:40 2009 +0000
+++ b/cgi-bin/LJ/S2.pm	Wed Mar 04 08:08:06 2009 +0000
@@ -2197,9 +2197,8 @@ sub UserLite
         'link_keyseq' => [ ],
     };
     my $lks = $o->{link_keyseq};
-    push @$lks, qw(add_friend post_entry memories);
-    push @$lks, "tell_friend"  unless $LJ::DISABLED{'tellafriend'};
-    push @$lks, "search"  unless $LJ::DISABLED{'offsite_journal_search'};
+    push @$lks, qw(manage_membership trust watch post_entry track message);
+    push @$lks, 'tell_friend' unless $LJ::DISABLED{tellafriend};
 
     # TODO: Figure out some way to use the userinfo_linkele hook here?
 
@@ -3455,37 +3454,23 @@ sub UserLite__get_link
 {
     my ($ctx, $this, $key) = @_;
 
-    my $u = $this->{_u};
-    my $user = $u->{user};
-    my $remote = LJ::get_remote();
-    my $is_remote = defined($remote) && $remote->{userid} eq $u->{userid};
-    my $has_journal = $u->{journaltype} ne 'I';
+    my $linkbar = $this->{_u}->user_link_bar( LJ::get_remote() );
 
     my $button = sub {
-        return LJ::S2::Link($_[0], $_[1], LJ::S2::Image("$LJ::IMGPREFIX/$_[2]", 22, 20));
-    };
-
-    if ($key eq 'add_friend' && defined($remote)) {
-        return $button->("$LJ::SITEROOT/manage/circle/add.bml?user=$user", "Add $user to friends list", "btn_addfriend.gif");
-    }
-    if ($key eq 'post_entry') {
-        return undef unless $has_journal and LJ::can_use_journal($remote->{'userid'}, $user);
-
-        my $caption = $is_remote ? "Update your journal" : "Post in $user";
-        return $button->("$LJ::SITEROOT/update.bml?usejournal=$user", $caption, "btn_edit.gif");
-    }
-    if ($key eq 'memories') {
-        my $caption = $is_remote ? "Your memories" : "${user}'s memories";
-        return $button->("$LJ::SITEROOT/tools/memories.bml?user=$user", $caption, "btn_memories.gif");
-    }
-    if ($key eq 'tell_friend' && $has_journal && !$LJ::DISABLED{'tellafriend'}) {
-        my $caption = $is_remote ? "Tell a friend about your journal" : "Tell a friend about $user";
-        return $button->("$LJ::SITEROOT/tools/tellafriend.bml?user=$user", $caption, "btn_tellfriend.gif");
-    }
-    if ($key eq 'search' && $has_journal && !$LJ::DISABLED{'offsite_journal_search'}) {
-        my $caption = $is_remote ? "Search your journal" : "Search $user";
-        return $button->("$LJ::SITEROOT/tools/search.bml?user=$user", $caption, "btn_search.gif");
-    }
+        my $link = $_[0];
+        return undef unless $link;
+
+        return LJ::S2::Link($link->{url}, $link->{title}, LJ::S2::Image($link->{image}, 20, 18));
+    };
+
+    return $button->( $linkbar->manage_membership ) if $key eq 'manage_membership';
+    return $button->( $linkbar->trust ) if $key eq 'trust';
+    return $button->( $linkbar->watch ) if $key eq 'watch';
+    return $button->( $linkbar->post ) if $key eq 'post_entry';
+    return $button->( $linkbar->message ) if $key eq 'message';    
+    return $button->( $linkbar->track ) if $key eq 'track';
+    return $button->( $linkbar->memories ) if $key eq 'memories';
+    return $button->( $linkbar->tellafriend ) if $key eq 'tell_friend';
 
     # Else?
     return undef;
diff -r 3bd415c4b16c -r 535e170916f2 htdocs/userinfo.bml.text
--- a/htdocs/userinfo.bml.text	Wed Mar 04 08:04:40 2009 +0000
+++ b/htdocs/userinfo.bml.text	Wed Mar 04 08:08:06 2009 +0000
@@ -330,94 +330,6 @@
 
 .nonexist.name=Unknown user
 
-.optionlinks.addsub=Subscribe
-
-.optionlinks.addsub.title.loggedout=You must be logged in to subscribe to this account
-
-.optionlinks.addsub.title.other=Subscribe to this account
-
-.optionlinks.addsub.title.self=Subscribe to your account
-
-.optionlinks.addtrust=Grant Access
-
-.optionlinks.addtrust.title.other=Grant access to this user
-
-.optionlinks.addtrust.title.loggedout=You must be logged in to grant access to this user
-
-.optionlinks.joincomm=Join
-
-.optionlinks.joincomm.title.cantjoin=You cannot join this community
-
-.optionlinks.joincomm.title.closed=Membership for this community is closed
-
-.optionlinks.joincomm.title.loggedout=You must be logged in to join this community
-
-.optionlinks.joincomm.title.open=Join this community
-
-.optionlinks.leavecomm=Leave
-
-.optionlinks.leavecomm.title=Leave this community
-
-.optionlinks.modifysub=Modify Subscription
-
-.optionlinks.modifysub.title.other=Modify/remove subscription for this account
-
-.optionlinks.modifysub.title.self=Modify/remove subscription for your account
-
-.optionlinks.modifytrust=Modify Access
-
-.optionlinks.modifytrust.title.other=Modify/remove access from this user
-
-.optionlinks.post=Post
-
-.optionlinks.post.title=Post to this community
-
-.optionlinks.post.title.cantpost=You cannot post to this community
-
-.optionlinks.post.title.loggedout=You must be logged in to post to this community
-
-.optionlinks.postentry=Post an Entry
-
-.optionlinks.postentry.title=Post to your journal
-
-.optionlinks.sendmessage=Send Message
-
-.optionlinks.sendmessage.title=Send a private message to this user
-
-.optionlinks.sendmessage.title.cantsendmessage=You cannot send a private message to this user
-
-.optionlinks.sendmessage.title.loggedout=You must be logged in to send a private message to this user
-
-.optionlinks.track=Track
-
-.optionlinks.track.title=Receive notifications of updates to this community
-
-.optionlinks.tracking=Tracking
-
-.optionlinks.tracking.title=Manage your notifications
-
-.optionlinks.tracksyn=Track Feed
-
-.optionlinks.tracksyn.title=Receive notifications of updates to this feed
-
-.optionlinks.trackuser=Track User
-
-.optionlinks.trackuser.title=Receive notifications of updates from this user
-
-.optionlinks.trackuser.title.cantuseesn=You cannot manage notifications
-
-.optionlinks.trackuser.title.loggedout=You must be logged in to manage notifications
-
-.optionlinks.viewjournal=View Journal
-
-.optionlinks.viewjournal.title.comm=View this community's journal
-
-.optionlinks.viewjournal.title.self=View your journal
-
-.optionlinks.viewjournal.title.syn=View this feed's journal
-
-.optionlinks.viewjournal.title.user=View this user's journal
-
 .people.header=People
 
 .people.members.none=Members (0)
--------------------------------------------------------------------------------

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