News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Custom profiles showing in members profile improperly

Started by mrhope, September 25, 2010, 09:09:19 AM

Previous topic - Next topic

mrhope

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, on this users profile it should not be showing any of the last four icons as they're all unchecked in the users profile.


mrhope

#1
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.


Norv

Sorry for the delay, mrhope, and thank you very much for the report.
To-do lists are for deferral. The more things you write down the later they're done... until you have 100s of lists of things you don't do.

File a security report | Developers' Blog | Bug Tracker


Also known as Norv on D* | Norv N. on G+ | Norv on Github

emanuele

#3
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']))


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Antechinus

#4
These last minute bumps should have been tracked to Mantis.

* Antechinus grumbes about hiding reports in obscure places.............

ETA: Sorted it.

emanuele



Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Advertisement: