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

  1. # FILE: topic-pg.pl
  2. # DESCRIPTION: Generates and regenerates the board topics page
  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. ### regenerate_topic_page
  20. ###
  21. ### Regenerate the board topics page
  22. ###
  23.  
  24. sub regenerate_topic_page {
  25.     my ($arg, $tree) = @_;
  26.     if (! $arg->{no_lock}) {
  27.         my $rv = &lock({ max => 1, no_error_message => 1 }, "$DCONF->{message_dir}/$DCONF->{board_topics_file}");
  28.         return 0 if $rv == 0;
  29.     }
  30.     $arg->{file} = read_topic_page(undef, $tree) if ! defined($arg->{file});
  31.     write_topic_page($arg->{file});
  32.     unlock("regenerate_topic_page", "$DCONF->{message_dir}/$DCONF->{board_topics_file}") if ! $arg->{no_unlock};
  33. }
  34.  
  35. ###
  36. ### read_topic_page
  37. ###
  38. ### Gets all kinds of information about the topics on the board
  39. ###
  40.  
  41. sub read_topic_page {
  42.     my ($args, $tree, $file_input) = @_;
  43.     undef my $pass;
  44.     $pass->{no_lock} = 1 if !$args->{lock};
  45.     $pass->{no_unlock} = 1 if !$args->{unlock};
  46.     if (defined $file_input) {
  47.         my @fi = ref $file_input eq 'ARRAY' ? @{$file_input} : ($file_input);
  48.         $file_input = \@fi;
  49.     }
  50.     my $file = defined $file_input ? $file_input : undef;
  51.     if (! defined($file)) {
  52.         if (! $DCONF->{pro} || (! $GLOBAL_OPTIONS->{secure_topics_file} && ! $GLOBAL_OPTIONS->{topics_to_show})) {
  53.             $file = readfile("$DCONF->{message_dir}/$DCONF->{board_topics_file}", "read_topic_page", $pass);
  54.         } else {
  55.             dreq("authwrap-PRO");
  56.             $file = wrapped_topics_file($pass);
  57.         }
  58.     }
  59.     undef my $result;
  60.     my $flag = 0;
  61.     $result->{'topics'} = board_topics(undef, $file, $tree);
  62.     foreach my $line (@{$file}) {
  63.         if ($line =~ m|^<!--Title Message-->|) {
  64.             $flag = 1;
  65.         } elsif ($line =~ m|^<!--/Title Message-->|) {
  66.             $flag = 0;
  67.         } elsif ($line =~ m|^<!--Message-->|) {
  68.             $flag = 2;
  69.         } elsif ($line =~ m|^<!--/Message-->|) {
  70.             $flag = 0;
  71.         } elsif ($flag == 1 || $flag == 2) {
  72.             next if ($line =~ m|^<!-Skip-!>| || $line =~ m|^<!--Skip-->|);
  73.             next if $line !~ m|\S|;
  74.             if ($line =~ m|^<hr>|i) {
  75.                 $result->{'titlemsg'}->{'hr'} = 1 if $flag == 1;
  76.                 $result->{'mainmsg'}->{'hr'} = 1 if $flag == 2;
  77.                 next;
  78.             } elsif ($line =~ m|^<!--Source:|) {
  79.                 next;
  80.             } elsif ($line !~ m|\S|) {
  81.                 next;
  82.             } else {
  83.                 chomp $line;
  84.                 $result->{'titlemsg'}->{text} = $line if $flag == 1;
  85.                 $result->{'mainmsg'}->{text} = $line if $flag == 2;
  86.             }
  87.         }
  88.     }
  89.     return $result;
  90. }
  91.  
  92. ###
  93. ### write_topic_page
  94. ###
  95. ### Writes the topic page
  96. ###
  97.  
  98. sub write_topic_page {
  99.     my ($arg, $zarg, $in_message_dir) = @_;
  100.     dreq("template");
  101.     hash_merge($arg, $zarg, 1);
  102.     my $subst = $arg;
  103.     bless $subst;
  104. #    $subst->{'color'}->{'bgcolor'} = $GLOBAL_OPTIONS->{'COLOR_bgcolor'};
  105. #    $subst->{'color'}->{'text'} = $GLOBAL_OPTIONS->{'COLOR_text'};
  106. #    $subst->{'color'}->{'link'} = $GLOBAL_OPTIONS->{'COLOR_link'};
  107. #    $subst->{'color'}->{'vlink'} = $GLOBAL_OPTIONS->{'COLOR_vlink'};
  108. #    $subst->{'color'}->{'alink'} = $GLOBAL_OPTIONS->{'COLOR_alink'};
  109. #    $subst->{'color'}->{'image'} = $GLOBAL_OPTIONS->{'COLOR_image'};
  110. #    $subst->{'color'}->{'face'} = $GLOBAL_OPTIONS->{'COLOR_face'};
  111. #    $subst->{'color'}->{'size'} = $GLOBAL_OPTIONS->{'COLOR_size'};
  112.     $subst->topic_page_board_info($arg->{topics});
  113.     $subst->{DYNAMIC}->{'server_time'} = time if $arg->{return_val};
  114.     my $text = templ_int("*topics", $subst);
  115.     return $text if $arg->{return_val};
  116.     my @text = ($text);
  117.     my $pass = {};
  118.     $pass->{no_lock} = 1 if !$arg->{lock};
  119.     $pass->{no_unlock} = 1 if !$arg->{unlock};
  120.     if ($in_message_dir || ! $DCONF->{pro} || (! $GLOBAL_OPTIONS->{secure_topics_file} && ! $GLOBAL_OPTIONS->{topics_to_show})) {
  121.         writefile("$DCONF->{message_dir}/$DCONF->{board_topics_file}", \@text, "write_topic_page", $pass);
  122.     } else {
  123.         dreq("authwrap-PRO");
  124.         wrapped_topics_file_write(\@text, $pass);
  125.     }
  126. }
  127.  
  128. ###
  129. ### topic_page_board_info
  130. ###
  131. ### For the Discus version, total messages, total messages displayed, registered users...
  132. ###
  133.  
  134. sub topic_page_board_info {
  135.     my $self = shift;
  136.     my $topics = shift;
  137.     undef my $i;
  138.     foreach my $l (@{ $topics }) {
  139.         $i->{topic_items_total} += 1;
  140.         if ($l->{type} == 1) {
  141.             $i->{topics_total} += 1;
  142.             if ($l->{lastmod} > $i->{last_post}) {
  143.                 $i->{last_post} = $l->{lastmod};
  144.                 $i->{last_poster} = $l->{last_poster};
  145.             }
  146.             $i->{messages_total} += $l->{posts};
  147.             $i->{pages_total} += $l->{subs};
  148.             if ($l->{hidden}) {
  149.                 $i->{topics_hidden} += 1 if $l->{hidden};
  150.             } else {
  151.                 $i->{topics_displayed} += 1;
  152.                 $i->{messages_displayed} += $l->{posts};
  153.                 $i->{pages_displayed} += $l->{subs};
  154.                 if ($l->{lastmod} > $i->{last_post_visible}) {
  155.                     $i->{last_post_visible} = $l->{lastmod};
  156.                     $i->{last_poster_visible} = $l->{last_poster};
  157.                 }
  158.             }
  159.         } else {
  160.             $i->{categories} + 1;
  161.         }
  162.     }
  163.     $i->{discus_version} = join(" ", "Discus", join(".", $PARAMS->{release}, $PARAMS->{revision}), ( $DCONF->{pro} == 1 ? "Pro" : "" ));
  164.     my $o = readfile("$DCONF->{admin_dir}/data/regusers.txt", "topic_page_board_info", { no_lock => 1, no_unlock => 1, create => 1 });
  165.     $i->{registered_users} = 0 + $o->[0]; chomp $i->{registered_users};
  166.     $self->{topicinfo} = hash_merge($self->{topicinfo}, $i, 1);
  167.     if ($GLOBAL_OPTIONS->{skinvar_board}) {
  168.         dreq("fcn-info");
  169.         board_info_topicinfo_save($topics, $self);
  170.     }
  171.     return $self;
  172. }
  173.  
  174. 1;
  175.