diff options
Diffstat (limited to 'bucky2/cgi-bin/api/thread')
| -rwxr-xr-x | bucky2/cgi-bin/api/thread | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/bucky2/cgi-bin/api/thread b/bucky2/cgi-bin/api/thread new file mode 100755 index 0000000..3c7def9 --- /dev/null +++ b/bucky2/cgi-bin/api/thread @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +use lib "../../lib"; +use Bucky; +use Bucky::Session; +my $bucky = new Bucky; +my $session = new Bucky::Session; +my $id = $session->param('id'); + +print "Content-type: text/plain\n\n"; +if (length $id && $id !~ /\D/) + { + my $thread = $bucky->db->select("thread", "id='$id'"); + my $files = $bucky->db->select("file", "thread='$id' order by filename asc"); + my $comment = $bucky->db->select("comment", "thread='$id' order by id asc"); + exit unless ref($thread) == "ARRAY"; + my $t = shift @$thread; + + my $flagged = $t->{'flagged'}; + + my @result = (); + + my $i = 0; + my $count = 0; + foreach my $file (@$files) + { + if (! $flagged && $file->{'filename'} =~ /(jpg|jpeg|gif|png)/i) + { + $flagged = $file->{'id'}; + } + $file->{'filename'} =~ /\.(...)$/i; + $file->{'type'} = lc $1 || next; + $file->{'title'} = $file->{'filename'}; + $file->{'title'} =~ s/\.(...)$//; + $file->{'title'} =~ s/_/ /g; + $file->{'title'} =~ s/-/ /g; + $file->{'title'} =~ s/\s+/ /g; + $file->{'title'} =~ s/^\s//; + $file->{'title'} =~ s/\s$//; + push @result, join("\t", @$file{qw[id type filename title date size]}); + } + if (ref($comment) == "ARRAY" && scalar(@$comment)) + { + my $c = shift @$comment; + my $words = $c->{'comment'}; + $words =~ s/\n/<br\/>/g; + $words =~ s/\r//g; + push @result, $c->{id}."\tcomment\t".$c->{username}."\t".$c->{date}."\t".$words; + } + $t->{'flagged'} ||= $flagged; + + print join "\t", @$t{qw[id title flagged createdate username keyword]}; + print "\n"; + print join "\n", @result; + print "\n"; + } +else + { + print "\n"; + } +1; |
