Modify the output
#1
Hello everyone,

I'm a beginner in developping MyBB plugin (but code in PHP since two years or so), and I'm trying to create a simple plugin, which basically queries a server, gets some statistics through that call, and displays them.
I choose to modify static numbers (with str_replace) instead of dynamically display them (with an echo for example). However, nothing is changed on my page Undecided .

Here's the code of my plugin : http://pastebin.com/fUUwcuvB

The plugin is working great, but it doesn't do anything yet, which is quite annoying Toungue . I'm not sure by the way if the "pre_output_page" hook is a good choice for the task I want to perform.

Thanks in advance Smile .
Reply
#2
It may be worth just piggy-backing that data onto the mybb class and placing a reference to that inside the template. There are certainly other ways, but I'm on a mobile and am short for time.

For this to work, you would need to start by hooking to global_start, load the mybb class into the global scope, then insert that array into the mybb class with $mybb->array_stat = $array_stat.

Then just add template variables for each of the data in your array_stat array: {$mybb->array_stat['total_players']}, for example.

I'm writing this from memory, on a laggy browser on my phone while the guy next door feels the need to power drill at 9:30 in the morning, but I think this should work.

b.
Reply
#3
^ This guy is a genius. Thanks a lot, and I hope the drill has eventually stopped Smile .
Reply
#4
the problem is that you are using str_replace, which is a function and expects to return something and you are not.

You should be using

$page = str_replace('Total...', $array_stat whatever, $page);

on those three lines you have
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#5
Thanks for pointing out that bug, I was frustrated not to know why my plugin didn't work, though I prefer Beardy's solution.

Thanks anyway Smile .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)