2007-10-11 17:06:08 +00:00
|
|
|
require "include.pl";
|
2007-10-10 21:48:12 +00:00
|
|
|
|
2007-10-29 15:00:40 +00:00
|
|
|
sub get_userinfo_from_sid
|
2007-10-11 17:26:39 +00:00
|
|
|
{
|
2007-10-10 21:48:12 +00:00
|
|
|
#get parameters
|
|
|
|
my ($sid) = @_;
|
|
|
|
|
|
|
|
#prepare query
|
2007-10-29 15:00:40 +00:00
|
|
|
my $sth = $dbh->prepare(qq{select id, username, locale, pagesize, cortado from users where sid = ?}) or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#execute it
|
2007-10-12 00:34:32 +00:00
|
|
|
$sth->execute($sid) or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#save the resulting username
|
2007-10-29 15:00:40 +00:00
|
|
|
($userinfo->{'id'}, $userinfo->{'username'}, $userinfo->{'locale'}, $userinfo->{'pagesize'}, $userinfo->{'cortado'}) = $sth->fetchrow_array();
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#finish query
|
2007-10-11 10:00:38 +00:00
|
|
|
$sth->finish() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
2007-10-11 10:00:38 +00:00
|
|
|
#return
|
2007-10-29 15:00:40 +00:00
|
|
|
return @userinfo;
|
2007-10-10 21:48:12 +00:00
|
|
|
}
|
2007-10-11 10:57:52 +00:00
|
|
|
|
2007-10-29 15:00:40 +00:00
|
|
|
sub get_page_array
|
2007-10-11 17:26:39 +00:00
|
|
|
{
|
2007-10-11 10:57:52 +00:00
|
|
|
#get parameters
|
2007-10-29 15:00:40 +00:00
|
|
|
my (@userinfo) = @_;
|
2007-10-11 10:57:52 +00:00
|
|
|
|
2007-12-18 12:39:27 +00:00
|
|
|
#if user is logged in, use his locale setting and check for new upload status
|
|
|
|
if($userinfo->{'username'})
|
2007-10-29 15:00:40 +00:00
|
|
|
{
|
|
|
|
$page->{'locale'} = $userinfo->{'locale'};
|
|
|
|
}
|
|
|
|
#else get the locale from the http server variable
|
|
|
|
else
|
|
|
|
{
|
|
|
|
($page->{'locale'}) = $query->http('HTTP_ACCEPT_LANGUAGE') =~ /^([^,]+),.*$/;
|
|
|
|
}
|
2007-12-18 12:39:27 +00:00
|
|
|
|
|
|
|
$page->{'username'} = $userinfo->{'username'};
|
2007-12-17 12:38:02 +00:00
|
|
|
$page->{'stylesheet'} = $stylesheet;
|
2007-10-29 15:00:40 +00:00
|
|
|
$page->{'xmlns:dc'} = $xmlns_dc;
|
|
|
|
$page->{'xmlns:cc'} = $xmlns_cc;
|
|
|
|
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
2007-10-11 10:57:52 +00:00
|
|
|
}
|
2007-10-29 16:47:16 +00:00
|
|
|
|
2007-11-26 14:25:31 +00:00
|
|
|
# called by video.pl (display ambiguous videos),
|
|
|
|
# search.pl (display search results)
|
2007-12-18 12:39:27 +00:00
|
|
|
# and upload.pl (display similar videos)
|
2007-10-29 16:47:16 +00:00
|
|
|
sub fill_results
|
|
|
|
{
|
|
|
|
#prepare query
|
|
|
|
my $sth = $dbh->prepare($dbquery) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#execute it
|
|
|
|
$resultcount = $sth->execute(@_) or die $dbh->errstr;
|
|
|
|
|
2007-12-21 17:39:49 +00:00
|
|
|
#set pagesize by query or usersettings or default
|
|
|
|
$pagesize = $query->param('pagesize') or $pagesize = $userinfo->{'pagesize'} or $pagesize = $defaultpagesize;
|
|
|
|
|
|
|
|
#if pagesize is more than maxpagesize reduce to maxpagesize
|
|
|
|
$pagesize = $pagesize > $maxpagesize ? $maxpagesize : $pagesize;
|
2007-10-29 16:47:16 +00:00
|
|
|
|
|
|
|
#rediculous but funny round up, will fail with 100000000000000 results per page
|
|
|
|
#on 0.0000000000001% of all queries - this is a risk we can handle
|
|
|
|
$lastpage = int($resultcount/$pagesize+0.99999999999999);
|
|
|
|
|
|
|
|
$currentpage = $query->param('page') or $currentpage = 1;
|
|
|
|
|
|
|
|
$dbquery .= " limit ".($currentpage-1)*$pagesize.", ".$pagesize;
|
|
|
|
|
|
|
|
#prepare query
|
|
|
|
$sth = $dbh->prepare($dbquery) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#execute it
|
|
|
|
$sth->execute(@_) or die $dbquery;
|
|
|
|
|
|
|
|
$page->{'results'}->{'lastpage'} = $lastpage;
|
|
|
|
$page->{'results'}->{'currentpage'} = $currentpage;
|
|
|
|
$page->{'results'}->{'resultcount'} = $resultcount eq '0E0' ? 0 : $resultcount;
|
|
|
|
$page->{'results'}->{'pagesize'} = $pagesize;
|
|
|
|
|
|
|
|
#get every returned value
|
2007-12-14 06:18:58 +00:00
|
|
|
while (my ($id, $title, $description, $publisher, $timestamp, $creator,
|
2007-12-22 12:30:11 +00:00
|
|
|
$subject, $source, $language, $coverage, $rights,
|
2007-12-14 06:18:58 +00:00
|
|
|
$license, $filesize, $duration, $width, $height, $fps, $viewcount,
|
2007-12-22 12:30:11 +00:00
|
|
|
$downloadcount) = $sth->fetchrow_array())
|
2007-10-29 16:47:16 +00:00
|
|
|
{
|
|
|
|
#before code cleanup, this was a really obfuscated array/hash creation
|
|
|
|
push @{ $page->{'results'}->{'result'} },
|
|
|
|
{
|
2007-11-01 23:00:14 +00:00
|
|
|
'thumbnail' => $duration == 0 ? "/images/tango/video-x-generic.png" : "/video-stills/$id",
|
2007-10-29 16:47:16 +00:00
|
|
|
'duration' => $duration,
|
|
|
|
'viewcount' => $viewcount,
|
|
|
|
'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false",
|
|
|
|
'rdf:RDF' =>
|
|
|
|
{
|
|
|
|
'cc:Work' =>
|
|
|
|
{
|
2007-12-01 18:04:28 +00:00
|
|
|
'rdf:about' => "$domain/download/$id/",
|
2007-10-29 16:47:16 +00:00
|
|
|
'dc:title' => [$title],
|
|
|
|
'dc:creator' => [$creator],
|
2007-11-25 04:44:14 +00:00
|
|
|
'dc:subject' => [$subject],
|
|
|
|
'dc:description' => [$description],
|
|
|
|
'dc:publisher' => [$publisher],
|
2007-10-29 16:47:16 +00:00
|
|
|
'dc:date' => [$timestamp],
|
2007-12-01 18:04:28 +00:00
|
|
|
'dc:identifier' => ["$domain/video/".urlencode($title)."/$id/" . ($duration == 0 ? "/action=edit" : "")],
|
2007-11-25 04:44:14 +00:00
|
|
|
'dc:source' => [$source],
|
|
|
|
'dc:language' => [$language],
|
|
|
|
'dc:coverage' => [$coverage],
|
|
|
|
'dc:rights' => [$rights]
|
2007-10-29 16:47:16 +00:00
|
|
|
},
|
|
|
|
'cc:License' =>
|
|
|
|
{
|
|
|
|
'rdf:about' => 'http://creativecommons.org/licenses/GPL/2.0/'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#finish query
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
|
|
|
}
|
2007-12-01 18:04:28 +00:00
|
|
|
|
|
|
|
#replace chars in url as said in this rfc: http://www.rfc-editor.org/rfc/rfc1738.txt
|
|
|
|
sub urlencode
|
|
|
|
{
|
|
|
|
my ($url) = @_[0];
|
|
|
|
$url =~ s/([^A-Za-z0-9_\$\-.+!*'()])/sprintf("%%%02X", ord($1))/eg;
|
|
|
|
return $url;
|
|
|
|
}
|
2007-12-17 18:55:33 +00:00
|
|
|
|
|
|
|
sub output_page
|
|
|
|
{
|
2007-12-17 21:33:45 +00:00
|
|
|
use XML::LibXSLT;
|
|
|
|
use XML::LibXML;
|
2007-12-18 12:39:27 +00:00
|
|
|
|
2007-12-17 21:33:45 +00:00
|
|
|
my $parser = XML::LibXML->new();
|
|
|
|
my $xslt = XML::LibXSLT->new();
|
2007-12-18 12:39:27 +00:00
|
|
|
|
|
|
|
#let the xslt param choose other stylesheets or default to xhtml.xsl
|
|
|
|
my $param_xslt = $query->param('xslt');
|
2007-12-21 17:39:49 +00:00
|
|
|
$param_xslt =~ s/[^\w]//gi;
|
2007-12-18 12:39:27 +00:00
|
|
|
|
|
|
|
if( -f "$root/xsl/$param_xslt.xsl")
|
|
|
|
{
|
|
|
|
$xsltpath = "$root/xsl/$param_xslt.xsl"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$xsltpath = "$root/xsl/xhtml.xsl";
|
|
|
|
}
|
2007-12-17 18:55:33 +00:00
|
|
|
|
2007-12-18 12:39:27 +00:00
|
|
|
my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath));
|
2007-12-17 18:55:33 +00:00
|
|
|
|
2007-12-17 22:52:36 +00:00
|
|
|
#TODO: this usage of libxsl omits the xsl:output definition (no ident of html) but outputs in UTF8
|
|
|
|
#TODO: later versions of XML::LibXSLT (>= 1.62) define output_as_bytes - this is what we want to use
|
|
|
|
#TODO: wait for debian packagers to update to 1.62 or later
|
|
|
|
$foo = $stylesheet->transform(
|
2007-12-17 21:33:45 +00:00
|
|
|
$parser->parse_string(
|
|
|
|
XMLout(
|
|
|
|
$page,
|
|
|
|
KeyAttr => {},
|
|
|
|
RootName => 'page',
|
|
|
|
AttrIndent => '1'
|
2007-12-17 18:55:33 +00:00
|
|
|
)
|
|
|
|
)
|
2007-12-17 22:52:36 +00:00
|
|
|
);
|
|
|
|
|
2007-12-27 14:50:08 +00:00
|
|
|
if($query->param('cortado') eq 'true')
|
|
|
|
{
|
|
|
|
@cookies = [$session->cookie(-name=>$session_name, -value=>$session->id), $session->cookie(-name=>'cortado', -value=>'true')];
|
|
|
|
}
|
|
|
|
elsif($query->param('cortado') eq 'false')
|
|
|
|
{
|
|
|
|
@cookies = [$session->cookie(-name=>$session_name, -value=>$session->id), $session->cookie(-name=>'cortado', -value=>'false')];
|
|
|
|
}
|
|
|
|
|
2007-12-21 17:39:49 +00:00
|
|
|
#send everything including http headers to the user - if xslt chosen is xspf set download filename
|
2007-12-17 22:52:36 +00:00
|
|
|
return $session->header(
|
|
|
|
-type=>'text/xml',
|
2007-12-27 14:50:08 +00:00
|
|
|
-charset=>'UTF-8',
|
|
|
|
-cookie=>@cookies
|
2007-12-17 22:52:36 +00:00
|
|
|
),
|
|
|
|
$foo->toString;
|
2007-12-17 18:55:33 +00:00
|
|
|
}
|