2007-10-11 17:06:08 +00:00
|
|
|
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-29 15:00:40 +00:00
|
|
|
@userinfo = get_userinfo_from_sid($session->id);
|
2007-10-27 11:59:23 +00:00
|
|
|
|
2007-10-29 15:00:40 +00:00
|
|
|
@page = get_page_array(@userinfo);
|
2007-10-26 00:35:29 +00:00
|
|
|
|
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-29 16:47:16 +00:00
|
|
|
$page->{'search'} = [''];
|
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
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
my @args = ();
|
2007-10-11 14:59:55 +00:00
|
|
|
|
2007-11-05 16:24:17 +00:00
|
|
|
$strquery = $query->param('query');
|
|
|
|
push @tags, $strquery =~ /tag:"([^"]+)"/gi;
|
|
|
|
push @tags, $strquery =~ /tag:(\w+)/gi;
|
|
|
|
$strquery =~ s/(tag|title):"[^"]+"//gi;
|
|
|
|
$strquery =~ s/(tag|title):\w+//gi;
|
|
|
|
$strquery =~ s/^\s*(.*?)\s*$/$1/;
|
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
#build mysql query
|
2007-12-14 06:18:58 +00:00
|
|
|
$dbquery = "select v.id, v.title, v.description, u.username,
|
|
|
|
from_unixtime( v.timestamp ), v.creator, v.subject, v.contributor,
|
|
|
|
v.source, v.language, v.coverage, v.rights, v.license, filesize,
|
|
|
|
duration, width, height, fps, viewcount, downloadcount, 1";
|
2007-10-18 11:47:50 +00:00
|
|
|
|
2007-11-05 16:24:17 +00:00
|
|
|
if($strquery)
|
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)";
|
2007-11-05 16:24:17 +00:00
|
|
|
push @args, $strquery, $strquery;
|
2007-10-26 00:35:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$dbquery .= " from videos as v, users as u where u.id = v.userid";
|
|
|
|
}
|
|
|
|
|
2007-11-05 16:24:17 +00:00
|
|
|
if(@tags)
|
|
|
|
{
|
|
|
|
$dbquery .= " and match(v.subject) against (? in boolean mode)";
|
|
|
|
push @args, "@tags";
|
|
|
|
}
|
|
|
|
|
2007-10-26 00:35:29 +00:00
|
|
|
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-29 16:47:16 +00:00
|
|
|
fill_results(@args);
|
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');
|