Well, I'll add a little bit here:
1 Originally was:
function ssi_welcome($output_method = 'echo')
{
global $context, $txt, $scripturl;
if ($output_method == 'echo')
{
if ($context['user']['is_guest'])
echo $txt['welcome_guest'];
else
echo $txt['hello_member'], ' <b>', $context['user']['name'], '</b>',
allowedTo('pm_read') ? ', ' . $txt[152] .
' <a href="' . $scripturl . '?action=pm">' . $context['user']['messages'] . ' ' .
($context['user']['messages'] == '1' ? $txt[471] : $txt[153]) . '</a>' .
$txt['newmessages4'] . ' ' . $context['user']['unread_messages']
. ' ' . ($context['user']['unread_messages'] == '1' ? $txt['newmessages0'] : $txt['newmessages1']) : '', '.';
}
// Don't echo... then do what?!
else
return $context['user'];
}
My idea:
function ssi_welcome( $output_method = 'echo' ) {
global $context, $txt, $scripturl;
if( $context['user']['is_guest'] ) {
$buffer = $txt['welcome_guest'];
} else {
$buffer = '<a href="foro/index.php?action=profile;u=' .
getUserID( $context['user']['name'] ).'">' .
$context['user']['name'] . '</a><br />';
if( allowedTo( 'pm_read' ) ) {
$buffer .= 'Tienes ' .
' <a href="' . $scripturl . '?action=pm">' .
$context['user']['unread_messages'] . ' ';
if( $context['user']['unread_messages'] == '1' ) {
$buffer .= ' mensaje';
} else {
$buffer .= ' mensajes';
}
$buffer .= '</a>';
} else {
$buffer .= '.';
}
}
if( $output_method == 'echo' ) {
echo $buffer;
} else { // Don't echo... then do what?!
return $buffer;
}
}
To put it clear, If I dont want something outputed (echo, print, etc) maybe i want it returned.
(array, var, string or bool return, so I can use it somwhere else.)
2 I would use a different approach to templates.
Here where I work, we use a like this:
<?php
//this is index.php
//logic and data processing.
include( template( '../templates/index.html' ) );
index.html looks like:
<html>
etc, etc,
<body>
{$variables_to_show}
Web structure.(tds, p, h1, etc)
</body>
</html>
The dirs looks like:
./include where functions and reusable stuff lives. (Hopefully, html, _SESSION, globals free functions)
./templates where all the templates lives.
./web where all the .php scripts are waiting to be called.
It's a nice and clean way to see the world and know what to change and where to change.
Maybe you can use that.