event hook for plugin configuration save?

Creating and modifying plugins.
Post Reply
User avatar
RobA
Regular
Posts: 317
Joined: Wed Apr 27, 2005 5:11 pm
Contact:

event hook for plugin configuration save?

Post by RobA » Mon Jun 13, 2005 3:33 pm

I'm ntrying to improve performance of the glossary plugin I put together. Currently, the plugin parses out the word/definition pairs every time the frontend_display event fires, then goes into the searh/replace function through the article body.

Is there an event hook that can be used so this parsing can only be done once (and saved to variables), when the plugin configuration gets saved? Pointers to other examples would also be helpful.

Thanks in advance,

Rob A>

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: event hook for plugin configuration save?

Post by garvinhicking » Mon Jun 13, 2005 3:38 pm

There'd be two ways to do that:

1. Use PEAR::Cache_Lite to only parse the key/value pairs once in frontend_display and then fetch the return array to operate on

2. Serialize the result of your variable munging into an array and then store that array via set_config which you can then later user

Apart from that, your Plugin will also improve pretty much when using the entryproperties caching; then it will parse your glossary/definitions only once per entry and the next time only when you modify the entry. :)

Regards,
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/

User avatar
RobA
Regular
Posts: 317
Joined: Wed Apr 27, 2005 5:11 pm
Contact:

Post by RobA » Mon Jun 13, 2005 5:03 pm

How does one enable the entryproperties caching? Is this a separate plugin?

Alternately, if I were to use suggestion (2), Im guessing the process would be something like....
    define an additional array using $propbag->add()
    create a new cleanup() function to parse and store using set_config()
    change the generate_content in the event_handler to acces this using a get_config() call.

Seems correct?

Also - in alot of the plugins I am seeing hooks for cacheable_events like:

$propbag->add('cachable_events', array('frontend_display' => true));

and install() and uninstall() functions like these:

Code: Select all

    function install() {
        serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
    }

    function uninstall() {
        serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
        serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
    }


What is this for...and when should they be used in a plugin?

Thanks in advance
-Rob A>

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Mon Jun 13, 2005 6:47 pm

Hi Rob!

Yes, the entryproperties caching is a seperate plugin, bundled. It's called "Extended Properties" and has a config option for caching. That's also what the "cachable events" hooks are for. You can look at the contentrewrite plugin or the bbcode plugin, both properly define those events and are skipped if a cached presentation of your entry is used.

About suggestion 2, that's not exactly what I meant. It would be more like:

1. Leave introspection as is
2. When your frontend_display is called you do things like:
foreach ($config AS $bla) {
...
}
And after that you'll do a str_replace($from, $to, $entry['body']) or something like that, right?
What I image now would be that you put the whole foreach() stuff where you fetch items like this:
- require the PEAR::Cache Lite
- Use the Function cache (I don't know the commands by hand; look at the DNSURBL spamblock plugins, they use the PEAR Lite Function cache)
- Store $from and $to in the cache
- Use $frmo and $to from the cache, if PEAR Cache returns that to you; only if it's not existing do the repetition

Best regards,
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/

User avatar
RobA
Regular
Posts: 317
Joined: Wed Apr 27, 2005 5:11 pm
Contact:

Post by RobA » Tue Jun 14, 2005 12:17 am

Think I'll just make it compatable with your entryproperties caching. As said before, I have limited experience with php, so most of my this is cut and paste from examples based on how I would do it in other languages :) I think I'll avoid the PEAR::Cache Lite until I have a better feel for php.

Is there a guide to the calls, or just follow the example of the bbcode?

TIA-

Rob A>

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Tue Jun 14, 2005 12:11 pm

There is no propper guide, so I'd just follow the example of bbcode. I think the easiest cache-supporting plugin is the serendipity_event_nl2br plugin. That does not have as much overhead like bbcode or emoticate...

Regards and have fun,
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/

Post Reply