You are here

function privatemsg_menu in Privatemsg 5.3

Same name and namespace in other branches
  1. 5 privatemsg.module \privatemsg_menu()
  2. 6.2 privatemsg.module \privatemsg_menu()
  3. 6 privatemsg.module \privatemsg_menu()
  4. 7.2 privatemsg.module \privatemsg_menu()
  5. 7 privatemsg.module \privatemsg_menu()

Implementation of hook_menu().

File

./privatemsg.module, line 29

Code

function privatemsg_menu($may_cache) {
  global $user;
  $items = array();
  $access = user_access('access private messages');
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/privatemsg',
      'title' => t('Privatemsg'),
      'description' => t('Configure Privatemsg settings.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'privatemsg_configure',
      ),
      'access' => user_access('administer private messages'),
    );
    $items[] = array(
      'path' => 'privatemsg',
      'title' => t('Private messages'),
      'callback' => 'privatemsg_list',
      'access' => !$user->uid || $access,
      'type' => MENU_SUGGESTED_ITEM,
    );
    $items[] = array(
      'path' => 'privatemsg/list',
      'title' => t('List'),
      'callback' => 'privatemsg_list',
      'callback arguments' => array(
        NULL,
      ),
      'access' => !$user->uid || $access,
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );
    $items[] = array(
      'path' => 'privatemsg/new',
      'title' => t('Compose'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'privatemsg_new_form',
      ),
      'access' => $access,
      'type' => MENU_LOCAL_TASK,
      'weight' => -5,
    );
    $items[] = array(
      'path' => 'privatemsg/contacts',
      'title' => t('Contacts'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'privatemsg_contacts_form',
      ),
      'access' => $access,
      'type' => MENU_LOCAL_TASK,
      'weight' => 0,
    );
    $items[] = array(
      'path' => 'privatemsg/folders',
      'title' => t('Manage folders'),
      'callback' => 'privatemsg_manage_folders',
      'access' => user_access('create new folder') && $user->uid,
      'type' => MENU_LOCAL_TASK,
      'weight' => 5,
    );
    $items[] = array(
      'path' => 'privatemsg/folders/movetonew',
      'title' => t('Move to new folder'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'privatemsg_new_folder_form',
      ),
      'access' => user_access('create new folder') && $user->uid,
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'privatemsg/autocomplete',
      'title' => t('Privatemsg autocomplete'),
      'callback' => 'privatemsg_autocomplete',
      'access' => $access,
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'privatemsg/delete',
      'callback' => 'privatemsg_delete',
      'access' => $access && $user->uid,
      // No guest access
      'type' => MENU_CALLBACK,
    );
  }
  else {
    if (!isset($user->privatemsg_allow)) {
      _privatemsg_user_add_defaults($user);
    }
    if (arg(0) == 'privatemsg' && arg(1) == 'view' && intval(arg(2)) > 0) {
      $items[] = array(
        'path' => 'privatemsg/view/' . arg(2),
        'title' => t('Read message'),
        'callback' => 'privatemsg_view',
        'callback arguments' => array(
          intval(arg(2)),
          FALSE,
        ),
        'access' => $access && $user->uid,
        // Check access/redirect in callback
        'type' => MENU_CALLBACK,
        'weight' => -10,
      );
      $items[] = array(
        'path' => 'privatemsg/view/' . arg(2) . '/read',
        'title' => t('Read message'),
        'access' => $access && $user->uid,
        // Check access/redirect in callback
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -10,
      );
      $items[] = array(
        'path' => 'privatemsg/view/' . arg(2) . '/back',
        'title' => t('Back to list'),
        'callback' => 'privatemsg_back_to_list',
        'callback arguments' => array(
          intval(arg(2)),
        ),
        'access' => TRUE,
        // Check access/redirect in callback
        'type' => MENU_LOCAL_TASK,
        'weight' => 0,
      );
    }
    if (arg(0) == 'privatemsg' && arg(1) == 'reply' && intval(arg(2)) > 0) {
      $items[] = array(
        'path' => 'privatemsg/reply/' . arg(2),
        'title' => t('Write a reply'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'privatemsg_new_form',
        ),
        'access' => $access,
        'type' => MENU_CALLBACK,
      );
    }
    if (arg(0) == 'privatemsg' && arg(1) == 'new' && intval(arg(2)) > 0) {
      $items[] = array(
        'path' => 'privatemsg/new/' . arg(2),
        'title' => t('Write a new message'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'privatemsg_new_form',
        ),
        'access' => $access,
        'type' => MENU_CALLBACK,
      );
    }
    if ($user->uid != arg(2) && arg(0) == 'privatemsg' && arg(1) == 'block' && ($account = user_load(array(
      'uid' => arg(2),
    )))) {
      $blocked = privatemsg_user_blocked($account->uid);
      $title_args = array(
        '@user' => $account->name,
      );
      $items[] = array(
        'path' => 'privatemsg/block/' . arg(2),
        'title' => $blocked ? t('Unblock @user', $title_args) : t('Block @user', $title_args),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          $blocked ? 'privatemsg_unblock_user_form' : 'privatemsg_block_user_form',
          $account,
        ),
        'type' => MENU_CALLBACK,
      );
    }
    $new = _privatemsg_get_new_messages();
    $items[] = array(
      'path' => 'privatemsg/inbox',
      'title' => variable_get('privatemsg_menu_link', t('My inbox')) . ($new ? ' (' . $new . ')' : ''),
      'callback' => 'drupal_goto',
      'callback arguments' => array(
        'privatemsg',
      ),
      'type' => $user->uid && $user->privatemsg_allow ? MENU_DYNAMIC_ITEM : MENU_CALLBACK,
    );
    if ($new && strncmp($_GET['q'], 'privatemsg', 10) && $user->privatemsg_setmessage_notify && user_access('access private messages')) {
      $m = drupal_set_message();
      if (empty($m)) {
        drupal_set_message(strtr(format_plural($new, 'You have a new <a href="!url">private message</a>.', 'You have @count new <a href="!url">private messages</a>.'), array(
          '!url' => url('privatemsg'),
        )));
      }
    }
    if (arg(0) == 'privatemsg' && arg(1) == 'folders' && intval(arg(2)) > 1) {
      $modify_folder = privatemsg_folder_access($user->uid, arg(2));
      if (!$modify_folder) {
        drupal_goto('privatemsg/folders');
      }
      $items[] = array(
        'path' => 'privatemsg/folders/' . arg(2) . '/rename',
        'title' => t('Rename folder'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'privatemsg_rename_folder_form',
          arg(2),
        ),
        'access' => $access,
        'type' => MENU_CALLBACK,
      );
      $items[] = array(
        'path' => 'privatemsg/folders/' . arg(2) . '/empty',
        'title' => t('Empty folder?'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'privatemsg_empty_folder_form',
          arg(2),
        ),
        'access' => $access,
        'type' => MENU_CALLBACK,
      );
      $items[] = array(
        'path' => 'privatemsg/folders/' . arg(2) . '/delete',
        'title' => t('Delete folder?'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'privatemsg_delete_folder_form',
          arg(2),
        ),
        'access' => $access,
        'type' => MENU_CALLBACK,
      );
    }
    if (is_numeric(arg(1)) && (arg(0) == 'privatemsg' || arg(0) == 'user') && ($user->uid == arg(1) || user_access('administer private messages'))) {
      if (arg(0) == 'user' && arg(2) == 'privatemsg') {
        $account = $user->uid == arg(1) ? $user : user_load(array(
          'uid' => arg(1),
        ));
        $items[] = array(
          'path' => 'user/' . arg(1) . '/privatemsg',
          'title' => t('Privatemsg'),
          'callback' => 'privatemsg_list',
          'callback arguments' => array(
            arg(1),
          ),
          'access' => $account->privatemsg_allow,
          'type' => MENU_LOCAL_TASK,
        );
      }
      if (arg(0) == 'privatemsg') {
        if ($user->uid == arg(1)) {
          $account = $user;
          $title = t('Private messages');
        }
        else {
          $account = user_load(array(
            'uid' => arg(1),
          ));
          $title = t('Private messages for @name', array(
            '@name' => $account->name,
          ));
        }
        $items[] = array(
          'path' => 'privatemsg/' . arg(1),
          'title' => $title,
          'callback' => 'privatemsg_list',
          'callback arguments' => array(
            arg(1),
          ),
          'access' => $account->privatemsg_allow,
          'type' => MENU_CALLBACK,
        );
      }
    }
    drupal_add_css('./' . drupal_get_path('module', 'privatemsg') . '/privatemsg.css');
  }
  return $items;
}