2007-10-17 19:14:34 +00:00
|
|
|
require "functions.pl";
|
|
|
|
|
|
|
|
#initialize session data
|
|
|
|
CGI::Session->name($session_name);
|
|
|
|
$query = new CGI;
|
|
|
|
$session = new CGI::Session;
|
|
|
|
|
2007-10-29 15:00:40 +00:00
|
|
|
@userinfo = get_userinfo_from_sid($session->id);
|
2007-10-27 09:17:30 +00:00
|
|
|
|
2007-10-29 15:00:40 +00:00
|
|
|
@page = get_page_array(@userinfo);
|
2007-10-27 09:17:30 +00:00
|
|
|
|
2007-11-26 14:25:31 +00:00
|
|
|
if($query->url_param('action') eq 'edit' and $query->url_param('id'))
|
|
|
|
{
|
|
|
|
$page->{'message'}->{'type'} = "information";
|
|
|
|
}
|
|
|
|
if($query->url_param('action') eq 'bookmark' and $query->url_param('id'))
|
2007-10-27 11:59:23 +00:00
|
|
|
{
|
|
|
|
$page->{'message'}->{'type'} = "information";
|
|
|
|
}
|
2007-10-21 16:41:29 +00:00
|
|
|
#check if id or title is passed
|
2007-10-27 11:59:23 +00:00
|
|
|
elsif($query->url_param('title') or $query->url_param('id'))
|
2007-10-17 19:14:34 +00:00
|
|
|
{
|
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-29 16:47:16 +00:00
|
|
|
$dbquery = "select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
2007-10-24 10:50:49 +00:00
|
|
|
v.creator, v.subject, v.contributor, v.source, v.language, v.coverage, v.rights,
|
2007-10-29 16:47:16 +00:00
|
|
|
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'));
|
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-29 16:47:16 +00:00
|
|
|
$dbquery = "select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
2007-10-24 11:25:18 +00:00
|
|
|
v.creator, v.subject, v.contributor, v.source, v.language, v.coverage, v.rights,
|
2007-10-29 16:47:16 +00:00
|
|
|
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'));
|
2007-10-18 08:20:28 +00:00
|
|
|
}
|
2007-10-17 19:14:34 +00:00
|
|
|
|
2007-10-29 16:47:16 +00:00
|
|
|
$sth = $dbh->prepare($dbquery);
|
|
|
|
$rowcount = $sth->execute(@args) or die $dbh->errstr;
|
|
|
|
|
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-12-14 06:18:58 +00:00
|
|
|
$dbquery = "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, 1";
|
2007-10-29 16:47:16 +00:00
|
|
|
$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)";
|
|
|
|
|
2007-12-01 18:04:28 +00:00
|
|
|
@args = ($query->url_param('title'), $query->url_param('title'));
|
2007-10-29 16:47:16 +00:00
|
|
|
|
|
|
|
$sth = $dbh->prepare($dbquery);
|
|
|
|
$rowcount = $sth->execute(@args) 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)
|
|
|
|
{
|
2007-11-07 06:55:02 +00:00
|
|
|
$page->{'embed'} = $query->param('embed') eq 'true' ? "true" : "false";
|
|
|
|
|
2007-10-21 16:41:29 +00:00
|
|
|
#if there was a single result, display the video
|
2007-10-29 16:47:16 +00:00
|
|
|
my ($id, $title, $description, $publisher, $timestamp, $creator, $subject,
|
2007-10-24 10:50:49 +00:00
|
|
|
$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-29 15:00:40 +00:00
|
|
|
if($userinfo->{'username'})
|
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-29 15:00:40 +00:00
|
|
|
$dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef,
|
|
|
|
$userinfo->{'id'}, $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 = '';
|
2007-12-17 12:38:02 +00:00
|
|
|
if($referer !~ /^$domain/)
|
2007-10-21 22:28:02 +00:00
|
|
|
{
|
|
|
|
#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-12-17 12:38:02 +00:00
|
|
|
if($query->param('cortado') eq 'true')
|
|
|
|
{
|
|
|
|
$cortado = 'true';
|
|
|
|
}
|
|
|
|
elsif($query->param('cortado') eq 'false')
|
|
|
|
{
|
|
|
|
$cortado = 'false'
|
|
|
|
}
|
|
|
|
elsif($userinfo->{'cortado'} = 1)
|
|
|
|
{
|
|
|
|
$cortado = 'true';
|
|
|
|
}
|
|
|
|
elsif($userinfo->{'cortado'} = 0)
|
|
|
|
{
|
|
|
|
$cortado = 'false';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cortado = 'true';
|
|
|
|
}
|
|
|
|
|
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 12:56:56 +00:00
|
|
|
'thumbnail' => "$domain/video-stills/$id",
|
2007-12-17 12:38:02 +00:00
|
|
|
'cortado' => $cortado,
|
2007-10-24 10:50:49 +00:00
|
|
|
'filesize' => $filesize,
|
|
|
|
'duration' => $duration,
|
|
|
|
'width' => $width,
|
|
|
|
'height' => $height,
|
|
|
|
'fps' => $fps,
|
|
|
|
'viewcount' => $viewcount,
|
|
|
|
'downloadcount' => $downloadcount,
|
2007-11-26 14:25:31 +00:00
|
|
|
'edit' => $userinfo->{'username'} eq $publisher ? "true" : "false",
|
2007-10-17 19:14:34 +00:00
|
|
|
'rdf:RDF' =>
|
|
|
|
{
|
|
|
|
'cc:Work' =>
|
|
|
|
{
|
2007-12-01 18:04:28 +00:00
|
|
|
'rdf:about' => "$domain/download/$id/",
|
2007-10-20 01:55:25 +00:00
|
|
|
'dc:title' => [$title],
|
|
|
|
'dc:creator' => [$creator],
|
|
|
|
'dc:subject' => [$subject],
|
|
|
|
'dc:description' => [$description],
|
2007-10-29 16:47:16 +00:00
|
|
|
'dc:publisher' => [$publisher],
|
2007-10-20 01:55:25 +00:00
|
|
|
'dc:contributor' => [$contributor],
|
|
|
|
'dc:date' => [$timestamp],
|
2007-12-01 18:04:28 +00:00
|
|
|
'dc:identifier' => ["$domain/video/".urlencode($title)."/$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 12:56:56 +00:00
|
|
|
$sth = $dbh->prepare(qq{select comments.id, comments.text, users.username, from_unixtime( comments.timestamp )
|
2007-10-24 10:50:49 +00:00
|
|
|
from comments, users where
|
|
|
|
comments.videoid=? and users.id=comments.userid}) or die $dbh->errstr;
|
|
|
|
$sth->execute($id) or die $dbh->errstr;
|
2007-10-24 12:56:56 +00:00
|
|
|
while (my ($commentid, $text, $username, $timestamp) = $sth->fetchrow_array())
|
2007-10-22 20:50:45 +00:00
|
|
|
{
|
|
|
|
push @{ $page->{'comments'}->{'comment'} }, {
|
2007-10-26 00:35:29 +00:00
|
|
|
'text' => [$text],
|
2007-10-24 12:56:56 +00:00
|
|
|
'username' => $username,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'id' => $commentid
|
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-12-19 23:32:01 +00:00
|
|
|
#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
|
2007-10-18 08:20:28 +00:00
|
|
|
}
|
2007-10-17 19:14:34 +00:00
|
|
|
}
|
|
|
|
else
|
2007-10-24 13:17:31 +00:00
|
|
|
{
|
2007-10-21 22:55:29 +00:00
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_202c";
|
2007-10-17 19:14:34 +00:00
|
|
|
}
|
2007-10-27 09:17:30 +00:00
|
|
|
|
2007-12-17 18:55:33 +00:00
|
|
|
print output_page();
|