Testing whether a plugin is actually installed

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Testing whether a plugin is actually installed

Post by yellowled »

Okay, so I know I can use serendipity_showPlugin to emit a plugin at almost any location in a blog. I also know how to suppress it's output in the sidebars. But is there a way to check whether a plugin is actually installed ... in smarty?

Here's what I'd like to do - in "fake" smarty:

Code: Select all

{if $plugin is installed}
{serendipity_showPlugin ...}
{else}
<p>You need to install ... for this feature.</p>
{/if}
YL
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Testing whether a plugin is actually installed

Post by garvinhicking »

Hi!

No, not in Smarty. You'd need to use PHP for that. I'm not even sure if there's an API method to check for it, so you'd need to query the serendipity_plugins Database.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Testing whether a plugin is actually installed

Post by yellowled »

garvinhicking wrote:No, not in Smarty. You'd need to use PHP for that. I'm not even sure if there's an API method to check for it, so you'd need to query the serendipity_plugins Database.
Yikes! Okay, thanks anyway :)

YL
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

If you want plugin output, could you call a hook specific to that plugin, and check for empty?

I suppose it really depends on whether you control both the plugin and the template, or just the template.
Judebert
---
Website | Wishlist | PayPal
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Post by yellowled »

judebert wrote:If you want plugin output, could you call a hook specific to that plugin, and check for empty?
I'm afraid I'm going to need a code example for that ...

YL
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Okay, here's what I'm thinking:

Modify the plugin in question to include a "generate_content" hook. This hook actually creates the HTML you want; you could actually just store the output before returning it from the plugin's regular hook and provide the same data for generate_content.

In Smarty, call the generate_content hook and assign it to a variable. (Sorry if I get the specifics wrong, I'm in the middle of a lot of stuff and can't look it up right now.) {capture assign="plugin_available"}{hook_event hook="generate_content"}{/capture}

In Smarty, check the variable's contents and print everything out only if it was generated:
{if $plugin_available}<div name="plugin_name">{$plugin_available}</div>{/if}

We may even be able to go general with this. Now I'm imagining an "capability" hook, which we would call with a capability name string. If a plugin existed to provide that capability, it would return the event hook to call to get its output. If the variable was empty, no plugin can do it.

So, it'd look like:

Code: Select all

{capture assign="weather_hook"}
{hook_event hook="capability" data="weather"}
{/capture}
{if $weather_hook}
<div name="weather_summary" class="sidebarItem">
{hook_event hook=$weather_hook}
</div>
{/if}
Then we could use any number of plugins to provide weather data. If no such plugins existed, no weather data would be printed. If more than one existed, only the first would return his hook (they'd all be programmed to return empty if a hook was already specified). Templates could tell if plugins providing a capability were available or not.
Judebert
---
Website | Wishlist | PayPal
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Post by yellowled »

judebert wrote:Modify the plugin in question to include a "generate_content" hook.
I'm deeply sorry, but this is the point where you lost me :) I'm still no coder, so I can't say much about this. It does, however, sound like something we should have in general, but I'm far from being able to say anything about whether this is doable and/or remotely possible in terms of performance, security, and all the other things you guys have to deal with.

Maybe Garvin can give this some thought, although I imagine it would be a great effort to modify all plugins.

YL
Post Reply