[dw-free] mimic polls on entry preview
[commit: http://hg.dwscoalition.org/dw-free/rev/8d5b8330fdd3]
http://bugs.dwscoalition.org/show_bug.cgi?id=3309
Show a proper preview of polls when we preview an entry. Also, if we don't
have the privs to create the poll, show a warning in lieu of the poll
preview.
Patch by
fu.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=3309
Show a proper preview of polls when we preview an entry. Also, if we don't
have the privs to create the poll, show a warning in lieu of the poll
preview.
Patch by
Files modified:
- cgi-bin/DW/Controller/Entry.pm
- htdocs/preview/entry.bml
--------------------------------------------------------------------------------
diff -r 36bbbe330d12 -r 8d5b8330fdd3 cgi-bin/DW/Controller/Entry.pm
--- a/cgi-bin/DW/Controller/Entry.pm Thu Jan 19 16:47:36 2012 +0800
+++ b/cgi-bin/DW/Controller/Entry.pm Thu Jan 19 17:18:41 2012 +0800
@@ -834,6 +834,23 @@
my ( $event, $subject ) = ( $form_req->{event}, $form_req->{subject} );
LJ::CleanHTML::clean_subject( \$subject );
+ # preview poll
+ if ( LJ::Poll->contains_new_poll( \$event ) ) {
+ my $error;
+ my @polls = LJ::Poll->new_from_html( \$event, \$error, {
+ 'journalid' => $u->userid,
+ 'posterid' => $up->userid,
+ });
+
+ my $can_create_poll = $up->can_create_polls || ( $u->is_community && $u->can_create_polls );
+ my $poll_preview = sub {
+ my $poll = shift @polls;
+ return '' unless $poll;
+ return $can_create_poll ? $poll->preview : qq{<div class="highlight-box">} . LJ::Lang::ml( '/poll/create.bml.error.accttype2' ) . qq{</div>};
+ };
+
+ $event =~ s/<poll-placeholder>/$poll_preview->()/eg;
+ }
# parse out embed tags from the RTE
$event = LJ::EmbedModule->transform_rte_post( $event );
diff -r 36bbbe330d12 -r 8d5b8330fdd3 htdocs/preview/entry.bml
--- a/htdocs/preview/entry.bml Thu Jan 19 16:47:36 2012 +0800
+++ b/htdocs/preview/entry.bml Thu Jan 19 17:18:41 2012 +0800
@@ -46,6 +46,24 @@
my ($event, $subject) = ($req{'event'}, $req{'subject'});
LJ::CleanHTML::clean_subject(\$subject);
+ # preview poll
+ if ( LJ::Poll->contains_new_poll( \$event ) ) {
+ my $error;
+ my @polls = LJ::Poll->new_from_html( \$event, \$error, {
+ 'journalid' => $u->userid,
+ 'posterid' => $up->userid,
+ });
+
+ my $can_create_poll = $up->can_create_polls || ( $u->is_community && $u->can_create_polls );
+ my $poll_preview = sub {
+ my $poll = shift @polls;
+ return '' unless $poll;
+ return $can_create_poll ? $poll->preview : qq{<div class="highlight-box">} . LJ::Lang::ml( '/poll/create.bml.error.accttype2' ) . qq{</div>};
+ };
+
+ $event =~ s/<poll-placeholder>/$poll_preview->()/eg;
+ }
+
# parse out embed tags from the RTE
$event = LJ::EmbedModule->transform_rte_post($event);
# do first expand_embedded pass with the preview flag to extract
--------------------------------------------------------------------------------

no subject