PHP-Nuke Garage
|
Suppose you want a module on your site that just displays some static HTML text. Maybe it's a Contact Us page, but you don't want to put the page up as part of the Content module. Instead, you want users to be able to access something like www.mysite.com/modules.php?name=ContactUs and get the appropriate page. This is a useful way to post content that always needs to be on your site, such as an About Us page or a Privacy Policy page, especially when that content doesn't change very often. No problem. You just need to make your own module. PHP-Nuke actually comes with a module named Addon_Sample, which you can access on your own. Figure 35.1 shows the module's default content, which isn't that fancy. Actually, the add-on does a lot more than just display static HTML, but it's a good start for making a module that just does that. Figure 35.1. The Addon_Sample module's default content.
Start by browsing to the modules/Addon_Sample folder on your Web site. Notice that it contains three files: Copyright.php,F2.php , and Index.php. Ignore the first two and let's concentrate on Index.php. Open that file in Windows Notepad (or, if you have a PHP script editor, use that; I use an editor named PrimalScript, which you can obtain at www.primalscript.com). Scroll to the bottom of the file, where you'll find something like this: switch($func) { default: AddonSample(); break; case "one": one(); break; case "two": two(); break; } This is present in every PHP-Nuke module. It's setting up the possible conditions for the module: Going to modules.php?name=Addon_Sample&op=one executes a function named one(); going to just modules.php?name=Addon_Sample, with no op in the URL, executes a function named AddonSample(). For our purposes, we just want that default action in the AddonSample() function to display some static text. So let's start editing. First, make a copy of the entire Addon_Sample folder, and name it ContactUs. Then edit the ContactUs/Index.php file so that the bottom of the file reads as follows: switch($func) { default: AddonSample(); break; } Locate the following code and delete it from Index.php: function one() { global $module_name; include("header.php"); OpenTable(); echo "Addon Sample File (index.php) function \"one\"<br><br>"; echo "<ul>"; echo "<li><a href=\"modules.php?name=$module_name&file=index\">Go to index.php</a>"; echo "</ul>"; CloseTable(); include("footer.php"); } function two() { global $module_name; include("header.php"); OpenTable(); echo "Addon Sample File (index.php) function \"two\""; echo "<ul>"; echo "<li><a href=\"modules.php?name=$module_name&file=index\">Go to index.php</a>"; echo "</ul>"; CloseTable(); include("footer.php"); }
That removes the two functions, one() and two(), that we're not going to be using. What you now have is more or less the bare minimum for a PHP-Nuke module: [View full width] <?php if (!eregi("modules.php", $_SERVER['PHP_SELF'])) { die ("You can't access this file directly..."); } $module_name = basename(dirname(__FILE__)); $index = 1; function AddonSample() { global $module_name; include("header.php"); OpenTable(); echo "Addon Sample File (index.php)<br><br>"; echo "<ul>"; echo "<li><a href=\"modules.php?name=$module_name&file=index&func=one
All that business in the middle, the AddonSample() part, is where your static Contact Us HTML needs to go. You want to leave everything up to and including the OpenTable(); line, and you need to leave the CloseTable(); line and everything that follows it. Those two lines are responsible for drawing the PHP-Nuke themed elements, and your HTML content goes in between them. Here's an example: function AddonSample() { global $module_name; include("header.php"); OpenTable(); echo "To contact us:<br>" ."<br>" ."E-mail contacts@daisyrecipestation.org, or <br>" ."Call 1-800-EAT-FOOD from 9am to 9pm Alaskan time."; CloseTable(); include("footer.php"); }
Notice how this goes together:
Delete the Copyright.php and F2.php files from the ContactUs folder. Make sure the remaining file is named index.php, with all lowercase letters. Copy the entire folder up to the modules folder of your Web site. Now when you go into the Modules item on your site's Administration menu, you'll see that a new module named ContactUs is available. You can activate it and make it available on your site. |
|