A.L.E.C wrote:
> I think it would be good start for plugins API to get rid of hardcoded 
> actions from index.php. So, we have such code:
> 
> // include task specific files
> if ($RCMAIL->task=='mail') {
>   include_once('program/steps/mail/func.inc');
> 
>   if ($RCMAIL->action=='show' || $RCMAIL->action=='preview' || 
> $RCMAIL->action=='print')
>     include('program/steps/mail/show.inc');

Well, the hard-coded includes are not very nice and could be replaced by a 
controller class or just an array mapping tasks/actions to a certain file.

I don't like the approach to use request parameters like $RCMAIL->task and 
$RCMAIL->action directly in include paths. This could open some security 
vulnerabilities. Even file_exists() will succeed if you want to include 
some password files.

I'd suggest to use an object oriented approach to define and register 
plugins. How about this:

class my_rcube_plugin extends rcube_plugin
{

function __construct()
{
   $this->add_hook('login', array($this, 'mlogin'));
   $this->register_action('foo', array($this, 'myfoo'));
   $this->add_toolbar_button('compose', ...);
   $this->add_folder_item(...);
}

function mylogin($p)
{
   $p['username'] = 'foo';
   $p['password'] = 'bar';
   return $p;
}

function myfoo()
{

}

}

The base class rcube_plugin will implement all the internal functions and 
add the registered actions and hooks to the according controller.

Each plugin should have it's separate folder within the plugin directory 
and we define a fixed name (eg. init.php) where the class name and more 
details (like the task where it belongs to) are defined. If we require the 
class file to be named as the class (in our case it would be 
my_rcube_plugin.php) it will work with our auto-loader. For performance 
reasons we can cache the contents of all init.php files to prevent from 
traversing the whole plugin directory on each request.

I don't see a reason why the init-file shouldn't be written in PHP since 
people who write a plugin have to do this in PHP as well and thus have 
basic knowledge about this language.

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

Reply via email to