MDPro API Command Reference

This document is in alpha state, and as such the description of the API is likely to change. Do not use the functions outlined in this document for development work.

12nd May 2002


Note: Through at least MDPro 1.07, MDP uses the PostNuke API and some references to PN have thus been left intact.


Table of Contents

1. Overview
1.1. What is the PostNuke API?
1.2. Advantages of an API
1.3. Disadvantages of an API
1.4. Who should use this API?
1.5. Status of the API
1.6. This Document
1.7. Related Documents
1.8. Suggestions and Updates
2. API Breakdown
2.1. Users
2.2. Modules
2.3. Security
2.4. Sessions
2.5. Variables
2.6. Output
2.7. Database
2.8. Miscellaneous
3. Notes on Programming with the API
3.1. Use of void
4. API Reference

The PostNuke API is a work-in-progress. There will be many functions that are missing from the API that developers would like. To this end, if a developer has a request for a particular function then they can submit it to the MDPro features request list on SourceForge at the PostNuke Homepage. The same system can be used for sending in updates of current functions or new functions. If you are a developer and currently either globals directly or accessing one of the core tables to obtain or update information then please consider sending in a feature request so that the MDPro team can develop an API to carry out the work instead. This will ensure that your code is more likely to continue working through future versions of MDPro without modification, and that

Please note that the main requirements for the core PostNuke API are stability and a relatively small footprint. Due to this it is possible that your request for a new or updated function will get refused on the grounds that it is too specific or can easily be built from other core API functions. In such situations the MDPro team will always try to provide a simple alternative, but please remember that submission of a new or updated part of the API does not guarantee inclusion.

The PostNuke API is broken down in to a number of different areas. These areas are as follows:

Throughout the API reference, use is made of a type void, especially for specific return values. PHP does not in itself have a type of void, it is used in this document to refer to an unset value. It's very important for you to understand this difference since the the void parameter is heavily used by the exception handling system on which PostNuke API functions are based.

For example, pnModAPIFunc() takes parameters of a module name, type, and function, works out which actual module function to call; it then calls the module function and passes back the return value as its own return value. The problem with this is that if pnModAPIFunc() returned false for a failure to find the specified function then to the developer this would be indistinguishable from the function being found and itself returning false. void return values can be checked with the PHP isset() function, as shown below:

$articles = pnModAPIFunc('News', 'user', 'getarticles');
if (!isset($articles) && pnExceptionMajor() != PN_NO_EXCEPTION) {
  // pnModAPIFunc() failed
  return; // throw back exception
}
if ($articles == false)
  // getarticles failed
} else {
  // getarticles succeeded, data in $articles
}
         

Throughout the PostNuke API reference the return values of void and false are distinct. false is returned when an API call functioned correctly but returns a negative response. void is returned when an API call has internal problems and raises an exception. Note that this is a general rule, and there are a few exceptions out of necessity. These exceptions are noted in the reference documentation for the relevant function.

Table of Contents

pnBlockGetInfo - get block information
pnBlockLoad - load a block
pnBlockShow - set configuration variable
pnConfigGetVar - get configuration variable
pnConfigSetVar - set configuration variable
pnConfigDelVar - delete a configuration variable
pnDBGetConn - get database connection
pnDBGetTables - get database tables
pnDBInit - initialize MDPro database connection
pnExceptionFree - reset exception status
pnExceptionId - return current exception identifier
pnExceptionMajor - return current exception major number
pnExceptionSet - raise an exception
pnExceptionValue - return current exception value
pnGetBaseURI - get base URI for MDPro
pnGetBaseURL - obtain base URL for this site
pnGetStatusMsg - obtain status message
pnInit - initialize MDPro
pnModAPIFunc - execute a module API function
pnModAPILoad - load a module API
pnModAvailable - check if a module is available
pnModCallHooks - carry out hook operations for module
pnModDBInfoLoad - load database info for a module
pnModDelVar - delete a module variable
pnModFunc - execute a module function
pnModGetAdminMods - get list of administration modules
pnModGetIDFromName - get module id from name
pnModGetInfo - get module info
pnModGetName - get name of current top-level module
pnModGetUserMods - get list of user modules
pnModGetVar - get module variable
pnModLoad - load module
pnModRegisterHook - register a hook function
pnModSetVar - set module variable
pnModUnregisterHook - unregister a hook function
pnModURL - create module URL
pnRedirect - redirect to another page
pnSecAddSchema - add security schema
pnSecAuthAction - authorize attempted action
pnSessionDelVar - delete session variable
pnSessionGetVar - get session variable
pnSessionInit - initialize session
pnSessionSetup - setup session
pnSessionSetVar - set session variable
pnThemeLoad - load display theme
pnUserGetAll - get basic information on all users
pnUserGetLang - get current language
pnUserGetTheme - get current theme
pnUserGetVar - get user variable
pnUserGetVars - get all user variables
pnUserLoggedIn - check if user is logged in
pnUserLogIn - log user in
pnUserLogOut - log user out
pnUserSetVar - set user variable
pnUserValidateVar - validate user variable
pnVarCensor - remove banned words from variable
pnVarCleanFromInput - obtain form variable
pnVarPrepForDisplay - prepare variable for display
pnVarPrepForOS - prepare variable for operating system
pnVarPrepForStore - prepare variable for database storage
pnVarPrepHTMLDisplay - prepare variable for display, preserving some HTML tags
pnVarValidate - validate a variable

