- <?php
- * @file
- * Theme functions for the User module.
- */
-
- * Returns HTML for a list of users.
- *
- * @param $variables
- * An associative array containing:
- * - users: An array with user objects. Should contain at least the name and
- * uid.
- * - title: (optional) Title to pass on to theme_item_list().
- *
- * @ingroup themeable
- */
- function theme_user_list($variables) {
- $users = $variables['users'];
- $title = $variables['title'];
- $items = array();
-
- if (!empty($users)) {
- foreach ($users as $user) {
- $items[] = theme('username', array('account' => $user));
- }
- }
- return theme('item_list', array('items' => $items, 'title' => $title));
- }
-
- * Returns HTML for a user signature.
- *
- * @param $variables
- * An associative array containing:
- * - signature: The user's signature.
- *
- * @ingroup themeable
- */
- function theme_user_signature($variables) {
- $signature = $variables['signature'];
- $output = '';
-
- if ($signature) {
- $output .= '<div class="clear">';
- $output .= '<div>—</div>';
- $output .= $signature;
- $output .= '</div>';
- }
-
- return $output;
- }
-
- * Returns HTML for a username, potentially linked to the user's page.
- *
- * @param $variables
- * An associative array containing:
- * - account: The user object to format.
- * - name: The user's name, sanitized.
- * - extra: Additional text to append to the user's name, sanitized.
- * - link_path: The path or URL of the user's profile page, home page, or
- * other desired page to link to for more information about the user.
- * - link_options: An array of options to pass to the l() function's $options
- * parameter if linking the user's name to the user's page.
- * - attributes: An array of attributes to pass to the
- * backdrop_attributes() function if not linking to the user's page.
- *
- * $variables['account'] is typically a User object, but it can be any object
- * that provides the uid and name properties, for example, a Node.
- *
- * @see template_preprocess_username()
- * @see template_preprocess_node()
- */
- function theme_username($variables) {
- if (isset($variables['link_path'])) {
-
-
-
-
-
-
-
-
-
-
- $variables['link_options']['attributes'] = array_merge_recursive($variables['link_attributes'], $variables['attributes']);
-
- $output = l($variables['name'] . $variables['extra'], $variables['link_path'], $variables['link_options']);
- }
- else {
- $output = '<span' . backdrop_attributes($variables['attributes']) . '>' . $variables['name'] . $variables['extra'] . '</span>';
- }
- return $output;
- }
-
- * Returns HTML for the administer permissions page.
- *
- * @param $variables
- * An associative array containing:
- * - form: A render element representing the form.
- *
- * @ingroup themeable
- */
- function theme_user_admin_permissions($variables) {
- $form = $variables['form'];
-
- $roles = user_roles();
- foreach (element_children($form['permission']) as $key) {
- $row = array(
- 'data' => array(),
- );
-
-
-
- hide($form['permission'][$key]);
-
-
- if (is_numeric($key)) {
- $module_text = '<div class="permission-module-name table-filter-text-source">' . $form['permission'][$key]['#markup'] . '</div>';
- $row['class'] = array('module-row');
- $row['data'][] = array(
- 'data' => $module_text,
- 'class' => array('module'),
- 'id' => 'module-' . $form['permission'][$key]['#id'],
- 'colspan' => count($form['roles']['#value']) + 1,
- );
- }
-
- else {
- $permission_text = '<div class="permission-name table-filter-text-source">' . $form['permission'][$key]['#markup'] . '</div>';
- $permission_text .= $form['permission'][$key]['#description'];
-
- $row['data'][] = array(
- 'data' => $permission_text,
- 'class' => array('permission', 'table-filter-text'),
- 'id' => $form['permission'][$key]['#id'],
- );
- foreach (element_children($form['checkboxes']) as $role_name) {
- $form['checkboxes'][$role_name][$key]['#title'] = $roles[$role_name] . ': ' . $form['permission'][$key]['#markup'];
- $form['checkboxes'][$role_name][$key]['#title_display'] = 'attribute';
- $row['data'][] = array(
- 'data' => backdrop_render($form['checkboxes'][$role_name][$key]),
- 'class' => array('checkbox'),
- );
- }
- }
- $rows[] = $row;
- }
- $header[] = (t('Permission'));
- foreach (element_children($form['role_names']) as $role_name) {
- $header_cell = array(
- 'data' => backdrop_render($form['role_names'][$role_name]),
- 'class' => array('checkbox'),
- );
-
- if (isset($form['role_names'][$role_name]['#description'])) {
- $header_cell['title'] = check_plain(strip_tags($form['role_names'][$role_name]['#description']));
- }
- $header[] = $header_cell;
- }
-
- $output = backdrop_render($form['filter']);
-
-
- $output .= '<div class="permissions-matrix">';
- $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'permissions')));
- $output .= '</div>';
- $output .= backdrop_render_children($form);
- return $output;
- }
-
- * Returns HTML for an individual permission description.
- *
- * @param $variables
- * An associative array containing:
- * - permission_item: An associative array representing the permission whose
- * description is being themed. Useful keys include:
- * - description: The text of the permission description.
- * - warning: A security-related warning message about the permission (if
- * there is one).
- *
- * @ingroup themeable
- */
- function theme_user_permission_description($variables) {
- $description = array();
- $permission_item = $variables['permission_item'];
- if (!empty($permission_item['description'])) {
- $description[] = '<div class="permission-description description table-filter-text-source">' . $permission_item['description'] . '</div>';
- }
- if (!empty($permission_item['restrict access'])) {
- $description[] = '<em class="permission-warning">' . t('Warning: Give to trusted roles only; this permission has security implications.') . '</em>';
- }
- if (!empty($permission_item['warning'])) {
- $description[] = '<a class="warning-toggle" href="#">more</a>';
- $description[] = '<div class="permission-warning-description">' . $permission_item['warning'] . '</div>';
- }
- if (!empty($description)) {
- return implode(' ', $description);
- }
- }
-
- * Returns HTML for the role order form.
- *
- * @param $variables
- * An associative array containing:
- * - form: A render element representing the form.
- *
- * @ingroup themeable
- */
- function theme_user_admin_roles($variables) {
- $form = $variables['form'];
-
- $header = array(
- array('data' => t('Name'), 'class' => array('role-name')),
- array(
- 'data' => t('Description'),
- 'class' => array('role-description', 'priority-low'),
- ),
- array('data' => t('Weight')),
- array('data' => t('Operations'), 'class' => array('role-operations')),
- );
- foreach (element_children($form['roles']) as $role_name) {
- $label = $form['roles'][$role_name]['#role']->label;
- if (in_array($role_name, array(BACKDROP_ANONYMOUS_ROLE, BACKDROP_AUTHENTICATED_ROLE))) {
- $label .= ' ' . t('(required)');
- }
-
- $row = array();
- $row[] = array(
- 'data' => theme('label_machine_name__role', array(
- 'label' => $label,
- 'machine_name' => $form['roles'][$role_name]['#role']->name,
- )),
- 'class' => array('role-name'),
- );
- $row[] = array(
- 'data' => filter_xss_admin($form['roles'][$role_name]['#role']->description),
- 'class' => array('role-description', 'priority-low'),
- );
- $row[] = array(
- 'data' => backdrop_render($form['roles'][$role_name]['weight']),
- );
- $row[] = array(
- 'data' => backdrop_render($form['roles'][$role_name]['operations']),
- 'class' => array('role-operations'),
- );
- $rows[] = array('data' => $row, 'class' => array('draggable'));
- }
-
- backdrop_add_tabledrag('user-roles', 'order', 'sibling', 'role-weight');
-
- $output = backdrop_render($form['roles_help']);
- $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'user-roles')));
- $output .= backdrop_render_children($form);
-
- return $output;
- }
-
- * Process variables for user-picture.tpl.php.
- *
- * The $variables array contains the following arguments:
- * - $account: A user, node or comment object with 'name', 'uid' and 'picture'
- * fields.
- *
- * @see user-picture.tpl.php
- */
- function template_preprocess_user_picture(&$variables) {
- $site_config = config('system.core');
- $variables['user_picture'] = '';
- if ($site_config->get('user_pictures')) {
- $account = $variables['account'];
- if (!empty($account->picture)) {
-
-
-
-
-
-
-
- if (is_numeric($account->picture)) {
- $account->picture = file_load($account->picture);
- }
- if (!empty($account->picture->uri)) {
- $filepath = $account->picture->uri;
- }
- }
- elseif ($site_config->get('user_picture_default')) {
- $filepath = $site_config->get('user_picture_default');
- }
- if (isset($filepath)) {
- $alt = t("@user's picture", array('@user' => user_format_name($account)));
-
-
- if (module_exists('image') && file_valid_uri($filepath) && $style = $site_config->get('user_picture_style')) {
- $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'uri' => $filepath, 'alt' => $alt, 'title' => $alt));
- }
- else {
- $variables['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt));
- }
- if (!empty($account->uid) && user_access('access user profiles')) {
- $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
- $variables['user_picture'] = l($variables['user_picture'], "user/$account->uid", $attributes);
- }
- }
- }
- }
-
- * Preprocesses variables for theme_username().
- *
- * Modules that make any changes to variables like 'name' or 'extra' must insure
- * that the final string is safe to include directly in the output by using
- * check_plain() or filter_xss().
- */
- function template_preprocess_username(&$variables) {
- $account = $variables['account'];
-
- $variables['extra'] = '';
- if (empty($account->uid)) {
- $variables['uid'] = 0;
- $variables['extra'] = ' (' . t('not verified') . ')';
- }
- else {
- $variables['uid'] = (int) $account->uid;
- }
-
-
-
-
-
-
- $name = $variables['name_raw'] = user_format_name($account);
- if (backdrop_strlen($name) > 20) {
- $name = backdrop_substr($name, 0, 15) . '...';
- }
- $variables['name'] = check_plain($name);
- $variables['profile_access'] = user_access('access user profiles');
-
-
- if ($variables['uid'] && $variables['profile_access']) {
-
- $variables['link_attributes']['title'] = t('View user profile.');
- $variables['link_path'] = 'user/' . $variables['uid'];
- }
- elseif (!empty($account->homepage)) {
-
-
-
- $variables['link_attributes']['rel'] = 'nofollow';
- $variables['link_path'] = $account->homepage;
- $variables['homepage'] = $account->homepage;
- }
-
- $variables['link_options']['html'] = TRUE;
-
- $variables['attributes'] = array('class' => array('username'));
- }
-
- * Process variables for user-profile.tpl.php.
- *
- * The $variables array contains the following arguments:
- * - $account
- *
- * @see user-profile.tpl.php
- */
- function template_preprocess_user_profile(&$variables) {
- $view_mode = $variables['view_mode'] = $variables['elements']['#view_mode'];
- $account = $variables['elements']['#account'];
-
-
- foreach (element_children($variables['elements']) as $key) {
- $variables['user_profile'][$key] = $variables['elements'][$key];
- }
-
-
- field_attach_preprocess('user', $account, $variables['elements'], $variables);
-
-
- $variables['theme_hook_suggestions'][] = 'user_profile__' . $view_mode;
- $variables['theme_hook_suggestions'][] = 'user_profile__' . $account->uid;
- $variables['theme_hook_suggestions'][] = 'user_profile__' . $account->uid . '__' . $view_mode;
- }