Ipb 1.3:Making a Mod
From IpbWiki
NOTE: I'm assuming you know PHP and SQL. If you don't, you aren't gonna get very far. Also, this is for v1.3. Sorry guys, but I don't got the money for v2.1.
Contents |
Introduction
Now I want to clear that I am no kind of expert. In fact, all that's in this guide is all I know - the basics. In fact, a lot of it could be wrong, in which case I hope a real expert can correct me. I hope this is a good guide for newbs who wanna mod their IPB. Experts, if this sucks, feel free to diss me and fix it up yourselves
The Basics
Its always good to know the structure off something before diving into it head first. So, to start off - IPB has just about three different important sections of code: sources, skins, and languages. Sources are the heart of the mod - the very inner workings. Skins are the HTML components - you'll find most of the HTML in IPB here. Languages are external libraries of messages and the such. You probably won't be fooling around with these unless you are making a large mod and want to make it multilanguage compatible.
Now, if you're making a miniscule mod, say, three lines of code to be added on to a file, you would probably wanna get to know the file you're modding. Wouldn't hurt to read all of this too. Any mod requires at least some basic knowledge. If you're making a small mod, you might be content with just one source file. If you're making a bigger file, you might want to separate the HTML onto a skin file. And finally, if you're making a really big mod, say, something like IBStore, you want to include a language file so other people can make your mod in different languages.
The Global Variables (classes)
Well, if you wanna make a mod, there are about six important global variables/classes you wanna know.
$ibforums
As our buddy Mr. Mecham describes it: a nice easy to transport super class. It includes all the conf_global settings, and a few handy functions/variables. Namely the input array (parse_incoming function), member info (authorise function), and a bunch of session stuff. I'll include a list of the included stuff (at least the code for them). Note, I'm just making this in code so you get familiar with the syntax. Don't fiddle with this, or add it in index.php or anything else.
$ibforums->input = $std->parse_incoming();
$ibforums->member = $sess->authorise();
$ibforums->skin = $std->load_skin();
$ibforums->skin_rid = $ibforums->skin['set_id'];
$ibforums->skin_id = 's'.$ibforums->skin['set_id'];
$ibforums->lastclick = $sess->last_click;
$ibforums->location = $sess->location;
$ibforums->session_id = $sess->session_id;
$ibforums->vars //an assortment of random variables.
That's probably not all of them, but its a bunch. $ibforums is truly a super-class. Will come in very handy as you start making your mod.
$std (quit it, pervs), $sess, and $display
These would be the three sections off our handy friend functions.php. Functions.php includes just about any PHP function used in IPB. And trust me, Matt Mecham loves functions (which is good, considering it makes the whole scripts much easier editted). Pretty much everything is a function. Error messages, printing the header, etc. I won't bother to include a list of important functions, because how important each function is depends on what your mod is. But remember, before doing almost ANYTHING, think: is there already a function for this?
$DB
The database query system. Works simple. Here's the syntax: $DB = "mysql query goes here";
The $DB is pretty simple. The reason it's its own class is so that IPB can be cross-database compatible. IPB is pretty much cross-everything compatible, as any good coded product should be. Now, you might be expected me to go through a whole description of the IPB database's organization, but I won't. For three reasons - one, its way too big. Two - its very simple, you could find out yourself by just looking through it where whatever is. And three - I don't know all of it.
$skin_universal
This is just a reference to all the functions within skin_global.php. You won't notice this very much while you're coding, but you'll notice it a lot in functions.php. That's because this is just the bare bones HTML stuff functions. Usually there is a corresponding functions.php function that should be used instead of using these functions. However, if for some reason the function in functions.php doesn't work for you, feel free to create a new one from scratch using these functions.
index.php
Well, I'll start off by saying index.php is the central hub for everything on IPB, except the ACP. What it is is just a file that loads all the globals, and then determines what files to include. That's where you come in. You want to tell index.php when to fetch your new file and where to fetch it. So open up your index.php. First, it never hurts to get acquaintanced with the file. Look through it - it defines most of the variables I showed you a second ago in the first 300 or so lines. It then does some basic permission checks and checks if the board is offline. Then comes the important part - it chooses which file to include.
First, it gives you an array of values for the act variable in the URL and which files to fetch in each case. After that, start the if statements:
- If there is no match in the array, act=idx.
- If act=home, go to IP Dynamic Lite.
- If act=modules, do the modules thing.
- And finally, if it ain't one of those, find go to the array, and it'll include the file that it says to include.
Numero 4 is the important one. Now, think up a short name for your mod. Then add it to the array with the corresponding file to include and its path from the sources folder. Here is an example, the one I used for my mod:
That means if the variable in the URL, act, equals "manage," then include the file mng_cnsl.php. Here's another example, this time for IBStore.
That means that if act=store, then include sources/store/store.php. Getting the jist of it? Good. Now that we've told index.php where to find the new mod, let's create it!
The Basics of your Mod
The first thing you wanna decide is what you're gonna call your mod's class. You probably want to keep it concise. If I were you, I'd call it the same thing I gave as the redirect (the act= thing). Start off by giving the following line of code:
And replace mng_cnsl with whatever you want to call your class. Then, time to define your class. Now, with your seasons PHP skills, you can define some variables that you think are going to be usefull somewhere in the code. Thats up to you. Now, you start writing the code! You might wanna check out the CSS first, to make your mod have the style of your board. You can do that through your ACP (Skins/Templates -> Style Sheets -> Edit).
A Few Handy Functions
Well, you're going to need to know some functions if you're going to make an IPB mod. Here are just three, that I find essential. There are probably more essential ones that I forgot to mention (experts, feel free to add them in). Here they are:
$std -> Error
Well, let's start out with the syntax: $std -> Error(array error);
In that array ($error), you'll need to specify three things. Here's an example:
The first thing you need to specify is the level. Make it 1. To date I haven't seen any other error level used, and quite frankly, I can't see where the level is used in the function. The second thing is the message. The thing you see in the example is the identifier to go find the message in lang_error.php. If you want to create your own error problem, you'll need to go create an error message identifier and a corresponding error message in Lang/lang_error.php. The final thing in the array is INIT (well, there is EXTRA, but I'm not gonna bother with it). Mr. Mecham has a good explanation of this one: INIT is passed to the array if we've not yet loaded a skin and stuff. That's all I've got to say.
$display -> do_output
Syntax: $display -> do_output(array info);
Here's an example of what goes into that array:
The title line defines what the title of the page is going to be in the top bar of your browser (<title> in HTML). The JS line defines whether or not you're going to be using javascript. And the NAV line is what the name of this location is going to be in the navagational-tree-thing (for example, I'm seeing "Invisionize - Forums » Programming » IPB Mods » IPB Modification Chat and Tips" right now).
$display -> add_output
Syntax: $display -> add_output(string output);
This is a function that you're going to NEED to use in your mod. Whatever HTML you want to be displayed, store it there. Use it instead of echo. Wherever you would use something like "echo "wassup";" use instead "$output .= "wassup";" or something of the such. Just don't forgot to add at the bottom of the mod these two lines of code, encompassing both of the past two functions:
$print -> do_output ( array( 'TITLE' => "$this->title", 'JS' => 0, NAV => $this->nav ) );
(Assuming you defined the title and the nav as a class variable...)
Conclusion
Well, I bet I've messed up a bunch of names, gave a bunch of wrong descriptions, left a bunch out, and generally screwed up. That's because I'm definetely not an expert. But hey, it's the best I could do, and I think that this forum needs a guide to the basics of IPB for wannabe-modders.
Original Article Author: Djbob2
