Have the option to have a different footer when comments are disabled 
on the Dreamwidth entry.

        Patch by allen. 

diffs (244 lines):

diff -r 7ac5693a7262 -r eec1fff2e035 bin/upgrading/en.dat
--- a/bin/upgrading/en.dat      Thu Jun 24 17:19:52 2010 +0800
+++ b/bin/upgrading/en.dat      Thu Jun 24 22:32:28 2010 +0800
@@ -2902,6 +2902,8 @@ setting.xpost.option.disablecomments=Dis
 
 setting.xpost.option.footer=Text of the footer to add on other sites. If you 
leave it blank, the system default footer will display.
 
+setting.xpost.option.footer.nocomments=Text of the footer when local comments 
are disabled.  Uses the main custom footer if blank, or the system default if 
both are blank.
+
 setting.xpost.option.footer.vars=The following variables may be used:
 setting.xpost.option.footer.vars.url=link to the original post
 setting.xpost.option.footer.vars.reply_url=link to the reply form on the 
original post
diff -r 7ac5693a7262 -r eec1fff2e035 bin/upgrading/proplists.dat
--- a/bin/upgrading/proplists.dat       Thu Jun 24 17:19:52 2010 +0800
+++ b/bin/upgrading/proplists.dat       Thu Jun 24 22:32:28 2010 +0800
@@ -125,6 +125,14 @@ userproplist.crosspost_footer_text:
   indexed: 0
   multihomed: 0
   prettyname: Custom footer for crossposted entries
+
+userproplist.crosspost_footer_nocomments:
+  cldversion: 4
+  datatype: blobchar
+  des: Custom footer for crossposted entries with comments disabled
+  indexed: 0
+  multihomed: 0
+  prettyname: Custom footer for crossposted entries with comments disabled
 
 userproplist.delete_reason:
   cldversion: 4
diff -r 7ac5693a7262 -r eec1fff2e035 cgi-bin/DW/External/XPostProtocol.pm
--- a/cgi-bin/DW/External/XPostProtocol.pm      Thu Jun 24 17:19:52 2010 +0800
+++ b/cgi-bin/DW/External/XPostProtocol.pm      Thu Jun 24 22:32:28 2010 +0800
@@ -85,6 +85,41 @@ sub scrub_polls {
     return $entry_text;
 }
 
