summaryrefslogtreecommitdiff
path: root/modules/profile
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2007-08-02 10:36:42 +0000
committerDries Buytaert <dries@buytaert.net>2007-08-02 10:36:42 +0000
commit99276849da740da568b54f165aa5256639a133b0 (patch)
tree011681b6f09353d0a5614e2301a152c85dd9dd73 /modules/profile
parentfe7faf76c20da61dc9fe99108e30a36fc13cb130 (diff)
downloadbrdo-99276849da740da568b54f165aa5256639a133b0.tar.gz
brdo-99276849da740da568b54f165aa5256639a133b0.tar.bz2
- Patch #162134 by dvessel: tplify profile module.
Diffstat (limited to 'modules/profile')
-rw-r--r--modules/profile/profile-block.tpl.php41
-rw-r--r--modules/profile/profile-listing.tpl.php51
-rw-r--r--modules/profile/profile-wrapper.tpl.php24
-rw-r--r--modules/profile/profile.module96
4 files changed, 183 insertions, 29 deletions
diff --git a/modules/profile/profile-block.tpl.php b/modules/profile/profile-block.tpl.php
new file mode 100644
index 000000000..995f59124
--- /dev/null
+++ b/modules/profile/profile-block.tpl.php
@@ -0,0 +1,41 @@
+<?php
+// $Id
+/**
+ * @file profile-block.tpl.php
+ * Default theme implementation for displaying a users profile within a
+ * block. It only shows in relation to a node displayed as a full page.
+ *
+ * Available variables:
+ * - $picture: Image configured for the account linking to the users page.
+ * - $profile: Keyed array of all profile fields that have a value.
+ *
+ * Each $field in $profile contains:
+ * - $field->title: Title of the profile field.
+ * - $field->value: Value of the profile field.
+ * - $field->type: Type of the profile field, i.e., checkbox, textfield,
+ * textarea, selection, list, url or date.
+ *
+ * Since $profile is keyed, a direct print of the field is possible. Not
+ * all accounts may have a value for a profile so do a check first. If a field
+ * of "last_name" was set for the site, the following can be used.
+ *
+ * <?php if (isset($profile['last_name'])): ?>
+ * <div class="field last-name">
+ * <?php print $profile['last_name']->title; ?>:<br />
+ * <?php print $profile['last_name']->value; ?>
+ * </div>
+ * <?php endif; ?>
+ *
+ * @see template_preprocess_profile_block()
+ */
+?>
+<?php print $picture; ?>
+
+<?php foreach ($profile as $field) : ?>
+ <p>
+ <?php if ($field->type != 'checkbox') : ?>
+ <strong><?php print $field->title; ?></strong><br />
+ <?php endif; ?>
+ <?php print $field->value; ?>
+ </p>
+<?php endforeach; ?>
diff --git a/modules/profile/profile-listing.tpl.php b/modules/profile/profile-listing.tpl.php
new file mode 100644
index 000000000..770f2d803
--- /dev/null
+++ b/modules/profile/profile-listing.tpl.php
@@ -0,0 +1,51 @@
+<?php
+// $Id
+/**
+ * @file profile-listing.tpl.php
+ * Default theme implementation for displaying a user and their profile data
+ * for member listing pages.
+ *
+ * @see profile-wrapper.tpl.php
+ * where all the data is collected and printed out.
+ *
+ * Available variables:
+ * - $picture: Image configured for the account linking to the users page.
+ * - $name: User's account name linking to the users page.
+ * - $profile: Keyed array of all profile fields that are set as visible
+ * in member list pages (configured by site administrators). It also needs
+ * to have a value in order to be present.
+ *
+ * Each $field in $profile contains:
+ * - $field->title: Title of the profile field.
+ * - $field->value: Value of the profile field.
+ * - $field->type: Type of the profile field, i.e., checkbox, textfield,
+ * textarea, selection, list, url or date.
+ *
+ * Since $profile is keyed, a direct print of the field is possible. Not
+ * all accounts may have a value for a profile so do a check first. If a field
+ * of "last_name" was set for the site, the following can be used.
+ *
+ * <?php if (isset($profile['last_name'])): ?>
+ * <div class="field last-name">
+ * <?php print $profile['last_name']->title; ?>:<br />
+ * <?php print $profile['last_name']->value; ?>
+ * </div>
+ * <?php endif; ?>
+ *
+ * @see template_preprocess_profile_listing()
+ */
+?>
+<div class="profile">
+ <?php print $picture; ?>
+
+ <div class="name">
+ <?php print $name; ?>
+ </div>
+
+ <?php foreach ($profile as $field) : ?>
+ <div class="field">
+ <?php print $field->value; ?>
+ </div>
+ <?php endforeach; ?>
+
+</div>
diff --git a/modules/profile/profile-wrapper.tpl.php b/modules/profile/profile-wrapper.tpl.php
new file mode 100644
index 000000000..27f742fd9
--- /dev/null
+++ b/modules/profile/profile-wrapper.tpl.php
@@ -0,0 +1,24 @@
+<?php
+// $Id
+/**
+ * @file profile-wrapper.tpl.php
+ * Default theme implementation for wrapping member listings and their
+ * profiles.
+ *
+ * This template is used when viewing a list of users. It can be a general
+ * list for viewing all users with the url of "example.com/profile" or when
+ * viewing a set of users who share a specific value for a profile such
+ * as "example.com/profile/country/belgium".
+ *
+ * Available variables:
+ * - $content: User account profiles iterated through profile-listing.tpl.php.
+ * - $current_field: The named field being browsed. Provided here for context.
+ * The above example would result in "last_name". An alternate template name
+ * is also based on this, e.g., "profile-wrapper-last_name.tpl.php".
+ *
+ * @see template_preprocess_profile_wrapper()
+ */
+?>
+<div id="profile">
+ <?php print $content; ?>
+</div>
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 54376d89b..0468878ab 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -58,10 +58,17 @@ function profile_theme() {
return array(
'profile_block' => array(
'arguments' => array('account' => NULL, 'fields' => array()),
+ 'file' => 'profile-block',
),
'profile_listing' => array(
'arguments' => array('account' => NULL, 'fields' => array()),
- ), );
+ 'file' => 'profile-listing',
+ ),
+ 'profile_wrapper' => array(
+ 'arguments' => array('content' => NULL),
+ 'file' => 'profile-wrapper',
+ )
+ );
}
/**
@@ -451,8 +458,8 @@ function profile_admin_overview() {
* Menu callback; display a list of user information.
*/
function profile_browse() {
- $name = arg(1);
- list(, , $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
+ // Ensure that the path is converted to 3 levels always.
+ list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
$field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
@@ -498,12 +505,13 @@ function profile_browse() {
// Extract the affected users:
$result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments);
- $output = '<div id="profile">';
+ $content = '';
while ($account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));
$profile = _profile_update_user_fields($fields, $account);
- $output .= theme('profile_listing', $account, $profile);
+ $content .= theme('profile_listing', $account, $profile);
}
+ $output = theme('profile_wrapper', $content);
$output .= theme('pager', NULL, 20);
if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
@@ -512,7 +520,6 @@ function profile_browse() {
else {
$title = check_plain($field->page);
}
- $output .= '</div>';
drupal_set_title($title);
return $output;
@@ -531,13 +538,13 @@ function profile_browse() {
// Extract the affected users:
$result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
- $output = '<div id="profile">';
+ $content = '';
while ($account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));
$profile = _profile_update_user_fields($fields, $account);
- $output .= theme('profile_listing', $account, $profile);
+ $content .= theme('profile_listing', $account, $profile);
}
- $output .= '</div>';
+ $output = theme('profile_wrapper', $content);
$output .= theme('pager', NULL, 20);
drupal_set_title(t('User list'));
@@ -790,39 +797,70 @@ function profile_categories() {
return $data;
}
-function theme_profile_block($account, $fields = array()) {
-
- $output .= theme('user_picture', $account);
+/**
+ * Process variables for profile-block.tpl.php.
+ *
+ * The $variables array contains the following arguments:
+ * - $account
+ * - $fields
+ *
+ * @see profile-block.tpl.php
+ */
+function template_preprocess_profile_block(&$variables) {
- foreach ($fields as $field) {
+ $variables['picture'] = theme('user_picture', $variables['account']);
+ $variables['profile'] = array();
+ // Supply filtered version of $fields that have values.
+ foreach ($variables['fields'] as $field) {
if ($field->value) {
- if ($field->type == 'checkbox') {
- $output .= "<p>$field->value</p>\n";
- }
- else {
- $output .= "<p><strong>$field->title</strong><br />$field->value</p>\n";
- }
+ $variables['profile'][$field->name]->title = $field->title;
+ $variables['profile'][$field->name]->value = $field->value;
+ $variables['profile'][$field->name]->type = $field->type;
}
}
- return $output;
}
-function theme_profile_listing($account, $fields = array()) {
-
- $output = "<div class=\"profile\">\n";
- $output .= theme('user_picture', $account);
- $output .= ' <div class="name">'. theme('username', $account) ."</div>\n";
+/**
+ * Process variables for profile-listing.tpl.php.
+ *
+ * The $variables array contains the following arguments:
+ * - $account
+ * - $fields
+ *
+ * @see profile-listing.tpl.php
+ */
+function template_preprocess_profile_listing(&$variables) {
- foreach ($fields as $field) {
+ $variables['picture'] = theme('user_picture', $variables['account']);
+ $variables['name'] = theme('username', $variables['account']);
+ $variables['profile'] = array();
+ // Supply filtered version of $fields that have values.
+ foreach ($variables['fields'] as $field) {
if ($field->value) {
- $output .= " <div class=\"field\">$field->value</div>\n";
+ $variables['profile'][$field->name]->title = $field->title;
+ $variables['profile'][$field->name]->value = $field->value;
+ $variables['profile'][$field->name]->type = $field->type;
}
}
- $output .= "</div>\n";
+}
- return $output;
+/**
+ * Process variables for profile-wrapper.tpl.php.
+ *
+ * The $variables array contains the following arguments:
+ * - $content
+ *
+ * @see profile-wrapper.tpl.php
+ */
+function template_preprocess_profile_wrapper(&$variables) {
+ $variables['current_field'] = '';
+ if ($field = arg(1)) {
+ $variables['current_field'] = $field;
+ // Supply an alternate template suggestion based on the browsable field.
+ $variables['template_files'][] = 'profile-wrapper-'. $field;
+ }
}
function _profile_field_types($type = NULL) {