You are here

function guestbook_user in Guestbook 6

Same name and namespace in other branches
  1. 5.2 guestbook.module \guestbook_user()
  2. 5 guestbook.module \guestbook_user()
  3. 6.2 guestbook.module \guestbook_user()

Implementation of hook_user()

File

./guestbook.module, line 86

Code

function guestbook_user($op, &$edit, &$user, $category = '') {
  $guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS);
  if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) {
    switch ($op) {
      case 'view':
        if (user_access('access user guestbooks') && empty($user->guestbook_status)) {
          $title = t("Read @username's guestbook.", array(
            '@username' => $user->name,
          ));
          $link = l(t('View recent guestbook entries'), "user/{$user->uid}/guestbook", array(
            'attributes' => array(
              'title' => $title,
            ),
          ));
          $user->content['summary']['guestbook'] = array(
            '#type' => 'user_profile_item',
            '#title' => t('Guestbook'),
            '#value' => $link,
            '#attributes' => array(
              'class' => 'guestbook',
            ),
          );
        }
        return;
      case 'form':
        if ($category == 'account') {
          $form['guestbook'] = array(
            '#type' => 'fieldset',
            '#title' => t('User guestbook'),
          );
          $form['guestbook']['guestbook_status'] = array(
            '#type' => 'radios',
            '#title' => t('Status'),
            '#default_value' => isset($edit['guestbook_status']) ? $edit['guestbook_status'] : 0,
            '#options' => array(
              t('Enabled'),
              t('Disabled'),
            ),
          );
          $form['guestbook']['guestbook_send_email'] = array(
            '#type' => 'checkbox',
            '#title' => t('Send email notification'),
            '#description' => t("Uncheck if you don't wish to be notified of new entries to your guestbook."),
            '#default_value' => isset($edit['guestbook_send_email']) ? $edit['guestbook_send_email'] : 0,
          );
          $form['guestbook']['guestbook_intro'] = array(
            '#type' => 'textarea',
            '#title' => t('Intro text'),
            '#default_value' => isset($edit['guestbook_intro']) ? $edit['guestbook_intro'] : '',
            '#cols' => 70,
            '#rows' => GUESTBOOK_TEXTAREA_ROWS,
            '#description' => t('The text that appears on top of your guestbook.'),
          );
          return $form;
        }
        break;
      case 'delete':
        db_query("DELETE FROM {guestbook} WHERE recipient = %d", $user->uid);
        db_query("UPDATE {guestbook} SET author = 0 WHERE author = %d", $user->uid);
        db_query("UPDATE {guestbook} SET commentauthor = 0 WHERE commentauthor = %d", $user->uid);
        break;
    }
  }
}