Plugins

Development related discussion.
User avatar
Jack
Advanced Member
Posts: 666
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Plugins

Post by Jack » Wed Jan 04, 2012 12:57 am

The current plan is to completely change how the plugin system works, no ideas yet but just letting people know.
Last edited by Jack on Wed Jan 04, 2012 12:58 am, edited 1 time in total.

User avatar
Jack
Advanced Member
Posts: 666
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Re: Plugins

Post by Jack » Sun Jan 22, 2012 12:04 am

The new plugin system has been finalised.



Traq 3.0 will be using FishHook 4.0, a custom library I created for Traq.



FishHook 3.0 used code evaluation, which while very very dangerous, didn't restrict what could be done to the variables that came before the "hook" call.



FishHook 4.0 has been rewritten to make things more secure. The way FishHook 4.0 works is, you have your plugin file "myplugin.php" which is a class, inside that class is a collection of methods.



To add these methods to FishHook so it can run them when the "myhook" hook is called, you would call the FishHook::add(); method, like so:

Code: Select all


FishHook::add('myhook', array('myclass', 'mymethod'));

 


Now the "myhook" hook passes variables to the plugins, like so:

Code: Select all


$fruit  = array(

  'Apple',

  'Banana'

);

FishHook::run('myhook', array(&$fruit));

 


And the plugins method looks like:

Code: Select all


function mymethod(&$fruit) {

    $fruit[] = 'Orange'

}

 


Notice that the plugins method doesn't make use of "return" or "global", but will still add Orange to the fruit array.



This is possible because FishHook 4.0 passes variables as references, allowing plugins to modify the variable, not completely replace it, you can see this by the use of '&' before the variables.
Last edited by Jack on Sun Jan 22, 2012 12:08 am, edited 1 time in total.

User avatar
arturo182
Advanced Member
Posts: 151
Joined: Mon Mar 22, 2010 10:28 am
Contact:

Re: Plugins

Post by arturo182 » Fri Feb 24, 2012 7:38 pm

Plugins should also be allowed to have their own translation files.

Maybe the (base) locale class could iterate through the plugins and add their locale string to itself.



Another thing - install/uninstall.

If the plugin has to make modifications to the db (for example add a table), when will it do it? Having it add it's sql when activating and remove it when deactivating is not the best idea cause if a plugin keeps it's settings in the db and you deactive it and then active it again, all settings are lost.

Here's how I see it:

- there's no install option, when you active a plugin it checks if it's fields/tables exist, if not - create them.

- there is an uninstall option for deactivated plugins, a special function in the plugin is called which removes all the plugin's sql and (maybe) deletes the plugin file/dir. This option should probably have a confirm dialog ;)
Last edited by arturo182 on Fri Feb 24, 2012 9:26 pm, edited 1 time in total.

User avatar
Jack
Advanced Member
Posts: 666
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Re: Plugins

Post by Jack » Sat Feb 25, 2012 12:54 am

Yes, I will be adding install/uninstall and enable/disable features to the plugins shortly.



I have an idea for the plugin locale strings.



I'll set it up so that loading a locale file is done like so:


Code: Select all


Locale::load('enus');

 


Then when plugins are loaded, the method "init()" will be called, this will be used to add their hooks to the hook system and load locales like so:


Code: Select all


class MyPlugin

{

    public static function init()

    {

        FishHook::add(...);

        Locale::plugin_locale('MyPlugin');

    }

}

 


The method "plugin_locale" may be different, it will look for, say 'ruRU' and fallback to enUS if it cannot be found in the plugins "locale" directory.



If the file exists, it will load the file, that will pretty much be:


Code: Select all


<?php

return array(

    'new_string' => "My new string"

);

 


All plugin locale strings will be accessed via "myplugin.new_string".
Last edited by Jack on Sat Feb 25, 2012 12:58 am, edited 1 time in total.

User avatar
Jack
Advanced Member
Posts: 666
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Re: Plugins

Post by Jack » Thu Mar 22, 2012 8:21 pm

Been doing some thinking about plugins and how to go about handling the install, enable, disable and uninstall stuff for them.



Perhaps something like this:

Code: Select all


class MyPlugin

{

    public static function __install();

    public static function __enable();

    public static function __disable();

    public static function __uninstall();

}

 


Also been thinking about how plugins will ago about adding stuff to the database, mainly permissions.



I was thinking something like this:

Code: Select all


class MyPlugin

{

    public static function __install()

    {

        Permission::create_default($action, $value);

    }

}

 

User avatar
arturo182
Advanced Member
Posts: 151
Joined: Mon Mar 22, 2010 10:28 am
Contact:

Re: Plugins

Post by arturo182 » Tue Jul 24, 2012 8:23 am

So how about them plugins?



I think that plugins should be little apps that have their own controllers/models/views folders there should also be a way to add new routes and permissions.



For example if I wanted to add a "news" plugin which would add a new site (/news) and permissions (view_news, add_news), also a hook to add nav tabs would be needed. I would have to create a new controller, model and views.



I also have an idea for a avatars plugin, so a hook to add custom profile field is needed, also a way to add user's avatar before his name everywhere in Traq.



I'm not saying it has to be done for 3.0, but somewhere in the future.
Traq, yo!

User avatar
Jack
Advanced Member
Posts: 666
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Re: Plugins

Post by Jack » Tue Jul 24, 2012 11:47 am

My plan is to allow plugins to register controller and view locations with the framework, not sure when though, but I will get to it, I want to do it a certain way.

User avatar
Jack
Advanced Member
Posts: 666
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Re: Plugins

Post by Jack » Thu Jul 26, 2012 7:25 am

Well the plugin system is pretty much done, there's two things left to do.



The first is to move the plugin system into the framework, so the framework can be hooked into and not just Traq.



The last is to add plugin hooks everywhere.



If anyone wants to start requesting plugin hooks now you are welcome to do so, just point out the files + line numbers and the variables you need access to.

User avatar
Jack
Advanced Member
Posts: 666
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Re: Plugins

Post by Jack » Sat Jul 28, 2012 12:51 am

Here's an example plugin for anyone wanting to create plugins:

Code: Select all


class Plugin_myplugin

{

    public static function init()

    {

        FishHook::add('model:__get', array('Plugin_myplugin', 'username'));

    }



    // The model name, variable name and model data is passed.

    // The return value of the Model::__get() method is also passed, but as a reference.

    // All you need to do is $val = "modified value";

    // No need to return anything.

    public static function username($model, $var, $data, &$val)

    {

        if ($model == 'User' and $var == 'name' and $data['group_id'] == 1)

        {

            $val = "[b]{$val}[/b]";

        }

    }

}

 
Last edited by Jack on Sat Jul 28, 2012 11:10 am, edited 1 time in total.

User avatar
arturo182
Advanced Member
Posts: 151
Joined: Mon Mar 22, 2010 10:28 am
Contact:

Re: Plugins

Post by arturo182 » Sat Jul 28, 2012 6:53 am

You're missing a ")" in the FishHook::add line.



Also, hook request:

Ability to add new .css and .js files to the page head, so probably file system\views\default\layouts\default.php about line 10.
Last edited by arturo182 on Sat Jul 28, 2012 7:16 am, edited 1 time in total.
Traq, yo!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests