Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.

Creating a Module

Jon Stockton edited this page Jun 30, 2014 · 26 revisions

I. Zip Folder Hierarchy and Naming Convention)

 moduleName.zip
     includes
        - moduleName.mod.php
        - moduleName_component.mod.php
     templates
        - moduleName.template
        - moduleName_component.template
        - moduleName_component_CONSTANT.template

II. Definition

Code

class moduleName extends SimpleModule {/*code*/}

Rules

moduleName must be the same as the filename: (ex. class testModule in testModule.mod.php)

III. Required Functions

isInstalled()

Arguments

Array $configs - The configuration array from config.inc.php (optional)

Return

Should return TRUE if the module has all the required pieces, FALSE otherwise.

install()

Arguments

Array $configs - The configuration array from config.inc.php (optional)

Return

Should attempt to install missing pieces and return TRUE on success, FALSE otherwise.

uninstall()

Arguments

Array $configs -The configuration array from config.inc.php (optional)

Return

Should attempt to uninstall extra module pieces (templates, database tables,
etc. - not code) and return TRUE on success, FALSE otherwise.

IV. Optional Functions

sideparse()

Arguments

String $content - The current template (prior to being parsed)
Array $configs - The configuration array from config.inc.php (optional)

Return

Should return the parsed version of $content (creating/overriding any constants)

choosePage()

Arguments

Array $configs - The configuration array from config.inc.php (optional)

Return

Should return the name of the template to be used ("" for default)

getContent()

Arguments

Array $configs - The configuration array from config.inc.php (optional)

Return

Should return whatever {CONTENT} should be replaced with.

V. Useful Functions

SimpleDisplay::bbencode()

SimpleDisplay::readTemplate()

SimpleUtils::checkReqFiles()

SimpleUtils::installReqFiles()

SimpleUtils::checkReqTbls()

SimpleUtils::installReqTbls()

SimpleUtils::simpleFilter()

VI. Sample Module

<?php
if(SIMPLESITE!=1)
    die("Can't access this file directly.");
class testModule extends SimpleDisplay implements simpleModule
{
    public static $info=array(  "author"  => "Jon Stockton",
                                "name"    => "Test Module",
                                "version" => "1.0",
                                "date"    => "April 9, 2012"
                            );
				  
    public function choosePage()
    {
        return "";
    }
    public function sideparse($content)
    {
        return str_replace("{TEST}","Hello World!",$content);
    }
    public function isInstalled($configs=array())
    {
        return $this->checkReqFiles(
                                    array(
                                     $_SERVER['DOCUMENT_ROOT'].$configs['path']['root'].$configs['path']['mod_templates']."/testModule.template"
                                    ),
                                    $configs
                                   );
    }
    public function install($configs=array())
    {
        $this->installReqFiles(array("testModule.template" => "e1RFU1R9"),$configs);
        return TRUE;
    }
    public function getContent($configs=array())`
    {
        return $this->readTemplate($_SERVER['DOCUMENT_ROOT'].$configs["path"]["root"].$configs["path"]["mod_templates"]."/testModule.template","testModule");
    }
}
?>