On Mon, 09 Jun 2008 12:52:26 +0200,  wrote:
> A.L.E.C wrote:
>> I think it would be good start for plugins API to get rid of
>> hardcoded actions from index.php.
> Absolutely!
> 
>> My proposition is to create file for each action (filename =
>> actionname) in tasks directories, and then we have:
>> 
>> foreach(array('plugins', 'steps') as $dir) if 
>>
>
(file_exists('program/'.$dir.'/'.$RCMAIL->task.'/'.$RCMAIL->action.'.inc'))
>>  { @include_once('program/'.$dir.'/'.$RCMAIL->task.'/_init.inc'); //
>>  init actions (renamed func.inc)
>> 
>>
>
@include_once('program/'.$dir.'/'.$RCMAIL->task.'/'.$RCMAIL->action.'.inc');
>>  @include_once('program/'.$dir.'/'.$RCMAIL->task.'/_destroy.inc'); //
>>  post actions break; }
>> 
>> 
>> plugins directory it's just for possibility to overwrite built-in
>> action with plugin action.
> This works fine as long as you validate the $RCMAIL->task variable and
> it only works for a single plugin.
> 
> And instead of focusing on files I'd recommend creating a plugin 
> directory that contains a well-defined "init.php" file which then 
> registers calls to plugin handlers (that's how Squirrelmail does it - 
> and it works quite well).
> Another way is to override classes, like Typo3 does, but this has the 
> drawback that some constellations don't work together.
> 
> My recommendation would be something like this:
> 
> /myplugin/init.php:
>       init_plugin('init', 'functionname');
>       init_plugin('showmail', 'functionname');
> 
> That way the plugin does not have to provide empty files - and using the 
> @ is not a good coding practice - instead do a file_exists!

You might also use the Drupal[1] way of defining plugin actions (called
modules and 'hooks' in Drupal):

One a plugin is registered in RC, do a function_exists() on
<module_name>_<action>. For example a plugin called 'filter' on the 'show'
action:

Roundcube:
exec_plugins('show', $email, $var2);

function exec_plugins($action) {
  $params = func_get_args();
  foreach ($registered_plugins as $plugin_name) {
    $function = $plugin_name .'_'. $action;
    if (function_exists($function)) {
      call_user_func_array($function, $args);
    }
  }
}

Plugin:
function filter_show(&$email_details, $var2) {
  // do stuff with email
}


-H-

[1] http://drupal.org

_______________________________________________
List info: http://lists.roundcube.net/dev/

Reply via email to