deleted ratings, added timestamp to comments, added video information

git-svn-id: http://yolanda.mister-muffin.de/svn@132 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2007-10-24 10:50:49 +00:00
parent 0d2b5deec1
commit 99e87dbcdf
2 changed files with 31 additions and 34 deletions

View file

@ -17,8 +17,6 @@ $dbh->do(qq{drop table tagcloud});
$dbh->do(qq{drop table referer}); $dbh->do(qq{drop table referer});
$dbh->do(qq{drop table ratings});
$dbh->do(qq{drop table comments}); $dbh->do(qq{drop table comments});
$dbh->do(qq{create table $dbh->do(qq{create table
@ -127,15 +125,6 @@ $dbh->do(qq{create table
) )
}) or die $dbh->errstr; }) or die $dbh->errstr;
$dbh->do(qq{create table
ratings
(
videoid int not null,
userid int not null,
rating tinyint not null
)
}) or die $dbh->errstr;
$dbh->do(qq{create table $dbh->do(qq{create table
comments comments
( (
@ -143,6 +132,7 @@ $dbh->do(qq{create table
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,
primary key (id) primary key (id)
) )
}) or die $dbh->errstr; }) or die $dbh->errstr;

View file

@ -25,9 +25,11 @@ if($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
$sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ), $sth = $dbh->prepare(qq{select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
creator, subject, contributor, source, language, coverage, rights, license v.creator, v.subject, v.contributor, v.source, v.language, v.coverage, v.rights,
from videos where id = ? }) or die $dbh->errstr; 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;
$rowcount = $sth->execute($query->url_param('id')) or die $dbh->errstr; $rowcount = $sth->execute($query->url_param('id')) or die $dbh->errstr;
} }
else else
@ -60,14 +62,15 @@ if($query->url_param('title') or $query->url_param('id'))
elsif($rowcount == 1) elsif($rowcount == 1)
{ {
#if there was a single result, display the video #if there was a single result, display the video
my ($id, $title, $description, $userid, $timestamp, $creator, $subject, my ($id, $title, $description, $username, $timestamp, $creator, $subject,
$contributor, $source, $language, $coverage, $rights, $license,) = $sth->fetchrow_array(); $contributor, $source, $language, $coverage, $rights, $license,
$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($userid = get_userid_from_sid($session->id) if($userid = get_userid_from_sid($session->id))
{ {
#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'))
@ -77,12 +80,7 @@ if($query->url_param('title') or $query->url_param('id'))
$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) values (?, ?, ?)}, undef, $userid, $id, $query->param('comment')) or die $dbh->errstr; $dbh->do(qq{insert into comments (userid, videoid, text, timestamp) values (?, ?, ?, unix_timestamp())}, undef, $userid, $id, $query->param('comment')) or die $dbh->errstr;
}
#check if user is about to rate video
elsif($query->param('rating'))
{
$dbh->do(qq{insert into ratings (userid, videoid, rating) values (?, ?, ?)}, undef, $userid, $id, $query->param('rating')) or die $dbh->errstr;
} }
} }
@ -115,7 +113,14 @@ if($query->url_param('title') or $query->url_param('id'))
#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' => ['./video-stills/225x150/4chan_city_mashup.png'], 'thumbnail' => "./video-stills/$id",
'filesize' => $filesize,
'duration' => $duration,
'width' => $width,
'height' => $height,
'fps' => $fps,
'viewcount' => $viewcount,
'downloadcount' => $downloadcount,
'rdf:RDF' => 'rdf:RDF' =>
{ {
'cc:Work' => 'cc:Work' =>
@ -125,7 +130,7 @@ if($query->url_param('title') or $query->url_param('id'))
'dc:creator' => [$creator], 'dc:creator' => [$creator],
'dc:subject' => [$subject], 'dc:subject' => [$subject],
'dc:description' => [$description], 'dc:description' => [$description],
'dc:publisher' => [get_username_from_id($userid)], 'dc:publisher' => [$username],
'dc:contributor' => [$contributor], 'dc:contributor' => [$contributor],
'dc:date' => [$timestamp], 'dc:date' => [$timestamp],
'dc:identifier' => ["video.pl?title=$title&id=$id"], 'dc:identifier' => ["video.pl?title=$title&id=$id"],
@ -142,20 +147,22 @@ if($query->url_param('title') or $query->url_param('id'))
}; };
#get comments #get comments
$sth = $dbh->prepare(qq{select comments.text, users.username from comments, users where $sth = $dbh->prepare(qq{select comments.text, users.username, from_unixtime( comments.timestamp )
comments.videoid=? and users.id=comments.userid}); from comments, users where
$sth->execute($id); comments.videoid=? and users.id=comments.userid}) or die $dbh->errstr;
while (my ($text, $username) = $sth->fetchrow_array()) $sth->execute($id) or die $dbh->errstr;
while (my ($text, $username, $timestamp) = $sth->fetchrow_array())
{ {
push @{ $page->{'comments'}->{'comment'} }, { push @{ $page->{'comments'}->{'comment'} }, {
'text' => decode_utf8($text), 'text' => [decode_utf8($text)],
'user' => $username 'username' => [$username],
'timestamp' => [$timestamp]
}; };
} }
#get referers #get referers
$sth = $dbh->prepare(qq{select count, referer from referer where videoid=?}); $sth = $dbh->prepare(qq{select count, referer from referer where videoid=?}) or die $dbh->errstr;
$sth->execute($id); $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)';