vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   this hack here shows all polls on 1 page. (https://vborg.vbsupport.ru/showthread.php?t=81885)

Viks 05-23-2005 03:55 AM

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 $
|| ####################################################################
\*======================================================================*/
?>


Marco van Herwaarden 05-23-2005 10:30 AM

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.

Viks 05-23-2005 08:14 PM

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

Marco van Herwaarden 05-24-2005 04:28 AM

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.

djnth 02-12-2006 09:49 PM

Is it possible to use something like this but to specify just certain Polls?

berayiwu5 02-18-2006 03:36 AM

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.


All times are GMT. The time now is 07:45 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01111 seconds
  • Memory Usage 1,856KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete