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
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-05-2007, 05:10 AM   #1 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default Hook System

I've been researching on google for some time now, I found 1 out of a thousand results for php auto updater which was useful for one of my projects, now I'm looking for a hook system for plugins and what not. Does anyone know how to make a basic PHP -> XML plugin hook system?
Nor is offline  
Reply With Quote
Old 11-05-2007, 01:08 PM   #2 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Could you be a bit more specific as to which part of this "hook" system you don't understand? Also, how does XML play a part in all this - I have a vague idea, but could you elaborate?
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

Last edited by Wildhoney : 11-05-2007 at 01:40 PM. Reason: Where did UML come from?
Karl is offline  
Reply With Quote
Old 11-05-2007, 01:54 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I think he wants something like the plugin system vBulletin has, where you import a XML-file :p
Tanax is offline  
Reply With Quote
Old 11-05-2007, 02:07 PM   #4 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

That doesn't actually have anything to do with the hook system (well, besides it contains the hooks related to the product that the XML file represents). The XML files simply provide a way to tie togehter all the pieces of a vBulletin product, that is, the tempaltes, hooks, stylevars, etc.

The actual hook system itself has nothing to do with XML (as far as I know anyway, I may be wrong?)
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 11-05-2007, 04:05 PM   #5 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

I really don't no nothing, I want to know how the actual hook system would be set up.
Nor is offline  
Reply With Quote
Old 11-05-2007, 04:44 PM   #6 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

There are many ways to do a "hook" system, one approach could be similar to this:



The whole process would work like this:
Client asks HookController to execute a hook (using getHook())
HookController asks the specified Hook (i.e. LoginHook) to execute.
After Hook execution any return value is returned to the HookController which is in turn returned to the Client.

The system could easily be extended to support plug ins and "families" of hooks - allowing you to group hooks into products.
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 11-05-2007, 06:19 PM   #7 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Okay using your basic concept, say I got a forum software(Working on a new PHP 5 OOP one), My Hook class would be basically a get hooks, check if hook is availible(login,etc.), then execute the hook.

Code:
class HookSystem
{
	private $hooks = array();
	private $page;
	function __construct($_cpage)
	{
		$this->page = $_cpage;
	}	
	function addhook($function_name,$type,...extra parameters...)
	{
		...update the array hooks with a new hook name
	}
	function checkhooks()
	{
		...runs a loop, check what type of hooks where 
	}
}
When running the class I could go about checking what page in viewing and then run the hooks for that page, and what type of hook it is(i.e,

registration -> form
registration -> header
registration -> captcha

)

It would ask what type of hook it is, then check if the hook is available based on something basic like my example say form, hook would be something similar to add a new field to the form with ease.

Code:
$page = htmlspecialchars($_GET['page']);
switch($page)
{
	case 'registration':
		$type = 'registration';
	break;
}
$hooks = new HookSystem($type);

function __form__($left,$right,$pos)
{	
	global $hooks;
	$hooks->addhook("__form__","registration","form",$left,$right,$pos);
}
__form__("Referrer","<input type='text' name='ref' />",3);
Just something simple like that, if you see what I'm getting at.(Most of it would be managed through MySQL database)
Nor 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 06:34 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design