Foren / Cotonti / Core Labs / set metas from standalone plugin

Orkan
#8819 25. Februar 2009, 15:58
# dervan : Orkan, what is wrong in the use of pointers?

Well, all Im saying - it is not a procedural approach.
It should be avoided, like GOTO command in C++, it only makes the code more difficult to read.

From the other hand, what if I wanna use footer hook to set metas? see, its not perfect anyway...

I really like the output buffering feature implemented in PHP - it seems to be perfect solution here IMO.
You can have nesting buffers for all three parts: header, body and footer.. and hook them separately.

<?PHP
$counter = 0;

function callback_header($header)
{	
	global $counter;
	return (++$counter).' - callback_header(), content: '.$header.'<br>';
}
function callback_body($body)
{	
	global $counter;
	return (++$counter).' - callback_body(), content: '.$body.'<br>';
}
function callback_footer($footer)
{	
	global $counter;
	return (++$counter).' - callback_footer(), content: '.$footer.'<br>';
}


ob_start('callback_header');
echo 'echo_1_header<br>';

ob_start('callback_body');
echo 'echo_2_body<br>';

ob_start('callback_footer');
echo 'echo_3_footer<br>';

while(@ob_end_flush());


?>


and this will output:
3 - callback_header(), content: echo_1_header
2 - callback_body(), content: echo_2_body
1 - callback_footer(), content: echo_3_footer

see? the callback_header() is processed by ob_end_flush() last, but it is sent to the browser as first :-)


Also, to get rid of additional hook include()'s - which is a waste, one can define (in the core) three global arrays for preg_replace() to use in these callbacks accordingly.
Perl - the only language that looks the same before and after RSA encryption.

Dieser Beitrag wurde von Orkan (am 25. Februar 2009, 16:53, vor 16 Jahre) bearbeitet