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-pg_m.pl < prev    next >
Text File  |  2009-11-06  |  8KB  |  189 lines

  1. # FILE: fcn-pg_m.pl
  2. # DESCRIPTION: Page Management (miscellaneous functions)
  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. ### rename_subtopic
  20. ###
  21. ### Gives a subtopic a new name
  22. ###
  23.  
  24. sub rename_subtopic {
  25.     my ($topic, $page, $new_name, $user, $file_in_1, $file_in_2, $tree_in, $tree_cat_in) = @_;
  26.     error_message("Rename subtopic error", "Topic cannot equal page in renaming subtopic.", 0, 1) if $topic == $page;
  27.     dreq("fcn-tree", "fcn-regn");
  28.     my $tree = defined $tree_in ? $tree_in : read_tree($topic, { no_unlock => 1 });
  29.     my $hb = tree_record_update($tree, $tree_cat_in, { page => $page, name => $new_name }, 1);
  30.     my $cat = $hb->{cat}; $tree = $hb->{tree};
  31.     write_tree($topic, $tree, { no_lock => 1 }) if ! defined $tree_in;
  32.     my $parent = $cat->{parent}->{$page};
  33.     my $file1 = defined $file_in_1 ? $file_in_1 : GetPage($topic, $parent, { lock => 1 });
  34.     $file1->{general}->{subtopic_raw} = 0;
  35.     $file1->{sublist} = expand_sublist($file1->{sublist}, $topic, $tree);
  36.     SetPage($file1, { unlock => 1 }) if ! defined $file_in_1;
  37.     my $file2 = defined $file_in_2 ? $file_in_2 : GetPage($topic, $page, { lock => 1 });
  38.     $file2->{head}->{me_name} = $new_name;
  39.     my $l = scalar(@{$file2->{head}->{levels}})-1;
  40.     $file2->{head}->{levels}->[$l]->{level_name} = $new_name;
  41.     SetPage($file2, { unlock => 1 }) if ! defined $file_in_2;
  42.     my $inc = incremental_descendants($topic, $page, "RS", $tree, $cat);
  43.     return unlink "$DCONF->{admin_dir}/backups/$inc->{tempfile}.TMP" if $inc->{count} == 0;
  44.     my $chgfile = regeneration_create_change_process_file("regen_level_change", $l, $new_name);
  45.     return regenerate_board({ esc => 1, hold => regeneration_create_hold({ HTTP_REFERER => "/$topic/$parent" }), topic => $topic, tempfile => $inc->{tempfile}, done => 0, total => $inc->{count}, action => "regen3", username => $user, changefile => $chgfile, operation => 5, description => 501 });
  46. }
  47.  
  48. ###
  49. ### reorder_subtopics
  50. ###
  51. ### Reorders subtopics & links on a page
  52. ###
  53.  
  54. sub reorder_subtopics {
  55.     my ($arg) = @_;
  56.     dreq("fcn-tree");
  57.     my $file = GetPage($arg->{topic}, $arg->{page}, { lock => 1 });
  58.     @{$file->{sublist}} = sort { $arg->{order}->{ $a->{number} } <=> $arg->{order}->{ $b->{number} } } @{$file->{sublist}};
  59.     $file->{general}->{subtopic_raw} = 0;
  60.     my $tree = read_tree($arg->{topic}, { no_unlock => 1 });
  61.     my $order = $arg->{order};
  62.     my $coderef = sub { $order->{$a->[0]->{page}} <=> $order->{$b->[0]->{page}} };
  63.     $tree = (tree_subtopic_reorder($tree, undef, $arg->{page}, $coderef, 0))[0];
  64.     $file->{sublist} = expand_sublist($file->{sublist}, $arg->{topic}, $tree);
  65.     write_tree($arg->{topic}, $tree, { no_lock => 1 });
  66.     SetPage($file, { unlock => 1 });
  67.     return $file->{sublist};
  68. }
  69.  
  70. ###
  71. ### change_page_layout
  72. ###
  73. ### Changes the layout of a given page with these parameters:
  74. ###        topic =>            Topic number
  75. ###        page =>                Page number
  76. ###        param =>            New parameters (Announce,Sublist,About,Messages,Add)
  77. ### If you're changing multiple pages at once you might want to define:
  78. ###        tree_ref =>            Tree reference
  79. ###        cat_ref =>            Categorized tree reference
  80. ###
  81.  
  82. sub change_page_layout {
  83.     my ($arg, $file_in) = @_;
  84.     my $param = {};
  85.     $param->{'topic'} = (defined($arg->{topic}) ? $arg->{'topic'} : error_message("Invalid Topic", "Invalid topic received for layout change!", 0, 1));
  86.     $param->{'page'} = (defined($arg->{page}) ? $arg->{'page'} : error_message("Invalid Page", "Invalid page received for layout change!", 0, 1));
  87.     $param->{'param'} = (defined($arg->{layout}) ? $arg->{'layout'} : "AnnounceSublistAboutMessages");
  88.     my $file = defined $file_in ? $file_in : GetPage($param->{topic}, $param->{page}, { lock => 1} );
  89.     my $m = $file->{head}->{param};
  90.     $file->{head}->{param} = $param->{param};
  91.     SetPage($file, { unlock => 1 }) if ! defined $file_in;
  92.     dreq("fcn-tree");
  93.     my $tree = defined $arg->{tree_ref} ? $arg->{tree_ref} : read_tree($param->{topic}, { no_unlock => 1 });
  94.     my ($tree_out, $cat) = tree_record_update($tree, $arg->{cat_ref}, { topic => $param->{topic}, page => $param->{page}, param => $param->{param} });
  95.     if ($DCONF->{pro} && $GLOBAL_OPTIONS->{sort_archive_method_on}) {
  96.         if (($m =~ /Archive/ && $param->{param} !~ /Archive/) || ($m !~ /Archive/ && $param->{param} =~ /Archive/)) {
  97.             if ($file->{head}->{parent} > 0 && $file->{head}->{parent} != $param->{page}) {
  98.                 dreq("posting");
  99.                 my $parent_arrays = {};
  100.                 foreach my $refr (@{ $tree_out }) {
  101.                     next if $refr->{page} == 0;
  102.                     push (@{ $parent_arrays->{ $refr->{parent} } }, $refr) if $refr->{level} > 0;
  103.                     push (@{ $parent_arrays->{ 0 } }, $refr) if $refr->{level} == 0;
  104.                 }
  105.                 @{$parent_arrays->{ $file->{head}->{parent} } } = sort sort_archive_method @{$parent_arrays->{ $file->{head}->{parent} } };
  106.                 $tree_out = buildtree($parent_arrays, 0);
  107.                 my $pg_in = GetPage($param->{topic}, $file->{head}->{parent}, { lock => 1 });
  108.                 $pg_in->{general}->{subtopic_raw} = 0;
  109.                 $pg_in->{sublist} = expand_sublist($pg_in->{sublist}, $param->{topic}, $tree_out);
  110.                 @{$pg_in->{sublist}} = sort sort_archive_method @{$pg_in->{sublist}};
  111.                 SetPage($pg_in, { unlock => 1 });        
  112.             }
  113.         }
  114.     }
  115.     if (! defined $arg->{tree_ref}) {
  116.         write_tree($param->{topic}, $tree_out, { no_lock => 1 }) if defined $tree_out;
  117.         topic_tree_to_main($tree_out, undef) if $param->{topic} == $param->{page};
  118.     }
  119.     return {
  120.         file => $file,
  121.         tree => $tree_out,
  122.         cat => $cat,
  123.     };
  124. }
  125.  
  126. ###
  127. ### change_page_properties
  128. ###
  129. ### Saves changes to link/page properties
  130. ###
  131.  
  132. sub change_page_properties {
  133.     my ($topic, $page, $lnum, $newprops, $tree_in, $cat_in) = @_;    
  134.     my $Z = GetPage($topic, $page, { lock => 1 });
  135.     my @U = save_subtopic_properties($topic, $Z->{sublist}, { $lnum => $newprops }, $tree_in, $cat_in);
  136.     $Z->{sublist} = $U[0];
  137.     $Z->{general}->{subtopic_raw} = 0;
  138.     SetPage($Z, { unlock => 1 });
  139.     push @U, $Z;
  140.     return @U;    
  141. }
  142.  
  143. ###
  144. ### save_subtopic_properties
  145. ###
  146. ### Saves changes to subtopic or link properties
  147. ###
  148.  
  149. sub save_subtopic_properties {
  150.     my ($topic, $subtopics, $updates, $tree_in, $tree_cat_in) = @_;
  151.     dreq("fcn-tree");
  152.     my $tree = defined $tree_in ? $tree_in : read_tree($topic, { no_unlock => 1 });
  153.     my $cat = defined $tree_cat_in ? $tree_cat_in : tree_categorize($tree);
  154.     foreach my $S (@{$subtopics}) {
  155.         my $num = $S->{number};
  156.         next if $updates->{$num} == 0;
  157.         my $U = $updates->{$num};
  158.         my $tl = $tree->[$cat->{array_pos}->{$num}];
  159.         $S->{descr} = $U->{descr} if defined $U->{descr};
  160.         $tl->{icon} = $U->{icon} if $U->{icon};
  161.         if (defined $U->{name}) {
  162.             $tl->{name} = $U->{name};
  163.             $S->{name} = $U->{name};
  164.         }
  165.         $tl->{property_emot} = $U->{emot} if $U->{emot};
  166.         $tl->{props}->{emot} = $U->{emot} if $U->{emot};
  167.         $tl->{props}->{icon} = $U->{icon} if $U->{icon};
  168.         $tl->{properties} = undef;
  169.         $tl->{url} = $U->{url} if $U->{url};
  170.         if ($U->{target}) {
  171.             $tl->{target} = $U->{target};
  172.             $S->{target} = $U->{target};
  173.         }
  174.         if (! $tl->{islink}) {
  175.             my $Q = GetPage($topic, $num, { no_unlock => 1 });
  176.             my $j = generate_properties_hash($Q->{head}->{properties});
  177.             $j->{emot} = $tl->{props}->{emot};
  178.             $j->{icon} = $tl->{props}->{icon};
  179.             $Q->{head}->{properties} = generate_properties($j);
  180.             SetPage($Q, { no_lock => 1 });    
  181.         }
  182.     }
  183.     $subtopics = expand_sublist($subtopics, $topic, $tree);
  184.     write_tree($topic, $tree, { no_lock => 1 }) if ! defined $tree_in;
  185.     return ($subtopics, $tree, $cat);    
  186. }
  187.  
  188. 1;
  189.