View source
<?php
function user_relationships_ui_help($section) {
switch ($section) {
case 'admin/help#user_relationships':
$output = '<p>' . t('This module allows you to create relationship types that users can use to connect to each other.') . '</p>';
return $output;
case 'admin/user/relationships':
$output = '<p>' . t('This page lets you setup user relationship types.') . '</p>';
return $output;
}
}
function user_relationships_ui_perm() {
return array(
'administer user relationships',
'maintain relationships',
'view user relationships',
);
}
function user_relationships_ui_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/user/relationships',
'title' => t('Relationships'),
'description' => t('Create relationship types'),
'access' => user_access('administer user relationships'),
'callback' => 'user_relationships_ui_types_list_page',
);
$items[] = array(
'path' => 'admin/user/relationships/list',
'title' => t('List'),
'callback' => 'user_relationships_types_list_page',
'access' => user_access('administer user relationships'),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items[] = array(
'path' => 'admin/user/relationships/add',
'title' => t('Add type'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'user_relationships_ui_type_edit_form',
),
'access' => user_access('administer user relationships'),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items[] = array(
'path' => 'admin/user/relationships/edit',
'title' => t('Edit type'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'user_relationships_ui_type_edit_form',
),
'access' => user_access('administer user relationships'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/user/relationships/delete',
'title' => t('Delete type'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'user_relationships_ui_type_delete_form',
),
'access' => user_access('administer user relationships'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/user/relationships/settings',
'title' => t('Settings'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'user_relationships_ui_settings',
),
'access' => user_access('administer user relationships'),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
$items[] = array(
'path' => 'relationship_types/autocomplete',
'title' => t('User Relationships Autocomplete'),
'callback' => '_user_relationships_autocomplete_types',
'access' => user_access('administer user relationships'),
'type' => MENU_CALLBACK,
);
}
else {
global $user;
$id = is_numeric(arg(1)) ? arg(1) : $user->uid;
$edit_access = $id == $user->uid && user_access('maintain relationships') || user_access('administer users');
$view_access = $id == $user->uid && user_access('maintain relationships') || user_access('view user relationships');
$items[] = array(
'path' => 'relationships',
'title' => t('My relationships'),
'access' => $id && user_access('maintain relationships'),
'type' => MENU_NORMAL_ITEM,
'callback' => 'theme',
'callback arguments' => array(
'user_relationships_page',
$user->uid,
),
);
$items[] = array(
'path' => "relationships/list",
'title' => t('All'),
'access' => $view_access,
'type' => MENU_NORMAL_ITEM | MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
if (true || $approval_required && $edit_access) {
$items[] = array(
'path' => "relationships/requests",
'title' => t('Pending'),
'access' => $edit_access,
'callback' => 'theme',
'type' => MENU_NORMAL_ITEM | MENU_LOCAL_TASK,
'weight' => -9,
'callback arguments' => array(
'user_relationships_pending_requests_page',
$user->uid,
),
);
}
if (arg(0) == 'relationships') {
$relationships = user_relationships_types_load();
foreach ($relationships as $rtid => $relationship) {
$items[] = array(
'path' => "relationships/{$rtid}",
'title' => t($relationship->name),
'access' => $view_access,
'type' => MENU_NORMAL_ITEM | MENU_LOCAL_TASK,
'callback' => 'theme',
'callback arguments' => array(
'user_relationships_page',
$user->uid,
$rtid,
),
);
}
}
$items[] = array(
'path' => "relationships/remove",
'title' => t('Remove relationship'),
'access' => $edit_access,
'callback' => 'drupal_get_form',
'callback arguments' => array(
'user_relationships_ui_remove',
$user->id,
),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => "relationship/request",
'title' => t('Create a relationship'),
'access' => $edit_access,
'callback' => 'drupal_get_form',
'callback arguments' => array(
'user_relationships_ui_request',
),
'type' => MENU_CALLBACK,
);
if (arg(0) == 'user' && $id && arg(2) == 'relationships') {
if ($id != $user->uid) {
$access = user_access('administer user relationships') || user_access('administer users');
$items[] = array(
'path' => "user/{$id}/relationships",
'title' => t('Relationships'),
'access' => $access,
'callback' => 'theme',
'callback arguments' => array(
'user_relationships_page',
$id,
),
);
$items[] = array(
'path' => "user/{$id}/relationships/list",
'title' => t('All'),
'access' => $access,
'type' => MENU_NORMAL_ITEM | MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => "user/{$id}/relationships/requests",
'title' => t('Pending'),
'access' => $access,
'type' => MENU_NORMAL_ITEM | MENU_LOCAL_TASK,
'weight' => -9,
'callback' => 'theme',
'callback arguments' => array(
'user_relationships_pending_requests_page',
$id,
),
);
if (arg(0) == 'user' && arg(2) == 'relationships' && is_numeric(arg(3))) {
$relationships = user_relationships_types_load();
foreach ($relationships as $rtid => $relationship) {
$items[] = array(
'path' => "user/{$id}/relationships/{$rtid}",
'title' => t($relationship->name),
'access' => $access,
'type' => MENU_NORMAL_ITEM | MENU_LOCAL_TASK,
'callback' => 'theme',
'callback arguments' => array(
'user_relationships_page',
$id,
$rtid,
),
);
}
}
}
else {
if ($_REQUEST['destination']) {
$query = "destination={$_REQUEST['destination']}";
unset($_REQUEST['destination']);
}
$items[] = array(
'path' => "user/{$id}/relationships",
'type' => MENU_CALLBACK,
'access' => TRUE,
'callback' => 'drupal_goto',
'callback arguments' => array(
str_replace("user/{$id}/", '', $_GET['q']),
$query,
),
);
}
if (in_array(arg(4), array(
'approve',
'disapprove',
'cancel',
))) {
$items[] = array(
'path' => "user/{$id}/relationships/requested",
'title' => t('Approve Relationship'),
'access' => $access || $id == $user->uid,
'type' => MENU_CALLBACK,
'callback' => 'drupal_get_form',
'callback arguments' => array(
'user_relationships_ui_pending_requested',
$id,
),
);
}
$items[] = array(
'path' => "user/{$id}/relationships/remove",
'title' => t('Remove relationship'),
'access' => $access || $id == $user->uid,
'callback' => 'drupal_get_form',
'callback arguments' => array(
'user_relationships_ui_remove',
$id,
),
'type' => MENU_CALLBACK,
);
}
}
return $items;
}
function user_relationships_ui_user($type, &$edit, &$account, $category = NULL) {
switch ($type) {
case 'login':
if (user_access('maintain relationships')) {
_user_relationships_ui_set_notifications($account);
}
break;
case 'view':
global $user;
$viewer =& $user;
if ($account->uid == $user->uid && user_access('maintain relationships')) {
_user_relationships_ui_set_notifications($account);
break;
}
$output = array();
if ($list = _user_relationships_ui_between($viewer, $account)) {
$output[] = array(
'title' => t('Your relationships to this user'),
'value' => theme('item_list', $list),
'class' => 'user_relationships',
);
}
if ($actions = _user_relationships_ui_actions_between($viewer, $account)) {
$output[] = array(
'title' => t('Relationship actions'),
'value' => theme('item_list', $actions),
'class' => 'user_relationships_actions',
);
}
if (sizeof($output)) {
return array(
t('Relationships') => $output,
);
}
break;
case 'form':
if ($category == 'account' && variable_get('user_relationships_require_approval', TRUE) && user_access('maintain relationships', $account)) {
$form['user_relationships_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Relationship settings'),
'#weight' => 5,
);
if (variable_get('user_relationships_allow_auto_approve', FALSE) && ($relationships = user_relationships_types_load())) {
$options = array();
foreach ($relationships as $relationship) {
if ($relationship->requires_approval) {
$options[$relationship->rtid] = $relationship->name;
}
}
$form['user_relationships_settings']['user_relationships_auto_approve'] = array(
'#type' => 'checkboxes',
'#title' => t('Automatically approve the following relationship requests'),
'#options' => $options,
'#default_value' => $edit['user_relationships_auto_approve'],
'#description' => t("Check off the types of relationships you'd like to automatically approve."),
);
}
}
if (sizeof($form['user_relationships_settings']) == 3) {
unset($form['user_relationships_settings']);
}
return $form;
}
}