You are here

function guestbook_page in Guestbook 6.2

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

Output a guestbook page; menu callback.

1 call to guestbook_page()
guestbook_content_guestbook_user in panels/guestbook_user.inc
Render the guestbook of a user.
1 string reference to 'guestbook_page'
guestbook_menu in ./guestbook.module
Implementation of hook_menu().

File

./guestbook.module, line 315

Code

function guestbook_page($account, $op = NULL, $op_id = NULL, $page = TRUE) {
  global $user;

  // Prepare site guestbook.
  if (empty($account->uid)) {
    $account = drupal_anonymous_user();
    drupal_set_title(variable_get('guestbook_site_title', t('Site guestbook')));
  }
  if (!_guestbook_exists($account->uid)) {
    if ($page) {
      drupal_not_found();
    }
    return;
  }

  // Set last visited time for own guestbook
  if ($account->uid > 0 && $account->uid == $user->uid) {
    user_save($account, array(
      'guestbook_visited' => time(),
    ));
  }

  // Delete or comment an entry
  $comment_entry = $sql_where = '';
  if (_guestbook_access('moderate', $account->uid) && is_numeric($op_id)) {
    switch ($op) {
      case 'edit':
        return drupal_get_form('guestbook_form_entry_form', $account->uid, 'page', $op_id);
      case 'delete':
        return guestbook_delete_entry_confirm_page($account->uid, $op_id);
      case 'comment':
        $comment_entry = $op_id;
        $sql_where = ' AND g.id = %d';
        break;
    }
  }
  if (!_guestbook_access('moderate', $account->uid) || !(user_access('moderate own guestbook') || user_access('moderate all guestbooks'))) {
    $sql_where = ' AND g.status = 1';
  }

  // Fetch guestbook entries
  $limit = variable_get('guestbook_entries_per_page', 20);
  $sql = "SELECT g.*, u1.uid, u1.name, u1.data, u1.picture, u2.name as commentby \n    FROM {guestbook} g \n    LEFT JOIN {users} u1 ON g.author = u1.uid \n    LEFT JOIN {users} u2 ON g.commentauthor = u2.uid \n    WHERE g.recipient = %d {$sql_where}\n    ORDER BY g.created DESC";
  if (!empty($comment_entry)) {

    // Fetch only guestbook entry for administrative comment.
    $result = db_query($sql, $account->uid, $comment_entry);
  }
  else {
    $result = pager_query($sql, $limit, 0, "SELECT COUNT(*) FROM {guestbook} g WHERE g.recipient = %d" . (_guestbook_access('moderate', $account->uid) && (user_access('moderate own guestbook') || user_access('moderate all guestbooks')) ? '' : ' AND g.status = 1'), $account->uid);
  }
  $entries = array();
  while ($entry = db_fetch_array($result)) {
    $entries[] = $entry;
  }
  return theme('guestbook', $account->uid, $entries, $comment_entry, $limit);
}