Fork me on GitHub
Subscribe 2

Ticket #70 (fixed enhancement)

Simplify generate_navlinks() function

  • Created: 2010-07-08 00:52:53
  • Reported by: Gizzmo
  • Assigned to: Reines
  • Milestone: 1.4.5
  • Component: code
  • Priority: low

I suggest the follow change to remove defining multiple links. ie the search link is there 3 times, profile and logout is there twice. It will also allow mod authors to add a link right before profile or right after profile with out multiple changes.

if ($pun_user['is_guest'])
{
    if ($pun_user['g_read_board'] == '1' && $pun_user['g_search'] == '1')
        $links[] = '<li id="navsearch"'.((PUN_ACTIVE_PAGE == 'search') ? ' class="isactive"' : '').'><a href="search.php">'.$lang_common['Search'].'</a></li>';

    $links[] = '<li id="navregister"'.((PUN_ACTIVE_PAGE == 'register') ? ' class="isactive"' : '').'><a href="register.php">'.$lang_common['Register'].'</a></li>';
    $links[] = '<li id="navlogin"'.((PUN_ACTIVE_PAGE == 'login') ? ' class="isactive"' : '').'><a href="login.php">'.$lang_common['Login'].'</a></li>';
}
else
{
    if (!$pun_user['is_admmod'])
    {
        if ($pun_user['g_read_board'] == '1' && $pun_user['g_search'] == '1')
            $links[] = '<li id="navsearch"'.((PUN_ACTIVE_PAGE == 'search') ? ' class="isactive"' : '').'><a href="search.php">'.$lang_common['Search'].'</a></li>';

        $links[] = '<li id="navprofile"'.((PUN_ACTIVE_PAGE == 'profile') ? ' class="isactive"' : '').'><a href="profile.php?id='.$pun_user['id'].'">'.$lang_common['Profile'].'</a></li>';
        $links[] = '<li id="navlogout"><a href="login.php?action=out&amp;id='.$pun_user['id'].'&amp;csrf_token='.pun_hash($pun_user['id'].pun_hash(get_remote_address())).'">'.$lang_common['Logout'].'</a></li>';
    }
    else
    {
        $links[] = '<li id="navsearch"'.((PUN_ACTIVE_PAGE == 'search') ? ' class="isactive"' : '').'><a href="search.php">'.$lang_common['Search'].'</a></li>';
        $links[] = '<li id="navprofile"'.((PUN_ACTIVE_PAGE == 'profile') ? ' class="isactive"' : '').'><a href="profile.php?id='.$pun_user['id'].'">'.$lang_common['Profile'].'</a></li>';
        $links[] = '<li id="navadmin"'.((PUN_ACTIVE_PAGE == 'admin') ? ' class="isactive"' : '').'><a href="admin_index.php">'.$lang_common['Admin'].'</a></li>';
        $links[] = '<li id="navlogout"><a href="login.php?action=out&amp;id='.$pun_user['id'].'&amp;csrf_token='.pun_hash($pun_user['id'].pun_hash(get_remote_address())).'">'.$lang_common['Logout'].'</a></li>';
    }
}

INTO

if ($pun_user['is_admmod'] || $pun_user['g_read_board'] == '1' && $pun_user['g_search'] == '1')
    $links[] = '<li id="navsearch"'.((PUN_ACTIVE_PAGE == 'search') ? ' class="isactive"' : '').'><a href="search.php">'.$lang_common['Search'].'</a></li>';

if ($pun_user['is_guest'])
{
    $links[] = '<li id="navregister"'.((PUN_ACTIVE_PAGE == 'register') ? ' class="isactive"' : '').'><a href="register.php">'.$lang_common['Register'].'</a></li>';
    $links[] = '<li id="navlogin"'.((PUN_ACTIVE_PAGE == 'login') ? ' class="isactive"' : '').'><a href="login.php">'.$lang_common['Login'].'</a></li>';
}
else
{
    $links[] = '<li id="navprofile"'.((PUN_ACTIVE_PAGE == 'profile') ? ' class="isactive"' : '').'><a href="profile.php?id='.$pun_user['id'].'">'.$lang_common['Profile'].'</a></li>';

    if ($pun_user['is_admmod'])
        $links[] = '<li id="navadmin"'.((PUN_ACTIVE_PAGE == 'admin') ? ' class="isactive"' : '').'><a href="admin_index.php">'.$lang_common['Admin'].'</a></li>';

    $links[] = '<li id="navlogout"><a href="login.php?action=out&amp;id='.$pun_user['id'].'&amp;csrf_token='.pun_hash($pun_user['id'].pun_hash(get_remote_address())).'">'.$lang_common['Logout'].'</a></li>';
}

History

Paul 2010-07-12 18:19:14

One thing that occurred to me when I was tinkering with templates is why is this a function at all.  Since it appears on every single page why not simply put the code in header.php and implode the array directly in the str_replace. The code which adds optional elements could be a function which returns a modified array.

Reines 2010-07-22 11:23:54

  • Milestone set to 2.0-beta1.

fg123 2010-08-08 06:10:06

That's kind of what I thought Paul.

Since it is in everypage, why not move it to header? I have to search through a lot of files to find that. And it's hard to edit it... hmm

Reines 2011-01-30 21:56:27

  • Milestone changed from 2.0-beta1 to 1.4.5.

Reines 2011-02-02 16:19:59

  • Priority changed from normal to low.

Reines 2011-02-07 22:22:20

  • Owner set to Reines.
  • Status changed from open to fixed.

I've now moved this into header.php and tidied it up slightly.

https://github.com/fluxbb/fluxbb/commit … 314fdd4cdd