The following pages have a complete PostNuke API reference. Any functions that are not listed in this section are to be considered internal and should not be used by developers.

Name

pnBlockGetInfo — get block information

Synopsis

array pnBlockGetInfo(bid);
int bid ;

            BAD_PARAM
            DATABASE_ERROR
            ID_NOT_EXIST
          

Description

pnBlockGetInfo() returns an array of Block information.

Parameters

bid

The id of this block in the MDPro system.

Return Values

This function returns an array of block information or void if an exception was raised.

Exceptions

This function raises BAD_PARAM if you pass an invalid parameter. This function raises DATABASE_ERROR if an error occurs while querying data. This function raises ID_NOT_EXIST if the block is unknown.

Notes

The block information array contains the following items:

bkey

title

The display title of the block

content

The container for block content. Serialized using pnBlockVarsFromContent() and pnBlockVarsToContent().

url

The url for blocks that depend on URLs, like a rss headlines block.

position

The position of the block, currently one of 'l' (left), 'r' (right), 'm' (middle). This is likely to change in later versions to make placement more flexible.

weight

The weight of the block, used for vertical placement of blocks.

active

The status of a block, '1' for active, '0' for inactive.

refresh

Indicates if a block should be refreshed. Examples would be headline blocks that fetch external content regularly.

last_update

The date and time of the last refresh of the block.

language

The language of the block.

mid

The ID of the module a block belongs to. '0' indicates a block belonging to the core.

Examples

// Get information on block
$blockinfo = pnBlockGetInfo($bid);
        

Name

pnBlockLoad — load a block

Synopsis

bool pnBlockLoad(modname, block);
string modname, string block ;

            BAD_PARAM
            DATABASE_ERROR
            ID_NOT_EXIST
            MODULE_FILE_NOT_EXIST
          

Description

pnBlockLoad() loads a block into the MDPro system.

Parameters

modname

The well-known name of a module to load the block from. This parameter can be left empty, or set to 'Core' to load core blocks.

block

The name of the block to load

Return Values

This function returns true if the module loaded successfully, and void if an exception was raised.

Exceptions

This function raises BAD_PARAM if you pass an invalid parameter. This function raises DATABASE_ERROR if an error occurs while querying data. This function raises ID_NOT_EXIST if the block is unknown. This function raises MODULE_FILE_NOT_EXIST if the block file doesn't exist.

Notes

The PostNuke API keeps track of what blocks have been loaded, so multiple calls to pnBlockLoad() with the same parameters will return true each time.

For more information on well-known names of modules please refer to the documentation for pnModGetVar()

This function does not display the block automatically, this must be carried out by a separate call to pnBlockShow().

Examples

  // Load the past article block from the News module
  if (!pnBlockLoad('News', 'past')) {
    die('Could not load past articles block');
  }
        

See Also

pnBlockShow()


Name

pnBlockShow — set configuration variable

Synopsis

string pnBlockShow(modname, block, blockinfo);
string modname, , string block, , array blockinfo ;

            BAD_PARAM
            DATABASE_ERROR
            ID_NOT_EXIST
            MODULE_FILE_NOT_EXIST
          

Description

pnBlockShow() gets the output of a block by calling its 'block_display' function.

Parameters

modname

The well-known name of a module to display the block from. This parameter can be left empty, or set to 'Core' to display core blocks.

block

The name of the block to load

blockinfo

An associative array of parameters to pass to the block display function. The exact number and type of parameter is block-dependent.

Return Values

This function returns the output of the block display function is if it succeeds, or void if an exception was raised.

Exceptions

This function raises BAD_PARAM if you pass an invalid parameter. This function raises DATABASE_ERROR if an error occurs while querying data. This function raises ID_NOT_EXIST if the block is unknown. This function raises MODULE_FILE_NOT_EXIST if the block file doesn't exist.

Notes

TODO: nail down the block standards. Note that the MDPro block standards state that blocks called in this way have to return output themselves. Especially, they need to implement the '{$modname}_{$block}block_display' function.

Examples

TODO
        

See Also

pnBlockLoad()


Name

pnConfigGetVar — get configuration variable

Synopsis

mixed pnConfigGetVar(name);
string name ;

            BAD_PARAM
            DATABASE_ERROR
          

Description

pnConfigGetVar() obtains a configuration variable from the MDPro system.

Parameters

name

The name of the configuration variable to obtain

Return Values

This function returns the requested variable if the variable exists. If the variable does not exist then this function will return void. This function also returns void if an exception was raised.

Exceptions

This function raises BAD_PARAM if you pass an invalid parameter. This function raises DATABASE_ERROR if an error occurs while querying data.

Notes

The configuration variables available with this release of the API are as follows:

debug

Level of debugging required. 0 is no debugging, 1 is normal debugging.

Version_Num

Version of this MDPro system

Version_ID

ID of this MDPro system; currently always 'MDPro'

Version_Sub

Sub-ID of this MDPro system

startpage

Name of initial module for this MDPro system to load

adminmail

Email address of site administrator

sitename

Name of this MDPro system

description (formerly slogan)

Description of this MDPro system

timezone_offset

Timezone offset of this MDPro system, in hours from GMT-12

seclevel

Security level of this site; one of 'high', 'medium', or 'low'

banners

Flag to state whether advertising banners are shown; '0' for no or '1' for yes

language

Code of default language for this MDPro system

locale

Locale for this MDPro system

BanMode

Flag to state whether banned is active; '0' for no or '1' for yes

BannedList

Array of words that are banned by this MDPro system

Other variables will be made available in future releases of the API.

Examples

// Get locale for this site
$locale = pnConfigGetVar('locale');
        

See Also

pnConfigSetVar()


Name

pnConfigSetVar — set configuration variable

Synopsis

bool pnConfigSetVar(name, value);
string name, , string value ;

            BAD_PARAM
            DATABASE_ERROR
          

Description

pnConfigSetVar() sets a configuration variable on the MDPro system.

Parameters

name

The name of the configuration variable to set

value

The value to set the configuration variable to

Return Values

This function currently returns false due to not being implemented.

Exceptions

This function raises BAD_PARAM if you pass an invalid parameter. This function raises DATABASE_ERROR if an error occurs while querying data.

Notes

This function is not currently implemented.

Examples

// Set locale for this site
if (!pnConfigSetVar('locale', 'en_GB')) {
    die('Error setting configuration variable');
}
        

See Also

pnConfigGetVar()


Name

pnConfigDelVar — delete a configuration variable

Synopsis

bool pnConfigDelVar(name);
string name ;

            BAD_PARAM
            DATABASE_ERROR
          

Description

pnConfigDelVar() deletes a configuration variable from the MDPro system.

Parameters

name

The name of the configuration variable to delete

Return Values

This function currently returns false due to not being implemented.

Exceptions

This function raises BAD_PARAM if you pass an invalid parameter. This function raises DATABASE_ERROR if an error occurs while querying data.

Notes

This function is not currently implemented.

Examples

// Remove locale setting
if (!pnConfigDelVar('locale')) {
  die('Error deleting configuration variable');
}
        

See Also

pnConfigGetVar(), pnConfigSetVar()


Name

pnDBGetConn — get database connection

Synopsis

array pnDBGetConn();

Description

pnDBGetConn() obtains database connection handles for direct querying of the MDPro database.

Return Values

This function returns an array of database connection values. At current the only active value is the first one, which should be used for all database interaction.

Notes

Future versions of the PostNuke API might supply extra connection information through this function, to allow for features such as replicated or failover databases.

Examples

// Get database connection
list($dbconn) = pnDBGetConn();
        

See Also

pnDBGetTables()


Name

pnDBGetTables — get database tables

Synopsis

array pnDBGetTables();

Description

pnDBGetTables() obtains database table information for direct querying of the MDPro database.

Return Values

This function returns an array of database table information.

Notes

At current this information is only sparsely documented; more documentation on this array and direct database access for developers is expected soon.

Examples

// Get database tables
$pntable = pnDBGetTables();
        

See Also

pnDBGetConn()


Name

pnDBInit — initialise MDPro database connection

Synopsis

bool pnDBInit();

Description

pnDBInit() initialises connections to the MDPro database.

Return Values

This function returns true if the connections were successfully made, or false if the connections were not successfully made.

Notes

pnDBInit() is normally called from within pnInit(), and as such should not be called by developers.

See Also

pnInit()


Name

pnExceptionFree — reset exception status

Synopsis

void pnExceptionFree();

Description

pnExceptionFree() makes a reset of current exception status.

Return Values

This function does not return a value.

Notes

You must always call pnExceptionFree() when you handle a caught exception or equivalently you don't throw the exception back to the callers chain.

See Also

pnExceptionId() pnExceptionMajor() pnExceptionSet() pnExceptionValue()


Name

pnExceptionId — return current exception identifier

Synopsis

string pnExceptionId();

Description

pnExceptionId() returns the string identifying the exception. The character string contains the ID for the exception (its PHP class name).

Return Values

This function returns the current exception identifier. If invoked when no exception was raised a void value is returned.

See Also

pnExceptionFree() pnExceptionMajor() pnExceptionSet() pnExceptionValue()


Name

pnExceptionMajor — return current exception major number

Synopsis

int pnExceptionMajor();

Description

pnExceptionMajor() allows the caller to establish whether an exception was raised, and to get the type of raised exception. The major PN_NO_EXCEPTION identifies the state in which no exception was raised.

Return Values

This function returns one of these values: PN_NO_EXCEPTION, PN_USER_EXCEPTION or PN_SYSTEM_EXCEPTION.

See Also

pnExceptionFree() pnExceptionId() pnExceptionSet() pnExceptionValue()


Name

pnExceptionSet — raise an exception

Synopsis

void pnExceptionSet();

Description

pnExceptionSet() allows a function to raise an exception. The caller must supply a value for the major parameter. The major parameter can have one of the values PN_NO_EXCEPTION, PN_USER_EXCEPTION, or PN_SYSTEM_EXCEPTION. The value of the major parameter constrains the other parameters in the call as follows:

* If the major parameter has the value PN_NO_EXCEPTION, this is a normal outcome to the operation. In this case, both exception_id and param must be NULL. Note that it is not necessary to invoke pnExceptionSet() to indicate a normal outcome; it is the default behavior if the method simply returns.

* For any other value of major it specifies either a user-defined or system exception. The exception_id parameter is the identifier representing the exception type. If the exception is declared to have members, the param parameter must be the exception struct (PHP class) containing the members. If the exception has no members, param must be NULL.

Return Values

This function does not return a value.

See Also

pnExceptionFree() pnExceptionId() pnExceptionMajor() pnExceptionValue()


Name

pnExceptionValue — return current exception value

Synopsis

void pnExceptionValue();

Description

pnExceptionValue() returns an object corresponding to this exception.

Return Values

This function returns the object that was passed as parameter to pnExceptionSet(). If invoked when no exception or an exception for which there is no associated information was raised, a void value is returned.

See Also

pnExceptionFree() pnExceptionId() pnExceptionMajor() pnExceptionSet()


Name

pnGetBaseURI — get base URI for MDPro

Synopsis

string pnGetBaseURI();
;

Description

pnGetBaseURI() returns the base URI of MDPro.

Return Values

This function returns the base URI of MDPro.

Notes

URI is the path part of an URL, for instance in the URL 'http://www.maxdev.com/stuff/index.php' the URI would be '/stuff/index.php'.

Examples

// get base URI
$path = pnGetBaseURI();

        

See Also

pnGetBaseURL()


Name

pnGetBaseURL — obtain base URL for this site

Synopsis

string pnGetBaseURL();

Description

pnGetBaseURL() obtains the base URL for the site. The base url is defined as the full URL for the site minus any file information i.e. everything before the 'index.php' from your start page.

Return Values

This function returns the base URL of the site.

Notes

The last character in the string returned by pnGetBaseURL() is always '/'

pnGetBaseURL() replaces the old nukeurl global variable.


Name

pnGetStatusMsg — obtain status message

Synopsis

string pnGetStatusMsg();

Description

pnGetStatusMsg() obtains the last status message posted for this session. The status message exists in one of two session variables: 'statusmsg' for a status message, or 'errormsg' for an error message. If both a status and an error message exists then the error message is returned.

Return Values

This function returns the value of the last status message posted, or void if no status message exists.

Notes

pnGetStatusMsg() is a destructive function - it deletes the two session variables 'statusmsg' and 'erorrmsg' during its operation.

