UPB2 Classes

From MyUPBWiki

Jump to: navigation, search

Although I try and comment the classes I write for UPB, those messages just don't seem to give a nice overview of what the class is suppose to do. Here you will find reference to all the classes used in UPB.


Contents

The Framework

Before you go diving into all the classes you must learn the framework we have created for UPB in order to manage the code and keep it nicely organized.

index.php

Lets take a quick look at how an action is performed in the UPB framework. index.php is the only file that is executed by the user (ex. http://forum.myupb.com/index.php) So here is the code:

<?php
/**
 * Execution entry point
 */

// Include the main class which derives all other classes
include dirname(__FILE__)."/includes/class/upb.class.php";

// Parse the command line
if(FALSE !== ($cmd = upb::parseCommand())) {
    // if UPB_MODDED is defined for this page then we pass control over to the mod
    if(!defined("UPB_MODDED")) $upb = new upbPage($cmd);
} trigger_error("Unable to initialize UPB", E_USER_ERROR);
?>

Doesn't look like much right? Ok, I'll be honest, it isn't all that much. But, this file performs everything from viewing a forum to modifying permissions. Cool eh? Lets take a closer look...

upb::parseCommand()

Please note at this point no class instances have been created, by using the scope resolution operator (::) we can access static methods of the upb class. parseCommand uses the input class to grab the requested command from the querystring (for example http://forum.myupb.com/index.php?c=usercp would call the User control panel command)

At this point a temporary textdb object is created to query the mods database and see if there is a mod for the requested command. If there is, then all control for this mod is handed over. Otherwise, a instance of upbPage is created. Each command has its own upbPage class, this extends the upb class.

How does the command get run?

If you're at all famaliar with OOP, you have probably already got it all figured out already. But for the rest of you, when we created an instance of the upbPage class it actually automatically calls the upbPage() function inside that class. If you look at one of the commands you can see everything for the command happens inside the upbPage() function.

Am I ready to start coding?

Maybe... Maybe not, I'm not the best teacher out there so i'll let you be the judge of this.

Back-bone Classes

  • Class upb - Core of UPB, the class that brings everything together and essentially creates the framework
  • Class tdb - The class that lets us use ONLY php to store and retrieve data
  • Class tpl - If you want to output, then you need to look at this one!

Other Classes

  • Class auth - An extension to the tdb class, this provides us with all the authorization functions
  • Class input - Some static functions to handle and clean user data before you (the programmer) uses it
  • Class fcn - Some miscelaneous functions used throughout UPB, these are also accessed statically