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