Index: bio/bio.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/bio/bio.info,v retrieving revision 1.1 diff -u -p -r1.1 bio.info --- bio/bio.info 30 Jan 2007 06:25:59 -0000 1.1 +++ bio/bio.info 19 Dec 2008 01:14:56 -0000 @@ -1,3 +1,4 @@ ; $Id: bio.info,v 1.1 2007/01/30 06:25:59 vauxia Exp $ name = Bio +core = 6.x description = Use a custom node type for user bios Index: bio/bio.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/bio/bio.install,v retrieving revision 1.1.2.6 diff -u -p -r1.1.2.6 bio.install --- bio/bio.install 25 Mar 2008 16:09:44 -0000 1.1.2.6 +++ bio/bio.install 19 Dec 2008 01:14:56 -0000 @@ -10,26 +10,23 @@ * Implementation of hook_install(). */ function bio_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {bio} ( - nid int unsigned NOT NULL default '0', - uid int unsigned NOT NULL default '0', - PRIMARY KEY (nid, uid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {bio} ( - nid int_unsigned NOT NULL default '0', - uid int_unsigned NOT NULL default '0', - PRIMARY KEY (nid, uid) - )"); - break; - } + drupal_install_schema('bio'); drupal_set_message(t('You can configure the bio module on the bio settings page.', array('@url' => url('admin/user/bio')))); } +/** + * Implementation of hook_schema(). + */ +function bio_schema() { + $schema['bio'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10')), + 'primary key' => array('nid', 'uid'), + ); + return $schema; +} + /** * @defgroup bio-updates-legacy Bio updates for versions prior to 5.x-1.x * @{ @@ -116,4 +113,4 @@ function bio_uninstall() { variable_del('bio_profile_takeover'); variable_del('bio_regstration_form'); variable_del('bio_regstration_form_fields'); -} \ No newline at end of file +} Index: bio/bio.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/bio/bio.module,v retrieving revision 1.2.2.28 diff -u -p -r1.2.2.28 bio.module --- bio/bio.module 24 Mar 2008 19:16:34 -0000 1.2.2.28 +++ bio/bio.module 19 Dec 2008 01:14:56 -0000 @@ -11,10 +11,10 @@ * - Add CCK fields to the user registration form. */ -// Panels integration. -if (module_exists('panels')) { - include_once drupal_get_path('module', 'bio') .'/bio_panels.inc'; -} +// Panels integration. - deprecated until someone can update it +// if (module_exists('panels')) { +// include_once drupal_get_path('module', 'bio') .'/bio_panels.inc'; +// } /** * Implementation of hook_init(). @@ -35,58 +35,55 @@ function bio_init() { /** * Implementation of hook_menu(). */ -function bio_menu($may_cache) { +function bio_menu() { global $user; $items = array(); - - if ($may_cache) { - $items[] = array( - 'path' => 'admin/user/bio', - 'title' => t('User biographies'), - 'description' => t('User biographies'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('bio_settings'), + $items['admin/user/bio'] = array( + 'title' => 'User biographies', + 'description' => 'User biographies', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('bio_settings'), + 'access callback' => 'bio_menu_access', + 'access arguments' => array(1), + ); + if (variable_get('bio_profile', 0)) { + $type = bio_get_type(); + $items['user/%user/bio'] = array( + 'title' => node_get_types('name', $type), + 'page callback' => 'bio_menu_page', + 'page arguments' => array(1), + 'type' => MENU_LOCAL_TASK, + 'access callback' => 'bio_menu_access', + 'access arguments' => array(1), ); } - else { - if (variable_get('bio_profile', 0) && (arg(0) == 'user') && (is_numeric(arg(1)))) { - $type = bio_get_type(); - $nid = bio_for_user(arg(1)); + return $items; +} - // Determine access based on whether user has a bio. - if ($nid) { - $node = node_load($nid); - $access = node_access('update', $node); - } - else { - $node = (object) array('type' => $type, 'uid' => arg(1)); - $access = (($user->uid == arg(1)) && node_access('create', $type)) || user_access('administer nodes'); - } - $items[] = array( - 'path' => 'user/'. arg(1) .'/bio', - 'title' => node_get_types('name', $type), - 'callback' => 'node_page_edit', - 'callback arguments' => array($node), - 'type' => MENU_LOCAL_TASK, - 'access' => $access, - ); - } - elseif (variable_get('bio_profile', 0) && (arg(0) == 'node') && is_numeric(arg(1)) && !arg(2)) { - // If we're about to visit a bio node page, but we've got "use bios for profiles" selected, - // redirect to the user page. - $node = node_load(arg(1)); - if (user_access('access user profiles') && $node->type == bio_get_type()) { - drupal_goto('user/'. $node->uid); - } - } +function bio_menu_page($arg) { + module_load_include('inc','node','node.pages'); + $type = variable_get('bio_nodetype','bio'); + $nid = bio_for_user($arg->uid); + $node = $nid ? node_load($nid) : (object) array('type' => $type, 'uid' => $arg->uid, 'name' => $arg->name); + return drupal_get_form($type.'_node_form',$node); +} + +function bio_menu_access($arg) { + $nid = bio_for_user(arg(1)); + if ($nid) { + $node = node_load($nid); + return node_access('update', $node); + } + else { + $node = (object) array('type' => $type, 'uid' => arg(1)); + return (($user->uid == arg(1)) && node_access('create', $type)) || user_access('administer nodes'); } - return $items; } /** * Implementation of hook_form_alter(). */ -function bio_form_alter($form_id, &$form) { +function bio_form_alter(&$form, $form_state, $form_id) { if ($form_id == bio_get_type() .'_node_form' && arg(0) == 'user') { // We're editing the bio in the user area... be sure we end up here when we // finish submission, and disallow changing the author. @@ -107,52 +104,43 @@ function bio_form_alter($form_id, &$form * * @see bio_user(). */ -function bio_user_register_form() { - $form = array(); +function bio_user_register_form($account) { if (variable_get('bio_regstration_form', 0) && module_exists('content')) { - $widget_types = _content_widget_types(); + $bio_form = array(); $fields = _bio_get_fields(); $default_values = variable_get('bio_regstration_form_fields', array()); - - // Create a dummy node to pass along to the cck hooks. - $node = new stdClass(); - $node->type = bio_get_type(); - + $type = bio_get_type(); + $bio_form['type']['#value'] = $type; $bio_type_name = node_get_types('name', bio_get_type()); + module_load_include('inc', 'content', 'includes/content.node_form'); + $bio_form = content_form($bio_form, $form_state); + unset($bio_form['type']); $form['bio_info'] = array( '#type' => 'fieldset', '#title' => t('@bio_type_name information', array('@bio_type_name' => $bio_type_name)), ); - + $form['bio_info'][$type] = $bio_form; foreach ($fields as $field_name => $field) { if ($field['required'] || !empty($default_values[$field_name])) { - $node_field = content_default_value($node, $field, array()); - - // Figure out what widget function to call. - $module = $widget_types[$field['widget']['type']]['module']; - $function = $module .'_widget'; - - // Get the form field and add it to the form. - $cck_field = $function('prepare form values', $node, $field, $node_field); - $cck_field = $function('form', $node, $field, $node_field); - $form['bio_info'][] = $cck_field; - } + $bio = TRUE; + } else { + unset($form['bio_info'][$type][$field_name]); + } } - // Add custom validate handler. - $form['#validate']['bio_user_register_validate'] = array(); + $form['#validate'][] = 'bio_user_register_validate'; } - return $form; + if ($bio) return $form; } /** * Validate handler for user registration form. Validate CCK fields. */ -function bio_user_register_validate($form_id, $form_values) { +function bio_user_register_validate($form, &$form_state) { // Create a dummy node to pass along to CCK. $node = new stdClass(); $node->type = bio_get_type(); - foreach ($form_values as $field_name => $value) { + foreach ($form_state['values'] as $field_name => $value) { if (preg_match('/^field_/', $field_name)) { $node->$field_name = $form_values[$field_name]; } @@ -166,14 +154,13 @@ function bio_user_register_validate($for * Submit handler for user registration form. Automatically creates a bio node * on registration if any bio fields are set to show on the registration form. */ -function bio_user_register_submit($form_values) { +function bio_user_register_submit($form_values, $account) { // Create bio node for this user. $node = new StdClass; $node->type = bio_get_type(); $node->uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $form_values['name'])); $node->title = $form_values['name']; $node->name = $form_values['name']; - node_object_prepare($node); $node_options = variable_get('node_options_'. $node->type, array('status', 'promote')); foreach (array('status', 'promote', 'sticky') as $key) { @@ -194,21 +181,21 @@ function bio_user_register_submit($form_ // Give us a nice log message. if ($node->nid) { - watchdog('content', t('Bio: added %user bio upon registration.', array('%user' => $node->name)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); + watchdog('content', 'Bio: added %user bio upon registration.', array('%user' => $node->name), WATCHDOG_NOTICE, l('view', "node/$node->nid")); } } /** * Implementation of hook_profile_alter(). */ -function bio_profile_alter(&$account, &$fields) { +function bio_profile_alter(&$account) { // Replace user profile with user bio. if (variable_get('bio_profile_takeover', 0) && $bio = bio_for_user($account->uid)) { $bio = node_load($bio); $typename = node_get_types('name', bio_get_type()); - foreach ($fields as $key => $val) { + foreach ($account->content as $key => $val) { if ($key != $typename) { - unset($fields[$key]); + unset($account->content[$key]); } } $account->name = $bio->title; @@ -240,7 +227,12 @@ function bio_node_info() { */ function bio_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { if ($node->type != bio_get_type()) return; - + if ($op == view && variable_get('bio_profile', 0) && (arg(0) == 'node') && is_numeric(arg(1)) && !arg(2)) { + // If it's a bio node we're going to, redirect to the user page. + if (user_access('access user profiles') && $node->type == bio_get_type()) { + drupal_goto('user/'. $node->uid); + } + } switch ($op) { case 'validate': // Ensure this user doesn't already have a bio node. @@ -272,11 +264,13 @@ function bio_user($op, &$edit, &$account switch ($op) { case 'view': - // Add bio to main user profile page, if option is enabled and bio is accessible. + // Add bio to user profile if option is enabled and bio is accessible. if (variable_get('bio_profile', 0) && node_access('view', $node = node_load($nid))) { $name = node_get_types('name', bio_get_type()); - $bio[$name]['bio']['value'] = node_view($node, FALSE, TRUE, FALSE); - return $bio; + $account->content[$name] = array( + '#type' => 'markup', + '#value' => node_view($node, FALSE, TRUE, FALSE) + ); } break; @@ -297,11 +291,11 @@ function bio_user($op, &$edit, &$account case 'register': // Display CCK fields on the user registration form, if they've been // marked as such. - return bio_user_register_form(); + return bio_user_register_form($account); break; case 'insert': - return bio_user_register_submit($edit); + return bio_user_register_submit($edit, $account); break; } } @@ -421,11 +415,22 @@ function bio_settings() { // Strange hack for invalidating Views cache. $add_a_submit = system_settings_form($form); - $add_a_submit['#validate']['bio_settings_validate_xxx'] = array(); + $add_a_submit['#validate'][] = 'bio_settings_validate_xxx'; return $add_a_submit; } /** + * Implementation of hook_theme(). + */ +function bio_theme() { + return array( + 'bio_registration_fields' => array( + 'arguments' => array('form' => NULL), + ), + ); +} + +/** * Theme function for bio registration form options that adds a disabled flag * to required fields. * @@ -440,7 +445,6 @@ function theme_bio_registration_fields($ $form[$field_name]['#value'] = $field_name; } } - return drupal_render($form); } @@ -454,7 +458,7 @@ function theme_bio_registration_fields($ * * @todo Less hackish way to do this? */ -function bio_settings_validate_xxx($form_id, $form_values) { +function bio_settings_validate_xxx($form, &$form_state) { if (module_exists('views')) { views_invalidate_cache(); } @@ -479,61 +483,12 @@ function bio_get_type() { return variable_get('bio_nodetype', 'bio'); } -/* - * Views integration for Bio module. - * - * Bio module's Views integration works by cloning many features of Views - * module's existing node integration. To avoid a large amount of code being - * loaded on every page, these functions therefore merely call private - * functions in bio_views.inc. - */ - /** - * Implementation of hook_views_table_alter(). - * - * @see _bio_views_tables_alter() + * Implementation of hook_views_api(). */ -function bio_views_tables_alter(&$tables) { - require_once drupal_get_path('module', 'bio') .'/bio_views.inc'; - return _bio_views_tables_alter($tables); -} - -/** - * Copy of views_handler_filter_isnew($op, $filter, $filterinfo, &$query) - * - * @see _bio_handler_filter_isnew() - */ -function bio_handler_filter_isnew($op, $filter, $filterinfo, &$query) { - require_once drupal_get_path('module', 'bio') .'/bio_views.inc'; - return _bio_handler_filter_isnew($op, $filter, $filterinfo, $query); -} - -/** - * Implementation of hook_views_query_alter(). - * - * @see _bio_views_query_alter() - */ -function bio_views_query_alter(&$query, $view, $summary, $level) { - require_once drupal_get_path('module', 'bio') .'/bio_views.inc'; - return _bio_views_query_alter($query, $view, $summary, $level); -} - -/** - * Implementation of hook_views_default_views(). - * - * @see _bio_views_default_views() - */ -function bio_views_default_views() { - require_once drupal_get_path('module', 'bio') .'/bio_views.inc'; - return _bio_views_default_views(); -} - -/** - * Implementation of hook_views_tables(). - * - * @see _bio_views_tables() - */ -function bio_views_tables() { - require_once drupal_get_path('module', 'bio') .'/bio_views.inc'; - return _bio_views_tables(); +function bio_views_api() { + return array( + 'api' => 2, + 'path' => drupal_get_path('module', 'bio') .'/views', + ); } Index: bio/views/bio.views.inc =================================================================== RCS file: bio/views/bio.views.inc diff -N bio/views/bio.views.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ bio/views/bio.views.inc 19 Dec 2008 01:14:56 -0000 @@ -0,0 +1,42 @@ + t('Node'), + 'title' => t('Biography'), + 'help' => t('Create a relationship to the bio node of the user.'), + 'relationship' => array( + 'handler' => 'bio_views_handler_relationship', + 'base' => 'node', + 'base field' => 'uid', + 'label' => t('Biography'), + ), + ); +} + + +/** + * Implementation of hook_views_handlers(). + */ +function bio_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'bio') .'/views', + ), + 'handlers' => array( + 'bio_views_handler_relationship' => array( + 'parent' => 'views_handler_relationship', + ), + ), + ); +} Index: bio/views/bio_views_handler_relationship.inc =================================================================== RCS file: bio/views/bio_views_handler_relationship.inc diff -N bio/views/bio_views_handler_relationship.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ bio/views/bio_views_handler_relationship.inc 19 Dec 2008 01:14:56 -0000 @@ -0,0 +1,55 @@ + 'radios', + '#title' => t('Content type'), + '#default_value' => $this->options['type'], + '#options' => bio_get_type(), + '#required' => TRUE, + ); + } + + /** + * Called to implement a relationship in a query. + */ + function query() { + // Figure out what base table this relationship brings to the party. + $join = new views_join(); + $join->definition = array( + 'table' => 'node', + 'field' => 'uid', + 'left_table' => 'users', + 'left_field' => 'uid', + 'extra' => array( + array('field' => 'type', 'value' => $this->options['type']), + ), + ); + + if (!empty($this->options['required'])) { + $join->definition['type'] = 'INNER'; + } + + $join->construct(); + $this->ensure_my_table(); + + $alias = $join->definition['table'] .'_'. $join->definition['left_table']; + $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship); + } +}