TinyPortal

Development => Block Codes => Topic started by: Thurnok on October 21, 2006, 07:21:13 AM

Title: [Block] Polls for TP/SMF - and associated SSI hack
Post by: Thurnok on October 21, 2006, 07:21:13 AM
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
Title: Re: Poll Block - and associated SSI hack
Post by: DawnsWebDesigns on October 26, 2006, 12:13:35 AM
TY :)
Title: Re: Poll Block - and associated SSI hack
Post by: 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);


Title: Re: Poll Block - and associated SSI hack
Post by: Thurnok on November 13, 2006, 02:34:45 AM
We aim to please.  ;)
Title: Re: Poll Block - and associated SSI hack
Post by: Wish on January 21, 2007, 06:01:33 AM
What about for version 1.1.1? What do we do then?
Title: Re: Poll Block - and associated SSI hack
Post by: IchBin on January 21, 2007, 07:08:09 AM
As far as I can tell it should still work. Did you try it?
Title: Re: Poll Block - and associated SSI hack
Post by: Thurnok on January 21, 2007, 10:17:16 AM
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.
Title: Re: Poll Block - and associated SSI hack
Post by: Thurnok on January 22, 2007, 01:38:04 AM
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.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: funxlab on January 23, 2007, 07:45:14 PM
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
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: 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.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: bigb on January 24, 2007, 03:11:21 AM
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 '

';
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: 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);
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: bigb on January 24, 2007, 03:42:55 PM
Thanks

Works great thanks for the help and quick response.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: funxlab on January 25, 2007, 10:36:38 AM
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
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Ken. on January 25, 2007, 12:31:31 PM
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.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: funxlab on January 25, 2007, 03:57:03 PM
ken.kimbrell
That was a great help. Accept my regards.
Jim
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Ken. on January 25, 2007, 04:56:10 PM
Welcome.  ;D
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Ken. on February 02, 2007, 02:26:42 PM
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. :-\
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Thurnok on February 03, 2007, 03:47:27 AM
@ken
Yep... the example in the first post of this topic actually shows it. ;)

Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Ken. on February 03, 2007, 04:16:25 AM
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
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: |||||| on March 29, 2007, 10:02:29 AM
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
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: G6Cad on March 29, 2007, 10:04:39 AM
Another happy customer with a blasting nickname  :2funny:

Thank you for the info :)
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: |||||| on March 29, 2007, 10:10:24 AM
Now lemme try to add the other hack so users can vote from there! ;)
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: jdvarner on March 30, 2007, 03:20:30 PM
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.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Spasm on April 10, 2007, 05:44:06 AM
Is there a way to display a random poll that has been created on your site?  Instead of just most recent or top one?
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: bloodynightmare on May 14, 2007, 07:44:52 PM
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?
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Thurnok on May 15, 2007, 07:36:06 AM
Read the first post in this topic.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: bloodynightmare on May 15, 2007, 01:54:29 PM
thx 1000, solved
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Dragooon on May 19, 2007, 07:32:49 PM
Is there a way so that ppl dont go to the topic just remain there on the TP page?
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Thurnok on May 20, 2007, 05:49:08 AM
After they vote you mean?  Not without modifying the whole voting system in SMF most likely.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Dragooon on May 20, 2007, 08:56:13 AM
omg I think I am okay with this only lol
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Dragooon on May 20, 2007, 01:14:26 PM
I tried this And The pol bars cbreak the lines and I even tried your SSI modifications to solve it but failed
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Dragooon on May 20, 2007, 05:56:10 PM
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.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: clemenzo on June 10, 2007, 03:27:39 AM
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
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Whiteyez on June 27, 2007, 04:17:10 PM
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?
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: IchBin on June 27, 2007, 07:10:42 PM
Where have you tried to put it?
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Whiteyez on June 27, 2007, 10:28:07 PM
I found it.....in the  script box.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Rus on September 05, 2007, 07:51:45 PM
This is awesome, thanks.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Spasm on September 06, 2007, 01:46:56 PM
Aw, I got the blank page error :(
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: 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!
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Ken. on November 05, 2007, 05:17:34 PM
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.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: koolaid on January 31, 2008, 06:53:04 AM
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".
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: Thurnok on February 10, 2008, 04:40:45 AM
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.
Title: Re: [Block] TP/SMF Poll - and associated SSI hack
Post by: pauls_uk on August 30, 2008, 11:59:54 AM
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
Title: Re: [Block] Polls for TP/SMF - and associated SSI hack
Post by: Thurnok on September 17, 2008, 09:03:03 PM
Double check the hack code, you might have missed something there.  This still works even under latest SMF/TP.
Title: Re: [Block] Polls for TP/SMF - and associated SSI hack
Post by: Thurnok on September 17, 2008, 09:04:46 PM
Modified the Topic title for better indexing.
Title: Re: [Block] Polls for TP/SMF - and associated SSI hack
Post by: forummaker on February 12, 2009, 01:50:00 AM
testing for smf 1.1.8 tp 1.0.5
Title: Re: [Block] Polls for TP/SMF - and associated SSI hack
Post by: 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?

And is there any way, to allow Guests to Vote when they don't Have permissions to see the forum?

Thanks
Title: Re: [Block] Polls for TP/SMF - and associated SSI hack
Post by: ZarPrime on March 04, 2009, 01:17:00 PM
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
Title: Re: [Block] Polls for TP/SMF - and associated SSI hack
Post by: SN on March 04, 2009, 01:23:58 PM
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
Title: Re: [Block] Polls for TP/SMF - and associated SSI hack
Post by: JPDeni on March 04, 2009, 01:31:28 PM
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.
Title: Re: [Block] Polls for TP/SMF - and associated SSI hack
Post by: bengalistation on April 28, 2009, 09:23:26 AM
works for 1.1.8 and TP beta 3 ?
Title: Re: [Block] Polls for TP/SMF - and associated SSI hack
Post by: IchBin on April 28, 2009, 05:52:44 PM
You try it?