home *** CD-ROM | disk | FTP | other *** search
/ Complete Internet Archive / Complete Internet Archive.iso / Web Boards / WebForum_tar(2).Z / WebForum_tar(2) / WebForum / src / mkmsg.pl < prev    next >
Encoding:
Text File  |  1995-01-19  |  2.9 KB  |  104 lines

  1. #
  2. # Create a new message
  3. #
  4. # Copyright (C) 1994 Afzal Ballim
  5.  
  6. ############################################################
  7. #
  8. # WFCommandMkmsg:
  9. #
  10. sub WFCommandMkmsg {
  11. require "ctime.pl";
  12.  
  13. # SPECIAL CASE!!! We want mkmsg to change the $in{subject}
  14. # to an encoded form, so don't have local %in
  15. %in=@_;
  16.  
  17. $date=&ctime(time);chop $date;
  18. $user=$ENV{"REMOTE_USER"};
  19. %mb=&WFReadDBFile($user);
  20.  
  21. if ($in{"forum"} eq "") {return "No forum given";}
  22. if ($in{"subject"} eq "") {return "No subject given";}
  23. if ($user eq "guest" && $in{"forum"} ne "WebForum%2ediscussion")
  24.     {return "Guests may not post here";}
  25.  
  26. local ($subject)=$in{"subject"};
  27. $in{"subject"}=&WFEncodeDatum($subject);
  28.  
  29. if (!-d "ABSWFSPOOL/$in{forum}/$in{subject}") {
  30.     mkdir("ABSWFSPOOL/$in{forum}/$in{subject}",0777)
  31.     ||return "Couldn't create the subject $forumdec/$subjectdec";
  32. }
  33.  
  34. # work out the article number
  35. $artno=++$mb{"numposts"};
  36. if (!&WFWriteDBFile($user,%mb)) {return "Could not update user file\n";}
  37.  
  38. if ($in{"message"} ne "") {
  39.  $aname=sprintf("$in{message}$user#%6.6d;",$artno);
  40. } else {
  41.  $aname=sprintf("$user#%6.6d;",$artno);
  42. }
  43.  
  44. if ($in{"mtype"} ne "html") {
  45.     # insulate the text by replacing the 3 special characters
  46.     # with their reference entity forms.
  47.     $in{"body"} =~ s/&/&\;/g;
  48.     $in{"body"} =~ s/</<\;/g;
  49.     $in{"body"} =~ s/>/>\;/g;
  50.     $in{"body"} = 
  51. "<pre>
  52. $in{body}
  53. </pre>";
  54. }
  55.  
  56. $msg{"body"}=$in{"body"};
  57. $msg{"poster"}="$user ($mb{username})";
  58. $msg{"email"}="<a href=mailto:$mb{email}>$mb{email}</a>";
  59. $msg{"hurl"}="<a href=$mb{homeurl}>$mb{homeurl}</a>";;
  60. $msg{"xref"}=$in{"message"};
  61. $msg{"date"}=$date;
  62. $msg{"expiry"}=$in{"expiry"};
  63.  
  64. # having some weird values passed for expiry, so catch them here
  65. if ($msg{"expiry"} =~ /([0-9]+) days/) {$msg{"expiry"} = "$1 days";}
  66. elsif ($msg{"expiry"} =~ /never/) {$msg{"expiry"} = "never";}
  67. else {$msg{"expiry"} = "7 days";}
  68.  
  69. &WFPutFile("ABSWFSPOOL/$in{forum}/$in{subject}/$aname",%msg);
  70.  
  71. print "<b>Message Posted</b><p><hr>";
  72.  
  73. # now, check to see if the forum has a control file
  74. # with an aux-post method
  75. if ($ENV{"REQUEST_NO_AUX_POST"} ne "YES"
  76.     && -r "ABSWFSPOOL/$in{forum}/.control") {
  77.  local (%cf)= &WFReadAVFile("ABSWFSPOOL/$in{forum}/.control");
  78.  local ($cfap) = $cf{"aux-post"};
  79.  if ($cfap ne "") {
  80.     local (*AP);
  81.     open(AP,"|ABSWFCTRLBIN/$cfap") ||
  82.      return "Couldn't execute auxiliary post method $cfap";
  83.  
  84.     $in{"body"} =~ s/<pre>\n?//;
  85.     $in{"body"} =~ s/<\/pre>\n?//;
  86.     print AP $cf{"aux-post-args"},"\n";
  87.     print AP "user=", &WFEncodeDatum($user),"\n";
  88.     print AP "username=", &WFEncodeDatum($mb{"username"}),"\n";
  89.     print AP "email=", &WFEncodeDatum($mb{"email"}),"\n";
  90.     print AP "hurl=", &WFEncodeDatum($mb{"homeurl"}),"\n";
  91.     print AP "xref=", &WFEncodeDatum($in{"message"}),"\n";
  92.     print AP "expiry=", &WFEncodeDatum($mb{"expiry"}),"\n";
  93.     print AP "date=", &WFEncodeDatum($date),"\n";
  94.     print AP "subject=", $in{"subject"},"\n";
  95.     print AP "body=", &WFEncodeDatum($in{"body"}),"\n";
  96.     close(AP);
  97.  }
  98. }
  99.  
  100. return "";
  101. }
  102.  
  103. 1;
  104.