Writing Modifications for MyBB 1.2

So as the time comes closer to the MyBB release, I guess it’s time to tell you guys that we will have broken a lot of older code modifications and plugins due to the extensive changes in MyBB 1.2. Each and every template has also changed to conform to our new standards.

This is a short guide on how to ensure your code modifications and plugins are ready for MyBB and what changes will be required for your modifications to work with 1.2 as well as other code based changes.

Function Calls

One of the major changes is that most of the functions within MyBB have renamed to make more sense and make them more understandable when reading the code.

Example changes include:

  • outputpage becomes output_page
  • getparentlist becomes get_parent_list
  • nopermission becomes error_no_permission
  • ismod becomes is_moderator
  • updateforumcount becomes update_forum_count

Generally, underscores are used to break the function name up so it becomes readable. Most functions are prefixed with a verb such as output, update, get, do, format, or build. You’ll need to check functions.php closer to the release for the new names of functions.

The other change in regards to function calls is that several are now deprecated and no longer exist within MyBB. postify, domecode, domycode are examples of these functions which no longer exist and have been replaced in some way, shape or form (The post parser is now a class)

Accessing Internal MyBB Variables

The $settings and $mybbuser variables became deprecated in MyBB 1.0, however we left in support for them due to the vast number of modifications still using them.

MyBB 1.2 no longer contains these references, and only supports accessing them through the MyBB class variable ($mybb). For example:

  • $settings becomes $mybb->settings
  • $mybbuser becomes $mybb->user

Get and Post Variables

Introduced with 1.0 along with the MyBB core class was a standardised way of accessing input (Get and Post) variables as well as having common variables such as thread ID (tid) and pid (post ID) automatically filtered for bad input. We also had in place code which would not kill global variables such as $tid, $pid assigned from Get or Post input when register_globals was turned on within PHP and the KILL_GLOBALS constant was not defined.

Up until 1.2, if you still followed old coding conventions with register_globals turned on, this would have worked. You are now required to either use $_GET, $_POST or preferably $mybb->input to fetch incoming data.

Variables within Templates

We were sloppy in MyBB with variables (specifically arrays) in templates. We still used $example[hi] instead of $example[’hi’] because our template parser (using eval) did not support this. MyBB 1.2 now uses, by default, variables enclosed within curly braces such as {$example[’hi’]}. The same applies for class variables.

Database Querying

MyBB 1.0 introduced $db->update_query and $db->insert_query methods for inserting data into a table within a database. We’ve further extended the database abstraction layer by adding a few more methods:

  • fetch_field - Fetch one specific field from a row being queried
  • simple_select - Used to perform a simple select query (with no joins) on a table
  • delete_query - Used to perform a delete query on a table in a database
  • escape_string - Replaces addslashes, escapes data before being used in a query
  • get_version - Returns the version number of the database server being used

That is just a handful of some of the new methods available in the release. You should make proper use of them when necessary to ensure your queries are cross compatible with different database engines. This release also includes a MySQLi database abstraction layer which is used in preference over MySQL if your server supports it.

Good Clean Code and Coding Standards

The MyBB coding standards have basically been rewritten to conform to stricter policies making code easier to read and write.

  • Code should be commented so that a user can understand what is happening
  • Functions should be descriptively named, contain underscores to break words and contain PHPDoc headers
  • Queries are now split on to multiple lines allowing you to quickly identify what is selected, from where, where joins are and the conditions/limits of the query

Full coding standards will be released along side the MyBB 1.2 release.

This is just a small overview of what has changed with MyBB 1.2. It is by no means a comprehensive guide and things will probably still change before the release.

I’ve probably managed to scare a few people off now by stating that most modifications will not work without further code changes, but MyBB 1.2 brings in many, many and even more advantages and features than any other MyBB release and you should be looking forward to it. It is a huge step for us, and probably you too.

