Hello all users of TalkPHP
I have been reading and looking and writing user system. Now I had this idea to make this plug&play style plugin system so you only need to upload the plugin to ftp folder and active it from controlpanel.
So what I have now is this :
Code:
<?php
if( !defined( "INPROCESS" ) ){
header("HTTP/1.0 403 Forbidden");
die();
}
include_once 'mysql'. EXT;
class plugin extends mysql{
var $mysql;
var $fullpath;
var $plugins = array();
function __construct() {
$this->mysql = new mysql();
if( phpversion( ) < 5 ){
mysql::__construct( );
}
// Lets check all avaible plugins
$list = array();
if ( ($directoryHandle = opendir( $this->fullpath . '/plugins/' )) == true ) {
while (($file = readdir( $directoryHandle )) !== false) {
// Make sure we're not dealing with a file or a link to the parent directory
if( is_dir( $this->fullpath . '/plugins/' . $file ) && ($file == '.' || $file == '..') !== true )
array_push( $list, $file );
}
}
$results = $this->Fetch_Object('SELECT * FROM plugins');
$newResult = array();
// Create an array: 'plugin name' = 'active' (1 or 0)
foreach ( $results as $result ){
$newResult[$result->name] = $result->active;
}
// Register the active plugins
foreach( $list as $plugin ){
if($newResult[$plugin] == "1"){
$this->registerplug($plugin);
}
}
}
function registerplug($plugin){
require_once( $this->fullpath . "/plugins/$plugin/$plugin.plugin.php" );
}
function hook($checkpoint){
// Cycle through all the plugins that are active
foreach($this->plugins as $plugin){
if(!call_user_func($checkpoint))
throw new Exception( "Cannot hook plugin ($plugin) at checkpoint ($checkpoint)" );
}
}
}
?>
And I use it like this ->
Code:
$plugin = new plugin;
$plugin->fullpath = $system_folder;
if( phpversion() < '5' )
$plugin->__construct( );
Now when I try to hook functions I use it like this :
Code:
$plugin->hook('Menu');
$plugin->hook('onLoad');
So the problem is that it wont print out "hello world" text which I asked it to do in both of those plugins.
Code:
class menu extends plugin {
function Menu(){
print 'Hello World!';
return true;
}
}
So what is wrong with this? Any suggestions? MySQL connections work 100% for sure (tested)