Poll Plugin
Poll Plugin
Hey all,
Was wondering if anyone could point me in the direction of a poll plugin?
Was wondering if anyone could point me in the direction of a poll plugin?
Re: Poll Plugin
Currently i only know "Evan Nemerson"'s Blog (Here) he develops an PollBox Plugin, but hasnt yet been public released it.Mecca wrote:Hey all,
Was wondering if anyone could point me in the direction of a poll plugin?
U can workaround with an Html Block and use an IFrame, or try with the PhpBox Plugin(Here).
Last edited by wese on Tue Nov 09, 2004 9:12 pm, edited 1 time in total.
Do your Part! Join now.
-
- Regular
- Posts: 88
- Joined: Fri Oct 08, 2004 6:20 am
- Location: 33°6'4.079" North, 117°3'6.563" West
- Contact:
/me wonders why his name is surrounded by quotation marks...
Here's what I have on my blog right now. The problem is that the configuration is a bit unfriendly... and I think I wrote this before there was an event hook in the CSS file, so everything is hard-coded. If you still want the code, though...
Don't get mad at me if the planet starts spinning in reverse or anything... :)
Here's what I have on my blog right now. The problem is that the configuration is a bit unfriendly... and I think I wrote this before there was an event hook in the CSS file, so everything is hard-coded. If you still want the code, though...
Code: Select all
<?php # $Id$
switch ($serendipity['lang']) {
case 'en':
default: {
@define('PLUGIN_POLLBOX_NAME', 'Poll Box');
@define('PLUGIN_POLLBOX_DESC', 'Create a poll in the sidebar.');
@define('PLUGIN_POLLBOX_NUMCHOICES', 'Number of options');
@define('PLUGIN_POLLBOX_CHOICE', 'Option #%d');
@define('PLUGIN_POLLBOX_QUESTION', 'Question');
@define('PLUGIN_POLLBOX_NUMCHOICES_DESC', 'The number of options the user will have to choose from.');
@define('PLUGIN_POLLBOX_CHOICE_DESC', 'The text for option #%d.');
@define('PLUGIN_POLLBOX_QUESTION_DESC', 'The question you want to ask.');
@define('PLUGIN_POLLBOX_TOTALVOTES', 'Total of %d votes.');
@define('PLUGIN_POLLBOX_VOTE', 'Vote');
@define('PLUGIN_POLLBOX_SHOWRESULTS', 'Show results.');
@define('PLUGIN_POLLBOX_RESET', 'Reset');
}
break;
}
class serendipity_plugin_pollbox extends serendipity_plugin {
function introspect(&$propbag)
{
global $serendipity;
if ( $this->get_config('reset', 'unset') != 'unset' ) {
/* This is what doesn't work. Can't figure out how to
clear title, question, pollbox_number_choices, and
reset. */
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}config WHERE name LIKE '{$this->instance}%';");
$plugin_l = strlen($this->instance);
foreach ( $serendipity as $key => $value ) {
if ( substr($key, 0, $plugin_l) == $this->instance ) {
unset($serendipity[$key]);
}
}
}
$conf_items = array('title', 'question', 'pollbox_number_choices');
$numchoices = $this->get_config('pollbox_number_choices', '');
if ( is_numeric($numchoices) ) {
for ( $x = 1 ; $x <= $numchoices ; $x++ ) {
$conf_items[] = 'choice_'.$x;
}
}
$conf_items[] = 'reset';
$propbag->add('name', PLUGIN_POLLBOX_NAME);
$propbag->add('description', PLUGIN_POLLBOX_DESC);
$propbag->add('configuration', $conf_items);
$propbag->add('event_hooks', array('frontend_configure' => true));
}
function introspect_config_item($name, &$propbag)
{
global $serendipity;
if ( $name == 'pollbox_number_choices' ) {
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_POLLBOX_NUMCHOICES);
$propbag->add('description', PLUGIN_POLLBOX_NUMCHOICES_DESC);
}
elseif ( $name == 'title' ) {
$propbag->add('type', 'string');
$propbag->add('name', TITLE);
$propbag->add('description', TITLE);
$propbag->add('default', '');
}
elseif ( $name == 'question' ) {
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_POLLBOX_QUESTION);
$propbag->add('description', PLUGIN_POLLBOX_QUESTION_DESC);
$propbag->add('default', '');
}
elseif ( $name == 'reset' ) {
$propbag->add('type', 'checkbox');
$propbag->add('name', PLUGIN_POLLBOX_RESET);
$propbag->add('description', PLUGIN_POLLBOX_RESET);
}
elseif ( preg_match('/^choice_([0-9]*)$/', $name, $num) ) {
$propbag->add('type', 'string');
$propbag->add('name', sprintf(PLUGIN_POLLBOX_CHOICE, $num[1]));
$propbag->add('description', sprintf(PLUGIN_POLLBOX_CHOICE_DESC, $num[1]));
}
return true;
}
function generate_content(&$title) {
global $serendipity;
$title = $this->get_config('title');
$numchoices = $this->get_config('pollbox_number_choices');
if ( $_REQUEST['serendipity_pollChoice'] && is_numeric( $_REQUEST['serendipity_pollChoice']) ) {
$_SESSION['serendipity_hasVoted'] = true;
$choice = $_REQUEST['serendipity_pollChoice'];
$this->set_config('votes_' . $choice, $t = $this->get_config('votes_' . $choice, 0) + 1);
$this->set_config('total_votes', $t = $this->get_config('total_votes', 0) + 1);
}
$showResults = (isset($_SESSION['serendipity_hasVoted']) || $_GET['pollbox_showResults']) ? true : false;
echo '<form method="post" action="' . htmlentities($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']) . '">';
echo $this->get_config('question', '') . "<br/>\n";
for ( $i = 1 ; $i <= $numchoices ; $i++ ) {
$total_votes = $this->get_config('total_votes', 0);
$choice = $this->get_config('choice_' . $i);
if ( $showResults ) {
$width = (($total_votes > 0) ? (($this->get_config('votes_' . $i, 0) / $total_votes) * 100) : 0);
echo '<div style="padding-top: 0.5em;">' . $choice . ($showResults ? ' (' . round($width) . '%)' : '') . '</div>';
echo '<div style="display: block; width: 100%; height: 1em; border: thin black solid;">';
if ( $width > 0 ) {
echo '<div style="width: ' . $width . '%; height: 100%; background: black; border: thin white solid;"></div>';
}
echo "</div>";
}
if ( !isset($_SESSION['serendipity_hasVoted']) ) {
echo '<div><input type="radio" name="serendipity_pollChoice" value="' . $i .'"/>' . ($showResults ? '' : $choice) . '</div>';
}
}
if ( !isset($_SESSION['serendipity_hasVoted']) ) {
echo '<div><input type="submit" name="submit" value="' . PLUGIN_POLLBOX_VOTE . '"/></div>';
}
echo '<div>';
if ( $showResults ) {
printf(PLUGIN_POLLBOX_TOTALVOTES, $total_votes);
}
else {
echo '<a href="?pollbox_showResults=true">' . PLUGIN_POLLBOX_SHOWRESULTS . '</a>';
}
echo '</div>';
echo '</form>';
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
LOL nope the planet didnt start spinning in reverse, and thankyou very much for the code
Just one question where abouts do i add the the text for the options ?
-----------
Poll
Question EG: What color is the sky
Option 1 EG: Blue
Option 2 EG: Red
Option 3 EG: Green
-------------
And Thanks again for the code
Just one question where abouts do i add the the text for the options ?
-----------
Poll
Question EG: What color is the sky
Option 1 EG: Blue
Option 2 EG: Red
Option 3 EG: Green
-------------
And Thanks again for the code
Um ok maybe i was a little hasty lol, the script does work great i just have a small problem with the options text all the options apear about 10 characters to the right of there respective radio button putting things out of alignment. I'm noy a guru php coder, so could you point me in the right direction to fix this small problem?
again thanx for your help
again thanx for your help
I got a lil problem with my template.. The option Button is in the second line.. I will find it.Mecca wrote:i just have a small problem with the options text all the options apear about 10 characters to the right of there respective radio button putting things out of alignment.
But Hey works great.
Sorry about the Caps and many thanks for the script.
Do your Part! Join now.
Plguin in German
I've just translated the Plugin into german language. Here's the code:
To install, create a new folder called "serendipity_plugin_pollbox" in your "plugins" directory. Copy the Plugin file in there and name it to "serendipity_plugin_pollbox.php".
Zpage
Code: Select all
<?php # $Id$
switch ($serendipity['lang']) {
case 'de':
default: {
@define('PLUGIN_POLLBOX_NAME', 'Poll Box');
@define('PLUGIN_POLLBOX_DESC', 'Ein Poll in der Sidebar erstellen.');
@define('PLUGIN_POLLBOX_NUMCHOICES', 'Anzahl der Antworten');
@define('PLUGIN_POLLBOX_CHOICE', 'Antwort #%d');
@define('PLUGIN_POLLBOX_QUESTION', 'Frage');
@define('PLUGIN_POLLBOX_NUMCHOICES_DESC', 'Die Anzahl der Antworten die der User wählen kann.');
@define('PLUGIN_POLLBOX_CHOICE_DESC', 'Der Text für Antwort #%d.');
@define('PLUGIN_POLLBOX_QUESTION_DESC', 'Die Frage die gestellt werden soll.');
@define('PLUGIN_POLLBOX_TOTALVOTES', '%d Votes');
@define('PLUGIN_POLLBOX_VOTE', 'Vote');
@define('PLUGIN_POLLBOX_SHOWRESULTS', 'Ergebnisse');
@define('PLUGIN_POLLBOX_RESET', 'Reset');
}
break;
}
class serendipity_plugin_pollbox extends serendipity_plugin {
function introspect(&$propbag)
{
global $serendipity;
if ( $this->get_config('reset', 'unset') != 'unset' ) {
/* This is what doesn't work. Can't figure out how to
clear title, question, pollbox_number_choices, and
reset. */
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}config WHERE name LIKE '{$this->instance}%';");
$plugin_l = strlen($this->instance);
foreach ( $serendipity as $key => $value ) {
if ( substr($key, 0, $plugin_l) == $this->instance ) {
unset($serendipity[$key]);
}
}
}
$conf_items = array('title', 'question', 'pollbox_number_choices');
$numchoices = $this->get_config('pollbox_number_choices', '');
if ( is_numeric($numchoices) ) {
for ( $x = 1 ; $x <= $numchoices ; $x++ ) {
$conf_items[] = 'choice_'.$x;
}
}
$conf_items[] = 'reset';
$propbag->add('name', PLUGIN_POLLBOX_NAME);
$propbag->add('description', PLUGIN_POLLBOX_DESC);
$propbag->add('configuration', $conf_items);
$propbag->add('event_hooks', array('frontend_configure' => true));
}
function introspect_config_item($name, &$propbag)
{
global $serendipity;
if ( $name == 'pollbox_number_choices' ) {
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_POLLBOX_NUMCHOICES);
$propbag->add('description', PLUGIN_POLLBOX_NUMCHOICES_DESC);
}
elseif ( $name == 'title' ) {
$propbag->add('type', 'string');
$propbag->add('name', TITLE);
$propbag->add('description', TITLE);
$propbag->add('default', '');
}
elseif ( $name == 'question' ) {
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_POLLBOX_QUESTION);
$propbag->add('description', PLUGIN_POLLBOX_QUESTION_DESC);
$propbag->add('default', '');
}
elseif ( $name == 'reset' ) {
$propbag->add('type', 'checkbox');
$propbag->add('name', PLUGIN_POLLBOX_RESET);
$propbag->add('description', PLUGIN_POLLBOX_RESET);
}
elseif ( preg_match('/^choice_([0-9]*)$/', $name, $num) ) {
$propbag->add('type', 'string');
$propbag->add('name', sprintf(PLUGIN_POLLBOX_CHOICE, $num[1]));
$propbag->add('description', sprintf(PLUGIN_POLLBOX_CHOICE_DESC, $num[1]));
}
return true;
}
function generate_content(&$title) {
global $serendipity;
$title = $this->get_config('title');
$numchoices = $this->get_config('pollbox_number_choices');
if ( $_REQUEST['serendipity_pollChoice'] && is_numeric( $_REQUEST['serendipity_pollChoice']) ) {
$_SESSION['serendipity_hasVoted'] = true;
$choice = $_REQUEST['serendipity_pollChoice'];
$this->set_config('votes_' . $choice, $t = $this->get_config('votes_' . $choice, 0) + 1);
$this->set_config('total_votes', $t = $this->get_config('total_votes', 0) + 1);
}
$showResults = (isset($_SESSION['serendipity_hasVoted']) || $_GET['pollbox_showResults']) ? true : false;
echo '<form method="post" action="' . htmlentities($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']) . '">';
echo $this->get_config('question', '') . "<br/>\n";
for ( $i = 1 ; $i <= $numchoices ; $i++ ) {
$total_votes = $this->get_config('total_votes', 0);
$choice = $this->get_config('choice_' . $i);
if ( $showResults ) {
$width = (($total_votes > 0) ? (($this->get_config('votes_' . $i, 0) / $total_votes) * 100) : 0);
echo '<div style="padding-top: 0.5em;">' . $choice . ($showResults ? ' (' . round($width) . '%)' : '') . '</div>';
echo '<div style="display: block; width: 100%; height: 1em; border: thin black solid;">';
if ( $width > 0 ) {
echo '<div style="width: ' . $width . '%; height: 100%; background: black; border: thin white solid;"></div>';
}
echo "</div>";
}
if ( !isset($_SESSION['serendipity_hasVoted']) ) {
echo '<div><input type="radio" name="serendipity_pollChoice" value="' . $i .'"/>' . ($showResults ? '' : $choice) . '</div>';
}
}
if ( !isset($_SESSION['serendipity_hasVoted']) ) {
echo '<div><input type="submit" name="submit" value="' . PLUGIN_POLLBOX_VOTE . '"/></div>';
}
echo '<div>';
if ( $showResults ) {
printf(PLUGIN_POLLBOX_TOTALVOTES, $total_votes);
}
else {
echo '<a href="?pollbox_showResults=true">' . PLUGIN_POLLBOX_SHOWRESULTS . '</a>';
}
echo '</div>';
echo '</form>';
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
Zpage
Layout problem
Hi,
the plugin is excellent... better than use the phpbox, i think.
My problem is that i get the radio button in a line over the text of its option, and i tried everything, but i dont know how to make it...
Someone can give a little help?
Thanks in advance!
the plugin is excellent... better than use the phpbox, i think.
My problem is that i get the radio button in a line over the text of its option, and i tried everything, but i dont know how to make it...
Someone can give a little help?
Thanks in advance!
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
davecjr: I think this is intentional; you already have voted and cannot vote again, so it shows you the results.
Regards,
Garvin
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Hi. So does this problem have a solution? It's very annoying and just doesn't look good at all.Mecca wrote:Um ok maybe i was a little hasty lol, the script does work great i just have a small problem with the options text all the options apear about 10 characters to the right of there respective radio button putting things out of alignment. I'm noy a guru php coder, so could you point me in the right direction to fix this small problem?
again thanx for your help
David