home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / FAQ / discus_admin_1357211388 / source / fcn-edit.pl < prev    next >
Text File  |  2009-11-06  |  6KB  |  167 lines

  1. # FILE: fcn-edit.pl
  2. # DESCRIPTION: Edit existing post
  3. #-------------------------------------------------------------------------------
  4. # DISCUS COPYRIGHT NOTICE
  5. #
  6. # Discus is copyright (c) 2002 by DiscusWare, LLC, all rights reserved.
  7. # The use of Discus is governed by the Discus License Agreement which is
  8. # available from the Discus WWW site at:
  9. #    http://www.discusware.com/discus/license
  10. #
  11. # Pursuant to the Discus License Agreement, this copyright notice may not be
  12. # removed or altered in any way.
  13. #-------------------------------------------------------------------------------
  14.  
  15. use strict;
  16. use vars qw($GLOBAL_OPTIONS $DCONF $PARAMS);
  17.  
  18. ###
  19. ### edit_post_form
  20. ###
  21. ### Presents a form to permit the editing of individual posts
  22. ###
  23.  
  24. sub edit_post_form {
  25.     my ($topic, $page, $post, $arg) = @_;
  26.     my $subst = {};
  27.     my $page_ref = defined $arg->{page_ref} ? $arg->{page_ref} : GetPage($topic, $page);
  28.     my @message = grep($_->{number} == $post, @{ $page_ref->{messages} });
  29.     dreq("webtags", "profane");
  30.     error_message(read_language()->{EDITING_POST_ERROR}, read_language()->{EDITING_POST_NO_EXIST}, 0, 1) if ref $message[0] ne "HASH";
  31.     $subst->{general}->{topic} = $topic;
  32.     $subst->{general}->{page} = $page;
  33.     $subst->{general}->{post} = $post;
  34.     $subst->{arg} = $arg;
  35.     $subst->{general}->{skip_headers} = 1;
  36.     $subst->{general}->{skip_nav_bar} = 1;
  37.     $subst->{general}->{skip_bottom} = 1;
  38.     $subst->{general}->{action} = defined $arg->{action} ? $arg->{action} : $PARAMS->{cgiurl};
  39.     $subst->{general}->{formaction} = defined $arg->{formaction} ? $arg->{formaction} : "editpost";
  40.     $subst->{head}->{param} = "Messages";
  41.     $subst->{head}->{topic_number} = $topic;
  42.     $subst->{messages} = \@message;
  43.     my @prop = map { name => _genkey($_), value => $message[0]->{$_} }, grep(/^property_/, keys(%{ $message[0] }));
  44.     $subst->{props} = \@prop;
  45.     if ($arg->{text}) {
  46.         $subst->{general}->{source} = $arg->{text};
  47.         my $message = profanity_filter($arg->{text}, {subst => $subst, alternate_handler => \&edit_profanity_error, error_report => 1});
  48.         my ($error, $text) = webtags($message, 1, 1, $arg->{is_moderator}, $arg->{is_superuser}, $topic);
  49.         $subst->{messages}->[0]->{text} = $text;
  50.         $subst->{general}->{error} = 1 if $error eq "!Error";
  51.     } else {
  52.         $subst->{general}->{source} = inverse_webtags($message[0]->{text}, $topic, undef);
  53.     }
  54.     return $subst if ($arg->{saver} && $arg->{makesubst} && ! $subst->{general}->{error});
  55.     if ($DCONF->{pro}) {
  56.         dreq("authwrap-PRO");
  57.         $subst->{messages} = auth_wrap_attachments($subst->{messages}, $topic);
  58.     }
  59.     return $subst if ($arg->{makesubst} && ! $subst->{general}->{error});
  60.     screen_out("editpost", $subst, $arg->{cookie_str});
  61. }
  62.  
  63. sub _genkey {
  64.     my ($in) = @_;
  65.     return $' if $in =~ /^property_/;
  66.     return $in;
  67. }
  68.  
  69. ###
  70. ### edit_profanity_error
  71. ###
  72. ### Alternate handler for profanity errors occurring when editing posts
  73. ###
  74.  
  75. sub edit_profanity_error {
  76.     my ($message, $argument, $words) = @_;
  77.     my $subst = $argument->{subst};
  78.     my $error_message = read_language()->{PROFANITY_DETECTED_MESSAGE};
  79.     my $l = join("<li>", sort keys(%{ $words })); $l = "<li>$l";
  80.     $error_message =~ s/\%wordlist/$l/g;
  81.     $subst->{messages}->[0]->{text} = $error_message;
  82.     $subst->{general}->{error} = 1;
  83.     screen_out("editpost", $subst, undef);
  84. }
  85.  
  86. ###
  87. ### save_edited_post
  88. ###
  89. ### Saves the text of an edited post and updates logs appropriately
  90. ###
  91.  
  92. sub save_edited_post {
  93.     my ($topic, $page, $post, $text, $arg) = @_;
  94.     my $a = $arg;
  95.     $a->{makesubst} = 1;
  96.     $a->{saver} = 1;
  97.     $a->{text} = $text;
  98.     if (($GLOBAL_OPTIONS->{admin_edit_note} && $arg->{is_superuser}) || (! $arg->{is_superuser} && $GLOBAL_OPTIONS->{mod_edit_note} && $arg->{is_moderator}) || ($GLOBAL_OPTIONS->{usr_edit_note} && ! $arg->{is_moderator})) {
  99.         my $l = read_language()->{EDITING_POST_NOTE};
  100.         $l =~ s/\%username/$arg->{username}/g;
  101.         my $x_str = defined read_language()->{EDITING_POST_DATE_FORMAT} ? read_language()->{EDITING_POST_DATE_FORMAT} : "dateonly";
  102.         $l =~ s/\%date/get_date_time($x_str)/ge;
  103.         $a->{text} .= "\n\n$l";
  104.     }
  105.     my @old = ();
  106.     my @new = ();
  107.     my $subst = edit_post_form($topic, $page, $post, $a);
  108.     my $page_ref = GetPage($topic, $page, { lock => 1 });
  109.     my $text_save = "";
  110.     foreach my $i (@{ $page_ref->{messages} }) {
  111.         if ($i->{number} == $post) {
  112.             $text_save = $i->{text};
  113.             $i->{text} = $subst->{messages}->[0]->{text};
  114.             last;
  115.         }
  116.     }
  117.     my $new = attachment_scan($subst->{messages}->[0]->{text});
  118.     my $old = attachment_scan($text_save);
  119.     my %OA = map { $_->{filename}, 1 } @{$old};
  120.     my %NA = map { $_->{filename}, 1 } @{$new};
  121.     my @ag = (); my @nw = ();
  122.     foreach my $knew (keys %NA) {
  123.         next if $OA{$knew};
  124.         push @nw, $knew;
  125.     }
  126.     foreach my $kold (keys %OA) {
  127.         next if $NA{$kold};
  128.         push @ag, $kold;
  129.     }
  130.     if (scalar(@nw) > 0) {
  131.         unlock("$DCONF->{message_dir}/$topic/$page.$DCONF->{ext}");
  132.         $subst->{general}->{attachadd} = 1;
  133.         $subst->{general}->{error} = 1;
  134.         my @li = ();
  135.         foreach my $x (@nw) {
  136.             push @li, { file => $x };
  137.         }
  138.         $subst->{list} = \@li;
  139.         screen_out("editpost", $subst, undef);
  140.     } elsif ($subst->{messages}->[0]->{text} =~ m|<img src="(.*?)"|is && $1 !~ m|^https?://.*$|i) {
  141.         unlock("$DCONF->{message_dir}/$topic/$page.$DCONF->{ext}");
  142.         $subst->{general}->{error} = 1;
  143.         screen_out("editpost", $subst, undef);
  144.     }
  145.     $page_ref->{general}->{messages_raw} = 0;
  146.     SetPage($page_ref, { unlock => 1 });
  147.     if (scalar(@ag)) {
  148.         my $dir = get_message_path($topic);
  149.         unlink map { join("/", $dir, $_) } @ag;
  150.     }
  151.     dreq("fcn-logs");
  152.     my $preview_storage = defined $DCONF->{log_preview_length} ? $DCONF->{log_preview_length} : 25;
  153.     my $firstchars_1 = lc(escape(substr(remove_html($subst->{messages}->[0]->{text}), 0, $preview_storage)));
  154.     my $firstchars_2 = lc(escape(substr(remove_html($text_save), 0, $preview_storage)));
  155.     my $search_stop_1 = search_stop($subst->{messages}->[0]->{text});
  156.     my $search_stop_2 = search_stop($text_save);
  157.     if ($firstchars_1 ne $firstchars_2) {
  158.         my $firstchars_NEW = escape(substr(remove_html($subst->{messages}->[0]->{text}), 0, $preview_storage));
  159.         log_search_update_entry($topic, "log", [ { postindex => $post, firstchars => $firstchars_NEW } ]);
  160.     }
  161.     if ($search_stop_1 ne $search_stop_2) {
  162.         log_search_update_entry($topic, "search", [ { postindex => $post, text => $search_stop_1 } ]);
  163.     }
  164. }
  165.  
  166. 1;
  167.