Index: guestbook.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/guestbook/guestbook.info,v retrieving revision 1.2 diff -u -p -r1.2 guestbook.info --- guestbook.info 21 Feb 2008 08:00:17 -0000 1.2 +++ guestbook.info 23 Feb 2008 03:01:51 -0000 @@ -1,4 +1,4 @@ -; $Id: guestbook.info,v 1.2 2008/02/21 08:00:17 hba Exp $ +; $Id: guestbook.info,v 1.1.2.4 2008/01/29 23:34:00 sun Exp $ name = Guestbook description = "A guestbook for drupal" core = 6.x Index: guestbook.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/guestbook/guestbook.install,v retrieving revision 1.2 diff -u -p -r1.2 guestbook.install --- guestbook.install 21 Feb 2008 08:00:17 -0000 1.2 +++ guestbook.install 23 Feb 2008 07:19:14 -0000 @@ -1,26 +1,66 @@ array( - 'id' => array('type' => 'serial', 'not null' => TRUE), - 'recipient' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), - 'author' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), - 'anonname' => array('type' => 'varchar', 'length' => '128', 'not null' => FALSE), - 'anonemail' => array('type' => 'varchar', 'length' => '128', 'not null' => FALSE), - 'anonwebsite' => array('type' => 'varchar', 'length' => '128', 'not null' => FALSE), - 'message' => array('type' => 'text', 'not null' => TRUE, 'default' => ''), - 'commentauthor' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), - 'comment' => array('type' => 'text', 'not null' => TRUE, 'default' => ''), - 'created' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'id' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'recipient' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'author' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'anonname' => array( + 'type' => 'varchar', + 'length' => '128', + 'not null' => FALSE, + ), + 'anonemail' => array( + 'type' => 'varchar', + 'length' => '128', + 'not null' => FALSE, + ), + 'anonwebsite' => array( + 'type' => 'varchar', + 'length' => '128', + 'not null' => FALSE, + ), + 'message' => array( + 'type' => 'text', + 'not null' => TRUE, + 'default' => '', + ), + 'commentauthor' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'comment' => array( + 'type' => 'text', + 'not null' => TRUE, + 'default' => '', + ), + 'created' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), ), 'indexes' => array( 'recipient' => array('recipient'), @@ -32,17 +72,23 @@ function guestbook_schema() { return $schema; } +/** + * Implementation of hook_install(). + */ +function guestbook_install() { + drupal_install_schema('guestbook'); +} + + function guestbook_update_1() { $ret = array(); - + db_add_field($ret, 'anonemail', 'nid', array('type' => 'varchar', 'not null' => FALSE)); db_add_field($ret, 'anonwebsite', 'nid', array('type' => 'varchar', 'not null' => FALSE)); db_add_field($ret, 'commentauthor', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE)); - - $query = db_query("SELECT max(id) as id FROM {guestbook}"); - $row = db_fetch_object($query); - $ret[] = update_sql("INSERT INTO {sequences} SET name = 'guestbook_id', id = '$row->id'"); - + + $current_id = db_result(db_query("SELECT max(id) as id FROM {guestbook}")); + $ret[] = update_sql("INSERT INTO {sequences} SET name = 'guestbook_id', id = ". (int)$current_id); return $ret; } @@ -52,7 +98,7 @@ function guestbook_update_2() { function guestbook_update_3() { $ret = array(); - + db_add_index($ret, 'guestbook', 'recipient', array('recipient')); db_add_index($ret, 'guestbook', 'commentauthor', array('commentauthor')); db_add_index($ret, 'guestbook', 'created', array('created')); @@ -61,12 +107,15 @@ function guestbook_update_3() { function guestbook_update_6001() { $ret = array(); - + db_drop_primary_key($ret, 'guestbook'); db_change_field($ret, 'guestbook', 'id', 'id', - array('type' => 'serial', 'not null' => TRUE), + array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('id'))); - + db_change_field($ret, 'guestbook', 'anonname', 'anonname', + array('type' => 'varchar', 'length' => '128', 'not null' => FALSE)); + return $ret; } -?> \ No newline at end of file + + Index: guestbook.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/guestbook/guestbook.module,v retrieving revision 1.2 diff -u -p -r1.2 guestbook.module --- guestbook.module 21 Feb 2008 08:00:17 -0000 1.2 +++ guestbook.module 23 Feb 2008 07:24:31 -0000 @@ -1,5 +1,5 @@ 'Guestbook', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('guestbook_admin_settings'), - 'access arguments' => 'administer site configuration', + 'title' => 'Guestbook', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('guestbook_admin_settings'), + 'access arguments' => array('administer site configuration'), ); if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) { - $items['guestbook'] = array( - 'title' => 'Guestbooks', - 'access callback' => '_guestbook_access_guestbook', - 'page callback' => 'guestbook_list', - ); + $items['guestbook'] = array( + 'title' => 'Guestbooks', + 'access callback' => '_guestbook_access_guestbook', + 'page callback' => 'guestbook_list', + ); } else { - $items['guestbook'] = array( - 'title' => variable_get('guestbook_site_title', 'Site guestbook'), - 'access arguments' => array('access site guestbook'), - 'page callback' => 'guestbook_page', - ); + $items['guestbook'] = array( + 'title' => variable_get('guestbook_site_title', 'Site guestbook'), + 'access arguments' => array('access site guestbook'), + 'page callback' => 'guestbook_page', + 'page arguments' => array(0), + ); + } + if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) { + $items['guestbook/%user_current'] = array( + 'title' => 'User guestbook', + 'title callback' => '_guestbook_info', + 'title arguments' => array(1, 'title'), + 'access callback' => '_guestbook_access_guestbook_uid', + 'access arguments' => array(1), + 'page callback' => 'guestbook_page', + 'page arguments' => array(1), + ); } + $items['guestbook/%user/form'] = array( + 'title' => 'Add guestbook entry', + 'access callback' => '_guestbook_post_guestbook_uid', + 'access arguments' => array(1), + 'page callback' => 'guestbook_page_form', + 'page arguments' => array(1), + 'type' => MENU_CALLBACK, + ); return $items; } +/** + * Check menu access for Guestbooks overview page. + */ function _guestbook_access_guestbook() { return user_access('access site guestbook') || user_access('access user guestbooks'); } -function _guestbook_access_guestbook_uid($uid) { - return $uid == 0 ? user_access('access site guestbook') : user_access('access user guestbooks'); -} - -function _guestbook_post_guestbook_uid($uid) { - return $uid == 0 ? user_access('post in site guestbook') : user_access('post in user guestbooks'); +/** + * Check menu access for site/user guestbook. + */ +function _guestbook_access_guestbook_uid($user) { + return $user->uid == 0 ? user_access('access site guestbook') : user_access('access user guestbooks'); } /** - * Implementation of hook_menu() + * Check menu access for posting into site/user guestbook. */ -function guestbook_menu() { - global $user; - $items = array(); - $guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS); - - if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) { - if ($user->uid > 0 && _guestbook_exists($user->uid)) { - $unread = _guestbook_newentries(); - $unread = $unread ? ' ('. $unread .')' : ""; - $items['guestbook/' . $user->uid] = array( - 'title' => '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['guestbook/'. $uid] = array( - 'title' => $title, - 'access callback' => '_guestbook_access_guestbook_uid', - 'access arguments' => array($uid), - 'type' => MENU_CALLBACK, - 'page callback' => 'guestbook_page', - 'page arguments' => array($uid), - ); - } - $items['guestbook/'. $uid . '/form'] = array( - 'title' => 'Add guestbook entry', - 'access callback' => '_guestbook_post_guestbook_uid', - 'access arguments' => array($uid), - 'type' => MENU_CALLBACK, - 'page callback' => 'guestbook_page_form', - 'page arguments' => array($uid), - ); - } - - return $items; +function _guestbook_post_guestbook_uid($user) { + return $user->uid == 0 ? user_access('post in site guestbook') : user_access('post in user guestbooks'); } /** @@ -120,19 +104,17 @@ function guestbook_user($op, &$edit, &$u if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) { switch ($op) { case 'view': - if (user_access('access user guestbooks') && $user->guestbook_status == 0) { + 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'), "guestbook/$user->uid", - array('attributes' => array('title' => $title))); + $link = l(t('View recent guestbook entries'), "guestbook/$user->uid", array('attributes' => array('title' => $title))); $user->content['summary']['guestbook'] = array( '#type' => 'user_profile_item', '#title' => t('Guestbook'), '#value' => $link, '#attributes' => array('class' => 'guestbook'), ); - return; } - break; + return; case 'form': if ($category == 'account') { @@ -143,19 +125,19 @@ function guestbook_user($op, &$edit, &$u $form['guestbook']['guestbook_status'] = array( '#type' => 'radios', '#title' => t('Status'), - '#default_value' => $edit['guestbook_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'] : 1, + '#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' => $edit['guestbook_intro'], + '#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.'), @@ -329,24 +311,25 @@ function guestbook_admin_settings() { * Shows a user or site guestbook * (menu callback) */ -function guestbook_page($uid = 0, $op = NULL, $op_id = NULL) { +function guestbook_page($account, $op = NULL, $op_id = NULL) { global $user; - if (!_guestbook_exists($uid)) { + if (!_guestbook_exists($account->uid)) { drupal_not_found(); return; } // Set last visited time for own guestbook - if ($uid > 0 && $user->uid == $uid) { + if ($account->uid > 0 && $account->uid == $user->uid) { user_save($user, array('guestbook_visited' => time())); } // Delete or comment an entry - if (_guestbook_access('administer', $uid) && is_numeric($op_id)) { + $comment_entry = ''; + if (_guestbook_access('administer', $account->uid) && is_numeric($op_id)) { switch ($op) { case 'delete': - return guestbook_delete_entry_confirm_page($uid, $op_id); + return guestbook_delete_entry_confirm_page($account->uid, $op_id); case 'comment': $comment_entry = $op_id; @@ -363,26 +346,26 @@ function guestbook_page($uid = 0, $op = LEFT JOIN {users} u2 ON g.commentauthor = u2.uid WHERE g.recipient = %d ORDER BY g.created DESC", - $limit, 0, "SELECT COUNT(*) FROM {guestbook} WHERE recipient = %d", $uid + $limit, 0, "SELECT COUNT(*) FROM {guestbook} WHERE recipient = %d", $account->uid ); $entries = array(); while ($entry = db_fetch_array($result)) { $entries[] = $entry; } - return theme('guestbook', $uid, $entries, $comment_entry, $limit); + return theme('guestbook', $account->uid, $entries, $comment_entry, $limit); } /** * Display the guestbook form on a separate page * (menu callback) */ -function guestbook_page_form($uid) { - if (!_guestbook_exists($uid)) { +function guestbook_page_form($account) { + if (!_guestbook_exists($account->uid)) { drupal_not_found(); return; } - return guestbook_form_entry($uid, 'page'); + return guestbook_form_entry($account->uid, 'page'); } /** @@ -415,7 +398,7 @@ function guestbook_list() { else if ($guestbook['uid'] > 0 && user_access('access user guestbooks')) { // user guestbooks $data = unserialize($guestbook['data']); - if ($data['guestbook_status'] == 0) { + if (empty($data['guestbook_status'])) { $guestbooks[$guestbook['uid']] = $guestbook; } } @@ -431,7 +414,7 @@ function guestbook_form_entry($uid, $dis return $output; } -function guestbook_form_entry_form($uid, $display = '') { +function guestbook_form_entry_form($form_state, $uid, $display = '') { global $user; $form = array(); @@ -475,11 +458,11 @@ function guestbook_form_entry_form($uid, return $form; } -function guestbook_form_entry_form_submit($form_id, $edit) { +function guestbook_form_entry_form_submit($form, &$form_state) { global $user; - $uid = $edit['uid']; - $message = $edit['message']; + $uid = $form_state['values']['uid']; + $message = $form_state['values']['message']; // Make sure this isn't a dupe $result = db_query("SELECT message FROM {guestbook} WHERE recipient = %d ORDER BY id DESC LIMIT 1", $uid); @@ -494,27 +477,27 @@ function guestbook_form_entry_form_submi if (module_exists('spam')) { // Is this spam? - $spamcheck = $edit['anonname'] .' '. $edit['anonemail'] .' '. $edit['anonwebsite']; + $spamcheck = $form_state['values']['anonname'] .' '. $form_state['values']['anonemail'] .' '. $form_state['values']['anonwebsite']; if (spam_content_filter('guestbook', 1, $spamcheck, $message, '_guestbook_spam')) { return; } } // E-mail notification - $iSendEMail = ''; + $iSendEmail = ''; $guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS); if ($uid == 0 && ($guestbook_mode & GUESTBOOK_SITE_GUESTBOOK)) { $iSendEmail = variable_get('guestbook_send_email', ''); } else if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) { $guestbook_user = ($uid != $user->uid) ? user_load(array('uid' => $uid, 'status' => 1)) : $user; - if ($guestbook_user->uid && $guestbook_user->guestbook_status == 0 && $guestbook_user->guestbook_send_email) { + if ($guestbook_user->uid && empty($guestbook_user->guestbook_status) && !empty($guestbook_user->guestbook_send_email)) { $iSendEmail = $guestbook_user->mail; } } $from = variable_get('site_mail', ini_get('sendmail_from')); - if ($iSendEmail != '') { + if ($iSendEmail) { drupal_mail('guestbook_notification', $iSendEmail, 'New guestbook entry', $message, $from); } @@ -523,15 +506,15 @@ function guestbook_form_entry_form_submi if ($user->uid == 0) { // anonymous user $result = db_query("INSERT INTO {guestbook} (anonname, anonemail, anonwebsite, author, recipient, message, created) - VALUES('%s', '%s', '%s', %d, %d, '%s', %d)", $edit['anonname'], $edit['anonemail'], $edit['anonwebsite'], 0, $uid, $message, time()); + VALUES('%s', '%s', '%s', %d, %d, '%s', %d)", $form_state['values']['anonname'], $form_state['values']['anonemail'], $form_state['values']['anonwebsite'], 0, $uid, $message, time()); } else { // registered user $result = db_query("INSERT INTO {guestbook} (author, recipient, message, created) - VALUES(%d, %d, %d, '%s', %d)", $user->uid, $uid, $message, time()); + VALUES(%d, %d, '%s', %d)", $user->uid, $uid, $message, time()); } } - return 'guestbook/'. $uid; + $form_state['redirect'] = 'guestbook/'. $uid; } /** @@ -539,23 +522,35 @@ function guestbook_form_entry_form_submi */ function guestbook_theme() { return array( - 'guestbook_form_entry_form' => array('arguments' => array('form')), - 'guestbook_form_comment_form' => array('arguments' => array('form')), - 'guestbook' => array('arguments' => array('uid', 'entries', 'comment_entry', 'limit')), - 'guestbook_entry' => array('arguments' => - array('uid', 'entry', 'comment_entry', 'zebra', 'confirm_delete')), - 'guestbook_user_picture' => array('arguments' => array('form')), - 'guestbook_entry_comment' => array('arguments' => array('uid', 'entry', 'comment_entry')), - 'guestbook_list' => array('arguments' => array('guestbooks', 'header', 'limit')), + 'guestbook_form_entry_form' => array( + 'arguments' => array('form'), + ), + 'guestbook_form_comment_form' => array( + 'arguments' => array('form'), + ), + 'guestbook' => array( + 'arguments' => array('uid', 'entries', 'comment_entry', 'limit'), + ), + 'guestbook_entry' => array( + 'arguments' => array('uid', 'entry', 'comment_entry', 'zebra', 'confirm_delete'), + ), + 'guestbook_user_picture' => array( + 'arguments' => array('form'), + ), + 'guestbook_entry_comment' => array( + 'arguments' => array('uid', 'entry', 'comment_entry'), + ), + 'guestbook_list' => array( + 'arguments' => array('guestbooks', 'header', 'limit'), + ), ); - } -function theme_guestbook_form_entry_form($form) { +function theme_guestbook_form_entry_form($form_state) { $output = ''; - $access = $form['access']['#value']; - $display = $form['display']['#value']; - $uid = $form['uid']['#value']; + $access = $form_state['access']['#value']; + $display = $form_state['display']['#value']; + $uid = $form_state['uid']['#value']; switch ($access) { case 'allowed': @@ -565,7 +560,7 @@ function theme_guestbook_form_entry_form } else { $output .= $display == 'page' ? '' : '

'. t('Add guestbook entry') .'

'; - $output .= drupal_render($form); + $output .= drupal_render($form_state); } break; @@ -589,7 +584,7 @@ function guestbook_form_comment($uid, $e return $output; } -function guestbook_form_comment_form($uid, $entry) { +function guestbook_form_comment_form($form_state, $uid, $entry) { $form = array(); $form['comment'] = array( '#type' => 'textfield', @@ -605,18 +600,19 @@ function guestbook_form_comment_form($ui return $form; } -function guestbook_form_comment_form_submit($form_id, $edit) { +function guestbook_form_comment_form_submit($form, &$form_state) { global $user; - if (_guestbook_access('administer', $edit['uid'])) { - db_query("UPDATE {guestbook} SET comment = '%s', commentauthor = %d WHERE id = %d", $edit['comment'], $user->uid, $edit['entry_id']); + if (_guestbook_access('administer', $form_state['values']['uid'])) { + db_query("UPDATE {guestbook} SET comment = '%s', commentauthor = %d WHERE id = %d", $form_state['values']['comment'], $user->uid, $form_state['values']['entry_id']); } - return array('guestbook/'. $edit['uid'], $_GET['page'] ? 'page='. $_GET['page'] : NULL); + $form_state['redirect'] = array('guestbook/'. $form_state['values']['uid'], !empty($_GET['page']) ? 'page='. $_GET['page'] : NULL); } -function theme_guestbook_form_comment_form($form) { +function theme_guestbook_form_comment_form($form_state) { $output = ''; $output .= '
'; - $output .= drupal_render($form); + $output .= drupal_render($form_state); + $output .= '
'; return $output; } @@ -624,7 +620,7 @@ function guestbook_delete_entry_confirm_ return drupal_get_form('guestbook_delete_entry_confirm', $uid, $entry_id); } -function guestbook_delete_entry_confirm($uid, $entry_id) { +function guestbook_delete_entry_confirm($form_state, $uid, $entry_id) { $entry = db_fetch_array(db_query( "SELECT g.*, u1.name, u1.data, u1.picture, u2.name as commentby FROM {guestbook} g @@ -644,11 +640,11 @@ function guestbook_delete_entry_confirm( ); } -function guestbook_delete_entry_confirm_submit($form_id, $form_values) { - if (_guestbook_access('administer', $form_values['uid']) && $form_values['confirm']) { - db_query("DELETE FROM {guestbook} WHERE id = %d", $form_values['entry_id']); +function guestbook_delete_entry_confirm_submit($form, &$form_state) { + if (_guestbook_access('administer', $form_state['values']['uid']) && $form_state['values']['confirm']) { + db_query("DELETE FROM {guestbook} WHERE id = %d", $form_state['values']['entry_id']); } - return 'guestbook/'. $form_values['uid']; + $form_state['redirect'] = 'guestbook/'. $form_state['values']['uid']; } /** @@ -665,10 +661,10 @@ function theme_guestbook($uid, $entries, $output .= _guestbook_user_profile_link($uid); // form on separate page - $output .= $form_location == 'separate page' ? guestbook_form_entry($uid, 'link') : ''; + $output .= ($form_location == 'separate page' ? guestbook_form_entry($uid, 'link') : ''); // form and pager above entries - $output .= $form_location == 'above' ? guestbook_form_entry($uid) : ''; - $output .= $pager_position & GUESTBOOK_PAGER_ABOVE ? theme('pager', NULL, $limit, 0) : ''; + $output .= ($form_location == 'above' ? guestbook_form_entry($uid) : ''); + $output .= ($pager_position & GUESTBOOK_PAGER_ABOVE ? theme('pager', NULL, $limit, 0) : ''); $i = 0; foreach ($entries as $entry) { @@ -734,11 +730,10 @@ function theme_guestbook_entry($uid, $en // links if (_guestbook_access('administer', $uid) && !$confirm_delete) { if ($comment_entry != $entry['id']) { - $pager = $_GET['page'] ? 'page='. $_GET['page'] : NULL; + $pager = !empty($_GET['page']) ? 'page='. $_GET['page'] : NULL; $output .= ''; } } @@ -778,20 +773,14 @@ function theme_guestbook_user_picture($u $user_link = 'guestbook'; $user_text = t('View guestbooks.'); } - if (empty($account->name)) { - $accountname = $account->name; - } else { - $accountname = variable_get('anonymous', 'Anonymous'); - } - $output = l($accountname, $user_link, array('attributes' => array("title" => $user_text))); + + $output = l($account->name ? $account->name : variable_get('anonymous', 'Anonymous'), $user_link, array('attributes' => array("title" => $user_text))); if (isset($picture)) { $alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', 'Anonymous'))); $picture = theme('image', $picture, $alt, $alt, '', false); if (!empty($account->uid) && user_access('access user profiles')) { - $picture = l($picture, $user_link, - array('attributes' => array('title' => $user_text), - 'html' => TRUE)); + $picture = l($picture, $user_link, array('attributes' => array('title' => $user_text), 'html' => TRUE)); } $output .= "
$picture
"; @@ -850,6 +839,9 @@ function _guestbook_info($uid, $data) { static $info; $guestbook_mode = variable_get('guestbook_mode', GUESTBOOK_SITE_GUESTBOOK | GUESTBOOK_USER_GUESTBOOKS); + if (is_object($uid)) { + $uid = $uid->uid; + } if (!isset($info[$uid])) { if ($uid == 0 && ($guestbook_mode & GUESTBOOK_SITE_GUESTBOOK)) { $info[$uid]['title'] = variable_get('guestbook_site_title', 'Site guestbook'); @@ -857,9 +849,18 @@ function _guestbook_info($uid, $data) { } else if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) { $guestbook_user = ($uid != $user->uid) ? user_load(array('uid' => $uid, 'status' => 1)) : $user; - if ($guestbook_user->uid && $guestbook_user->guestbook_status == 0) { - $info[$uid]['title'] = t("@username's guestbook", array('@username' => $guestbook_user->name)); - $info[$uid]['intro'] = $guestbook_user->guestbook_intro; + if ($guestbook_user->uid && empty($guestbook_user->guestbook_status)) { + if ($uid != $user->uid) { + // Guestbook of other users. + $info[$uid]['title'] = t("@username's guestbook", array('@username' => $guestbook_user->name)); + $info[$uid]['intro'] = !empty($guestbook_user->guestbook_intro) ? $guestbook_user->guestbook_intro : ''; + } + else { + // Own guestbook. + $unread = _guestbook_newentries(); + $info[$uid]['title'] = t('My guestbook') . ($unread ? ' ('. $unread .')' : ''); + $info[$uid]['intro'] = !empty($guestbook_user->guestbook_intro) ? $guestbook_user->guestbook_intro : ''; + } } } } @@ -876,7 +877,7 @@ function _guestbook_user_profile_link($u $output = ''; if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS && user_access('access user profiles') && $uid != $user->uid) { $guestbook_user = user_load(array('uid' => $uid, 'status' => 1)); - if ($guestbook_user->uid && $guestbook_user->guestbook_status == 0) { + if ($guestbook_user->uid && empty($guestbook_user->guestbook_status)) { $namelink = l($guestbook_user->name, "user/$uid", array('attributes' => array('title' => t('View user profile.')))); $output .= '
'. t("Visit !username's profile", array('!username' => $namelink)) .'
'; } @@ -939,7 +940,7 @@ function _guestbook_timeinterval($time) function _guestbook_newentries() { global $user; - $count = db_result(db_query("SELECT COUNT(created) FROM {guestbook} WHERE recipient = %d AND created > %d", $user->uid, $user->guestbook_visited)); + $count = db_result(db_query("SELECT COUNT(created) FROM {guestbook} WHERE recipient = %d AND created > %d", $user->uid, isset($user->guestbook_visited) ? $user->guestbook_visited : time())); return $count; }