How to include a HTML file in a PHP-Nuke module.

From what we have said about the structure of a PHP-Nuke module (see Section 21.1), it is easy to include a HTML file in a module – all we have to do is use the PHP include command, to include it between the calls to OpenTable() and CloseTable() functions:

Create a folder under the modules directory. Call it whatever you like, but take care to replace blanks with underscores in the name.

Using a decent text editor (see Chapter 11), create a text file called index.php in that newly created directory.

Copy the following code in index.php:

/********************************/
/* PHP-NUKE: Web Portal System */
/* =================  */
/*  */
/* PHP-Nuke-HOWTO module for PHP-Nuke */
/*  */
/* Copyright (c) 2003 index.php  */
/* by Chris   */
/* www. karakas-online. */
/* */
/* See licence.html for the Licence of the other files */
/* distributed together with this index.php file.  */
/*  */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.  */
/***********************************/
if (!eregi(“modules.php”, $PHP_SELF)) {
  die (“You can’t access this file directly…”);
}
$index = 0;   // 0 : do not show right blocks – 1:show right blocks
require_once(“mainfile.php”);
$module_name = basename(dirname(__FILE__));
include(“header.php”);
OpenTable();
include(“path/to/the/html/file”); // <– CHANGE THIS!
CloseTable();
include(“footer.php”);
?>

Change the licence to reflect your decisions. Of course, I urge you to use the GNU General Public License whenever possible, to help the cause of free software – PHP-Nuke is itself set under the GPL, after all, so why would you want a different licence for your module?.

Then just enter the right path to the HTML file you want to include, replacing the “path/to/the/html/file” string. This can be either a full filesystem path, or a relative one – relative to the PHP-Nuke root directory, which is always the same directory where config.php is located. But it may also very well be a URL to a HTML file of another site. Examples:

include(“/usr/local/httpd/htdocs/myfile.html”); // absolute filesystem path
include(“modules/PHP-Nuke_HOWTO/cookies.html”); // relative filesstem path
include(“http://www.wiivil.com/ filexx.html”); // full URL

Finally, activate the module from the modules administration (see Section 9.3).

 Javascript in modules
  There is nothing that prevents you from including a file that contains Javascript code in a module. As long as the Javascript functions defined in the included file are not also present in the includes/javascript.php file (see Section 21.9.1), and the HTML page created with the Javascript does not break the table layout of your theme, there should be no problem. In this way you could create a PHP-Nuke Guestbook module, for example, if you already had the Javascript code for a guestbook (see Javascript in themes).
 

If you want to include two files in the module, so that they appear side-by-side, rather than one after the other, you can use the usual HTML table trick to show the files in two separate cells of the same table row (see Using “include” for HTML pages):

OpenTable();
echo “

CloseTable();

An alternative way to include a HTML file in the module, is to terminate PHP interpretation of the file with a closing ?>, include the HTML code verbatim and then reopen the PHP context with a new

if (!eregi(“modules.php”, $PHP_SELF)) {
die (“You can’t access this file directly…”);
}
$index = 0;   // 0 : do not show right blocks – 1:show right blocks
require_once(“mainfile.php”);
$module_name = basename(dirname(__FILE__));
include(“header.php”);
OpenTable();
?>
PUT YOUR HTML CODE HERE, WHATEVER COMES BETWEEN THE AND
TAGS OF YOUR HTML FILE
CloseTable();
include(“footer.php”);
?>

Note that we have inserted a closing ?> after the call to OpenTable() and an opening

”;
include (“page.html”);
echo “
”;
include (“page2.html”);
echo “