FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » Fudla! Plugin Core Code Changes (Requirements for FUD 3.0.2 <-> Joomla integration)
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Fudla! Plugin Core Code Changes [message #165027 is a reply to message #165024] Sun, 17 April 2011 14:36 Go to previous messageGo to previous message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma:
Senior Member
Hi.

I think this can be improved by using the following in plugins.inc


/* Execute all registered plugins of a particular hook. */
function plugin_call_hook($type, $data=array()) {
	global $plugin_hooks;

	if (isset($plugin_hooks[$type])) {
		if ($type == 'PRE_TEMPLATE') {
			if (isset($plugin_hooks['POST_TEMPLATE'])) {
				// We only start the buffer if there is a need
				ob_start();
			}
		} elseif ($type == 'POST_TEMPLATE') {
			// Abort if plugins trigger this hook without the PRE_TEMPLATE
			if (!isset($plugin_hooks['PRE_TEMPLATE'])) {
				return null;
			}
			$data = ob_get_contents();
			ob_end_clean();
		}
		foreach ($plugin_hooks[$type] as $func) {
			$data = call_user_func($func, $data);
		}
	}
	return $data;
}


root_index.php.t gets changed to read ...
 	/* Call themed template. */
	if (defined('plugins')) {
		plugin_call_hook('PRE_TEMPLATE');
	}
	require($WWW_ROOT_DISK . fud_theme .'language.inc');	// Initialize theme's language helper functions.
	require($WWW_ROOT_DISK . fud_theme . $t .'.php');
	if (defined('plugins')) {
		$htmlData = plugin_call_hook('POST_TEMPLATE');
		if (isset($plugin_hooks['POST_TEMPLATE']) && !empty($htmlData)) {
			// We only send output if process was not aborted
			echo $htmlData;
		}
	}


The sample plugin (file: x.plugin) to capture and process output becomes:

<?php
plugin_add_hook('PRE_TEMPLATE',  'plugin_x_capture_output');
plugin_add_hook('POST_TEMPLATE', 'plugin_x_process_output');

function plugin_x_capture_output() {
	//Run some code if desired.
}

function plugin_x_process_output($data) {
	//$modified_data = Modify $data, add headers, footers, go mad...
	return $modified_data;
}
?>



Yes it means the application is doing some hand holding but that exactly is what good applications do and the user does not have to worry about stuff as the hook behaves consistently with others.

In this case, html is passed in, user processes, returns and sees processed html displayed without having to do anything special.

PRE_TEMPLATE remains flexible as a user might want this without wanting to change the output

What do you think?

[Updated on: Sun, 17 April 2011 15:16]

Report message to a moderator

[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Tips for higher iPhone/Andriod/Pre compatibility
Next Topic: Help Needed - fud_user_reg class
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 17:48:59 GMT 2024

Total time taken to generate the page: 0.04107 seconds