An Example Theme


As an example, check out this theme.php example. I'll throw in explanations along the way. The first part defines some global colors, using hexadecimal color codes. It also includes a file named tables.php, which contains the OpenTable() and CloseTable() functions. By the way, don't worry about lines that seem to wrap to the next line; PHP-Nuke is okay with that.

 <?php $bgcolor1 = "#FFFFFF"; $bgcolor2 = "#FFFFFF"; $bgcolor3 = "#FFFFFF"; $bgcolor4 = "#FFFFFF"; $textcolor1 = "#000000"; $textcolor2 = "#000000"; $nameoftheme = "Blue"; include("themes/Blue/tables.php"); 

Here's the themeheader() function. Notice that this includes a file named banners.php, which handles rotating ad banners on the site.

[View full width]

function themeheader() { global $admin, $user, $banners, $sitename, $slogan, $cookie, $prefix, $db, $nukeurl, $anonymous; if ($banners == 1) { include("banners.php");} cookiedecode($user); $username = $cookie[1]; if ($username == "") { $username = "Anonymous"; }

Here, the script begins defining and outputting the page's main HTML. Here you see the HTML <body> tag, which specifies things like the overall background color.

[View full width]

echo "<body background=\"themes/Blue/images/background.png\" bgcolor=\"#000000\" text= \"#FFFFCC\" leftmargin=\"10\" topmargin=\"10\" marginwidth=\"10\" marginheight=\"10\">"; if ($username == "Anonymous") { $theuser = "<a class=\"header\" href=\"modules.php?name=Your_Account&op=new_user \">Register</a>"; } else { $theuser = "$username"; } $datetime = "<script type=\"text/javascript\">\n\n" ."<!-- // Array ofmonth Names\n" ."var monthNames = new Array( \""._JANUARY."\",\""._FEBRUARY."\",\""._MARCH." \",\""._APRIL."\",\""._MAY."\",\""._JUNE."\",\""._JULY."\",\""._AUGUST."\",\""._SEPTEMBER." \",\""._OCTOBER."\", \""._NOVEMBER."\",\""._DECEMBER."\");\n" ."var now = new Date();\n" ."thisYear = now.getYear();\n" ."if(thisYear < 1900) {thisYear += 1900}; // corrections if Y2K display problem\n" ."document.write(monthNames[now.getMonth()] + \" \" + now.getDate() + \", \" + thisYear);\n" ."// -->\n\n" ."</script>";

In the following code, you can see that a file named header.html is being loaded. This theme actually uses static HTML files for most of the theme's elements, making it easier to work with those elements in an HTML editor like Microsoft FrontPage. header.html contains the initial HTML table, the site's logo, and so forth.

Notice that the function also calls the PHP-Nuke public_message() function, which displays the messages you've configured to display at the top of the page.

Then you'll see a call to block(left), which asks PHP-Nuke to provide the full content for the left column. Next, the file left_center.html is included. It contains only a couple of HTML tags: It closes the table cell that makes up the left column of blocks, and it creates the table that makes up the center module content.

                 $public_msg = public_message();     $tmpl_file = "themes/Blue/header.html";     $thefile = implode("", file($tmpl_file));     $thefile = addslashes($thefile);     $thefile = "\$r_file=\"".$thefile."\";";     eval($thefile);     print $r_file;     blocks(left);     $tmpl_file = "themes/Blue/left_center.html";     $thefile = implode("", file($tmpl_file));     $thefile = addslashes($thefile);     $thefile = "\$r_file=\"".$thefile."\";";     eval($thefile);     print $r_file; } 

The following is the function that draws the bottom of the page, themefooter(). Notice that this includes a file named center_right.html, which closes up the bottom of the module content and begins the table cell that holds the right column of blocks. Then the script asks PHP-Nuke to build the right blocks via a call to blocks(right), after which the footer of the pagecontained in footer.htmlis included.

 function themefooter() {     global $index, $foot1, $foot2, $foot3, $foot4, $copyright, $totaltime, $footer_message;     if ($index == 1) {     $tmpl_file = "themes/Blue/center_right.html";     $thefile = implode("", file($tmpl_file));     $thefile = addslashes($thefile);     $thefile = "\$r_file=\"".$thefile."\";";     eval($thefile);     print $r_file;     blocks(right);     }     $tmpl_file = "themes/Blue/footer.html";     $thefile = implode("", file($tmpl_file));     $thefile = addslashes($thefile);     $thefile = "\$r_file=\"".$thefile."\";";     eval($thefile);     print $r_file;                     echo "<center>\n";         $footer_message = footmsg();             echo "</center>\n";             echo "<br>\n"; } 

