Index: guestbook.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/guestbook/Attic/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 19 Feb 2008 23:24:06 -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/Attic/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 19 Feb 2008 23:41:37 -0000 @@ -1,65 +1,95 @@ 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, + ), + ), + '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)); + + $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'"); + return $ret; } @@ -69,15 +99,21 @@ 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', 'not null' => TRUE), + array('primary key' => array('id'))); + + return $ret; +} + Index: guestbook.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/guestbook/Attic/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 19 Feb 2008 23:38:07 -0000 @@ -25,76 +25,80 @@ 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' => '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) { + $items['guestbook'] = array( + 'title' => variable_get('guestbook_site_title', 'Site guestbook'), + 'access arguments' => array('access site guestbook'), + 'page callback' => 'guestbook_page', + ); + } + 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, + $items['guestbook/' . $user->uid] = array( + 'title' => 'My guestbook' . $unread, 'type' => MENU_DYNAMIC_ITEM, ); } - } - if (arg(0) == 'guestbook' && is_numeric(arg(1))) { + } + 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, + $items['guestbook/'. $uid] = array( 'title' => $title, - 'access' => $uid == 0 ? user_access('access site guestbook') : user_access('access user guestbooks'), + 'access callback' => '_guestbook_access_guestbook_uid', + 'access arguments' => array($uid), 'type' => MENU_CALLBACK, - 'callback' => 'guestbook_page', - 'callback arguments' => array($uid), + 'page callback' => 'guestbook_page', + 'page 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'), + $items['guestbook/'. $uid . '/form'] = array( + 'title' => 'Add guestbook entry', + 'access callback' => '_guestbook_post_guestbook_uid', + 'access arguments' => array($uid), 'type' => MENU_CALLBACK, - 'callback' => 'guestbook_page_form', - 'callback arguments' => array($uid), + 'page callback' => 'guestbook_page_form', + 'page arguments' => array($uid), ); - } } return $items; } +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'); +} + /** * Implementation of hook_user() */ @@ -105,13 +109,14 @@ function guestbook_user($op, &$edit, &$u case 'view': if (user_access('access user guestbooks') && $user->guestbook_status == 0) { $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); + return; } break; @@ -163,8 +168,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.'); } @@ -503,20 +508,33 @@ 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)", $edit['anonname'], $edit['anonemail'], $edit['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, %d, '%s', %d)", $user->uid, $uid, $message, time()); } } return '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) { $output = ''; $access = $form['access']['#value']; @@ -703,8 +721,8 @@ function theme_guestbook_entry($uid, $en if ($comment_entry != $entry['id']) { $pager = $_GET['page'] ? 'page='. $_GET['page'] : NULL; $output .= '