Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 05-23-2005, 03:55 AM
Viks Viks is offline
 
Join Date: Sep 2004
Location: Toronto
Posts: 295
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default this hack here shows all polls on 1 page.

Sometime back I got a paid hack which shows all polls on 1 single page.

the PHP copy is attached. Lately I have got wary of the mod, it has lost its attractiveness - since it uses no templates - it looks pretty bland on my forum.
PLUS instead of showing recent poll first.. it shows the oldest poll first and most recent right in the end.

Can someone out here suggest or better this mod in some way... will really appreciate your help in this.


thanks


PHP Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS'1);
define('THIS_SCRIPT''polls');
define('POLLSPERPAGE'3);

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
    
'polloptions_table',
    
'polloption',
    
'polloption_multiple',
    
'pollresults_table',
    
'pollresult',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
'./includes/functions_bigthree.php');
require_once(
'./includes/functions_showthread.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################


// check for vboption
//if (!isset($vboptions['pollsperpage']))
//{
//    $DB_site->query("INSERT INTO " . TABLE_PREFIX . "phrase (phraseid, languageid, varname, text, phrasetypeid) VALUES (NULL, '0', 'setting_pollsperpage_title', '" . addslashes('Polls Per Page') ."', '5000')");
//    $DB_site->query("INSERT INTO " . TABLE_PREFIX . "phrase (phraseid, languageid, varname, text, phrasetypeid) VALUES (NULL, '0',  'setting_pollsperpage_desc', '" . addslashes('The number of polls you would like displayed on the page that displays all polls.') ."', '5000')");
//    $DB_site->query("INSERT INTO " . TABLE_PREFIX . "setting (varname, grouptitle, value, defaultvalue, displayorder, volatile) VALUES('pollsperpage', 'poll', 10, 10, 120, 1)");
//    $vboptions['pollsperpage'] = '10';
//}

$threads $DB_site->query("SELECT forumid, pollid, open, threadid FROM " TABLE_PREFIX "thread WHERE pollid > 0");
while(
$thread $DB_site->fetch_array($threads))
{
    
$threadpollinfo[$thread['pollid']][] = $thread['forumid'];
    
$threadpollinfo[$thread['pollid']][] = $thread['open'];
    
$threadpollinfo[$thread['pollid']][] = $thread['threadid'];
}

if (empty(
$_REQUEST['start'])) $_REQUEST['start'] = 0;

$pollnum 0;


$polls $DB_site->query("SELECT * FROM " TABLE_PREFIX "poll");
$totalpolls $DB_site->num_rows($polls);

// page number
if (empty($_REQUEST['page'])) $pagenumber 1;
    else 
$pagenumber $_REQUEST['page'];

// page construction
$perpage $vboptions['pollsperpage'];
$pagenav construct_page_nav($totalpolls"polls.php?$session[sessionurl]""&amp;pp=".$vboptions['pollsperpage']);

// start number
$prevpage $pagenumber 1;
$start $perpage $prevpage;

$polls $DB_site->query("SELECT * FROM " TABLE_PREFIX "poll ORDER BY pollid LIMIT " $start .", "$perpage);
while(
$pollinfo $DB_site->fetch_array($polls))
{
    
$pollbits '';
    
$counter 1;
    
$pollid $pollinfo['pollid'];
    
    
$threadinfo['forumid'] = $threadpollinfo[$pollid]['0'];
    
$thread['open'] = $threadpollinfo[$pollid]['1'];

    
$show['editpoll'] = iif(can_moderate($threadinfo['forumid'], 'caneditpoll'), truefalse);

    
$pollinfo['question'] = parse_bbcode(unhtmlspecialchars($pollinfo['question']));

    
$splitoptions explode('|||'$pollinfo['options']);
    
$splitvotes explode('|||'$pollinfo['votes']);

    
$showresults 0;
    
$uservoted 0;

    
$forumperms fetch_permissions($threadinfo['forumid']);

    if (!(
$forumperms CANVOTE))
    {
        
$nopermission 1;
    }

    
//if (!$pollinfo['active'] OR ($pollinfo['dateline'] + ($pollinfo['timeout'] * 86400) < TIMENOW AND $pollinfo['timeout'] != 0))
    
if (!$pollinfo['active'] OR !$thread['open'] OR ($pollinfo['dateline'] + ($pollinfo['timeout'] * 86400) < TIMENOW AND $pollinfo['timeout'] != 0) OR $nopermission)
    {
        
// poll is closed, ie show results no matter what
        
$showresults 1;
    }
    else
    {
        
//get userid, check if user already voted
        
$voted fetch_bbarray_cookie('poll_voted'$pollid);
        if (
$voted)
        {
            
$uservoted 1;
        }
    }

    if (
$pollinfo['timeout'] AND !$showresults)
    {
        
$pollendtime vbdate($vboptions['timeformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
        
$pollenddate vbdate($vboptions['dateformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
        
$show['pollenddate'] = true;
    }
    else
    {
        
$show['pollenddate'] = false;
    }

    
$option['open'] = $stylevar['left'][0];
    
$option['close'] = $stylevar['right'][0];

    foreach (
$splitvotes AS $index => $value)
    {
        
$pollinfo['numbervotes'] += $value;
    }

    if (
$bbuserinfo['userid'] > AND $pollinfo['numbervotes'] > 0)
    {
        
$pollvotes $DB_site->query("
            SELECT voteoption
            FROM " 
TABLE_PREFIX "pollvote
            WHERE userid = 
$bbuserinfo[userid] AND pollid = $pollid
        "
);
        if (
$DB_site->num_rows($pollvotes) > 0)
        {
            
$uservoted 1;
        }
    }

    if (
$showresults OR $uservoted)
    {
        if (
$uservoted)
        {
            
$uservote = array();
            while (
$pollvote $DB_site->fetch_array($pollvotes))
            {
                
$uservote["$pollvote[voteoption]"] = 1;
            }
        }
    }

    foreach (
$splitvotes AS $index => $value)
    {
        
$arrayindex $index 1;
        
$option['uservote'] = iif($uservote["$arrayindex"], truefalse);
        
$option['question'] = parse_bbcode($splitoptions["$index"], $forum['forumid'], 1);

        
// public link
        
if ($pollinfo['public'] AND $value)
        {
            
$option['votes'] = '<a href="poll.php?' $session['sessionurl'] . 'do=showresults&amp;pollid=' $pollinfo['pollid'] . '">' $value '</a>';
        }
        else
        {
            
$option['votes'] = $value;   //get the vote count for the option
        
}

        
$option['number'] = $counter;  //number of the option

        //Now we check if the user has voted or not
        
if ($showresults OR $uservoted)
        { 
// user did vote or poll is closed

            
if ($value == 0)
            {
                
$option['percent'] = 0;
            }
            else if (
$pollinfo['multiple'])
            {
                
$option['percent'] = vb_number_format($value $pollinfo['voters'] * 1002);
                
$option['percent'] = vb_number_format(($value $pollinfo['voters']) ? $value $pollinfo['voters'] * 100 1002);
            }
            else
            {
                
$option['percent'] = vb_number_format(($value $pollinfo['numbervotes']) ? $value $pollinfo['numbervotes'] * 100 1002);
            }

            
$option['graphicnumber'] = $option['number'] % 1;
            
$option['barnumber'] = round($option['percent']) * 2;

            
// Phrase parts below
            
if ($nopermission)
            {
                
$pollstatus $vbphrase['you_may_not_vote_on_this_poll'];
            }
            else if (
$showresults)
            {
                
$pollstatus $vbphrase['this_poll_is_closed'];
            }
            else if (
$uservoted)
            {
                
$pollstatus $vbphrase['you_have_already_voted_on_this_poll'];
            }

            eval(
'$pollbits .= "' fetch_template('pollresult') . '";');
        }
        else
        {
            if (
$pollinfo['multiple'])
            {
                eval(
'$pollbits .= "' fetch_template('polloption_multiple') . '";');
            }
            else
            {
                eval(
'$pollbits .= "' fetch_template('polloption') . '";');
            }
        }
        
$counter++;
    }

    if (
$pollinfo['multiple'])
    {
        
$pollinfo['numbervotes'] = $pollinfo['voters'];
        
$show['multiple'] = true;
    }

    if (
$pollinfo['public'])
    {
        
$show['publicwarning'] = true;
    }
    else
    {
        
$show['publicwarning'] = false;
    }

    
// add thread link
    
eval('$poll.= "<table><tr><td><br><b>Login to cast your vote or click<a href=\"showthread.php?$session[sessionurl]t=".$threadpollinfo[$pollid][2]."\">here</a> to discuss this poll.</b><br></td></tr></table>";');
    if (
$showresults OR $uservoted)
    {
        eval(
'$poll .= "' fetch_template('pollresults_table') . '";');
    }
    else
    {
        eval(
'$poll .= "' fetch_template('polloptions_table') . '";');
    }

}



eval(
'$HTML = "<div align=\"$stylevar[right]\">$pagenav</div>$poll<div align=\"$stylevar[right]\">$pagenav</div>";');



// #############################################################################
// draw navbar
$navbits = array();
$navbits[''] = 'Polls';

$navbits construct_navbits($navbits);
eval(
'$navbar = "' fetch_template('navbar') . '";');

// #############################################################################
// output page
eval('print_output("' fetch_template('GENERIC_SHELL') . '");');

/*======================================================================*\
|| ####################################################################
|| # Downloaded: 17:11, Tue Jan 18th 2005
|| # CVS: $RCSfile: polls.php,v $ - $Revision: 1.454.2.7 $
|| ####################################################################
\*======================================================================*/
?>
Reply With Quote
  #2  
Old 05-23-2005, 10:30 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

To show newest first, change:
PHP Code:
$polls $DB_site->query("SELECT * FROM " TABLE_PREFIX "poll ORDER BY pollid LIMIT " $start .", "$perpage); 
to:
PHP Code:
$polls $DB_site->query("SELECT * FROM " TABLE_PREFIX "poll ORDER BY pollid DESC LIMIT " $start .", "$perpage); 
Not tested, but that should do it after a quick look.

And it does use templates, so i don't get how you got the impression it didn't.
Reply With Quote
  #3  
Old 05-23-2005, 08:14 PM
Viks Viks is offline
 
Join Date: Sep 2004
Location: Toronto
Posts: 295
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

MMarcoH64

Thank for you help.. that was very nice, YES! it worked.

As for templates, i meant external templates picked up from Style Manager.... since everything is in-built in 1 single PHP.

Vik
Reply With Quote
  #4  
Old 05-24-2005, 04:28 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Viks
As for templates, i meant external templates picked up from Style Manager.... since everything is in-built in 1 single PHP.
Just search the code for 'fetch_template' and you will find all templates used.
Reply With Quote
  #5  
Old 02-12-2006, 09:49 PM
djnth djnth is offline
 
Join Date: May 2003
Location: AZ
Posts: 73
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is it possible to use something like this but to specify just certain Polls?
Reply With Quote
  #6  
Old 02-18-2006, 03:36 AM
berayiwu5 berayiwu5 is offline
 
Join Date: Feb 2006
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Could anyone tell me where exactly I am supposed to modify or insert the provided codes? I am not a programmer, but I am good at following precise instructions.

And has anyone else ever tried this hack? Please let me know if that works. Since I don't know anything about coding, I don't want to mess things up.

Your tips are immensely appreciated.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:43 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04086 seconds
  • Memory Usage 2,325KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete