/[drupal]/contributions/modules/user_display/user_display.theme.inc
ViewVC logotype

Contents of /contributions/modules/user_display/user_display.theme.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sat Jul 19 23:12:33 2008 UTC (16 months, 1 week ago) by sun
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
Initial commit of User Display API.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Overrides for the standard user theme functions.
7 */
8
9 /**
10 * @ingroup themeable
11 * @{
12 */
13
14 /**
15 * Format a username.
16 *
17 * This backwards compatible implementation of theme_username() has additional
18 * support to show the user's picture (provided that it is available in the
19 * $account).
20 *
21 * @param $account
22 * The user account to format, usually returned from user_load().
23 * @param $class
24 * A user display class, leave empty to output default username.
25 * @param $style
26 * A user display style to force, for example when invoked via
27 * phptemplate_user_picture().
28 * @return
29 * A string containing an HTML link to the user's page if the passed object
30 * suggests that this is a site user. Otherwise, only the username is returned.
31 */
32 function phptemplate_username($account, $class = NULL, $style = NULL) {
33 if (isset($class)) {
34 $styles = user_display_styles();
35 if (!is_numeric($class)) {
36 $classes = variable_get('user_display_classes', array());
37 $style = isset($classes[$class]) ? $styles[$classes[$class]] : NULL;
38 }
39 else {
40 $style = isset($styles[$class]) ? $styles[$class] : NULL;
41 }
42 }
43 if ($account->uid && $account->name && isset($style)) {
44 $content = '';
45 $classes = array('display');
46 foreach ($style['elements'] as $element) {
47 if (function_exists($element[0])) {
48 // Invoke element callback.
49 $element = call_user_func_array($element[0], array_merge(array($account, $style), isset($element[1]) ? $element[1] : array()));
50 if (!empty($element) && is_array($element)) {
51 // Add rendered content to output.
52 $content .= $element['content'];
53 if (!empty($element['class'])) {
54 // Add defined element classes to user-display container.
55 $classes = array_merge($classes, $element['class']);
56 }
57 }
58 }
59 }
60 // Skip potential duplicate classes.
61 $classes = array_unique($classes);
62 $output = '<div class="user-'. implode(' user-', $classes) .'">';
63 $output .= $content;
64 $output .= '</div>';
65 }
66 else {
67 // Fallback on core theme function.
68 $output = theme_username($account);
69 }
70
71 return $output;
72 }
73
74 /**
75 * Display a user picture.
76 *
77 * This backwards compatible implementation of theme_user_picture() has
78 * additional support to use imagecache presets for user pictures.
79 *
80 * @param $account
81 * A user object with the picture property set.
82 * @param $namespace
83 * A valid imagecache preset.
84 */
85 function phptemplate_user_picture($account, $class = NULL, $preset = NULL) {
86 if (variable_get('user_pictures', 0)) {
87 if (!isset($preset) && isset($class)) {
88 $styles = user_display_styles();
89 if (!is_numeric($class)) {
90 $classes = variable_get('user_display_classes', array());
91 $style = isset($classes[$class]) ? $styles[$classes[$class]] : NULL;
92 }
93 else {
94 $style = isset($styles[$class]) ? $styles[$class] : NULL;
95 }
96 if (isset($style)) {
97 return theme('username', $account, NULL, $style);
98 }
99 }
100
101 // Fall back to default presets for user style and other pages.
102 if (!isset($preset)) {
103 $presets = user_display_imagecache_presets();
104 if (arg(0) == 'user' && is_numeric(arg(1))) {
105 $preset = isset($presets['default_profile']) ? 'default_profile' : USER_DISPLAY_DEFAULT_PICTURE;
106 }
107 else {
108 $preset = isset($presets['default']) ? 'default' : USER_DISPLAY_DEFAULT_PICTURE;
109 }
110 }
111
112 if ($account->picture && file_exists($account->picture)) {
113 $file = $account->picture;
114 }
115 else if (variable_get('user_picture_default', '')) {
116 $file = variable_get('user_picture_default', '');
117 }
118
119 if (!empty($file)) {
120 $alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
121 // Render an user picture generated via ImageCache.
122 if (module_exists('imagecache') && is_string($preset)) {
123 $picture = theme('imagecache', $preset, $file, $alt, $alt);
124 }
125 // Render user picture like Drupal core if no valid class has been given.
126 else if (is_numeric($preset) && $preset == USER_DISPLAY_DEFAULT_PICTURE) {
127 $picture = theme('image', $file, $alt, $alt, '', FALSE);
128 }
129 // Fall back on username if picture has been disabled.
130 else {
131 return theme_username($account);
132 }
133 // Add user profile link to the user picture.
134 if (!empty($account->uid) && user_access('access user profiles')) {
135 $picture = l($picture, "user/$account->uid", array('title' => t('View user profile.')), NULL, NULL, FALSE, TRUE);
136 }
137
138 return "<div class=\"user-picture\">". $picture .'</div>';
139 }
140 }
141 }
142
143 /**
144 * Display a list of users.
145 *
146 * This backwards compatible implementation of theme_user_list() has additional
147 * support to show user pictures.
148 *
149 * @param $users
150 * An array with user objects. Should contain at least the name and uid.
151 * @return
152 * description
153 */
154 function phptemplate_user_list($users, $title = NULL, $class = NULL) {
155 if (!empty($users)) {
156 foreach ($users as $user) {
157 $items[] = theme('username', $user, $class);
158 }
159 }
160 return theme('item_list', $items, $title);
161 }
162
163 /**
164 * @} End of "ingroup themeable".
165 */

  ViewVC Help
Powered by ViewVC 1.1.2