MyBB Community Forums

Full Version: $collapsed from global.php in plugin templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone. Recently I was doing some stuff on my forum like adding sidebar. It is maintained by plugin that is getting some data (like time online) from database and representing it in "top x" form. It uses it's own templates in global (not theme ones) and when I wanted to add collapse and expand functionality it worked. But there is only one problem - it's not saving state of collapsed sidebar items. I was checking and yes, my forum adds information to cookie file, even adds it to $collapsed, but plugin seems to not be able to reach $collapsed in it. Maybe it's because I use wrong hooks?
Does someone know when $collapsed is used internally by MyBB to read collapsed states? Which hook I should use to get this information? I was working on it for 3 days now and still no luck, so I decided to ask here, maybe someone know how to read that variable in plugin. Thanks for any help or advice.
Not entirely familiar with how MyBB uses $collapsed, but it's tough to give an exact answer because I don't know what sidebar plugin you're using or what the code looks like for this. Are you trying to collapse the entire sidebar on every page or on the index or something specifically? Could you paste your code?

Edit: some files that may be useful for you to look at as well:
https://github.com/mybb/mybb/blob/e9d557...al.js#L591
https://github.com/mybb/mybb/blob/d83c5d....php#L1105
Searching on the git repo never hurts either Big Grin
I found this parts of code even in my copy of MyBB, but it was helpless.
Plugin is called TopStats - it's polish plugin as far as I know. Sidebar is added on index page and I want to collapse only "part" of sidebar, for example simple table with some important links. It can collapse and expand, it IS saved even in collapsed cookie. But when plugin generates it's own top tables it isn't able to read $collapsed like it is not created yet. That was the point where I started to think that there's a hook or something when MyBB have created $collapsed content already and I can just isnert it to read collapsed states of my tables. When I try to reach this states in just index page template I was able to succesfully read it. It seems that my plugin runs before MyBB even creates $collapsed php variable from global.php.
(2017-07-26, 08:42 PM)Shiraishi Wrote: [ -> ]That was the point where I started to think that there's a hook or something when MyBB have created $collapsed content already and I can just isnert it to read collapsed states of my tables. When I try to reach this states in just index page template I was able to succesfully read it. It seems that my plugin runs before MyBB even  creates $collapsed php variable from global.php.

In fact I think this is the exact issue. If you look here you can see that the $collapsed var is created just before global_end, but well after global_start. TopStats hooks into global_start and index_end. Try adjusting the plugin so that the $collapsed logic is checked in its own specific method that hooks into global_end and see if that works.
Okay I found what I have to do. It's really simple...

Just had to add $collapsed to global variables in plugin, so plugin was able to read it. It was that simple...

Thanks for your help.
(2017-07-26, 09:13 PM)Shiraishi Wrote: [ -> ]Okay I found what I have to do. It's really simple...

Just had to add $collapsed to global variables in plugin, so plugin was able to read it. It was that simple...

Thanks for your help.

Hah! That was my next guess, happens to me all the time when I add templates. Glad you figured it out!
Take a look at it, should solve your problem: https://github.com/mybb/mybb/blob/b68cce...#L486-L498