Announcement

  •  » Extensions
  •  » Detect from theme if a certain plugin is active

#16 2013-11-26 17:43:43

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: Detect from theme if a certain plugin is active

it's fragile but there is no other way

that's because I want (published) theme creators to modify templates as few as possible and only play with CSS

by the way my "selectors" are very simple, you could manage to keep the same classes for your theme

Offline

 

#17 2013-11-26 17:56:05

marjolein
Member
Amsterdam, NL
2013-11-10
29

Re: Detect from theme if a certain plugin is active

flop25 wrote:

Do you need the basic bricks, like urls, to build your own integration of that plugin: the plugin doesn't provide them and you're trying to create them?

More generally I'm trying to work out a cleaner method of integrating plugins and templates that does not involve HTML markup in PHP code, but have all of that markup in templates which a template writer then can access or replace with something functionally equivalent that matches the theme.

In the case of UC (but not only that!) it uses "fragile" prefilter to do a search-and-replace in the template - there is not template for that (yet). So I created the template and a variable to make its existence known to the theme. That way you get a clean separation between logic (PHP) and presentation (HTML+CSS).

My theme is going to be technically very "clean" with strict separation between HTML, CSS and script (and the latter only as an add-on, all the basic operations should work without JS as well). It means I have to figure out various mechanisms to accomplish that within the framework of Piwigo, but I'm well on my way with that. :)
Because it's a theme I'm writing, I do my best to limit my code to templates (and its themeconf.inc.php and such), and only "touch" PHP processes when absolutely needed for templates (such as extracting markup and putting it in a template) - I'm not touching any major logic at all.

Last edited by marjolein (2013-11-26 18:10:05)

Offline

 

#18 2013-11-26 18:03:06

flop25
Piwigo Team
2006-07-06
7037

Re: Detect from theme if a certain plugin is active

I think Mistic100 that's about what we have already discussed a long time ago: a plugin which relies on prefilter for its integration must provide Smarty variables to allow its easy integration using only template files and manipulation
Like plugins on WordPress
If I understand well, which is not sure


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#19 2013-11-26 18:03:14

marjolein
Member
Amsterdam, NL
2013-11-10
29

Re: Detect from theme if a certain plugin is active

mistic100 wrote:

it's fragile but there is no other way

that's because I want (published) theme creators to modify templates as few as possible and only play with CSS

by the way my "selectors" are very simple, you could manage to keep the same classes for your theme

I'm not criticizing you - but yes, the method is fragile but there is another way. What I want to accomplish is that theme authors don't have to dig in PHP code to find the markup they need to change... If you're using a templating tool (like Smarty, or another one), markup has no place in PHP at all.

Keep in mind that Piwigo is just a new program for me - it's by no means the first time I've been doing this sort of thing... Markup in PHP always causes tears in a templating environment. UC was also not the first plugin where I noticed this - it's just a good starting point because its interaction with a theme is not trivial. :)

Offline

 

#20 2013-11-26 18:15:23

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: Detect from theme if a certain plugin is active

flop25 wrote:

I think Mistic100 that's about what we have already discussed a long time ago: a plugin which relies on prefilter for its integration must provide Smarty variables to allow its easy integration using only template files and manipulation
Like plugins on WordPress
If I understand well, which is not sure

I don't remember this discution :)

the problem for me is that themes MUST handle ALL possible variables exposed by plugins
I can't imagine how this would be possible, there are some "placeholders" like $PLUGIN_INDEX_ACTIONS but we can't add this kind of variables everywhere


@marjolein : you said there is another way... but you didn't say which one

Offline

 

#21 2013-11-26 18:23:16

marjolein
Member
Amsterdam, NL
2013-11-10
29

Re: Detect from theme if a certain plugin is active

Well, to summarize where I am now:

- I've replaced the prefilter search-and-replace with a template (all markup) and setting a template variable that contains the  (absolute) path to the template
- the template exists, the prefilter call is no longer done, the template variable is actually being assigned since I can display it in my template

Except,
- I don't want to just display it in my template :)
- I want to test for its existence and then act accordingly from an event handler rather than doing such logic from a template (where it has no business being)
- The only question seems to be now: which event do I need to 'handle' to actually access this template variable? (I see $template->get_template_vars() all over the place so that bit cannot be the problem).

Offline

 

#22 2013-11-26 18:31:18

marjolein
Member
Amsterdam, NL
2013-11-10
29

Re: Detect from theme if a certain plugin is active

mistic100 wrote:

@marjolein : you said there is another way... but you didn't say which one

Well, the first step is to use templates and variables. :-)  That way each theme author is free to use the provided template as-is or use a functionally equivalent variant that fits in with the theme. Themes and plugins don't bite each other that way.

Which is what I'm working on now. The next step is a way to communicate which plugin variables are available for templates to use - a simple approach might be another global array variable - but I haven't tackled that bit yet: I'm doing things step by baby step. ;-)

