You are here

function user_relationships_ui_user in User Relationships 6

Same name and namespace in other branches
  1. 5.3 user_relationships_ui/user_relationships_ui.hooks.inc \user_relationships_ui_user()

Implementation of hook_user().

File

user_relationships_ui/user_relationships_ui.module, line 630
UI components of user_relationships @author Jeff Smick (creator) @author Alex Karshakevich (maintainer) http://drupal.org/user/183217 @author Darren Ferguson (contributor) http://drupal.org/user/70179

Code

function user_relationships_ui_user($type, &$edit, &$account, $category = NULL) {
  switch ($type) {
    case 'login':
      if (user_access('maintain own relationships')) {
        _user_relationships_ui_set_notifications($account);
      }
      break;
    case 'view':
      global $user;
      $viewer =& $user;
      if ($account->uid == $user->uid && user_access('maintain own relationships')) {
        _user_relationships_ui_set_notifications($account);
        break;
      }
      $output = array();
      if ($list = _user_relationships_ui_actions_between($viewer, $account, array(
        'remove' => 1,
      ))) {
        $output['relations'] = array(
          '#title' => t('Your relationships to this user'),
          '#type' => 'user_profile_item',
          '#value' => theme('item_list', $list),
          '#attributes' => array(
            'class' => 'user_relationships_ui',
          ),
        );
      }
      if ($actions = _user_relationships_ui_actions_between($viewer, $account, array(
        'add' => 1,
        'requested' => 1,
        'received' => 1,
      ))) {
        $output['actions'] = array(
          '#title' => t('Relationship actions'),
          '#type' => 'user_profile_item',
          '#value' => theme('item_list', $actions),
          '#attributes' => array(
            'class' => 'user_relationships_ui_actions',
          ),
        );
      }
      if (sizeof($output)) {
        $account->content['user_relationships_ui'] = array(
          '#type' => 'user_profile_category',
          '#title' => t('Relationships'),
        );
        $account->content['user_relationships_ui'] = array_merge($account->content['user_relationships_ui'], $output);
      }
      break;
    case 'form':
      if ($category == 'account' && variable_get('user_relationships_ui_require_approval', TRUE) && user_access('maintain own relationships', $account)) {
        if (variable_get('user_relationships_allow_auto_approve', FALSE) && ($relationships = user_relationships_types_load())) {
          if (!is_array($edit['user_relationships_ui_auto_approve'])) {
            $edit['user_relationships_ui_auto_approve'] = array();
          }
          $options = array();
          foreach ($relationships as $relationship) {
            if ($relationship->requires_approval) {
              $options[$relationship->rtid] = ur_tt("user_relationships:rtid:{$relationship->rtid}:name", $relationship->name);
            }
          }

          //#453090 Do nothing if there are no options.
          if (count($options)) {
            $form['user_relationships_ui_settings'] = array(
              '#type' => 'fieldset',
              '#title' => t('Relationship settings'),
              '#weight' => 5,
              '#collapsible' => TRUE,
            );
            $form['user_relationships_ui_settings']['user_relationships_ui_auto_approve'] = array(
              '#type' => 'checkboxes',
              '#title' => t('Automatically approve the following relationship requests'),
              '#options' => $options,
              '#default_value' => $edit['user_relationships_ui_auto_approve'],
              '#description' => t("Check off the types of relationships you'd like to automatically approve."),
            );
          }
        }
      }

      //#257748 #458046 for adding the functionality of allowing/disallowing private messages.
      if ($category == 'account' && variable_get('user_relationships_restrict_privatemsg', 'all') == 'all_overridable' && user_access('maintain own relationships', $account) && module_exists('privatemsg')) {

        //check if privatemsg is installed
        $form['user_relationships_ui_privatemsg_settings'] = array(
          '#type' => 'fieldset',
          '#title' => t('Private messages'),
          '#weight' => 10,
          '#collapsible' => TRUE,
        );
        $options = drupal_map_assoc(array(
          'on in relations',
          'on all users',
        ));
        $form['user_relationships_ui_privatemsg_settings']['user_relationships_allow_private_message'] = array(
          '#type' => 'radios',
          '#title' => t('Allow private messages'),
          '#description' => t('Allow/disallow users in or outside relationships to send you private messages.'),
          '#options' => array(
            'on all users' => t('Everyone'),
            'on in relations' => t('My relationships only'),
          ),
          '#default_value' => isset($edit['user_relationships_allow_private_message']) ? $edit['user_relationships_allow_private_message'] : "on all users",
        );
      }

      // No options have been set so don't display it
      if (isset($form['user_relationships_ui_settings']) && sizeof($form['user_relationships_ui_settings']) == 3) {
        unset($form['user_relationships_ui_settings']);
      }
      if (isset($form)) {
        return $form;
      }
  }
}