Просмотр исходного кода

A standalone quick function to load custom profile fields
without having to use loadMemberContext()

Signed-off-by: Suki <[email protected]>

Suki 12 лет назад
Родитель
Сommit
5aaf48f27a
1 измененных файлов с 81 добавлено и 0 удалено
  1. 81 0
      Sources/Load.php

+ 81 - 0
Sources/Load.php

@@ -1242,6 +1242,87 @@ 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 boolean $return = false, whether or not return the custom fields
+ * @return array
+ */
+function loadMemberCustomFields($users)
+{
+	global $modSettings, $context, $smcFunc, $txt;
+	global $scripturl, $settings;
+
+	// Make sure it's an array.
+	$users = !is_array($users) ? array($users) : array_unique($users);
+
+	$temp = array();
+	$return = array();
+
+	$request = $smcFunc['db_query']('', '
+		SELECT *
+		FROM {db_prefix}themes
+		WHERE id_member' . (count($users) == 1 ? ' = {int:loaded_ids}' : ' IN ({array_int:loaded_ids})'),
+		array(
+			'loaded_ids' => count($users) == 1 ? $users[0] : $users,
+		)
+	);
+
+	while ($row = $smcFunc['db_fetch_assoc']($request))
+		$temp[$row['id_member']]['options'][$row['variable']] = $row['value'];
+
+	$smcFunc['db_free_result']($request);
+
+	if (!isset($context['display_fields']))
+		$context['display_fields'] = unserialize($modSettings['displayFields']);
+
+	foreach ($users as $user)
+		foreach ($context['display_fields'] as $custom)
+		{
+			if (!isset($custom['title']) || trim($custom['title']) == '' || empty($temp[$user]['options'][$custom['colname']]))
+				$return[$user] = array();
+
+			else
+			{
+				$value = $temp[$user]['options'][$custom['colname']];
+
+				// BBC?
+				if ($custom['bbc'])
+					$value = parse_bbc($value);
+
+				// ... or checkbox?
+				elseif (isset($custom['type']) && $custom['type'] == 'check')
+					$value = $value ? $txt['yes'] : $txt['no'];
+
+				// Enclosing the user input within some other text?
+				if (!empty($custom['enclose']))
+					$value = strtr($custom['enclose'], array(
+						'{SCRIPTURL}' => $scripturl,
+						'{IMAGES_URL}' => $settings['images_url'],
+						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
+						'{INPUT}' => $value,
+					));
+
+				$return[$user][] = array(
+					'title' => $custom['title'],
+					'colname' => $custom['colname'],
+					'value' => $value,
+					'placement' => !empty($custom['placement']) ? $custom['placement'] : 0,
+				);
+
+				$memberContext[$user]['custom_fields'][] = array(
+					'title' => $custom['title'],
+					'colname' => $custom['colname'],
+					'value' => $value,
+					'placement' => !empty($custom['placement']) ? $custom['placement'] : 0,
+				);
+			}
+		}
+
+		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