Current time: 01-09-2009, 11:00 AM Hello There, Guest! (LoginRegister)


Post Reply 
Very simple question
12-14-2008, 10:13 PM (This post was last modified: 12-14-2008 10:14 PM by Snowball.)
Post: #1
Very simple question
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
Find all posts by this user
Quote this message in a reply
12-15-2008, 11:38 AM
Post: #2
RE: Very simple question
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?

Who is Yumi?


It's still the KFC crazed person who can't spell names properly with annoying AlTeRnAtInG CaPiTaLs in the NaMe
Visit this user's website Find all posts by this user
Quote this message in a reply
12-16-2008, 03:56 PM
Post: #3
RE: Very simple question
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.
Find all posts by this user
Quote this message in a reply
12-18-2008, 04:50 AM
Post: #4
RE: Very simple question
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.

Who is Yumi?


It's still the KFC crazed person who can't spell names properly with annoying AlTeRnAtInG CaPiTaLs in the NaMe
Visit this user's website Find all posts by this user
Quote this message in a reply
12-24-2008, 10:20 PM (This post was last modified: 12-24-2008 10:20 PM by Snowball.)
Post: #5
RE: Very simple question
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?
Find all posts by this user
Quote this message in a reply
12-25-2008, 02:24 AM (This post was last modified: 12-25-2008 02:24 AM by Yumi.)
Post: #6
RE: Very simple question
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';


Who is Yumi?


It's still the KFC crazed person who can't spell names properly with annoying AlTeRnAtInG CaPiTaLs in the NaMe
Visit this user's website Find all posts by this user
Quote this message in a reply
12-25-2008, 08:35 PM
Post: #7
RE: Very simple question
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...
Find all posts by this user
Quote this message in a reply
01-02-2009, 11:28 PM (This post was last modified: 01-02-2009 11:28 PM by Yumi.)
Post: #8
RE: Very simple question
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.

Who is Yumi?


It's still the KFC crazed person who can't spell names properly with annoying AlTeRnAtInG CaPiTaLs in the NaMe
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: