Tatsuki SUGIURA
sugi****@users*****
2006年 7月 12日 (水) 20:41:53 JST
Index: slashjp/plugins/PollBooth/Makefile.PL diff -u slashjp/plugins/PollBooth/Makefile.PL:1.1.1.1 slashjp/plugins/PollBooth/Makefile.PL:1.2 --- slashjp/plugins/PollBooth/Makefile.PL:1.1.1.1 Wed Jan 28 06:55:05 2004 +++ slashjp/plugins/PollBooth/Makefile.PL Wed Jul 12 20:41:53 2006 @@ -5,5 +5,8 @@ WriteMakefile( 'NAME' => 'Slash::PollBooth', 'VERSION_FROM' => 'PollBooth.pm', # finds $VERSION - 'PM' => { 'PollBooth.pm' => '$(INST_LIBDIR)/PollBooth.pm' }, + 'PM' => { + 'PollBooth.pm' => '$(INST_LIBDIR)/PollBooth.pm', + 'ResKey.pm' => '$(INST_LIBDIR)/PollBooth/ResKey.pm', + }, ); Index: slashjp/plugins/PollBooth/PLUGIN diff -u slashjp/plugins/PollBooth/PLUGIN:1.2 slashjp/plugins/PollBooth/PLUGIN:1.3 --- slashjp/plugins/PollBooth/PLUGIN:1.2 Fri Dec 24 05:13:41 2004 +++ slashjp/plugins/PollBooth/PLUGIN Wed Jul 12 20:41:53 2006 @@ -1,9 +1,10 @@ -# $Id: PLUGIN,v 1.2 2004/12/23 20:13:41 oliver Exp $ +# $Id: PLUGIN,v 1.3 2006/07/12 11:41:53 sugi Exp $ name=PollBooth description="PollBooth" mysql_schema=mysql_schema mysql_dump=mysql_dump htdoc=pollBooth.pl +css=polls.css template=templates/data;pollBooth;default template=templates/editpoll;pollBooth;default template=templates/listpolls;pollBooth;default Index: slashjp/plugins/PollBooth/PollBooth.pm diff -u slashjp/plugins/PollBooth/PollBooth.pm:1.3 slashjp/plugins/PollBooth/PollBooth.pm:1.4 --- slashjp/plugins/PollBooth/PollBooth.pm:1.3 Fri Dec 31 21:37:12 2004 +++ slashjp/plugins/PollBooth/PollBooth.pm Wed Jul 12 20:41:53 2006 @@ -1,7 +1,7 @@ # This code is a part of Slash, and is released under the GPL. -# Copyright 1997-2004 by Open Source Development Network. See README +# Copyright 1997-2005 by Open Source Technology Group. See README # and COPYING for more information, or see http://slashcode.com/. -# $Id: PollBooth.pm,v 1.3 2004/12/31 12:37:12 oliver Exp $ +# $Id: PollBooth.pm,v 1.4 2006/07/12 11:41:53 sugi Exp $ package Slash::PollBooth; @@ -16,7 +16,7 @@ use base 'Slash::DB::Utility'; use base 'Slash::DB::MySQL'; -($VERSION) = ' $Revision: 1.3 $ ' =~ /\$Revision:\s+([^\s]+)/; +($VERSION) = ' $Revision: 1.4 $ ' =~ /\$Revision:\s+([^\s]+)/; #Right, this is not needed at the moment but will be in the near future sub new { Index: slashjp/plugins/PollBooth/ResKey.pm diff -u /dev/null slashjp/plugins/PollBooth/ResKey.pm:1.1.2.1 --- /dev/null Wed Jul 12 20:41:53 2006 +++ slashjp/plugins/PollBooth/ResKey.pm Wed Jul 12 20:41:53 2006 @@ -0,0 +1,48 @@ +# This code is a part of Slash, and is released under the GPL. +# Copyright 1997-2005 by Open Source Technology Group. See README +# and COPYING for more information, or see http://slashcode.com/. +# $Id: ResKey.pm,v 1.1.2.1 2006/07/12 11:41:53 sugi Exp $ + +package Slash::PollBooth::ResKey; + +use warnings; +use strict; + +use Slash::Utility; +use Slash::Constants ':reskey'; + +use base 'Slash::ResKey::Key'; + +our($VERSION) = ' $Revision: 1.1.2.1 $ ' =~ /\$Revision:\s+([^\s]+)/; + +sub doCheck { + my($self) = @_; + + my $slashdb = getCurrentDB(); + my $constants = getCurrentStatic(); + my $user = getCurrentUser(); + + if ($user->{is_anon} && !$constants->{allow_anon_poll_voting}) { + return(RESKEY_DEATH, ['anon', {}, 'pollBooth']); + } + + my $qid = $self->opts->{qid}; + + return(RESKEY_DEATH, ['no qid', {}, 'pollBooth']) unless $qid; + + my $pollvoter_md5 = getPollVoterHash(); + my $qid_quoted = $slashdb->sqlQuote($qid); + + # Yes, qid/id/uid is a key in pollvoters. + my($voters) = $slashdb->sqlSelect('id', 'pollvoters', + "qid=$qid_quoted AND id='$pollvoter_md5' AND uid=$user->{uid}" + ); + + if ($voters) { + return(RESKEY_DEATH, ['already voted', {}, 'pollBooth']); + } + + return RESKEY_SUCCESS; +} + +1; Index: slashjp/plugins/PollBooth/mysql_dump diff -u slashjp/plugins/PollBooth/mysql_dump:1.2 slashjp/plugins/PollBooth/mysql_dump:1.3 --- slashjp/plugins/PollBooth/mysql_dump:1.2 Fri Dec 24 05:13:41 2004 +++ slashjp/plugins/PollBooth/mysql_dump Wed Jul 12 20:41:53 2006 @@ -1,5 +1,12 @@ # -# $Id: mysql_dump,v 1.2 2004/12/23 20:13:41 oliver Exp $ +# $Id: mysql_dump,v 1.3 2006/07/12 11:41:53 sugi Exp $ # +INSERT INTO discussion_kinds (dkid, name) VALUES (NULL, 'poll'); + INSERT INTO hooks (param, class, subroutine) VALUES ('admin_save_story_success','Slash::PollBooth','createAutoPollFromStory'); + +INSERT INTO css (rel, type, media, file, title, skin, page, admin, theme, ctid, ordernum, ie_cond) VALUES ('stylesheet','text/css','screen, projection','polls.css','','','pollBooth','no','',2,0, ''); + +INSERT INTO vars (name, value, description) VALUES ('allow_anon_poll_voting', '1', 'Set this to decide whether anonymous users can vote in polls)'); + Index: slashjp/plugins/PollBooth/mysql_schema diff -u slashjp/plugins/PollBooth/mysql_schema:1.3 slashjp/plugins/PollBooth/mysql_schema:1.4 --- slashjp/plugins/PollBooth/mysql_schema:1.3 Fri Dec 31 21:37:12 2004 +++ slashjp/plugins/PollBooth/mysql_schema Wed Jul 12 20:41:53 2006 @@ -1,5 +1,5 @@ # -# $Id: mysql_schema,v 1.3 2004/12/31 12:37:12 oliver Exp $ +# $Id: mysql_schema,v 1.4 2006/07/12 11:41:53 sugi Exp $ # # Not going to install this unless the pollbooth plugin is installed Index: slashjp/plugins/PollBooth/pollBooth.pl diff -u slashjp/plugins/PollBooth/pollBooth.pl:1.3 slashjp/plugins/PollBooth/pollBooth.pl:1.4 --- slashjp/plugins/PollBooth/pollBooth.pl:1.3 Fri Dec 31 21:37:12 2004 +++ slashjp/plugins/PollBooth/pollBooth.pl Wed Jul 12 20:41:53 2006 @@ -1,8 +1,8 @@ #!/usr/bin/perl -w # This code is a part of Slash, and is released under the GPL. -# Copyright 1997-2004 by Open Source Development Network. See README +# Copyright 1997-2005 by Open Source Technology Group. See README # and COPYING for more information, or see http://slashcode.com/. -# $Id: pollBooth.pl,v 1.3 2004/12/31 12:37:12 oliver Exp $ +# $Id: pollBooth.pl,v 1.4 2006/07/12 11:41:53 sugi Exp $ use strict; use Slash; @@ -22,15 +22,13 @@ list => \&listpolls, default => \&default, vote => \&vote, - vote_return => \&vote_return, get => \&poll_booth, preview => \&editpoll, detach => \&detachpoll, linkstory => \&link_story_to_poll ); - my $op = $form->{op}; - $op = 'default' unless $ops{$form->{op}}; + my $op = $form->{op} && $ops{$form->{op}} ? $form->{op} : 'default'; if (defined $form->{aid}) { # Only allow a short range of answer ids here. @@ -53,7 +51,7 @@ sub poll_booth { my($form) = @_; - print pollbooth($form->{'qid'}, 0, 1); + print sidebox('Poll', pollbooth($form->{'qid'}, 0, 1), 'poll', 1); } ################################################################# @@ -230,10 +228,13 @@ $question->{sid} = $form->{override_sid} if $form->{override_sid}; if ($question->{sid}) { - $story_ref = $reader->sqlSelectHashref("sid,qid,time,primaryskid,tid,displaystatus", + $story_ref = $reader->sqlSelectHashref("sid,qid,time,primaryskid,tid", "stories", "sid=" . $reader->sqlQuote($question->{sid}) ); + + $story_ref->{displaystatus} = $reader->_displaystatus($story_ref->{stoid}) if $story_ref; + if ($story_ref) { $question->{'date'} = $story_ref->{'time'}; $question->{topic} = $story_ref->{'tid'}; @@ -369,7 +370,7 @@ if ($constants->{poll_discussions}) { my $poll = $slashdb->getPollQuestion($qid); my $discussion; - if ($poll->{sid}) { + if ($form->{sid}) { # if sid lookup fails, then $discussion is empty, # and the poll's discussion is not set $discussion = $slashdb->getStory( @@ -377,6 +378,7 @@ ); } elsif (!$poll->{discussion}) { $discussion = $slashdb->createDiscussion({ + kind => 'pollbooth', title => $form->{question}, topic => $form->{topic}, approved => 1, # Story discussions are always approved -Brian @@ -398,36 +400,13 @@ } ################################################################# -sub vote_return { - my($form, $slashdb) = @_; - my $reader = getObject('Slash::DB', { db_type => 'reader' }); - - my $qid = $form->{'qid'}; - my $aid = $form->{'aid'}; - return unless $qid && $aid; - - my(%all_aid) = map { ($_->[0], 1) } - @{$reader->getPollAnswers($qid, ['aid'])}; - my $poll_open = $reader->isPollOpen($qid); - my $has_voted = $slashdb->hasVotedIn($qid); - - if ($has_voted) { - # Specific reason why can't vote. - } elsif (!$poll_open) { - # Voting is closed on this poll. - } elsif (exists $all_aid{$aid}) { - $slashdb->createPollVoter($qid, $aid); - } -} - -################################################################# sub vote { my($form, $slashdb) = @_; my $reader = getObject('Slash::DB', { db_type => 'reader' }); my $qid = $form->{'qid'}; my $aid = $form->{'aid'}; - return unless $qid; + return unless $qid && $aid; my(%all_aid) = map { ($_->[0], 1) } @{$reader->getPollAnswers($qid, ['aid'])}; @@ -441,18 +420,19 @@ my $question = $reader->getPollQuestion($qid, ['voters', 'question']); my $notes = getData('display'); - if (getCurrentUser('is_anon') && !getCurrentStatic('allow_anon_poll_voting')) { - $notes = getData('anon'); - } elsif ($aid > 0) { + if ($aid > 0) { my $poll_open = $reader->isPollOpen($qid); - my $has_voted = $slashdb->hasVotedIn($qid); - if ($has_voted) { - # Specific reason why can't vote. - $notes = getData('uid_voted'); - } elsif (!$poll_open) { + if (!$poll_open) { # Voting is closed on this poll. $notes = getData('poll_closed'); + } + + my $reskey = getObject('Slash::ResKey'); + my $rkey = $reskey->key('pollbooth', { qid => $qid }); + + if (!$rkey->createuse) { + $notes = $rkey->errstr; } elsif (exists $all_aid{$aid}) { $notes = getData('success', { aid => $aid }); $slashdb->createPollVoter($qid, $aid); @@ -498,11 +478,23 @@ ################################################################# sub listpolls { - my($form) = @_; + my($form, $slashdb, $constants) = @_; my $reader = getObject('Slash::DB', { db_type => 'reader' }); my $min = $form->{min} || 0; my $type = $form->{type}; my $questions = $reader->getPollQuestionList($min, { type => $type }); + my $gSkin = getCurrentSkin(); + my $opts = (); + $opts->{type} = $form->{type}; + $opts->{section} = $gSkin->{skid}; + + my $section = $gSkin->{name}; + if ($gSkin->{skid} == $constants->{mainpage_skid}) { + $opts->{section} = ''; + } + + $questions = $reader->getPollQuestionList($min, $opts); + my $sitename = getCurrentStatic('sitename'); # Just me, but shouldn't title be in the template? Index: slashjp/plugins/PollBooth/polls.css diff -u /dev/null slashjp/plugins/PollBooth/polls.css:1.1.2.1 --- /dev/null Wed Jul 12 20:41:53 2006 +++ slashjp/plugins/PollBooth/polls.css Wed Jul 12 20:41:53 2006 @@ -0,0 +1,47 @@ +.bar +{ + font-weight: bold; + margin: 0 0 1em 0; + border: 1px #ddd solid; + font-size: 80%; +} + +.barAnswer +{ + font-size: 120%; + text-align: left; + margin: .5em 0 0 0; +} + +.barColor +{ + background: #aaa; + border: 1px #ddd solid; + border-bottom: 1px #555 solid; + border-right: 1px #555 solid; +} + +.barPercent +{ + padding: 0 .3em; + background: #eee; + color: #555; +} + +.barVotes +{ + padding: 0 .3em; + background: #eee; + color: #555; + white-space: nowrap; +} + +.totalVotes { float: right; } +#polls-wide li { margin: 0 0 1em 0; } +.note ul +{ + font-size: 80%; + font-family: arial, sans-serif; +} +#pollBooth .generalbody table {width: 80%; margin: 0 0 1em 10%} +#pollBooth .generalbody caption {margin-left: 10%} Index: slashjp/plugins/PollBooth/rebuildAutoPoll diff -u slashjp/plugins/PollBooth/rebuildAutoPoll:1.2 slashjp/plugins/PollBooth/rebuildAutoPoll:1.3 --- slashjp/plugins/PollBooth/rebuildAutoPoll:1.2 Fri Dec 24 05:13:41 2004 +++ slashjp/plugins/PollBooth/rebuildAutoPoll Wed Jul 12 20:41:53 2006 @@ -1,8 +1,8 @@ #!/usr/bin/perl -w # This code is a part of Slash, and is released under the GPL. -# Copyright 1997-2004 by Open Source Development Network. See README +# Copyright 1997-2005 by Open Source Technology Group. See README # and COPYING for more information, or see http://slashcode.com/. -# $Id: rebuildAutoPoll,v 1.2 2004/12/23 20:13:41 oliver Exp $ +# $Id: rebuildAutoPoll,v 1.3 2006/07/12 11:41:53 sugi Exp $ use strict; use File::Basename; @@ -13,7 +13,7 @@ use vars qw( $slashdb $werder $constants $junk ); -(my $VERSION) = ' $Revision: 1.2 $ ' =~ /\$Revision:\s+([^\s]+)/; +(my $VERSION) = ' $Revision: 1.3 $ ' =~ /\$Revision:\s+([^\s]+)/; my $PROGNAME = basename($0); my %opts; @@ -78,7 +78,7 @@ $PROGNAME $VERSION This code is a part of Slash, and is released under the GPL. -Copyright 1997-2004 by Open Source Development Network. See README +Copyright 1997-2005 by Open Source Technology Group. See README and COPYING for more information, or see http://slashcode.com/. EOT