[dw-free] Add comment-count image to crossposted entries
[commit: http://hg.dwscoalition.org/dw-free/rev/b3557872aaba]
http://bugs.dwscoalition.org/show_bug.cgi?id=1035
Add comment-count image to crossposted entries, add preview for footer text.
Patch by
allen.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1035
Add comment-count image to crossposted entries, add preview for footer text.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/en.dat
- cgi-bin/DW/External/XPostProtocol.pm
- cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm
- cgi-bin/DW/Setting/XPostAccounts.pm
- cgi-bin/LJ/Entry.pm
- htdocs/stc/settings.css
-------------------------------------------------------------------------------- diff -r 47415b27b7d7 -r b3557872aaba bin/upgrading/en.dat --- a/bin/upgrading/en.dat Wed Aug 05 04:57:16 2009 +0000 +++ b/bin/upgrading/en.dat Wed Aug 05 06:44:12 2009 +0000 @@ -2893,8 +2893,16 @@ setting.viewingadultcontent.option.selec setting.viewingadultcontent.reason=(To change this option, you must <a [[aopts]]>set your birthdate</a> first.) +setting.xpost.accounts=Accounts + setting.xpost.btn.add=Add New Account +setting.xpost.comments=Comments + +setting.xpost.footer=Footer + +setting.xpost.footer.default.label=System default footer: + setting.xpost.label=Crossposting setting.xpost.message.usage=Current accounts configured: <b>[[current]] of [[max]]</b> @@ -2911,7 +2919,14 @@ setting.xpost.option.delete=Delete setting.xpost.option.disablecomments=Disable comments on crossposts made to other sites -setting.xpost.option.footer=Text of the footer to add on other sites. If you leave it blank, the default will display. To include a link to the post locally, use "%%url%%". +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.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 +setting.xpost.option.footer.vars.comment_url=link to view the comments on the original post +setting.xpost.option.footer.vars.comment_image=image tag that dynamically displays the comment count on the original post +setting.xpost.option.footer.vars.comment_image.alttext=comment count unavailable setting.xpost.option.footer.when=Add the footer to the post on the other site: @@ -2930,6 +2945,10 @@ setting.xpost.option.xpostbydefault=Cros setting.xpost.option.xpostbydefault=Crosspost by Default setting.xpost.noaccounts=No accounts configured + +setting.xpost.preview=Preview + +setting.xpost.settings=Crosspost Settings setting.xpostcomments.about=When Crossposting to LJ-based accounts, disable comments on the other posts. diff -r 47415b27b7d7 -r b3557872aaba cgi-bin/DW/External/XPostProtocol.pm --- a/cgi-bin/DW/External/XPostProtocol.pm Wed Aug 05 04:57:16 2009 +0000 +++ b/cgi-bin/DW/External/XPostProtocol.pm Wed Aug 05 06:44:12 2009 +0000 @@ -85,6 +85,26 @@ sub scrub_polls { return $entry_text; } +# creates the footer text +sub create_footer_text { + my ($self, $entry, $footer_text) = @_; + + my $url = $entry->url; + my $comment_url = $entry->url( anchor => "comments" ); + my $reply_url = $entry->reply_url; + my $comment_image = $entry->comment_imgtag; + + # note: if you change any of these, be sure to change the preview + # javascript in DW/Setting/XPostAccounts.pm, too. + $footer_text =~ s/%%url%%/$url/gi; + $footer_text =~ s/%%reply_url%%/$reply_url/gi; + $footer_text =~ s/%%comment_url%%/$comment_url/gi; + $footer_text =~ s/%%comment_image%%/$comment_image/gi; + $footer_text = "\n\n" . $footer_text; + + return $footer_text; +} + # validates that the given server is running the appropriate protocol. # must be run in an eval block. returns 1 on success, 0 on failure sub validate_server { 1 } diff -r 47415b27b7d7 -r b3557872aaba cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm --- a/cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm Wed Aug 05 04:57:16 2009 +0000 +++ b/cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm Wed Aug 05 06:44:12 2009 +0000 @@ -167,9 +167,7 @@ sub crosspost { $adding_footer = 1; if ( $footer_text ) { - my $url = $entry->url; - $footer_text =~ s/%%url%%/$url/gi; - $footer_text = "\n\n" . $footer_text; + $footer_text = $self->create_footer_text($entry, $footer_text); } else { # FIXME: this should check if comments are disabled # on the local site and do the right thing, but @@ -185,9 +183,7 @@ sub crosspost { # (and they are) if ( $footer_text ) { - my $url = $entry->url; - $footer_text =~ s/%%url%%/$url/gi; - $footer_text = "\n\n" . $footer_text; + $footer_text = $self->create_footer_text($entry, $footer_text); } else { # FIXME: this should check if comments are disabled # on the local site and do the right thing, but diff -r 47415b27b7d7 -r b3557872aaba cgi-bin/DW/Setting/XPostAccounts.pm --- a/cgi-bin/DW/Setting/XPostAccounts.pm Wed Aug 05 04:57:16 2009 +0000 +++ b/cgi-bin/DW/Setting/XPostAccounts.pm Wed Aug 05 06:44:12 2009 +0000 @@ -57,6 +57,7 @@ sub option { # be sure to add your style info in htdocs/stc/settings.css or this won't # look very good. + $ret .= "<h2>" . $class->ml('setting.xpost.accounts') ."</h2><br/>"; $ret .= "<table class='setting_table'>\n"; if (scalar @accounts) { $ret .= "<tr>\n"; @@ -102,29 +103,20 @@ sub option { $ret .= "<div class='xpost_add'><a href='$LJ::SITEROOT/manage/externalaccount'>" . $class->ml('setting.xpost.btn.add') . "</a></div>\n"; } + $ret .= "<h2>" . $class->ml('setting.xpost.settings') . "</h2>"; # disable comments on crosspost - $ret .= "<br /><p><label for='${key}xpostdisablecomments'>" . $class->ml('setting.xpost.option.disablecomments') . "</label>"; + $ret .= "<table><tr>"; + $ret .= "<td><b>" . $class->ml('setting.xpost.comments') . "</b></td><td><label for='${key}xpostdisablecomments'>" . $class->ml('setting.xpost.option.disablecomments') . "</label></td><td>"; $ret .= LJ::html_check({ name => "${key}xpostdisablecomments", value => 1, id => "${key}xpostdisablecomments", selected => $u->prop('opt_xpost_disable_comments') }) . "</p>"; - - # define custom footer - $ret .= "<p><label for='${key}crosspost_footer_text'>" . $class->ml( 'setting.xpost.option.footer' ) . "</label>"; - my $footer_text = $u->prop('crosspost_footer_text'); - - $ret .= LJ::html_text({ - name => "${key}crosspost_footer_text", - id => "${key}crosspost_footer_text", - size => "70", - maxlength => "255", - value => $footer_text - }) . "</p>"; - + $ret .= "</td></tr>"; + # When should the footer be displayed? - $ret .= "<p><label for='${key}crosspost_footer_append'>" . $class->ml( 'setting.xpost.option.footer.when' ) . "</label> "; + $ret .= "<tr><td><b>" . $class->ml('setting.xpost.footer') . "</b></td><td><label for='${key}crosspost_footer_append'>" . $class->ml( 'setting.xpost.option.footer.when' ) . "</label></td><td>"; my $append_when = $u->prop('crosspost_footer_append'); $ret .= LJ::html_select({ @@ -136,7 +128,52 @@ sub option { 'D' => $class->ml( 'setting.xpost.option.footer.when.disabled' ), 'N' => $class->ml( 'setting.xpost.option.footer.when.never' ) ); + $ret .= "</td></tr>"; + # define custom footer + $ret .= "<tr><td> </td><td colspan='2'><label for='${key}crosspost_footer_text'>" . $class->ml( 'setting.xpost.option.footer' ) . "</label><br/>"; + + my $footer_text = $u->prop('crosspost_footer_text'); + + $ret .= LJ::html_textarea({ + name => "${key}crosspost_footer_text", + id => "${key}crosspost_footer_text", + rows => 3, + cols => 80, + maxlength => "512", + onkeyup => "javascript:updatePreview()", + value => $footer_text + }) . "<br/><br/>"; + + $ret .= "" . $class->ml('setting.xpost.preview') . "\n"; + + my $baseurl = $LJ::SITEROOT; + my $alttext = $class->ml('setting.xpost.option.footer.vars.comment_image.alttext'); + my $default_comment = $class->ml('xpost.redirect.comment', { postlink => "%%url%%" }); + + $ret .= qq [ + <div id='footer_preview' class='xpost_footer_preview'></div> + <script type="text/javascript"> + function updatePreview() { + var previewString = \$('${key}crosspost_footer_text').value; + if (! previewString) { + previewString = '$default_comment'; + } + previewString = previewString.replace(/%%url%%/, '$baseurl/12345.html'); + previewString = previewString.replace(/%%reply_url%%/, '$baseurl/12345.html?mode=reply'); + previewString = previewString.replace(/%%comment_url%%/, '$baseurl/12345.html#comments'); + previewString = previewString.replace(/%%comment_image%%/, '<img src="$baseurl/tools/commentcount?samplecount=23" alt="$alttext" style="vertical-align: middle;"/>'); + \$('footer_preview').innerHTML = previewString; + } + updatePreview(); + </script> + ]; + $ret .= "<p style='font-size: smaller;'>" . $class->ml('setting.xpost.option.footer.vars') . "<br/>"; + foreach my $var qw (url reply_url comment_url comment_image) { + $ret .= "<b>%%$var%%</b>: " . $class->ml("setting.xpost.option.footer.vars.$var") . "<br/>\n"; + } + $ret .= "<br/>" . $class->ml("setting.xpost.footer.default.label") . "<br/>" . LJ::ehtml($default_comment) . "\n"; + $ret .= "</td></tr></table>\n"; return $ret; } diff -r 47415b27b7d7 -r b3557872aaba cgi-bin/LJ/Entry.pm --- a/cgi-bin/LJ/Entry.pm Wed Aug 05 04:57:16 2009 +0000 +++ b/cgi-bin/LJ/Entry.pm Wed Aug 05 06:44:12 2009 +0000 @@ -223,6 +223,24 @@ sub url { } $url .= "#$anchor" if $anchor; return $url; +} + +# returns a url that will display the number of comments on the entry +# as an image +sub comment_image_url { + my $self = shift; + my $u = $self->{u}; + + return "$LJ::SITEROOT/tools/commentcount?uid=" . $self->journalid . "&ditemid=" . $self->ditemid; +} + +# returns a pre-generated comment img tag using the comment_image_url +sub comment_imgtag { + my $self = shift; + + my $alttext = LJ::Lang::ml('setting.xpost.option.footer.vars.comment_image.alttext'); + + return '<img src="' . $self->comment_image_url . '" alt="' . $alttext . '" style="vertical-align: middle;"/>'; } sub anum { diff -r 47415b27b7d7 -r b3557872aaba htdocs/stc/settings.css --- a/htdocs/stc/settings.css Wed Aug 05 04:57:16 2009 +0000 +++ b/htdocs/stc/settings.css Wed Aug 05 06:44:12 2009 +0000 @@ -169,3 +169,10 @@ .xpost_add { text-align: center; } + +.xpost_footer_preview { + border: 1px solid #000000; + width: 100%; + background: #EEEEEE; + padding: 10px 5px 10px 5px; +} --------------------------------------------------------------------------------
no subject