New S2 functions: viewer_has_access, viewer_is_subscribed,
viewer_is_admin, viewer_is_moderator.
Patch by foxfirefey.
diffs (111 lines):
diff -r e9f508c96f2f -r 06104cf6052e bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2 Sun Jun 06 17:16:58 2010 -0500
+++ b/bin/upgrading/s2layers/core2.s2 Sun Jun 06 18:40:34 2010 -0500
@@ -905,7 +905,19 @@ Useful for returning links to manage inf
Useful for returning links to manage information, or edit entries.";
function builtin viewer_is_friend() : bool
-"Returns true if the user viewing the page is both logged in, and is a friend
of the journal being viewed. Always returns false for communities, since they
cannot have friends.";
+"Returns true if the user viewing the page is logged in and has access to the
journal being viewed. Returns true if the user is a member of a community.";
+
+function builtin viewer_is_subscribed() : bool
+"Returns true if the user viewing the page is logged in and subscribes to the
journal being viewed.";
+
+function builtin viewer_has_access() : bool
+"Returns true if the user viewing the page is logged in and has access to the
journal being viewed. In communities, returns true if the viewer is a member
of the community.";
+
+function builtin viewer_is_admin() : bool
+"Returns true if the user viewing a community is logged in and is an admin of
the community.";
+
+function builtin viewer_is_moderator() : bool
+"Returns true if the user viewing a community is logged in and a moderator of
the community.";
function builtin viewer_is_member() : bool
"Returns true if the user viewing the page is both logged in, and is a member
of the community being viewed. Always returns false for personal journals,
since they cannot have members.";
diff -r e9f508c96f2f -r 06104cf6052e cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm Sun Jun 06 17:16:58 2010 -0500
+++ b/cgi-bin/LJ/S2.pm Sun Jun 06 18:40:34 2010 -0500
@@ -2563,18 +2563,16 @@ sub pageview_unique_string {
sub viewer_logged_in
{
- my ($ctx) = @_;
my $remote = LJ::get_remote();
return defined $remote;
}
sub viewer_is_owner
{
- my ($ctx) = @_;
my $remote = LJ::get_remote();
return 0 unless $remote;
return 0 unless defined($LJ::S2::CURR_PAGE);
- return $remote->{'userid'} == $LJ::S2::CURR_PAGE->{'_u'}->{'userid'};
+ return $remote->{userid} == $LJ::S2::CURR_PAGE->{_u}->{userid};
}
# NOTE: this method is old and deprecated, but we still support it for people
@@ -2586,26 +2584,58 @@ sub viewer_is_owner
# suggest that people update their styles to use the DW core/functions.
sub viewer_is_friend
{
- my ($ctx) = @_;
+ return viewer_has_access();
+}
+
+sub viewer_has_access
+{
my $remote = LJ::get_remote();
return 0 unless $remote;
return 0 unless defined($LJ::S2::CURR_PAGE);
- my $ju = $LJ::S2::CURR_PAGE->{'_u'};
- return 0 if $ju->is_community;
+ my $ju = $LJ::S2::CURR_PAGE->{_u};
+ return viewer_is_member() if $ju->is_community;
return $ju->trusts( $remote );
}
+sub viewer_is_subscribed {
+ my $remote = LJ::get_remote();
+ return 0 unless $remote;
+ return 0 unless defined $LJ::S2::CURR_PAGE;
+
+ my $ju = $LJ::S2::CURR_PAGE->{_u};
+ return $remote->watches( $ju );
+}
+
sub viewer_is_member
{
- my ($ctx) = @_;
my $remote = LJ::get_remote();
return 0 unless $remote;
return 0 unless defined($LJ::S2::CURR_PAGE);
- my $ju = $LJ::S2::CURR_PAGE->{'_u'};
+ my $ju = $LJ::S2::CURR_PAGE->{_u};
return 0 unless $ju->is_community;
return $remote->member_of( $ju );
+}
+
+sub viewer_is_admin {
+ my $remote = LJ::get_remote();
+ return 0 unless $remote;
+ return 0 unless defined $LJ::S2::CURR_PAGE;
+
+ my $ju = $LJ::S2::CURR_PAGE->{_u};
+ return 0 unless $ju->is_community;
+ return $remote->can_manage( $ju );
+}
+
+sub viewer_is_moderator {
+ my $remote = LJ::get_remote();
+ return 0 unless $remote;
+ return 0 unless defined $LJ::S2::CURR_PAGE;
+
+ my $ju = $LJ::S2::CURR_PAGE->{_u};
+ return 0 unless $ju->is_community;
+ return LJ::check_rel( $ju, $remote, 'M' );
}
sub viewer_sees_control_strip
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog