Thread: Plugin System
View Single Post
Old 03-30-2008, 08:48 PM   #7 (permalink)
abiko
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

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.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
The Following 2 Users Say Thank You to abiko For This Useful Post:
flyingbuddha (03-31-2008), freenity (03-30-2008)