Simple Machines Community Forum

SMF Development => Bug Reports => Fixed or Bogus Bugs => Topic started by: mrhope on September 25, 2010, 09:09:19 AM

Title: Custom profiles showing in members profile improperly
Post by: mrhope on September 25, 2010, 09:09:19 AM
I have SMF 2.0RC3 custom profiles feature enabled with the ability for users to add icons to their profiles by checking a box in their profile. This works great when viewing the users profile in a thread, however, when opening that users profile it shows all icons regardless if they're checked or not. I also noticed that even if these fields are empty that the <li></li> will also be printed. Probably because of the || in the below code.

default\Profile.template.php

// Are there any custom profile fields for the summary?
if (!empty($context['custom_fields']))
{
foreach ($context['custom_fields'] as $field)
if ($field['placement'] == 1 || empty($field['output_html']))
echo '
<li>', $field['output_html'], '</li>';
}


I tried comparing the above code with what is in the display.template.php and noticed that it's $context['member']['custom_fields'] but changing the code to how it is in the display.template.php doesn't seem to work, just shows no icons even if they're checked.

This is an Example page (http://www.computerhope.com/forum/index.php?action=profile;u=72330), on this users profile it should not be showing any of the last four icons as they're all unchecked in the users profile.

Title: Re: Custom profiles showing in members profile improperly
Post by: mrhope on September 27, 2010, 05:45:49 PM
Since I haven't got a reply spent some time debugging this and found the fix. Here is how I fixed this.

I looked at the array using print_r ($context['custom_fields']) which showed me arrays like the one shown below.


[0] => Array
(
    [name] => F@H
    [desc] => Folding @ Home user
    [type] => check
    [input_html] => <input type="checkbox" name="customfield[cust_f]"  class="input_check" />
    [output_html] => <a href="URL"><img src="folding.gif" alt="F@H member" /></a>

    [placement] => 1
    [colname] => cust_f
    [value] => 0
)


As can be seen I have HTML data, but the value is 0 (e.g. box is not checked). So even though this isn't checked it's still going to show using the original SMF code. To fix this I changed it so if the value is not 0 (checked) AND is not empty then echo the data.


// Are there any custom profile fields for the summary?
if (!empty($context['custom_fields']))
foreach ($context['custom_fields'] as $field)
if ($field['placement'] == 1 && !$field['value'] == 0 && !empty($field['value']))
echo '
<li>', $field['output_html'], '</li>';



Hope this helps, if this isn't already fixed in RC4 would highly recommend it.

Title: Re: Custom profiles showing in members profile improperly
Post by: Norv on October 17, 2010, 11:25:42 PM
Sorry for the delay, mrhope, and thank you very much for the report.
Title: Re: Custom profiles showing in members profile improperly
Post by: emanuele on May 28, 2011, 03:58:37 PM
Last minute bump program! :P (sorry for the late bump, but I completely forgot about them... :-[)

Updated fix:
Code (find) Select
// Are there any custom profile fields for the summary?
if (!empty($context['custom_fields']))
{
foreach ($context['custom_fields'] as $field)
if ($field['placement'] == 1 || empty($field['output_html']))


Code (replace with) Select
// Are there any custom profile fields for the summary?
if (!empty($context['custom_fields']))
{
foreach ($context['custom_fields'] as $field)
if (($field['placement'] == 1 || empty($field['output_html'])) && !empty($field['value']))
Title: Re: Custom profiles showing in members profile improperly
Post by: Antechinus on May 28, 2011, 06:59:08 PM
These last minute bumps should have been tracked to Mantis.

/me grumbes about hiding reports in obscure places.............

ETA: Sorted it.
Title: Re: Custom profiles showing in members profile improperly
Post by: emanuele on May 29, 2011, 03:08:52 AM
Sorry for not tracking it... :-[