Changeset 2859
- Timestamp:
- 07/29/08 20:50:43 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/feature-revision-histories/lib/MT/CMS/Entry.pm
r2737 r2859 730 730 731 731 sub preview { 732 my $app = shift; 732 my $app = shift; 733 my $entry = _create_temp_entry($app); 734 735 return _build_entry_preview($app, $entry); 736 } 737 738 sub _create_temp_entry { 739 my $app = shift; 740 my $type = $app->param('_type') || 'entry'; 741 my $entry_class = $app->model($type); 742 my $blog_id = $app->param('blog_id'); 743 my $blog = $app->blog; 744 my $id = $app->param('id'); 745 my $entry; 746 my $user_id = $app->user->id; 747 748 if ($id) { 749 $entry = $entry_class->load( { id => $id, blog_id => $blog_id } ) 750 or return $app->errtrans( "Invalid request." ); 751 $user_id = $entry->author_id; 752 } 753 else { 754 $entry = $entry_class->new; 755 $entry->author_id($user_id); 756 $entry->id(-1); # fake out things like MT::Taggable::__load_tags 757 $entry->blog_id($blog_id); 758 } 759 760 my $names = $entry->column_names; 761 my %values = map { $_ => scalar $app->param($_) } @$names; 762 delete $values{'id'} unless $app->param('id'); 763 ## Strip linefeed characters. 764 for my $col (qw( text excerpt text_more keywords )) { 765 $values{$col} =~ tr/\r//d if $values{$col}; 766 } 767 $values{allow_comments} = 0 768 if !defined( $values{allow_comments} ) 769 || $app->param('allow_comments') eq ''; 770 $values{allow_pings} = 0 771 if !defined( $values{allow_pings} ) 772 || $app->param('allow_pings') eq ''; 773 $entry->set_values( \%values ); 774 775 return $entry; 776 } 777 778 sub _build_entry_preview { 779 my $app = shift; 780 my ($entry, %param) = @_; 733 781 my $q = $app->param; 734 782 my $type = $q->param('_type') || 'entry'; … … 737 785 my $blog = $app->blog; 738 786 my $id = $q->param('id'); 739 my $entry;740 787 my $user_id = $app->user->id; 741 742 if ($id) {743 $entry = $entry_class->load( { id => $id, blog_id => $blog_id } )744 or return $app->errtrans( "Invalid request." );745 $user_id = $entry->author_id;746 }747 else {748 $entry = $entry_class->new;749 $entry->author_id($user_id);750 $entry->id(-1); # fake out things like MT::Taggable::__load_tags751 $entry->blog_id($blog_id);752 }753 788 my $cat; 754 my $names = $entry->column_names;755 756 my %values = map { $_ => scalar $app->param($_) } @$names;757 delete $values{'id'} unless $q->param('id');758 ## Strip linefeed characters.759 for my $col (qw( text excerpt text_more keywords )) {760 $values{$col} =~ tr/\r//d if $values{$col};761 }762 $values{allow_comments} = 0763 if !defined( $values{allow_comments} )764 || $q->param('allow_comments') eq '';765 $values{allow_pings} = 0766 if !defined( $values{allow_pings} )767 || $q->param('allow_pings') eq '';768 $entry->set_values( \%values );769 770 789 my $cat_ids = $q->param('category_ids'); 771 790 if ($cat_ids) { … … 861 880 $ctx->var('preview_template', 1); 862 881 my $html = $tmpl->output; 863 my %param;864 882 unless ( defined($html) ) { 865 883 my $preview_error = $app->translate( "Publish error: [_1]", … … 964 982 || $col eq 'meta' 965 983 || $col eq 'comment_count' 966 || $col eq 'ping_count'; 984 || $col eq 'ping_count' 985 || $col eq 'current_revision'; 967 986 if ( $col eq 'basename' ) { 968 987 if ( ( !defined $q->param('basename') ) … … 1020 1039 $param{object_type} = $type; 1021 1040 $param{object_label} = $entry_class->class_label; 1041 1042 $param{diff_view} = $app->param('rev_numbers') || $app->param('collision'); 1043 $param{collision} = 1; 1044 if(my @rev_numbers = split /,/, $app->param('rev_numbers')) { 1045 $param{comparing_revisions} = 1; 1046 $param{rev_a} = $rev_numbers[0]; 1047 $param{rev_b} = $rev_numbers[1]; 1048 } 1049 1022 1050 if ($fullscreen) { 1023 1051 return $app->load_tmpl( 'preview_entry.tmpl', \%param ); … … 1264 1292 $app->_translate_naughty_words($obj); 1265 1293 1266 $obj->modified_by( $author->id ) unless $is_new;1267 1268 1294 $app->run_callbacks( 'cms_pre_save.' . $type, $app, $obj, $orig_obj ) 1269 1295 || return $app->error( … … 1273 1299 ) 1274 1300 ); 1301 1302 # Setting modified_by updates modified_on which we want to do before 1303 # a save but after pre_save callbacks fire. 1304 $obj->modified_by( $author->id ) unless $is_new; 1275 1305 1276 1306 $obj->save
