PDA

View Full Version : Embedded Poll (like UBB.Threads)


Ianomed
01-23-2005, 10:00 PM
Embedded Poll Hack v1.1 by Ianomed, a request from TheAdminZone (http://www.theadminzone.com/forums/showthread.php?t=6563)

It's a simple addition to showthread.php, and two template mods (showthread + postbit[legacy])

What it does is embed a poll in the first post, rather than show it at the top of the thread. On pages 2+ of course it'll show it at the top of the thread, since post 1 won't be displayed there.

See attached screenshot for an example, or check out this poll (http://www.startrek-online.net/community/showthread.php?t=479&page=1&pp=10&styleid=4)

Works with and tested on vB 3.0.6

Changelog:
v1.1 - 30 January 2005 - Added support for hybrid+threaded mode
v1.0 - 24 January 2005 - Initial release

--- Install instructions ---

in showthread.php, find:

################################################## ##############################
####################### SHOW THREAD IN LINEAR MODE #############################
################################################## ##############################
if ($threadedmode == 0)
{


below find:

$post['musername'] = fetch_musername($post);
$post['islastshown'] = ($post['postid'] == $lastpostid);
$post['attachments'] = &$postattach["$post[postid]"];

if ($post['isdeleted'])
{
$template = 'postbit_deleted';
}
else
{
$template = 'postbit';
}
$postbits .= construct_postbit($post, $template);

replace with:

$post['musername'] = fetch_musername($post);
$post['islastshown'] = ($post['postid'] == $lastpostid);
$post['attachments'] = &$postattach["$post[postid]"];

if ($post['isdeleted'])
{
$template = 'postbit_deleted';
}
else
{
$template = 'postbit';
}
// embedded poll
if ($poll && ($post['postcount'] == 1))
{
$post['pollresults']=$poll;
}
else
{
$post['pollresults']="";
}
// embedded poll end
$postbits .= construct_postbit($post, $template);


find:

################################################## ##############################
################ SHOW THREAD IN THREADED OR HYBRID MODE ########################
################################################## ##############################
}
else
{


below find:

// init
$postcount = 0;
$postbits = '';
$saveparsed = '';
$jspostbits = '';

foreach (explode(',', $cache_postids) AS $id)
{
// get the post from the post array
if (!isset($postarray["$id"]))
{
continue;
}
$post = $postarray["$id"];

$post['musername'] = fetch_musername($post);
$post['postcount'] = ++$postcount;

$parsed_postcache = array('text' => '', 'images' => 1);

$template = iif($post['isdeleted'], 'postbit_deleted', 'postbit');

$post['attachments'] = &$postattach["$post[postid]"];
$bgclass = 'alt2';
if ($threadedmode == 2) // hybrid display mode
{
$postbits .= construct_postbit($post, $template);
}
else // threaded display mode
{
$postbit = construct_postbit($post, $template);



replace with:

// init
$postcount = 0;
$postbits = '';
$saveparsed = '';
$jspostbits = '';

foreach (explode(',', $cache_postids) AS $id)
{
// get the post from the post array
if (!isset($postarray["$id"]))
{
continue;
}
$post = $postarray["$id"];

$post['musername'] = fetch_musername($post);
$post['postcount'] = ++$postcount;

$parsed_postcache = array('text' => '', 'images' => 1);

$template = iif($post['isdeleted'], 'postbit_deleted', 'postbit');

$post['attachments'] = &$postattach["$post[postid]"];
// embedded poll
if ($poll && ($post['postcount'] == 1))
{
$post['pollresults']=$poll;
}
else
{
$post['pollresults']="";
}
// embedded poll end
$bgclass = 'alt2';
if ($threadedmode == 2) // hybrid display mode
{
$postbits .= construct_postbit($post, $template);
}
else // threaded display mode
{
$postbit = construct_postbit($post, $template);


save and close file.

open template SHOWTHREAD, find (near the top):
$poll
replace with: (this makes sure the poll will appear at the top on pages 2+, as per default, but hides it on page 1)

<if condition="$pagenumber > 1">
$poll
</if>


finally open template postbit or postbitlegacy (depending on your preferences), find:

<!-- message -->
<div>$post[message]</div>
<!-- / message -->

replace with:

<!-- message -->
<div>$post[message]<!-- embedded poll -->
<if condition="$post[pollresults]">
<br />
<br />
$post[pollresults]
</if><!-- embedded poll end -->
</div>
<!-- / message -->


unless of course you want it beneath (possible) attachments, but above the signature, etc etc., then you'd place it there :)

yoyoyoyo
01-24-2005, 12:39 PM
cool idea! I will check it out later! Thanks for sharing.

Ianomed
01-24-2005, 12:42 PM
My pleasure :)

nexialys
01-24-2005, 12:46 PM
/me check and please!!

Ianomed
01-24-2005, 12:57 PM
Hey Nexy, good to see you around :)
And nice to see you're pleased with the hack.

nexialys
01-24-2005, 01:04 PM
Hey Nexy, good to see you around :)
And nice to see you're pleased with the hack.

hum.. around ?!... you missed me ?! ;) ;)

yeah, i just applyed the hack, and it's good... i thought to recode it a bit, but it's useless, you worked it out well.

btw, in showthread.php there is 3 "$postbits .= construct_postbit($post, $template);" ... specify what is the one to edit... ;) -- or guys, edit the three, you will have the same setting for all kind of displays (threaded as well)

Ianomed
01-24-2005, 01:12 PM
lol, indeed. I've been rather busy with work, enjoying a short breather now. As such not been around here much.

About the 3 sequences, I've never used threaded/hybrid mode on any board whatsoever, so it kinda escaped my attention to make it tick for those as well. *whistles*

I'll post an update to include instructions for it shortly, thanks for pointing it out :D

Guy G
01-24-2005, 04:42 PM
Thats fantasitc.
Doing it now for sure.

Ianomed
01-24-2005, 04:45 PM
thanks :)
keep in mind it doesn't work for threaded and hybrid mode, yet.
I'm posting up a revised version that includes instructions for getting that to work too.
Thusfar all admins I asked never use those modes, but you never know ;)

Skyline_GT
01-24-2005, 06:05 PM
nice hack... Might install it later.
Thanks.

Ianomed
01-30-2005, 05:46 PM
Hybrid + Threaded mode are now also supported :)

Sebastian
02-02-2005, 09:59 PM
anyway to keep the poll embedded when they click on results link? just like if you vote on the poll it will show the results embedded.

edit: nevermind, i already made it... i should stop being lazy :)

Ianomed
02-03-2005, 06:34 PM
most excellent :)
mind sharing it as an addon hack?

Sebastian
02-03-2005, 08:18 PM
in showthread.php find:
'posted' => INT,

replac with:
'posted' => INT,
'viewpoll' => INT,

still in showthread.php, find three instances of:

if ($showresults OR $uservoted)

replace with:
if ($showresults OR $uservoted OR $viewpoll)

edit template poll > polloptions_table

find:
<a href="poll.php?$session[sessionurl]do=showresults&amp;pollid=$pollinfo[pollid]">$vbphrase[view_poll_results]</a>

replace with:
<a href="poll.php?$session[sessionurl]t=$thread[threadid]&amp;viewpoll=1">$vbphrase[view_poll_results]</a>

you can make it part of your orginal hack... i dont care.

dsboyce8624
06-10-2005, 06:49 PM
Could this be combined with the hack that keeps the first post on every page?