Single file modules are useful in case case no additional files have to be distributed with your module. Because the module consists of only one single file, it is very easy to distribute. Beware though that the moment that you want to support for example a settings screen, multiple languages or custom images, you will have to switch to the multiple file module structure. Switching does mean some extra work for your users. So only use this format for modules for which you are sure that you do not need additional files in the future.
Single file modules consist of one single PHP file. The name
of this file is not restricted. We advice you to use
mod_<module name>.php
though
for clarity and consitency with other module
(e.g. mod_foo.php
).
This file contains both the module information and the hook
function definitions. For storing the module informaton, a
special PHP comment is used. This comment must look like the
following:
/* phorum module info <module information lines go here> */
Using the example module info from Example 2.1, “Module information”, the complete single file module would look like this (see XXX why we use the check on PHORUM at the start of this file):
Example 2.2. Single file module
{phorum dir}/mods/mod_foo.php
<?php
if(!defined("PHORUM")) return;
/* phorum module info
title: Foo
desc: This is the Foo module for Phorum. Nothing exciting...
version: 1.0.2
release_date: Jan 1st, 2008
url: http://www.phorum.org
author: John Doe <johndoe@example.com>
require_version: 5.2.2
category: user_features
hook: some_hook|phorum_mod_foo_some_hook
hook: some_other_hook|phorum_mod_foo_some_other_hook
hook: yet_another_hook|phorum_mod_foo_some_other_hook
priority: run some_hook before some_other_module
*/
function phorum_mod_foo_some_hook ($data) {
// Do stuff for "some_hook".
return $data;
}
function phorum_mod_foo_some_other_hook ($data) {
// Do stuff for "some_other_hook" and "yet_another_hook".
return $data;
}
?>
Installation of a single file module is done by putting the PHP
file (e.g. mod_foo.php
) directly in the
directory {phorum dir}/mods/
and activating
the module from the "Modules" screen in your admin interface.