TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-11-2008, 02:06 PM   #1 (permalink)
The Visitor
 
Join Date: Dec 2007
Posts: 4
Thanks: 0
Jonnee is on a distinguished road
Default Interactive plugin system

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)
Jonnee is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:40 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0