This function draws the news stories for the front page. You can see toward the end that it uses another HTML file, story_home.html, to provide the majority of the HTML formatting; this function is passedby PHP-Nukeall the information about the story (time, title, informant, and so forth); this function simply formats that information as desired.

[View full width]

function themeindex ($aid, $informant, $time, $title, $counter, $topic, $thetext, $notes, $morelink, $topicname, $topicimage, $topictext) { global $anonymous, $tipath; if ($notes != "") { $notes = "<br><br><b>"._NOTE."</b> <i>$notes</i>\n"; } else { $notes = ""; } if ("$aid" == "$informant") { $content = "$thetext$notes\n"; } else { if($informant != "") { $content = "<a href=\"modules .php?name=Your_Account&amp;op=userinfo&amp;username=$informant\"> $informant</a> "; } else { $content = "$anonymous "; } $content .= ""._WRITES." <i>\"$thetext\"</i>$notes\n"; } $posted = ""._POSTEDBY." "; $posted .= get_author($aid); $posted .= " "._ON." $time $timezone ($counter "._READS.")"; $tmpl_file = "themes/Blue/story_home.html"; $thefile = implode("", file($tmpl_file)); $thefile = addslashes($thefile); $thefile = "\$r_file=\"".$thefile."\";"; eval($thefile); print $r_file; }

Similar to the previous function, themearticle() accepts the story details in variables and then creates a formatted display. It uses an HTML file named story_page.html to contain most of the formatting, and then it simply adds in the story's details and text.

[View full width]

function themearticle ($aid, $informant, $datetime, $title, $thetext, $topic, $topicname, $topicimage, $topictext) { global $admin, $sid, $tipath; $posted = ""._POSTEDON." $datetime "._BY." "; $posted .= get_author($aid); if ($notes != "") { $notes = "<br><br><b>"._NOTE."</b> <i>$notes</i>\n"; } else { $notes = ""; } if ("$aid" == "$informant") { $content = "$thetext$notes\n"; } else { if($informant != "") { $content = "<a href=\"modules .php?name=Your_Account&amp;op=userinfo&amp;username=$informant\"> $informant</a> "; } else { $content = "$anonymous "; } $content .= ""._WRITES.":<br><br>$thetext<br>$notes\n"; } $tmpl_file = "themes/Blue/story_page.html"; $thefile = implode("", file($tmpl_file)); $thefile = addslashes($thefile); $thefile = "\$r_file=\"".$thefile."\";"; eval($thefile); print $r_file; }

This short function draws a single block. PHP-Nuke provides the block's title and content in variables; this script uses an HTML file named blocks.html to provide the formatting. This is the same technique used by the previous functions, but it might be easier to understand here since this is such a short function.

 function themesidebox($title, $content) {     $tmpl_file = "themes/Blue/blocks.html";     $thefile = implode("", file($tmpl_file));     $thefile = addslashes($thefile);     $thefile = "\$r_file=\"".$thefile."\";";     eval($thefile);     print $r_file; } ?> 

Here's the HTML contained in blocks.html. See how the HTML itself contains $content and $title? That's where the block's title and contents, as passed in by PHP-Nuke, are inserted. This technique allowed me to create this file in FrontPage and to just type $title and $content where I wanted those elements to appear. I can change the theme at any time by just changing blocks.html and the other static HTML files; they serve as templates and contain most of the theme's actual formatting.

 <!--- Begin block --> <table border="0" width="180"  cellspacing="0" cellpadding="0">     <tr>         <td valign="top" bgcolor="#4c71bd"  width="180">         $title</td>     </tr>     <tr>         <td valign="top" width="180" >$content</td>     </tr>     <tr>         <td valign="top" height="20" width="180">&nbsp;</td>     </tr> </table> <!-- End block --> 

Of course, not all themes work this way. In the next topic, I show you how to work a third-party theme into your site, and after that, I show you how to tweak a theme that you've acquired to meet your needs. Hopefully, this topic has given you some idea of how a theme is built, although I certainly don't expect you to start constructing one from scratch!



    PHP-Nuke Garage
    PHP-Nuke Garage
    ISBN: 0131855166
    EAN: 2147483647
    Year: 2006
    Pages: 235
    Authors: Don Jones

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net