summaryrefslogtreecommitdiff
path: root/cgi-bin/post
blob: fd2de78b195065e4484064a0c12e60b997ce86f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/perl
#########################################
# post
#    - create a new thread/post from an initial file
#    - form: append multiple files
#########################################

use localbucky;

my $pid;

$dbh = DBI->connect ($dsn);

our ($USER, $lastlog) = checkin();
logout() unless ($USER != -1);

if ($input->{c} eq 'new')
  { new_post_action(); }
elsif ($input->{c} eq 'reply')
  { reply_post_action(); }
else
  { long_post_form(); }

#################################

sub long_post_form
    {
  my $t = -1;
  my $k = -1;
  if ( exists($input->{thread}) )
    {
    my $header_args;

    $t = get_thread( $input->{thread} );
    $k = get_keyword( $t->{keyword} );

    error("No such post!")    unless ($t != -1);
    error("No such keyword!") unless ($k == -1 || ($k->{public} || check_op($k)));

    $header_args->{title}    = qq(reply to $t->{title});
    $header_args->{subtitle} = qq(<span class="lite"><a href="$BUCKY/).details_link($t).qq($t->{id}">return to post</a></span>);

    header ($header_args);
    }
  elsif ( exists($input->{keyword}) )
    {
    my $header_args;

    $k = get_keyword( $input->{keyword} );

    if ($k != -1 && (($k->{public} || check_op($k))))
      {
      $header_args->{title}    = qq(new $k->{keyword});
      $header_args->{subtitle} = qq(<span class="lite"><a href=").keyword_link($k).qq(">return to $BUCKY_LEXICON_KEYWORD</a></span>);
      header ($header_args);
      }
    else
      {
      header("Creating a new post...");
      }
    }
  else
    {
    header("Creating a new post...");
    }

    menu();
  print "<p>\n\n";
  my $checked = '';

  print qq(<form action="$BUCKY/post" method="post" enctype="multipart/form-data">\n);
  print qq!<input type="hidden" name="debug" value="$DEBUG">\n\n! if ($DEBUG);

  print <<FORMmid;
<center>
<table cellpadding=0 cellspacing=0 border=0>
<tr><td class="bluebox" style="padding: 20px 40px 20px 40px;">
FORMmid

  if ($t != -1)
    {
    print qq!<input type="hidden" name="c" value="reply">!;
    print qq!<input type="hidden" name="thread" value="$t->{id}">!;
    print qq!<table border=0 width=100%><tr><td style="text-align: right; vertical-align: center;">replying to:</td><td align="center"><b><big><a href="$BUCKY/!.details_link($t).qq!/$t->{id}">$t->{title}</a></big></b><br>posted !.verbosedate($t->{createdate}).qq! by <a href="$BUCKY/profile/$t->{username}">$t->{username}</a></td></tr></table>!;
    }
  else
    {
    print qq!<table cellpadding=2 border=0>!;
    print qq!<tr><td align="right" valign="baseline">!;
    print qq!title:&nbsp;!;
    print qq!</td><td align="left" valign="baseline">!;
    print qq!<input name="title" value="" size=48 maxlength=48><br>\n!;
    print qq!</tr>!;
    print qq!<tr><td align="right" valign="baseline">!;
    print "category: ";
    print qq!</td><td align="left" valign="baseline">!;
    if ($k->{public} || check_op($k))
      {
      keyword_pulldown($k->{keyword});
      $checked = $k->{public} ? "" : " checked";
      }
    else
      { keyword_pulldown(); }
    print qq!</tr>!;
    print qq!<tr><td align="right" valign="baseline">!;
    print qq!tags:&nbsp;!;
    print qq!</td><td align="left" valign="baseline">!;
    print qq!<input name="tags" value="" size=30 maxlength=48><br>\n!;
    print qq!</tr>!;
    print qq!<tr><td align="right" valign="middle">!;
    print qq!publicity:!;
    print qq!</td><td align="left" valign="middle">!;
    # don't need this
    # print qq!<input type=checkbox name="private" value="1"$checked>!
    privacy_select("private", $checked);
    print qq!</td></tr>!;
    print qq!<tr><td></td><td align="left" valign="top">!;
    print qq!<small>(can be changed at any time via post settings)</small>\n!;
    print qq!</td></tr>!;
    print qq!<tr><td align="right" valign="baseline">!;
    print qq!</table>!;
    print qq!<input type="hidden" name="c" value="new">!;
    }

  print qq!<hr color="$BUCKY_COLOR_HR" size=1>!;
  print qq!<p><textarea name="comment" cols="52" rows="16"></textarea><p>\n!;

  if (! check_key($t->{display}, "no-upload"))
    {
    print <<FORMEND;
<input type="file" name="file1" size="12" maxlength="192" style="font-size: 10px; font-family: Trebuchet MS, Helvetica, Arial, sans-serif;" /> <input type="file" name="file2" size="12" maxlength="192" style="font-size: 10px; font-family: Trebuchet MS, Helvetica, Arial, sans-serif;" /> <input type="file" name="file3" size="12" maxlength="192" style="font-size: 10px; font-family: Trebuchet MS, Helvetica, Arial, sans-serif;" /><br>
<input type="file" name="file4" size="12" maxlength="192" style="font-size: 10px; font-family: Trebuchet MS, Helvetica, Arial, sans-serif;" /> <input type="file" name="file5" size="12" maxlength="192" style="font-size: 10px; font-family: Trebuchet MS, Helvetica, Arial, sans-serif;" /> <input type="file" name="file6" size="12" maxlength="192" style="font-size: 10px; font-family: Trebuchet MS, Helvetica, Arial, sans-serif;" /><br>
<input type="file" name="file7" size="12" maxlength="192" style="font-size: 10px; font-family: Trebuchet MS, Helvetica, Arial, sans-serif;" /> <input type="file" name="file8" size="12" maxlength="192" style="font-size: 10px; font-family: Trebuchet MS, Helvetica, Arial, sans-serif;" /> <input type="file" name="file9" size="12" maxlength="192" style="font-size: 10px; font-family: Trebuchet MS, Helvetica, Arial, sans-serif;" /><p>
FORMEND
    }
  print qq(<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td width=90% align="center"><small>);
#  if ($t != -1)
#    { print qq(remember! you can always use <a href="$BUCKY/import?id=$t->{id}"><u><b>ftp</b></u></a> to upload files . . .); }
#  else
#    { print qq(remember! you can always use <a href="$BUCKY/import"><u><b>ftp</b></u></a> to upload files . . .); }
  print "&nbsp;";
  print <<FORMEND;
</small></td>
<td align="left"><input type="submit" value="POST" class="clicky"></td></tr></table>
</form>
</td></tr></table>
</center>
FORMEND
        footer();
        }

sub new_post_action
  {
  my $files;
  my $title = '';
  my $private = 0;
  my $k;

  $k = get_keyword($input->{keyword}) if (exists($input->{keyword}) && ($input->{keyword} ne "NONE"));

  if ($input->{title})
    {
    $title = $input->{title};
    $title =~ s/^\s+//;
    $title =~ s/\s+/ /g;
    $title =~ s/_/ /g;
    }
  else
    {
    for (my $i = 1; $i < 10; $i++)
      {
      if ($input->{"file".$i} ne "temp_")
        {
        $title = $input->{"file".$i};
        $i = 11;
        }
      }
    if ($title)
      {
      $title =~ s/^temp_//i;
      $title =~ s/\.....?$//;
      $title =~ s/^\s+//;
      $title =~ s/\s+/ /g;
      $title =~ s/_/ /g;
      }
    elsif ($$input{"comment"})
      {
      $title = "dER buCKYiSt ***cHaTTEN**** AUF ZZem *AwL**";
      }
    else
      {
      error ("No title specified!");
      }
    }

  if ($DEBUG)
    {
    header("new post");
    print "attempting to make a new post: $title<p>";
    }

  $private = $input->{private} if ($input->{private});

  $thread_id = add_thread($title, $USER->{username}, $private);
  print "id: $thread_id<p>" if ($DEBUG);
  add_comment($thread_id,-1,$USER->{username},$$input{comment});
  situate_files($thread_id, $USER->{username});
  switch_thread_privacy($thread_id, $private);
  if ($k->{public} || check_op($k))
    {
    keyword_assign_mechanism($k->{keyword}, $thread_id, $k);
    }

  # Check for any supplied tags
  if (exists($input->{tags}) && (length(trim($input->{tags}) ) > 0) )
    {
    # Unpack tags from the form text field (remove delimiters, retrieve already existing tags, 
    # create new tags
    my $tags = get_tags_from_string( $input->{tags} );

    # Loop through each tag
    foreach my $tag (@$tags)
      {
      # should we even get this??
#      next unless ($tag->{public} || check_op($tag));

      # Associate this tag with this thread
      tag_assign_mechanism( $tag, $thread_id );
      }
    }

  if ($DEBUG)
    {
    print qq{this way to your new post: <a href="$BUCKY/details/$thread_id">link!</a>};
         footer();
    }

  if ($k != -1)
    {
    redirect("$BUCKY/".details_link($k)."/$thread_id");
    }
  else
    {
    redirect("$BUCKY/$BUCKY_LEXICON_DETAILS/$thread_id");
    }
  }

sub reply_post_action
  {
  if ($DEBUG)
    {
    header("posting to $input->{thread}");
    }
  my $thread = (exists($input->{thread})) ? get_thread($input->{thread}) : error("No such thread!");
  my $keyword = ($thread->{keyword}) ? get_keyword($thread->{keyword}) : -1;
  error("Cannot see comment!") unless (check_privacy($thread) || check_op($keyword));

  print "id: $thread->{id}<p>" if ($DEBUG);
  add_comment($thread->{id}, -1, $USER->{username}, $input->{comment}) if ($input->{comment} ne undef);
  situate_files($thread->{id}, $USER->{username});
  switch_thread_privacy($thread->{id}, $thread->{private});
  redirect("$BUCKY/".details_link($thread)."/$thread->{id}");
  }

$dbh->disconnect ();

print "Post: " . &report_time() . "\n" if $timer;