From 454deb0c9194c3c4db7bdf3cdcaf196e6382970c Mon Sep 17 00:00:00 2001 From: josch Date: Mon, 22 Oct 2007 19:15:39 +0000 Subject: [PATCH] added comment posting functionality git-svn-id: http://yolanda.mister-muffin.de/svn@123 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/init_sql.pl | 7 +++---- trunk/video.pl | 26 +++++++++++++++++--------- trunk/xsl/xhtml.xsl | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/trunk/init_sql.pl b/trunk/init_sql.pl index 4cae8e3..bcb0580 100644 --- a/trunk/init_sql.pl +++ b/trunk/init_sql.pl @@ -19,7 +19,7 @@ $dbh->do(qq{drop table referer}); $dbh->do(qq{drop table ratings}); -$dbh->do(qq{drop table messages}); +$dbh->do(qq{drop table comments}); $dbh->do(qq{create table tagcloud @@ -137,14 +137,13 @@ $dbh->do(qq{create table }) or die $dbh->errstr; $dbh->do(qq{create table - messages + comments ( id int auto_increment not null, userid int not null, videoid int not null, - replyto int default 0, message varchar(255) not null, - primary key (id), + primary key (id) ) }) or die $dbh->errstr; diff --git a/trunk/video.pl b/trunk/video.pl index 19f11f5..4880405 100644 --- a/trunk/video.pl +++ b/trunk/video.pl @@ -25,7 +25,7 @@ if($query->param('title') or $query->param('id')) if($query->param('id')) { #if id is passed ignore title and check for the id - $sth = $dbh->prepare(qq{select title, description, userid, from_unixtime( timestamp ), + $sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ), creator, subject, contributor, source, language, coverage, rights, license from videos where id = ? }) or die $dbh->errstr; $rowcount = $sth->execute($query->param('id')) or die $dbh->errstr; @@ -33,7 +33,7 @@ if($query->param('title') or $query->param('id')) else { #if no id was passed there has to be a title we search for - $sth = $dbh->prepare(qq{select title, description, userid, from_unixtime( timestamp ), + $sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ), creator, subject, contributor, source, language, coverage, rights, license from videos where title = ? }) or die $dbh->errstr; $rowcount = $sth->execute($query->param('title')) or die $dbh->errstr; @@ -43,12 +43,13 @@ if($query->param('title') or $query->param('id')) #if there was a title passed, then perform a search if($rowcount == 0 and $query->param('title')) { - $sth = $dbh->prepare(qq{select title, description, userid, from_unixtime( timestamp ), + $sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ), creator, subject, contributor, source, language, coverage, rights, license from videos where match(title, description, subject) against( ? ) }) or die $dbh->errstr; $rowcount = $sth->execute($query->param('title')) or die $dbh->errstr; } + #from this point on, do not use $query->param('id') anymore - we do not know what was given if($rowcount == 0) { #still no results @@ -59,12 +60,19 @@ if($query->param('title') or $query->param('id')) elsif($rowcount == 1) { #if there was a single result, display the video - my ($title, $description, $userid, $timestamp, $creator, $subject, + my ($id, $title, $description, $userid, $timestamp, $creator, $subject, $contributor, $source, $language, $coverage, $rights, $license,) = $sth->fetchrow_array(); #finish query $sth->finish() or die $dbh->errstr; + + #check if a comment is about to be created and the user is logged in + if($query->param('comment') and $userid = get_userid_from_sid($session->id)) + { + $dbh->do(qq{insert into comments (userid, videoid, message) values (?, ?, ?)}, undef, $userid, $id, $query->param('comment')) or die $dbh->errstr; + } + #if referer is not the local site update referer table $referer = $query->referer() or $referer = ''; $server_name = $query->server_name(); @@ -72,21 +80,21 @@ if($query->param('title') or $query->param('id')) { #check if already in database $sth = $dbh->prepare(qq{select 1 from referer where videoid = ? and referer = ? }) or die $dbh->errstr; - my $rowcount = $sth->execute($query->param('id'), $referer) or die $dbh->errstr; + my $rowcount = $sth->execute($id, $referer) or die $dbh->errstr; $sth->finish() or die $dbh->errstr; if($rowcount > 0) { #video is in database - increase referercount $sth = $dbh->prepare(qq{update referer set count=count+1 where videoid = ? and referer = ? }) or die $dbh->errstr; - $sth->execute($query->param('id'), $referer) or die $dbh->errstr; + $sth->execute($id, $referer) or die $dbh->errstr; $sth->finish(); } else { #add new referer $sth = $dbh->prepare(qq{insert into referer (videoid, referer) values (?, ?) }) or die $dbh->errstr; - $sth->execute($query->param('id'), $referer) or die $dbh->errstr; + $sth->execute($id, $referer) or die $dbh->errstr; $sth->finish(); } } @@ -99,7 +107,7 @@ if($query->param('title') or $query->param('id')) { 'cc:Work' => { - 'rdf:about' => "./videos/".$query->param('id'), + 'rdf:about' => "./videos/$id", 'dc:title' => [$title], 'dc:creator' => [$creator], 'dc:subject' => [$subject], @@ -107,7 +115,7 @@ if($query->param('title') or $query->param('id')) 'dc:publisher' => [get_username_from_id($userid)], 'dc:contributor' => [$contributor], 'dc:date' => [$timestamp], - 'dc:identifier' => ["./videos/".$query->param('id')], + 'dc:identifier' => [$id], 'dc:source' => [$source], 'dc:language' => [$language], 'dc:coverage' => [$coverage], diff --git a/trunk/xsl/xhtml.xsl b/trunk/xsl/xhtml.xsl index f0852b4..9708f23 100755 --- a/trunk/xsl/xhtml.xsl +++ b/trunk/xsl/xhtml.xsl @@ -486,6 +486,21 @@ + +
+
+ + + + + + Leave Comment: +
+ +
+ +
+