Website Settings


The PostNuke Site Settings options let you customize global variables and code that appear on all pages of your site. Although many of these page variables are easily changed in the form fields, the formatting of the variables is hard-coded into PostNuke. Also some metatag data options are missing altogether.

This is not a cause for concern, as a few simple hacks can remedy the need for extensions or customizations within your PostNuke site. The following sections cover some of the most commonly requested changes.

Change Title Display in Browser

PostNuke normally displays the site name, two colons, and the site slogan, as defined in the Website Settings. The title is used for bookmarks and browser histories, as well as sometimes being an important tool for populating search engine information. But if you want to customize the title further, you need to hack the title display.

PostNuke .75 introduces Xanthia themes that handle things a bit differently than regular PostNuke themes. If you are using a normal PostNuke theme, perform the following steps:

In your site's root folder is a file called header.php. Open this file in a standard text editor. Look for the if statement starting about line 93:

 if ($artpage==1) {     /**      * article page output      */     global $info, $hometext;     echo "<title>$info[title] :: ".pnConfigGetVar('sitename').' :: '.pnConfigGetVar ('slogan')."</title>\n";     if (pnConfigGetVar('dyn_keywords') == 1) {        $htmlless = check_html($info['maintext'], $strip ='nohtml');        $symbolLess = trim(ereg_replace('("|\?|!|:|\.|\(|\)|;|\\\\)+', ' ', $htmlless));        $keywords = ereg_replace('( |'.CHR(10).'|'.CHR(13).')+', ',', $symbolLess);        $metatags = ereg_replace(",+", ",",$keywords);        echo "<meta http-equiv=\"Keywords\" content=\"$metatags\">\n";     } else {        echo "<meta name=\"KEYWORDS\" content=\"".pnConfigGetVar('metakeywords')."\">\n";     } } else {     /**      * all other page output      */     echo '<title>'.pnConfigGetVar('sitename').' :: '.pnConfigGetVar('slogan')."</title>\n";     echo '<meta name="KEYWORDS" content="'.pnConfigGetVar('metakeywords')."\">\n"; } 

The older PostNuke code caters to its multimodule article system with the first half of the statement. When you browse into article areas, the title of an article displays before the site name.

First, you need to decide how you want your title to look. Changes to this code apply globally throughout your site. Set the site name to appear at the far left in all cases, followed by a single colon, and the article name can alternate with the slogan depending on the page.

Copy line 98, comment out the original, and change the <title> tag to look like this:

 echo "<title>".pnConfigGetVar('sitename').": $info[title]</title>\n"; 

and change the <title> tag at about line 112 to look like this:

 echo "<title>".pnConfigGetVar('sitename').": ".pnConfigGetVar('slogan')."</title>\n"; 

Notice the second change in this example was very minimal; if you didn't want to change the colon format, you would not have to change it at all.

Xanthia theme users will find this change much easier. You need to edit the title plug-in, which has simplified code due to its modularity. Open this file in your editor:

 /modules/Xanthia/plugins/function.title.php 

You need to edit lines 61 and 64 similar to the preceding example. The first line should be edited to look like this:

 $title = pnConfigGetVar('sitename').": ".$GLOBALS['info']['title']; 

And line 64 should appear as this:

 $title = pnConfigGetVar('sitename').": ".pnConfigGetVar('slogan'); 

Don't forget to back up the original lines so you can go back to them if desired later. This hack illustrates how quick and clean development is becoming with the ongoing PostNuke standardization.

Append Dynamic Keywords to Static

PostNuke handles metatag keywords (see Figure 21.1) through the Website Configuration page. Although you can define a large number of terms to apply to your pages, if you select the Dynamic MetaKeywords option, the static words are not used on those pages on which words can be generated. This system creates nicely customized keywords for your articles, but it means important words in the static list might go unused.

Figure 21.1. Defining keywords for your pages.


The solution to this problem is to combine the features and get the best of both worlds. You can hack the PostNuke metatag code to append dynamic terms to the static listing if dynamic words are available.

Note

If you plan to use this hack, you might want to review your static keyword selections. Too many keywords can be a bad thing, so leave only the important words and remove unneeded extras.


If you are using a non-Xanthia theme, find the file header.php in your site's root folder. Open it in a text editor and look for the assignment statement at about line 103:

 $metatags = ereg_replace(",+", ",",$keywords); 

Duplicate the line and alter your copy so that it looks like this:

 $metatags = pnConfigGetVar('metakeywords').','.ereg_replace(",+", ",",$keywords); 

That places the metakeywords variable before the dynamic article words. If you only change this one line, the Dynamic MetaKeywords enable/disable option in the Site Settings (see Figure 21.1) still works. If you disable the Dynamic MetaKeywords option, the static words are used; if you enable it, both are used.

You can also force the use of both sets of terms with articles by removing this code at about line 99:

 if (pnConfigGetVar('dyn_keywords') == 1) { 

and lines 105 and 106:

 } else { echo "<meta name=\"KEYWORDS\" content=\"".pnConfigGetVar('metakeywords')."\">\n"; 

Doing so means the Website Settings option no longer works.

If you are using a Xanthia theme, you need to open this file:

 /modules/Xanthia/plugins/function.keywords.php 

and change line 102 from this:

 $keywords = implode(',', $keywords); 

to instead look like this:

 $keywords = pnConfigGetVar('metakeywords').implode(',', $keywords); 

Be certain to comment out the original line. Now your static keywords appear before the dynamic.

Create Description Metatag

PostNuke does not allow you to define the contents of the description metatag. Instead, it uses whatever you have defined in your slogan as the description. Separating the two can be approached in two ways; you can hard-code the description metatag in the header.php or master.htm files, or you can create a description field in the site settings.

The first option is very easy to accomplish. If you are not using a Xanthia theme, open the header.php file in a text editor and look for line 115:

 echo '<meta name="DESCRIPTION" content="'.pnConfigGetVar('slogan')."\">\n"; 

Edit it with your own description so that it appears as follows:

 echo "<meta name=\"DESCRIPTION\" content=\"My site does many great things\">\n"; 

Xanthia users need to open the master.htm file for their respective theme:

 /themes/[yourthemename]/templates/master.htm 

Back up line 6:

 <meta name="DESCRIPTION" content="<!--[slogan]-->"> 

and edit the working copy with your own description like this:

 <meta name="DESCRIPTION" content="My site does many great things"> 

Browse to the Xanthia Theme Engine Administration page and find your theme in the table. Click the Reload Templates link in the Actions column to apply your change to the live site. That description now appears on all pages and the site slogan remains separate.

Besides changing PHP code, the second option of creating a new field in the Site Settings requires an additional variable and database entry. It's a fairly easy process whether you use a database tool or not. You can start by making the table changes.

The table with Site Settings data is called nuke_module_vars. If you are using an administration tool such as phpMyAdmin, find the table in the listing, select the Insert operation, and enter the following data into the fields, as shown in Table 21.1.

Table 21.1. Creating Description Metatag in Database

FIELD

VALUE

pn_id

Leave blank, it will autoincrement

pn_modname

/PNConfig

pn_name

metadescription

pn_value

Leave blank, it will be NULL for now


If you are not using a database tool or simply prefer to use straight Structured Query Language (SQL), the statement you need to submit is this:

 INSERT INTO nuke_module_vars (pn_modname, pn_name) VALUES ('/PNConfig', 'metadescription'); 

Note

If you chose a table prefix other than nuke during your install, that is the text which appears before module_vars in the table name.


Now that the database is prepared to receive the data, the next step is to add a text description for the form you will make later. Open this file in your text editor:

 /modules/NS-Settings/lang/eng/global.php 

Tip

The change to the global.php file in the eng directory only prepares the English language. If you use other languages, you must change their files, as well.


The definition lines are sorted in alphabetical order, and you should maintain the format for consistency. Look for this code at about line 59:

 define('_METAKEYWORDS','Meta keywords'); 

Enter the new line right above _METAKEYWORDS. Make a new line and add this code:

 define('_METADESCRIPTION','Meta Description'); 

Save the file. Now, you need to create a form element that will populate your table entry. The form should be on the Site Settings page with the other metatag options, and that file is found at this location:

 /modules/NS-Settings/admin.php 

Look at lines 163167:

 .'</td></tr><tr><td >' ._SITESLOGAN.":</td><td><input type=\"text\" name=\"xslogan\" value= \"".pnConfigGetVar('slogan')."\" size=\"50\" maxlength=\"100\" class=\"pn-normal\" />" .'</td></tr><tr><td >' ._METAKEYWORDS.':</td><td><textarea name="xmetakeywords" cols="80" rows="10" >'.htmlspecialchars(pnConfigGetVar('metakeywords')).'</textarea>' .'</td></tr><tr><td >' 

Note

Note how the end and start of table rows are on the same line. It's common to run Hypertext Markup Language (HTML) together where page lines and code lines do not correspond, but if you are unfamiliar with HTML, be careful you maintain the table's consistency.


Add the new Meta Description field after the Slogan and before the Keywords. The Meta Keywords code is very similar to what you want for the description field, so you might want to copy lines 174 and 175 to make it easier. Your final code should look like this:

 .'</td></tr><tr><td >' ._SITESLOGAN.":</td><td><input type=\"text\" name=\"xslogan\" value= \"".pnConfigGetVar('slogan')."\" size=\"50\" maxlength=\"100\" class=\"pn-normal\" />" .'</td></tr><tr><td >' ._METADESCRIPTION.':</td><td><textarea name="xmetadescription" cols="80" rows="10" >'.htmlspecialchars(pnConfigGetVar('metadescription')).'</textarea>' .'</td></tr><tr><td >' ._METAKEYWORDS.':</td><td><textarea name="xmetakeywords" cols="80" rows="10" >'.htmlspecialchars(pnConfigGetVar('metakeywords')).'</textarea>' .'</td></tr><tr><td >' 

Save the file. You can now browse to the Site Settings Administration page and see the added form entry in Figure 21.2. It does work; you can add a description and submit the form, and the information will be stored in the database, but you have not yet told PostNuke to use the stored information with your site's pages.

Figure 21.2. Adding Meta Description to your site.


For non-Xanthia themes, start up your editor and open the header.php file in your PostNuke root. Just as described in the hard-coded description hack previously, look for the following code at about line 115:

 echo '<meta name="DESCRIPTION" content="'.pnConfigGetVar('slogan')."\">\n"; 

Copy and change the line to look like this:

 echo "<meta name=\"DESCRIPTION\" content=\"".pnConfigGetVar('metadescription')."\">\n"; 

This enables PostNuke to use your description variable with the metatag. If you leave the description blank, the tag is generated with nothing for a description. If that concerns you, you can alternatively create an if statement to use another variable, such as the slogan, if the description is empty. Replace line 115 with this code:

 if (pnConfigGetVar('metadescription') != NULL) {    echo "<meta name=\"DESCRIPTION\" content=\"".pnConfigGetVar('metadescription')."\">\n"; } else {    echo "<meta name=\"DESCRIPTION\" content=\"".pnConfigGetVar('slogan')."\">\n"; } 

This change does not prevent a NULL entry if both the description and slogan fields have been left blank, but it does add a little robustness.

Xanthia users have a few more steps yet to complete. The Xanthia Theme Engine (XTE) has a set of modular plug-ins used to generate variable information for themes. Because the Meta Description information is entirely new, a new plug-in function needs to be created.

Look at the Xanthia plugins folder:

 /modules/Xanthia/plugins/ 

You can copy one of those files for a source, or you can download the version of the description plug-in described here from the book's online materials. If you want to make the changes yourself, copy one of the files to a new file called function.metadescription.php.

Open this file in your editor. The only code you need to be concerned about is past the header comments, starting at roughly line 54. The line begins with function smarty_function_. Replace all of the function code with the following:

 function smarty_function_metadescription($params, &$smarty) {     extract($params);     unset($params);     return pnConfigGetVar('metadescription'); } 

Be certain you do not delete the closing PHP code: ?> after the end of the function. Now open up the master.htm file for your theme:

 /themes/[yourthemename]/templates/master.htm 

Edit a copy of line 6 to replace the word "slogan" with "metadescription." The line should now look like this:

 <meta name="DESCRIPTION" content="<!--[metadescription]-->"> 

Now, your theme templates are prepared, but you must reload them for your changes to become live. Go to the Xanthia Theme Engine Administration page. Find your theme in the table, and click the Reload Templates link in the Actions column. You can see your description changes by viewing the source on any page.

Fix Copyright Metatag Date

PostNuke generates a copyright metatag, but if you are using a non-Xanthia theme, you might have noticed it still has a 2003 date. You can fix this oversight very easily with one edit.

In your site's root folder is a file called header.php. Open this file in a standard text editor. Look for this statement on line 120:

 echo '<meta name="copyright" content="Copyright (c) 2003 by '.pnConfigGetVar( 'sitename')."\">\n"; 

Change the 2003 to 2004, save, and you're finished.

You can also dynamically generate the current year so that you do not have to edit it in the future with this line:

 echo '<meta name="copyright" content="Copyright (c)'.date('Y').' by '.pnConfigGetVar( 'sitename')."\">\n"; 

Xanthia themes generate the copyright statement separately in each theme. You need to edit the master.htm file for the theme you are using. The path to the file is this:

 /themes/[yourthemename]/templates/master.htm 

The standard copyright tag is on line 11. The new Xanthia themes all have 2004 hard-coded, but going forward you'll need to update that to the current year. After you've made a change, you need to click the Reload Templates link for your theme on the Xanthia Theme Engine Administration page.

Create Favicon Metatag

It seems like nearly every site is using a favicon these days; you can see their use as the small icons displayed by Favorite entries in Microsoft Internet Explorer or on tabs in Mozilla Firefox. This nifty site enhancement is possible using PostNuke with just a few site changes. First, you need your icon file. If you're not certain how to create a favicon file, take a look at the information found at www.favicon.com. After you have your favicon file ready, place the icon in your website's root folder.

If you are not using a Xanthia theme, simply open up the header.php file in your site's root. After the style sheet @import finishes with </style> on line 131, add these two lines:

 <link rel="shortcut icon" href="http://www.mysitename.com/favicon.ico" /> <link rel="icon" href="http://www.mysitename.com/favicon.ico" type="image/png" /> 

You need both of these lines to ensure you have complete browser support. The first line is the old way of defining a favicon, and one that most versions of Internet Explorer still use. The second line is the new standard for referencing a favicon, and current Mozilla and Opera browsers need that code.

Tip

With the new standard for site icon development, you can also use the Portable Network Graphics (PNG) image format. The benefit of PNG over the ICO Icon format is access to 24-bit color and a true alpha mask. You can create both images, and newer browsers use the PNG.


For Xanthia themes, you need to edit your theme's master.htm template file found here:

 /themes/[yourthemename]/templates/master.htm 

You should see that these two lines already exist in the template at lines 19 and 20:

 <link rel="icon" href="<!--[$imagepath]-->/icon.png" type="image/png"> <link rel="shortcut icon" href="<!--[$imagepath]-->/favicon.ico"> 

Though the lines exist, the default Xanthia themes do not come with icons. You need to place your icon in the theme's images directory. Change lines 19 and 20 to reflect the filename of your icon. After you have completed all your changes, click the Reload Templates link for your theme on the Xanthia Theme Engine Administration page. This applies your master.htm changes and your icon appears.

Display Indigenous Language Names

An issue that's been brought up many times in the PostNuke community is the display of language names while in the default English setting. If you offer multiple languages on your site, it's generally preferred that the names of other languages be written in their respective indigenous format. For example, when a German user is personalizing his language interface, it's better for him to see Deutsch as an option instead of German. Having Aleman as the German option in the Spanish language set is just as problematic.

PostNuke currently displays the latter method, in which language names appear with English spellings. To make this change, you need to edit the language listing included with the English package. Start up your text editor and open this file:

 /language/eng/global.php 

The language definitions begin at line 183 and continue through line 224. Comment out the original language references; it is handy to have the English versions readily available. Now add in all of the following code:

 define('_LANGUAGE_ARA','Arabic'); define('_LANGUAGE_BUL','Bulgarian'); define('_LANGUAGE_CAT','Català'); define('_LANGUAGE_CES','C^esky'); define('_LANGUAGE_CRO','Croatian CRO'); define('_LANGUAGE_HRV','Croatian HRV'); define('_LANGUAGE_DAN','Dansk'); define('_LANGUAGE_DEU','Deutsch'); define('_LANGUAGE_ELL','Greek'); define('_LANGUAGE_ENG','English'); define('_LANGUAGE_EPO','Esperanto'); define('_LANGUAGE_EST','Eesti'); define('_LANGUAGE_FIN','Suomi'); define('_LANGUAGE_FRA','Français'); define('_LANGUAGE_HEB','Hebrew'); define('_LANGUAGE_HUN','Magyar'); define('_LANGUAGE_IND','Bahasa Indonesia'); define('_LANGUAGE_ISL','íslenska'); define('_LANGUAGE_ITA','Italiano'); define('_LANGUAGE_JPN','Japanese'); define('_LANGUAGE_KOR','Korean'); define('_LANGUAGE_LAV','Latvieu); define('_LANGUAGE_LIT','Lietuvin'); define('_LANGUAGE_MAS','Malay'); define('_LANGUAGE_MKD','Macedonian'); define('_LANGUAGE_NLD','Nederlands'); define('_LANGUAGE_NOR','Norsk'); define('_LANGUAGE_POL','Polski'); define('_LANGUAGE_POR','Português'); define('_LANGUAGE_RON','Românã'); define('_LANGUAGE_RUS','pa Ruski'); define('_LANGUAGE_SLV','Slovencina); define('_LANGUAGE_SPA','Español'); define('_LANGUAGE_SWE','Svensk'); define('_LANGUAGE_THA','Thai'); define('_LANGUAGE_TUR','Türkçe'); define('_LANGUAGE_UKR','Ukrainian'); define('_LANGUAGE_X_BRAZILIAN_PORTUGUESE','Português Brasileiro'); define('_LANGUAGE_X_KLINGON','Klingon'); define('_LANGUAGE_X_RUS_KOI8R','Russian KOI8-R'); define('_LANGUAGE_YID','Yiddish'); define('_LANGUAGE_ZHO','Chinese (Simp.)'); 

This list is designed to be universal, and all language packs can use it. A few of the languages listed are not converted due to possible limitations in browser displays. If your site visitors are assumed to have the proper character sets installed in their browsers for a given language, you should change the language entries here appropriately.

Add and Remove Tags from Allowed List

The list of HTML tags on the Site Settings page was developed to provide both flexibility and security. You can see from the warnings at the bottom of the page (see Figure 21.3) that some tags can be exploited by visitors wanting to crack your site. There might, however, be times when you need to open up access to additional tags or remove deprecated or unused tags.

Figure 21.3. The dangers of HTML tags.


If you are running your site in a secure environment, such as a business intranet, protection from attacks might not be an issue at all. Also as Extensible Hypertext Markup Language (XHTML) standards evolve, you might find the need to add other tags that were not initially considered at the time your PostNuke version was released.

Thankfully, it's very easy to manage tags on the Site Settings page. Launch your text editor and open this file:

 /modules/NS-Settings/admin.php 

Scroll down to the bottom of the file to about line 523 where you should see this code:

 // Local function to provide list of all possible HTML tags function settingsGetHTMLTags() {     // Possible allowed HTML tags     return array('!--', 

Below the preceding code is a long array of every HTML tag in the Site Settings list. Add additional lines with the tag name shown minus the < and > brackets, or remove those tags you feel are no longer needed. It's recommended you only comment out a line using // rather than completely deleting the code.

Change References to Allowed Tags

After you've changed the tag listing, you might want to change or remove the way allowed tags are referenced in other modules. As an example of this, look at the Comments feature shown in Figure 21.4.

Figure 21.4. Allowed HTML for comments.


The tag list at the bottom of the form is automatically generated from the Site Settings table. You might find you prefer only publicizing certain tags or would rather remove the tag note altogether. Either is possible with a very quick hack.

Open your text editor and load up this file:

 /modules/NS-Comments/index.php 

Scroll down to roughly two thirds of the file and you should see this code starting at about line 879:

 ."<span class=\"pn-sub\">"._ALLOWEDHTML."&nbsp;"; $AllowableHTML = pnConfigGetVar('AllowableHTML'); while (list($key, $access, ) = each($AllowableHTML)) {     if ($access > 0) echo " &lt;".$key."&gt;"; } echo "</span><br /><br />"; 

The ALLOWEDHTML variable displays the label text before the tags. If you want to hard-code a limited set of tags, you need to change only the middle code. Comment out the $AllowableHTML assignment and while statement, and add this line to replace them:

 echo "&lt;mytagname&gt;"; 

This adds one tag. You can create multiple lines or string your tags together for something like this:

 echo "&lt;agt; &lt;bgt; &lt;igt; &lt;br /gt;"; 

To remove the tag reference altogether, you need to comment all of the code shown previously, and add in this line:

 echo "<br /><br />"; 

That ensures the spacing remains the same.



    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