Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: ricktee76 on March 02, 2013, 03:24:19 PM

Title: SSI menubar (re)fix
Post by: ricktee76 on March 02, 2013, 03:24:19 PM
A couple of days ago i came across this problem on my localhost test site and read up on here about some fixes, i decided that i'd try to shorten the amount of pages that needed editing, here's what i came up with.
It allows you to put the forum menu on any page anywhere on your website, just remember to edit the link to reflect which directory your forum is installed in.

I've edited 2 files and created a new function called login_menu_ext(for external login) which allows you to use the forum ssi_menubar with all the links working.
mywebsite.co/forum

*remember to change /forum to whatever directory your forum is in.

in the file you want the menu to appear, add the SSi code where you want it:
ssi_menubar();

in themes/{yourtheme}/index.template.php above the line:
// Show the menu up top. Something like [home] [help] [profile] [logout]...

add this to create an new function for using the menu outside the forum directory:

//modified menu at top ext(external)
function template_menu_ext()
{

global $context, $settings, $options, $scripturl, $txt;

echo '
<div id="main_menu">
<ul class="dropmenu" id="menu_nav">';

foreach ($context['menu_buttons'] as $act => $button)
{


$button['href'] = str_replace($button['href'],"forum/index.php?action=$act",$button['href']);
//$button['target'] = $button['href'];



echo '
<li id="button_', $act, '">
<a class="', $button['active_button'] ? 'active ' : '', 'firstlevel" href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '>
<span class="', isset($button['is_last']) ? 'last ' : '', 'firstlevel">', $button['title'], '</span>
</a>';
if (!empty($button['sub_buttons']))
{
echo '
<ul>';



foreach ($button['sub_buttons'] as $act => $childbutton)
{


$childbutton['href'] = str_replace($childbutton['href'],"forum/index.php?action=$act",$childbutton['href']);

// moderate links
if ($childbutton['href'] == "forum/index.php?action=reports") {
$childbutton['href'] = "forum/index.php?action=moderate;area=reports";

}

// profile links
// DONT CHANGE THE ORDER OF THE PROFILE LINKS
// OR YOU WILL GET 2 LINKS TO PROFILE INSTEAD OF ONE TO PROFILE AND
// ONE TO FORUMPROFILE

if ($childbutton['href'] == "forum/index.php?action=profile") {
$childbutton['href'] = "forum/index.php?action=profile;area=forumprofile";

}

if ($childbutton['href'] == "forum/index.php?action=summary") {
$childbutton['href'] = "forum/index.php?action=profile";

}

if ($childbutton['href'] == "forum/index.php?action=account") {
$childbutton['href'] = "forum/index.php?action=profile;area=account";

}

// members menu links
if ($childbutton['href'] == "forum/index.php?action=mlist_search") {
$childbutton['href'] = "forum/index.php?action=mlist;sa=search";

}

if ($childbutton['href'] == "forum/index.php?action=mlist_view") {
$childbutton['href'] = "forum/index.php?action=mlist";

}


//message links

if ($childbutton['href'] == "forum/index.php?action=pm_read") {
$childbutton['href'] = "forum/index.php?action=pm";

}

if ($childbutton['href'] == "forum/index.php?action=pm_send") {
$childbutton['href'] = "forum/index.php?action=pm;sa=send";
  }

// admin links

if ($childbutton['href'] == "forum/index.php?action=featuresettings") {
$childbutton['href'] = "forum/index.php?action=admin;area=featuresettings";

}

if ($childbutton['href'] == "forum/index.php?action=packages") {
$childbutton['href'] = "forum/index.php?action=admin;area=packages";

}

if ($childbutton['href'] == "forum/index.php?action=errorlog") {
$childbutton['href'] = "forum/index.php?action=admin;area=errorlog";

}

if ($childbutton['href'] == "forum/index.php?action=permissions") {
$childbutton['href'] = "forum/index.php?action=admin;area=permissions";

}
// end of rewrite

echo '
<li id="button_', $act, '">
<a href="', $childbutton['href'], '"', isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', '>
<span', isset($childbutton['is_last']) ? ' class="last"' : '', '>', $childbutton['title'], !empty($childbutton['sub_buttons']) ? '...' : '', '</span>
</a>';
// 3rd level menus :)
if (!empty($childbutton['sub_buttons']))
{
echo '
<ul>';

foreach ($childbutton['sub_buttons'] as $act => $grandchildbutton)
$grandchildbutton['href'] = str_replace($grandchildbutton['href'],"forum/index.php?action=$act",$grandchildbutton['href']);
echo '
<li>
<a href="', $grandchildbutton['href'], '"', isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', '>
<span', isset($grandchildbutton['is_last']) ? ' class="last"' : '', '>', $grandchildbutton['title'], '</span>
</a>
</li>';

echo '
</ul>';
}

echo '
</li>';
}
echo '
</ul>';
}
echo '
</li>';
}

echo '
</ul>

</div>';

}






in the file forum/SSI.php
replace:

// Display a menu bar, like is displayed at the top of the forum.
function ssi_menubar($output_method = 'echo')
{
global $context;

if ($output_method == 'echo')
template_menu();
// What else could this do?
else
return $context['menu_buttons'];
}


with:


// Display a menu bar, like is displayed at the top of the forum.
function ssi_menubar($output_method = 'echo')
{
global $context;

if ($output_method == 'echo')
template_menu_ext();
// What else could this do?
else
return $context['menu_buttons'];

}


      
So far this is working perfectly, if you need to modify links make a note of the address:

The formula is pretty simple e.g.

if ($childbutton['href'] == "WHERE ITS SENDING US") {
$childbutton['href'] = "WHERE WE WANT TO GO";

}



not tried 3rd level links yet but i'm certain the same will apply to them as they are generated in the same way.

Good Luck :)