News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Subs.php / Menu Help

Started by 420Connect.co.uk, March 11, 2015, 12:51:46 PM

Previous topic - Next topic

420Connect.co.uk

I've been tweaking my subs / main menu to suit my liking but seem to have some issue with the code..

It doesn't throw any errors like it is but I've mucked up some code and some of the the sub-sub-buttons aren't displaying at all. & I'd also like to add in some more once I get this solved!

If someone wouldn't mind fixing the below code to make the sub-menu buttons for the calendar work, I should be able to use the new code as a template for my additional ones I'd like to add in..

Many thanks as always!  :)



~ solved by removing the show variable..
// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.
if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'] . '-' . empty($context['disable_sp']), $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated'])
{
$buttons = array(
'home' => array(
'title' => $txt['home'],
'href' => $modSettings['sp_portal_mode'] == 3 && empty($context['disable_sp']) ? $modSettings['sp_standalone_url'] : $scripturl,
'show' => true,
'sub_buttons' => array(

'calendar' => array(
'title' => $txt['calendar'],
'href' => $scripturl . '?action=calendar',
'show' => $context['allow_calendar'],
'sub_buttons' => array(
'view' => array(
'title' => $txt['calendar_menu'],
'href' => $scripturl . '?action=calendar',
'show' => !empty($context['allow_calendar_event']),
),
'post' => array(
'title' => $txt['calendar_post_event'],
'href' => $scripturl . '?action=calendar;sa=post',
'show' => !empty($context['allow_calendar_event']),
),
),


),
'tags' => array(
'title' => $txt['smftags_menu'],
'href' => $scripturl . '?action=tags',
'show' => true,
),
'search' => array(
'title' => $txt['search'],
'href' => $scripturl . '?action=search',
'show' => $context ['allow_search'],

),
'admin' => array(
'title' => $txt['admin'],
'href' => $scripturl . '?action=admin',
'show' => $context['allow_admin'],
'is_last' => true,
),
),
),
'forum' => array(
'title' => empty($txt['sp-forum']) ? 'test' : $txt['sp-forum'],
'href' => $scripturl . ($modSettings['sp_portal_mode'] == 1 && empty($context['disable_sp']) ? '?action=forum' : ''),
'show' => in_array($modSettings['sp_portal_mode'], array(1, 3)) && empty($context['disable_sp']),
'sub_buttons' => array(
),

// This is where help use to be!!!
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Shambles

Is this solved?

I guess so, as there's a showing.

Kindred

BTW: for sanity's sake, indents are your friend
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

420Connect.co.uk

Okay, I thought I was getting the hang of this but maybe not.. :P
(& Tab doesn't indent on my keyboard :( )

I'm going to unmark this as solved and I've attached my full Subs.php file..

I think I possibly have some parts of a MOD left over that is causing things to not work as they should?

I'm having great difficulty re-expanding my 'Admin' drop-down list and frequently get an error on testing about the line ";" from ");" under the menu structure..

Thanks a million to anyone who can help clean this up!
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

margarett

It's easier to ask: how do you want it to be? Maybe you can do a mockup image of how it should be?
Because now, your first button "home", has bunch of other buttons inside it. But if you put all of those side-by-side, you'll get a *massive* menu which will probably go beyond your forum width.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

420Connect.co.uk

Hey Bruno!  ;D

I'm pretty happy with how I've got it set up for now, (m)any more on display does wrap onto the next line and I'd like to avoid that, hence exploring sub-menus..

From my Subs.php I'd like to add in the only change I'd like to make is have the usual sub-menu items that are usually found in 'admin' :

'sub_buttons' => array(
'featuresettings' => array(
'title' => $txt['modSettings_title'],
'href' => $scripturl . '?action=admin;area=featuresettings',
'show' => allowedTo('admin_forum'),
),
'packages' => array(
'title' => $txt['package'],
'href' => $scripturl . '?action=admin;area=packages',
'show' => allowedTo('admin_forum'),
),
'errorlog' => array(
'title' => $txt['errlog'],
'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
'show' => allowedTo('admin_forum') && !empty($modSettings['enableErrorLogging']),
),
'permissions' => array(
'title' => $txt['edit_permissions'],
'href' => $scripturl . '?action=admin;area=permissions',
'show' => allowedTo('manage_permissions'),
'is_last' => true,
),


But I can't seem to add these back in without getting errors :(

I've also another set of "sub_buttons", I'm looking to add into another file, but they too throw errors when I try to add them in.  :-\
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Shambles

If you're struggling, make your [failing] edits to Subs.php then attach that file here.

420Connect.co.uk

Thanks for dropping back in!  :P
Flying visit but thank you very much and my Subs with failing admin submenu's attached!
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Shambles

What an abomination. Gawd only knows how many "things" have edited that file - indentation all over the place and array closures were mismatched in 5 places.

Meh, either way. I tidied it up and the attached should parse correctly.

Whether it behaves correctly is another matter....


420Connect.co.uk

 :-[ Yeah.. I've added and removed A LOT of mod's whilst trying to shape the site, with some maybe leaving behind traces and can only really blame myself for the awful indentation and I'm probably the cause of the array mismatches too :( - I've a lot to learn!

Anyway, Thank you a million for tidying up the file - Really appreciated!  :-*
Unfortunately when I 'tried it on', it didn't behave as expected - most of my menu buttons were part of the same button now (Home / or 'Discussions' on my site, with lots of different sub-menu's extending from it.)
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

margarett

Quote from: 420connect.info on March 14, 2015, 12:28:06 PM
:-[ Yeah.. I've added and removed A LOT of mod's whilst trying to shape the site, with some maybe leaving behind traces
That's why I suggested you that you need to consider a fresh set of files and just deploy what you really need ;) (you should do it in a duplicate forum, of course)

Let me try to have a look.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

margarett

Try it like this (although your theme must support 2nd level sub-menus)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Illori

Quote from: margarett on March 16, 2015, 07:56:51 AM
Try it like this (although your theme must support 2nd level sub-menus)


but rename the file to Subs.php without the (1)

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

420Connect.co.uk

Hey,

Just tried on that latest version and it looks as if it's working as expected :D

Yey!

Many thanks everyone who's helped here! - You're amazing! :)

& The only thing holding me back from a fresh set of files, is the number of tweaks I've made to so many files, so it's a bigger job than just a set of fresh files.. .. I don't really want to lose anything I've got so far but will definitely look into rebuilding it in some way, without the unnecessary mod's I've tried in the past etc.
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

420Connect.co.uk

One last thing on the menu for now!

I have this in another file. It adds it's own menu button by merging into the existing menu.. I'm sure you're familiar with the idea..

anyway I have the below code in place and although it doesn't cause any errors, it won't show my added sub-buttons? - I tried different amounts of ")," after it; thinking thats what was wrong but that seems to throw an errow.  :-[


function sg_add_menu(&$menu_buttons)
{
global $modSettings, $txt, $scripturl;

$fnd = 0;
reset($menu_buttons);

while((list($key, $val) = each($menu_buttons)) && $key != 'arcade')
$fnd++;

$menu_buttons = array_merge(
array_slice($menu_buttons, 0, $fnd),
array(
'sgroups' => array(
'title' => !empty($modSettings['sgroups_menu_title']) ? $modSettings['sgroups_menu_title'] : $txt['sgroups_text'],
'href' => $scripturl . '?action=sgroups',
'show' => allowedTo('sgroups_view'),
'active_button' => false,
'sub_buttons' => array(
'Add Group' => array(
'title' => $txt['groupadd'],
'href' => $scripturl . '?action=sgroups;sa=add',
'show' => $context['allow_calendar'],
),
'My Groups' => array(
'title' => $txt['groupmy'],
'href' => $scripturl . '?action=sgroups;sa=list',
'show' => $context['allow_calendar'],
),
'All Groups' => array(
'title' => $txt['groupall'],
'href' => $scripturl . '?action=sgroups;sa=list;gid=1',
'show' => $context['allow_calendar'],
),
'Search' => array(
'title' => $txt['groupsearch'],
'href' => $scripturl . '?action=sgroups;sa=search',
'show' => $context['allow_calendar'],
),
'Stats'=> array(
'title' => $txt['groupstats'],
'href' => $scripturl . '?action=sgroups;sa=stats',
'show' => $context['allow_calendar'],
                                        ),
),
),
),
array_slice($menu_buttons, $fnd)
);
}



* Unlimited tea/coffee provided :P
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

margarett

You can't use spaces in array keys

Try it like this
<?php

function sg_add_menu(&$menu_buttons)
{
global $modSettings$txt$scripturl;

$fnd 0;
reset($menu_buttons);

while((list($key$val) = each($menu_buttons)) && $key != 'arcade')
$fnd++;

$menu_buttons array_merge(
array_slice($menu_buttons0$fnd),
array(
'sgroups' => array(
'title' => !empty($modSettings['sgroups_menu_title']) ? $modSettings['sgroups_menu_title'] : $txt['sgroups_text'],
'href' => $scripturl '?action=sgroups',
'show' => allowedTo('sgroups_view'),
'active_button' => false,
'sub_buttons' => array(
'sg_add_group' => array(
'title' => $txt['groupadd'],
'href' => $scripturl '?action=sgroups;sa=add',
'show' => $context['allow_calendar'],
),
'sg_my_groups' => array(
'title' => $txt['groupmy'],
'href' => $scripturl '?action=sgroups;sa=list',
'show' => $context['allow_calendar'],
),
 'sg_all_groups' => array(
'title' => $txt['groupall'],
'href' => $scripturl '?action=sgroups;sa=list;gid=1',
'show' => $context['allow_calendar'],
),
'sg_search' => array(
'title' => $txt['groupsearch'],
'href' => $scripturl '?action=sgroups;sa=search',
'show' => $context['allow_calendar'],
),
'sg_stats'=> array(
'title' => $txt['groupstats'],
'href' => $scripturl '?action=sgroups;sa=stats',
'show' => $context['allow_calendar'],
),
),
),
),
);
}


?>


edit: why are you performing another array_slice?
--> array_slice($menu_buttons, $fnd)
This was incorrectly placed inside the array, I removed it.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

420Connect.co.uk

Ahh, okay I'll try and remember that no spaces rule for next time, (if there is one!)

& when I swapped in the new code I was getting an error on line 67 of the file..

"Parse error: syntax error, unexpected ')'

& the array_slice was already there from the original file..  ???

full file attached / will remove if I should and thanks a million as always!

edit:
tried the original version, with _'s replacing the spaces but no luck :(
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

margarett

Try this, then
<?php

function sg_add_menu(&$menu_buttons)
{
global $modSettings$txt$scripturl;

$fnd 0;
reset($menu_buttons);

while((list($key$val) = each($menu_buttons)) && $key != 'arcade')
$fnd++;

$menu_buttons array_merge(
array_slice($menu_buttons0$fnd),
array(
'sgroups' => array(
'title' => !empty($modSettings['sgroups_menu_title']) ? $modSettings['sgroups_menu_title'] : $txt['sgroups_text'],
'href' => $scripturl '?action=sgroups',
'show' => allowedTo('sgroups_view'),
'active_button' => false,
'sub_buttons' => array(
'sg_add_group' => array(
'title' => $txt['groupadd'],
'href' => $scripturl '?action=sgroups;sa=add',
'show' => $context['allow_calendar'],
),
'sg_my_groups' => array(
'title' => $txt['groupmy'],
'href' => $scripturl '?action=sgroups;sa=list',
'show' => $context['allow_calendar'],
),
 'sg_all_groups' => array(
'title' => $txt['groupall'],
'href' => $scripturl '?action=sgroups;sa=list;gid=1',
'show' => $context['allow_calendar'],
),
'sg_search' => array(
'title' => $txt['groupsearch'],
'href' => $scripturl '?action=sgroups;sa=search',
'show' => $context['allow_calendar'],
),
'sg_stats'=> array(
'title' => $txt['groupstats'],
'href' => $scripturl '?action=sgroups;sa=stats',
'show' => $context['allow_calendar'],
),
),
),
),
array_slice($menu_buttons$fnd)
);
}


?>
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

420Connect.co.uk

Again they wouldn't appear but I had a idea to try using a different 'show' variable thing and it worked! :D

Many thanks once again Bruno!

You're amazinggg!

:-*

Forever grateful!



marks solved!
www.420Connect.co.uk ~ A Social Network For The #CannabisCommunity ~ Come say "High" ;)

Advertisement: