added comment posting functionality

git-svn-id: http://yolanda.mister-muffin.de/svn@123 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2007-10-22 19:15:39 +00:00
parent 2a14506d8d
commit 454deb0c91
3 changed files with 35 additions and 13 deletions

View file

@ -19,7 +19,7 @@ $dbh->do(qq{drop table referer});
$dbh->do(qq{drop table ratings}); $dbh->do(qq{drop table ratings});
$dbh->do(qq{drop table messages}); $dbh->do(qq{drop table comments});
$dbh->do(qq{create table $dbh->do(qq{create table
tagcloud tagcloud
@ -137,14 +137,13 @@ $dbh->do(qq{create table
}) or die $dbh->errstr; }) or die $dbh->errstr;
$dbh->do(qq{create table $dbh->do(qq{create table
messages 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,
replyto int default 0,
message varchar(255) not null, message varchar(255) not null,
primary key (id), primary key (id)
) )
}) or die $dbh->errstr; }) or die $dbh->errstr;

View file

@ -25,7 +25,7 @@ if($query->param('title') or $query->param('id'))
if($query->param('id')) if($query->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 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 creator, subject, contributor, source, language, coverage, rights, license
from videos where id = ? }) or die $dbh->errstr; from videos where id = ? }) or die $dbh->errstr;
$rowcount = $sth->execute($query->param('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 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
$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 creator, subject, contributor, source, language, coverage, rights, license
from videos where title = ? }) or die $dbh->errstr; from videos where title = ? }) or die $dbh->errstr;
$rowcount = $sth->execute($query->param('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 there was a title passed, then perform a search
if($rowcount == 0 and $query->param('title')) 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 creator, subject, contributor, source, language, coverage, rights, license
from videos where match(title, description, subject) against( ? ) }) or die $dbh->errstr; from videos where match(title, description, subject) against( ? ) }) or die $dbh->errstr;
$rowcount = $sth->execute($query->param('title')) 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) if($rowcount == 0)
{ {
#still no results #still no results
@ -59,12 +60,19 @@ if($query->param('title') or $query->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 ($title, $description, $userid, $timestamp, $creator, $subject, my ($id, $title, $description, $userid, $timestamp, $creator, $subject,
$contributor, $source, $language, $coverage, $rights, $license,) = $sth->fetchrow_array(); $contributor, $source, $language, $coverage, $rights, $license,) = $sth->fetchrow_array();
#finish query #finish query
$sth->finish() or die $dbh->errstr; $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 #if referer is not the local site update referer table
$referer = $query->referer() or $referer = ''; $referer = $query->referer() or $referer = '';
$server_name = $query->server_name(); $server_name = $query->server_name();
@ -72,21 +80,21 @@ if($query->param('title') or $query->param('id'))
{ {
#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($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
$sth = $dbh->prepare(qq{update referer set count=count+1 where videoid = ? and referer = ? }) or die $dbh->errstr; $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(); $sth->finish();
} }
else else
{ {
#add new referer #add new referer
$sth = $dbh->prepare(qq{insert into referer (videoid, referer) values (?, ?) }) or die $dbh->errstr; $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(); $sth->finish();
} }
} }
@ -99,7 +107,7 @@ if($query->param('title') or $query->param('id'))
{ {
'cc:Work' => 'cc:Work' =>
{ {
'rdf:about' => "./videos/".$query->param('id'), 'rdf:about' => "./videos/$id",
'dc:title' => [$title], 'dc:title' => [$title],
'dc:creator' => [$creator], 'dc:creator' => [$creator],
'dc:subject' => [$subject], 'dc:subject' => [$subject],
@ -107,7 +115,7 @@ if($query->param('title') or $query->param('id'))
'dc:publisher' => [get_username_from_id($userid)], 'dc:publisher' => [get_username_from_id($userid)],
'dc:contributor' => [$contributor], 'dc:contributor' => [$contributor],
'dc:date' => [$timestamp], 'dc:date' => [$timestamp],
'dc:identifier' => ["./videos/".$query->param('id')], 'dc:identifier' => [$id],
'dc:source' => [$source], 'dc:source' => [$source],
'dc:language' => [$language], 'dc:language' => [$language],
'dc:coverage' => [$coverage], 'dc:coverage' => [$coverage],

View file

@ -487,6 +487,21 @@
</tr> </tr>
</table> </table>
<form method="post" action="video.pl">
<fieldset>
<input name="id" type="hidden">
<xsl:attribute name="value">
<xsl:value-of select="rdf:RDF/cc:Work/dc:identifier" />
</xsl:attribute>
</input>
Leave Comment:
<br />
<textarea name="comment" cols="50" rows="5"></textarea>
<br />
<input type="submit" name="send" />
</fieldset>
</form>
</xsl:template> </xsl:template>
<xsl:template match="registerform"> <xsl:template match="registerform">