Current location: Hot Scripts Forums » Programming Languages » PHP » Plugin system


Plugin system

Reply
  #1 (permalink)  
Old 08-23-08, 06:54 AM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
Plugin system

Hello,
I want to code plugin system.

I want to code a class for this job and on where I want add hook.
E.g:
PHP Code:

if($_GET['page'] == 'register' && $loginset == '0')

{
    eval(
'$page  = "' $tem->get('register',$MyTheme) . '";');
    eval(
'$index  = "' $tem->get('index',$MyTheme) . '";');
    
$plugin->addHook('register');
    echo 
$index;

My plugins are like
PHP Code:

<?php


/**
 * @author Hamed
 * @copyright 2008
 */

//$info is for plugin info
$info['pulgin_name'] = ''//Name of Plugin 
$info['plugin_des'] = '';  //What does this plugin do
$info['plugin_maker'] = '';  //Your name (Who make this plugin?)
$info['plugin_maker_website'] = '';  //Your website
$info['plugin_version'] = ''//Version on this plugin
$info['sanction_code'] = 'simple'//This name should be in english and we use it for function name
$info['plugin_hook'] = ''//plug that we put it in.


//This function did what this plugin need for install.
function install()
{
    
}

//This function did what this plugout need for uninstall.
function uninstall()
{
    
}

//This function will run on plug that you select.
function simple()
{
    
}
?>
$info['plugin_hook'] is my plugin hook (e.g: register)

I want to do this job:
on __construct() of class I check my database and I will find active plugin and I can include them now How can I run their function? (function simple() is plugin function)

and What should I write on addHook(); function ?
(All plugins are in folder by the name plugins in root dir)
I think I do not explain it very good.
Reply With Quote
  #2 (permalink)  
Old 08-24-08, 05:04 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Quote:
Originally Posted by Hamed View Post
How can I run their function? (function simple() is plugin function)
www.php.net/call_user_func

PHP Code:

$result call_user_func($info['sanction_code'], $optional_arguments); 

Quote:
and What should I write on addHook(); function ?
(All plugins are in folder by the name plugins in root dir)
We don't even know what you're trying to do, or even WHEN these hooks are supposed to be executed. So I really don't know how to answer this question...

Quote:
I think I do not explain it very good.
I agree.
Reply With Quote
  #3 (permalink)  
Old 08-24-08, 11:10 PM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
I call function in other way.
PHP Code:

include_once('./plugins/'.$sanction_code.'.php');
                
$sanction_code(); 
Does it make problem because it work well.
Reply With Quote
  #4 (permalink)  
Old 08-25-08, 02:40 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
No problem at all. This is perfectly valid too.
Reply With Quote
  #5 (permalink)  
Old 08-25-08, 05:10 AM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks.
One thing when I run this function I should global vars that I want use in function Is there any way that I do not do it?
Reply With Quote
  #6 (permalink)  
Old 08-25-08, 05:22 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
So you want to use global variables inside a function?
This can be done with the global keyword.
http://www.php.net/manual/en/languag...bles.scope.php
Reply With Quote
  #7 (permalink)  
Old 08-25-08, 05:25 AM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 188
Thanks: 2
Thanked 0 Times in 0 Posts
I know global but I want to do not use global keyword.
Quote:
Originally Posted by <?Wille?> View Post
So you want to use global variables inside a function?
This can be done with the global keyword.
http://www.php.net/manual/en/languag...bles.scope.php
Reply With Quote
  #8 (permalink)  
Old 08-25-08, 05:26 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Then use the $GLOBALS superglobal.

www.php.net/reserved.variables.globals
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I code a Plugin system Hamed PHP 9 01-20-08 11:54 AM
problems with a store system spyke01 JavaScript 16 08-22-06 04:56 PM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
Link system TAK PHP 3 08-17-03 11:17 AM
Good template system [PL]Greg PHP 3 06-28-03 04:09 AM


All times are GMT -5. The time now is 07:54 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.