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 /************************************************************************/ /* PHP-NUKE: Web Portal System */ /* =========================== */ /* */ /* PHP-Nuke-HOWTO module for <application>PHP-Nuke</application> */ /* */ /* Copyright (c) 2003 index.php */ /* by Chris Karakas */ /* http://www.karakas-online.de */ /* */ /* 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 <acronym>GNU</acronym> 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.yoursite.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 "<table><tr><td>"; include ("page.html"); echo "</td><td>"; include ("page2.html"); echo "</td></tr></table"; 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 <?php line:
<?php 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 <html> AND </html> TAGS OF YOUR HTML FILE <?php CloseTable(); include("footer.php"); ?> |
Note that we have inserted a closing ?> after the call to OpenTable() and an opening <?php before the call to CloseTable(). Whatever comes in between, should be plain HTML code, not PHP. This method is suitable for small HTML texts, for larger texts the include method is recommended.