# FILE: src-board-subs-9 # Copyright (c) 1998, Kevin W. Paulisse and William F. Polik, all rights reserved # Licensed under the Discus license agreement # http://www.chem.hope.edu/discus #---SEPARATOR---# #REQ:get_date_time sub post_message { local ($topic_number, $me_number, $message_hold, $newmessage, $postby, $username, $group, $datestring_in) = @_; local ($datetime, @message, $line, $postindex); &lock("$admin_dir/postindex.txt"); open (FILE, "$admin_dir/postindex.txt"); $postindex = ; close (FILE); ++$postindex; open (FILE, ">$admin_dir/postindex.txt"); print FILE $postindex; close (FILE); &unlock("$admin_dir/postindex.txt"); $datetime = &get_date_time("long"); $datetime = $datestring_in if $datestring_in ne ""; &lock("$message_dir/$topic_number/$me_number.$ext"); local ($head, $color, $lm, $sublist, $about, $about_src, $message, $message_src) = &get_page($topic_number, $me_number); if ($new_messages_go == 0) { $message2 = $message; $message = ""; } $message .= "\n"; $message .= "\n"; $message .= "
\n"; $pb = $L{POSTBY}; $pb =~ s/\%name/$postby/g; $pb =~ s/\%date/$datetime/g; $message .= "$pb

