News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

[WIP] Menu Button Manager mod

Started by Kays, February 21, 2013, 06:03:11 PM

Previous topic - Next topic

Arantor

I don't know, but I removed it from being cached myself.

Kays

LOL, not quite the answer I expected from you. :D

In looking at caching, a number of items which don't require too much processing are cached. Yet the array for that buttons, which could require quite some processing (especially if several mods add buttons using hooks) isn't cached. Since it is called on every page load and rarely changes, I think it is something which should be cached. Plus this mod adds additional processing yet.... ;)

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Arantor

That's the thing. There really is no logic that actually makes any sense for it to be cached at level 2 in SMF. The menu is basically a static declaration in an unmodified SMF install; it doesn't have any funny business to it or expensive dynamic calls. allowedTo calls are not the cheapest they could be, but they're also not that expensive either in the scheme of things. It's actually not worth caching them.

In Wedge's case other stuff ends up in the menu (error log count, moderated posts count, unapproved members count etc) and in the end we concluded it wasn't worth actually caching it when all the little pieces are cached anyway.

Kays

I agree, with the default menu it's not a big deal since the additional processing to the permission calls is removing the buttons a user can't see. But if there are several buttons installed by mods which each need to slice and dice the array to place the buttons of which SD is an extreme example. Then I think that there might be an argument for caching it.

Originally it was a tossup between either caching the whole buttons array or just the permission calls. If I do go ahead with this, it looks like the latter is probably best and easiest way to do it. Do you see any problems with caching it on a per user basis?

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Arantor

While it's perfectly feasible to do, the big issue with doing it is that you're likely to push meaningful stuff out of the cache simply by way of the number of items there.

I haven't looked at the mod lately, hard to say if this would be a huge deal, but the ideal approach IMHO in this case is to try to cache the structure and not the specific values, if that makes sense. Capture that a given button is controlled by a permission and capture the permission, and cache *that* information. Permission calls are cheap in the scheme of things (it's an in_array test against an array that is already loaded and itself potentially subject to caching) so I wouldn't worry about that so much.

Kays

Quote
While it's perfectly feasible to do, the big issue with doing it is that you're likely to push meaningful stuff out of the cache simply by way of the number of items there.

Thanks, that's what I was wondering about.

Quote
but the ideal approach IMHO in this case is to try to cache the structure and not the specific values, if that makes sense. Capture that a given button is controlled by a permission and capture the permission, and cache *that* information.

Basically, that's how I'm doing it already. The structure is written to file, so that is already cached. To get the permissions, I loop through the three levels of the $buttons array and build a separate array with the button name as the index and the permission setting, 0 or 1 as the value. This is checked against when the bottoms are processed using !empty(). It's this permissions array which I'm now thinking of caching

In rethinking it, unlike a full menu, this doesn't need to be done on a per user basis, but rather by member groups. Which I think should be easier on the cache. Or maybe should I just give up on this idea. ::)

Thanks for your input on this.:)

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

tMicky

Quote from: Kays on April 22, 2013, 10:03:23 AM
Quote
While it's perfectly feasible to do, the big issue with doing it is that you're likely to push meaningful stuff out of the cache simply by way of the number of items there.

Thanks, that's what I was wondering about.

Quote
but the ideal approach IMHO in this case is to try to cache the structure and not the specific values, if that makes sense. Capture that a given button is controlled by a permission and capture the permission, and cache *that* information.

Basically, that's how I'm doing it already. The structure is written to file, so that is already cached. To get the permissions, I loop through the three levels of the $buttons array and build a separate array with the button name as the index and the permission setting, 0 or 1 as the value. This is checked against when the bottoms are processed using !empty(). It's this permissions array which I'm now thinking of caching

In rethinking it, unlike a full menu, this doesn't need to be done on a per user basis, but rather by member groups. Which I think should be easier on the cache. Or maybe should I just give up on this idea. ::)

Thanks for your input on this.:)
Is this mod available for download?

Branko.

