Hello There, Guest! › Register

MySubscriptions 2.2 released.
Looking for a custom plugin for your site? Ask here for a quote.

How to make a "plugin" like MyShoutbox
#11

For the first question I recommend you to look at my plugins to see how they do it. Look at the quick reply PM plugin since it's very simple.

TIME_NOW is a constant which holds the value returned by time() when called in global.php so your "time" field must be an integer.
To download our paid plugins and receive support you must be a paid subscriber. Click here for more information.
Reply
#12

So I can only make it save unix timeformat?

I don't really know what function or hook I should look for.
Reply
#13

"So I can only make it save unix timeformat?"
No, but you either parse TIME_NOW and format it the way you want it or you'll be inserting an integer...

"I don't really know what function or hook I should look for. "
It depends on what you want, there's a list of hooks on the MyBB Wiki. However, what I recommend you to do is to look at the file you want to add a hook and search for "hook" inside it. Choose the proper hook you want and that's it.
To download our paid plugins and receive support you must be a paid subscriber. Click here for more information.
Reply
#14

Look, I want to do what you do with the {myshoutbox_abcd}.
I want {servers} to be replaced with a div with a table in it, generated using PHP and MySQL.

I do a MySQL query, that puts out the server in the correct group, with their info. Works like a charm. What I need now is just the {servers} to replace with what I want. I looked up the hooks but the documentation is actually really "crappy". I don't understand how this page is so undetailed. There's not a single hook explained.

Could you please write me a simple example that outputs a table with one row, one cell?
Reply
#15

One thing is {$variable} another thing is {variable}.

I've already told you to look at my Quick Reply PM plugin, better example is impossible.
To download our paid plugins and receive support you must be a paid subscriber. Click here for more information.
Reply
#16

(11-23-2012, 04:56 AM)Pirata Nervo Wrote: One thing is {$variable} another thing is {variable}.

I've already told you to look at my Quick Reply PM plugin, better example is impossible.

Yes but I have no idea where I should start. I searched for $quickreplypm and {$quickreplypm} and read a little through the code, yet I don't know how to replace the {<name>} with a table or something similar.
Also, I don't want to use templates, just a .php file if possible, because I'm using quite some PHP and I have no idea how to combine that with a template file.
Reply
#17

I'm sorry for being a bit vague then. I assumed you had "some decent PHP and MySQL knowledge" - you shouldn't have said that in the first place because I took that as guaranteed.

To "replace" variables in templates you must make it the variable global in the appropriate hook and then either eval it to a certain template or just assign it a value.

Imagine you have a variable on the index template that you want to assign a certain value.
You add a hook to index_start for example (or index_end depending on where you want your function to be executed) and make the variable global in your function, then assign it a value.
To download our paid plugins and receive support you must be a paid subscriber. Click here for more information.
Reply
#18

So basically,
$plugins->add_hook("index_start", $servers);

would replace {$servers} with $servers?

---- edit ----
Wait, when I do this:

$plugins->add_hook("index_start", $servers);
And I assign this:
eval("\$servers = \$servers_page;");

Then I'd build up the page with $servers_page
Reply
#19

No! Look at the plugin I told you about, it looks like you haven't read it at all.

This is how hooks work.
index.php
----
some code
$plugins->run_hook("test");
some more code
----

Now when you do:
$plugins->add_hook("test", "myfunction");

It will like "add" your function between "some code" and "some more code" but executed as a function and not global code.
So you need to globalize certain variables ($mybb, $db, etc) that you may need in your myfunction function which is the function in which you will treat the $servers variable.
To download our paid plugins and receive support you must be a paid subscriber. Click here for more information.
Reply
#20

I still don't seem to get it.
Code:
    function servers_func() {
        global $mybb;
        
        if ($mybb->settings['enabled_servers'] == 1) {
            $server_bit = "<div id=\"lololol\"><center><h1>Server display works!</h1><br />Try to disable it!</center></div>";
        }
        return $server_bit;
    }

And on top of my script, just under the checkign if it's in MyBB, I have this:
Code:
$plugins->add_hook("index","servers_func");

Edit, also tried to do echo $server_bit;, didn't work either. Sorry, but the MyBB hooks are so undetailed, and I'm now to classes.

I'm so stupid. I have to run this function, then search for the {$servers} in the index template and replace it...

Nope, still don't get it...

Could you please help me and show me how to return a string where I put {servers} in the template? I just can't find any proper documentation, and I started with PHP about a few months ago. I can write some decent things, but the MyBB documentation is so horrible that I can't find it out myself. Even while reading through your scripts, I'd like to know what function does what and what hook does what.
Reply




Users browsing this thread: 1 Guest(s)