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;
|
|
|
|
|
2007-10-27 11:59:23 +00:00
|
|
|
$username = get_username_from_sid($session->id);
|
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
%page = ();
|
2007-10-27 11:59:23 +00:00
|
|
|
|
|
|
|
$page->{'username'} = $username;
|
2007-10-26 00:35:29 +00:00
|
|
|
$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
|
|
|
#check if query is set
|
2007-10-26 00:35:29 +00:00
|
|
|
if($query->param('query') or $query->param('orderby'))
|
2007-10-11 17:26:39 +00:00
|
|
|
{
|
2007-10-27 11:59:23 +00:00
|
|
|
$page->{'results'}->{'scriptname'} = 'search.pl';
|
|
|
|
$page->{'results'}->{'argument'} = 'query';
|
|
|
|
$page->{'results'}->{'value'} = $query->param('query');
|
|
|
|
$page->{'results'}->{'orderby'} = $query->param('orderby');
|
|
|
|
$page->{'results'}->{'sort'} = $query->param('sort');
|
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;
|
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
my @args = ();
|
2007-10-11 14:59:55 +00:00
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
#build mysql query
|
2007-10-26 12:51:00 +00:00
|
|
|
$dbquery = "select v.id, v.title, v.creator, v.description, u.username, from_unixtime( v.timestamp ), v.duration, v.viewcount";
|
2007-10-18 11:47:50 +00:00
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
if($query->param('query'))
|
2007-10-18 11:47:50 +00:00
|
|
|
{
|
2007-10-26 00:35:29 +00:00
|
|
|
$dbquery .= ", match(v.title, v.description, v.subject) against( ? in boolean mode) as relevance";
|
|
|
|
$dbquery .= " from videos as v, users as u where u.id = v.userid";
|
|
|
|
$dbquery .= " and match(v.title, v.description, v.subject) against( ? in boolean mode)";
|
|
|
|
push @args, $query->param('query'), $query->param('query');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$dbquery .= " from videos as v, users as u where u.id = v.userid";
|
|
|
|
}
|
|
|
|
|
|
|
|
if($query->param('orderby'))
|
|
|
|
{
|
|
|
|
if($query->param('orderby') eq 'filesize')
|
2007-10-18 11:47:50 +00:00
|
|
|
{
|
2007-10-26 00:35:29 +00:00
|
|
|
$dbquery .= " order by v.filesize";
|
|
|
|
}
|
|
|
|
elsif($query->param('orderby') eq 'duration')
|
|
|
|
{
|
|
|
|
$dbquery .= " order by v.duration";
|
|
|
|
}
|
|
|
|
elsif($query->param('orderby') eq 'viewcount')
|
|
|
|
{
|
|
|
|
$dbquery .= " order by v.viewcount";
|
|
|
|
}
|
|
|
|
elsif($query->param('orderby') eq 'downloadcount')
|
|
|
|
{
|
|
|
|
$dbquery .= " order by v.downloadcount";
|
|
|
|
}
|
|
|
|
elsif($query->param('orderby') eq 'timestamp')
|
|
|
|
{
|
|
|
|
$dbquery .= " order by v.timestamp";
|
|
|
|
}
|
|
|
|
elsif($query->param('orderby') eq 'relevance' and $query->param('query'))
|
|
|
|
{
|
|
|
|
$dbquery .= " order by relevance";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$dbquery .= " order by v.id";
|
|
|
|
}
|
|
|
|
|
|
|
|
if($query->param('sort') eq "asc")
|
|
|
|
{
|
|
|
|
$dbquery .= " asc"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$dbquery .= " desc"
|
|
|
|
}
|
2007-10-18 11:47:50 +00:00
|
|
|
}
|
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
#prepare query
|
|
|
|
my $sth = $dbh->prepare($dbquery) or die $dbh->errstr;
|
2007-10-18 11:47:50 +00:00
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
#execute it
|
2007-10-27 11:59:23 +00:00
|
|
|
$resultcount = $sth->execute(@args) or die $dbh->errstr;
|
2007-10-18 11:47:50 +00:00
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
$rowsperpage = 2;
|
2007-10-18 11:47:50 +00:00
|
|
|
|
2007-10-26 12:51:00 +00:00
|
|
|
#rediculous but funny round up, will fail with 1000000000000000 results per page
|
|
|
|
#on 0.00000000000001% of all queries - this is a risk we can handle
|
|
|
|
$lastpage = int($resultcount/$rowsperpage+0.999999999999999);
|
2007-10-18 11:47:50 +00:00
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
$currentpage = $query->param('page') or $currentpage = 1;
|
2007-10-18 11:47:50 +00:00
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
$dbquery .= " limit ".($currentpage-1)*$rowsperpage.", ".$rowsperpage;
|
2007-10-18 11:47:50 +00:00
|
|
|
|
|
|
|
#prepare query
|
2007-10-26 00:35:29 +00:00
|
|
|
$sth = $dbh->prepare($dbquery) or die $dbh->errstr;
|
2007-10-18 11:47:50 +00:00
|
|
|
|
|
|
|
#execute it
|
2007-10-26 00:35:29 +00:00
|
|
|
$sth->execute(@args) or die $dbquery;
|
|
|
|
|
|
|
|
$page->{'results'}->{'lastpage'} = $lastpage;
|
|
|
|
$page->{'results'}->{'currentpage'} = $currentpage;
|
2007-10-26 12:51:00 +00:00
|
|
|
$page->{'results'}->{'resultcount'} = $resultcount;
|
2007-10-11 14:59:55 +00:00
|
|
|
|
|
|
|
#get every returned value
|
2007-10-27 11:59:23 +00:00
|
|
|
while (my ($id, $title, $creator, $description, $publisher, $timestamp, $duration, $viewcount, $relevance) = $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-26 12:51:00 +00:00
|
|
|
'thumbnail' => "./video-stills/$id",
|
|
|
|
'duration' => $duration,
|
|
|
|
'viewcount' => $viewcount,
|
2007-10-27 11:59:23 +00:00
|
|
|
'edit' => $username eq $publisher ? "true" : "false",
|
2007-10-15 00:25:23 +00:00
|
|
|
'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-26 12:51:00 +00:00
|
|
|
'rdf:about' => "$domain/download/$id",
|
|
|
|
'dc:title' => [$title],
|
|
|
|
'dc:creator' => [$creator],
|
|
|
|
'dc:date' => [$timestamp],
|
|
|
|
'dc:identifier' => ["$domain/video/$title/$id"],
|
2007-10-27 11:59:23 +00:00
|
|
|
'dc:publisher' => [$publisher]
|
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;
|
2007-10-11 17:26:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-21 22:55:29 +00:00
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_202c";
|
2007-10-11 14:59:55 +00:00
|
|
|
}
|
2007-10-27 09:17:30 +00:00
|
|
|
|
|
|
|
#print xml http header along with session cookie
|
|
|
|
print $session->header(-type=>'text/xml', -charset=>'UTF-8');
|
|
|
|
|
|
|
|
#print xml
|
|
|
|
print XMLout($page, KeyAttr => {}, XMLDecl => $XMLDecl, RootName => 'page', AttrIndent => '1');
|