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
|
|
|
{
|
2008-02-14 22:15:38 +00:00
|
|
|
#get parameters
|
|
|
|
my ($sid) = @_;
|
|
|
|
|
|
|
|
#prepare query
|
2008-04-03 12:44:59 +00:00
|
|
|
my $sth = $dbh->prepare(qq{select id, username, locale, pagesize from users where sid = ?}) or die $dbh->errstr;
|
2008-02-14 22:15:38 +00:00
|
|
|
|
|
|
|
#execute it
|
|
|
|
$sth->execute($sid) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#save the resulting username
|
2008-04-03 12:44:59 +00:00
|
|
|
($userinfo->{'id'}, $userinfo->{'username'}, $userinfo->{'locale'}, $userinfo->{'pagesize'}) = $sth->fetchrow_array();
|
2008-02-14 22:15:38 +00:00
|
|
|
|
|
|
|
#finish query
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#return
|
|
|
|
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
|
|
|
{
|
2008-02-14 22:15:38 +00:00
|
|
|
#get parameters
|
|
|
|
my (@userinfo) = @_;
|
|
|
|
|
|
|
|
#if user is logged in, use his locale setting and check for new upload status
|
|
|
|
if($userinfo->{'username'})
|
|
|
|
{
|
|
|
|
$page->{'locale'} = $userinfo->{'locale'};
|
|
|
|
}
|
|
|
|
#else get the locale from the http server variable
|
|
|
|
else
|
|
|
|
{
|
|
|
|
($page->{'locale'}) = $query->http('HTTP_ACCEPT_LANGUAGE') =~ /^([^,]+),.*$/;
|
|
|
|
unless($page->{'locale'})
|
|
|
|
{
|
|
|
|
$page->{'locale'} = "en_us";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$page->{'username'} = $userinfo->{'username'};
|
|
|
|
$page->{'stylesheet'} = $stylesheet;
|
|
|
|
$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
|
|
|
|
{
|
2008-02-14 22:15:38 +00:00
|
|
|
#prepare query
|
|
|
|
my $sth = $dbh->prepare($dbquery) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#execute it
|
|
|
|
$resultcount = $sth->execute(@_) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
#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
|
|
|
|
while (my ($id, $title, $description, $publisher, $timestamp, $creator,
|
|
|
|
$subject, $source, $language, $coverage, $rights,
|
|
|
|
$license, $filesize, $duration, $width, $height, $fps, $viewcount,
|
|
|
|
$downloadcount) = $sth->fetchrow_array())
|
|
|
|
{
|
|
|
|
#before code cleanup, this was a really obfuscated array/hash creation
|
|
|
|
push @{ $page->{'results'}->{'result'} },
|
|
|
|
{
|
2008-04-07 14:19:06 +00:00
|
|
|
'thumbnail' => "$domain/video-stills/thumbnails/$id",
|
|
|
|
'preview' => "$domain/video-stills/previews/$id",
|
2008-02-14 22:15:38 +00:00
|
|
|
'duration' => $duration,
|
|
|
|
'viewcount' => $viewcount,
|
|
|
|
'rdf:RDF' =>
|
|
|
|
{
|
|
|
|
'cc:Work' =>
|
|
|
|
{
|
|
|
|
'rdf:about' => "$domain/download/$id/",
|
|
|
|
'dc:title' => [$title],
|
|
|
|
'dc:creator' => [$creator],
|
|
|
|
'dc:subject' => [$subject],
|
|
|
|
'dc:description' => [$description],
|
|
|
|
'dc:publisher' => [$publisher],
|
|
|
|
'dc:date' => [$timestamp],
|
|
|
|
'dc:identifier' => ["$domain/video/".urlencode($title)."/$id/" . ($duration == 0 ? "/action=edit" : "")],
|
|
|
|
'dc:source' => [$source],
|
|
|
|
'dc:language' => [$language],
|
|
|
|
'dc:coverage' => [$coverage],
|
|
|
|
'dc:rights' => [$rights]
|
|
|
|
},
|
|
|
|
'cc:License' =>
|
|
|
|
{
|
|
|
|
'rdf:about' => 'http://creativecommons.org/licenses/GPL/2.0/'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#finish query
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
2007-10-29 16:47:16 +00:00
|
|
|
}
|
2007-12-01 18:04:28 +00:00
|
|
|
|
2008-03-07 20:13:35 +00:00
|
|
|
#replace chars in url according to RFC 1738 <http://www.rfc-editor.org/rfc/rfc1738.txt>
|
2007-12-01 18:04:28 +00:00
|
|
|
sub urlencode
|
|
|
|
{
|
2008-02-14 22:15:38 +00:00
|
|
|
my ($url) = @_[0];
|
|
|
|
$url =~ s/([^A-Za-z0-9_\$\-.+!*'()])/sprintf("%%%02X", ord($1))/eg;
|
|
|
|
return $url;
|
2007-12-01 18:04:28 +00:00
|
|
|
}
|
2007-12-17 18:55:33 +00:00
|
|
|
|
|
|
|
sub output_page
|
|
|
|
{
|
2008-02-14 22:15:38 +00:00
|
|
|
use XML::LibXSLT;
|
|
|
|
use XML::LibXML;
|
|
|
|
|
|
|
|
my $parser = XML::LibXML->new();
|
|
|
|
my $xslt = XML::LibXSLT->new();
|
|
|
|
|
2008-03-07 20:13:35 +00:00
|
|
|
#let the XSLT param choose other stylesheets or default to xhtml.xsl
|
2008-02-14 22:15:38 +00:00
|
|
|
my $param_xslt = $query->param('xslt');
|
|
|
|
$param_xslt =~ s/[^\w]//gi;
|
|
|
|
|
2008-03-09 19:32:24 +00:00
|
|
|
if($param_xslt eq "null")
|
2008-03-10 15:44:46 +00:00
|
|
|
{
|
2008-03-09 19:32:24 +00:00
|
|
|
return $session->header(
|
|
|
|
-type=>'application/xml',
|
|
|
|
-charset=>'UTF-8',
|
|
|
|
),
|
2008-04-01 16:16:04 +00:00
|
|
|
XMLout(
|
|
|
|
$page,
|
|
|
|
KeyAttr => {},
|
|
|
|
RootName => 'page'
|
|
|
|
);
|
2008-02-14 22:15:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-09 19:32:24 +00:00
|
|
|
if( -f "$root/xsl/$param_xslt.xsl")
|
|
|
|
{
|
|
|
|
$xsltpath = "$root/xsl/$param_xslt.xsl"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$xsltpath = "$root/xsl/xhtml.xsl";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath));
|
2007-12-17 18:55:33 +00:00
|
|
|
|
2008-03-09 19:32:24 +00:00
|
|
|
$output = $stylesheet->transform(
|
2008-02-14 22:15:38 +00:00
|
|
|
$parser->parse_string(
|
|
|
|
XMLout(
|
|
|
|
$page,
|
|
|
|
KeyAttr => {},
|
2008-03-10 15:44:46 +00:00
|
|
|
RootName => 'page'
|
2008-02-14 22:15:38 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2008-03-09 19:32:24 +00:00
|
|
|
|
|
|
|
if($param_xslt eq "xspf")
|
|
|
|
{
|
|
|
|
return $session->header(
|
2008-03-10 15:44:46 +00:00
|
|
|
-type=>$stylesheet->media_type,
|
|
|
|
-charset=>$stylesheet->output_encoding,
|
2008-03-09 19:32:24 +00:00
|
|
|
-attachment=>$query->param('query').".xspf",
|
|
|
|
),
|
|
|
|
$output->toString;
|
2008-04-01 16:16:04 +00:00
|
|
|
#$stylesheet->output_as_bytes($output); <= for future use with XML::LibXSLT (>= 1.62)
|
2008-03-09 19:32:24 +00:00
|
|
|
}
|
2008-03-10 15:44:46 +00:00
|
|
|
elsif($param_xslt eq "pr0n")
|
2008-03-09 19:32:24 +00:00
|
|
|
{
|
|
|
|
return $session->header(
|
2008-03-10 15:44:46 +00:00
|
|
|
-status=>'402 Payment required',
|
2008-03-27 16:43:08 +00:00
|
|
|
-cost=>'$9001.00', # OVER NEIN THOUSAND
|
2008-03-10 15:44:46 +00:00
|
|
|
)
|
2008-03-09 19:32:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $session->header(
|
2008-03-10 15:44:46 +00:00
|
|
|
-type=>$stylesheet->media_type,
|
|
|
|
-charset=>$stylesheet->output_encoding,
|
2008-03-09 19:32:24 +00:00
|
|
|
),
|
|
|
|
$output->toString;
|
2008-04-01 16:16:04 +00:00
|
|
|
#$stylesheet->output_as_bytes($output); <= for future use with XML::LibXSLT (>= 1.62)
|
2008-03-09 19:32:24 +00:00
|
|
|
}
|
2008-02-14 22:15:38 +00:00
|
|
|
}
|
2007-12-17 18:55:33 +00:00
|
|
|
}
|