+# creates the footer
+sub create_footer {
+    my ( $self, $entry, $extacct, $local_nocomments, 
$disabling_remote_comments ) = @_;
+    
+    # are we adding a footer?
+    my $xpostfootprop = $extacct->owner->prop( 'crosspost_footer_append' ) ? 
$extacct->owner->prop( 'crosspost_footer_append' ) : "D"; # assume old behavior 
if undefined
+    
+    if ( ( $xpostfootprop eq "A" ) || ( ( $xpostfootprop eq "D" ) && 
$disabling_remote_comments ) ) {
+        # get the default custom footer text
+        my $custom_footer_template;
+        if ( $local_nocomments ) {
+            $custom_footer_template = $extacct->owner->prop( 
'crosspost_footer_nocomments' ) || $extacct->owner->prop( 
'crosspost_footer_text' );
+        } else {
+            $custom_footer_template = $extacct->owner->prop( 
'crosspost_footer_text' );
+        }
+
+        if ( $custom_footer_template ) {
+            return $self->create_footer_text($entry, $custom_footer_template);
+        } else {
+            # did we disable comments on the local entry? tweak language 
string to match
+            my $footer_text_redirect_key = $local_nocomments ? 
'xpost.redirect' : 'xpost.redirect.comment';
+            
+            return "\n\n" . LJ::Lang::ml( $footer_text_redirect_key, { 
postlink => $entry->url } );
+        }
+    } elsif ( ( $xpostfootprop eq "N" ) || ( ( $xpostfootprop eq "D" ) && ( ! 
$disabling_remote_comments ) )  ) {
+        return "";
+    } else {
+        # fallthrough. shouldn't get here, but in case we do for
+        # some crazy reason, let's assume the old behavior.
+        my $footer_text_redirect_key = $local_nocomments ? 'xpost.redirect' : 
'xpost.redirect.comment';
+            
+        return "\n\n" . LJ::Lang::ml( $footer_text_redirect_key, { postlink => 
$entry->url } );
+    }
+}
+
 # creates the footer text
 sub create_footer_text {
     my ($self, $entry, $footer_text) = @_;
diff -r 7ac5693a7262 -r eec1fff2e035 
cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm
--- a/cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm     Thu Jun 24 17:19:52 
2010 +0800
+++ b/cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm     Thu Jun 24 22:32:28 
2010 +0800
@@ -190,58 +190,16 @@ sub crosspost {
         # FIXME: temporary hack to limit crossposts to one level, avoiding an 
infinite loop
         $req->{xpost} = 0;
 
-        # did we disable comments on the local entry? tweak language string to 
match
-        my $footer_text_redirect_key = $req->{props}->{opt_nocomments} ? 
'xpost.redirect' : 'xpost.redirect.comment';
+        # are we disabling comments on the remote entry?
+        my $disabling_comments = $extacct->owner->prop( 
'opt_xpost_disable_comments' ) ? 1 : 0;
 
-        # are we disabling comments on the remote entry?
-        my $disabling_comments  = $extacct->owner->prop( 
'opt_xpost_disable_comments' ) ? 1 : 0;
+        # append the footer, if any
+        my $footer_text = $self->create_footer( $entry, $extacct, 
$req->{props}->{opt_nocomments}, $disabling_comments );
+
         # set the value for comments on the crossposted entry
         $req->{props}->{opt_nocomments} = $disabling_comments || 
$req->{props}->{opt_nocomments} || 0;
-
-        # are we adding a footer?
-        my ( $adding_footer, $footer_text );
-        $footer_text = $extacct->owner->prop( 'crosspost_footer_text' );
-        my $xpostfootprop = $extacct->owner->prop( 'crosspost_footer_append' ) 
? $extacct->owner->prop( 'crosspost_footer_append' ) : "D"; # assume old 
behavior if undefined
-
-        if ( $xpostfootprop eq "A" ) {
-            # we are always adding a footer, but we need to
-            # make some adjustments based on whether it's a custom
-            # footer, whether comments are disabled, etc
-
-            $adding_footer = 1;
-            if ( $footer_text ) {
-                $footer_text = $self->create_footer_text($entry, $footer_text);
-            } else {
-                $footer_text = "\n\n" . LJ::Lang::ml( 
$footer_text_redirect_key, { postlink => $entry->url } );
-            }
-
-        } elsif ( $xpostfootprop eq "D" ) {
-
-            $adding_footer = 1 if $disabling_comments;
-            # we are only adding a footer if comments are disabled
-            # (and they are)
-
-            if ( $footer_text ) {
-                $footer_text = $self->create_footer_text($entry, $footer_text);
-            } else {
-                $footer_text = "\n\n" . LJ::Lang::ml( 
$footer_text_redirect_key, { postlink => $entry->url } );
-            }
-        } elsif ( $xpostfootprop eq "N" ) {
-            # we aren't adding a footer
-
-            $adding_footer = 0;
-        } else {
-            # fallthrough. shouldn't get here, but in case we do for
-            # some crazy reason, let's assume the old behavior.
-            $adding_footer = 1;
-            $footer_text = "\n\n" . LJ::Lang::ml( $footer_text_redirect_key, { 
postlink => $entry->url } );
-        }
-
-        # now that we have all of that settled, let's assemble it
-        # together into the post-in-progress:
-
-        $req->{event} = $req->{event} . $footer_text if $adding_footer;
-
+        
+        $req->{event} = $req->{event} . $footer_text if $footer_text;
     }
 
     # get the correct itemid for edit
diff -r 7ac5693a7262 -r eec1fff2e035 cgi-bin/DW/Setting/XPostAccounts.pm
--- a/cgi-bin/DW/Setting/XPostAccounts.pm       Thu Jun 24 17:19:52 2010 +0800
+++ b/cgi-bin/DW/Setting/XPostAccounts.pm       Thu Jun 24 22:32:28 2010 +0800
@@ -5,7 +5,7 @@ use warnings;
 
 use Digest::MD5 qw(md5_hex);
 
-sub tags { qw(xpost_option_server xpost_option_username xpost_option_password 
xpost_option_xpostbydefault xpost_option_recordlink crosspost_footer_append 
crosspost_footer_text) }
+sub tags { qw(xpost_option_server xpost_option_username xpost_option_password 
xpost_option_xpostbydefault xpost_option_recordlink crosspost_footer_append 
crosspost_footer_text crosspost_footer_nocomments) }
 
 my $footer_length = 1024;
 
@@ -152,21 +152,55 @@ sub option {
 
     $ret .= "<div id='preview_section' style='display: none;'>" . 
$class->ml('setting.xpost.preview') . "\n";
 
+    $ret .= "<div id='footer_preview' 
class='xpost_footer_preview'></div></div>\n";
+
+    # define custom footer
+    $ret .= "<tr><td>&nbsp</td><td colspan='2'><label 
for='${key}crosspost_footer_nocomments'>" . $class->ml( 
'setting.xpost.option.footer.nocomments' ) . "</label><br/>";
+
+    my $footer_nocomments = $u->prop('crosspost_footer_nocomments');
+
+    $ret .= LJ::html_textarea({
+        name      => "${key}crosspost_footer_nocomments",
+        id        => "${key}crosspost_footer_nocomments",
+        rows      => 3,
+        cols      => 80,
+        maxlength => "512",
+        onkeyup   => "javascript:updatePreviewNocomments()",
+        value     => $footer_nocomments
+    }) . "<br/><br/>";
+
+    $ret .= "<div id='preview_nocomments' style='display: none;'>" . 
$class->ml('setting.xpost.preview') . "\n";
+    $ret .= "<div id='footer_nocomments_preview' 
class='xpost_footer_preview'></div></div>\n";
+
     my $baseurl = $LJ::SITEROOT;
     my $alttext = 
$class->ml('setting.xpost.option.footer.vars.comment_image.alt');
     my $default_comment = $class->ml('xpost.redirect.comment', { postlink => 
"%%url%%" });
-    
+    my $default_nocomments = $class->ml('xpost.redirect', { postlink => 
"%%url%%" });
+
     # the javascript.  we have to do some special magic to get the lengths
     # to line up for differing newline characters and for unicode characters
     # outside the basic multilingual plane.
     $ret .= qq [
-      <div id='footer_preview' class='xpost_footer_preview'></div>
-      </div>
       <script type="text/javascript">
         function updatePreview() {
-          var previewString = \$('${key}crosspost_footer_text').value;
+          updatePreviewField('${key}crosspost_footer_text', 'footer_preview', 
'$default_comment');
+          if (! \$('${key}crosspost_footer_nocomments').value ) {
+            updatePreviewNocomments();
+          }
+        }
+
+        function updatePreviewNocomments() {
+          var defaultValue = \$('${key}crosspost_footer_text').value;
+          if (! defaultValue) {
+            defaultValue = '$default_nocomments';
+          }
+          updatePreviewField('${key}crosspost_footer_nocomments', 
'footer_nocomments_preview', defaultValue);
+        }
+
+        function updatePreviewField(sourceFieldId, previewFieldId, 
defaultValue) {
+          var previewString = \$(sourceFieldId).value;
           if (! previewString) {
-            previewString = '$default_comment';
+            previewString = defaultValue;
           }
           previewString = previewString.replace(/\\r/g, "");
           previewString = previewString.replace(/\\n/g, "\\r\\n");
@@ -175,7 +209,7 @@ sub option {
           previewString = previewString.replace(/%%reply_url%%/gi, 
'$baseurl/12345.html?mode=reply');
           previewString = previewString.replace(/%%comment_url%%/gi, 
'$baseurl/12345.html#comments');
           previewString = previewString.replace(/%%comment_image%%/gi, '<img 
src="$baseurl/tools/commentcount?samplecount=23" width="30" height="12" 
alt="$alttext" style="vertical-align: middle;"/>');
-          \$('footer_preview').innerHTML = previewString;
+          \$(previewFieldId).innerHTML = previewString;
         }
 
         function substrUtf(previewString, count) {
@@ -211,7 +245,9 @@ sub option {
         }
 
         \$('preview_section').style.display = 'block';
+        \$('preview_nocomments').style.display = 'block';
         updatePreview();
+        updatePreviewNocomments();
       </script>
     ];
     $ret .= "<p style='font-size: smaller;'>" . 
$class->ml('setting.xpost.option.footer.vars') . "<br/>";
@@ -254,6 +290,7 @@ sub save {
 
     # change footer text
     $u->set_prop( crosspost_footer_text => LJ::text_trim( $class->get_arg( 
$args, "crosspost_footer_text" ), 0, $footer_length ) );
+    $u->set_prop( crosspost_footer_nocomments => LJ::text_trim( 
$class->get_arg( $args, "crosspost_footer_nocomments" ), 0, $footer_length ) );
 
     # change footer display
     $u->set_prop( crosspost_footer_append => $class->get_arg( $args, 
"crosspost_footer_append" ) );
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to