Comments

  1. 1.

    Dempsey (June 2nd, 2006, 7:17 pm)

    Sounds like great work, you’ve all been really busy :D You’ve got me worried how much work I’m going to have to do to upgrade MPSounds.net as it quite heavily uses MyBB for its entire site. Any approximate release dates so we know when we can start preparing for our code changes?

    Keep up the great work guys :D

  2. 2.

    sock (June 2nd, 2006, 7:48 pm)

    Sweet. myBB 4 teh win!

  3. 3.

    Bobby (June 2nd, 2006, 10:13 pm)

    This is really great! The Team is getting along so well, and I’m glad that you have a coding standards guideline set out. This will further improve the high standard of what MyBB offers against others.

    I’m still interested in what the Admin CP will look like, tabular, drop-down… the suspense is killing me! Just to clarify, do ALL translators get a pre-release preview of 1.2 before everone else? (Please say yes, please say yes, please say yes….)

  4. 4.

    xiaozhu (June 2nd, 2006, 10:16 pm)

    Hehe..Random pick Previewers or maybe Beta Testers? :p

  5. 5.

    Bobby (June 2nd, 2006, 10:23 pm)

    xiaozhu said:
    Hehe..Random pick Previewers or maybe Beta Testers? :p

    When I said Pre-release Previews I meant Beta Testing, sorry.

    Dempsey said:
    Sounds like great work, you’ve all been really busy :D You’ve got me worried how much work I’m going to have to do to upgrade MPSounds.net as it quite heavily uses MyBB for its entire site. Any approximate release dates so we know when we can start preparing for our code changes?

    Keep up the great work guys :D

    Well you should get ready this month, the Wiki states that there should be a major release almost every six months, and that sixth month is this June, this month! Although it could be early next month - beta’s arnt out yet (I think), I think they get out first then its tested for a while and then the public gets it.

  6. 6.

    Chris Boulton (June 2nd, 2006, 11:33 pm)

    I’m still interested in what the Admin CP will look like, tabular, drop-down… the suspense is killing me! Just to clarify, do ALL translators get a pre-release preview of 1.2 before everone else? (Please say yes, please say yes, please say yes….)

    The new Admin CP won’t be in 1.2 as we’ve stated before.

    Translators get access to the beta.

    Well you should get ready this month, the Wiki states that there should be a major release almost every six months, and that sixth month is this June, this month! Although it could be early next month - beta’s arnt out yet (I think), I think they get out first then its tested for a while and then the public gets it.

    The beta will be out in to private testing sometime within the next two weeks because of the amount of assignment work I have to deal with at the moment. (Speaking of which - anybody got any decent tips for making huge green screens for filming? - Need some hints)

  7. 7.

    John Anderton (June 3rd, 2006, 5:34 am)

    the new mybb is going to be better than every with all the things you guys are adding :)

  8. 8.

    tikitiki (June 3rd, 2006, 9:18 am)

    Chris Boulton said:
    (Speaking of which - anybody got any decent tips for making huge green screens for filming? - Need some hints)

    How about painting your wall green? :P

  9. 9.

    Belloman (June 3rd, 2006, 2:34 pm)

    Hmm, let’s just hope a lot of the modifications I use become features :D And hopefully Tikitiki will be able to get my news poster working if it doesn’t… (I should test it out…)

    John Anderton said:
    the new mybb is going to be better than every with all the things you guys are adding :)

    Of course it will :P

    Bobby said:
    I’m still interested in what the Admin CP will look like, tabular, drop-down… the suspense is killing me!

    The few screenshots I’ve seen of the future MyBB ACP look great ;) I’ll just say it’ll be a pleasent surprise when it comes :)

  10. 10.

    k776 (June 3rd, 2006, 3:00 pm)

    Well, I’m back. I thought I’d pop in to say congrats on even more fantastic updates. I might have to pop back and do up my plugins to work with 1.2, although my life is too busy atm to do as much as I used to (post support and what not). So maybe, when 1.2 is out, expect me back (I havn’t checked but hopefully no one has stolen my mods ideas :P)

    Some questions for the developers:
    * XHTML and CSS code validated and all correct?
    * E_ALL turned on and errors all fixed up yet?

  11. 11.

    Bobby (June 3rd, 2006, 4:05 pm)

    Chris Boulton said:
    The new Admin CP won’t be in 1.2 as we’ve stated before.

    WHAT! OMG! RU SERIOUS! WHY? :cry: :cry:

    Chris Boulton said:
    Translators get access to the beta.

    Ok, I guess this evens it out, no new admin but I get to be the first ppl to preview it!!! OMG!!! :) :)

  12. 12.

    Chris Boulton (June 3rd, 2006, 6:05 pm)

    We’ve always stated it won’t be in 1.2 - at least for the first few months.

    We don’t want to rush in to the Admin CP to ensure that it is all rushed. We want it thought out, well organised and clean.

    MyBB 1.2 is primarily a front end based release where as 1.4 will focus more on administration.

  13. 13.

    Peter Akkies (June 3rd, 2006, 8:29 pm)

    k776 said:
    Some questions for the developers:
    * XHTML and CSS code validated and all correct?
    * E_ALL turned on and errors all fixed up yet?

    That’s going to be 1.4 stuff I think. We have it valid, but the code isn’t semantic by far. It’s high on my personal MyBB to-do list, but I’m not sure what others think (the new ACP is important too, but I reckon we can do both).

  14. 14.

    Bobby (June 3rd, 2006, 11:16 pm)

    Peter Akkies said:

    That’s going to be 1.4 stuff I think. We have it valid, but the code isn’t semantic by far. It’s high on my personal MyBB to-do list, but I’m not sure what others think (the new ACP is important too, but I reckon we can do both).

    Both is good, but the earlier should be more of a priority. Once you have the code right, your imagination is the only thing stopping you from mods to the looks.

  15. 15.

    tikitiki (June 4th, 2006, 1:39 am)

    k776 said:
    Well, I’m back. I thought I’d pop in to say congrats on even more fantastic updates. I might have to pop back and do up my plugins to work with 1.2, although my life is too busy atm to do as much as I used to (post support and what not). So maybe, when 1.2 is out, expect me back (I havn’t checked but hopefully no one has stolen my mods ideas :P)

    Some questions for the developers:
    * XHTML and CSS code validated and all correct?
    * E_ALL turned on and errors all fixed up yet?

    They’ve most likely all been stolen :P *XHTML - I’m not sure if xhtml has been validated but I went through the acp a while ago and cleaned up alot of the tags.
    *E_ALL - Thats another story for another time :P

    Bobby said:

    WHAT! OMG! RU SERIOUS! WHY? :cry: :cry:

    Ok, I guess this evens it out, no new admin but I get to be the first ppl to preview it!!! OMG!!! :) :)

    If we were to stuff everything in 1.2 it would never be released!!! :P

  16. 16.

    Bobby (June 4th, 2006, 9:55 am)

    lol, I understand now. Ill be waiting between christmas and my birthday (march 22 - im giving you two months extra! :)) for the new admin cp.

  17. 17.

    tikitiki (June 7th, 2006, 7:36 am)

    You may have to wait 6 months for the next release, according to the 6 month release scedule: http://wiki.mybboard.com/index.php/Versions#1.2.x

  18. 18.

    Dennis (June 8th, 2006, 4:39 pm)

    tikitiki said:
    If we were to stuff everything in 1.2 it would never be released!!! :P

    If it were to be released, it would be impossible to download as the package would be an infinite number of bytes :)

  19. 19.

    Bobby (June 8th, 2006, 9:18 pm)

    Dennis said:

    If it were to be released, it would be impossible to download as the package would be an infinite number of bytes :)

    Really! What does that mean… mybb is getting bulky?

  20. 20.

    Dennis (June 11th, 2006, 9:21 am)

    If we were to stuff “everything” (everything imaginable) into MyBB, the number of bytes would be infinite.

  21. 21.

    Bobby (June 11th, 2006, 2:09 pm)

    oh, LOL, i get it now (took me a while)

  22. 22.

    Ryan (June 16th, 2006, 3:36 pm)

    I may wait until 1.2 comes out to move MyBBT, we’ll see though…

  23. 23.

    DennisTT.Net (June 24th, 2006, 5:39 pm)

    MyBB Security…

    Over the last few weeks there have been two releases to MyBB to patch potential security vulnerabilities that have been discovered by various parties. I have seen some people who have found these seemingly miniscule updates too trivial to apply to the…

Post a Comment

Note: * indicates required fields.