Index: guestbook.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/guestbook/guestbook.info,v retrieving revision 1.1.2.4 diff -u -p -r1.1.2.4 guestbook.info --- guestbook.info 29 Jan 2008 23:34:00 -0000 1.1.2.4 +++ guestbook.info 23 Feb 2008 07:27:04 -0000 @@ -1,3 +1,4 @@ ; $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.1.4.4 diff -u -p -r1.1.4.4 guestbook.install --- guestbook.install 29 Jan 2008 23:34:00 -0000 1.1.4.4 +++ guestbook.install 23 Feb 2008 07:19:14 -0000 @@ -1,65 +1,94 @@ array( + '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'), + 'commentauthor' => array('commentauthor'), + 'created' => array('created'), + ), + 'primary key' => array('id'), + ); + return $schema; +} + +/** + * Implementation of hook_install(). + */ function guestbook_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $query = db_query("CREATE TABLE IF NOT EXISTS {guestbook} ( - id int(10) unsigned NOT NULL default '0', - recipient int(10) unsigned NOT NULL default '0', - author int(10) unsigned NOT NULL default '0', - anonname varchar(64) default NULL, - anonemail varchar(128) default NULL, - anonwebsite varchar(128) default NULL, - message text, - commentauthor int(10) unsigned default NULL, - comment text, - created int(11) unsigned NOT NULL default '0', - PRIMARY KEY (id), - KEY recipient (recipient) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); - break; - case 'pgsql': - $query = db_query("CREATE TABLE {guestbook} ( - id serial, - recipient integer NOT NULL default '0', - author integer NOT NULL default '0', - anonname varchar(64) default NULL, - anonemail varchar(128) default NULL, - anonwebsite varchar(128) default NULL, - message text, - commentauthor integer default NULL, - comment text, - created integer NOT NULL default '0', - PRIMARY KEY (id) - ); CREATE INDEX {guestbook}_recipient_idx ON {guestbook}(recipient);"); - break; - } - if ($query) { - drupal_set_message(t('Guestbook module installed successfully.')); - } - else { - drupal_set_message(t('Table installation for the guestbook module was unsuccessful. The tables may need to be installed by hand. See guestbook.install file for a list of the installation queries.'), 'error'); - } + drupal_install_schema('guestbook'); } + function guestbook_update_1() { $ret = array(); - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql('ALTER TABLE {guestbook} ADD COLUMN anonemail varchar(128)'); - $ret[] = update_sql('ALTER TABLE {guestbook} ADD COLUMN anonwebsite varchar(128)'); - $ret[] = update_sql('ALTER TABLE {guestbook} ADD COLUMN commentauthor int(10) unsigned'); - $ret[] = update_sql('ALTER TABLE {guestbook} MODIFY COLUMN anonname varchar(64)'); - - $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'"); - break; - case 'pgsql': - break; - } + + 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)); + + $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; } @@ -69,15 +98,24 @@ function guestbook_update_2() { function guestbook_update_3() { $ret = array(); - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - case 'pgsql': - $ret[] = update_sql('CREATE INDEX guestbook_author ON {guestbook}(author)'); - $ret[] = update_sql('CREATE INDEX guestbook_commentauthor ON {guestbook}(commentauthor)'); - $ret[] = update_sql('CREATE INDEX guestbook_created ON {guestbook}(created)'); - break; - } + + db_add_index($ret, 'guestbook', 'recipient', array('recipient')); + db_add_index($ret, 'guestbook', 'commentauthor', array('commentauthor')); + db_add_index($ret, 'guestbook', 'created', array('created')); return $ret; } -?> \ No newline at end of file + +function guestbook_update_6001() { + $ret = array(); + + db_drop_primary_key($ret, 'guestbook'); + db_change_field($ret, 'guestbook', 'id', 'id', + 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; +} + + Index: guestbook.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/guestbook/guestbook.module,v retrieving revision 1.1.10.12 diff -u -p -r1.1.10.12 guestbook.module --- guestbook.module 30 Jan 2008 02:44:45 -0000 1.1.10.12 +++ guestbook.module 23 Feb 2008 07:24:31 -0000 @@ -25,77 +25,78 @@ define('GUESTBOOK_TEXTAREA_ROWS', 8); /** * Implementation of hook_menu() */ -function guestbook_menu($may_cache) { +function guestbook_menu() { 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'), - ); + $items['admin/settings/guestbook'] = array( + '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[] = 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', - ); - } + if ($guestbook_mode & GUESTBOOK_USER_GUESTBOOKS) { + $items['guestbook'] = array( + 'title' => 'Guestbooks', + 'access callback' => '_guestbook_access_guestbook', + 'page callback' => 'guestbook_list', + ); } 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), - ); - } + $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'); +} + +/** + * 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'); +} + +/** + * Check menu access for posting into site/user guestbook. + */ +function _guestbook_post_guestbook_uid($user) { + return $user->uid == 0 ? user_access('post in site guestbook') : user_access('post in user guestbooks'); +} + +/** * Implementation of hook_user() */ function guestbook_user($op, &$edit, &$user, $category = '') { @@ -103,17 +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('title' => $title)); - $items[] = array( - 'title' => t('Guestbook'), - 'value' => $link, - 'class' => 'guestbook', + $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 array(t('Guestbook') => $items); } - break; + return; case 'form': if ($category == 'account') { @@ -124,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.'), @@ -163,8 +164,8 @@ function guestbook_perm() { /** * Implementation of hook_help() */ -function guestbook_help($section) { - switch ($section) { +function guestbook_help($path, $arg) { + switch ($path) { case 'admin/modules#description': return t('Adds a site guestbook and individual user guestbooks.'); } @@ -310,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; @@ -344,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'); } /** @@ -396,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; } } @@ -412,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(); @@ -456,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); @@ -475,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); } @@ -503,25 +505,52 @@ function guestbook_form_entry_form_submi if (_guestbook_access('post', $uid) == 'allowed') { if ($user->uid == 0) { // anonymous user - $entryid = db_next_id('{guestbook}_id'); - $result = db_query("INSERT INTO {guestbook} (id, anonname, anonemail, anonwebsite, author, recipient, message, created) - VALUES(%d, '%s', '%s', '%s', %d, %d, '%s', %d)", $entryid, $edit['anonname'], $edit['anonemail'], $edit['anonwebsite'], 0, $uid, $message, time()); + $result = db_query("INSERT INTO {guestbook} (anonname, anonemail, anonwebsite, author, recipient, message, created) + 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 - $entryid = db_next_id('{guestbook}_id'); - $result = db_query("INSERT INTO {guestbook} (id, author, recipient, message, created) - VALUES(%d, %d, %d, '%s', %d)", $entryid, $user->uid, $uid, $message, time()); + $result = db_query("INSERT INTO {guestbook} (author, recipient, message, created) + VALUES(%d, %d, '%s', %d)", $user->uid, $uid, $message, time()); } } - return 'guestbook/'. $uid; + $form_state['redirect'] = 'guestbook/'. $uid; +} + +/** + * Implementation of hook_theme() + */ +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'), + ), + ); } -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': @@ -531,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; @@ -555,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', @@ -571,18 +600,18 @@ 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; } @@ -591,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 @@ -611,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']; } /** @@ -632,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) { @@ -701,10 +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 .= ''; } } @@ -745,13 +774,13 @@ function theme_guestbook_user_picture($u $user_text = t('View guestbooks.'); } - $output = l($account->name ? $account->name : variable_get('anonymous', 'Anonymous'), $user_link, 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('title' => $user_text), NULL, NULL, FALSE, TRUE); + $picture = l($picture, $user_link, array('attributes' => array('title' => $user_text), 'html' => TRUE)); } $output .= "
$picture
"; @@ -810,16 +839,28 @@ 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', t('Site guestbook')); + $info[$uid]['title'] = variable_get('guestbook_site_title', 'Site guestbook'); $info[$uid]['intro'] = variable_get('guestbook_site_intro', ''); } 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 : ''; + } } } } @@ -836,8 +877,8 @@ 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) { - $namelink = l($guestbook_user->name, "user/$uid", array('title' => t('View user profile.'))); + 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)) .'
'; } } @@ -899,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; } @@ -912,7 +953,7 @@ function _guestbook_form_filter_tips() { function _guestbook_spam($source, $id, $header, $body, $probability, $old, $action) { if ($probability > 98) { $msgtext = t('Entry is spam: ') . $header .' '. $body .' probability: '. $probability; - watchdog('guestbook', $msgtext, WATCHDOG_WARNING); + watchdog('guestbook', $msgtext, array(), WATCHDOG_WARNING); drupal_set_message($msgtext, 'error'); return TRUE; }