Revision [3572]

This is an old revision of UserMenus made by ChristianBarthelemy on 2004-12-21 13:59:40.

 

User defined menus

Last edited by ChristianBarthelemy:
Alternate solution for user defined menus
Tue, 21 Dec 2004 13:59 UTC [diff]


There is already a solution to create, manage and use menus from WikkaMenus. I was troubled because it allows any WikiUser to change any menu, possibly changing so the interface used by the other users. Also I wanted something closer from the users, allowing them to design icon-menus if they want.

An alternate solution

So I came with a simple idea that any user could simply define a WikiPage named UserLogonMenu where he would simply type in the menu he wants using the standard wikka formatting. He may define the ACLs of this menu page as he wish. This solution is perfectly compliant with the WikkaMenulets too.

The header.php and the stylesheet needs to be slightly changed so that when the system finds a page named UserLogonMenu it simply use it as the user menu. It also allows the admin to design an alternate GuestMenu for unidentified users.
I decided to have a class different from the "header" one but this is not mandatory.

The code

This code relies on the ExistsPage()function available from 1.1.6.0.
It also include the LoggedUsersHomepage proposal.

New header.php - the lines commented by only if you wish a different presentation are not mandatory
<?php
    $message = $this->GetMessage();
    $user = $this->GetUser();
      $site_base = $this->GetConfigValue("base_url");
      if ( substr_count($site_base, 'wikka.php?wakka=') > 0 ) $site_base = substr($site_base,0,-16);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <title><?php echo $this->GetWakkaName().": ".$this->PageTitle(); ?></title>
    <base href="<?php echo $site_base ?>" />
    <?php if ($this->GetMethod() != 'show') echo "<meta name=\"robots\" content=\"noindex, nofollow\"/>\n";?>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="keywords" content="<?php echo $this->GetConfigValue("meta_keywords") ?>" />
    <meta name="description" content="<?php echo $this->GetConfigValue("meta_description") ?>" />
    <link rel="stylesheet" type="text/css" href="css/<?php echo $this->GetConfigValue("stylesheet") ?>" />
    <link rel="stylesheet" type="text/css" href="css/print.css" media="print" />
    <script language="JavaScript" type="text/javascript">
        function fKeyDown()
        {
            if (event.keyCode == 9)
            {
                event.returnValue = false;
                document.selection.createRange().text = String.fromCharCode(9);
            }
        }
    </script>
</head>

<body
    <?php echo (!$user || ($user["doubleclickedit"] == 'Y')) && ($this->GetMethod() == "show") ? "ondblclick=\"document.location='".$this->href("edit")."';\" " : "" ?>
    <?php echo $message ? "onLoad=\"alert('".$message."');\" " : "" ?>
>

<div class="header">
    <h2><?php echo $this->config["wakka_name"] ?> : <a href="<?php echo $this->href("", "TextSearch", "phrase=").urlencode($this->GetPageTag()); ?>"><?php echo $this->GetPageTag(); ?></a></h2>
    <?php
        if ($this->GetUser()) {
            $username=$this->GetUserName();
            $usermenu=$username."Menu";
            if ($this->ExistsPage($usermenu)) {
                $themenu=$this->LoadPage($usermenu);
                echo '</div><div class="menuicon">'; //only if you wish a different presentation
                echo $this->Format($themenu["body"]);
                echo "</div>"; //only if you wish a different presentation
            }
            else
            {
                echo ($this->GetUser() ? $this->Link($this->config["logged_in_homepage"]) : $this->Link($this->config["root_page"]))." :: ";
                echo $this->config["logged_in_navigation_links"] ? $this->Format($this->config["logged_in_navigation_links"])." :: " : "";
                echo "You are ".$this->Format($this->GetUserName());
            }
        } else {
            if ($this->ExistsPage(GuestMenu)) {
                echo '</div><div class="menuicon">';  //only if you wish a different presentation
                $themenu=$this->LoadPage(GuestMenu);
                echo $this->Format($themenu["body"]);
                echo "</div>";  //only if you wish a different presentation
            }
            else
            {
                echo $this->Link($this->config["root_page"])." :: ";
                echo $this->config["navigation_links"] ? $this->Format($this->config["navigation_links"]) : "";
            }
        }
    ?>  
</div>


Add something like this in the style sheet file if you want a different presentation for these menus
.menuicon {  
    color: #333;
    background: #CCCCCC;
    text-align: center;  
}


Menu samples

You may have something like:
[[HomePage Home]] - {{edit}} - [[PageIndex Index]] - [[FormattingRules Writing rules]] - SandBox - [[UserSettings Settings]] - [[UserName My Home]]

Or more sexy like (I already use an icons folder but the user could upload its own icons using the files action:
{{image alt="Home Page" title="Home Page" url="icons/32/home.png" link="HomePage"}}{{imageedit alt="Edit Page" title="Edit this page" url="icons/32/pen.png"}}{{image alt="Index" title="Pages Index" url="icons/32/dictionary.png" link="PageIndex"}}{{image alt="Formatting Rules" title="Formatting Rules" url="icons/32/Whiteboard.png" link="FormattingRules"}}{{image alt="Sandbox" title="Sandbox" url="icons/32/paddle.png" link="SandBox"}}{{image alt="User Settings" title="Change Settings/Logout" url="icons/32/kgpg.png" link="UserSettings"}}{{image alt="User Page" title="My own page" url="icons/32/identity.png" link="UserName"}}
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki