14.4. Modifying the PHP-Nuke theme body

In this section we continue our study of PHP-Nuke themes - this time with the body of a theme! We cover topics like:

14.4.1. How to get multipage News articles

It appears that while Reviews, Section, and Content areas allow multipage bodies, the general News article does not. Contrary to what one would think, if you want to add such functionality in the News module, the code under modules/News/ is not the right place. The right place is the themearticle() in the theme.php file of your theme!

This is so, because it is the themearticle() function that outputs the article text, through a call to the FormatStory() function (which is also defined in theme.php):

FormatStory($thetext, $notes="", $aid, $informant);

Thus, all we have to do is format $thetext accordingly, before it is passed to FormatStory. Just add the following code to the begining of the themearticle() function in theme.php, like this[1] (see Multipage articles, Pagebreaks in articles):

function themearticle ($aid, $informant, $datetime, $title, $thetext, 
$topic, $topicname, $topicimage, $topictext) {
global $admin, $sid, $tipath, $page;
$contentpages = explode( "<!--pagebreak-->", $thetext );
$pageno = count($contentpages);
if ( $page=="" || $page < 1 )
$page = 1; 
if ( $page > $pageno )
$page = $pageno;
$arrayelement = (int)$page;
$arrayelement --;
if ($pageno > 1) {
$thetextNew .= "Page: $page/$pageno<br>";
}
$thetextNew .= "<p align=\"justify\">$contentpages[$arrayelement]</p>";
if($page >= $pageno) {
$next_page = "";
} else {
$next_pagenumber = $page + 1;
if ($page != 1) {
$next_page .= "- ";
}
$next_page .= "<a href=\"modules.php?name=News&file=article&sid=$sid
&page=$next_pagenumber\">"._NEXT." ($next_pagenumber/$pageno)</a> 
<a href=\"modules.php?name=News&file=article&sid=$sid&page=$next_pagenumber\">
<img src=\"images/right.gif\"border=\"0\" alt=\""._NEXT."\"></a>";
}
if ($page == $pageno) {
$thetextNew .= "<br><p align=\"justify\">".nl2br($mypage[page_footer])."</p><br><br>";
}
if($page <= 1) { 
$previous_page = "";
} else {
$previous_pagenumber = $page - 1;
$previous_page = "<a href=\"modules.php?name=News&file=article&sid=$sid
&page=$previous_pagenumber\">
<img src=\"images/left.gif\" border=\"0\" alt=\""._PREVIOUS."\"></a> 
<a href=\"modules.php?name=News&file=article&sid=$sid
&page=$previous_pagenumber\">"._PREVIOUS." ($previous_pagenumber/$pageno)</a>";
}
$thetextNew .= "<br><br><br><center>$previous_page $next_page</center><br><br>";
$thetext = $thetextNew;

Now you can use <!--pagebreak--> in your News stories, and the code above will split the text at the <!--pagebreak--> and create the “previous” and “next” hyperlinks for you (don't forget to define _NEXT and _PREVIOUS in your language file, as shown in Chapter 13).

14.4.2. How to change background colour

A well-constructed theme will offer you a simple way to change the various colours (see How to change the background colour): in the theme.php file of the NukeNews theme, for example, you can read:

/************************************************************/
/* Theme Colors Definition                                  */
/*                                                          */
/* Define colors for your web site. $bgcolor2 is generaly   */
/* used for the tables border as you can see on OpenTable() */
/* function, $bgcolor1 is for the table background and the  */
/* other two bgcolor variables follows the same criteria.   */
/* $texcolor1 and 2 are for tables internal texts           */
/************************************************************/

and immediately after that:

$bgcolor1 = "#efefef";
$bgcolor2 = "#cfcfbb";
$bgcolor3 = "#efefef";
$bgcolor4 = "#cfcfbb";
$textcolor1 = "#000000";
$textcolor2 = "#000000";

The strings to the right side of the above assignments are hexadecimal representations of colours. They begin with a # and contain six hexadecimal digits, two for each colour of the basic ones, red, green and blue. Thus, the string "#cfcfbb" fot $bgcolor4 means cf for red, cf for green and bb for blue. Each one of the three hexadecimal two-digit numbers has a range from 00 to FF (just as each hexadecimal digit goes from 0 to F: 0, 1, 2, 3..., 8, 9, a, b, c, d, e, f, where a means 10, b means 11, c means 12 ... and f means 15 in the hexadecimal system). This means a range from 0 to 255 - that's 256 different values for each colour.

TipColour wheels
 

A useful tool in exploring the visible spectrum in HTML is the colour wheel. Just hover over the wheel with your mouse to view 4096 colors in their web safe, web smart and unsafe versions.

You can also use the colour popups of the Tag-o-matic to show all 216 web-safe colours in a virtual colour card.

But what do you do if your theme does not follow this scheme and does not offer you this possibility? In such a case, we need to applly our knowledge on the structure of a theme (see Section 14.1). We have seen that each theme comes with its own definition of the OpenTable() and CloseTable() functions. A brief look at the code of tables.php in modules/NukeNews reveals the place where $bgcolor1 and $bgcolor2 are used in the Nuke News theme: in the definitions of OpenTable() and CloseTable()! This is for example the OpenTable() function for the NukeNews theme (see modules/NukeNews/tables.php):

function OpenTable() {
    global $bgcolor1, $bgcolor2;
    echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" 
           cellpadding=\"0\" bgcolor=\"$bgcolor2\"><tr><td>\n";
    echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" 
          cellpadding=\"8\" bgcolor=\"$bgcolor1\"><tr><td>\n";
}

Other themes construct their the OpenTable() and CloseTable() functions similarly, if not identically. We will use this fact to change the background colour in the Stories Archive module - and only there. To this end, we only need to define new OpenTable() and CloseTable() functions, with the colour of our choice, then use the new functions instead of the old ones everywhere in the module:

In the theme.php file of your theme, add the following two functions[2]:

function OpenTableNew() {
    global $bgcolor1, $bgcolor2;
    echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" 
          cellpadding=\"0\" bgcolor=\"$bgcolornew2\"><tr><td>\n";
    echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" 
          cellpadding=\"8\" bgcolor=\"$bgcolornew1\"><tr><td>\n";
} 
function CloseTableNew() {
    echo "</td></tr></table></td></tr></table>\n";
}

Give the new background colours, $bgcolornew1 and $bgcolornew2, the values of your liking in the start of theme.php, for example:

$bgcolornew1 = "#ffffff";
$bgcolornew2 = "#660000";

Then just change every occurence of "OpenTable" and "CloseTable" with "OpenTableNew" and "CloseTableNew" respectively in modules/Stories_Archive/index.php. That's all! The Stories Archive module will now use the new colours.

There is one small detail you may also want to fix though: the colours of the cells for the “Articles | Comments | Reads | Score | Date | Actions” links. To change those too, you will have to change the $bgcolour2 colour in the table cells of the show_month function of modules/Stories_Archive/index.php (see also Background color in Stories Archive):

    echo "<table border=\"0\" width=\"100%\"><tr>"
        ."<td bgcolor=\"$bgcolor2\" align=\"left\"><b>"._ARTICLES."</b></td>"
        ."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>"._COMMENTS."</b></td>"
        ."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>"._READS."</b></td>"
        ."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>"._USCORE."</b></td>"
        ."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>"._DATE."</b></td>"
        ."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>"._ACTIONS."</b></td></tr>";

For your design to be consistent, the best way would be to change the six occurences of $bgcolor2 in the above code, to your new background colour $bgcolornew2.

If you want to change the foreground colour, the easiest method might be to change the value of the text attribute in the <body> tag that is echoed in the themeheader() function of theme.php (see How to change the main font color):

echo "<body bgcolor=\"#505050\" text=\"#000000\" 
link=\"#363636\" vlink=\"#363636\" alink=\"#d5ae83\">";

Setting

text=\"#FF0000\"

for example, should make all text appear in red.

Notes

[1]

Notice that we have added $page to the global variable list - other than that ,the first two lines are included here only for your orientation.

[2]

Strictly seen, the CloseTableNew() function is not necessarily needed, since no new colour is defined there, but it is good to have, to keep the functions conceptually separated from the standard ones.