WebsiteBaker 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) 2018, Your name 
 
  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.
 
 -------------------------------------------------------------------------------
 Module: XXX for WebsiteBaker v2.10.x (https://www.websitebaker.org)
 Module description
 -------------------------------------------------------------------------------
   v0.10  (Your name; 11.06.2018)
    + initial release of the module
 -------------------------------------------------------------------------------
**/
 
/* -------------------------------------------------------- */
// Must include code to stop this file being accessed directly
if (!defined('SYSTEM_RUN')) { header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); flush(); exit; }
/* -------------------------------------------------------- */
 
$module_directory     = 'specify desired module directory';
$module_name          = 'Specify module name (displayed as page type)';
$module_function      = 'page, tool or snippet';
$module_version       = '0.10';
$module_platform      = '2.10.x';
$module_author        = 'Your name';
$module_license       = 'GNU General Public License';
$module_description   = 'Short description of the Module';
 

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 WebsiteBaker. The variable $module_function defines whether the module is a page type module (page), a administration tool (tool) or a code snippet (snippet). The closing PHP Tag (?>) is not needed.

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 WebsiteBaker 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.