 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
03-21-2008, 11:22 AM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 119
Thanks: 17
|
Plugin System
Hi all.
I have never done a plugin system and I would like to here your thoughts/suggestions or read some articles/anything about how a plugin system should work or should be designed.
The plugin system I'm talking about is like the one for a CMS or even Wordpress that of course extends the functionality of the program.
Thanks
|
|
|
|
03-21-2008, 12:48 PM
|
#2 (permalink)
|
|
The Acquainted
Join Date: Jan 2008
Posts: 136
Thanks: 4
|
I would also be very interested in this!
|
|
|
|
03-21-2008, 01:20 PM
|
#3 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
I think probably the best way to go about a plugin system is via hooks. But the plugin should work via a class file which is placed in a special pool folder for plugins. You would do something then like the following:
php Code:
class My_Plugin extends Plugin_Interface { public $m_szHook = 'comment-post'; }
Then in your code you would initiate this class if the hook is valid. All the comment data would then be forwarded to the construct in an array. You would then feed back the data as an array -- and all would be well, the comment would be posted!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
03-21-2008, 08:30 PM
|
#4 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 119
Thanks: 17
|
Thanks for answering Wildhoney.
I don't quite understand this :S
Let's take an example of a CMS, where I make plugins to extend it's functionality, like say, news plugin, photogallery, blog...
What I'm thinking on now, is have a folder (plugins) where all the plugin files go. Then the cms looks into that folder and knows what plugins I have and what I don't, well then, I have a plugin file (main.php or something) this file will contain a plugin class (ex. News), this class will have several methods like Install() - that will install the plugin (create a needed db, configure some stuff, etc), Configure(), render() - that will actually show the news, and it should be executed on the page where the news will be shown....
Am I right about this?? or is there better ways to do it.
|
|
|
|
03-27-2008, 07:10 PM
|
#5 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Location: Birmingham, UK
Posts: 60
Thanks: 10
|
freenity: this interests me too, I don't really have much experience of how others do it, but here's how I do it in my cms -
PHP Code:
// snipped to the main part
function field($params=array()){
if(method_exists($this,$params['type'])){
$op = call_user_func(array($this,$params['type']),$params);
return $op;
}
else{
return 'field type not defined';
}
}
now when I'm looping through my fields to build the form I call that method (field), I then have several core field types defined such as text,textarea,select,checkbox,radio, etc., example -
PHP Code:
// textfield - I've stripped out all the code so you can see basics
function textfield($params=array()){
return '<input type="text" name="" id="" value="" />';
}
So I could do something like -
PHP Code:
echo $object->field(array(
'type' => 'textfield',
));
Obviously these would be called internally, you wouldn't just echo the output, but I'm keeping my examples lean.
This method allows me to keep my core methods (textfield,textarea,etc.) in one place, but gives third parties the chance to 'extend' my class and call their own, i.e.
PHP Code:
function freenity($params=array()){
return 'Hello world';
}
echo $object->field(array(
'type' => 'freenity',
));
Alternatively, I could write an api call so people wouldn't need to extend my class, ie. $object->plugin(...);
Hope this spurs some ideas :)
|
|
|
|
|
The Following User Says Thank You to flyingbuddha For This Useful Post:
|
|
03-28-2008, 05:08 PM
|
#6 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 119
Thanks: 17
|
thanks.
:)
|
|
|
|
03-30-2008, 08:48 PM
|
#7 (permalink)
|
|
The Contributor
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
|
Well, this is my way of doing plugings - I write them like a standalone app - with their templates, classes etc.
I have a config file in which is described which plugin go to what page. (About - article, gallery - using gallery plugin).
And I just make a plugin.php file that is loaded to the CMS, and it is using all the global vars.
Example.
CMS calling the plugin.php -
PHP Code:
<?php // Loading the plugin "controller" include_once( 'lib/pluginFrontController.php'); $action = $engine->url->action; $fc = new x3PluginFrontController( $module, $action ); include_once( 'tmpl/index.php'); ?>
And the pluginFrontController.php -
PHP Code:
<?php include_once '__pluginPrototype.php'; class x3PluginFrontController extends __pluginPrototype { protected $module;
public function __construct ( $action, $module ) { parent::__contruct(); switch ( $action ) { case 'view': include_once 'x3PluginView.php'; x3PluginView::__construct( $module ); break;
default: include_once 'x3PluginMain.php'; x3PluginMain::__construct( $module ); break; } } }
?>
And at last - pluginPrototype :
PHP Code:
<?php
class __pluginPrototype { protected $article = "table_article"; protected $comment = "table_comments"; protected $user = "table_users";
public function __construct() {}
protected function __doSomeAction() {} } ?>
In plugin prototype I've added database table names as protected and some function that will be use trough all the classes - eg. check data, or check user..
All "actions"- view, comment etc are seperate classes in which you define what is going to happen in that action - view - loads the selected article etc.
I used to write all this in one big class - and it become ove bloated - one class had ~1200 lines. So this seems like a good thing - for now.
If anybody has any suggestions - please suggest :)
Critcism is always welcome.
This could be modified to use the real MVC platform - like ZendFramework/Cake/Kohana ...
__________________
Back from sysadmins to the programmers.
|
|
|
|
The Following 2 Users Say Thank You to abiko For This Useful Post:
|
|
04-01-2008, 11:43 AM
|
#8 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
A question on this subject, is this possible?
php Code:
/** |||||||||||||||||||||||||||||||||||||||||| |||| @author Tanax |||| @copyright 2008 |||||||||||||||||||||||||||||||||||||||||| **/
class TANAXIA_PLUGIN_HOOK { public static $db; public static $plugin; public static function setDatabase($db) { self::$db = $db; } public static function loadPlugin($name) { self::$plugin = new $name(self::$db); return self::$plugin; } }
__________________
|
|
|
|
04-01-2008, 12:07 PM
|
#9 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by Tanax
A question on this subject, is this possible?
php Code:
/** |||||||||||||||||||||||||||||||||||||||||| |||| @author Tanax |||| @copyright 2008 |||||||||||||||||||||||||||||||||||||||||| **/
class TANAXIA_PLUGIN_HOOK { public static $db; public static $plugin; public static function setDatabase($db) { self::$db = $db; } public static function loadPlugin($name) { self::$plugin = new $name(self::$db); return self::$plugin; } }
|
Nvm.
It worked 
__________________
|
|
|
|
04-01-2008, 12:07 PM
|
#10 (permalink)
|
|
The Contributor
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
|
It is possible, if you look into Zends core - simmilar thing can be seen - I've seen simmilar things in Kohanas core - that is why the check for indexAction() or someAction() to be defined as "controllers".
Edit:
LOL, same post time :)
__________________
Back from sysadmins to the programmers.
|
|
|
04-01-2008, 12:59 PM
|
#11 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Nevermind again 
I just made a mistake in the include part ..
And yea, hehe we posted the same time  Although, I don't really understand your script :-O
__________________
Last edited by Tanax : 04-01-2008 at 01:41 PM.
|
|
|
|
04-01-2008, 04:08 PM
|
#12 (permalink)
|
|
The Contributor
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
|
Quote:
Originally Posted by Tanax
Although, I don't really understand your script :-O
|
What parts are troubling you?
__________________
Back from sysadmins to the programmers.
|
|
|
04-01-2008, 08:15 PM
|
#13 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by abiko
What parts are troubling you?
|
ehm, like.. all xD 
__________________
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|