Add new feature for communities: ability to show/hide a 'post to comm' 
link when someone joins the comm, as well as ability to say 'this post contains 
our posting guidelines' which is shown to people who join the community.

        Patch by wyntarvox. 

diffs (339 lines):

diff -r 43de6d4f95fb -r d6762606a18d bin/upgrading/proplists.dat
--- a/bin/upgrading/proplists.dat       Wed Oct 21 17:15:15 2009 +0000
+++ b/bin/upgrading/proplists.dat       Wed Oct 21 17:24:56 2009 +0000
@@ -349,6 +349,14 @@ userproplist.hide_adult_content:
   indexed: 0
   multihomed: 0
   prettyname: Hide adult content on journals
+
+userproplist.hide_join_post_link:
+    cldversion: 4
+    datatype: bool
+    des: Option to hide post to community link on join community success page
+    indexed: 0
+    multihomed: 0
+    prettyname: Hide post to community link on join page
 
 userproplist.icbm:
   cldversion: 4
@@ -870,6 +878,14 @@ userproplist.opt_show_captcha_to:
   multihomed: 0
   prettyname: Show CAPTHCHA on commenting
 
+userproplist.posting_guidelines_entry:
+  cldversion: 4
+  datatype: char
+  des: Community posting guidelines entry ID
+  indexed: 0
+  multihomed: 0
+  prettyname: Community posting guidelines entry ID
+
 userproplist.profile_collapsed_headers:
   cldversion: 4
   datatype: char
diff -r 43de6d4f95fb -r d6762606a18d cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm        Wed Oct 21 17:15:15 2009 +0000
+++ b/cgi-bin/LJ/User.pm        Wed Oct 21 17:24:56 2009 +0000
@@ -1925,6 +1925,19 @@ sub google_analytics {
 }
 
 
