Hacking Basics


To perform a hack, you need to be familiar with PostNuke's files. For some hacks, half the work can be finding exactly where the code is that you want to change. But, thankfully, knowing how files are organized and how to search them can make it relatively easy to pin down your target code.

Directory Structure

Here is a simplified diagram of the PostNuke directory tree:

 [root] |---/docs |---/images |---/includes |   |---/blocks |   |---/classes |   |   |---/Smarty |   |---/language |   |   |---/blocks |   |       |---/eng |   |---/search |---/install |---/javascript |---/language |   |---/eng |---/modules |   |---/Autolinks |   |   |---/pndocs |   |   |---/pnimages |   |   |---/pnlang |   |       |---/eng |   |---/AvantGo |   |   |---/docs |   |   |---/lang |   |       |---/eng |   |---/Blocks |   |   |---/pnimages |   |   |---/pnlang |   |       |---/eng |   | --- [etc.] |---/pnadodb |---/themes 

There's a pattern in the structure of which you need to be aware; everything in PostNuke is designed to be modular. Throughout the structure, you will repeatedly find folders for docs, images, and language files. Each module has one or more of those folders, and you'll see them all in the site root too.

The documentation folders usually contain text files with install and usage notes. Sometimes, they also include version information and troubleshooting tips. The images folders contain whatever graphics are needed for their respective modules or systems.

The language folders contain the PHP files that define a module's plain text variables. For example, when you see the text "Go back to main page," the page is actually calling a variable _GOBACK. The system cross-references the variable name with the currently selected language, and displays the appropriate text on the screen during load.

Root Folders

The root folders are defined as follows:

  • docs Basic PostNuke documentation; short installation guide included.

  • images Primary image folder; key folder is the subdirectory global, which contains many important images used throughout PostNuke.

  • includes Components used by most modules; the blocks subdirectory is important for hacking, and you can find a number of key files in the includes root.

  • install Temporary directory containing the files required to install Postnuke. The folder should not be present on your server after your site install is complete.

  • javascript General scripts used by some modules, such as a window pop-up.

  • language Global language definitions used throughout the site. Note that there are many language files distributed throughout the directory structure.

  • modules Location of all PostNuke modules on your site. If you are hacking a module, look here for its source.

  • pnadodb PostNuke's database abstraction library; provides support for a number of different databases through this code. You shouldn't change any of these files.

  • themes Location of the themes available for application to your site. These files are heavily edited when developing a new theme, but you don't need them for code hacks.

Code Hunting

Being familiar with the PostNuke file structure can make finding specific source code easier, but there are a few tips to keep in mind that should make it easy for you to find anything.

First browse to the pages that display what you want to change. Look at the uniform resource locator (URL) in your browser. For example, if you're viewing the Theme Select page for a user, you see the following URL:

 http://www.yoursite.com/user.php?op=chgtheme 

It seems clear that the file you need to edit is /user.php. Now look at this sample URL:

 http://www.yoursite.com/admin.php?module=NS-Polls&op=main 

In this case, the file that needs to be developed is not admin.php in the PostNuke root. Instead, you need to edit the admin.php file under the /modules/NS-Polls/ folder. Sometimes, the URL clearly shows the file and sometimes it simply points you in the right direction. But it's always a good first step.

Next try to determine if you need to edit a module file, a block, or something more global to PostNuke. Block files are always found in /includes/blocks and, the majority of the time, module files are located in their respective /modules/modulename folder.

After you have a fair idea what files to look into, your text editor can do the rest of the work for you. Your editor needs to be able to perform a search/find operation on open files. An ideal feature available with some editors is Search All Open Documents. With the All Documents feature, you can open a dozen files or more and easily determine where specific lines are written.

You can perform a simple track operation to see how it's done. Browse to the Web Links Configuration page (see Figure 20.2). Your URL should state this:

Figure 20.2. Tracking down code using language keywords.


 http://www.yoursite.com/admin.php?module=Web_Links&op=main 

Look at the text on the page. For example, suppose you just need to remove the Broken Link Reports option from the page. So, the target is the code that echoes that link.

The URL specifically references the /admin.php file, but there is a module reference associated with it, and you know the screen specifically relates to one module. So, more likely, the code is in /modules/Web_Links/admin.php.

To confirm exactly which file, you perform a search based on the text displayed for the link. Searching for "Broken Link Reports" in any of the code files does not find the line you need. All of the text is generated through the language system using variable definitions. Following the assumption that the relevant files are located in /modules/Web_Links, open the module's language file into your editor:

 /modules/Web_Links/lang/eng/global.php 

Search that file for "Broken Link Reports" and you come up with line 45:

 define('_BROKENLINKSREP','Broken link reports'); 

That line tells you the variable that determines the exact code to edit is _BROKENLINKSREP. Now open up the Web Links admin.php file and try a search there:

 /modules/Web_Links/admin.php 

Tip

Don't stop at the first search hit; sometimes, the same variable is referenced multiple times in the same file and might also be in multiple files. Be certain you have the right code before you start making changes.


Very quickly, you hit on line 80:

 ."<a href=\"admin.php?module=".$GLOBALS['module']."&amp;op=LinksListBrokenLinks\">"._ BROKENLINKSREP." (".pnVarPrepForDisplay($totalbrokenlinks).")</a> | " 

You can now very easily edit or remove the link by changing the code surrounding the key variable. Hunting down code in PostNuke isn't always that easy, but you'll find these steps jump you to the right code nearly every time.



    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