Block Hacks


As PostNuke has evolved, control of smaller elements like individual blocks has become easier and easier. The current release with Xanthia theme support allows you to develop custom block zones with separate theme templates for each zone. Similar features are found with other theme modules, such as AutoTheme (spidean.mckenzies.net), BlockHome (www.natewelch.com), or Nuclei (www.tangant.com).

If you are not comfortable with complicated theme systems, or just prefer a quick code change, hacking your PostNuke install might be a preferable option. Blocks on a given site are usually used with specific purpose, in that you can easily control where they are and how they look.

Note

The main drawback to hacking code that could be themed is the loss of modularity. If you later upgrade your site, your hack will be gone. A customized theme can be reapplied to a new install instantly. You can also recode your hack, however, and doing multiple hacks might take less time than theme development.


Apply Styles to Blocks

You can apply direct styles to blocks by editing the code used to generate the block. This effect can be handy if you want to quickly highlight a block to set its contents apart from the rest of your site.

Use the Incoming block as a good example. It appears dynamically whenever there is new content waiting to be approved. If this block is too far down in the site layout, it might be hard to see, and new content might go unnoticed. A simply styled hack can brighten up the block to make it impossible to miss.

The Incoming block is actually part of the core Menu block code, so you need to open this file in your editor:

 /includes/blocks/menu.php 

Scroll down to around line 133 and you see this code:

 // Waiting content if (!empty($vars['displaywaiting'])) {     // Separate from current content, if any     if ($content == 1) {         $block['content'] .= addMenuStyledUrl($vars['style'], "", "", "");     } 

That is the beginning of the Incoming content code. Because this code is within another block, you can only edit the content area without affecting other block instances. But the benefit is any usage of the Waiting Content check box option with Menu blocks displays the hack changes. If you don't want a separate Incoming block, and want to display the content inside the Main Menu for example, it automatically applies there too.

Add the two lines of code after the first if statement in the following example:

 if (!empty($vars['displaywaiting'])) {    // Hack to highlight waiting content    $block['content'] .= "<div style=\"background-color:#FFC000; padding:5px;\">";    // Separate from current content, if any    if ($content == 1) {       $block['content'] .= addMenuStyledUrl($vars['style'], "", "", "");    } 

Now scroll down to what should be line 226 after you have made the preceding change. The code looks like this:

             }         }     } } // Styling $block['content'] .= endMenuStyle($vars['style']); 

You need to close the <div> tag after the first three closing } brackets. Here is the finished code:

         }     }     }     $block['content'] .= "</div>"; } 

After you've saved your changes, load up your site in a browser, and your block looks like Figure 21.5. This example uses the gold color, but you can, of course, use any coloring, including bright red (#FF0000) if desired.

Figure 21.5. Highlighting content waiting for approval.


Page/Module-Specific Blocks

You can customize blocks to only appear for certain modules. Different theme systems offer this feature, including both Xanthia and AutoTheme, but if you are not familiar with more advanced settings in the themes, or simply don't like having to develop different templates for each module, this hack can save a great deal of time and trouble.

For this example, use the core Polls block. You'll make the block only appear on the main News page. The main Polls administration and comments code is all in the NS-Polls folder, but the file you want is located here:

 /includes/blocks/poll.php 

Open that file in your editor. Scroll down to about line 52 where you should see this code:

 function pollMain($pollID, $row) {     if (!pnSecAuthAction(0, 'Pollblock::', "$row[title]::", ACCESS_READ)) {         return;     } 

The pollMain function controls the display of the Polls block, and the first if statement is checking to see if a given user has read access before displaying the block.

Add the following code after the opening { and before the read check:

 // Hack to allow Polls only on News page if ($GLOBALS['ModName'] != "News") {     return; } 

The script simply checks whether the current module is called News. You can use any module name there; NS-Admin, for example, only shows the block on the Administration page. Similarly, this code makes the block appear on all pages except the Administration page:

 // Hack to disallow Polls on Admin page if ($GLOBALS['ModName'] == "NS-Admin") {     return; } 

Consult the Modules Administration page for the proper module names to use for any module you have installed.



    PostNuke Content Management
    PostNuke Content Management
    ISBN: 0672326868
    EAN: 2147483647
    Year: 2003
    Pages: 207
    Authors: Kevin Hatch

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