Plug:ignatius:phpCMS ExtMenuClass

From phpCMS

Jump to: navigation, search

Contents

[edit] phpCMS ExtMenuClass

[edit] Overview

title         : phpCMS ExtMenuClass
version       : 0.1
author        : (c) by Thilo Wagner (Ignatius)
licence       : GPL
description   : With this plugin for phpCMS you can overwrite the menu-class of a content file by an external parameter.                     
phpCMS version: tested with phpCMS 1.1.7 and 1.2.0

Please post any errors, discussions etc. about this plugin to the phpCMS forum at http://www.phpcms.de or twagner (at) drachenreiter.de

[edit] License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

[edit] Download

The plugin can be downloaded from the plugin database on http://www.phpcms.de. The direct link is:

http://phpcms.de/download/plugins/files/phpcms_extmenuclass_01.zip

Please make sure that there is no newer version in the plugin database (and update this page in the wiki if this is the case)

[edit] Plugin description

With this plugin for phpCMS you can overwrite the menu class of a content file by an external parameter. The plugin can also add this parameter automaticaly to links in the menu file if wanted. With these two features this plugin makes it possible to call a content file from different positions of the menu with different menu classes and to have always the correct menu item displayed as 'active'.

Example: Sometimes you want to place a link to the same content file from different positions in the menu, for example:

MENU: SUB1
CLASS;    MNAME;    LINK
00.01.01; My Page;  $home/mypage.htm
..
..
MENU: SUB1
CLASS;    MNAME;    LINK
00.05.01; My Page;  $home/mypage.htm
..
..

If you have the menu with the menu class 00.01 opened and you click on the "My Page" link, phpCMS opens the page mypage.htm and then it has to decide, which menu should be displayd as 'active'. There are two possibilities in phpCMS to find out which is the right menu class for the current parsed content file.

  1. You have placed a "{MENU} xx.xx.xx" field in the content files which tells phpCMS which menu class this file belongs to, or
  2. You don't have a {MENU} field in the content file, then phpCMS tries to find the menu class out by comparing the URL with the links of the menu items in the menu file. In our example it will find the first occurence which is the menu class 00.01.01

Both methods have one problem: they all bind the content file to exact one menu class, so if you open the content file via the second link (from the menu with the class 00.05), it will still display the menu item 00.01.01 as 'active' instead of the item 00.05.01.

This is the point where this plugin comes into action. With the phpCMS ExtMenuClass plugin you can configure the menu so that it always displays the correct menu item as 'active', even if a page is linked from more then one position in the menu file.

[edit] Documentation

[edit] Installation instructions

Step 1:

Copy the file phpcms_extmenuclass.php to the plugin directory of your phpCMS installation (normaly this is something like /parser/plugs)

Step 2:

Include the plugin as a static plugin at the beginning of your page template file:

{PLUGIN FILE="$plugindir/phpcms_extmenuclass.php" TYPE="STATIC"}

If you have phpCMS ExtMenuClass installed in a different directory, you must point to the correct path, of course.

Attention: it is important, that the plugin is placed in the template before the line where the menu is included in the template. If the plugin is placed after that line (e.g. at the end of the template) the menu was already included into the layout when the plugin runs so it can't make any changes to the menu anymore.

Step 3:

You have to place the line

{MENU} EXTMENUCLASS

in all content-files, for which it should be able to change the menu class via the external parameter (and of course you have to remove the old {MENU} field if it existed in the content file). This is mainly for security reasons. So if you don't have placed that menu field in a content file and you try to change the menu class for that file via the external parameter, it simply won't work and phpCMS will ignore the external menu class.

Step 4:

You have to add a field with the name "EXTMENUCLASS" to the menu file and add the parameter "ON" to this field for all menu items which are called from more than one position in the menu file.

For example:

MENU: MAIN
CLASS;    MNAME;       LINK;                EXTMENUCLASS
00.01;    My Page;     $home/mypage.htm;    ON
00.02;    Submenu1;    $home/sub1.htm;
00.02;    Submenu2;    $home/sub2.htm;

MENU: SUB1
CLASS;    MNAME;       LINK;
00.01.01; Other Page1; $home/otherpage1.htm;
00.01.02; Other Page2; $home/otherpage2.htm;

MENU: SUB1
CLASS;    MNAME;       LINK;                EXTMENUCLASS
00.02.01; My Page;     $home/mypage.htm;    ON
00.02.02; Other Page3; $home/otherpage.htm;


In this example we have a main-menu with two submenus. The content file "mypage.htm" is called from the main menu and the second submenu, all other pages are only called from one location. To make the plugin run correctly we have to add the fieldname "EXTMENUCLASS" to the two menus, where we have a link to the "mypage.htm" file and add the parameter "ON" to these two menu items.

Step 5:

Clear the cache via the phpCMS GUI.

That's all.

If you now browse your site, phpCMS should automatically append the parameter ?&extmenuclass=xx.xx.xx to all links with the EXTMENUCLASS field set to "ON" in the menu-file, so for our example from above, the links to the file "mypage.htm" will be changed automaticaly to

$home/mypage.htm?&extmenuclass=00.01 

and

$home/mypage.htm?&extmenuclass=00.02.01 

respectively.

If you want to see this plugin in action, have a look at:

http://www.drachenreiter.de/stammtisch.html and http://www.drachenreiter.de/stammtisch.html?extmenuclass=00.03.03.01

and see how the correct item is always hightlighted in the menu.

[edit] Caching

The phpCMS ExtMenuClass plugin has an effect on the caching of some pages. The problem is, that pages with the "{MENU} EXTMENUCLASS" field can't be cached. Otherwise it won't work that the same page is displayed with two different menu classes. But if you include the plugin as 'STATIC' it switches the caching off by itself when it discovers the "{MENU} EXTMENUCLASS" field in a content file. All other files will be cached as usual, so the plugin won't have any effect on the caching of pages which don't have the "{MENU} EXTMENUCLASS" field set.

The phpCMS ExtMenuClass will disable the caching only for pages which have the "{MENU} EXTMENUCLASS" field set, all other pages can be cached as usual.

[edit] Special Features

You can change the name of the parameter from "extmenuclass" to whatever you want. You only have to change the line

$parameterName = 'extmenuclass';

to something different in the sourcecode of phpcms_extmenuclass.php

Be aware that this also changes the name of the parameter in the menu file and in the content files, so if you change the name of the parameter in the sourcecode to

$parameterName = 'mymenuclass';

You will also have to place

{MENU} mymenuclass 

in the content file (step 3 of the installation guide) and your menu file will look something like:

MENU: SUB1
CLASS;    MNAME;       LINK;                MYMENUCLASS
00.02.01; My Page;     $home/mypage.htm;    ON

(step 4 of the installation guide)

[edit] Development status / known bugs

No known bugs at the moment. Found any bugs? Then please contact me!

[edit] Version History

31.04.2003 V0.1

  • First public release

Main Page: Main Page | Top Page: Plugin Documentation MainPage

Personal tools