2007-10-11 17:06:08 +00:00
|
|
|
require "include.pl";
|
|
|
|
require "functions.pl";
|
2007-10-11 14:59:55 +00:00
|
|
|
|
|
|
|
#initialize session data
|
|
|
|
CGI::Session->name($session_name);
|
|
|
|
$query = new CGI;
|
|
|
|
$session = new CGI::Session;
|
|
|
|
|
|
|
|
#check if query is set
|
2007-10-11 17:26:39 +00:00
|
|
|
if($query->param('query'))
|
|
|
|
{
|
2007-10-12 11:18:13 +00:00
|
|
|
%page = ();
|
2007-10-11 14:59:55 +00:00
|
|
|
|
|
|
|
#if a username is associated with session id, username is nonempty
|
2007-10-12 11:18:13 +00:00
|
|
|
$page->{'username'} = get_username_from_sid($session->id);
|
|
|
|
$page->{'locale'} = $locale;
|
|
|
|
$page->{'stylesheet'} = $stylesheet;
|
|
|
|
$page->{'xmlns:dc'} = $xmlns_dc;
|
|
|
|
$page->{'xmlns:cc'} = $xmlns_cc;
|
|
|
|
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
2007-10-11 14:59:55 +00:00
|
|
|
|
2007-10-12 10:37:02 +00:00
|
|
|
$page->{results}->{query} = decode_utf8($query->param('query'));
|
2007-10-11 14:59:55 +00:00
|
|
|
|
|
|
|
#connect to db
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#prepare query
|
2007-10-18 09:53:32 +00:00
|
|
|
my $sth = $dbh->prepare(qq{select id, title, description, userid, timestamp from videos where match(title, description) against( ? ) }) or die $dbh->errstr;
|
2007-10-11 14:59:55 +00:00
|
|
|
|
|
|
|
#execute it
|
2007-10-12 10:37:02 +00:00
|
|
|
$sth->execute($query->param('query')) or die $dbh->errstr;
|
2007-10-11 14:59:55 +00:00
|
|
|
|
|
|
|
#get every returned value
|
2007-10-18 09:53:32 +00:00
|
|
|
while (my ($id, $title, $description, $userid, $timestamp) = $sth->fetchrow_array())
|
2007-10-11 14:59:55 +00:00
|
|
|
{
|
2007-10-15 00:25:23 +00:00
|
|
|
#before code cleanup, this was a really obfuscated array/hash creation
|
2007-10-11 16:29:13 +00:00
|
|
|
push @{ $page->{'results'}->{'result'} },
|
|
|
|
{
|
2007-10-15 00:25:23 +00:00
|
|
|
'thumbnail' => ['./video-stills/225x150/4chan_city_mashup.png'],
|
|
|
|
'rdf:RDF' =>
|
2007-10-11 16:29:13 +00:00
|
|
|
{
|
2007-10-15 00:25:23 +00:00
|
|
|
'cc:Work' =>
|
2007-10-11 16:29:13 +00:00
|
|
|
{
|
2007-10-18 08:20:28 +00:00
|
|
|
'rdf:about' => "./video.pl?title=$title&id=$id",
|
2007-10-15 00:25:23 +00:00
|
|
|
'dc:title' => [$title],
|
|
|
|
'dc:date' => [$timestamp],
|
|
|
|
'dc:publisher' => [get_username_from_id($userid)]
|
2007-10-11 16:29:13 +00:00
|
|
|
},
|
2007-10-15 00:25:23 +00:00
|
|
|
'cc:License' =>
|
2007-10-11 16:29:13 +00:00
|
|
|
{
|
2007-10-15 00:25:23 +00:00
|
|
|
'rdf:about' => 'http://creativecommons.org/licenses/GPL/2.0/'
|
2007-10-11 16:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2007-10-11 14:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#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
|
2007-10-11 23:47:13 +00:00
|
|
|
print XMLout($page, KeyAttr => {}, XMLDecl => $XMLDecl, RootName => 'page');
|
2007-10-11 17:26:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-11 14:59:55 +00:00
|
|
|
print $session->header();
|
|
|
|
print "no query passed";
|
|
|
|
}
|