Someone asked me how to put multiple polls in the same block. Here's a block example for that, and some other info for those that may not have seen it elsewhere or where it may have gotten lost in the shuffle.
To create your (multi-)Poll block, create a phpblock. In it place the following code - replicate as required:
ssi_showPoll(70.0);
echo '<br /><hr />';
ssi_showPoll(135.0);
echo '<br /><hr />';
ssi_showPoll(121.0);
echo '<br /><hr />';
ssi_showPoll(122.0);
Replace the numbers in parenthesis with the actual number of your poll's post. This example shows 4 polls, only place as many as you need/have in the block obviously. ;)
In order for your members to actually vote from the Poll block, you need the SSI hack found here (http://www.tinyportal.net/index.php?topic=9623.msg65481#msg65481).
And you should include the SSI hack below to prevent the bars from breaking your theme borders.
This hack originally comes courtesy of another TP Team member (Raysr) and is highly recommended if you plan to have a Poll block as left/right. I've updated it to include the fix for SMF 1.1RC3 as well as some fixes to the original 1.1RC2 version. This one also sets each option name to italics, but only in the results list.
Edit SSI.php
[FIND ALL OCCURRANCES]
$barWide = $bar == 0 ? 1 : floor(($bar * 5) / 3);
[REPLACE ALL WITH]
$barWide = $bar == 0 ? 1 : floor(($bar * 5) / 6);
What to do next depends on the version of SMF you have installed. Please use only the one for your version.
For SMF 1.1RC2 ONLY!
[FIND]
echo '
<tr>
<td align="left" valign="top"><b>', $option['option'], '</b></td>
<td align="left">', $option['bar'], ' ', $option['votes'], '(', $option['percent'], '%)</td>
</tr>';
[REPLACE WITH]
echo '
<tr>
<td colspan="2" align="left" valign="top" style="font-style: italic"><b>', $option['option'], '</b></td>
</tr>
<tr>
<td align="left">', $option['bar'], '<td>
<td align="left">', $option['votes'], '(', $option['percent'], '%)</td>
</tr>';
For and tested with SMF 1.1RC3, 1.1, 1.1.1 - 1.1.6 ONLY!
[FIND]
echo '
<tr>
<td align="right" valign="top">', $option['option'], '</td>
<td align="left">', $option['bar'], ' ', $option['votes'], ' (', $option['percent'], '%)</td>
</tr>';
[REPLACE WITH]
echo '
<tr>
<td colspan="2" align="left" valign="top" style="font-style: italic">', $option['option'], '</td>
</tr>
<tr>
<td align="left">', $option['bar'], '</td>
<td align="left">', $option['votes'], ' (', $option['percent'], '%)</td>
</tr>';
EDIT: Edited to fix one broken link... Ken. (thanks Ken.) :)
EDIT: Updated supported versions... T
TY :)
Changing this code has solved my portal's visual problem with bar graphics. :up:
$barWide = $bar == 0 ? 1 : floor(($bar * 5) / 6);
We aim to please. ;)
What about for version 1.1.1? What do we do then?
As far as I can tell it should still work. Did you try it?
Version 1.1.1 should be able to use the same hack as 1.1RC3. I haven't validated yet, but if the search text for 1.1.1 is identical to 1.1RC3, then you can pretty much count on the replace text being identical.
I'll validate this tomorrow sometime.
Validated. SMF 1.1 and 1.1.1 has identical code as that of 1.1RC3 for this particular area. I tested this in both and works as designed.
Thurnok !
I just installed your code on my fresh SMF and TP installation. As it is new forum, I knew post number of my poll. But how can I find out post number of any future polls ?
I will have to change phpbloc every time I want a specfic poll to appear on TP right?
Regards,
Jim
Yes, when you make a new poll that you want displayed in a TP block on your frontpage, you will need to edit the php block and add the new post info to it. You can have multiple polls within the same block as you can see from the example. So you can add as many as you like, though I wouldn't recommend adding too many because that will make your page quite long. You can of course replace previous ones with the new ones simply by replacing the post number.
Is there some way of setting up a random array to display a different poll each time the block is refreshed.
randpollarray = new Array();
randpollarray[0] = 'Poll #';
randpollarray[1] = 'Poll #';
randpollarray[2] = 'Poll #';
ssi_showPoll(this would be the random are array#.0);
echo '
';
Sure... this of course assumes you already have a number of polls and you manually enter the ones you want as part of the random display into the array...
example:
// if you are using php version < 4.2.0, you need to seed the random generator
srand((float) microtime() * 10000000);
// change <postnum> to actual post numbers - this is your array of polls
$randpollarray = array(<postnum>, <postnum>, <postnum>...);
// grabs a random key from the array
$randpollkey = array_rand($randpollarray);
// get the postnum value from the random array element
$randpollvalue = $randpollarray[$randpollkey];
ssi_showPoll($randpollvalue);
Thanks
Works great thanks for the help and quick response.
Quote from: Thurnok on January 24, 2007, 02:16:34 AM
Yes, when you make a new poll that you want displayed in a TP block on your frontpage, you will need to edit the php block and add the new post info to it. You can have multiple polls within the same block as you can see from the example. So you can add as many as you like, though I wouldn't recommend adding too many because that will make your page quite long. You can of course replace previous ones with the new ones simply by replacing the post number.
Thank you Thurnok . But how I can find post number? :)
Regards,
Jim
With the poll in question displayed, look at your browser address bar and you should see the post # an the end of the address string.
ken.kimbrell
That was a great help. Accept my regards.
Jim
Welcome. ;D
As noted in the Other Thread (http://www.tinyportal.net/index.php?topic=9623.msg65481) for this hack:
Just installed all of these poll hacks for my fresh upgrade of SMF 1.1.1 & TP 097 and it worked like a charm.
Used FireFox to vote with my 'test' user and it looks good to me. :coolsmiley:
IE7 looks good too.
You can see two polls on the right side of my Forum (http://www.mykimbrell.com/FamilyForum/index.php)
Ps: I do have one question; is there a way to insert a horizontal line between each poll when you display two or more in a single block?
With the Mirage Theme that is the current default on my forum it just doesnââ,¬â,,¢t look right with two in one blockââ,¬Â¦ not clearly defined enough to me anyways. :-\
@ken
Yep... the example in the first post of this topic actually shows it. ;)
Quote from: Thurnok on February 03, 2007, 03:47:27 AM
@ken
Yep... the example in the first post of this topic actually shows it. ;)
Strange how that works out... my code didn't have the < hr /> entry! :2funny:
Thanks Thurnok
QuoteFor SMF 1.1RC3, 1.1, and 1.1.1 ONLY!
Just wanna say it worked for 1.1.2 too. Thx alot for this code! ;D
Another happy customer with a blasting nickname :2funny:
Thank you for the info :)
Now lemme try to add the other hack so users can vote from there! ;)
how do i add just last recent poll where it dont mess up the alignment of website/forum and also is capable of member voting from the block itself vs just showing the poll stats.
Is there a way to display a random poll that has been created on your site? Instead of just most recent or top one?
Quote from: ckale on November 12, 2006, 10:49:50 AM
Changing this code has solved my portal's visual problem with bar graphics. :up:
$barWide = $bar == 0 ? 1 : floor(($bar * 5) / 6);
? How to?
Read the first post in this topic.
thx 1000, solved
Is there a way so that ppl dont go to the topic just remain there on the TP page?
After they vote you mean? Not without modifying the whole voting system in SMF most likely.
omg I think I am okay with this only lol
I tried this And The pol bars cbreak the lines and I even tried your SSI modifications to solve it but failed
I tried everything works fine on my test forum but on my main forum it says Page cannot be displayed when voted
EDIT:I even tried replacing the 2 SSI but still failed.
My attempt to package this along with my rotating color poll bars mod is approved! Check out http://custom.simplemachines.org/mods/index.php?mod=765
Quote from: Thurnok on January 24, 2007, 08:59:48 AM
Sure... this of course assumes you already have a number of polls and you manually enter the ones you want as part of the random display into the array...
example:
// if you are using php version < 4.2.0, you need to seed the random generator
srand((float) microtime() * 10000000);
// change <postnum> to actual post numbers - this is your array of polls
$randpollarray = array(<postnum>, <postnum>, <postnum>...);
// grabs a random key from the array
$randpollkey = array_rand($randpollarray);
// get the postnum value from the random array element
$randpollvalue = $randpollarray[$randpollkey];
ssi_showPoll($randpollvalue);
Hmmm i dont get it, where do i put this?
Where have you tried to put it?
I found it.....in the script box.
This is awesome, thanks.
Aw, I got the blank page error :(
Quote from: Thurnok on October 21, 2006, 07:21:13 AM
In order for your members to actually vote from the Poll block, you need the SSI hack found here (http://www.tinyportal.net/smf/index.php?topic=9623.msg65481#msg65481).
Forgive me if this has already been answered, but this topic appears to have been removed. Could someone point me to the relocation or tell me how I can get the hack? Thanks!
Quote from: pianoman723 on November 05, 2007, 05:09:12 PM
Quote from: Thurnok on October 21, 2006, 07:21:13 AM
In order for your members to actually vote from the Poll block, you need the SSI hack found here (http://www.tinyportal.net/smf/index.php?topic=9623.msg65481#msg65481).
Forgive me if this has already been answered, but this topic appears to have been removed. Could someone point me to the relocation or tell me how I can get the hack? Thanks!
The Topic is still there, the link you referenced has an extra bit of info in it.
Try this one:
http://www.tinyportal.net/index.php?topic=9623.msg65481#msg65481
EDIT:
The link in the referenced message has been corrected.
I'm using SMF 1.1.4, TP 0.9.8 and after i tested the poll by voting.. logged out and the results are shown = people who aren't logged in can see the results. I also reseted the poll so there aren't any votes and the same thing happened. Is there a way to prevent the results being shown to people who aren't logged in?
When i created the poll, i did check the option "Only show the results after someone has voted".
When someone is not logged in (a guest in other words) they will only be able to see results, not the options to select. This is because SMF doesn't have a mechanism for guest voting (at least it didn't - sorry, I've been on hiatus for about 6+ months :) ) The option "Only show the results after someone has voted" is for logged in users only - since they should have the option to vote, so the options are shown until they do vote.
This did not work for me the bars still go off the screen even after i edit the ssi.php so i have it in the centre for now
Double check the hack code, you might have missed something there. This still works even under latest SMF/TP.
Modified the Topic title for better indexing.
testing for smf 1.1.8 tp 1.0.5
Great Snippet! thanks
Is there any way, i can stop it from redirecting to the thread after you have voted?
And is there any way, to allow Guests to Vote when they don't Have permissions to see the forum?
Thanks
Quote from: SN on March 04, 2009, 09:00:06 AM
Great Snippet! thanks
Is there any way, i can stop it from redirecting to the thread after you have voted?
Someone who is a better coder than I would have to look at the code to see if a redirect to some other location of your choosing would be possible. Where would you want them to be redirected to?
Quote from: SN on March 04, 2009, 09:00:06 AM
And is there any way, to allow Guests to Vote when they don't Have permissions to see the forum?
Thanks
Since Polls are tied to topics, off the top of my head, I can't think of a way that guests would be able to vote, especially if they didn't have permission to post in the Forum. For more information, see Thurnok's post above --> http://www.tinyportal.net/index.php/topic,9869.msg178080.html#msg178080
ZarPrime
Thanks for your replay mate.
so do you think it will be better to just get a free Poll scripts from somewhere instead and just place it in a block?
because all i want the poll for is the front page, i don't really mind if it has nothing to do with the forum Topics
I'm not sure about the redirect thing. I'd have to take a look at it.
As for guests, you could make a board that guests can read and put your polls in there.
I just looked more closely at the code. You can't have guests vote in polls because SMF allows for the changing of votes. Also, having a user id is the only way that it keeps track of who has voted. Guests would be able to vote over and over again.
So, yes, it would probably be better to find another script if you want guests to vote in polls.
works for 1.1.8 and TP beta 3 ?
You try it?