New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General stuff #298
General stuff #298
Changes from all commits
a94e008
e2926c7
5aaf48f
a99a625
6465303
5af2d19
e2bf6e0
5d3b79a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1242,6 +1242,72 @@ function loadMemberContext($user, $display_custom_fields = false) | |
return true; | ||
} | ||
|
||
/** | ||
* Loads the user's custom profile fields | ||
* | ||
* @param mixed $users either an integer or an array of integers | ||
* @param mixed $param either a string or an array of strings with profile fields names | ||
* @return array | ||
*/ | ||
function loadMemberCustomFields($users, $params) | ||
{ | ||
global $smcFunc, $txt, $scripturl, $settings; | ||
|
||
// Do not waste my time... | ||
if (empty($users) || empty($params)) | ||
return false; | ||
|
||
// Make sure it's an array. | ||
$users = !is_array($users) ? array($users) : array_unique($users); | ||
$params = !is_array($params) ? array($params) : array_unique($params); | ||
$return = array(); | ||
|
||
$request = $smcFunc['db_query']('', ' | ||
SELECT c.id_field, c.col_name, c.field_name, c.field_desc, c.field_type, c.field_length, c.field_options, c.mask, show_reg, | ||
c.show_display, c.show_profile, c.private, c.active, c.bbc, c.can_search, c.default_value, c.enclose, c.placement, t.variable, t.value, t.id_member | ||
FROM {db_prefix}themes AS t | ||
LEFT JOIN {db_prefix}custom_fields AS c ON (c.col_name = t.variable) | ||
WHERE id_member' . (count($users) == 1 ? ' = {int:loaded_ids} ' : ' IN ({array_int:loaded_ids}) ') . | ||
'AND variable' . (count($params) == 1 ? ' = {string:params}' : ' IN ({array_string:params})'), | ||
array( | ||
'loaded_ids' => (int) count($users) == 1 ? $users[0] : $users, | ||
'params' => (string) count($params) == 1 ? $params[0] : $params, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what is the intention of these casts, but they won't work as (probably) expected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .___. again, I just copy/paste SMF code... you should point that out to whoever wrote that ten years ago. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please point me to an example? |
||
); | ||
|
||
while ($row = $smcFunc['db_fetch_assoc']($request)) | ||
{ | ||
// BBC? | ||
if (!empty($row['bbc'])) | ||
$row['value'] = parse_bbc($row['value']); | ||
|
||
// ... or checkbox? | ||
elseif (isset($row['type']) && $row['type'] == 'check') | ||
$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; | ||
|
||
// Enclosing the user input within some other text? | ||
if (!empty($row['enclose'])) | ||
$row['value'] = strtr($row['enclose'], array( | ||
'{SCRIPTURL}' => $scripturl, | ||
'{IMAGES_URL}' => $settings['images_url'], | ||
'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], | ||
'{INPUT}' => $row['value'], | ||
)); | ||
|
||
// Send a simple array if there is just 1 param | ||
if (count($params) == 1) | ||
$return[$row['id_member']] = $row; | ||
|
||
// More than 1? knock yourself out... | ||
else | ||
$return[$row['id_member']][$row['id_field']] = $row; | ||
} | ||
|
||
$smcFunc['db_free_result']($request); | ||
|
||
return !empty($return) ? $return : false; | ||
} | ||
|
||
/** | ||
* Loads information about what browser the user is viewing with and places it in $context | ||
* - uses the class from Class-BrowerDetect.php | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use just IN?
That would save you some comparisons:
and here below:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because thats how SMF do things... I just followed and copy/paste SMF coding style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay...never checked before... 👼
/me feels is a bit odd
I'm not sure if there is any practical difference...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't if you aren't picky in terms of performance, it is if you want the code to be more organized but there is a bazillion other places where SMF does this, might as well go with the flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SMF avoids using 'IN' in the query, for the query to use the index instead. There's only an index on id_member iirc however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my (quick) test with EXPLAIN, MySQL is smart enough to understand there is just one value and uses the index anyway. Of course if there is more than one then it doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks for checking it out!