Strong people don't put others down, they lift them up.
A clever person solves a problem. A wise person avoids it.

Kays

Thanks Branko. :)

I really should get back to this, finish it up and submit it.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

emanuele

Small issue, I think in ManageButtons.php, function EditMenuUtilities a require_once($sourcedir . '/Subs-Buttons.php'); is missing. ;)


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Kays

Yep, looks like I missed that.  :-[

Updated the archive. No version change.

Thanks :)

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Draffi

WOW!

Thats an awesome Mod!!! I have never seen this before...

Including the possibility to add another Menu bar is....phuuuuhhhh.....WOW!!!!

But i have an error in my error-log, coming all the time:

8: Undefined index: menu_auto_update

in the File ManageButtons.template.php (line 97)

I know, this is still a Beta release, but it would be nice if someone can have a look...

Thank you for this nice piece of coding stuff!

Kays

#52
Hi, thanks for that. :)

To get by that error, replace the line indidcated with the following:


', $category['id'] == 1 && !empty($modSettings['menu_disable_auto_update']) ? '<a href="' . $scripturl . '?action=admin;area=managemenus;findButtons#manage_boards">' . $txt['menu_find_new_buttons'] . '</a>' : '', '

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Draffi

I installed this Mod some days ago - yesterday i installed some other mods, all is working fine.

But now i have strange problem:
I cannot saving the membergroups, who can see the Button.

i choose the permission-method ("By member group"), click "save" = Settings correct saving
i mark the membergroups who can see the button, click "save" = redirect to the overview.

look inside "change Button" - and the membergroups what i was choosing are "unticked"

What can i do? call "hooks.php" from the package again, directly in the browser?

Draffi

#54
Looks like this mod make some trouble:
http://custom.simplemachines.org/mods/index.php?mod=2351

This mod make automatic a menu-button. This i was moving with the Menu-Manager to the "profile" section.

Now, the "open notepad in a popup"-menu item doesnt work, and this is the only button, where i can change the membergroup permissions...

In all the other buttons I can't change the membergroup.

Edited to remove Caps Lock

Kays

Sorry, but I can't replicate that. All works still fine for me. ???

Any errors in  the error log?

Note, during most of the development and testing of this mod I did have that notepad mod installed since it added the buttons using hooks and the popup button is a bit unique.


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Burke ♞ Knight

Quote from: Kays on May 28, 2013, 10:02:30 AM
Hi, thanks for that. :)

To get by that error, replace the line indidcated with the following:


', $menu['id'] == 1 && !empty($modSettings['menu_disable_auto_update']) ? '<a href="' . $scripturl . '?action=admin;area=managemenus;findButtons#manage_boards">' . $txt['menu_find_new_buttons'] . '</a>' : '', '


That now gives this error instead:

8: Undefined variable: menu
File: /Themes/default/ManageButtons.template.php (main sub template - eval?)
Line: 97


EDIT:

Only shows up while in Edit menu buttons section, not Utilities or Settings.

Kays

Ooops.  :-[

That line should be:


', $category['id'] == 1 && !$modSettings['menu_disable_auto_update'] ? '<a href="' . $scripturl . '?action=admin;area=managemenus;findButtons#manage_boards">' . $txt['menu_find_new_buttons'] . '</a>' : '', '

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Burke ♞ Knight

#58
Now getting:

8: Undefined index: menu_disable_auto_update
File: /Themes/default/ManageButtons.template.php (main sub template - eval?)
Line: 97




EDIT:

Also, you might want to consider adding a choice to align the main menu.
You could follow the idea from:
Mod Name: Curve centered menu
Created By: Antechinus

Or have 3 choices:
Left Center Right

Just an idea...

Kays

Grr, my bad...


', $category['id'] == 1 && !empty($modSettings['menu_disable_auto_update']) ? '<a href="' . $scripturl . '?action=admin;area=managemenus;findButtons#manage_boards">' . $txt['menu_find_new_buttons'] . '</a>' : '', '

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Advertisement: