From e76b691e78e273226cba9284cb8cd22a423319ed Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:23:25 -0500 Subject: bucky2 --- bucky2/cgi-bin/api/auto.db | 1 + bucky2/cgi-bin/api/autocomplete | 44 ++++++++++ bucky2/cgi-bin/api/gross.db | 1 + bucky2/cgi-bin/api/index | 40 +++++++++ bucky2/cgi-bin/api/search | 40 +++++++++ bucky2/cgi-bin/api/thread | 61 +++++++++++++ bucky2/cgi-bin/auto.db.1 | Bin 0 -> 5234688 bytes bucky2/cgi-bin/gross.db | Bin 0 -> 6230016 bytes bucky2/cgi-bin/gross.db.1 | Bin 0 -> 6230016 bytes bucky2/cgi-bin/gross.db.old | Bin 0 -> 1912832 bytes bucky2/cgi-bin/history | 44 ++++++++++ bucky2/cgi-bin/images | 44 ++++++++++ bucky2/cgi-bin/poetaster | 105 +++++++++++++++++++++++ bucky2/cgi-bin/search | 184 ++++++++++++++++++++++++++++++++++++++++ bucky2/cgi-bin/svn | 7 ++ 15 files changed, 571 insertions(+) create mode 120000 bucky2/cgi-bin/api/auto.db create mode 100755 bucky2/cgi-bin/api/autocomplete create mode 120000 bucky2/cgi-bin/api/gross.db create mode 100755 bucky2/cgi-bin/api/index create mode 100755 bucky2/cgi-bin/api/search create mode 100755 bucky2/cgi-bin/api/thread create mode 100644 bucky2/cgi-bin/auto.db.1 create mode 100644 bucky2/cgi-bin/gross.db create mode 100644 bucky2/cgi-bin/gross.db.1 create mode 100644 bucky2/cgi-bin/gross.db.old create mode 100755 bucky2/cgi-bin/history create mode 100755 bucky2/cgi-bin/images create mode 100755 bucky2/cgi-bin/poetaster create mode 100755 bucky2/cgi-bin/search create mode 100755 bucky2/cgi-bin/svn (limited to 'bucky2/cgi-bin') diff --git a/bucky2/cgi-bin/api/auto.db b/bucky2/cgi-bin/api/auto.db new file mode 120000 index 0000000..7a5d5c2 --- /dev/null +++ b/bucky2/cgi-bin/api/auto.db @@ -0,0 +1 @@ +../auto.db \ No newline at end of file diff --git a/bucky2/cgi-bin/api/autocomplete b/bucky2/cgi-bin/api/autocomplete new file mode 100755 index 0000000..ac42f06 --- /dev/null +++ b/bucky2/cgi-bin/api/autocomplete @@ -0,0 +1,44 @@ +#!/usr/bin/perl + +use lib "../../lib"; +use Bucky; +use Bucky::Session; +use Bucky::Search; +my $bucky = new Bucky; +my $session = new Bucky::Session; +my $q = $session->param('q'); + +print "Content-type: text/plain\n\n"; + +if (length $q) + { + my $search = new Bucky::Search; + my $guess = $search->autocomplete($q); + my $results = $search->search_light($guess->{'full'}, 0, 40); + # my $terms = $results->{terms}; + + print $guess->{'tail'} || "_"; + print "\n"; + foreach my $result (@{$results->{'results'}}) + { + my $thread = $results->{'threads'}->{ $result->{'thread'} }; + my $comment = $results->{'comments'}->{ $result->{'comment'} }; + my $file = $results->{'files'}->{ $result->{'file'} }; + my $z_thread = $thread->{'id'}; + my $z_title = $thread->{'title'}; + my $z_file = $file->{'id'}; + my $z_subtitle = $file->{'filename'}; + $z_subtitle =~ s/[^a-zA-Z0-9 ()\.]/ /g; + $z_subtitle =~ s/_/ /g; + $z_subtitle =~ s/\s+/ /g; + $z_subtitle =~ s/^\s//; + $z_subtitle =~ s/\s$//; + print join "\t", $z_thread, $z_title, $z_subtitle, $z_file; + print "\n"; + } + } +else + { + print "\n"; + } +1; diff --git a/bucky2/cgi-bin/api/gross.db b/bucky2/cgi-bin/api/gross.db new file mode 120000 index 0000000..00a14d0 --- /dev/null +++ b/bucky2/cgi-bin/api/gross.db @@ -0,0 +1 @@ +../gross.db \ No newline at end of file diff --git a/bucky2/cgi-bin/api/index b/bucky2/cgi-bin/api/index new file mode 100755 index 0000000..306e01e --- /dev/null +++ b/bucky2/cgi-bin/api/index @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +use lib "../../lib"; +use Bucky; +use Bucky::Session; +my $bucky = new Bucky; +# my $session = new Bucky::Session; + +print "Content-type: text/plain\n\n"; + +# get most recent 80 threads +# for each thread, get most recent mp3 +# if no mp3, skip the thread + +my $threads = $bucky->db->select("thread", "order by lastmodified desc limit 80"); + +foreach my $t (@$threads) + { + my $z_thread = $t->{id}; + my $files = $bucky->db->select("file", "thread='$z_thread' and filename like '%mp3' order by date limit 1"); + my $file = {id=>undef,filename=>undef}; + if ($files) + { + $file = $files->[0]; + } + + my $z_title = $bucky->trim( $t->{title} ); + my $z_file = $file->{'id'}; + my $z_subtitle = $file->{'filename'}; + $z_subtitle =~ s/[^a-zA-Z0-9 ()\.]/ /g; + $z_subtitle =~ s/_/ /g; + $z_subtitle =~ s/\s+/ /g; + $z_subtitle =~ s/^\s//; + $z_subtitle =~ s/\s$//; + print join "\t", $z_thread, $z_title, $z_subtitle, $z_file; + print "\n"; + } + +1; + diff --git a/bucky2/cgi-bin/api/search b/bucky2/cgi-bin/api/search new file mode 100755 index 0000000..2bebda8 --- /dev/null +++ b/bucky2/cgi-bin/api/search @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +use lib "../../lib"; +use Bucky; +use Bucky::Session; +use Bucky::Search; +my $bucky = new Bucky; +my $session = new Bucky::Session; +my $q = $session->param('q'); + +print "Content-type: text/plain\n\n"; + +if (length $q) + { + my $search = new Bucky::Search; + my $results = $search->search_light($q, 0, 40); + foreach my $result (@{$results->{'results'}}) + { + my $thread = $results->{'threads'}->{ $result->{'thread'} }; + my $comment = $results->{'comments'}->{ $result->{'comment'} }; + my $file = $results->{'files'}->{ $result->{'file'} }; + my $z_thread = $thread->{'id'}; + my $z_title = $search->bold_terms( $thread->{'title'}, $terms); + my $z_file = $file->{'id'}; + my $z_subtitle = $file->{'filename'}; + $z_subtitle =~ s/[^a-zA-Z0-9 ()\.]/ /g; + $z_subtitle =~ s/_/ /g; + $z_subtitle =~ s/\s+/ /g; + $z_subtitle =~ s/^\s//; + $z_subtitle =~ s/\s$//; + print join "\t", $z_thread, $z_title, $z_subtitle, $z_file; + print "\n"; + } + $search->log_query($query, $total); + } +else + { + print "\n"; + } +1; 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//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; diff --git a/bucky2/cgi-bin/auto.db.1 b/bucky2/cgi-bin/auto.db.1 new file mode 100644 index 0000000..53b26c1 Binary files /dev/null and b/bucky2/cgi-bin/auto.db.1 differ diff --git a/bucky2/cgi-bin/gross.db b/bucky2/cgi-bin/gross.db new file mode 100644 index 0000000..b5a1629 Binary files /dev/null and b/bucky2/cgi-bin/gross.db differ diff --git a/bucky2/cgi-bin/gross.db.1 b/bucky2/cgi-bin/gross.db.1 new file mode 100644 index 0000000..074684d Binary files /dev/null and b/bucky2/cgi-bin/gross.db.1 differ diff --git a/bucky2/cgi-bin/gross.db.old b/bucky2/cgi-bin/gross.db.old new file mode 100644 index 0000000..7182cba Binary files /dev/null and b/bucky2/cgi-bin/gross.db.old differ diff --git a/bucky2/cgi-bin/history b/bucky2/cgi-bin/history new file mode 100755 index 0000000..129d727 --- /dev/null +++ b/bucky2/cgi-bin/history @@ -0,0 +1,44 @@ +#!/usr/bin/perl +use lib "../lib"; +use Bucky; +my $bucky = new Bucky; + +print "Content-type: text/html\n\n"; +my $files = $bucky->db->select("file", "group by thread"); + +my $i = 0; +my $count = 0; +print ""; +foreach my $file (@$files) + { + my $z_thread = $file->{'thread'}; + my $z_img; + if ($file->{'filename'} =~ /(jpg|png|gif)/i) + { + my $ext = $1; + my $username = $file->{'username'}; + my $filename = $file->{'filename'}; + my $lc_filename = lc($file->{'filename'}); + my $label_filename = $filename; + $label_filename =~ s/\.$ext//g; + $label_filename =~ s/\W+/ /g; + $label_filename =~ s/_+/ /g; + $z_img .= ""; + $z_img .= ""; + $z_img .= ""; + $z_img .= "
".$label_filename; + } + next unless $z_img; + if ($i == 0) + { print ""; } + print ""; + $i++; + $count++; + if ($i == 5) + { print "\n"; $i = 0; } + } + print "
"; + print $z_img; + print "
"; + print $count." images found\n"; +1; diff --git a/bucky2/cgi-bin/images b/bucky2/cgi-bin/images new file mode 100755 index 0000000..129d727 --- /dev/null +++ b/bucky2/cgi-bin/images @@ -0,0 +1,44 @@ +#!/usr/bin/perl +use lib "../lib"; +use Bucky; +my $bucky = new Bucky; + +print "Content-type: text/html\n\n"; +my $files = $bucky->db->select("file", "group by thread"); + +my $i = 0; +my $count = 0; +print ""; +foreach my $file (@$files) + { + my $z_thread = $file->{'thread'}; + my $z_img; + if ($file->{'filename'} =~ /(jpg|png|gif)/i) + { + my $ext = $1; + my $username = $file->{'username'}; + my $filename = $file->{'filename'}; + my $lc_filename = lc($file->{'filename'}); + my $label_filename = $filename; + $label_filename =~ s/\.$ext//g; + $label_filename =~ s/\W+/ /g; + $label_filename =~ s/_+/ /g; + $z_img .= ""; + $z_img .= ""; + $z_img .= ""; + $z_img .= "
".$label_filename; + } + next unless $z_img; + if ($i == 0) + { print ""; } + print ""; + $i++; + $count++; + if ($i == 5) + { print "\n"; $i = 0; } + } + print "
"; + print $z_img; + print "
"; + print $count." images found\n"; +1; diff --git a/bucky2/cgi-bin/poetaster b/bucky2/cgi-bin/poetaster new file mode 100755 index 0000000..29bbe3b --- /dev/null +++ b/bucky2/cgi-bin/poetaster @@ -0,0 +1,105 @@ +#!/usr/bin/perl +use lib "../lib"; +use Rest; +use Bucky::Session; +use Poetaster; + +my $session = new Bucky::Session; +my $q = $session->param('q'); +my $id = $session->param('id'); + +if ($id) + { + print header(); + print cache_get($id); + print form(); + print footer(); + } +elsif ($q) + { + print header(); + print poetast($q); + print form(); + print footer(); + } +else + { + print header(); + print form(); + print footer(); + } + +sub poetast + { + my ($q) = @_; + my $data; + if ($q =~ /^http/) + { + $data = Rest->new->rest_get_raw($q); + } + else + { + $data = $q; + } + $data =~ s/<(\/)?(b|i|strong|em)>/[$1$2]/g; + $data =~ s/<[^>]+>//g; + $data =~ s/\[//g; + $data =~ s/[\r\n]+/ /g; + $data =~ s/\s+/ /g; + $data =~ s/\. \. \. /... /g; + my $self = new Poetaster; + my $poem = $self->poem($data); + print "
$poem
"; + print sprintf("%0.1f kb", (length($poem)/1024)); + print "
"; + return; + } +sub poetast_cache_set + { + my ($data) = @_; + my $id; + return $id; + } +sub poetast_cache_get + { + my ($id) = @_; + my $data; + return $data; + } +sub header + { + my ($title) = @_; + if ($title) { $title = "Poetaster: $title" } + else { $title = "Poetaster"; } + return <<__HEADER__; +Content-type: text/html +Pragma: no-cache + + + +Poetaster + + + +
+__HEADER__ + } +sub form + { + return <<__FORM__; +Enter text or a URL: +
+
+ +
+__FORM__ + } +sub footer + { + return <<__FOOTER__; +
+ + +__FOOTER__ + } diff --git a/bucky2/cgi-bin/search b/bucky2/cgi-bin/search new file mode 100755 index 0000000..15a89a6 --- /dev/null +++ b/bucky2/cgi-bin/search @@ -0,0 +1,184 @@ +#!/usr/bin/perl +use lib "../lib"; +use Bucky; +use Data::Dumper; + +my $session = new Bucky::Session; + +my $query = $session->param("q"); + +print <<__BODY__; +Content-type: text/html +Pragma: no-cache + + + + bucky [SEARCH: $query] + + + + + + + +
+ + +
+ +
+ + +
bucky's backwards binoculars
+ + + + + +
+
+
+ +home | post | +ftp | +inbox | +message | +profile | + +logout + + +
+
+
+__BODY__ + +print <<__SEARCH_FORM__; +
+ + + + + + + +__SEARCH_FORM__ + +if ($query) +{ +my $start = $session->param("start"); +my $limit = $session->param("limit"); + +my $search = new Bucky::Search; +my $results = $search->search($query, $start, $limit); + +my $terms = $results->{'terms'}; +my $r = 0; + +my $z_last_start = $results->{'start'} - $results->{'limit'} + 1; +my $z_start = $results->{'start'}; +my $z_limit = $results->{'limit'}; +my $z_upto = $z_last_start + $z_limit - 1; +my $z_total = $results->{'total'}; +my $z_next; + +if ($results->{'total'} == 0) + { + my $z_next = "
No Results!
"; + print ""; + } +else + { + $z_next = "displaying $z_last_start-$z_upto of $z_total results ..."; + if ($z_start < $z_total) + { + $z_next .= " next page >>"; + } + } +print "" if $z_next; +foreach my $result (@{$results->{'results'}}) + { + $r = $r ? 0 : 1; + my $thread = $results->{'threads'}->{ $result->{'thread'} }; + my $comment = $results->{'comments'}->{ $result->{'comment'} }; + my $file = $results->{'files'}->{ $result->{'file'} }; + + my $z_thread = $thread->{'id'}; + my $z_username = $thread->{'username'}; + my $z_title = $search->bold_terms( $thread->{'title'}, $terms); + my $z_comment = $search->bold_snippet( $comment->{'comment'}, $terms); + my $z_filename = $file->{'filename'}; + my $z_file = $search->bold_terms( $z_filename, $terms); + my $z_date = scalar localtime $thread->{'createdate'}; + my $z_strength = $result->{'strength'} . "x" . $result->{'count'}; + my $z_bigs = $result->{'count'} > ( scalar(@$terms) - 3 ) + ? "" : ""; + my $z_unbigs = $result->{'count'} > ( scalar(@$terms) - 3 ) + ? "" : ""; + my $z_img; + if ($file && $file->{'filename'} =~ /jpg/i) + { + my $filename = lc($file->{'filename'}); + $z_img = "" if $filename; + } + elsif ($thread->{'flagged'}) + { + my $file = $results->{'files'}->{ $thread->{'flagged'} }; + my $filename = lc($file->{'filename'}); + $z_img = "" if $filename; + } + my $z_color = "c"; + $z_color .= $r; + my $z_filelink = "$z_file" if $z_file; + + print <<__RESULT__; + + + + + +__RESULT__ +# print Dumper($result); + } +print "" if $z_next; +} + +print <<__FOOTER__; +
  +
+ + +
+ + + +
+
+
 
 $z_next 
 $z_next 
+$z_img + +$z_bigs$z_title$z_unbigs
+$z_strength   posted by $z_username | $z_date
+
$z_filelink $z_comment
+
 $z_next 
+
+ + + + + + + +
+ + + + + +__FOOTER__ +1; diff --git a/bucky2/cgi-bin/svn b/bucky2/cgi-bin/svn new file mode 100755 index 0000000..dcc409d --- /dev/null +++ b/bucky2/cgi-bin/svn @@ -0,0 +1,7 @@ +#!/usr/bin/perl +use lib "../lib"; +use Bucky::SVN; +my $svn = new Bucky::SVN; + +$svn->query_incoming; + -- cgit v1.2.3-70-g09d2