WB Module Files

Website Baker modules consists of text files such as PHP, HTML, Javascript and CSS. This chapter provides a brief introduction of the different module files and its purpose depending on the different module types. This is the basic knowledge required for the creation of own modules.

Essential files (all module types)

There are two files which are required (or recommended) for all modules:

  • info.php: contains information about module directory, module type, author, description, license
  • index.php: prevents the listing of files contained in the module

File info.php (essential): 

<?php
/**
  Copyright (C) 2007, Christian Sommer

  This module is free software. You can redistribute it and/or modify it under
the terms of the GNU General Public License - version 2 or later, as published
by the Free Software Foundation: http://www.gnu.org/licenses/gpl.html.

  This module is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

 -------------------------------------------------------------------------------
  Modul: XXX für Website Baker v2.6.x (http://www.websitebaker.org)
  Short module description here
 -------------------------------------------------------------------------------
   v0.10  (Christian Sommer; 11.06.2007)
    + initial release of the module
 -------------------------------------------------------------------------------
**/

$module_directory     = 'module directory';
$module_name          = 'module name (shown as new page type)';
$module_function      = 'page, tool or snippet';
$module_version       = '0.10';
$module_platform      = '2.6.x';
$module_author        = 'Christian Sommer';
$module_license       = 'GNU General Public License';
$module_description   = 'short description of the modules purpose';
?>

The opening PHP tag (<?php) is followed by a multiline comments block (/** ... **/) which provides optional information about the choosen module license, a disclaimer and the module development history.

The module variables provides the required information for Website Baker. The variable $module_function defines whether the module is a page type module (page), a administration tool (tool) or a code snippet (snippet). The info.php file ends with the closing PHP Tag (?>).

File index.php (recommended): 

The index.php file prevents the listing of files and folder contained in the module directory independent of your server settings. This is a simple measure to enhance security as no additional information about the module architecture will be displayed. 

<?php
header('Location: ../index.php');
?>

Optional files (all module types)

The following files are optional and can be used to execute code during installation and uninstallation process. This files are automaticall invoked from the Website Baker backend: Add-Ons -> Module -> Install Module / Uninstall Module.

  • install.php: invoked if the module does not already exists. Useful to add database tables or to copy required module files
  • upgrade.php: invoked if the module already exists. Useful to add a database field to an existing database or to exchange module files...
  • uninstall.php: invoked during uninstallation process. Should be used to delete module databases created during installation process.

The content of those files depends from the modules purpose. A working example can be found with the Hello World Module from the Add-Ons Repository.

Module files: page type modules

A page type module requires to set the variable in the info.php as follows:

$module_function = page;

Page type modules can contain the following files:

  • view.php: defines the content displayed when the page is viewed in the frontend
  • modify.php: invoked when viewed in the backend via: Pages -> click on page title. This file contains the backend functions and settings useable in the backend.
  • add.php: invoked when a new page/section of the module type is added via the WB backend. Useful to e.g. add/updated database entries.
  • delete.php: invoked if a module/section of this module type is deleted via the WB backend. Useful to delete database entries for this page/section.

The content of those files depends from the modules purpose. A working example can be found with the Hello World Module from the Add-Ons Repository.

Module files: Administration tools

A administration tool requires to set the variable in the info.php as follows:

$module_function = tool;

Administration tools contain the following file: 

  • tool.php: invoked when clicking on the module link in the WB backend: Settings -> Show Advanced Options -> Administration Tools

Module files: Code Snippets

A code snippet requires to set the variable in the info.php as follows:

$module_function = snippet;

All functions contained in the following file can be invoked from the index.php file of your template or from a page/section of type code:

  • include.php: Automatically included by WB for front- and backend. Functions contained in this file can be executed from a page/section of type code or from the index.php file of your template.