--- content_profile.module 2010-01-13 05:38:26.000000000 -0500 +++ content_profile-NEW.module 2010-03-01 21:33:29.000000000 -0500 @@ -170,6 +170,17 @@ function content_profile_admin_settings( 'sub' => t("Show a secondary tab below the user's edit tab"), ), ); + $form['display']['page_redirect'] = array( + '#type' => 'radios', + '#title' => t("Prevent duplicate pages by adding a redirect."), + '#default_value' => content_profile_get_settings($type, 'page_redirect'), + '#description' => t("Optionally redirect all full page node views or default user profile views"), + '#options' => array( + 0 => t("Do not add a redirect"), + 1 => t('Redirect content profile node to user profile'), + 2 => t('Redirect user profile to content profile node'), + ), + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), @@ -461,6 +472,7 @@ function content_profile_content_profile 'edit_link' => 0, 'edit_tab' => 'sub', 'add_link' => 1, + 'page_redirect' => 0, ); } @@ -625,6 +637,32 @@ function content_profile_template_prepro } } +function content_profile_preprocess_page(&$variables) { + // Check that we are on node/N where N is the NID of a profile + if (arg(0) == 'node' && arg(1) == $variables['node']->nid && arg(2) == "") { + // Check if we're on a node profile + if (is_content_profile($variables['node']->type)) { + // Check if the redirect settings for this node type are set to redirect content profile to user page + if (content_profile_get_settings($variables['node']->type, 'page_redirect') == 1) { + // redirect to the user profile page + drupal_goto("user/". $variables['node']->uid); + } + } + } + // Check that we are on user/U where U is the UID of a user + elseif (arg(0) == 'user' && arg(1) != "" && arg(2) == "") { + foreach (content_profile_get_types('names') as $type => $type_name) { + // Check if the redirect settings for this node type are set to redirect content profile to user page + if (content_profile_get_settings($type, 'page_redirect') == 2) { + // redirect to the user profile page + if ($node = content_profile_load($type, check_plain(arg(1)))) { + drupal_goto("node/". $node->nid); + } + } + } + } +} + /** * Implementation of hook_simpletest(). */