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-pgdl.pl < prev    next >
Text File  |  2009-11-06  |  4KB  |  120 lines

  1. # FILE: fcn-pgdl.pl
  2. # DESCRIPTION: Delete a page from the user interface
  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. ### remove_page
  20. ###
  21. ### Removes a page or links.  Incoming values required are:
  22. ###        topic =>        Topic number
  23. ###        page =>            Page number (parent of pages to be removed)
  24. ###        remove =>        Pages to remove (comma-delimited list of numbers)
  25. ### Optionally, define $tree_file_in and $cat_array_in.  If you do that,
  26. ### the tree array will be updated but changes won't be saved.  If
  27. ### not, this handles the tree file for you too.
  28. ###
  29.  
  30. sub remove_page {
  31.     my ($arg, $tree_file_in, $cat_array_in, $file_in) = @_;
  32.     undef my $nuke;
  33.     my @children = ();
  34.     dreq("fcn-tree");
  35.     my $tree = defined $tree_file_in ? $tree_file_in : read_tree($arg->{topic}, { no_unlock => 1 });
  36.     my $cat_array = defined $cat_array_in ? $cat_array_in : tree_categorize($tree);
  37.     if (ref $arg->{remove} eq 'HASH') {
  38.         $nuke = $arg->{remove};
  39.         foreach my $i (keys(%{$arg->{remove}})) {
  40.             push (@children, tree_dump_into_array(tree_build_children_of($tree, $cat_array, $i)));
  41.         }
  42.     } else {
  43.         foreach my $i (split(/,/, $arg->{remove})) {
  44.             $nuke->{$i} = 1;
  45.             push (@children, tree_dump_into_array(tree_build_children_of($tree, $cat_array, $i)));
  46.         }
  47.     }
  48.     my @nuke = ();
  49.     foreach my $i (@children) { push (@nuke, $i->{page}); }
  50.     foreach my $i (keys(%{ $nuke })) { push (@nuke, $i); }
  51.     my $pg = undef;
  52.     ($tree, $cat_array, $pg) = tree_remove_page($tree, $cat_array, $arg->{remove}, $arg->{page});
  53.     if (! defined $tree_file_in) {
  54.         write_tree($arg->{topic}, $tree, { no_lock => 1 });
  55.         topic_tree_to_main($tree);
  56.     }
  57.     undef my $ding_msg;
  58.     foreach my $i (@{ $pg }) { $ding_msg->{$i} = 1; }
  59.     my $file = defined $file_in ? $file_in : GetPage($arg->{topic}, $arg->{page}, { lock => 1 });
  60.     $file->{sublist} = expand_sublist($file->{sublist}, $arg->{topic}, $tree);
  61.     my @newst = ();
  62.     foreach my $n (@{ $file->{sublist} }) {
  63.         next if $nuke->{$n->{number}};
  64.         push (@newst, $n);
  65.     }
  66.     $file->{sublist} = \@newst;
  67.     $file->{general}->{subtopic_raw} = 0;
  68.     $file->{general}->{messages_raw} = 1;
  69.     SetPage($file, { unlock => 1 }) if ! defined $file_in;
  70.     recursive_attachment_deleter(\@nuke, $arg);
  71.     dreq("fcn-logs");
  72.     if ($DCONF->{pro} && $GLOBAL_OPTIONS->{database} == 1) {
  73.         delete_entry ({ files_already_locked => $arg->{files_already_locked}, topic => $arg->{topic}, database => "log", messages => $ding_msg });
  74.         delete_entry ({ files_already_locked => $arg->{files_already_locked}, topic => $arg->{topic}, database => "search", messages => $ding_msg });
  75.     } else {
  76.         delete_entry ({ files_already_locked => $arg->{files_already_locked}, topic => $arg->{topic}, messages => $ding_msg });
  77.     }
  78.     if (! $arg->{no_upward_update}) {
  79.          pages_upward_update($tree, $cat_array, [ $arg->{page} ]);
  80.         dreq("topic-pg"); regenerate_topic_page();
  81.     }
  82.     return {
  83.         tree => $tree,
  84.         cat_array => $cat_array,
  85.         oldfile => $file,
  86.     };
  87. }
  88.  
  89. ###
  90. ### recursive_attachment_deleter
  91. ###
  92. ### Removes images and attachments associated with certain pages
  93. ###
  94.  
  95. sub recursive_attachment_deleter {
  96.     my ($nukes, $arg, $taskman) = @_;
  97.     my $flag = ($GLOBAL_OPTIONS->{discus_taskman} && $GLOBAL_OPTIONS->{taskman_image});
  98.     $flag = 0 if $taskman;
  99.     my @nuke = ref $nukes eq 'ARRAY' ? @{$nukes} : ($nukes);
  100.     if ($flag == 1) {
  101.         foreach my $pg (@nuke) {
  102.             my @a = ($pg, $arg, 1);
  103.             taskman_create_job("recursive_attachment_deleter", "fcn-pgdl", \@a);
  104.         }
  105.     } else {
  106.         foreach my $pg (@nuke) {
  107.             my $u = GetPage($arg->{topic}, $pg, { no_unlock => 1, no_lock => 1, no_error => 1 });
  108.             my $dir = get_message_path($arg->{topic});
  109.             if (ref $u->{messages} eq 'ARRAY') {
  110.                 unlink map { join("/", $dir, $_->{filename}) } @{attachment_scan($u->{messages})};
  111.             }
  112.             unlink "$dir/$pg.$DCONF->{ext}";
  113.         }
  114.     }
  115.     return scalar(@nuke);    
  116. }
  117.  
  118.  
  119. 1;
  120.