MyBB Community Forums

Full Version: Don't hardcode HTML
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Actually, I only have a single request: Please don't hardcode HTML in PHP files. It's not just bad practice. It makes customization of styles a lot harder.
As everybody should do, I use sprites for my images. I had a hard time changing the expcolimage (it has the .gif exension hardcoded), but with selectors, it's posible to do so. Worse are the buddy_options:
$buddy_list = explode(',', $mybb->user['buddylist']);
if(in_array($mybb->input['uid'], $buddy_list))
{
	$buddy_options = "<br /><a href=\"./usercp.php?action=do_editlists&amp;delete={$mybb->input['uid']}&amp;my_post_key={$mybb->post_code}\"><img src=\"{$theme['imgdir']}/remove_buddy.gif\" alt=\"{$lang->remove_from_buddy_list}\" /> {$lang->remove_from_buddy_list}</a>";
}
else
{
	$buddy_options = "<br /><a href=\"./usercp.php?action=do_editlists&amp;add_username=".urlencode($memprofile['username'])."&amp;my_post_key={$mybb->post_code}\"><img src=\"{$theme['imgdir']}/add_buddy.gif\" alt=\"{$lang->add_to_buddy_list}\" /> {$lang->add_to_buddy_list}</a>";
}

$ignore_list = explode(',', $mybb->user['ignorelist']);
if(in_array($mybb->input['uid'], $ignore_list))
{
	$buddy_options .= "<br /><a href=\"./usercp.php?action=do_editlists&amp;manage=ignored&amp;delete={$mybb->input['uid']}&amp;my_post_key={$mybb->post_code}\"><img src=\"{$theme['imgdir']}/remove_ignore.gif\" alt=\"{$lang->remove_from_ignore_list}\" /> {$lang->remove_from_ignore_list}</a>";
}
else
{
	$buddy_options .= "<br /><a href=\"./usercp.php?action=do_editlists&amp;manage=ignored&amp;add_username=".urlencode($memprofile['username'])."&amp;my_post_key={$mybb->post_code}\"><img src=\"{$theme['imgdir']}/add_ignore.gif\" alt=\"{$lang->add_to_ignore_list}\" /> {$lang->add_to_ignore_list}</a>";
}

why is this hard coded? It should be just like the topic subscribe links. The links don't even contain an id or class. Not even a title. Nothing that can be used to style them with CSS. The only posibility is to wrap the buddy/ignore in a span, and style the first-child differently (killing IE6, but who cares). Even doing that, IE7 will still download the img. In practice, one has to either keep using the .gif (an 8-bit image) or write a plugin to correct MyBB's default behaviour.

I can give quite a few other examples, but I'm sure you get my point: No HTML should be hardcoded within PHP files.
No HTML will be hard coded in PHP files. I've been looking into putting the buddy options into templates, but it's not a priority at the moment.
Thanks Tomm!
where i can find buddy option php?
(2011-10-22, 03:54 AM)daadeguzman Wrote: [ -> ]where i can find buddy option php?

In ./member.php around line # 1787