Page 1 of 1

Plugin to allow configuration of sidebar items per category

Posted: Fri Mar 02, 2007 12:48 am
by pickle
Hey all,

I've been mucking around this evening with a plugin that allows you to configure sidebar plugins to be visible depending on the category. For example, you could have an HTML nugget that only displays when the category 'X' (or an article from category 'X') is being displayed.

I wanted to do this per sidebar plugin configuration page, so I added two extra event hooks into the core to be able to tweak these configuration pages on the fly.

There's probably a better way to do this, and I already know a few places where the code isn't particularly efficient.. My excuse is that I've only just picked up the methodology for writing an s9y plugin from existing code (the API docs didn't really cover what I needed, but still helped).. ;)

I'd appreciate constructive comments from those with experience in the s9y codebed! :) Since it's only a few hours old, and I haven't done anything 'serious' in PHP for three years until now, I expect there might be a bug or two.

The plugin, including a diff against version 1.1.1 can be found at <http://simon.butcher.name/uploads/2007/ ... ry-0.1.zip>.

Thanks,

- Simon[/url]

Re: Plugin to allow configuration of sidebar items per categ

Posted: Fri Mar 02, 2007 1:00 am
by garvinhicking
Hi!

Did you check out the plugin 'Hide/Toggle visibility of sidebars' plugin? (serendipity_plugin_sidebarhider from spartacus)?

There should be sufficient event hooks prominent to do this kind of hiding?

I don't have the time to check out your plugin right now, but I'll try to do so the next days! Maybe my reference to the plugin above might be some helpto you...

Bestregards,
Garvin

Re: Plugin to allow configuration of sidebar items per categ

Posted: Fri Mar 02, 2007 1:39 am
by pickle
Hi Garvin,
garvinhicking wrote:Did you check out the plugin 'Hide/Toggle visibility of sidebars' plugin? (serendipity_plugin_sidebarhider from spartacus)?
Seen it, but it's not quite what I was after. What I wanted was to be able to configure the sidebar hiding based on category, and really hide them.

Examples help: If I had categories X, Y and Z, and I wanted a sidebar plugin to only appear when looking at the Z category page, or a full article from Z, I can now do it by configuring that plugin to only display in that category. I can now do this for any sidebar plugin..
garvinhicking wrote:There should be sufficient event hooks prominent to do this kind of hiding?
To hide there was a hook. I hooked frontend_generate_plugins and remove 'hidden' plugins from the array.

Unfortunately, to be able to add a configuration option to all sidebar plugins, this needed two hooks: one for adding configuration options to property bag of the plugin being configured and one for additional introspect_config_item().

The configuration could have been done a number of ways, but I felt it was more "logical" to configure a sidebar plugin's visibility within its own configuration page. I don't know if there are guidelines on the user interface for s9y that would govern this..

Cheers,

- Simon

Re: Plugin to allow configuration of sidebar items per categ

Posted: Fri Mar 02, 2007 1:55 am
by garvinhicking
Hi!
Examples help: If I had categories X, Y and Z, and I wanted a sidebar plugin to only appear when looking at the Z category page, or a full article from Z, I can now do it by configuring that plugin to only display in that category. I can now do this for any sidebar plugin..
Yes, the sidebarhider plugin can do that as well. It's not restricted to adding the hide/show buttons, it can also fixed hide sidebar plugins.
Unfortunately, to be able to add a configuration option to all sidebar plugins, this needed two hooks: one for adding configuration options to property bag of the plugin being configured and one for additional introspect_config_item().
I will need to look at that exactly, but adding a hook there is quite performance intense and should be avoided.

It's a nice idea though to enhance the configuration option from a foreign plugin! So I'll definitely have a look and see what can be done about thatto allow it in a way that doesn't hurt performance too much. Event hooks are quite "costy", especially on parts of the code that are executed many times.

The sidebarhider plugin does it on its own management panel - I think that makes it easier to configure visibility on a central page instead of having to go to each single plugin and configure that. But concerning usability, your approach might be the better one, because that's where people might look at first instance...

Best regards,
Garvin

Re: Plugin to allow configuration of sidebar items per categ

Posted: Sat Mar 03, 2007 2:26 pm
by pickle
Hey Garvin,
garvinhicking wrote:Yes, the sidebarhider plugin can do that as well. It's not restricted to adding the hide/show buttons, it can also fixed hide sidebar plugins.
I didn't realise this at first - that plugin isn't really clear with its description. I've just tried it out, and it adds a lot more than just selecting categories for sidebar plugins. If I had known about it, though, I would have probably just used that!
garvinhicking wrote:I will need to look at that exactly, but adding a hook there is quite performance intense and should be avoided.

It's a nice idea though to enhance the configuration option from a foreign plugin! So I'll definitely have a look and see what can be done about thatto allow it in a way that doesn't hurt performance too much. Event hooks are quite "costy", especially on parts of the code that are executed many times.
Unfortunately yeah, it's costly, and since I don't know the s9y code that well, I don't know if the places I've put the hooks are the best ones. With regards to the hook that emulates introspect_config_item(), I've tried to only call it when an item was not found within the plugin, hopefully reducing event hook calls.

With event hooks calling configuration bits and pieces, I can see the code becomes pretty inefficient. :(

Cheers,

- Simon

Re: Plugin to allow configuration of sidebar items per categ

Posted: Sun Mar 04, 2007 12:09 am
by garvinhicking
Hi!
I didn't realise this at first - that plugin isn't really clear with its description. I've just tried it out, and it adds a lot more than just selecting categories for sidebar plugins. If I had known about it, though, I would have probably just used that!
Yeah, the problem is that this functionality was only added later to the plugin, and initially it only cared about hiding/showing - so maybe you have an idea to update the description of that plugin to make it clearer for people?

I haven'T yet had the chance because of my flu to look at your code, but it's still on my radar :)

Regards,
Garvin

Re: Plugin to allow configuration of sidebar items per categ

Posted: Tue Mar 06, 2007 6:53 pm
by pickle
garvinhicking wrote:Yeah, the problem is that this functionality was only added later to the plugin, and initially it only cared about hiding/showing - so maybe you have an idea to update the description of that plugin to make it clearer for people?
Fwoar - nah, you don't want me to suggest something. I'm the worst person to write copy :)
garvinhicking wrote:I haven'T yet had the chance because of my flu to look at your code, but it's still on my radar :)
It's alright, I understand entirely: I was hit by the flu on Sunday and I'm all fuzzy and incoherent now myself. Not really a good state of mind to read someone else's code.. :)