You are here

function guestbook_menu in Guestbook 5

Same name and namespace in other branches
  1. 5.2 guestbook.module \guestbook_menu()
  2. 6.2 guestbook.module \guestbook_menu()
  3. 6 guestbook.module \guestbook_menu()
  4. 7.2 guestbook.module \guestbook_menu()

Implementation of hook_menu().

File

./guestbook.module, line 27

Code

function guestbook_menu($may_cache) {
  global $user;
  $items = array();
  $guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS);
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/guestbook',
      'title' => t('Guestbook'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'guestbook_admin_settings',
      ),
      'access' => user_access('administer site configuration'),
    );

    // User guestbooks.
    if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
      $items[] = array(
        'path' => 'guestbook',
        'title' => t('Guestbooks'),
        'access' => user_access('access site guestbook') || user_access('access user guestbooks'),
        'callback' => 'guestbook_list',
      );
    }
    else {
      $items[] = array(
        'path' => 'guestbook',
        'title' => variable_get('guestbook_site_title', t('Site guestbook')),
        'access' => user_access('access site guestbook'),
        'callback' => 'guestbook_page',
      );
    }
  }
  else {
    if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
      if ($user->uid > 0 && _guestbook_exists($user->uid)) {
        $unread = _guestbook_newentries();
        $unread = $unread ? ' (' . $unread . ')' : "";
        $items[] = array(
          'path' => 'guestbook/' . $user->uid,
          'title' => t('My guestbook') . $unread,
          'type' => MENU_DYNAMIC_ITEM,
        );
      }
    }
    if (arg(0) == 'guestbook' && is_numeric(arg(1))) {
      $uid = arg(1);
      $title = _guestbook_info($uid, 'title');
      if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
        $items[] = array(
          'path' => 'guestbook/' . $uid,
          'title' => $title,
          'access' => $uid == 0 ? user_access('access site guestbook') : user_access('access user guestbooks'),
          'type' => MENU_CALLBACK,
          'callback' => 'guestbook_page',
          'callback arguments' => array(
            $uid,
          ),
        );
      }
      $items[] = array(
        'path' => 'guestbook/' . $uid . '/form',
        'title' => t('Add guestbook entry'),
        'access' => $uid == 0 ? user_access('post in site guestbook') : user_access('post in user guestbooks'),
        'type' => MENU_CALLBACK,
        'callback' => 'guestbook_page_form',
        'callback arguments' => array(
          $uid,
        ),
      );
    }
  }
  return $items;
}