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' ? '' : '