2007-10-17 19:14:34 +00:00
|
|
|
require "include.pl";
|
|
|
|
require "functions.pl";
|
|
|
|
|
|
|
|
#initialize session data
|
|
|
|
CGI::Session->name($session_name);
|
|
|
|
$query = new CGI;
|
|
|
|
$session = new CGI::Session;
|
|
|
|
|
2007-10-21 16:41:29 +00:00
|
|
|
#check if id or title is passed
|
2007-10-23 23:12:41 +00:00
|
|
|
if($query->url_param('title') or $query->url_param('id'))
|
2007-10-17 19:14:34 +00:00
|
|
|
{
|
|
|
|
%page = ();
|
|
|
|
|
|
|
|
#if a username is associated with session id, username is nonempty
|
|
|
|
$page->{'username'} = get_username_from_sid($session->id);
|
|
|
|
$page->{'locale'} = $locale;
|
|
|
|
$page->{'stylesheet'} = $stylesheet;
|
|
|
|
$page->{'xmlns:dc'} = $xmlns_dc;
|
|
|
|
$page->{'xmlns:cc'} = $xmlns_cc;
|
|
|
|
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
|
|
|
|
|
|
|
#connect to db
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
|
|
|
|
2007-10-23 23:12:41 +00:00
|
|
|
if($query->url_param('id'))
|
2007-10-18 08:20:28 +00:00
|
|
|
{
|
2007-10-21 16:41:29 +00:00
|
|
|
#if id is passed ignore title and check for the id
|
2007-10-24 10:50:49 +00:00
|
|
|
$sth = $dbh->prepare(qq{select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
|
|
|
v.creator, v.subject, v.contributor, v.source, v.language, v.coverage, v.rights,
|
|
|
|
v.license, filesize, duration, width, height, fps, viewcount,
|
|
|
|
downloadcount
|
|
|
|
from videos as v, users as u where v.id = ? and u.id=v.userid }) or die $dbh->errstr;
|
2007-10-23 23:12:41 +00:00
|
|
|
$rowcount = $sth->execute($query->url_param('id')) or die $dbh->errstr;
|
2007-10-18 08:20:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-21 16:41:29 +00:00
|
|
|
#if no id was passed there has to be a title we search for
|
2007-10-24 11:25:18 +00:00
|
|
|
$sth = $dbh->prepare(qq{select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
|
|
|
v.creator, v.subject, v.contributor, v.source, v.language, v.coverage, v.rights,
|
|
|
|
v.license, filesize, duration, width, height, fps, viewcount,
|
|
|
|
downloadcount
|
|
|
|
from videos as v, users as u where v.title = ? and u.id=v.userid }) or die $dbh->errstr;
|
2007-10-23 23:12:41 +00:00
|
|
|
$rowcount = $sth->execute($query->url_param('title')) or die $dbh->errstr;
|
2007-10-18 08:20:28 +00:00
|
|
|
}
|
2007-10-17 19:14:34 +00:00
|
|
|
|
2007-10-21 16:41:29 +00:00
|
|
|
#if the args are wrong there my be zero results
|
|
|
|
#if there was a title passed, then perform a search
|
2007-10-23 23:12:41 +00:00
|
|
|
if($rowcount == 0 and $query->url_param('title'))
|
2007-10-17 19:14:34 +00:00
|
|
|
{
|
2007-10-24 11:25:18 +00:00
|
|
|
$sth = $dbh->prepare(qq{select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
|
|
|
v.creator, v.subject, v.contributor, v.source, v.language, v.coverage, v.rights,
|
|
|
|
v.license, filesize, duration, width, height, fps, viewcount,
|
|
|
|
downloadcount
|
|
|
|
from videos as v, users as u where match(v.title, v.description, v.subject) against( ? )
|
|
|
|
and u.id=v.userid }) or die $dbh->errstr;
|
2007-10-23 23:12:41 +00:00
|
|
|
$rowcount = $sth->execute($query->url_param('title')) or die $dbh->errstr;
|
2007-10-21 16:41:29 +00:00
|
|
|
}
|
|
|
|
|
2007-10-22 19:15:39 +00:00
|
|
|
#from this point on, do not use $query->param('id') anymore - we do not know what was given
|
2007-10-21 16:41:29 +00:00
|
|
|
if($rowcount == 0)
|
|
|
|
{
|
|
|
|
#still no results
|
2007-10-21 22:55:29 +00:00
|
|
|
#there is nothing we can do now - this video doesn't exist...
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_202c";
|
2007-10-21 16:41:29 +00:00
|
|
|
}
|
|
|
|
elsif($rowcount == 1)
|
|
|
|
{
|
|
|
|
#if there was a single result, display the video
|
2007-10-24 10:50:49 +00:00
|
|
|
my ($id, $title, $description, $username, $timestamp, $creator, $subject,
|
|
|
|
$contributor, $source, $language, $coverage, $rights, $license,
|
|
|
|
$filesize, $duration, $width, $height, $fps, $viewcount, $downloadcount) = $sth->fetchrow_array();
|
2007-10-21 22:28:02 +00:00
|
|
|
|
|
|
|
#finish query
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
|
|
|
|
2007-10-23 23:12:41 +00:00
|
|
|
#if user is logged in
|
2007-10-24 10:50:49 +00:00
|
|
|
if($userid = get_userid_from_sid($session->id))
|
2007-10-22 19:15:39 +00:00
|
|
|
{
|
2007-10-23 23:12:41 +00:00
|
|
|
#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
|
2007-10-24 10:50:49 +00:00
|
|
|
$dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef, $userid, $id, $query->param('comment')) or die $dbh->errstr;
|
2007-10-23 23:12:41 +00:00
|
|
|
}
|
2007-10-22 19:15:39 +00:00
|
|
|
}
|
|
|
|
|
2007-10-21 22:28:02 +00:00
|
|
|
#if referer is not the local site update referer table
|
|
|
|
$referer = $query->referer() or $referer = '';
|
|
|
|
$server_name = $query->server_name();
|
|
|
|
if($referer !~ /^\w+:\/\/$server_name/)
|
|
|
|
{
|
|
|
|
#check if already in database
|
|
|
|
$sth = $dbh->prepare(qq{select 1 from referer where videoid = ? and referer = ? }) or die $dbh->errstr;
|
2007-10-22 19:15:39 +00:00
|
|
|
my $rowcount = $sth->execute($id, $referer) or die $dbh->errstr;
|
2007-10-21 22:28:02 +00:00
|
|
|
$sth->finish() or die $dbh->errstr;
|
|
|
|
|
|
|
|
if($rowcount > 0)
|
|
|
|
{
|
|
|
|
#video is in database - increase referercount
|
2007-10-24 11:25:18 +00:00
|
|
|
$dbh->do(qq{update referer set count=count+1 where videoid = ? and referer = ? }, undef, $id, $referer) or die $dbh->errstr;
|
2007-10-21 22:28:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#add new referer
|
2007-10-24 11:25:18 +00:00
|
|
|
$dbh->do(qq{insert into referer (videoid, referer) values (?, ?) }, undef, $id, $referer) or die $dbh->errstr;
|
2007-10-21 22:28:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-17 19:14:34 +00:00
|
|
|
#before code cleanup, this was a really obfuscated array/hash creation
|
|
|
|
push @{ $page->{'video'} },
|
|
|
|
{
|
2007-10-24 10:50:49 +00:00
|
|
|
'thumbnail' => "./video-stills/$id",
|
|
|
|
'filesize' => $filesize,
|
|
|
|
'duration' => $duration,
|
|
|
|
'width' => $width,
|
|
|
|
'height' => $height,
|
|
|
|
'fps' => $fps,
|
|
|
|
'viewcount' => $viewcount,
|
|
|
|
'downloadcount' => $downloadcount,
|
2007-10-17 19:14:34 +00:00
|
|
|
'rdf:RDF' =>
|
|
|
|
{
|
|
|
|
'cc:Work' =>
|
|
|
|
{
|
2007-10-23 23:12:41 +00:00
|
|
|
'rdf:about' => "download.pl?id=$id&view=true",
|
2007-10-20 01:55:25 +00:00
|
|
|
'dc:title' => [$title],
|
|
|
|
'dc:creator' => [$creator],
|
|
|
|
'dc:subject' => [$subject],
|
|
|
|
'dc:description' => [$description],
|
2007-10-24 10:50:49 +00:00
|
|
|
'dc:publisher' => [$username],
|
2007-10-20 01:55:25 +00:00
|
|
|
'dc:contributor' => [$contributor],
|
|
|
|
'dc:date' => [$timestamp],
|
2007-10-23 23:12:41 +00:00
|
|
|
'dc:identifier' => ["video.pl?title=$title&id=$id"],
|
2007-10-20 01:55:25 +00:00
|
|
|
'dc:source' => [$source],
|
|
|
|
'dc:language' => [$language],
|
|
|
|
'dc:coverage' => [$coverage],
|
|
|
|
'dc:rights' => [$rights]
|
2007-10-17 19:14:34 +00:00
|
|
|
},
|
|
|
|
'cc:License' =>
|
|
|
|
{
|
2007-10-20 01:55:25 +00:00
|
|
|
'rdf:about' => $license
|
2007-10-17 19:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2007-10-22 20:50:45 +00:00
|
|
|
|
|
|
|
#get comments
|
2007-10-24 10:50:49 +00:00
|
|
|
$sth = $dbh->prepare(qq{select 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 ($text, $username, $timestamp) = $sth->fetchrow_array())
|
2007-10-22 20:50:45 +00:00
|
|
|
{
|
|
|
|
push @{ $page->{'comments'}->{'comment'} }, {
|
2007-10-24 10:50:49 +00:00
|
|
|
'text' => [decode_utf8($text)],
|
|
|
|
'username' => [$username],
|
|
|
|
'timestamp' => [$timestamp]
|
2007-10-22 20:50:45 +00:00
|
|
|
};
|
|
|
|
}
|
2007-10-23 21:29:16 +00:00
|
|
|
|
|
|
|
#get referers
|
2007-10-24 10:50:49 +00:00
|
|
|
$sth = $dbh->prepare(qq{select count, referer from referer where videoid=?}) or die $dbh->errstr;
|
|
|
|
$sth->execute($id) or die $dbh->errstr;
|
2007-10-23 21:29:16 +00:00
|
|
|
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
|
|
|
|
};
|
2007-10-24 10:50:49 +00:00
|
|
|
}
|
2007-10-17 19:14:34 +00:00
|
|
|
}
|
2007-10-18 08:20:28 +00:00
|
|
|
else
|
|
|
|
{
|
2007-10-21 16:41:29 +00:00
|
|
|
#when an ambigous title was passed there may me many results - display them like search.pl does
|
2007-10-23 23:12:41 +00:00
|
|
|
$page->{results}->{query} = decode_utf8($query->url_param('title'));
|
2007-10-18 08:20:28 +00:00
|
|
|
#get every returned value
|
2007-10-23 23:12:41 +00:00
|
|
|
while (my ($id, $title, $description, $userid, $timestamp) = $sth->fetchrow_array())
|
2007-10-18 08:20:28 +00:00
|
|
|
{
|
|
|
|
#before code cleanup, this was a really obfuscated array/hash creation
|
|
|
|
push @{ $page->{'results'}->{'result'} },
|
|
|
|
{
|
|
|
|
'thumbnail' => ['./video-stills/225x150/4chan_city_mashup.png'],
|
|
|
|
'rdf:RDF' =>
|
|
|
|
{
|
|
|
|
'cc:Work' =>
|
|
|
|
{
|
2007-10-23 23:12:41 +00:00
|
|
|
'rdf:about' => "./video.pl?title=$title&id=".$id,
|
2007-10-18 08:20:28 +00:00
|
|
|
'dc:title' => [$title],
|
|
|
|
'dc:date' => [$timestamp],
|
|
|
|
'dc:publisher' => [get_username_from_id($userid)],
|
2007-10-18 09:53:32 +00:00
|
|
|
'dc:description'=> [$description]
|
2007-10-18 08:20:28 +00:00
|
|
|
},
|
|
|
|
'cc:License' =>
|
|
|
|
{
|
|
|
|
'rdf:about' => 'http://creativecommons.org/licenses/GPL/2.0/'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2007-10-21 22:28:02 +00:00
|
|
|
#finish query
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
2007-10-18 08:20:28 +00:00
|
|
|
}
|
2007-10-17 19:14:34 +00:00
|
|
|
|
|
|
|
#close db
|
|
|
|
$dbh->disconnect() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#print xml http header along with session cookie
|
|
|
|
print $session->header(-type=>'text/xml');
|
|
|
|
|
|
|
|
#print xml
|
|
|
|
print XMLout($page, KeyAttr => {}, XMLDecl => $XMLDecl, RootName => 'page');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-21 22:55:29 +00:00
|
|
|
%page = ();
|
|
|
|
|
|
|
|
#if a username is associated with session id, username is nonempty
|
|
|
|
$page->{'username'} = get_username_from_sid($session->id);
|
|
|
|
$page->{'locale'} = $locale;
|
|
|
|
$page->{'stylesheet'} = $stylesheet;
|
|
|
|
$page->{'xmlns:dc'} = $xmlns_dc;
|
|
|
|
$page->{'xmlns:cc'} = $xmlns_cc;
|
|
|
|
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
|
|
|
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_202c";
|
|
|
|
|
|
|
|
#print xml http header along with session cookie
|
|
|
|
print $session->header(-type=>'text/xml');
|
|
|
|
|
|
|
|
#print xml
|
|
|
|
print XMLout($page, KeyAttr => {}, XMLDecl => $XMLDecl, RootName => 'page');
|
2007-10-17 19:14:34 +00:00
|
|
|
}
|