? LICENSE.txt ? nodeprofile-display-add-link.tpl.php ? nodeprofile-display-full.tpl.php ? nodeprofile-display-teaser.tpl.php ? np.txt Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/nodeprofile/README.txt,v retrieving revision 1.25 diff -u -r1.25 README.txt --- README.txt 6 May 2007 12:44:00 -0000 1.25 +++ README.txt 20 Jan 2008 11:11:13 -0000 @@ -1,4 +1,4 @@ -$Id: README.txt,v 1.25 2007/05/06 12:44:00 fago Exp $ +$Id: README.txt,v 1.22.2.4 2007/05/06 12:44:10 fago Exp $ Nodeprofile Module ------------------------ Index: nodeprofile.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/nodeprofile/nodeprofile.info,v retrieving revision 1.4 diff -u -r1.4 nodeprofile.info --- nodeprofile.info 18 Jun 2007 23:50:55 -0000 1.4 +++ nodeprofile.info 20 Jan 2008 11:11:13 -0000 @@ -1,6 +1,12 @@ -; $Id: nodeprofile.info,v 1.4 2007/06/18 23:50:55 dww Exp $ +; $Id: nodeprofile.info,v 1.1.2.3 2007/06/18 23:06:54 dww Exp $ name = "Node Profile" description = "Marks content types as profiles." package = "Node Profile" -dependencies = nodefamily subform_element +dependencies[] = subform_element +core = 6.x + +; Information added by drupal.org packaging script on 2007-10-30 +version = "6.x-1.x-dev" +project = "nodeprofile" +datestamp = "1193746047" Index: nodeprofile.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/nodeprofile/nodeprofile.install,v retrieving revision 1.5 diff -u -r1.5 nodeprofile.install --- nodeprofile.install 5 Apr 2007 10:27:40 -0000 1.5 +++ nodeprofile.install 20 Jan 2008 11:11:13 -0000 @@ -1,5 +1,5 @@ 'admin/content/types/'. arg(3) .'/edit', - 'title' => t('Edit'), + //Register a path for each node + $types = node_get_types('names'); + foreach ($types as $type => $typename) { + if (is_nodeprofile($type)) { + $items['admin/content/types/'. str_replace('_', '-', $type) .'/edit'] = array( + 'title' => 'Edit', 'type' => MENU_DEFAULT_LOCAL_TASK, ); - $items[] = array( - 'path' => 'admin/content/types/'. arg(3) .'/nodeprofile', - 'title' => t('Node profile'), - 'description' => t('Configure the display and management of this node profile.'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('nodeprofile_admin_settings', $type), - 'access' => user_access('administer nodes'), + $items['admin/content/types/'. str_replace('_', '-', $type) .'/nodeprofile'] = array( + 'title' => 'Node profile', + 'description' => 'Configure the display and management of this node profile.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('nodeprofile_admin_settings', $type), + 'access callback' => 'user_access', + 'access arguments' => array('administer nodes'), 'type' => MENU_LOCAL_TASK, 'weight' => 1, ); - } - } - else if ($may_cache) { - if (module_exists('usernode')) { - // prevent the deletion of the usernode-ct - nodeprofile-ct relation - $items[] = array( - 'path' => 'admin/content/nodefamily/'. USERNODE_CONTENT_TYPE, - 'title' => t('delete relation'), - 'callback' => 'nodeprofile_keep_relation', - 'access' => user_access('administer nodes'), - 'type' => MENU_CALLBACK, + $items['user/%/edit/'. str_replace('_', '-', $type)] = array( + 'title' => 'Node profile', + 'description' => 'Configure the display and management of this node profile.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('nodeprofile_admin_settings', $type), + 'access callback' => 'user_access', + 'access arguments' => array('administer nodes'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 1, ); } } + return $items; } /** * Menu callback; node profile settings. */ -function nodeprofile_admin_settings($type) { +function nodeprofile_admin_settings($type_something, $type) { $form['integration'] = array( '#type' => 'fieldset', '#title' => t('Input Form Integration'), @@ -72,24 +71,9 @@ '#type' => 'checkbox', '#title' => t("Show this node profile during user registration."), '#default_value' => nodeprofile_get_settings('register', $type), - '#description' => t('If selected this node profile\'s form will be shown on the user register page. ') . + '#description' => t('If selected this node profile\'s form will be shown on the user register page. ') . t('Note that this will bypass the node creation permission settings, so this will work for your users regardless if they have access to edit or create their nodeprofile later!'), ); - if (module_exists('rolesignup')) { - // List roles having Role Signup's "register for role" permission - if ($roles = user_roles(TRUE, 'register for role')) { - $form['integration']['register_roles'] = array( - '#type' => 'checkboxes', - '#title' => t('Roles allowed to see this node profile during user registration'), - '#default_value' => nodeprofile_get_settings('register_roles', $type), - '#options' => $roles, - '#description' => t('If the Show this node profile during user registration option has been enabled, you may select what roles will see it. If no role is selected, all users will see this node profile. Note that this feature relies on the Role Signup module.'), - ); - } - } - else { - $form['integration']['#description'] .= '
'. t('The !rolesignup module is currently not installed. If installed, it would allow you show this node profile only to users who register for specific roles.', array('!rolesignup' => l(t('Role Signup'), 'http://drupal.org/project/rolesignup'))); - } $form['weight'] = array( '#type' => 'weight', '#title' => t("Weight"), @@ -134,41 +118,18 @@ return $form; } -function nodeprofile_admin_settings_submit($form_id, $form_values) { +function nodeprofile_admin_settings_submit($form, &$form_state) { $settings = nodeprofile_get_settings(); foreach (nodeprofile_available_settings() as $setting) { - if (is_array($form_values[$setting])) { - $form_values[$setting] = array_filter($form_values[$setting]); + if (is_array($form_state['values'][$setting])) { + $form_state['values'][$setting] = array_filter($form_state['values'][$setting]); } - $settings[$setting][$form_values['type']] = $form_values[$setting]; + $settings[$setting][$form_state['values']['type']] = $form_state['values'][$setting]; } nodeprofile_set_settings($settings); drupal_set_message('Your changes have been saved.'); } - - -/** - * Menu callback. - * Hooks into admin/content/nodefamily/usernode which is normally handled by - * the nodefamily module, but gets special handling here for relations that - * may not be deleted. - */ -function nodeprofile_keep_relation() { - - if (is_nodeprofile(arg(4))) { - drupal_set_message(t('You may not delete this relation manually. To remove it unmark the '. - 'content type "%type" as nodeprofile.', - array('%type' => node_get_types('name', arg(4)))), 'error'); - drupal_goto('admin/content/nodefamily'); - } - else { - // proceed with deletion - return nodefamily_admin_page(); - } -} - - /** * Determine if a given node is a nodeprofile. * @param $type The node object or the node's type @@ -234,39 +195,30 @@ /** * Implementation of hook_form_alter(). */ -function nodeprofile_form_alter($form_id, &$form) { - +function nodeprofile_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'node_type_form' && ( !module_exists('usernode') || $form['#node_type']->type != USERNODE_CONTENT_TYPE )) { - - /* The 'nodeprofile_type' field is in the workflow fieldset at the moment, - * because the buttons are not properly weighted. - * TODO: if node_type_form() in node's content_types.inc fixes this, - * we can think about switching back to our own block. - */ - /* $form['nodeprofile'] = array( '#type' => 'fieldset', '#title' => t('Node Profile'), '#collapsible' => 1, '#weight' => 32, - );*/ - $form['workflow']['nodeprofile'] = array( + ); + $form['nodeprofile']['nodeprofile'] = array( '#type' => 'checkbox', '#title' => t('Use this content type as a nodeprofile for users'), '#default_value' => is_nodeprofile($form['#node_type']->type), '#return_value' => 1, ); - $form['#submit']['nodeprofile_node_settings_submit'] = array( - is_nodeprofile($form['#node_type']->type), + $form['#submit'][] = 'nodeprofile_node_settings_submit'; + //$form['nodeprofile_node_settings'] = is_nodeprofile($form['#node_type']->type); + $form['nodeprofile']['is_nodeprofile'] = array( + '#type' => 'value', + '#value' => is_nodeprofile($form['#node_type']->type), ); - - if (is_nodeprofile($form['#node_type']->type)) { - $form['workflow']['nodefamily_max']['#disabled'] = TRUE; - } } else if (module_exists('rolesignup') && $form_id == 'user_admin_perm') { - $form['#submit']['nodeprofile_user_admin_perm_submit'] = array(); + $form['#submit'][] = 'nodeprofile_user_admin_perm_submit'; } } @@ -278,7 +230,7 @@ * we get the expected behavior when no specific role is enabled for * registration in the nodeprofile settings. */ -function nodeprofile_user_admin_perm_submit($form_id, $form_values) { +function nodeprofile_user_admin_perm_submit($form, &$form_state) { $settings = nodeprofile_get_settings(); $user_roles = user_roles(TRUE, 'register for role'); if (isset($settings['register_roles'])) { @@ -290,25 +242,12 @@ } } } - nodeprofile_set_settings($settings); } + nodeprofile_set_settings($settings); } -function nodeprofile_node_settings_submit($form_id, $form_values, $old_value) { - $type = $form_values['type']; - if (!$old_value && $form_values['nodeprofile']) { - // activated - if (module_exists('usernode')) { - nodefamily_ct_relation_add(USERNODE_CONTENT_TYPE, $type); - nodefamily_content_type_set_max($type, 1); - } - } - else if ($old_value && !$form_values['nodeprofile']) { - // deactivated - if (module_exists('usernode')) { - nodefamily_ct_relation_remove(USERNODE_CONTENT_TYPE, $type); - } - } +function nodeprofile_node_settings_submit($form, &$form_state, $old_value = false) { + // empty to keep API consistent? } /** @@ -344,20 +283,20 @@ else if (!node_access('update', $node)) { break; } - $fields[$category] = array( - '#type' => 'subform', - '#id' => $node->type. '_node_form', - '#arguments' => array($node), - '#subform_after_build' => array('nodeprofile_integration_adapt_node_form'), - ); + + require_once(drupal_get_path('module', 'node') .'/node.pages.inc'); + $form_state = array(); + $fields[$category]['subform'] = subform_element_create($node->type .'_node_form', array($node), $form_state); + $fields[$category]['subform']['#form'] = nodeprofile_integration_adapt_node_form($fields[$category]['subform']['#form']); + $fields[$category]['subform']['#form']['#submit'][] = 'nodeprofile_node_form_submit'; + return $fields; } break; case 'update': if (nodeprofile_get_settings('user_edit', $category) && node_access('create', $category)) { - subform_element_submit(); - unset($edit[$category. '_node_form']); + unset($edit[$category .'_node_form']); } break; @@ -366,13 +305,26 @@ foreach (nodeprofile_get_types('names') as $type => $type_name) { if ($style = nodeprofile_get_settings('user_display', $type)) { $output = array( + '#title' => $type_name, '#type' => 'nodeprofile_display_'. $style, '#tabs' => nodeprofile_get_settings('edit_link', $type) ? array('view', 'edit') : ($style == 'teaser' ? array('view') : array()), '#uid' => $account->uid, '#content_type' => $type, ); $title = $style != 'link' ? check_plain($type_name) : ''; - if ($content = drupal_render($output)) { + $content = drupal_render($output); + if (trim(strip_tags($content)) != '') { + if (!isset($account->content[$title])) { + $account->content[$title] = array('type' => array()); + } + $account->content[$title][$type] = array( + '#title' => NULL, + '#value' => $content, + '#class' => 'nodeprofile-display', + '#weight' => nodeprofile_get_settings('weight', $type), + ); + $account->content[$title]['#weight'] = nodeprofile_get_settings('weight', $type); + $fields[$title][$type] = array( 'title' => NULL, 'value' => $content, @@ -382,6 +334,10 @@ $fields[$title]['weight'] = nodeprofile_get_settings('weight', $type); } else if ($account->uid == $user->uid && nodeprofile_get_settings('add_link', $type) && user_access('create '. $type .' content')) { + if (!isset($account->content[$type_name])) { + $account->content[$type_name] = array('profile' => array()); + } + $account->content[$type_name]['profile']['#value'] = theme('nodeprofile_display_add_link', $type, $type_name); $fields[$type_name]['profile']['value'] = theme('nodeprofile_display_add_link', $type, $type_name); $fields[$type_name]['weight'] = nodeprofile_get_settings('weight', $type); } @@ -391,7 +347,7 @@ uasort($fields[''], '_user_sort'); //sorts the links if there are multiple links } uasort($fields, '_user_sort'); - //remove the weights we used for sorting, because user module can't display them.. + //remove the weights we used for sorting, because user module can't display them. foreach ($fields as $key => $category) { $fields[$key] = array_filter($category, 'is_array'); } @@ -403,7 +359,7 @@ foreach (node_get_types('names') as $typename => $visiblename) { if (is_nodeprofile($typename)) { $typenames[] = $typename; - $typenames = array_merge($typenames, nodefamily_get_descendant_types($typename)); + //$typenames = array_merge($typenames, nodefamily_get_descendant_types($typename)); } } @@ -429,22 +385,32 @@ } } break; - + case 'register': return nodeprofile_get_register_form(); - case 'insert': - global $new_account; - - if ($types = nodeprofile_get_settings('register')) { - $new_account = $account; //this will be used on nodeapi op submit to set the correct author uid - subform_element_submit(); + case 'load': + global $_nodeprofile_profile_nid; + if ($types = nodeprofile_get_settings('register') && isset($_nodeprofile_profile_nid) && is_numeric($_nodeprofile_profile_nid)) { + // Update the author (the uid) of the profile + db_query('UPDATE {node} SET uid = %d WHERE nid = %d', $account->uid, $_nodeprofile_profile_nid); //this will be used on nodeapi op submit to set the correct author uid } break; } } /** + * Saves the changes of a node + */ +function nodeprofile_node_form_submit($form, &$form_state) { + // unset the handler to prevent repeatedly calling + unset($form['#submit'][array_search('nodeprofile_node_form_submit', $form['#submit'])]); + + require_once(drupal_get_path('module', 'node') .'/node.pages.inc'); + node_form_submit($form, $form_state); +} + +/** * The original node_delete() function uses node_load() to get the $node object. * Unfortunately, when a hook_user('delete') is called, node_load() doesn't * work anymore because the user has already been deleted, and node_load() @@ -492,7 +458,7 @@ search_wipe($node->nid, 'node'); } drupal_set_message(t('%title has been deleted.', array('%title' => $node->title))); - watchdog('content', t('@type: deleted %title.', array('@type' => node_get_types('name', $node->type), '%title' => $node->title))); + watchdog('content', '@type: deleted %title.', array('@type' => node_get_types('name', $node->type), '%title' => $node->title)); } /* @@ -519,12 +485,11 @@ '#weight' => nodeprofile_get_settings('weight', $type), ); $node = (object)array('uid' => 0, 'name' => '', 'type' => $type); - $form[$type]['form'] = array( - '#type' => 'subform', - '#id' => $type. '_node_form', - '#arguments' => array($node), - '#subform_after_build' => array('nodeprofile_integration_adapt_node_form'), - ); + + require_once(drupal_get_path('module', 'node') .'/node.pages.inc'); + $form[$type]['form'] = subform_element_create($type .'_node_form', array($node), $form[$type]['form'], FALSE); + $form[$type]['form']['#form'] = nodeprofile_integration_adapt_node_form($form[$type]['form']['#form']); + $form[$type]['form']['#form']['#submit'][] = 'nodeprofile_node_form_submit'; } } if (!empty($form)) { @@ -534,19 +499,25 @@ } /* - * Implementation of hook_nodeapi + * Implementation of hook_nodeapi(). */ -function nodeprofile_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { - global $new_account, $last_nid; - - //Set the correct author for new nodes created during registration - if ($op == 'submit' && is_nodeprofile($node->type) && isset($new_account)) { - $node->uid = $new_account->uid; - $node->name = $new_account->name; - } - - //index themed node - if ($op == 'alter' && is_nodeprofile($node->type) && isset($last_nid)) { +function nodeprofile_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { + global $_nodeprofile_profile_nid, $last_nid; + + if ($op == 'insert' && is_nodeprofile($node->type)) { + // Save the nid so we can change the author from anonymous to the real author + $_nodeprofile_profile_nid = $node->nid; + } + else if ($op == 'prepare' && is_nodeprofile($node->type) && !isset($node->nid) && strpos(drupal_get_normal_path($_GET['q']), 'admin/user/') !== 0 && strpos(drupal_get_normal_path($_GET['q']), 'user/register') !== 0) { + // Check if this nodetype already exists + $result = db_query("SELECT n.nid AS nid FROM {node} n WHERE n.type = '%s' AND n.uid = %d AND n.language = '%s'", $node->type, $node->uid, $node->language); + if ($nid = db_result($result)) { + // This node already exists, redirect to edit page + drupal_goto('node/'. $nid .'/edit', 'destination='. urlencode('user/'. $node->uid)); + } + } + else if ($op == 'alter' && is_nodeprofile($node->type) && isset($last_nid)) { + // Index themed node $node->body = theme('node', $node, FALSE, TRUE); } } @@ -579,7 +550,7 @@ foreach (nodeprofile_available_settings() as $setting) { $settings += array($setting => array()); foreach (nodeprofile_get_types('names') as $type => $type_name) { - if (!isset($settings[$setting][$type]) && $value = nodeprofile_get_setting_defaults($setting, $type)) { + if (!isset($settings[$setting][$type]) && ($value = nodeprofile_get_setting_defaults($setting, $type)) !== FALSE) { $settings[$setting][$type] = $value; } } @@ -634,11 +605,10 @@ /* * Deactivates some unwanted fields for integrated node forms - * This is invoked through #after_build on the subform elment */ -function nodeprofile_integration_adapt_node_form($form_element, &$form_values) { +function nodeprofile_integration_adapt_node_form($form_element) { foreach (array('preview', 'submit', 'delete', 'author') as $name) { - $form_element[$name]['#access'] = FALSE; + $form_element['buttons'][$name]['#access'] = FALSE; } return $form_element; } @@ -656,12 +626,91 @@ } /* + * Registeres theme functions + */ +function nodeprofile_theme() { + return array( + 'nodeprofile_display_teaser' => array( + 'template' => 'nodeprofile-display-teaser', + 'arguments' => array('element' => NULL), + ), + 'nodeprofile_display_full' => array( + 'template' => 'nodeprofile-display-full', + 'arguments' => array('element' => NULL), + ), + 'nodeprofile_display_add_link' => array( + 'template' => 'nodeprofile-display-add-link', + 'arguments' => array('element' => NULL, 'type_name' => 'profile'), + ), + 'nodeprofile_display_box' => array( + 'arguments' => array('element' => NULL, 'content' => NULL), + ), + 'nodeprofile_display_tab_view' => array( + 'arguments' => array('node' => NULL), + ), + 'nodeprofile_display_tab_edit' => array( + 'arguments' => array('node' => NULL), + ), + ); +} + +/** + * Implementation of template_preprocess_HOOK() + */ +function template_preprocess_nodeprofile_display_teaser(&$variables) { + $element = $variables['element']; + if ($variables['node'] = nodeprofile_load($element['#content_type'], $element['#uid'])) { + if (node_access('view', $variables['node'])) { + $path = drupal_get_path('module', 'nodeprofile') .'/nodeprofile.css'; + drupal_add_css($path, 'module', 'all', FALSE); + + $variables['title'] = isset($element['#title']) ? check_plain($element['#title']) : ''; + $tabs = array(); + if (isset($element['#tabs']) && count($element['#tabs']) > 0) { + foreach ($element['#tabs'] as $tab_name) { + if (function_exists('theme_nodeprofile_display_tab_'. $tab_name)) { + $tabs[] = call_user_func('theme_nodeprofile_display_tab_'. $tab_name, $variables['node']); + } + } + } + if (count($tabs) > 0) { + $variables['tabs'] = $tabs; + } + + if (isset($variables['node']->body)) { + $variables['content'] = $variables['node']->body; + } + else { + $variables['content'] = ''; + } + } + } +} + +/** + * Implementation of template_preprocess_HOOK() + */ +function template_preprocess_nodeprofile_display_full(&$variables) { + template_preprocess_nodeprofile_display_teaser($variables); +} + +/** + * Implementation of template_preprocess_HOOK() + */ +function template_preprocess_nodeprofile_display_add_link(&$variables) { + $element = $variables['element']; + $variables['title'] = isset($variables['type_name']) ? check_plain($variables['type_name']) : ''; + $variables['editlink'] = nodeprofile_get_add_path($element); + $variables['addprofile'] = t("Create your @profile_node.", array('@profile_node' => isset($variables['type_name']) ? check_plain($variables['type_name']) : '')); +} + +/* * Theme function for the nodeprofile display as teaser */ function theme_nodeprofile_display_teaser(&$element) { if ($node = nodeprofile_load($element['#content_type'], $element['#uid'])) { if (node_access('view', $node)) { - $element['#node'] = $node; + $element['#node'] = $node; return theme('nodeprofile_display_box', $element, node_view($node, TRUE, TRUE, FALSE)); } } @@ -687,7 +736,7 @@ if (node_access('view', $node)) { $output = l(node_get_types('name', $node->type), 'node/'. $node->nid); if (in_array('edit', $element['#tabs']) && node_access('update', $node)) { - $output .= ' '. l('['. t('edit') .']', nodeprofile_get_edit_path($node), array(), drupal_get_destination()); + $output .= ' '. l('['. t('edit') .']', nodeprofile_get_edit_path($node), array('query' => drupal_get_destination())); } return $output; } @@ -713,7 +762,7 @@ } $output .= "\n"; } - return $head .'
'. $output . $content. '
'; + return $head .'
'. $output . $content .'
'; } /** @@ -735,7 +784,7 @@ */ function theme_nodeprofile_display_tab_edit($node) { if (node_access('update', $node)) { - return l(t('Edit'), nodeprofile_get_edit_path($node), array(), drupal_get_destination()); + return l(t('Edit'), nodeprofile_get_edit_path($node), array('query' => drupal_get_destination())); } } @@ -762,7 +811,7 @@ /* * Returns an array suitable for use with drupal_render, - * that shows all nodperofiles as configured by the admin + * that shows all nodeprofiles as configured by the admin */ function nodeprofile_show_profiles($uid) { $fields = array(); @@ -771,7 +820,7 @@ $fields[$type] = array( '#type' => 'nodeprofile_display_'. $style, '#tabs' => nodeprofile_get_settings('edit_link', $type) ? array('view', 'edit') : ($style == 'teaser' ? array('view') : array()), - '#title' => $type_name, + '#title' => $type_name, '#uid' => $uid, '#content_type' => $type, '#weight' => nodeprofile_get_settings('weight', $type), @@ -780,4 +829,4 @@ } } return $fields; -} +} \ No newline at end of file Index: nodeprofile_workflow_ng.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/nodeprofile/nodeprofile_workflow_ng.inc,v retrieving revision 1.1 diff -u -r1.1 nodeprofile_workflow_ng.inc --- nodeprofile_workflow_ng.inc 15 Sep 2007 11:49:09 -0000 1.1 +++ nodeprofile_workflow_ng.inc 20 Jan 2008 11:11:14 -0000 @@ -1,5 +1,5 @@ $form_values['type']); +function nodeprofile_user_has_profile_condition_submit($form, &$form_state) { + return array('type' => $form_state['values']['type']); }