\n"; $message .= "$newmessage\n"; $message .= "\n"; if ($new_messages_go == 0) { $message .= $message2; } $ctr = 0; while ($message_hold =~ /\\image\{([^\}]*)\}/) { $tag = $1; ++$ctr; $message_hold = $` . "\\image_notuploaded{$ctr,$tag}" . $'; } if ($L{IMAGE_TAG_NAME} ne "image" && $L{IMAGE_TAG_NAME} ne "") { $trep = $L{IMAGE_TAG_NAME}; while ($message_hold =~ /\\$trep\{([^\}]*)\}/) { $tag = $1; ++$ctr; $message_hold = $` . "\\image_notuploaded{$ctr,$tag}" . $'; } } local ($chars, $poststr, $message_hold_2); $message_hold_2 = $message_hold; $message_hold_2 .= " "; $poststr = &remove_html($postby); $poststr = &escape($poststr); $nmtemp = $newmessage; $nmtemp = &remove_html($newmessage, 1); $nmtemp .= " "; $nmtemp =~ m|^([\s\S]{0,40})\s|; $chars = $1; $chars =~ s/\s+$//; $chars = &escape($chars); $message_hold = &escape($message_hold); $message_src .= "\n$message_hold\n\n"; &set_page($topic_number, $me_number, $head, $color, $lm, $sublist, $about, $about_src, $message, $message_src); &unlock("$message_dir/$topic_number/$me_number.$ext"); &lock("$admin_dir/log.txt"); open (LOG, ">>$admin_dir/log.txt"); print LOG "$postindex;$username:$group;", time, ";$topic_number/$me_number;$ENV{'REMOTE_ADDR'};$ENV{'REMOTE_HOST'};$chars;$poststr\n"; close (LOG); &unlock("$admin_dir/log.txt"); return $postindex; } #---SEPARATOR---# sub get_date_time { local ($format, $timer) = @_; local ($months, $weekdays, $ampm, $time_string); $timer = time if $timer == 0; local ($sec, $min, $hour, $day, $nmonth, $year, $wday, $yday, $isdst) = localtime($timer); if ($L{HRCLOCK} == 12) { if ($hour > 12) { $hour -= 12; $ampm = $L{PM}; } elsif ($hour == 12) { $ampm = $L{PM}; } else { $ampm = $L{AM}; } $hour = 12 if $hour == 0; } $year += 1900; $week = $DAY[$wday]; $month = $MONTH[$nmonth]; $nmonth += 1; $min = "0$min" if $min < 10; $hour = "0$hour" if $hour < 10; $ls = $L{LONGDATE} if $format eq "long"; $ls = $L{SHORTDATE} if $format eq "short"; $ls = $L{REALSHORTDATE} if $format eq "realshort"; $ls =~ s/\%weekday/$week/g; $ls =~ s/\%hour/$hour/g; $ls =~ s/\%minute/$min/g; $ls =~ s/\%month/$month/g; $ls =~ s/\%nmonth/$nmonth/g; $ls =~ s/\%year/$year/g; $ls =~ s/\%ampm/$ampm/g; $ls =~ s/\%day/$day/g; $ls =~ s/\s+$//; return ($ls); } #---SEPARATOR---# sub get_number { local ($num); &lock("$admin_dir/data.txt"); open(NUMBER,"$admin_dir/data.txt") || &error_message("File Error", "Cannot open data index file ($admin_dir/data.txt)"); $num = ; close(NUMBER); if ($num >= 99999999) { $num = "1"; } else { $num++; } open(NUMBER,">" . "$admin_dir/data.txt") || &error_message("File Error", "Cannot write data index file ($admin_dir/data.txt)"); print NUMBER $num; close(NUMBER); &unlock("$admin_dir/data.txt"); return $num; } #---SEPARATOR---# sub check_owner { local ($user,$owner) = @_; local ($ownit,$line,$curown,$group,@group_data,$username,$group_name); $ownit = 0; &lock("$admin_dir/groups.txt"); open (GROUPFILE, "$admin_dir/groups.txt") || &error_message("Error", "Cannot open group file."); @group_data = ; close (GROUPFILE); &unlock("$admin_dir/groups.txt"); foreach $group (@group_data) { ($username, $group_name) = split(/;/, $group); if ($username eq $user && $owner eq $group_name) { return; } } &error_message("Permissions error", "You are not a member of the group that owns the requested topic!"); } #---SEPARATOR---# sub extract_colorsonly { local ($line, $filename, @file); local (%v,$basefont,$basesize); $filename = "$message_dir/board-topics.html"; open (FILEEXTR, $filename) || &error_message("Extract Error", "Couldn't open top file (board-topics.html)"); @file = ; close (FILEEXTR); foreach $line (@file) { $_ = $line; if (//) { return ($v{'1'},$v{'2'},$v{'3'},$v{'4'},$v{'5'},$2,$1, $v{'6'}); } } return ($v{'1'},$v{'2'},$v{'3'},$v{'4'},$v{'5'}, $v{'6'}); } #---SEPARATOR---# # OBSELETE #---SEPARATOR---# sub update_time { local ($topic_number, $childnum, $thisnum, $datestring, $printeddate, $recursing) = @_; local ($line, @file, $olddate, $parentnum, $filename); $filename = "$message_dir/$topic_number/$thisnum.$ext"; $filename = "$message_dir/board-topics.html" if $thisnum eq "-TOP-"; $secure = 0; &lock($filename); if ($thisnum ne "-TOP-") { local ($head, $color, $lm, $sublist, $about, $about_src, $message, $message_src) = &get_page($topic_number, $thisnum); @sublist = split(/\n/, $sublist); foreach $line (@sublist) { if ($line =~ m|(.*)([^<]+)<|i) { $line = join ("", $`, "$1$printeddate<", $'); } } } $sublist = join("\n", @sublist); &set_page($topic_number, $thisnum, $head, $color, $datestring, $sublist, $about, $about_src, $message, $message_src); if ($head =~ m||) { $parentnum = $1; if ($parentnum ne $thisnum) { &update_time ($topic_number, $thisnum, $parentnum, $datestring, $printeddate, 1); } } } else { open (FILE, "$filename"); @file = ; close (FILE); foreach $line (@file) { if ($line =~ m|/; $topic_number = $1; $line = join ("", $before, "(.*)([^<]+)<|i) { $line = join ("", $`, "$1$printeddate<", $'); } } } open (FILE, ">$filename.NEW"); print FILE @file; close (FILE); if (-e "$filename.NEW") { if ($platform eq "NT" || $NT) { $code = 0; } else { $code = rename("$filename.NEW", "$filename"); } if ($code != 1 || !-e $filename) { open (FILE, ">$filename"); print FILE @file; close (FILE); unlink ("$filename.NEW"); } chmod (0666, "$filename"); } else { &error_message("Update time - Write Error", "Could not open $filename.NEW for reading. Reason: $!!"); } } &unlock($filename); &update_time($topic_number, $topic_number, "-TOP-", $ts, $dt, 1) if $recursing == 0; }