But it's not exceptional that relatively independent parts of an application communicate with each other via a sort of "bulletin board". (In fact, in Object-oriented designs this is very common.) We should find a way for Piwigo to do such communication. :)

Offline

 

#23 2013-11-26 18:34:49

marjolein
Member
Amsterdam, NL
2013-11-10
29

Re: Detect from theme if a certain plugin is active

marjolein wrote:

- The only question seems to be now: which event do I need to 'handle' to actually access this template variable? (I see $template->get_template_vars() all over the place so that bit cannot be the problem).

Or maybe I can create another event - just after this variable I need has been assigned? If I can do that - how?

Offline

 

#24 2013-11-26 19:23:53

marjolein
Member
Amsterdam, NL
2013-11-10
29

Re: Detect from theme if a certain plugin is active

marjolein wrote:

marjolein wrote:

- The only question seems to be now: which event do I need to 'handle' to actually access this template variable? (I see $template->get_template_vars() all over the place so that bit cannot be the problem).

Or maybe I can create another event - just after this variable I need has been assigned? If I can do that - how?

Stupid  me - that bit I could find out by myself :) And did:

Right after assigning the template variable ("communicating" to the theme where the template is to be found), I added a line:

Code:

trigger_event('collection_actions_path_published');  ##TEST##

And then I changed my event handler to handle this event instead of 'loc_end_index', and hey presto now both my template and the event handler have access to the needed (and "communicated") template variable. Maybe this code just falls through the cracks of event triggers otherwise and there's no (core) event that gives access to this state?

So now I just need to put my logic into place in my event handler.

Apart from the fact that I'm not too happy with the naming of that event: shouldn't the plugin name be part of it? And an 'after' keyword?

Are there rules for naming events?

Cheers, happy again ! :-)
-- Marjolein

Offline

 

#25 2013-11-26 20:18:22

marjolein
Member
Amsterdam, NL
2013-11-10
29

Re: Detect from theme if a certain plugin is active

IT WORKS!

I now have the HTML in place, and basically only need to update the stylesheet (which effectively means ripping out code rather than adding more :-))

Thanks both for your help, I was hitting a mental block...

-- Marjolein

Offline

 

#26 2013-11-26 21:18:10

flop25
Piwigo Team
2006-07-06
7037

Re: Detect from theme if a certain plugin is active

I see two things there :

@mistic100: you don't get it : what I mean is the plugins should assign variables in case of problem of integration. Of course, the themes can't handle all plugins, but the plugin can provide either a variable {$PLUGFOO_FORM} or a set of variables {$PLUGFOO_FORM.id}..., in order to let the user or the designer do the integration, when the search-and-replace mechanism can't work

and on the other hand, we have here a perfect example of a designer which can't think programmation in a template, using all the features of the powerful Smarty, with {if} and modifier

for instance, in WP http://wordpress.org/plugins/breadcrumb … tallation/  http://wordpress.org/plugins/wp-pagenavi/installation/ can be handled by themes due to there popularity but they provide a way to install them. In Piwigo that kind of lugin would use the prefiltering system and assign variables too


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#27 2013-11-26 21:23:19

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: Detect from theme if a certain plugin is active

Ok I get it

fact is that (in that particular case) it's already the case : we are talking about a prefilter, if the prefilter fails and the theme creator knows the prefilter will fail he can still use the variables (with a nice {if isset()})

remember that we have only one instance of Template (except the ones for email) so until the tpl file is parsed, absolutely all vars are available anywhere

Offline

 

#28 2013-11-26 21:25:42

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: Detect from theme if a certain plugin is active

Actually I don't see any situation where what you want is not already doable...

Offline

 

#29 2013-11-26 21:27:45

flop25
Piwigo Team
2006-07-06
7037

Re: Detect from theme if a certain plugin is active

mistic100 wrote:

it's already the case : we are talking about a prefilter, if the prefilter fails and the theme creator knows the prefilter will fail he can still use the variables (with a nice {if isset()})

indeed, that's mostly the case, nothing is done to facilitate the access to those information, and eventually simplify the variables. Im' to blame too with my plugins ^^


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#30 2013-11-26 22:18:21

marjolein
Member
Amsterdam, NL
2013-11-10
29

Re: Detect from theme if a certain plugin is active

mistic100 wrote:

remember that we have only one instance of Template (except the ones for email) so until the tpl file is parsed, absolutely all vars are available anywhere

Anywhere in any template or child template, yes.

But I'm still puzzled by the fact that I "had to" create an extra event to get access to a template variable from an event handler in my theme. I'm quite happy it works now - I just would like to understand why I (apparently) had to add that event.

BTW, stylesheet sorted, too. On to the next plugin that does one of those prefilter search-and-replace :) (OpenStreetMap - where I found it first) :-D

Good night all!
-- Marjolein

Offline

 
  •  » Extensions
  •  » Detect from theme if a certain plugin is active

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact