MyBB Community Forums

Full Version: Very simple question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do I add another set of options to the new thread page? I'm wanting to add a new poll type that uses Single Transferable Vote to determine the results
Hi,
May be a simple question, but unfortunately, you're going to have to code all the actions behind the voting system (ie a system to transfer votes).
Are you familiar with PHP?
Yup, and SQL etc. It's not the coding of STV that's worrying me, it's just I cant seem to figure out which hook to use to add the button for the poll. I appreciate the whole project wont be simple to code.
It depends on how you want to approach the issue. For example, you may wish to place a hook for showthread_start, then if you want to display some link for example, evaluate it there. Don't forget to place a variable in the appropriate template so that the link actually gets displayed on the showthread page.
Ok, I've now got the following:

PHP Code:
function myplugin_activate()
{
        global 
$db;
        include 
MYBB_ROOT '/inc/adminfunctions_templates.php';

        
$find     '#' preg_quote('{pollbox}') . '#';
        
$replace  '{stvbox}{pollbox}';
        
find_replace_templatesets('newthread'$find$replace1);


So how do I set the value of {stvbox}? Is this the right way to go about adding something to a page?
It's actually {$pollbox} etc (templates are eval'd as strings).

You need to have a hook before the template is evaluated, eg newthread_start - you then set the variable there.

Example:
PHP Code:
function myplugin_activate()
{
        global 
$db;
        include 
MYBB_ROOT '/inc/adminfunctions_templates.php';

        
$find     '#' preg_quote('{$pollbox}') . '#';
        
$replace  '{$stvbox}{$pollbox}';
        
find_replace_templatesets('newthread'$find$replace1);


$plugins->add_hook('newreply_start''myplugin_newreply_start');
function 
myplugin_newreply_start()
{
    global 
$stvbox;
    
    
$stvbox 'This is a box';

But surely any variable created by a function called by a hook will only be local to that function, and when the stack frame is popped, it's gone? If this is the case I cant see how within the hook system I can set the $stvbox variable without modifying core code...
Declare the variable as global (as I have done in the above code sample). Local, non-static, variables get deleted after the function has been executed.
Reference URL's