Revision [3507]

This is an old revision of WikkaMenulets made by GeorgePetsagourakis on 2004-12-19 23:20:52.

 

Wikka Menulets


As part of my proposal for a general overhaul of the WikkaMenus menu management system in WikkaWiki, I suggest we should turn the current system-generated items that occur in the main menu and footer menu into modular menulets, i.e. mini-actions generating content for menu items.
Any of these mini-actions can of course be used in pages as well.

Here's a list of potential menulets and their output, feel free to add your suggestions.

<?php
if ($this->GetUser()) {
        echo "You are ".$this->Format($this->GetUserName()); #i18n
}
?>

Here's my take (untested!):
<?php
// define output format (i18n)
define('WHO_OUT', "You are %1");    # %1 is either user name or remote address
// get name or remote address
if ($this->GetUser())
{
    $who = $this->Format($this->GetUserName());
}
else
{
    if (isset($_SERVER['REMOTE_HOST']))
    {
         $who = $_SERVER['REMOTE_HOST'];
    }
    else
    {
         $who = $_SERVER['REMOTE_ADDR'];
    }
}
// display output
echo str_replace(' ','&nbsp',sprintf(WHO_OUT, $who));
?>

By putting the whole phrase in a define, we are taking care of differences in word order in different languages; at the output stage we replace spaces by no-breaking spaces to keep the whole string together. This also takes care of usage of {{who}} in the main_menu (displaying address instead of user name). --JavaWoman
"Nice way of doing it JavaWoman.
<?php
// define output format (i18n)
define('WHO_OUT', "You are %1");    # %1 is either user name or remote address
// get name or remote address
$who = ($this->GetUser()) ? $this->Format($this->GetUserName()) : ( (isset($_SERVER['remote_host'])) ? $_SERVER['remote_host'] : $_SERVER['remote_addr'] ) ;
// display output
echo str_replace( ' ', '&nbsp', sprintf(WHO_OUT, $who));
?>
Here is a smaller take on the same code... -- GeorgePetsagourakis
Ya, it's smaller - but not faster. In fact, it's exactly the same thing, just harder to read. I just happen to like readable code. I wrote it like that for a reason: it's faster to maintain. ;-) --JavaWoman
"It is probably cause I never had the chance to use the (condition)? smth : oth_th ; syntax and I am so excited about it .. :D --GeorgePetsagourakis
<?php
echo $this->VERSION;
?>

...

DarTar, can you post your code for these actions here? The way some of the menu items are formatted now should be improved - but if this little project moves ahead (I hope) we might as well do it in the "menulets" action code instead of the current code. And new code should be ready for i18n as well (I don't know if yours is...) --JavaWoman


CategoryDevelopment
There are 18 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki