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