+# get/set post to community link visibility
+sub hide_join_post_link {
+    my $u = $_[0];
+
+    if ( defined $_[1] ) {
+        $u->set_prop( hide_join_post_link => $_[1] );
+        return $_[1];
+    }
+
+    return $u->prop( 'hide_join_post_link' );
+}
+
+
 # tests to see if a user is in a specific named class. class
 # names are site-specific.
 sub in_class {
@@ -2096,6 +2109,48 @@ sub opt_whatemailshow {
 
     # otherwise, return the default: no email shown
     return 'N';
+}
+
+
+# get/set community's guidelines entry ditemid
+sub posting_guidelines_entry {
+    my ( $u, $args ) = @_;
+
+    if ( defined $args ) {
+        unless ( $args ) {
+            $u->set_prop( posting_guidelines_entry => '' );
+            return 1;
+        }
+        my $ditemid;
+        if ( $args =~ m!/(\d+)\.html! ) {
+            $ditemid = $1;
+        } elsif ( $args =~ m!^(\d+)$! ) {
+            $ditemid = $1;
+        } else {
+            return 0;
+        }
+
+        my $entry = LJ::Entry->new( $u, ditemid => $ditemid );
+        return 0 unless $entry && $entry->valid;
+
+        $u->set_prop( posting_guidelines_entry => $ditemid );
+        return $ditemid;
+    }
+
+    return $u->prop( 'posting_guidelines_entry' );
+}
+
+
+# get community's guidelines entry as entry object
+sub get_posting_guidelines_entry {
+    my $u = shift;
+
+    if ( my $ditemid = $u->posting_guidelines_entry ) {
+        my $entry = LJ::Entry->new( $u, ditemid => $ditemid );
+        return $entry if $entry->valid;
+    }
+
+    return undef;
 }
 
 
diff -r 43de6d4f95fb -r d6762606a18d htdocs/community/join.bml
--- a/htdocs/community/join.bml Wed Oct 21 17:15:15 2009 +0000
+++ b/htdocs/community/join.bml Wed Oct 21 17:24:56 2009 +0000
@@ -117,8 +117,25 @@ body<=
 
         # success message -- only shows if user didn't add the community as a 
friend
         my $profile_url = $cu->profile_url;
+        my $show_join_post_link = $cu->hide_join_post_link ? 0 : 1;
+        my $post_url = $LJ::SITEROOT . "/update?usejournal=" . $cu->user
+            if $show_join_post_link && $remote->can_post_to( $cu );
+        my $posting_guidelines_entry = $cu->get_posting_guidelines_entry;
+        my $posting_guidelines_entry_url = $posting_guidelines_entry->url
+            if $posting_guidelines_entry;
+
         $ret .= "<?h1 $ML{'.success'} h1?><?p " . BML::ml('.label.membernow6',
                                                           { 'commname' => 
LJ::ljuser($cu) }) . " p?>";
+
+        if ( $post_url || $posting_guidelines_entry_url ) {
+            $ret .= "<ul>";
+            $ret .= "<li><a 
href='$post_url'>$ML{'.success.posttocommunity'}</a></li>"
+                if $post_url;
+            $ret .= "<li><a 
href='$posting_guidelines_entry_url'>$ML{'.success.readcommunitypostingguidelines'}</a></li>"
+                if $posting_guidelines_entry_url;
+            $ret .= "</ul>";
+        }
+
     } else {
         my $commuser = $cu->{user};
         my $cancel_text = $ML{'.btn.cancel'};
diff -r 43de6d4f95fb -r d6762606a18d htdocs/community/join.bml.text
--- a/htdocs/community/join.bml.text    Wed Oct 21 17:15:15 2009 +0000
+++ b/htdocs/community/join.bml.text    Wed Oct 21 17:24:56 2009 +0000
@@ -83,6 +83,10 @@
 
 .success=Success
 
+.success.posttocommunity=Post to this community
+
+.success.readcommunitypostingguidelines=Read this community's posting 
guidelines
+
 .title=Join Community
 
 .toomanyfriends=Adding [[community]] as a friend would exceed the maximum 
number of friends your account is allowed. You have however now joined this 
community.
diff -r 43de6d4f95fb -r d6762606a18d htdocs/community/settings.bml
--- a/htdocs/community/settings.bml     Wed Oct 21 17:15:15 2009 +0000
+++ b/htdocs/community/settings.bml     Wed Oct 21 17:24:56 2009 +0000
@@ -95,7 +95,11 @@ body<=
         if ( $mode eq 'create' && !%errors && $cu->is_community ) {
             $errors{'username'} = $ML{'.error.alreadycomm'};
         }
-        
+
+        # check the posting guidelines entry is valid
+        $errors{'postingguidelinesentry'} = 
$ML{'.error.postingguidelinesentryinvalid'}
+            unless $cu->posting_guidelines_entry( 
$POST{'postingguidelinesentry'} );
+
         # if we found errors, we'll redisplay the form below.  otherwise,
         # proceed.
         unless (%errors) {
@@ -145,9 +149,12 @@ body<=
             LJ::run_hook("change_journal_type", $cu);
 
             my $moderated = $POST{moderated} ? 1 : 0;
+            my $hidejoinpostlink = $POST{showjoinpostlink} ? 0 : 1;
 
             LJ::set_userprop($cu, 'nonmember_posting', $nonmember_posting);
             LJ::set_userprop($cu, 'moderated', $moderated);
+            $cu->hide_join_post_link( $hidejoinpostlink );
+            $cu->posting_guidelines_entry( $POST{'postingguidelinesentry'} );
 
             if ( LJ::is_enabled( 'adult_content' ) ) {
                 my $adult_content = $POST{'adult_content'};
@@ -192,6 +199,8 @@ body<=
                 'postlevel'=>$POST{'postlevel'} || 'members',
                 'nonmember_posting'=>$POST{'nonmember_posting'} || 0,
                 'moderated'=>$POST{'moderated'} || 0,
+                'hide_join_post_link'=>$POST{'showjoinpostlink'} ? 0 : 1,
+                'posting_guidelines_entry'=>$POST{'postingguidelinesentry'} || 
'',                
                 );
 
     if ($mode eq 'modify') {
@@ -199,7 +208,8 @@ body<=
             # old GET arg
             return 
BML::redirect("$LJ::SITEROOT/community/settings?authas=$GET{comm}");
         }
-        $cname = LJ::canonical_username($GET{'authas'});
+        my $authas_name = $POST{'cuser'} ? $POST{'cuser'} : $GET{'authas'};
+        $cname = LJ::canonical_username($authas_name);
         $c = LJ::load_user($cname);
         unless ($c) {
             # if no community was specified, redirect to manage
@@ -209,13 +219,21 @@ body<=
         unless ( $c->is_community ) {
             $ret .= "<?h1 $ML{'Error'} h1?><?p $ML{'.error.notcomm'} p?>";
             return $ret;
-        } 
-        my $dbr = LJ::get_db_reader();
-        ($info{'membership'},$info{'postlevel'}) = 
-            $dbr->selectrow_array("SELECT membership, postlevel FROM community 
WHERE userid=$c->{'userid'}");
-        LJ::load_user_props($c, "nonmember_posting", "moderated");
-        $info{'nonmember_posting'} = $c->{'nonmember_posting'} ? 1 : 0;
-        $info{'moderated'} = $c->{'moderated'} ? 1 : 0;
+        }
+
+        # get props unless we're reloading the form because of an error
+        unless ( LJ::did_post() ) {
+            my $dbr = LJ::get_db_reader();
+            ($info{'membership'},$info{'postlevel'}) = 
+                $dbr->selectrow_array("SELECT membership, postlevel FROM 
community WHERE userid=$c->{'userid'}");
+            LJ::load_user_props($c, "nonmember_posting", "moderated", 
"hide_join_post_link", "posting_guidelines_entry");
+            $info{'nonmember_posting'} = $c->{'nonmember_posting'} ? 1 : 0;
+            $info{'moderated'} = $c->{'moderated'} ? 1 : 0;
+            $info{'hide_join_post_link'} = $c->{'hide_join_post_link'} ? 1 : 0;
+            my $e = $c->get_posting_guidelines_entry;
+            $info{'posting_guidelines_entry'} = $e->url
+                if $e;
+        }
     }
 
     $ret .= "<form method='post' action='settings?mode=$mode'>";
@@ -232,11 +250,11 @@ body<=
           $ret .= "<?inerr $errors{'username'} inerr?><br />";
           $ret .= "$ML{'.label.password'}<br /><input name='cpassword' 
type='password' /><br />";
           $ret .= "<?inerr $errors{'password'} inerr?></td></tr></table> 
standout?>";
-      } else {
-          LJ::set_active_crumb('commsettings');
-            $ret .= LJ::html_hidden('cuser', $cname);
-            $ret .= LJ::maintainer_linkbar($c, "settings");
-        }
+    } else {
+        LJ::set_active_crumb('commsettings');
+          $ret .= LJ::html_hidden('cuser', $cname);
+          $ret .= LJ::maintainer_linkbar($c, "settings");
+    }
 
     $ret .= "<div id='left-column'>";
 
@@ -326,6 +344,25 @@ body<=
 
     $ret .= "</div></fieldset>";
 
+    $ret .= "<fieldset id='success-page-display'>";
+    $ret .= "<legend>$ML{'.label.successpagedisplay'}</legend><?p 
$ML{'.label.showwhatlinks'} p?>";
+
+    $ret .= "<p class='input-wrapper'>";
+    $ret .= LJ::html_check( {
+                id => 'showjoinpostlink', name => 'showjoinpostlink',
+                selected => $info{'hide_join_post_link'} ? 0 : 1
+            } );
+    $ret .= " <label 
for='showjoinpostlink'>$ML{'.label.showjoinpostlink'}</label></p>";
+
+    $ret .= "<p class='input-wrapper'>";
+    $ret .= " <label 
for='postingguidelinesentry'>$ML{'.label.postingguidelinesentry'}</label> ";
+    $ret .= LJ::html_text( {
+                id => 'postingguidelinesentry', name => 
'postingguidelinesentry', value => $info{'posting_guidelines_entry'}
+            });
+    $ret .= "<br /><?inerr $errors{'postingguidelinesentry'} inerr?></p>";
+
+    $ret .= "</fieldset>";
+
     $ret .= "</div>";
 
     $ret .= "<div style='clear: left; max-width: 695px;'><?standout <input 
type='submit' value='" .
diff -r 43de6d4f95fb -r d6762606a18d htdocs/community/settings.bml.text
--- a/htdocs/community/settings.bml.text        Wed Oct 21 17:15:15 2009 +0000
+++ b/htdocs/community/settings.bml.text        Wed Oct 21 17:24:56 2009 +0000
@@ -17,6 +17,8 @@
 .error.notcomm=Not a community account.
 
 .error.notfound=Community account not found.
+
+.error.postingguidelinesentryinvalid=Invalid Dreamwidth entry ID or URL 
entered.
 
 .error.samenames=Maintainer account and community account cannot be the same.
 
@@ -86,7 +88,15 @@
 
 .label.postingaccessselect=<b>Select Members</b><br />Members can post only if 
a maintainer gives them access.
 
+.label.postingguidelinesentry=URL or ID of your community's posting guidelines 
entry (leave blank if you don't want to link to an entry):
+
 .label.rellinks=Relevant links:
+
+.label.showjoinpostlink=Post to community
+
+.label.showwhatlinks=What links should be displayed to users when they join 
your community?
+
+.label.successpagedisplay=Join Links
 
 .label.username=Username:
 
diff -r 43de6d4f95fb -r d6762606a18d htdocs/manage/circle/add.bml
--- a/htdocs/manage/circle/add.bml      Wed Oct 21 17:15:15 2009 +0000
+++ b/htdocs/manage/circle/add.bml      Wed Oct 21 17:24:56 2009 +0000
@@ -103,11 +103,25 @@
 
         $title = $ML{'.add.title'};
         $body .= "<?h1 $ML{'.add.header'} h1?>";
+        my $posting_guidelines_entry_url;
+        my $post_url;
+        if ( $u->is_community ) {
+            my $posting_guidelines_entry = $u->get_posting_guidelines_entry;
+            $posting_guidelines_entry_url = $posting_guidelines_entry->url
+                if $posting_guidelines_entry;
+            my $show_join_post_link = $u->hide_join_post_link ? 0 : 1;
+            $post_url = $LJ::SITEROOT . "/update?usejournal=" . $u->user
+                if $show_join_post_link && $remote->can_post_to( $u );
+        }
 
         $body .= "<?p " . BML::ml('.add.text2', { 'ljuser' => LJ::ljuser($u) 
}) . " p?>";
         $body .= "<ul>";
         $body .= "<li><a 
href='$LJ::SITEROOT/inbox/compose?user=$user'>$ML{'.add.next.message'}</a></li>"
             if $u->is_personal && $u->can_receive_message( $remote );
+        $body .= "<li><a 
href='$posting_guidelines_entry_url'>$ML{'.add.next.postingguidelines'}</a></li>"
+            if $posting_guidelines_entry_url;
+        $body .= "<li><a 
href='$post_url'>$ML{'.add.next.posttocommunity'}</a></li>"
+            if $post_url;
         $body .= "<li><a href='" . $remote->journal_base . 
"/read'>$ML{'.add.next.friends'}</a></li>";
         $body .= "<li><a 
href='$LJ::SITEROOT/manage/circle/edit'>$ML{'.add.next.modify'}</a></ul>";
         return;
diff -r 43de6d4f95fb -r d6762606a18d htdocs/manage/circle/add.bml.text
--- a/htdocs/manage/circle/add.bml.text Wed Oct 21 17:15:15 2009 +0000
+++ b/htdocs/manage/circle/add.bml.text Wed Oct 21 17:24:56 2009 +0000
@@ -7,6 +7,10 @@
 .add.next.message=Send this user a message
 
 .add.next.modify=Modify your circle
+
+.add.next.postingguidelines=Read this community's posting guidelines
+
+.add.next.posttocommunity=Post to this community
 
 .add.text2=[[ljuser]]'s status in your circle has been updated.
 
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to