Roundcube Community Forum

Third Party Contributions => Old Style Plug-Ins => Topic started by: corbosman on May 18, 2009, 05:34:15 AM

Title: passing variables/plugin api
Post by: corbosman on May 18, 2009, 05:34:15 AM
Hi all, what is the recommended way to pass state in between calls of functions of a plugin?

As an example.. lets say I want to show the last login of a user in a template. I create a template object, hook into it through plugin api, and add the last login to the content var. But the last_login info from the user object is already modified by then to be the current login time/date. So I need to grab this info at an earlier hook (login_after), and then pass it to the template hook.  (btw, the example userinfo plugin also fails here..it shows the current login time).

Im using a cookie now, but im wondering if there isnt a better way. I cant just create an object variable ($this->last_login) because the data is wiped between login_after and template_object_*.

Also, is there some uniform way to save permanent longterm data as a plugin without having to build my own DB query?  

Regards,

Cor
Title: passing variables/plugin api
Post by: rosali on May 20, 2009, 12:56:17 AM
An idea would be to use the startup hook and to check if $_POST['_user'] is set. If so, query "users" table for "last_login" before it is updated by the login function and save the last login value into the session or a cookie. To avoid a database query for last login on each request, skip the query if the session value or the cookie is already present. I would prefer a session value. Otherwise you have to care to clear the cookie on a request where the user is not authenticated.

To save permanent longtern data not only within a session you could add it to "users" table field "preferences" as a part of the serialized array. I do so e.g. for my password recovery tool (secret question and answer).
Title: passing variables/plugin api
Post by: corbosman on May 20, 2009, 04:06:04 AM
Where can I find your password recovery tool?

Regards,

Cor
Title: passing variables/plugin api
Post by: rosali on May 20, 2009, 07:55:27 AM
Unfortunately it is part of MyRoundCube (see footer). It has not been updated to use the new plugin API yet.