summaryrefslogtreecommitdiff
path: root/bucky2/cgi-bin/api/thread
diff options
context:
space:
mode:
authorJules Laplace <carbon@melanarchy.org>2013-08-02 17:23:25 -0500
committerJules Laplace <carbon@melanarchy.org>2013-08-02 17:23:25 -0500
commite76b691e78e273226cba9284cb8cd22a423319ed (patch)
treea58d22f69869fe2bf3885f81bdda4952f87ff6d7 /bucky2/cgi-bin/api/thread
parent753f60c7d4769fa72d3b910e491f37db6f130898 (diff)
bucky2
Diffstat (limited to 'bucky2/cgi-bin/api/thread')
-rwxr-xr-xbucky2/cgi-bin/api/thread61
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;