You are here

function user_relationships_ui_menu in User Relationships 5.3

Same name and namespace in other branches
  1. 6 user_relationships_ui/user_relationships_ui.module \user_relationships_ui_menu()
  2. 7 user_relationships_ui/user_relationships_ui.module \user_relationships_ui_menu()

Menu

File

user_relationships_ui/user_relationships_ui.hooks.inc, line 36

Code

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;
}