See Also

pnSessionSetVar()


Name

pnInit — initialise MDPro

Synopsis

void pnInit();

Description

pnInit() initialises the MDPro system. It loads the required includes, sets up sessions and database connections, and obtains the system configuration.

Return Values

pnInit() does not return a value; if the function fails somewhere it will exit.

Notes

In future pnInit() might give a return value, to make it easier to optionally include MDPro functionality in third-party scripts.


Name

pnModAPIFunc — execute a module API function

Synopsis

mixed pnModFunc(modname, type, func, args);
string modname, , string type, , string func, , array args ;

            BAD_PARAM
            MODULE_FUNCTION_NOT_EXIST
          

Description

pnModFunc() calls a specific module API function.

Parameters

modname

The well-known name of a module to execute a function from

type

The type of function to execute; currently one of 'user' or 'admin'

func

The name of the module API function to execute

args

An associative array of arguments to pass to the module API function. The exact number and type of arguments is function-dependent.

Return Values

This function returns whatever the return value of the resultant function is if it succeeds. This function returns void if an exception was raised.

Exceptions

This function raises BAD_PARAM if you pass an invalid parameter. This function raises MODULE_FUNCTION_NOT_EXIST if the module function doesn't exist. This function throw back exceptions raised by module function.

Notes

Before calling this function you MUST load the module API with pnModAPILoad.

For more information on well-known names of modules please refer to the documentation for pnModGetVar()

Examples

// Call News module user function getarticles with argument 'id' set to 3
$articles = pnModAPIFunc('News',
                         'user',
                         'getarticles',
                         array('id' => 3));
if (!isset($articles)) {
  // pnModAPIFunc() failed
} elseif ($articles == false)
  // getarticles failed
} else {
  // getarticles succeeded, data in $articles
}

// Call Permissions admin function list with no arguments
$list = pnModAPIFunc('Permissions',
                     'admin',
                     'list');
if (!isset($list)) {
  // pnModAPIFunc() failed
} elseif ($list == false)
  // list failed
} else {
  // list succeeded, data in $list
}

        

See Also

pnModGetVar(), pnModAPILoad(), pnModFunc()


Name

pnModAPILoad — load a module API

Synopsis

int pnModAPILoad(modname, type);
string modname, , string type ;

            BAD_PARAM
            DATABASE_ERROR
            MODULE_FILE_NOT_EXIST
            MODULE_NOT_EXIST
          

Description

pnModAPILoad() loads extra functions into the MDPro system to extend its abilities.

Parameters

modname

The well-known name of a module to load

type

The type of module functions to load; currently one of 'user' or 'admin'.

Return Values

This function returns true if the module loaded successfully. This function returns void if an exception was raised.

Exceptions

This function raises BAD_PARAM if you pass an invalid parameter. This function raises DATABASE_ERROR if an error occurs while querying data. This function raises MODULE_FILE_NOT_EXIST if a module file doesn't exist. This function raises MODULE_NOT_EXIST if the module doesn't exist.

Notes

The PostNuke API keeps track of what modules have been loaded, so multiple calls to pnModAPILoad() with the same parameters will return true each time.

This function does not load in the relevant display functionality for this module automatically, this must be carried out by a separate call to pnModLoad().

For more information on well-known names of modules please refer to the documentation for pnModGetVar()

Examples

// See if News module is available
if (pnModAvailable('News')) {
  // Load the user API for the News module
  if (!pnModAPILoad('News', 'user')) {
    die('Could not load News module API');
  }
}
        

See Also

pnModLoad(), pnModGetVar()


Name

pnModAvailable — check if a module is available

Synopsis

bool pnModAvailable(modname);
string modname ;

            BAD_PARAM
            DATABASE_ERROR
          

Description

pnModAvailable() confirms whether a module is available to be used within the MDPro system.

Parameters

modname

The well-known name of a module to check

Return Values

This function returns true if the module is available for use, false if the module is not available for use. This function returns void if an exception was raised.

Exceptions

This function raises BAD_PARAM if you pass an invalid parameter. This function raises DATABASE_ERROR if an error occurs while querying data.

Notes

A module that is loaded into the MDPro system but which is inactive or uninitialized is defined as not available for use.

For more information on well-known names of modules please refer to the documentation for pnModGetVar()

Examples

// See if News module is available
if (pnModAvailable('News')) {
  // Load the News module
  if (!pnModAPILoad('News', 'user')) {
    die('Could not load News module API');
  }
}