diff --git a/trunk/README_DATABASE b/trunk/README_DATABASE index 073a9e1..ccbb364 100644 --- a/trunk/README_DATABASE +++ b/trunk/README_DATABASE @@ -9,5 +9,5 @@ eg.: insert into tagcloud values ('web tv', 68); create table users (id int auto_increment not null, username varchar(255) not null, password char(41) not null, primary key (id)); -create table videos (id int auto_increment not null, title varchar(255) not null, userid varchar(255) not null, hash char(64) not null, status int not null, primary key (id)); +create table videos (id int auto_increment not null, title varchar(255) not null, caption text, userid varchar(255) not null, hash char(64) not null, status int not null, primary key (id), fulltext (title, caption)); diff --git a/trunk/include.pl b/trunk/include.pl index b0a79bf..b9c9a50 100644 --- a/trunk/include.pl +++ b/trunk/include.pl @@ -2,7 +2,8 @@ use CGI qw(:standard); use CGI::Session; use DBI; use XML::Simple qw(:strict); -use Digest::SHA qw(sha256_hex); +use Digest::SHA; +#use Digest::SHA qw(sha256_hex); #set global variables $database = 'gnutube'; diff --git a/trunk/search.pl b/trunk/search.pl new file mode 100644 index 0000000..58598d7 --- /dev/null +++ b/trunk/search.pl @@ -0,0 +1,57 @@ +require "/var/www/perl/include.pl"; +require "/var/www/perl/functions.pl"; + +#initialize session data +CGI::Session->name($session_name); +$query = new CGI; +$session = new CGI::Session; + +#check if query is set +if($query->param('query')) { + my $search_query = $query->param('query'); + + $page = XMLin('/var/www/perl/search.xml', ForceArray => 1, KeyAttr => {} ); + + #if a username is associated with session id, username is nonempty + $page->{username} = get_username_from_sid($session->id); + + $page->{results}->{query} = $query->param('query'); + + #connect to db + my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr; + + #prepare query + my $sth = $dbh->prepare(qq{select title, caption from videos where match(title, caption) against('$search_query') }) or die $dbh->errstr; + + #execute it + $sth->execute() or die $dbh->errstr; + + #get every returned value + while (my ($title, $caption) = $sth->fetchrow_array()) + { + #really ofuscated array/hash creation + push @{ $page->{'results'}->{'result'} }, { 'thumbnail' => ['./video-stills/225x150/4chan_city_mashup.png'], + 'rdf:RDF' => { 'cc:Work' => { 'rdf:about' => './videos/1050x700/4chan_city_mashup.ogg', + 'dc:title' => [$title] + }, + 'cc:License' => { 'rdf:about' => 'http://creativecommons.org/licenses/GPL/2.0/' + } + } + }; + } + + #finish query + $sth->finish() or die $dbh->errstr; + + #close db + $dbh->disconnect() or die $dbh->errstr; + + #print xml http header along with session cookie + print $session->header(-type=>'text/xml'); + + #print xml + print XMLout($page, KeyAttr => {}, XMLDecl => '', RootName => 'page'); +} else { + print $session->header(); + print "no query passed"; +} diff --git a/trunk/search.xml b/trunk/search.xml new file mode 100755 index 0000000..b0ed861 --- /dev/null +++ b/trunk/search.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/trunk/uploader.pl b/trunk/uploader.pl index b85d619..0933bac 100644 --- a/trunk/uploader.pl +++ b/trunk/uploader.pl @@ -23,14 +23,16 @@ if($userid) { #save POST data in local variables my $title = $query->param("title"); + my $caption = $query->param("caption"); #video status: - # 0 - fresh upload - needs conversion - # 1 - successfully converted - # 2 - error: was not a valid video/format - # 3 - error: video is a duplicate + # 0 - new entry - nothing done yet + # 1 - successfully uploaded + # 2 - successfully converted + # 3 - error: was not a valid video/format + # 4 - error: video is a duplicate #do query - $dbh->do(qq{insert into videos (title, userid, status) values ('$title', '$userid', 0)}) or die $dbh->errstr; + $dbh->do(qq{insert into videos (title, caption, userid, status) values ('$title', '$caption', '$userid', 0)}) or die $dbh->errstr; #prepare query my $sth = $dbh->prepare(qq{select last_insert_id() }) or die $dbh->errstr; diff --git a/trunk/xsl/xhtml.xsl b/trunk/xsl/xhtml.xsl index d6bf83a..e5461a7 100755 --- a/trunk/xsl/xhtml.xsl +++ b/trunk/xsl/xhtml.xsl @@ -20,7 +20,7 @@ -results.pl?query= +search.pl?query=