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-pgad.pl < prev    next >
Text File  |  2009-11-06  |  16KB  |  360 lines

  1. # FILE: fcn-pgad.pl
  2. # DESCRIPTION: Adds new pages
  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. ### change_page_layout
  20. ###
  21. ### Changes the layout of a given page with these parameters:
  22. ###        topic =>            Topic number
  23. ###        page =>                Page number
  24. ###        param =>            New parameters (Announce,Sublist,About,Messages,Add)
  25. ### If you're changing multiple pages at once you might want to define:
  26. ###        tree_ref =>            Tree reference
  27. ###        cat_ref =>            Categorized tree reference
  28. ###
  29.  
  30. sub change_page_layout {
  31.     my ($arg) = @_;
  32.     undef my $param;
  33.     $param->{'topic'} = (defined($arg->{topic}) ? $arg->{'topic'} : error_message("Invalid Topic", "Invalid topic received for layout change!", 0, 1));
  34.     $param->{'page'} = (defined($arg->{page}) ? $arg->{'page'} : error_message("Invalid Page", "Invalid page received for layout change!", 0, 1));
  35.     $param->{'param'} = (defined($arg->{layout}) ? $arg->{'layout'} : "AnnounceSublistAboutMessages");
  36.     my $file = GetPage($param->{topic}, $param->{page}, { lock => 1} );
  37.     $file->{head}->{param} = $param->{param};
  38.     $file->{sublist} = expand_sublist($file->{sublist}, $file->{head}->{topic_number});
  39.     SetPage($file, { unlock => 1 });
  40.  
  41.     dreq("fcn-tree");
  42.     undef my $tree;
  43.     if (defined $arg->{tree_ref}) {
  44.         $tree = $arg->{tree_ref};
  45.     } else {
  46.         $tree = read_tree($param->{topic}, { no_unlock => 1 });
  47.     }
  48.     my ($tree_out, $cat) = tree_record_update($tree, $arg->{cat_ref}, { topic => $param->{topic}, page => $param->{page}, param => $param->{param} });
  49.     if (! defined $arg->{tree_ref}) {
  50.         write_tree($param->{topic}, $tree_out, { no_lock => 1 }) if defined $tree_out;
  51.         topic_tree_to_main($tree_out, $param->{topic}) if $param->{topic} == $param->{page};
  52.     }
  53.     return {
  54.         file => $file,
  55.         tree => $tree_out,
  56.         cat => $cat,
  57.     };
  58. }
  59.  
  60. ###
  61. ### add_link
  62. ###
  63. ### Adds a link as a subtopic onto your board.  You should use these inputs:
  64. ###        name =>            Name of this link
  65. ###        URL =>            URL for this link
  66. ###        target =>        Target (4=_self, 5=Main, 6=_top, 7=_parent, 8=_blank)
  67. ###        topic =>        Topic Number
  68. ###        host =>            Host (Page Number of this subtopic's parent)
  69. ### Here are some other inputs you might want to use:
  70. ###        descr =>        Description for this link
  71. ###        position =>        Position (0=bottom, 1=top, 2=alphabetized)
  72. ###        tree_ref =>        Tree reference (if defined, tree file won't be written)
  73. ###        cat_ref =>        Categorized tree reference
  74. ###
  75.  
  76. sub add_link {
  77.     my ($arg) = @_;
  78.     undef my $param;
  79.     $param->{target} = ("", "", "", "", "_self", "Main", "_top", "_parent", "_blank")[$arg->{type}];
  80.     $param->{URL} = ($arg->{'URL'} =~ m|^(\w+)://| ? $arg->{'URL'} : error_message("Add Link Error", "Link to [$param->{URL}] is not valid.  It should start with http:// or https://!", 0, 1));
  81.     $param->{descr} = ($arg->{'descr'} =~ m|\S| ? $arg->{'descr'} : "");
  82.     $param->{topic} = $arg->{'topic'}; $param->{'topic'} =~ s/\D//g;
  83.     $param->{host} = $arg->{'host'}; $param->{'host'} =~ s/\D//g;
  84.     $param->{number} = ( defined($arg->{number}) ? $arg->{number} : get_number() );
  85.     $param->{name} = ( defined($arg->{name}) ? $arg->{name} : "Untitled Link" );
  86.     $param->{position} = ($arg->{'position'} == 0 ? 0 : $arg->{'position'});
  87.     $param->{icon} = $1 if $arg->{'icon'} =~ m|^(\w+)$|;
  88.     undef my $tree;
  89.     if (defined $arg->{tree_ref}) {
  90.         $tree = $arg->{tree_ref};
  91.     } else {
  92.         $tree = read_tree($param->{topic}, { no_unlock => 1 });
  93.     }
  94.     my $page_hash = GetPage($param->{topic}, $param->{host}, { lock => 1 });
  95.     undef my $new_subtopic_hash;
  96.     $new_subtopic_hash->{name} = $param->{name};
  97.     $new_subtopic_hash->{number} = $param->{number};
  98.     $new_subtopic_hash->{descr} = $param->{descr};
  99.     $new_subtopic_hash->{type} = 1;
  100.     $new_subtopic_hash->{url} = $param->{'URL'};
  101.     $new_subtopic_hash->{target} = $param->{'target'};
  102.     $new_subtopic_hash->{icon} = $param->{'icon'} || 'tree_m';
  103.     $page_hash->{sublist} = expand_sublist($page_hash->{sublist}, $param->{topic}, $tree);
  104.     $page_hash->{general}->{subtopic_raw} = 0;
  105.     push (@{ $page_hash->{sublist} }, $new_subtopic_hash) if $param->{position} != 1;
  106.     unshift (@{ $page_hash->{sublist} }, $new_subtopic_hash) if $param->{position} == 1;
  107.     @{ $page_hash->{sublist} } = sort alpha_sort @{ $page_hash->{sublist} } if $param->{position} == 2;
  108.     @{ $page_hash->{sublist} } = sort sort_archive_method @{ $page_hash->{sublist} } if $GLOBAL_OPTIONS->{sort_archive_method_on};
  109.     SetPage($page_hash, { unlock => 1 });
  110.  
  111.     undef my $new_subtopic_tree;
  112.     $new_subtopic_tree->{topic} = $param->{topic};
  113.     $new_subtopic_tree->{page} = $param->{number};
  114.     $new_subtopic_tree->{name} = $param->{name};
  115.     $new_subtopic_tree->{parent} = $param->{host};
  116.     $new_subtopic_tree->{islink} = 1;
  117.     $new_subtopic_tree->{target} = $param->{'target'};
  118.     $new_subtopic_tree->{url} = $param->{'URL'};
  119.     $new_subtopic_tree->{posts} = 0;
  120.     $new_subtopic_tree->{param} = undef;
  121.     $new_subtopic_tree->{properties} = undef;
  122.     $new_subtopic_tree->{props}->{icon} = $new_subtopic_hash->{icon};
  123.     $new_subtopic_tree->{lastmod} = 0;
  124.     $new_subtopic_tree->{originator} = "";
  125.     $new_subtopic_tree->{subs} = 0;
  126.     $new_subtopic_tree->{last_poster} = "";
  127.  
  128.     dreq("fcn-tree");
  129.     my ($treeref2, $cat) = tree_insert_record($tree, $arg->{cat_ref}, $new_subtopic_tree, $param);
  130.     ($treeref2, $cat) = tree_upward_update($treeref2, $cat, $param->{host}, { metoo => 1, subs => '+1' });
  131.     if (! defined $arg->{tree_ref}) {
  132.         write_tree($param->{topic}, $treeref2, { no_lock => 1 });
  133.         $arg->{main_tree} = topic_tree_to_main($treeref2);
  134.     }
  135.     return {
  136.         number => $param->{number},
  137.         tree => $treeref2,
  138.         cat => $cat,
  139.         file => $page_hash,
  140.         main_tree => $arg->{main_tree},
  141.     };
  142. }
  143.  
  144. ###
  145. ### add_page
  146. ###
  147. ### Adds a discussion page onto your board.  You should use these inputs:
  148. ###        name =>            Name of this subtopic
  149. ###        topic =>        Topic Number
  150. ###        host =>            Host (Page Number of this subtopic's parent)
  151. ###        type =>            Page type (0=Private Index,1=Public Index,2=Message,3=Closed Thread,4=Archive)
  152. ### Here are some other inputs you might want to use:
  153. ###        position =>        Position (0=bottom, 1=top, 2=alphabetized)
  154. ###        descr =>        Description for this subtopic
  155. ###        lastmod =>        Last modified time (seconds since epoch)
  156. ###        last_poster =>    Name of last person to post
  157. ###        originator =>    First poster in this conversation
  158. ###        msg_count =>    Number of messages under this point
  159. ###        post_update =>    Update the number of posts above this point
  160. ###        post_list =>    Set the post list for this new page
  161. ###        subs =>            Number of subtopics under this point
  162. ###        tree_ref =>        Tree reference (for adding multiple pages)
  163. ###        cat_ref =>        Categorized tree reference
  164. ###
  165.  
  166. sub add_page {
  167.     my ($arg) = @_;
  168.     undef my $param;
  169.     $param->{descr} = $arg->{'descr'} =~ m|\S| ? $arg->{'descr'} : "";
  170.     $param->{topic} = $arg->{'topic'}; $param->{'topic'} =~ s/\D//g;
  171.     $param->{host} = $arg->{'host'}; $param->{'host'} =~ s/\D//g;
  172.     $param->{lastmod} = $arg->{lastmod} != 0 ? $arg->{lastmod} : time;
  173.     $param->{icon} = $arg->{icon} if $arg->{icon} ne "";
  174.     $param->{last_poster} = $arg->{'last_poster'} eq "" ? " " : $arg->{'last_poster'};
  175.     $param->{originator} = $arg->{'originator'} eq "" ? " " : $arg->{'originator'};
  176.     $param->{msg_count} = $arg->{'msg_count'} == 0 ? 0 : $arg->{'msg_count'};
  177.     $param->{subs} = $arg->{'subs'} == 0 ? 1 : $arg->{'subs'};
  178.     $param->{number} = defined $arg->{force_new_page_number} ? $arg->{force_new_page_number} : get_number();
  179.     $param->{name} = defined($arg->{name}) ? $arg->{name} : "Untitled Subtopic";
  180.     $param->{position} = $arg->{'position'} == 0 ? 0 : $arg->{'position'};
  181.     $param->{post_update} = $arg->{new_post} > 0 ? "+$arg->{new_post}" : "";
  182.     $param->{post_list} = $arg->{post_list} eq "" ? "" : $arg->{post_list};
  183.     $param->{emoticon} = $arg->{emoticon} eq "" ? "" : $arg->{emoticon};
  184.     $param->{messages} = defined $arg->{messages} ? $arg->{messages} : \();
  185.     $param->{type} = defined $arg->{type} ? $arg->{type} : 0;
  186.     $param->{stype} = defined $arg->{stype} ? $arg->{stype} : 0;
  187.     my $page_hash = defined $arg->{pagehash} ? $arg->{pagehash} : GetPage($param->{topic}, $param->{host}, { lock => 1 });
  188.     undef my $new_page_hash;
  189.     $new_page_hash->{head} = $page_hash->{head};
  190.     $new_page_hash->{parent} = $param->{host};
  191.     $new_page_hash->{me_number} = $param->{number};
  192.     $new_page_hash->{me_name} = $param->{name};
  193.     $new_page_hash->{topic_number} = $param->{topic};
  194.     $new_page_hash->{topic_name} = $page_hash->{head}->{topic_name};
  195.     $new_page_hash->{levels} = $page_hash->{head}->{levels};
  196.     $new_page_hash->{properties} = "emot=$param->{emoticon}" if $param->{emoticon};
  197.     if ($arg->{type} =~ m|^\d+$|) {
  198.         $new_page_hash->{param} = "Sublist" if $arg->{type} == 0;
  199.         $new_page_hash->{param} = "SublistCreate" if $arg->{type} == 1;
  200.         $new_page_hash->{param} = "MessagesAdd" if $arg->{type} == 2;
  201.         $new_page_hash->{param} = "Messages" if $arg->{type} == 3;
  202.         $new_page_hash->{param} = "MessagesArchive" if $arg->{type} == 4;
  203.         $new_page_hash->{param} = "SublistArchive" if $arg->{type} == 5;
  204.     } else {
  205.         $new_page_hash->{param} = $arg->{type};
  206.     }
  207.     $page_hash->{general}->{subtopic_raw} = 0;
  208.     undef my $file;
  209.     undef my $new_subtopic_hash;
  210.     $new_subtopic_hash->{name} = $param->{name};
  211.     $new_subtopic_hash->{number} = $param->{number};
  212.     $new_subtopic_hash->{descr} = $param->{descr};
  213.     $new_subtopic_hash->{stype} = $param->{stype};
  214.     $new_subtopic_hash->{url} = "$DCONF->{message_url}/$param->{topic}/$param->{number}.$DCONF->{ext}";
  215.     $new_subtopic_hash->{url} .= "?$param->{lastmod}" if !$DCONF->{noqm};
  216.     $new_subtopic_hash->{last_poster} = $param->{last_poster};
  217.     $new_subtopic_hash->{originator} = $param->{originator};
  218.     $new_subtopic_hash->{msg_count} = $param->{msg_count};
  219.     $new_subtopic_hash->{subs} = $param->{subs};
  220.     $new_subtopic_hash->{lastmod} = $param->{lastmod};
  221.     $new_subtopic_hash->{property_emot} = $param->{emoticon};
  222.     $new_subtopic_hash->{param} = $new_page_hash->{param};
  223.     $new_subtopic_hash->{'icon'} = tree_icon_chooser($param->{'icon'}, $new_page_hash->{'param'}, undef);
  224.     my $tree = defined $arg->{tree_ref} ? $arg->{tree_ref} : read_tree($param->{topic}, { no_unlock => 1 });
  225.     undef $PARAMS->{"lookup:$param->{topic}"};
  226.     $page_hash->{sublist} = expand_sublist($page_hash->{sublist}, $param->{topic}, $tree);
  227.     $page_hash->{head}->{param} .= "Sublist" if $page_hash->{head}->{param} !~ /Sublist/;
  228.     push (@{ $page_hash->{sublist} }, $new_subtopic_hash) if $param->{position} != 1;
  229.     unshift (@{ $page_hash->{sublist} }, $new_subtopic_hash) if $param->{position} == 1;
  230.     @{ $page_hash->{sublist} } = sort alpha_sort @{ $page_hash->{sublist} } if $param->{position} == 2;
  231.     @{ $page_hash->{sublist} } = sort sort_archive_method @{ $page_hash->{sublist} } if $GLOBAL_OPTIONS->{sort_archive_method_on};
  232.     SetPage($page_hash, { privcache => $arg->{privcache}, unlock => 1 }) if ! defined $arg->{pagehash};
  233.     $file = $page_hash;
  234.     my $inp = create_new_page($new_page_hash, $page_hash);
  235.     $inp->{messages} = $param->{messages} if ref $param->{messages} eq "ARRAY";
  236.     push @{$inp->{messages}}, $arg->{first_post} if defined $arg->{first_post};
  237.     SetPage( $inp ) if ! $arg->{nosetpage};
  238.     $file = $inp if $arg->{jump};
  239.     undef my $new_subtopic_tree;
  240.     $new_subtopic_tree->{topic} = $param->{topic};
  241.     $new_subtopic_tree->{page} = $param->{number};
  242.     $new_subtopic_tree->{name} = $param->{name};
  243.     $new_subtopic_tree->{parent} = $param->{host};
  244.     $new_subtopic_tree->{posts} = $param->{msg_count};
  245.     $new_subtopic_tree->{param} = $new_page_hash->{param};
  246.     $new_subtopic_tree->{properties} = undef;
  247.     # Next line was commented out
  248.     $new_subtopic_tree->{props}->{icon} = $new_subtopic_hash->{icon} if defined $new_subtopic_hash->{icon};
  249.     $new_subtopic_tree->{props}->{emot} = $param->{emoticon} if $param->{emoticon};
  250.     $new_subtopic_tree->{lastmod} = $param->{lastmod};
  251.     $new_subtopic_tree->{originator} = $param->{originator};
  252.     $new_subtopic_tree->{subs} = $param->{subs};
  253.     $new_subtopic_tree->{last_poster} = $param->{last_poster};
  254.     $new_subtopic_tree->{post_list} = $param->{post_list};
  255.     dreq("fcn-tree");
  256.     my ($treeref2, $cat) = tree_insert_record($tree, $arg->{cat_ref}, $new_subtopic_tree, $param);
  257.     ($treeref2, $cat) = tree_upward_update($treeref2, $cat, $param->{host}, { metoo => 1, subs => '+1' });
  258.     if (! defined $arg->{tree_ref} ) {
  259.         write_tree($param->{topic}, $treeref2, { no_lock => 1 });
  260.         $arg->{main_tree} = topic_tree_to_main($treeref2);
  261.     }
  262.     return {
  263.         number => $param->{number},
  264.         tree => $treeref2,
  265.         cat => $cat,
  266.         file => $file,
  267.         main_tree => $arg->{main_tree},
  268.         pghash => $page_hash,
  269.         newfile => $inp,
  270.     };
  271. }
  272.  
  273. ###
  274. ### create_new_page
  275. ###
  276. ### Creates a new, blank page (called internally)
  277. ###
  278.  
  279. sub create_new_page {
  280.     my ($params, $parent_param) = @_;
  281.     undef my $result;
  282.     $result->{pginfo}->{headers_asstring} = "<!--Me: $params->{me_number}/$params->{me_name}-->\n";
  283.     $result->{head}->{me_number} = $params->{me_number};
  284.     $result->{head}->{me_name} = $params->{me_name};
  285.     $result->{pginfo}->{headers_asstring} .= "<!--Topic: $params->{topic_number}/$params->{topic_name}-->\n";
  286.     $result->{head}->{topic_number} = $params->{topic_number};
  287.     $result->{head}->{topic_name} = $params->{topic_name};
  288.     $result->{pginfo}->{headers_asstring} .= "<!--Param: $params->{param}-->\n";
  289.     $result->{head}->{param} = $params->{param};
  290.     $result->{pginfo}->{headers_asstring} .= "<!--Properties: $params->{properties}-->\n";
  291.     $result->{head}->{properties} = $params->{properties};
  292.     $result->{pginfo}->{headers_asstring} .= "<!--Parent: $params->{parent}-->\n";
  293.     $result->{head}->{parent} = $params->{parent};
  294.     $result->{head}->{levels} = [{}]; # Cool huh?
  295.     if ($params->{me_number} != $params->{topic_number}) {
  296.         my $ctr = 0;
  297.         foreach my $x (@{ $params->{levels} }) {
  298.             next if $x->{level_number} == 0;
  299.             $ctr++;
  300.             $result->{pginfo}->{headers_asstring} .= "<!--Level $ctr: $x->{level_number}/$x->{level_name}-->\n";
  301.             push (@{ $result->{head}->{levels} }, $x);
  302.         }
  303.         $ctr++;
  304.         $result->{pginfo}->{headers_asstring} .= "<!--Level $ctr: $params->{me_number}/$params->{me_name}-->\n";
  305.         undef my $nref;
  306.         $nref->{level_number} = $params->{me_number};
  307.         $nref->{level_name} = $params->{me_name};
  308.         push (@{ $result->{head}->{levels} }, $nref);
  309.     }
  310.     $result->{general}->{showadminfromhere} = 1;
  311.     @{ $result->{sublist} } = ();
  312.     @{ $result->{messages} } = ();
  313.     # Inherit META tags from parent
  314.     $result->{meta_description} = $parent_param->{meta_description};
  315.     $result->{meta_keywords} = $parent_param->{meta_keywords};
  316.     $result->{meta_robots} = $parent_param->{meta_robots};
  317.     return $result;
  318. }
  319.  
  320. ###
  321. ### page_mgr_add_subtopic
  322. ###
  323. ### Adds a subtopic to a page via the Page Manager
  324. ###
  325.  
  326. sub page_mgr_add_subtopic {
  327.     my ($FORMref) = @_;
  328.     dreq("webtags");
  329.     my ($lint_subj, $subtopic_name) = webtags($FORMref->{subtopic}, 3, 1, 1);
  330.     error_message("Add Subtopic Error - Problem With Name", $subtopic_name, 0, 1) if $lint_subj eq "!Error";
  331.     my $add_args = {};
  332.     if ($FORMref->{descr} ne "") {
  333.         my ($lint_subj2, $descr) = webtags($FORMref->{descr}, 3, 1, 1);
  334.         error_message("Add Subtopic Error - Problem With Description", $descr, 0, 1) if $lint_subj2 eq "!Error";
  335.         $add_args->{'descr'} = $descr;
  336.     }
  337.     $add_args->{name} = $subtopic_name;
  338.     $add_args->{topic} = $FORMref->{topic};
  339.     $add_args->{host} = $FORMref->{page};
  340.     $add_args->{type} = $FORMref->{createas};
  341.     $add_args->{position} = $FORMref->{position};
  342.     $add_args->{jump} = $FORMref->{jumpinto} == 1;
  343.     $add_args->{emoticon} = $FORMref->{emoticon};
  344.     $add_args->{icon} = $FORMref->{icon} if $FORMref->{icon} ne "";
  345.     my $add_ref = {};
  346.     if ($add_args->{'type'} <= 3) {
  347.         $add_ref = add_page($add_args);
  348.         $FORMref->{HTTP_REFERER} = "/$FORMref->{topic}/$add_ref->{number}.$DCONF->{ext}" if $add_args->{jump};
  349.     } else {
  350.         $add_args->{'URL'} = $FORMref->{'URL'};
  351.         $add_ref = add_link($add_args);
  352.     }
  353.     pages_upward_update($add_ref->{tree}, $add_ref->{cat}, [ $add_args->{host} ]);
  354.     dreq("topic-pg"); regenerate_topic_page(undef, $add_ref->{main_tree});
  355.     $PARAMS->{"lookup:$add_args->{topic}"} = undef;
  356.     page_mgr_sublist($FORMref, $add_ref->{file}, $add_ref->{tree});
  357. }
  358.  
  359. 1;
  360.