converted tabs to spaces in all perl files
git-svn-id: http://yolanda.mister-muffin.de/svn@239 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
parent
316feffced
commit
dfb29b7142
11 changed files with 1065 additions and 1065 deletions
|
@ -8,109 +8,109 @@ $session = new CGI::Session;
|
|||
#do we have an id?
|
||||
if($query->param('id'))
|
||||
{
|
||||
#check if video with requested id is in the database
|
||||
my $sth = $dbh->prepare(qq{select title from videos where id = ? });
|
||||
$sth->execute($query->param('id'));
|
||||
#check if video with requested id is in the database
|
||||
my $sth = $dbh->prepare(qq{select title from videos where id = ? });
|
||||
$sth->execute($query->param('id'));
|
||||
|
||||
if(($title) = $sth->fetchrow_array())
|
||||
{
|
||||
#if referer is not the local site update referer table
|
||||
$referer = $query->referer() or $referer = '';
|
||||
if($referer !~ /^$domain/)
|
||||
{
|
||||
#check if already in database
|
||||
$sth = $dbh->prepare(qq{select 1 from referer where videoid = ? and referer = ? }) or die $dbh->errstr;
|
||||
my $rowcount = $sth->execute($query->param('id'), $referer) or die $dbh->errstr;
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
if(($title) = $sth->fetchrow_array())
|
||||
{
|
||||
#if referer is not the local site update referer table
|
||||
$referer = $query->referer() or $referer = '';
|
||||
if($referer !~ /^$domain/)
|
||||
{
|
||||
#check if already in database
|
||||
$sth = $dbh->prepare(qq{select 1 from referer where videoid = ? and referer = ? }) or die $dbh->errstr;
|
||||
my $rowcount = $sth->execute($query->param('id'), $referer) or die $dbh->errstr;
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
|
||||
if($rowcount > 0)
|
||||
{
|
||||
#video is in database - increase referercount
|
||||
$dbh->do(qq{update referer set count=count+1 where videoid = ? and referer = ? },
|
||||
undef, $query->param('id'), $referer) or die $dbh->errstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
#add new referer
|
||||
$dbh->do(qq{insert into referer (videoid, referer) values (?, ?) },
|
||||
undef, $query->param('id'), $referer) or die $dbh->errstr;
|
||||
}
|
||||
}
|
||||
if($rowcount > 0)
|
||||
{
|
||||
#video is in database - increase referercount
|
||||
$dbh->do(qq{update referer set count=count+1 where videoid = ? and referer = ? },
|
||||
undef, $query->param('id'), $referer) or die $dbh->errstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
#add new referer
|
||||
$dbh->do(qq{insert into referer (videoid, referer) values (?, ?) },
|
||||
undef, $query->param('id'), $referer) or die $dbh->errstr;
|
||||
}
|
||||
}
|
||||
|
||||
#are we only watching this video or downloading it?
|
||||
if($query->param('view'))
|
||||
{
|
||||
#seems we only want to watch it - update viewcount
|
||||
$dbh->do(qq{update videos set viewcount=viewcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
#video is being downloaded - update downloadcount
|
||||
$dbh->do(qq{update videos set downloadcount=downloadcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
||||
}
|
||||
#are we only watching this video or downloading it?
|
||||
if($query->param('view'))
|
||||
{
|
||||
#seems we only want to watch it - update viewcount
|
||||
$dbh->do(qq{update videos set viewcount=viewcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
#video is being downloaded - update downloadcount
|
||||
$dbh->do(qq{update videos set downloadcount=downloadcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
||||
}
|
||||
|
||||
#in both cases - do some slurp-eaze to the browser
|
||||
open(FILE, "<$root/videos/".$query->param('id'));
|
||||
#in both cases - do some slurp-eaze to the browser
|
||||
open(FILE, "<$root/videos/".$query->param('id'));
|
||||
|
||||
$filesize = -s "$root/videos/".$query->param('id');
|
||||
$range = $query->http('range');
|
||||
$range =~ s/bytes=([0-9]+)-/$1/;
|
||||
$filesize = -s "$root/videos/".$query->param('id');
|
||||
$range = $query->http('range');
|
||||
$range =~ s/bytes=([0-9]+)-/$1/;
|
||||
|
||||
#if a specific range is requested send http partial content headers and seek in the inputfile
|
||||
if($range)
|
||||
{
|
||||
#if $range is equal or more than filesize throw http 416 header
|
||||
if($range >= $filesize)
|
||||
{
|
||||
print $query->header(-status=>'416 Requested Range Not Satisfiable');
|
||||
}
|
||||
else
|
||||
{
|
||||
print $query->header(-type=>'application/ogg',
|
||||
-content_length=> $filesize-$range,
|
||||
-status=>'206 Partial Content',
|
||||
-attachment=>$title.".ogv",
|
||||
-accept_ranges=> "bytes",
|
||||
-content_range=> "bytes $range-".($filesize-1)."/$filesize"
|
||||
);
|
||||
#if a specific range is requested send http partial content headers and seek in the inputfile
|
||||
if($range)
|
||||
{
|
||||
#if $range is equal or more than filesize throw http 416 header
|
||||
if($range >= $filesize)
|
||||
{
|
||||
print $query->header(-status=>'416 Requested Range Not Satisfiable');
|
||||
}
|
||||
else
|
||||
{
|
||||
print $query->header(-type=>'application/ogg',
|
||||
-content_length=> $filesize-$range,
|
||||
-status=>'206 Partial Content',
|
||||
-attachment=>$title.".ogv",
|
||||
-accept_ranges=> "bytes",
|
||||
-content_range=> "bytes $range-".($filesize-1)."/$filesize"
|
||||
);
|
||||
|
||||
seek FILE, $range, 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $query->header(-type=>'application/ogg',
|
||||
-content_length=> $filesize,
|
||||
-attachment=>$title.".ogv"
|
||||
);
|
||||
}
|
||||
seek FILE, $range, 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $query->header(-type=>'application/ogg',
|
||||
-content_length=> $filesize,
|
||||
-attachment=>$title.".ogv"
|
||||
);
|
||||
}
|
||||
|
||||
while (my $BytesRead = read (FILE, $buff, 8192))
|
||||
{
|
||||
print $buff;
|
||||
}
|
||||
close(FILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
@userinfo = get_userinfo_from_sid($session->id);
|
||||
while (my $BytesRead = read (FILE, $buff, 8192))
|
||||
{
|
||||
print $buff;
|
||||
}
|
||||
close(FILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
@userinfo = get_userinfo_from_sid($session->id);
|
||||
|
||||
@page = get_page_array(@userinfo);
|
||||
@page = get_page_array(@userinfo);
|
||||
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
|
||||
print output_page();
|
||||
}
|
||||
print output_page();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@userinfo = get_userinfo_from_sid($session->id);
|
||||
@userinfo = get_userinfo_from_sid($session->id);
|
||||
|
||||
@page = get_page_array(@userinfo);
|
||||
@page = get_page_array(@userinfo);
|
||||
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
|
||||
print output_page();
|
||||
print output_page();
|
||||
}
|
||||
|
|
|
@ -2,50 +2,50 @@ require "include.pl";
|
|||
|
||||
sub get_userinfo_from_sid
|
||||
{
|
||||
#get parameters
|
||||
my ($sid) = @_;
|
||||
#get parameters
|
||||
my ($sid) = @_;
|
||||
|
||||
#prepare query
|
||||
my $sth = $dbh->prepare(qq{select id, username, locale, pagesize, cortado from users where sid = ?}) or die $dbh->errstr;
|
||||
#prepare query
|
||||
my $sth = $dbh->prepare(qq{select id, username, locale, pagesize, cortado from users where sid = ?}) or die $dbh->errstr;
|
||||
|
||||
#execute it
|
||||
$sth->execute($sid) or die $dbh->errstr;
|
||||
#execute it
|
||||
$sth->execute($sid) or die $dbh->errstr;
|
||||
|
||||
#save the resulting username
|
||||
($userinfo->{'id'}, $userinfo->{'username'}, $userinfo->{'locale'}, $userinfo->{'pagesize'}, $userinfo->{'cortado'}) = $sth->fetchrow_array();
|
||||
#save the resulting username
|
||||
($userinfo->{'id'}, $userinfo->{'username'}, $userinfo->{'locale'}, $userinfo->{'pagesize'}, $userinfo->{'cortado'}) = $sth->fetchrow_array();
|
||||
|
||||
#finish query
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
#finish query
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
|
||||
#return
|
||||
return @userinfo;
|
||||
#return
|
||||
return @userinfo;
|
||||
}
|
||||
|
||||
sub get_page_array
|
||||
{
|
||||
#get parameters
|
||||
my (@userinfo) = @_;
|
||||
#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";
|
||||
}
|
||||
}
|
||||
#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;
|
||||
$page->{'username'} = $userinfo->{'username'};
|
||||
$page->{'stylesheet'} = $stylesheet;
|
||||
$page->{'xmlns:dc'} = $xmlns_dc;
|
||||
$page->{'xmlns:cc'} = $xmlns_cc;
|
||||
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
||||
}
|
||||
|
||||
# called by video.pl (display ambiguous videos),
|
||||
|
@ -53,142 +53,142 @@ sub get_page_array
|
|||
# and upload.pl (display similar videos)
|
||||
sub fill_results
|
||||
{
|
||||
#prepare query
|
||||
my $sth = $dbh->prepare($dbquery) or die $dbh->errstr;
|
||||
#prepare query
|
||||
my $sth = $dbh->prepare($dbquery) or die $dbh->errstr;
|
||||
|
||||
#execute it
|
||||
$resultcount = $sth->execute(@_) 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;
|
||||
#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;
|
||||
#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);
|
||||
#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;
|
||||
$currentpage = $query->param('page') or $currentpage = 1;
|
||||
|
||||
$dbquery .= " limit ".($currentpage-1)*$pagesize.", ".$pagesize;
|
||||
$dbquery .= " limit ".($currentpage-1)*$pagesize.", ".$pagesize;
|
||||
|
||||
#prepare query
|
||||
$sth = $dbh->prepare($dbquery) or die $dbh->errstr;
|
||||
#prepare query
|
||||
$sth = $dbh->prepare($dbquery) or die $dbh->errstr;
|
||||
|
||||
#execute it
|
||||
$sth->execute(@_) or die $dbquery;
|
||||
#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;
|
||||
$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'} },
|
||||
{
|
||||
'thumbnail' => $duration == 0 ? "/images/tango/video-x-generic.png" : "/video-stills/$id",
|
||||
'duration' => $duration,
|
||||
'viewcount' => $viewcount,
|
||||
'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false",
|
||||
'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/'
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
#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'} },
|
||||
{
|
||||
'thumbnail' => $duration == 0 ? "/images/tango/video-x-generic.png" : "/video-stills/$id",
|
||||
'duration' => $duration,
|
||||
'viewcount' => $viewcount,
|
||||
'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false",
|
||||
'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;
|
||||
#finish query
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
}
|
||||
|
||||
#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;
|
||||
my ($url) = @_[0];
|
||||
$url =~ s/([^A-Za-z0-9_\$\-.+!*'()])/sprintf("%%%02X", ord($1))/eg;
|
||||
return $url;
|
||||
}
|
||||
|
||||
sub output_page
|
||||
{
|
||||
use XML::LibXSLT;
|
||||
use XML::LibXML;
|
||||
use XML::LibXSLT;
|
||||
use XML::LibXML;
|
||||
|
||||
my $parser = XML::LibXML->new();
|
||||
my $xslt = XML::LibXSLT->new();
|
||||
my $parser = XML::LibXML->new();
|
||||
my $xslt = XML::LibXSLT->new();
|
||||
|
||||
#let the xslt param choose other stylesheets or default to xhtml.xsl
|
||||
my $param_xslt = $query->param('xslt');
|
||||
$param_xslt =~ s/[^\w]//gi;
|
||||
#let the xslt param choose other stylesheets or default to xhtml.xsl
|
||||
my $param_xslt = $query->param('xslt');
|
||||
$param_xslt =~ s/[^\w]//gi;
|
||||
|
||||
if( -f "$root/xsl/$param_xslt.xsl")
|
||||
{
|
||||
$xsltpath = "$root/xsl/$param_xslt.xsl"
|
||||
}
|
||||
else
|
||||
{
|
||||
$xsltpath = "$root/xsl/xhtml.xsl";
|
||||
}
|
||||
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));
|
||||
my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath));
|
||||
|
||||
#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(
|
||||
$parser->parse_string(
|
||||
XMLout(
|
||||
$page,
|
||||
KeyAttr => {},
|
||||
RootName => 'page',
|
||||
AttrIndent => '1'
|
||||
)
|
||||
)
|
||||
);
|
||||
#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(
|
||||
$parser->parse_string(
|
||||
XMLout(
|
||||
$page,
|
||||
KeyAttr => {},
|
||||
RootName => 'page',
|
||||
AttrIndent => '1'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
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')];
|
||||
}
|
||||
else
|
||||
{
|
||||
@cookies = [$session->cookie(-name=>$session_name, -value=>$session->id)];
|
||||
}
|
||||
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')];
|
||||
}
|
||||
else
|
||||
{
|
||||
@cookies = [$session->cookie(-name=>$session_name, -value=>$session->id)];
|
||||
}
|
||||
|
||||
#send everything including http headers to the user - if xslt chosen is xspf set download filename
|
||||
return $session->header(
|
||||
-type=>'text/xml',
|
||||
-charset=>'UTF-8',
|
||||
-cookie=>@cookies
|
||||
),
|
||||
$foo->toString;
|
||||
#send everything including http headers to the user - if xslt chosen is xspf set download filename
|
||||
return $session->header(
|
||||
-type=>'text/xml',
|
||||
-charset=>'UTF-8',
|
||||
-cookie=>@cookies
|
||||
),
|
||||
$foo->toString;
|
||||
}
|
||||
|
|
|
@ -13,21 +13,21 @@ $page->{frontpage} = [''];
|
|||
|
||||
if($query->param('information'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
$page->{'message'}->{'text'} = $query->param('information');
|
||||
$page->{'message'}->{'value'} = $query->param('value');
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
$page->{'message'}->{'text'} = $query->param('information');
|
||||
$page->{'message'}->{'value'} = $query->param('value');
|
||||
}
|
||||
elsif($query->param('error'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = $query->param('error');
|
||||
$page->{'message'}->{'value'} = $query->param('value');
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = $query->param('error');
|
||||
$page->{'message'}->{'value'} = $query->param('value');
|
||||
}
|
||||
elsif($query->param('warning'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "warning";
|
||||
$page->{'message'}->{'text'} = $query->param('warning');
|
||||
$page->{'message'}->{'value'} = $query->param('value');
|
||||
$page->{'message'}->{'type'} = "warning";
|
||||
$page->{'message'}->{'text'} = $query->param('warning');
|
||||
$page->{'message'}->{'value'} = $query->param('value');
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,8 +40,8 @@ $sth->execute() or die $dbh->errstr;
|
|||
#get every returned value
|
||||
while (my ($text, $count) = $sth->fetchrow_array())
|
||||
{
|
||||
#push the new value to the $page->tagcloud array
|
||||
push @{ $page->{tagcloud}->{tag} }, { text => [$text =~ / / ? "\"$text\"" : $text], count => [$count] };
|
||||
#push the new value to the $page->tagcloud array
|
||||
push @{ $page->{tagcloud}->{tag} }, { text => [$text =~ / / ? "\"$text\"" : $text], count => [$count] };
|
||||
}
|
||||
|
||||
#finish query
|
||||
|
|
|
@ -19,124 +19,124 @@ $dbh->do(qq{drop table referer});
|
|||
$dbh->do(qq{drop table comments});
|
||||
|
||||
$dbh->do(qq{create table
|
||||
tagcloud
|
||||
(
|
||||
text varchar(255) not null,
|
||||
count int not null
|
||||
)
|
||||
tagcloud
|
||||
(
|
||||
text varchar(255) not null,
|
||||
count int not null
|
||||
)
|
||||
}) or die $dbh->errstr;
|
||||
|
||||
$dbh->do(qq{insert into
|
||||
tagcloud values
|
||||
(
|
||||
'web tv', 68
|
||||
)
|
||||
tagcloud values
|
||||
(
|
||||
'web tv', 68
|
||||
)
|
||||
}) or die $dbh->errstr;
|
||||
|
||||
$dbh->do(qq{create table
|
||||
config
|
||||
(
|
||||
attribute varchar(255) not null,
|
||||
value varchar(255) not null,
|
||||
primary key (attribute)
|
||||
)
|
||||
config
|
||||
(
|
||||
attribute varchar(255) not null,
|
||||
value varchar(255) not null,
|
||||
primary key (attribute)
|
||||
)
|
||||
}) or die $dbh->errstr;
|
||||
|
||||
$dbh->do(qq{create table
|
||||
users
|
||||
(
|
||||
id int auto_increment not null,
|
||||
username varchar(255) not null,
|
||||
password char(41) not null,
|
||||
sid char(32) not null,
|
||||
timestamp bigint not null,
|
||||
locale varchar(10) not null,
|
||||
pagesize tinyint unsigned default 5,
|
||||
cortado varchar(5) default 'true',
|
||||
primary key (id)
|
||||
)
|
||||
users
|
||||
(
|
||||
id int auto_increment not null,
|
||||
username varchar(255) not null,
|
||||
password char(41) not null,
|
||||
sid char(32) not null,
|
||||
timestamp bigint not null,
|
||||
locale varchar(10) not null,
|
||||
pagesize tinyint unsigned default 5,
|
||||
cortado varchar(5) default 'true',
|
||||
primary key (id)
|
||||
)
|
||||
}) or die $dbh->errstr;
|
||||
|
||||
$dbh->do(qq{insert into
|
||||
users
|
||||
(
|
||||
username,
|
||||
password
|
||||
)
|
||||
values
|
||||
(
|
||||
'test',
|
||||
password( 'test' )
|
||||
)
|
||||
users
|
||||
(
|
||||
username,
|
||||
password
|
||||
)
|
||||
values
|
||||
(
|
||||
'test',
|
||||
password( 'test' )
|
||||
)
|
||||
}) or die $dbh->errstr;
|
||||
|
||||
$dbh->do(qq{create table
|
||||
uploaded
|
||||
(
|
||||
id int auto_increment not null,
|
||||
title varchar(255) not null,
|
||||
description text not null,
|
||||
userid int not null,
|
||||
timestamp bigint not null,
|
||||
creator varchar(255) not null,
|
||||
subject varchar(255) not null,
|
||||
source varchar(255) not null,
|
||||
language varchar(255) not null,
|
||||
coverage varchar(255) not null,
|
||||
rights varchar(255) not null,
|
||||
license varchar(255) not null,
|
||||
status int default 0,
|
||||
primary key (id)
|
||||
)
|
||||
uploaded
|
||||
(
|
||||
id int auto_increment not null,
|
||||
title varchar(255) not null,
|
||||
description text not null,
|
||||
userid int not null,
|
||||
timestamp bigint not null,
|
||||
creator varchar(255) not null,
|
||||
subject varchar(255) not null,
|
||||
source varchar(255) not null,
|
||||
language varchar(255) not null,
|
||||
coverage varchar(255) not null,
|
||||
rights varchar(255) not null,
|
||||
license varchar(255) not null,
|
||||
status int default 0,
|
||||
primary key (id)
|
||||
)
|
||||
}) or die $dbh->errstr;
|
||||
|
||||
$dbh->do(qq{create table
|
||||
videos
|
||||
(
|
||||
id int auto_increment not null,
|
||||
title varchar(255) not null,
|
||||
description text not null,
|
||||
userid int not null,
|
||||
timestamp bigint not null,
|
||||
creator varchar(255) not null,
|
||||
subject varchar(255) not null,
|
||||
source varchar(255) not null,
|
||||
language varchar(255) not null,
|
||||
coverage varchar(255) not null,
|
||||
rights varchar(255) not null,
|
||||
license varchar(255) not null,
|
||||
filesize int not null,
|
||||
duration int not null,
|
||||
width smallint not null,
|
||||
height smallint not null,
|
||||
fps float not null,
|
||||
hash char(64) not null,
|
||||
viewcount int default 0,
|
||||
downloadcount int default 0,
|
||||
primary key (id),
|
||||
fulltext (title, description, subject)
|
||||
)
|
||||
videos
|
||||
(
|
||||
id int auto_increment not null,
|
||||
title varchar(255) not null,
|
||||
description text not null,
|
||||
userid int not null,
|
||||
timestamp bigint not null,
|
||||
creator varchar(255) not null,
|
||||
subject varchar(255) not null,
|
||||
source varchar(255) not null,
|
||||
language varchar(255) not null,
|
||||
coverage varchar(255) not null,
|
||||
rights varchar(255) not null,
|
||||
license varchar(255) not null,
|
||||
filesize int not null,
|
||||
duration int not null,
|
||||
width smallint not null,
|
||||
height smallint not null,
|
||||
fps float not null,
|
||||
hash char(64) not null,
|
||||
viewcount int default 0,
|
||||
downloadcount int default 0,
|
||||
primary key (id),
|
||||
fulltext (title, description, subject)
|
||||
)
|
||||
}) or die $dbh->errstr;
|
||||
|
||||
$dbh->do(qq{create table
|
||||
referer
|
||||
(
|
||||
videoid int not null,
|
||||
referer varchar(255) not null,
|
||||
count int default 1
|
||||
)
|
||||
referer
|
||||
(
|
||||
videoid int not null,
|
||||
referer varchar(255) not null,
|
||||
count int default 1
|
||||
)
|
||||
}) or die $dbh->errstr;
|
||||
|
||||
$dbh->do(qq{create table
|
||||
comments
|
||||
(
|
||||
id int auto_increment not null,
|
||||
userid int not null,
|
||||
videoid int not null,
|
||||
text varchar(255) not null,
|
||||
timestamp bigint not null,
|
||||
primary key (id)
|
||||
)
|
||||
comments
|
||||
(
|
||||
id int auto_increment not null,
|
||||
userid int not null,
|
||||
videoid int not null,
|
||||
text varchar(255) not null,
|
||||
timestamp bigint not null,
|
||||
primary key (id)
|
||||
)
|
||||
}) or die $dbh->errstr;
|
||||
|
||||
print $session->header();
|
||||
|
|
246
trunk/login.pl
246
trunk/login.pl
|
@ -12,147 +12,147 @@ $session = new CGI::Session;
|
|||
#check if action is set
|
||||
if($query->param('action'))
|
||||
{
|
||||
if($query->param('action') eq "logout")
|
||||
{
|
||||
#if logout is requested
|
||||
#remove sid from database
|
||||
$dbh->do(qq{update users set sid = '' where id = ?}, undef, $userinfo->{'id'}) or die $dbh->errstr;
|
||||
$session->delete();
|
||||
print $query->redirect("index.pl?information=information_logged_out");
|
||||
}
|
||||
#check if user is logged in
|
||||
elsif($userinfo->{'username'})
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_already_logged_in";
|
||||
if($query->param('action') eq "logout")
|
||||
{
|
||||
#if logout is requested
|
||||
#remove sid from database
|
||||
$dbh->do(qq{update users set sid = '' where id = ?}, undef, $userinfo->{'id'}) or die $dbh->errstr;
|
||||
$session->delete();
|
||||
print $query->redirect("index.pl?information=information_logged_out");
|
||||
}
|
||||
#check if user is logged in
|
||||
elsif($userinfo->{'username'})
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_already_logged_in";
|
||||
|
||||
print output_page();
|
||||
}
|
||||
#if login is requested
|
||||
elsif($query->param('action') eq "login")
|
||||
{
|
||||
#prepare query - empty password are openid users so omit those entries
|
||||
my $sth = $dbh->prepare(qq{select id from users
|
||||
where password = password( ? ) and username = ? and not password = '' limit 1 });
|
||||
print output_page();
|
||||
}
|
||||
#if login is requested
|
||||
elsif($query->param('action') eq "login")
|
||||
{
|
||||
#prepare query - empty password are openid users so omit those entries
|
||||
my $sth = $dbh->prepare(qq{select id from users
|
||||
where password = password( ? ) and username = ? and not password = '' limit 1 });
|
||||
|
||||
#execute query
|
||||
$sth->execute($query->param('pass'), $query->param('user'));
|
||||
#execute query
|
||||
$sth->execute($query->param('pass'), $query->param('user'));
|
||||
|
||||
#if something was returned username and password match
|
||||
if($sth->fetchrow_array())
|
||||
{
|
||||
#store session id in database
|
||||
$dbh->do(qq{update users set sid = ? where username = ? }, undef, $session->id, $query->param('user')) or die $dbh->errstr;
|
||||
print $query->redirect("index.pl?information=information_logged_in");
|
||||
}
|
||||
else
|
||||
{
|
||||
#if not, print error
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_username_password_do_not_match";
|
||||
#if something was returned username and password match
|
||||
if($sth->fetchrow_array())
|
||||
{
|
||||
#store session id in database
|
||||
$dbh->do(qq{update users set sid = ? where username = ? }, undef, $session->id, $query->param('user')) or die $dbh->errstr;
|
||||
print $query->redirect("index.pl?information=information_logged_in");
|
||||
}
|
||||
else
|
||||
{
|
||||
#if not, print error
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_username_password_do_not_match";
|
||||
|
||||
print output_page();
|
||||
}
|
||||
print output_page();
|
||||
}
|
||||
|
||||
}
|
||||
elsif($query->param('action') eq "openid")
|
||||
{
|
||||
#create our openid consumer object
|
||||
$con = Net::OpenID::Consumer->new(
|
||||
ua => LWPx::ParanoidAgent->new, # FIXME - use LWPx::ParanoidAgent
|
||||
cache => undef, # or File::Cache->new,
|
||||
args => $query,
|
||||
consumer_secret => $session->id, #is this save? don't know...
|
||||
required_root => $domain );
|
||||
}
|
||||
elsif($query->param('action') eq "openid")
|
||||
{
|
||||
#create our openid consumer object
|
||||
$con = Net::OpenID::Consumer->new(
|
||||
ua => LWPx::ParanoidAgent->new, # FIXME - use LWPx::ParanoidAgent
|
||||
cache => undef, # or File::Cache->new,
|
||||
args => $query,
|
||||
consumer_secret => $session->id, #is this save? don't know...
|
||||
required_root => $domain );
|
||||
|
||||
#is an openid passed?
|
||||
if($query->param('user'))
|
||||
{
|
||||
#claim identity
|
||||
$claimed = $con->claimed_identity($query->param('user'));
|
||||
if(!defined($claimed))
|
||||
{
|
||||
print $session->header();
|
||||
print "claim failed: ", $con->err;
|
||||
}
|
||||
$check_url = $claimed->check_url(
|
||||
return_to => "$domain/login.pl?action=openid&ret=true", #on success return to this address
|
||||
trust_root => $domain); #this is the string the user will be asked to trust
|
||||
#is an openid passed?
|
||||
if($query->param('user'))
|
||||
{
|
||||
#claim identity
|
||||
$claimed = $con->claimed_identity($query->param('user'));
|
||||
if(!defined($claimed))
|
||||
{
|
||||
print $session->header();
|
||||
print "claim failed: ", $con->err;
|
||||
}
|
||||
$check_url = $claimed->check_url(
|
||||
return_to => "$domain/login.pl?action=openid&ret=true", #on success return to this address
|
||||
trust_root => $domain); #this is the string the user will be asked to trust
|
||||
|
||||
#redirect to openid server to check claim
|
||||
print $query->redirect($check_url);
|
||||
}
|
||||
#we return from an identity check
|
||||
elsif($query->param('ret'))
|
||||
{
|
||||
if($setup_url = $con->user_setup_url)
|
||||
{
|
||||
#redirect to setup url - user will give confirmation there
|
||||
print $query->redirect($setup_url);
|
||||
}
|
||||
elsif ($con->user_cancel)
|
||||
{
|
||||
#cancelled - redirect to login form
|
||||
print $session->header();
|
||||
print "cancelled";
|
||||
}
|
||||
elsif ($vident = $con->verified_identity)
|
||||
{
|
||||
#we are verified!!
|
||||
my $verified_url = $vident->url;
|
||||
#redirect to openid server to check claim
|
||||
print $query->redirect($check_url);
|
||||
}
|
||||
#we return from an identity check
|
||||
elsif($query->param('ret'))
|
||||
{
|
||||
if($setup_url = $con->user_setup_url)
|
||||
{
|
||||
#redirect to setup url - user will give confirmation there
|
||||
print $query->redirect($setup_url);
|
||||
}
|
||||
elsif ($con->user_cancel)
|
||||
{
|
||||
#cancelled - redirect to login form
|
||||
print $session->header();
|
||||
print "cancelled";
|
||||
}
|
||||
elsif ($vident = $con->verified_identity)
|
||||
{
|
||||
#we are verified!!
|
||||
my $verified_url = $vident->url;
|
||||
|
||||
#check if this openid user already is in database
|
||||
my $sth = $dbh->prepare(qq{select 1 from users where username = ? limit 1 });
|
||||
$sth->execute($verified_url);
|
||||
if($sth->fetchrow_array())
|
||||
{
|
||||
#store session id in database
|
||||
$dbh->do(qq{update users set sid = ? where username = ? }, undef, $session->id, $verified_url) or die $dbh->errstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
#add openid user to dabase
|
||||
$dbh->do(qq{insert into users (username, sid) values ( ?, ? ) }, undef, $verified_url, $session->id) or die $dbh->errstr;
|
||||
}
|
||||
#check if this openid user already is in database
|
||||
my $sth = $dbh->prepare(qq{select 1 from users where username = ? limit 1 });
|
||||
$sth->execute($verified_url);
|
||||
if($sth->fetchrow_array())
|
||||
{
|
||||
#store session id in database
|
||||
$dbh->do(qq{update users set sid = ? where username = ? }, undef, $session->id, $verified_url) or die $dbh->errstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
#add openid user to dabase
|
||||
$dbh->do(qq{insert into users (username, sid) values ( ?, ? ) }, undef, $verified_url, $session->id) or die $dbh->errstr;
|
||||
}
|
||||
|
||||
print $query->redirect("index.pl?information=information_logged_in");
|
||||
}
|
||||
else
|
||||
{
|
||||
#an error occured
|
||||
print $session->header();
|
||||
print "error validating identity: ", $con->err;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if not, print login form
|
||||
$page->{'loginform'}->{'action'} = 'openid';
|
||||
print $query->redirect("index.pl?information=information_logged_in");
|
||||
}
|
||||
else
|
||||
{
|
||||
#an error occured
|
||||
print $session->header();
|
||||
print "error validating identity: ", $con->err;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if not, print login form
|
||||
$page->{'loginform'}->{'action'} = 'openid';
|
||||
|
||||
print output_page();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#something ugly was passed
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
print output_page();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#something ugly was passed
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
|
||||
print output_page();
|
||||
}
|
||||
print output_page();
|
||||
}
|
||||
}
|
||||
#check if user is logged in
|
||||
elsif($userinfo->{'username'})
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_already_logged_in";
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_already_logged_in";
|
||||
|
||||
print output_page();
|
||||
print output_page();
|
||||
}
|
||||
else
|
||||
{
|
||||
#if not, print login form
|
||||
$page->{'loginform'} = [''];
|
||||
#if not, print login form
|
||||
$page->{'loginform'} = [''];
|
||||
|
||||
print output_page();
|
||||
print output_page();
|
||||
}
|
||||
|
|
|
@ -12,75 +12,75 @@ $session = new CGI::Session;
|
|||
#check if user is logged in
|
||||
if($username)
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_already_registered";
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_already_registered";
|
||||
|
||||
print output_page();
|
||||
print output_page();
|
||||
}
|
||||
#if username and password are passed put them into the database
|
||||
elsif($query->param('user') and $query->param('pass') and $query->param('pass_repeat'))
|
||||
{
|
||||
if($query->param('pass') eq $query->param('pass_repeat'))
|
||||
{
|
||||
my $sth = $dbh->prepare(qq{select id from users where username = ? limit 1 });
|
||||
if($query->param('pass') eq $query->param('pass_repeat'))
|
||||
{
|
||||
my $sth = $dbh->prepare(qq{select id from users where username = ? limit 1 });
|
||||
|
||||
#execute query
|
||||
$sth->execute($query->param('user'));
|
||||
#execute query
|
||||
$sth->execute($query->param('user'));
|
||||
|
||||
#if something was returned the selected username already exists
|
||||
if($sth->fetchrow_array())
|
||||
{
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_username_already_registered";
|
||||
#if something was returned the selected username already exists
|
||||
if($sth->fetchrow_array())
|
||||
{
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_username_already_registered";
|
||||
|
||||
print output_page();
|
||||
}
|
||||
else
|
||||
{
|
||||
#insert new user
|
||||
$dbh->do(qq{insert into users (username, password, timestamp, locale) values ( ?, password( ? ), unix_timestamp(), ?)}, undef,
|
||||
$query->param("user"), $query->param("pass"), $page->{'locale'}) or die $dbh->errstr;
|
||||
print output_page();
|
||||
}
|
||||
else
|
||||
{
|
||||
#insert new user
|
||||
$dbh->do(qq{insert into users (username, password, timestamp, locale) values ( ?, password( ? ), unix_timestamp(), ?)}, undef,
|
||||
$query->param("user"), $query->param("pass"), $page->{'locale'}) or die $dbh->errstr;
|
||||
|
||||
print $query->redirect("index.pl?information=information_registered");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_passwords_do_not_match";
|
||||
print $query->redirect("index.pl?information=information_registered");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_passwords_do_not_match";
|
||||
|
||||
print output_page();
|
||||
}
|
||||
print output_page();
|
||||
}
|
||||
}
|
||||
elsif(not $query->param('user') and ($query->param('pass') or $query->param('pass_repeat')))
|
||||
{
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_insert_username";
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_insert_username";
|
||||
|
||||
print output_page();
|
||||
print output_page();
|
||||
}
|
||||
elsif(not $query->param('pass') and ($query->param('user') or $query->param('pass_repeat')))
|
||||
{
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_insert_password";
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_insert_password";
|
||||
|
||||
print output_page();
|
||||
print output_page();
|
||||
}
|
||||
elsif(not $query->param('pass_repeat') and ($query->param('user') or $query->param('pass')))
|
||||
{
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_repeat_password";
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_repeat_password";
|
||||
|
||||
print output_page();
|
||||
print output_page();
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'registerform'} = [''];
|
||||
$page->{'registerform'} = [''];
|
||||
|
||||
print output_page();
|
||||
print output_page();
|
||||
}
|
||||
|
|
200
trunk/search.pl
200
trunk/search.pl
|
@ -12,120 +12,120 @@ $session = new CGI::Session;
|
|||
#check if query is set
|
||||
if($query->param('query'))
|
||||
{
|
||||
$page->{'search'} = [''];
|
||||
$page->{'results'}->{'query'} = $query->param('query');
|
||||
$page->{'search'} = [''];
|
||||
$page->{'results'}->{'query'} = $query->param('query');
|
||||
|
||||
my @args = ();
|
||||
my @args = ();
|
||||
|
||||
$strquery = $query->param('query');
|
||||
$strquery =~ s/%([0-9A-F]{2})/chr(hex($1))/eg;
|
||||
(@tags) = $strquery =~ /tag:(\w+)/gi;
|
||||
($orderby) = $strquery =~ /orderby:(\w+)/i;
|
||||
($sort) = $strquery =~ /sort:(\w+)/i;
|
||||
#($title) = $strquery =~ /title:(\w+)/i;
|
||||
#($description) = $strquery =~ /description:(\w+)/i;
|
||||
#($creator) = $strquery =~ /creator:(\w+)/i;
|
||||
#($language) = $strquery =~ /language:(\w+)/i;
|
||||
#($coverage) = $strquery =~ /coverage:(\w+)/i;
|
||||
#($rights) = $strquery =~ /rights:(\w+)/i;
|
||||
#($license) = $strquery =~ /license:(\w+)/i;
|
||||
#($filesize) = $strquery =~ /filesize:([<>]?\w+)/i;
|
||||
#($duration) = $strquery =~ /duration:([<>]?\w+)/i;
|
||||
#($timestamp) = $strquery =~ /timestamp:([<>]?\w+)/i;
|
||||
$strquery =~ s/(tag|orderby|sort):\w+//gi;
|
||||
$strquery =~ s/^\s*(.*?)\s*$/$1/;
|
||||
$strquery = $query->param('query');
|
||||
$strquery =~ s/%([0-9A-F]{2})/chr(hex($1))/eg;
|
||||
(@tags) = $strquery =~ /tag:(\w+)/gi;
|
||||
($orderby) = $strquery =~ /orderby:(\w+)/i;
|
||||
($sort) = $strquery =~ /sort:(\w+)/i;
|
||||
#($title) = $strquery =~ /title:(\w+)/i;
|
||||
#($description) = $strquery =~ /description:(\w+)/i;
|
||||
#($creator) = $strquery =~ /creator:(\w+)/i;
|
||||
#($language) = $strquery =~ /language:(\w+)/i;
|
||||
#($coverage) = $strquery =~ /coverage:(\w+)/i;
|
||||
#($rights) = $strquery =~ /rights:(\w+)/i;
|
||||
#($license) = $strquery =~ /license:(\w+)/i;
|
||||
#($filesize) = $strquery =~ /filesize:([<>]?\w+)/i;
|
||||
#($duration) = $strquery =~ /duration:([<>]?\w+)/i;
|
||||
#($timestamp) = $strquery =~ /timestamp:([<>]?\w+)/i;
|
||||
$strquery =~ s/(tag|orderby|sort):\w+//gi;
|
||||
$strquery =~ s/^\s*(.*?)\s*$/$1/;
|
||||
|
||||
#build mysql query
|
||||
$dbquery = "select v.id, v.title, v.description, u.username,
|
||||
from_unixtime( v.timestamp ), v.creator, v.subject,
|
||||
v.source, v.language, v.coverage, v.rights, v.license, filesize,
|
||||
duration, width, height, fps, viewcount, downloadcount";
|
||||
#build mysql query
|
||||
$dbquery = "select v.id, v.title, v.description, u.username,
|
||||
from_unixtime( v.timestamp ), v.creator, v.subject,
|
||||
v.source, v.language, v.coverage, v.rights, v.license, filesize,
|
||||
duration, width, height, fps, viewcount, downloadcount";
|
||||
|
||||
if($strquery)
|
||||
{
|
||||
$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, $strquery, $strquery;
|
||||
}
|
||||
else
|
||||
{
|
||||
$dbquery .= " from videos as v, users as u where u.id = v.userid";
|
||||
}
|
||||
if($strquery)
|
||||
{
|
||||
$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, $strquery, $strquery;
|
||||
}
|
||||
else
|
||||
{
|
||||
$dbquery .= " from videos as v, users as u where u.id = v.userid";
|
||||
}
|
||||
|
||||
if(@tags)
|
||||
{
|
||||
$dbquery .= " and match(v.subject) against (? in boolean mode)";
|
||||
push @args, "@tags";
|
||||
}
|
||||
if(@tags)
|
||||
{
|
||||
$dbquery .= " and match(v.subject) against (? in boolean mode)";
|
||||
push @args, "@tags";
|
||||
}
|
||||
|
||||
if($publisher)
|
||||
{
|
||||
$dbquery .= " and match(u.username) against (? in boolean mode)";
|
||||
push @args, "$publisher";
|
||||
}
|
||||
if($publisher)
|
||||
{
|
||||
$dbquery .= " and match(u.username) against (? in boolean mode)";
|
||||
push @args, "$publisher";
|
||||
}
|
||||
|
||||
if($orderby)
|
||||
{
|
||||
if($orderby eq 'filesize')
|
||||
{
|
||||
$dbquery .= " order by v.filesize";
|
||||
}
|
||||
elsif($orderby eq 'duration')
|
||||
{
|
||||
$dbquery .= " order by v.duration";
|
||||
}
|
||||
elsif($orderby eq 'viewcount')
|
||||
{
|
||||
$dbquery .= " order by v.viewcount";
|
||||
}
|
||||
elsif($orderby eq 'downloadcount')
|
||||
{
|
||||
$dbquery .= " order by v.downloadcount";
|
||||
}
|
||||
elsif($orderby eq 'timestamp')
|
||||
{
|
||||
$dbquery .= " order by v.timestamp";
|
||||
}
|
||||
elsif($orderby eq 'relevance' and $strquery)
|
||||
{
|
||||
$dbquery .= " order by relevance";
|
||||
}
|
||||
else
|
||||
{
|
||||
$dbquery .= " order by v.id";
|
||||
}
|
||||
if($orderby)
|
||||
{
|
||||
if($orderby eq 'filesize')
|
||||
{
|
||||
$dbquery .= " order by v.filesize";
|
||||
}
|
||||
elsif($orderby eq 'duration')
|
||||
{
|
||||
$dbquery .= " order by v.duration";
|
||||
}
|
||||
elsif($orderby eq 'viewcount')
|
||||
{
|
||||
$dbquery .= " order by v.viewcount";
|
||||
}
|
||||
elsif($orderby eq 'downloadcount')
|
||||
{
|
||||
$dbquery .= " order by v.downloadcount";
|
||||
}
|
||||
elsif($orderby eq 'timestamp')
|
||||
{
|
||||
$dbquery .= " order by v.timestamp";
|
||||
}
|
||||
elsif($orderby eq 'relevance' and $strquery)
|
||||
{
|
||||
$dbquery .= " order by relevance";
|
||||
}
|
||||
else
|
||||
{
|
||||
$dbquery .= " order by v.id";
|
||||
}
|
||||
|
||||
if($sort eq "ascending")
|
||||
{
|
||||
$dbquery .= " asc";
|
||||
}
|
||||
elsif($sort eq "descending")
|
||||
{
|
||||
$dbquery .= " desc";
|
||||
}
|
||||
}
|
||||
if($sort eq "ascending")
|
||||
{
|
||||
$dbquery .= " asc";
|
||||
}
|
||||
elsif($sort eq "descending")
|
||||
{
|
||||
$dbquery .= " desc";
|
||||
}
|
||||
}
|
||||
|
||||
fill_results(@args);
|
||||
fill_results(@args);
|
||||
|
||||
if(@{$page->{'results'}->{'result'}} == 0)
|
||||
{
|
||||
print $query->redirect("index.pl?warning=warning_no_results");
|
||||
}
|
||||
elsif((@{$page->{'results'}->{'result'}} == 1 or $query->param('lucky')) and (not $query->param('page') or $query->param('page') == 1))
|
||||
{
|
||||
print $query->redirect($page->{'results'}->{'result'}[0]->{'rdf:RDF'}->{'cc:Work'}->{'dc:identifier'}[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print output_page();
|
||||
}
|
||||
if(@{$page->{'results'}->{'result'}} == 0)
|
||||
{
|
||||
print $query->redirect("index.pl?warning=warning_no_results");
|
||||
}
|
||||
elsif((@{$page->{'results'}->{'result'}} == 1 or $query->param('lucky')) and (not $query->param('page') or $query->param('page') == 1))
|
||||
{
|
||||
print $query->redirect($page->{'results'}->{'result'}[0]->{'rdf:RDF'}->{'cc:Work'}->{'dc:identifier'}[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print output_page();
|
||||
}
|
||||
}
|
||||
elsif($query->param('advanced'))
|
||||
{
|
||||
print $query->redirect("index.pl?error=error_202c");
|
||||
print $query->redirect("index.pl?error=error_202c");
|
||||
}
|
||||
else
|
||||
{
|
||||
print $query->redirect("index.pl?error=error_no_query");
|
||||
print $query->redirect("index.pl?error=error_no_query");
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ $session = new CGI::Session;
|
|||
|
||||
if($userinfo->{'username'})
|
||||
{
|
||||
if($query->param('submit'))
|
||||
{
|
||||
$dbh->do(qq{update users set locale = ?, pagesize = ?, cortado = ? where id = ?}, undef, $query->param('locale'), $query->param('pagesize'), $query->param('cortado'), $userinfo->{'id'} ) or die $dbh->errstr;
|
||||
if($query->param('submit'))
|
||||
{
|
||||
$dbh->do(qq{update users set locale = ?, pagesize = ?, cortado = ? where id = ?}, undef, $query->param('locale'), $query->param('pagesize'), $query->param('cortado'), $userinfo->{'id'} ) or die $dbh->errstr;
|
||||
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
$page->{'message'}->{'text'} = "information_settings_changed";
|
||||
}
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
$page->{'message'}->{'text'} = "information_settings_changed";
|
||||
}
|
||||
}
|
||||
|
||||
@userinfo = get_userinfo_from_sid($session->id);
|
||||
|
@ -24,14 +24,14 @@ if($userinfo->{'username'})
|
|||
|
||||
if($userinfo->{'username'})
|
||||
{
|
||||
$page->{'settings'}->{'locale'} = $userinfo->{'locale'};
|
||||
$page->{'settings'}->{'pagesize'} = $userinfo->{'pagesize'};
|
||||
$page->{'settings'}->{'cortado'} = $userinfo->{'cortado'}
|
||||
$page->{'settings'}->{'locale'} = $userinfo->{'locale'};
|
||||
$page->{'settings'}->{'pagesize'} = $userinfo->{'pagesize'};
|
||||
$page->{'settings'}->{'cortado'} = $userinfo->{'cortado'}
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
}
|
||||
|
||||
print output_page();
|
||||
|
|
262
trunk/upload.pl
262
trunk/upload.pl
|
@ -11,146 +11,146 @@ $session = new CGI::Session;
|
|||
|
||||
if($userinfo->{'username'})
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.Title'} = $query->param('DC.Title');
|
||||
$page->{'uploadform'}->{'DC.Subject'} = $query->param('DC.Subject');
|
||||
$page->{'uploadform'}->{'DC.Description'} = $query->param('DC.Description');
|
||||
$page->{'uploadform'}->{'DC.Creator'} = $query->param('DC.Creator');
|
||||
$page->{'uploadform'}->{'DC.Source'} = $query->param('DC.Source');
|
||||
$page->{'uploadform'}->{'DC.Language'} = $query->param('DC.Language');
|
||||
$page->{'uploadform'}->{'DC.Coverage'} = $query->param('DC.Coverage');
|
||||
$page->{'uploadform'}->{'DC.Rights'} = $query->param('DC.Rights');
|
||||
$page->{'uploadform'}->{'DC.License'} = $query->param('DC.License');
|
||||
$page->{'uploadform'}->{'DC.Title'} = $query->param('DC.Title');
|
||||
$page->{'uploadform'}->{'DC.Subject'} = $query->param('DC.Subject');
|
||||
$page->{'uploadform'}->{'DC.Description'} = $query->param('DC.Description');
|
||||
$page->{'uploadform'}->{'DC.Creator'} = $query->param('DC.Creator');
|
||||
$page->{'uploadform'}->{'DC.Source'} = $query->param('DC.Source');
|
||||
$page->{'uploadform'}->{'DC.Language'} = $query->param('DC.Language');
|
||||
$page->{'uploadform'}->{'DC.Coverage'} = $query->param('DC.Coverage');
|
||||
$page->{'uploadform'}->{'DC.Rights'} = $query->param('DC.Rights');
|
||||
$page->{'uploadform'}->{'DC.License'} = $query->param('DC.License');
|
||||
|
||||
if($query->param('2'))
|
||||
{
|
||||
if($query->param('DC.Title')&&$query->param('DC.Subject')&&$query->param('DC.Description'))
|
||||
{
|
||||
$page->{'innerresults'} = [''];
|
||||
if($query->param('2'))
|
||||
{
|
||||
if($query->param('DC.Title')&&$query->param('DC.Subject')&&$query->param('DC.Description'))
|
||||
{
|
||||
$page->{'innerresults'} = [''];
|
||||
|
||||
my @args = ();
|
||||
my @args = ();
|
||||
|
||||
#build mysql query
|
||||
$dbquery = "select v.id, v.title, v.description, u.username,
|
||||
from_unixtime( v.timestamp ), v.creator, v.subject,
|
||||
v.source, v.language, v.coverage, v.rights,
|
||||
v.license, filesize, duration, width, height, fps, viewcount,
|
||||
downloadcount,
|
||||
match(v.title, v.description, v.subject)
|
||||
against( ? in boolean mode) as relevance
|
||||
from videos as v, users as u where u.id = v.userid
|
||||
and match(v.title, v.description, v.subject)
|
||||
against( ? in boolean mode)";
|
||||
push @args, $query->param('DC.Title'), $query->param('DC.Title');
|
||||
#build mysql query
|
||||
$dbquery = "select v.id, v.title, v.description, u.username,
|
||||
from_unixtime( v.timestamp ), v.creator, v.subject,
|
||||
v.source, v.language, v.coverage, v.rights,
|
||||
v.license, filesize, duration, width, height, fps, viewcount,
|
||||
downloadcount,
|
||||
match(v.title, v.description, v.subject)
|
||||
against( ? in boolean mode) as relevance
|
||||
from videos as v, users as u where u.id = v.userid
|
||||
and match(v.title, v.description, v.subject)
|
||||
against( ? in boolean mode)";
|
||||
push @args, $query->param('DC.Title'), $query->param('DC.Title');
|
||||
|
||||
fill_results(@args);
|
||||
$page->{'uploadform'}->{'page'} = '2';
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$query->param('DC.Title'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_missing_DC.Title";
|
||||
}
|
||||
elsif(!$query->param('DC.Subject'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_missing_DC.Subject";
|
||||
}
|
||||
elsif(!$query->param('DC.Description'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_missing_DC.Description";
|
||||
}
|
||||
$page->{'uploadform'}->{'page'} = '1';
|
||||
}
|
||||
}
|
||||
elsif($query->param('3'))
|
||||
{
|
||||
$page->{'uploadform'}->{'page'} = '3';
|
||||
}
|
||||
elsif($query->param('4'))
|
||||
{
|
||||
if($query->param('DC.License') eq 'cc-by')
|
||||
{
|
||||
$page->{'uploadform'}->{'remix'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-sa')
|
||||
{
|
||||
$page->{'uploadform'}->{'sharealike'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-nd')
|
||||
{
|
||||
$page->{'uploadform'}->{'noderivatives'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-nc')
|
||||
{
|
||||
$page->{'uploadform'}->{'remix'} = 'true';
|
||||
$page->{'uploadform'}->{'noncommercial'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-nc-sa')
|
||||
{
|
||||
$page->{'uploadform'}->{'sharealike'} = 'true';
|
||||
$page->{'uploadform'}->{'noncommercial'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-nc-nd')
|
||||
{
|
||||
$page->{'uploadform'}->{'noderivatives'} = 'true';
|
||||
$page->{'uploadform'}->{'noncommercial'} = 'true';
|
||||
}
|
||||
fill_results(@args);
|
||||
$page->{'uploadform'}->{'page'} = '2';
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$query->param('DC.Title'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_missing_DC.Title";
|
||||
}
|
||||
elsif(!$query->param('DC.Subject'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_missing_DC.Subject";
|
||||
}
|
||||
elsif(!$query->param('DC.Description'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_missing_DC.Description";
|
||||
}
|
||||
$page->{'uploadform'}->{'page'} = '1';
|
||||
}
|
||||
}
|
||||
elsif($query->param('3'))
|
||||
{
|
||||
$page->{'uploadform'}->{'page'} = '3';
|
||||
}
|
||||
elsif($query->param('4'))
|
||||
{
|
||||
if($query->param('DC.License') eq 'cc-by')
|
||||
{
|
||||
$page->{'uploadform'}->{'remix'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-sa')
|
||||
{
|
||||
$page->{'uploadform'}->{'sharealike'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-nd')
|
||||
{
|
||||
$page->{'uploadform'}->{'noderivatives'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-nc')
|
||||
{
|
||||
$page->{'uploadform'}->{'remix'} = 'true';
|
||||
$page->{'uploadform'}->{'noncommercial'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-nc-sa')
|
||||
{
|
||||
$page->{'uploadform'}->{'sharealike'} = 'true';
|
||||
$page->{'uploadform'}->{'noncommercial'} = 'true';
|
||||
}
|
||||
elsif($query->param('DC.License') eq 'cc-by-nc-nd')
|
||||
{
|
||||
$page->{'uploadform'}->{'noderivatives'} = 'true';
|
||||
$page->{'uploadform'}->{'noncommercial'} = 'true';
|
||||
}
|
||||
|
||||
$page->{'uploadform'}->{'page'} = '4';
|
||||
}
|
||||
elsif($query->param('5'))
|
||||
{
|
||||
if($query->param('modification') and not $query->param('DC.License'))
|
||||
{
|
||||
if($query->param('modification') eq 'remix')
|
||||
{
|
||||
if($query->param('noncommercial'))
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-nc';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by';
|
||||
}
|
||||
}
|
||||
elsif($query->param('modification') eq 'sharealike')
|
||||
{
|
||||
if($query->param('noncommercial'))
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-nc-sa';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-sa';
|
||||
}
|
||||
}
|
||||
elsif($query->param('modification') eq 'noderivatives')
|
||||
{
|
||||
if($query->param('noncommercial'))
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-nc-nd';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-nd';
|
||||
}
|
||||
}
|
||||
}
|
||||
$page->{'uploadform'}->{'page'} = '4';
|
||||
}
|
||||
elsif($query->param('5'))
|
||||
{
|
||||
if($query->param('modification') and not $query->param('DC.License'))
|
||||
{
|
||||
if($query->param('modification') eq 'remix')
|
||||
{
|
||||
if($query->param('noncommercial'))
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-nc';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by';
|
||||
}
|
||||
}
|
||||
elsif($query->param('modification') eq 'sharealike')
|
||||
{
|
||||
if($query->param('noncommercial'))
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-nc-sa';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-sa';
|
||||
}
|
||||
}
|
||||
elsif($query->param('modification') eq 'noderivatives')
|
||||
{
|
||||
if($query->param('noncommercial'))
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-nc-nd';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'uploadform'}->{'DC.License'} = 'cc-by-nd';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$page->{'uploadform'}->{'page'} = '5';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'uploadform'}->{'page'} = '1';
|
||||
}
|
||||
$page->{'uploadform'}->{'page'} = '5';
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'uploadform'}->{'page'} = '1';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
}
|
||||
|
||||
print output_page();
|
||||
|
|
|
@ -6,14 +6,14 @@ $session = new CGI::Session;
|
|||
|
||||
sub hook
|
||||
{
|
||||
#this is going to become an ajax progress bar
|
||||
#alternatively, reloading every N seconds (mozilla doesn't flicker)
|
||||
my ($filename, $buffer, $bytes_read, $data) = @_;
|
||||
#print $ENV{'CONTENT_LENGTH'};
|
||||
#print sha256_hex($buffer);
|
||||
#open(TEMP, ">>/var/www/perl/videos/temp.temp") or die "cannot open";
|
||||
#print "Read $bytes_read bytes of $filename\n";
|
||||
#close TEMP;
|
||||
#this is going to become an ajax progress bar
|
||||
#alternatively, reloading every N seconds (mozilla doesn't flicker)
|
||||
my ($filename, $buffer, $bytes_read, $data) = @_;
|
||||
#print $ENV{'CONTENT_LENGTH'};
|
||||
#print sha256_hex($buffer);
|
||||
#open(TEMP, ">>/var/www/perl/videos/temp.temp") or die "cannot open";
|
||||
#print "Read $bytes_read bytes of $filename\n";
|
||||
#close TEMP;
|
||||
}
|
||||
|
||||
@userinfo = get_userinfo_from_sid($session->id);
|
||||
|
@ -21,36 +21,36 @@ sub hook
|
|||
@page = get_page_array(@userinfo);
|
||||
|
||||
if($userinfo->{'id'} && $query->param("DC.Title") &&
|
||||
$query->param("DC.Description") && $query->param("DC.Subject"))
|
||||
$query->param("DC.Description") && $query->param("DC.Subject"))
|
||||
{
|
||||
#make new entry for video into the databse
|
||||
#FIXME: contributor, rights
|
||||
$dbh->do(qq{insert into uploaded (title, description, userid, timestamp,
|
||||
creator, subject, source, language, coverage, rights, license)
|
||||
values ( ?, ?, ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ? )}, undef,
|
||||
$query->param("DC.Title"), $query->param("DC.Description"), $userinfo->{'id'},
|
||||
$query->param("DC.Creator"), $query->param("DC.Subject"), $query->param("DC.Source"),
|
||||
$query->param("DC.Language"), $query->param("DC.Coverage"),
|
||||
$query->param("DC.Rights"), $query->param("DC.License")) or die $dbh->errstr;
|
||||
#make new entry for video into the databse
|
||||
#FIXME: contributor, rights
|
||||
$dbh->do(qq{insert into uploaded (title, description, userid, timestamp,
|
||||
creator, subject, source, language, coverage, rights, license)
|
||||
values ( ?, ?, ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ? )}, undef,
|
||||
$query->param("DC.Title"), $query->param("DC.Description"), $userinfo->{'id'},
|
||||
$query->param("DC.Creator"), $query->param("DC.Subject"), $query->param("DC.Source"),
|
||||
$query->param("DC.Language"), $query->param("DC.Coverage"),
|
||||
$query->param("DC.Rights"), $query->param("DC.License")) or die $dbh->errstr;
|
||||
|
||||
#get the id of the inserted db entry
|
||||
$sth = $dbh->prepare(qq{select last_insert_id() }) or die $dbh->errstr;
|
||||
$sth->execute() or die $dbh->errstr;
|
||||
my ($id) = $sth->fetchrow_array() or die $dbh->errstr;
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
#get the id of the inserted db entry
|
||||
$sth = $dbh->prepare(qq{select last_insert_id() }) or die $dbh->errstr;
|
||||
$sth->execute() or die $dbh->errstr;
|
||||
my ($id) = $sth->fetchrow_array() or die $dbh->errstr;
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
|
||||
#save uploaded file into temppath
|
||||
$upload_filehandle = $query->upload("file");
|
||||
open(TEMPFILE, ">/tmp/$id");
|
||||
while ( <$upload_filehandle> )
|
||||
{
|
||||
print TEMPFILE;
|
||||
}
|
||||
close TEMPFILE;
|
||||
#save uploaded file into temppath
|
||||
$upload_filehandle = $query->upload("file");
|
||||
open(TEMPFILE, ">/tmp/$id");
|
||||
while ( <$upload_filehandle> )
|
||||
{
|
||||
print TEMPFILE;
|
||||
}
|
||||
close TEMPFILE;
|
||||
|
||||
print $query->redirect("index.pl?information=information_uploaded&value=$domain/video/".urlencode($query->param("DC.Title"))."/$id/");
|
||||
print $query->redirect("index.pl?information=information_uploaded&value=$domain/video/".urlencode($query->param("DC.Title"))."/$id/");
|
||||
}
|
||||
else
|
||||
{
|
||||
print $query->redirect("index.pl?error=error_202c");
|
||||
print $query->redirect("index.pl?error=error_202c");
|
||||
}
|
||||
|
|
382
trunk/video.pl
382
trunk/video.pl
|
@ -11,224 +11,224 @@ $session = new CGI::Session;
|
|||
|
||||
if($query->url_param('action') eq 'edit' and $query->url_param('id'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
}
|
||||
if($query->url_param('action') eq 'bookmark' and $query->url_param('id'))
|
||||
{
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
}
|
||||
#check if id or title is passed
|
||||
elsif($query->url_param('title') or $query->url_param('id'))
|
||||
{
|
||||
if($query->url_param('id'))
|
||||
{
|
||||
#if id is passed ignore title and check for the id
|
||||
$dbquery = "select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
||||
v.creator, v.subject, v.source, v.language, v.coverage, v.rights,
|
||||
v.license, filesize, duration, width, height, fps, viewcount, downloadcount
|
||||
from videos as v, users as u where v.id = ? and u.id=v.userid";
|
||||
if($query->url_param('id'))
|
||||
{
|
||||
#if id is passed ignore title and check for the id
|
||||
$dbquery = "select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
||||
v.creator, v.subject, v.source, v.language, v.coverage, v.rights,
|
||||
v.license, filesize, duration, width, height, fps, viewcount, downloadcount
|
||||
from videos as v, users as u where v.id = ? and u.id=v.userid";
|
||||
|
||||
@args = ($query->url_param('id'));
|
||||
}
|
||||
else
|
||||
{
|
||||
#if no id was passed there has to be a title we search for
|
||||
$dbquery = "select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
||||
v.creator, v.subject, v.source, v.language, v.coverage, v.rights,
|
||||
v.license, filesize, duration, width, height, fps, viewcount, downloadcount
|
||||
from videos as v, users as u where v.title = ? and u.id=v.userid";
|
||||
@args = ($query->url_param('id'));
|
||||
}
|
||||
else
|
||||
{
|
||||
#if no id was passed there has to be a title we search for
|
||||
$dbquery = "select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
||||
v.creator, v.subject, v.source, v.language, v.coverage, v.rights,
|
||||
v.license, filesize, duration, width, height, fps, viewcount, downloadcount
|
||||
from videos as v, users as u where v.title = ? and u.id=v.userid";
|
||||
|
||||
@args = ($query->url_param('title'));
|
||||
}
|
||||
@args = ($query->url_param('title'));
|
||||
}
|
||||
|
||||
$sth = $dbh->prepare($dbquery);
|
||||
$rowcount = $sth->execute(@args) or die $dbh->errstr;
|
||||
$sth = $dbh->prepare($dbquery);
|
||||
$rowcount = $sth->execute(@args) or die $dbh->errstr;
|
||||
|
||||
#if the args are wrong there my be zero results
|
||||
#if there was a title passed, then perform a search
|
||||
if($rowcount == 0 and $query->url_param('title'))
|
||||
{
|
||||
$dbquery = "select v.id, v.title, v.description, u.username,
|
||||
from_unixtime( v.timestamp ), v.creator, v.subject,
|
||||
v.source, v.language, v.coverage, v.rights, v.license, filesize,
|
||||
duration, width, height, fps, viewcount, downloadcount, 1";
|
||||
$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)";
|
||||
#if the args are wrong there my be zero results
|
||||
#if there was a title passed, then perform a search
|
||||
if($rowcount == 0 and $query->url_param('title'))
|
||||
{
|
||||
$dbquery = "select v.id, v.title, v.description, u.username,
|
||||
from_unixtime( v.timestamp ), v.creator, v.subject,
|
||||
v.source, v.language, v.coverage, v.rights, v.license, filesize,
|
||||
duration, width, height, fps, viewcount, downloadcount, 1";
|
||||
$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)";
|
||||
|
||||
@args = ($query->url_param('title'), $query->url_param('title'));
|
||||
@args = ($query->url_param('title'), $query->url_param('title'));
|
||||
|
||||
$sth = $dbh->prepare($dbquery);
|
||||
$rowcount = $sth->execute(@args) or die $dbh->errstr;
|
||||
}
|
||||
$sth = $dbh->prepare($dbquery);
|
||||
$rowcount = $sth->execute(@args) or die $dbh->errstr;
|
||||
}
|
||||
|
||||
#from this point on, do not use $query->param('id') anymore - we do not know what was given
|
||||
if($rowcount == 0)
|
||||
{
|
||||
#still no results
|
||||
#there is nothing we can do now - this video doesn't exist...
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
}
|
||||
elsif($rowcount == 1)
|
||||
{
|
||||
if($query->param('embed') eq "video")
|
||||
{
|
||||
$page->{'embed'} = "video";
|
||||
}
|
||||
elsif($query->param('embed') eq "preview")
|
||||
{
|
||||
$page->{'embed'} = "preview";
|
||||
}
|
||||
#from this point on, do not use $query->param('id') anymore - we do not know what was given
|
||||
if($rowcount == 0)
|
||||
{
|
||||
#still no results
|
||||
#there is nothing we can do now - this video doesn't exist...
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
}
|
||||
elsif($rowcount == 1)
|
||||
{
|
||||
if($query->param('embed') eq "video")
|
||||
{
|
||||
$page->{'embed'} = "video";
|
||||
}
|
||||
elsif($query->param('embed') eq "preview")
|
||||
{
|
||||
$page->{'embed'} = "preview";
|
||||
}
|
||||
|
||||
#if there was a single result, display the video
|
||||
my ($id, $title, $description, $publisher, $timestamp, $creator, $subject,
|
||||
$source, $language, $coverage, $rights, $license,
|
||||
$filesize, $duration, $width, $height, $fps, $viewcount, $downloadcount) = $sth->fetchrow_array();
|
||||
#if there was a single result, display the video
|
||||
my ($id, $title, $description, $publisher, $timestamp, $creator, $subject,
|
||||
$source, $language, $coverage, $rights, $license,
|
||||
$filesize, $duration, $width, $height, $fps, $viewcount, $downloadcount) = $sth->fetchrow_array();
|
||||
|
||||
#finish query
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
#finish query
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
|
||||
#if user is logged in
|
||||
if($userinfo->{'username'})
|
||||
{
|
||||
#check if a comment is about to be created
|
||||
if($query->param('comment'))
|
||||
{
|
||||
#output infobox
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
$page->{'message'}->{'text'} = "information_comment_created";
|
||||
#if user is logged in
|
||||
if($userinfo->{'username'})
|
||||
{
|
||||
#check if a comment is about to be created
|
||||
if($query->param('comment'))
|
||||
{
|
||||
#output infobox
|
||||
$page->{'message'}->{'type'} = "information";
|
||||
$page->{'message'}->{'text'} = "information_comment_created";
|
||||
|
||||
#add to database
|
||||
$dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef,
|
||||
$userinfo->{'id'}, $id, $query->param('comment')) or die $dbh->errstr;
|
||||
}
|
||||
}
|
||||
#add to database
|
||||
$dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef,
|
||||
$userinfo->{'id'}, $id, $query->param('comment')) or die $dbh->errstr;
|
||||
}
|
||||
}
|
||||
|
||||
#if referer is not the local site update referer table
|
||||
$referer = $query->referer() or $referer = '';
|
||||
if($referer !~ /^$domain/)
|
||||
{
|
||||
#check if already in database
|
||||
$sth = $dbh->prepare(qq{select 1 from referer where videoid = ? and referer = ? }) or die $dbh->errstr;
|
||||
my $rowcount = $sth->execute($id, $referer) or die $dbh->errstr;
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
#if referer is not the local site update referer table
|
||||
$referer = $query->referer() or $referer = '';
|
||||
if($referer !~ /^$domain/)
|
||||
{
|
||||
#check if already in database
|
||||
$sth = $dbh->prepare(qq{select 1 from referer where videoid = ? and referer = ? }) or die $dbh->errstr;
|
||||
my $rowcount = $sth->execute($id, $referer) or die $dbh->errstr;
|
||||
$sth->finish() or die $dbh->errstr;
|
||||
|
||||
if($rowcount > 0)
|
||||
{
|
||||
#video is in database - increase referercount
|
||||
$dbh->do(qq{update referer set count=count+1 where videoid = ? and referer = ? }, undef, $id, $referer) or die $dbh->errstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
#add new referer
|
||||
$dbh->do(qq{insert into referer (videoid, referer) values (?, ?) }, undef, $id, $referer) or die $dbh->errstr;
|
||||
}
|
||||
}
|
||||
if($rowcount > 0)
|
||||
{
|
||||
#video is in database - increase referercount
|
||||
$dbh->do(qq{update referer set count=count+1 where videoid = ? and referer = ? }, undef, $id, $referer) or die $dbh->errstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
#add new referer
|
||||
$dbh->do(qq{insert into referer (videoid, referer) values (?, ?) }, undef, $id, $referer) or die $dbh->errstr;
|
||||
}
|
||||
}
|
||||
|
||||
if($query->param('cortado') eq 'true')
|
||||
{
|
||||
$cortado = 'true';
|
||||
}
|
||||
elsif($query->param('cortado') eq 'false')
|
||||
{
|
||||
$cortado = 'false';
|
||||
}
|
||||
elsif($userinfo->{'cortado'} eq 'true')
|
||||
{
|
||||
$cortado = 'true';
|
||||
}
|
||||
elsif($userinfo->{'cortado'} eq 'false')
|
||||
{
|
||||
$cortado = 'false';
|
||||
}
|
||||
elsif($query->cookie('cortado') eq 'true')
|
||||
{
|
||||
$cortado = 'true';
|
||||
}
|
||||
elsif($query->cookie('cortado') eq 'false')
|
||||
{
|
||||
$cortado = 'false';
|
||||
}
|
||||
else
|
||||
{
|
||||
$cortado = 'true';
|
||||
}
|
||||
if($query->param('cortado') eq 'true')
|
||||
{
|
||||
$cortado = 'true';
|
||||
}
|
||||
elsif($query->param('cortado') eq 'false')
|
||||
{
|
||||
$cortado = 'false';
|
||||
}
|
||||
elsif($userinfo->{'cortado'} eq 'true')
|
||||
{
|
||||
$cortado = 'true';
|
||||
}
|
||||
elsif($userinfo->{'cortado'} eq 'false')
|
||||
{
|
||||
$cortado = 'false';
|
||||
}
|
||||
elsif($query->cookie('cortado') eq 'true')
|
||||
{
|
||||
$cortado = 'true';
|
||||
}
|
||||
elsif($query->cookie('cortado') eq 'false')
|
||||
{
|
||||
$cortado = 'false';
|
||||
}
|
||||
else
|
||||
{
|
||||
$cortado = 'true';
|
||||
}
|
||||
|
||||
#before code cleanup, this was a really obfuscated array/hash creation
|
||||
push @{ $page->{'video'} },
|
||||
{
|
||||
'thumbnail' => "$domain/video-stills/$id",
|
||||
'cortado' => $cortado,
|
||||
'filesize' => $filesize,
|
||||
'duration' => $duration,
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'fps' => $fps,
|
||||
'viewcount' => $viewcount,
|
||||
'downloadcount' => $downloadcount,
|
||||
'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false",
|
||||
'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/"],
|
||||
'dc:source' => [$source],
|
||||
'dc:language' => [$language],
|
||||
'dc:coverage' => [$coverage],
|
||||
'dc:rights' => [$rights]
|
||||
},
|
||||
'cc:License' =>
|
||||
{
|
||||
'rdf:about' => $license
|
||||
}
|
||||
}
|
||||
};
|
||||
#before code cleanup, this was a really obfuscated array/hash creation
|
||||
push @{ $page->{'video'} },
|
||||
{
|
||||
'thumbnail' => "$domain/video-stills/$id",
|
||||
'cortado' => $cortado,
|
||||
'filesize' => $filesize,
|
||||
'duration' => $duration,
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'fps' => $fps,
|
||||
'viewcount' => $viewcount,
|
||||
'downloadcount' => $downloadcount,
|
||||
'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false",
|
||||
'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/"],
|
||||
'dc:source' => [$source],
|
||||
'dc:language' => [$language],
|
||||
'dc:coverage' => [$coverage],
|
||||
'dc:rights' => [$rights]
|
||||
},
|
||||
'cc:License' =>
|
||||
{
|
||||
'rdf:about' => $license
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#get comments
|
||||
$sth = $dbh->prepare(qq{select comments.id, comments.text, users.username, from_unixtime( comments.timestamp )
|
||||
from comments, users where
|
||||
comments.videoid=? and users.id=comments.userid}) or die $dbh->errstr;
|
||||
$sth->execute($id) or die $dbh->errstr;
|
||||
while (my ($commentid, $text, $username, $timestamp) = $sth->fetchrow_array())
|
||||
{
|
||||
push @{ $page->{'comments'}->{'comment'} }, {
|
||||
'text' => [$text],
|
||||
'username' => $username,
|
||||
'timestamp' => $timestamp,
|
||||
'id' => $commentid
|
||||
};
|
||||
}
|
||||
#get comments
|
||||
$sth = $dbh->prepare(qq{select comments.id, comments.text, users.username, from_unixtime( comments.timestamp )
|
||||
from comments, users where
|
||||
comments.videoid=? and users.id=comments.userid}) or die $dbh->errstr;
|
||||
$sth->execute($id) or die $dbh->errstr;
|
||||
while (my ($commentid, $text, $username, $timestamp) = $sth->fetchrow_array())
|
||||
{
|
||||
push @{ $page->{'comments'}->{'comment'} }, {
|
||||
'text' => [$text],
|
||||
'username' => $username,
|
||||
'timestamp' => $timestamp,
|
||||
'id' => $commentid
|
||||
};
|
||||
}
|
||||
|
||||
#get referers
|
||||
$sth = $dbh->prepare(qq{select count, referer from referer where videoid=?}) or die $dbh->errstr;
|
||||
$sth->execute($id) or die $dbh->errstr;
|
||||
while (my ($count, $referer) = $sth->fetchrow_array())
|
||||
{
|
||||
$referer or $referer = 'no referer (refreshed, manually entered url or bookmark)';
|
||||
push @{ $page->{'referers'}->{'referer'} }, {
|
||||
'count' => $count,
|
||||
'referer' => $referer
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#when an ambigous title was passed there may me many results
|
||||
#redirect to an appropriate search or throw an error with a link to such a search
|
||||
}
|
||||
#get referers
|
||||
$sth = $dbh->prepare(qq{select count, referer from referer where videoid=?}) or die $dbh->errstr;
|
||||
$sth->execute($id) or die $dbh->errstr;
|
||||
while (my ($count, $referer) = $sth->fetchrow_array())
|
||||
{
|
||||
$referer or $referer = 'no referer (refreshed, manually entered url or bookmark)';
|
||||
push @{ $page->{'referers'}->{'referer'} }, {
|
||||
'count' => $count,
|
||||
'referer' => $referer
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#when an ambigous title was passed there may me many results
|
||||
#redirect to an appropriate search or throw an error with a link to such a search
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
$page->{'message'}->{'type'} = "error";
|
||||
$page->{'message'}->{'text'} = "error_202c";
|
||||
}
|
||||
|
||||
print output_page();
|
||||
|
|
Loading…
Reference in a new issue