SimpleMAINlink

Summary: Add a link to your Main Home Page
Version: 0.1
Prerequisites: PMWiki, of course. Beeblebrox Theme
Status: beta
Maintainer: Brooks Kelley
Categories: Links/Page handling

Questions answered by this recipe

If you would like your TitleFmt links to contain a reference to your Main group's home page when in a sub-group in a skin like Beeblebrox?, then you will enjoy this little hack I just did.

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

Description

This recipe adds a link to your TitleFmt part of your skins template that allows users of your site to navigate to the Main Homepage if the Main group is no longer linked because you are in another group.

For example,

Group >> Page

becomes

Main >> Group >> Page

But, it does not create a link for Main if it is in the Main group already, so it will not create

Main >> Main >> Page from Main >> Page

I did this for my [(approve links) edit diff] site to make it look a little more slick for those navigating the pages. ( note: go into one of the repeater map locations and you will see it in action at this site )

It is for very simple navigation and I have not tested in a more complex environment with sub-folders containing WIKI pages. Maybe I will and Maybe I won't. I just don't know yet.

Here is how to do what I did though ...

1. Open up your command shell or favorite editor and create a php file in the cookbook folder called createmainhomepagelink.php and paste this script into it and save it with the appropriate permissions to your cookbook/ folder ( notice it is not ended with a ?>, that is what you should do because of a quirk in PHP and the way it handles includes ) ...

<?php
$CurrentURL = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$RealPageName = strrev( $_SERVER['REQUEST_URI']);
$RealPageName = strrev( substr( $RealPageName, 0 , strpos($RealPageName,"/")));
$RealPageName = substr( $RealPageName, 0, strpos( $RealPageName,".php")) . ".php";
$RealPWD = substr( $CurrentURL, 0, strpos( $CurrentURL, $RealPageName ));
$CurrentURLinREV = strrev($CurrentURL);
$GroupPlace = strpos($CurrentURLinREV, strrev($RealPageName));
$GroupPart = strrev( substr( $CurrentURLinREV, 0, $GroupPlace ));
$GroupEquals = strpos( $GroupPart, "n=" ) + 2;
$GroupDOT = strpos( $GroupPart, "." ) - 3;
$RealGroupName = substr( $GroupPart, $GroupEquals , $GroupDOT );
if ( $RealGroupName == "Main" ) {
$MainLink = "";
}
else
{
$MainLink = "<a href=\"" . $RealPWD . $RealPageName . "?n=Main.HomePage\" >Main</a>" . " »" ;
}
if ( $GroupEquals == 2 ) {
$MainLink = "";
} ;

2. Then add this line to local/config.php

include_once('cookbook/createmainhomepagelink.php');

3. Modify the skin's tmpl file, say, like the Beeblebrox? gila.tmpl file located at pub/skins/beeblebrox-gila2, to include $MainLink in front of the first breadcrumb ...

<!--TitleFmt-->
<div id="breadcrumbs">
$MainLink
<a href="$ScriptUrl/$Group">$Group</a> »
<a href="$PageUrl">$Title</a>
</div>
<!--/TitleFmt-->

And that is it.

Notes

For the most part, I like to avoid using PERL expressions to pull out the Group name. So, I did not use $GroupPattern as a means to pull this information out. I guess it is because I tend to think in terms of BASH scripts where I use tac, rev, and cut to quickly extract URL information more rapidly than a SED script with reg-ex would. I am assuming that it is the same case in php and I am not really slowing down my page renderings by doing so.

Release Notes

I released this on 14 January 2007. I will probably not make any revisions as it is a really simple script based on a simple URL where "n=" is used to access the page name. For example, pmwiki.php?n=Main.HomePage and pmwiki.php?n=Group.Page If I change that, my script will not work and then I have to come up with a work around. Case in point, the URL for this page would not work with this recipe. Your location bar is saying /wiki/Cookbook/SimpleMAINlink.

But, if it gives you ideas and you want to run with it to do more, do so by all means. It is GPLed as far as I am concerned. Just give me credit in your creation for however this script helped you ( or you could give me your credit card number and expiration date instead, har har ).

I have to thank PM because it was his pmwiki.php page that showed me all I needed to know in order to create this script. Thanks PM for creating your fantastic WIKI!

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

Comments

See Also

Brooks Kelley's SED script in ConvertTABLE

Contributors

Brooks Kelley 14 January 2007

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.