# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: drupalvb.admin-pages.inc --- drupalvb.admin-pages.inc Base (1.13) +++ drupalvb.admin-pages.inc Locally Modified (Based On 1.13) @@ -10,18 +10,53 @@ /** * Form builder function for DrupalvB integration settings. - * - * @todo Add vBulletin license. - * @todo Add required vBulletin configuration values; remove drupalvb_get_config(). */ -function drupalvb_settings_integration() { +function drupalvb_settings_integration($form_state) { if (!drupalvb_db_is_valid()) { drupal_goto('admin/settings/drupalvb/database'); } $form = array(); - $form['drupalvb_license'] = array( + $form['drupalvb_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Forum settings'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#prefix' => '
', + '#suffix' => '
', + ); + + // Set $version_value based on state of the form + if (isset($form_state['values']['drupalvb_version'])) { + $version_value = $form_state['values']['drupalvb_version']; + } + else { + $version_value = variable_get('drupalvb_version', 3); + } + $form['drupalvb_settings']['drupalvb_version'] = array( + '#type' => 'select', + '#title' => t('vBulletin version'), + '#default_value' => $version_value, + '#description' => 'Select the version that most closely matches your vBulletin installation.', + '#options' => array( + '3.0' => t('3.0+'), + '3.8' => t('3.8.4 PL2+'), + '4.0' => t('4.0+'), + ), + '#ahah' => array( + 'event' => 'change', + 'method' => 'replace', + 'path' => 'admin/settings/drupalvb/ajax/version', + 'wrapper' => 'drupalvb-forum-settings', + ), + ); + + // Assign $license as a short alias for drupalvb_license form element. + $license =& $form['drupalvb_settings']['drupalvb_license']; + + // Initialize drupalvb_license form element. + $license = array( '#type' => 'textfield', '#title' => t('vBulletin license number'), '#default_value' => variable_get('drupalvb_license', ''), @@ -29,21 +64,64 @@ '#description' => t('Enter your vBulletin license number, which can be found at the top of any PHP file of vBulletin. This is required to generate proper session id hashes for cookies. Please note that this is not your customer number.'), ); - $form['drupalvb_dual_login'] = array( + // In 3.8.4 PL2 vBulletin stopped using license number as salt for password + // and began using a constant named COOKIE_SALT. + if ($version_value >= 3.8) { + $license['#title'] = t('Cookie salt'); + $license['#description'] = t('Enter your vBulletin cookie salt, which can be found defined in the includes/functions.php PHP file of vBulletin. This is required to generate proper session id hashes for cookies.'); + } + + $form['drupalvb_settings']['misc'] = array( + '#type' => 'fieldset', + '#title' => t('Additional configuration settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => t('If your vBulletin installation is using custom settings for any of the options below then update the values to match.'), + ); + + $form['drupalvb_settings']['misc']['drupalvb_admincpdir'] = array( + '#type' => 'textfield', + '#title' => t('Admin control panel directory'), + '#default_value' => variable_get('drupalvb_admincpdir', 'admincp'), + '#size' => 20, + ); + + $form['drupalvb_settings']['misc']['drupalvb_modcpdir'] = array( + '#type' => 'textfield', + '#title' => t('Moderator control panel directory'), + '#default_value' => variable_get('drupalvb_modcpdir', 'modcp'), + '#size' => 20, + ); + + $form['drupalvb_settings']['misc']['drupalvb_cookieprefix'] = array( + '#type' => 'textfield', + '#title' => t('Cookie prefix'), + '#default_value' => variable_get('drupalvb_cookieprefix', 'bb'), + '#size' => 20, + ); + + $form['drupalvb_users'] = array( + '#type' => 'fieldset', + '#title' => t('User settings'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + + $form['drupalvb_users']['drupalvb_dual_login'] = array( '#type' => 'checkbox', '#title' => t('Users login to vBulletin forum when they log into Drupal.'), '#default_value' => variable_get('drupalvb_dual_login', TRUE), '#description' => t('Select to enable the dual login feature.'), ); - $form['drupalvb_acct_generation'] = array( + $form['drupalvb_users']['drupalvb_acct_generation'] = array( '#type' => 'checkbox', '#title' => t('Create matching vBulletin accounts for new Drupal users.'), '#default_value' => variable_get('drupalvb_acct_generation', TRUE), '#description' => t('Select to enable the matching account generation feature.'), ); - $form['drupalvb_acct_sync'] = array( + $form['drupalvb_users']['drupalvb_acct_sync'] = array( '#type' => 'checkbox', '#title' => t('Synchronize Drupal account updates and deletions with vBulletin.'), '#default_value' => variable_get('drupalvb_acct_sync', TRUE), @@ -52,7 +130,7 @@ $roles = drupalvb_get_roles(); - $form['drupalvb_default_usergroup'] = array( + $form['drupalvb_users']['drupalvb_default_usergroup'] = array( '#type' => 'select', '#title' => t('Usergroup for new users'), '#default_value' => variable_get('drupalvb_default_usergroup', 2), @@ -60,7 +138,7 @@ '#description' => t('Select the default usergroup for created users.'), ); - $form['drupalvb_default_options'] = array( + $form['drupalvb_users']['drupalvb_default_options'] = array( '#type' => 'textfield', '#title' => t('New User Options'), '#default_value' => variable_get('drupalvb_default_options', '3415'), Index: drupalvb.css --- drupalvb.css No Base Revision +++ drupalvb.css Locally New @@ -0,0 +1,6 @@ +/* $Id$ */ + +#edit-drupalvb-version-wrapper .description { + clear: both; +} + Index: drupalvb.inc.php --- drupalvb.inc.php Base (1.34) +++ drupalvb.inc.php Locally Modified (Based On 1.34) @@ -25,10 +25,9 @@ return FALSE; } - $vb_config = drupalvb_get('config'); $vb_options = drupalvb_get('options'); + $cookie_prefix = drupalvb_get_cookieprefix(); - $cookie_prefix = (isset($vb_config['Misc']['cookieprefix']) ? $vb_config['Misc']['cookieprefix'] : 'bb'); $cookie_path = $vb_options['cookiepath']; $now = time(); $expire = $now + (@ini_get('session.cookie_lifetime') ? ini_get('session.cookie_lifetime') : 60 * 60 * 24 * 365); @@ -59,6 +58,7 @@ setcookie($cookie_prefix .'lastactivity', $now, $expire, $cookie_path, $vb_cookie_domain); setcookie($cookie_prefix .'userid', $vbuser['userid'], $expire, $cookie_path, $vb_cookie_domain); setcookie($cookie_prefix .'password', md5($vbuser['password'] . variable_get('drupalvb_license', '')), $expire, $cookie_path, $vb_cookie_domain); + return TRUE; } @@ -68,10 +68,9 @@ * @see drupalvb_logout(), drupalvb_user_logout() */ function drupalvb_clear_cookies($userid = NULL) { - $vb_config = drupalvb_get('config'); $vb_options = drupalvb_get('options'); - $cookie_prefix = (isset($vb_config['Misc']['cookieprefix']) ? $vb_config['Misc']['cookieprefix'] : 'bb'); + $cookie_prefix = drupalvb_get_cookieprefix(); $cookie_path = $vb_options['cookiepath']; $expire = time() - 86400; @@ -289,6 +288,9 @@ /** * Get vBulletin configuration. + * + * @deprecated + * No longer used, all configurations set through Drupal variables */ function drupalvb_get_config() { static $config = array(); @@ -303,6 +305,20 @@ } /** + * Get vB cookie prefix. + */ +function drupalvb_get_cookieprefix() { + $cookieprefix = variable_get('drupalvb_cookieprefix', 'bb'); + + // Version 4 began using an underscore following the prefix + if (variable_get('drupalvb_version', 3) >= 4) { + $cookieprefix .= '_'; + } + + return $cookieprefix; +} + +/** * Get vB user roles. */ function drupalvb_get_roles() { Index: drupalvb.module --- drupalvb.module Base (1.36) +++ drupalvb.module Locally Modified (Based On 1.36) @@ -43,15 +43,11 @@ case 'admin/settings/drupalvb': module_load_include('inc', 'drupalvb'); - $vb_config = drupalvb_get('config'); $vb_options = drupalvb_get('options'); - if (empty($vb_config)) { - return ''; - } $items = array( l(t('View the Forum'), $vb_options['bburl']), - l(t('Forum Admin Control Panel'), $vb_options['bburl'] .'/'. $vb_config['Misc']['admincpdir']), - l(t('Forum Moderator Control Panel'), $vb_options['bburl'] .'/'. $vb_config['Misc']['modcpdir']), + l(t('Forum Admin Control Panel'), $vb_options['bburl'] .'/'. variable_get('drupalvb_admincpdir', 'admincp')), + l(t('Forum Moderator Control Panel'), $vb_options['bburl'] .'/'. variable_get('drupalvb_modcpdir', 'modcp')), ); return theme_item_list($items); @@ -61,6 +57,13 @@ } /** + * Implementation of hook_init(). + */ +function drupalvb_init() { + drupal_add_css(drupal_get_path('module', 'drupalvb') .'/drupalvb.css'); +} + +/** * Implementation of menu_hook(). */ function drupalvb_menu() { @@ -101,6 +104,13 @@ 'type' => MENU_LOCAL_TASK, 'weight' => 88, ); + $items['admin/settings/drupalvb/ajax/version'] = array( + 'title' => 'vBulletin version change', + 'page callback' => 'drupalvb_settings_ajax', + 'page arguments' => array('version'), + 'access arguments' => array('administer drupalvb'), + 'type' => MENU_CALLBACK, + ); $items['drupalvb/pms'] = array( 'page callback' => 'drupalvb_private_messages', 'access arguments' => array('access content'), @@ -150,6 +160,67 @@ } /** + * Ajax handling function for DrupalvB settings. + */ +function drupalvb_settings_ajax($identifier) { + // Ensure that needed files are available to prevent undefined functions + module_load_include('inc', 'drupalvb'); + module_load_include('inc', 'drupalvb', 'drupalvb.admin-pages'); + + $form_state = array( + 'storage' => NULL, + 'submitted' => FALSE, + // Rebuild set to true to prevent #submit callbacks + 'rebuild' => TRUE, + ); + + $form_build_id = $_POST['form_build_id']; + $form = form_get_cache($form_build_id, $form_state); + + $args = $form['#parameters']; + $form_id = array_shift($args); + $form_state['post'] = $form['#post'] = $_POST; + $form['#programmed'] = $form['#redirect'] = FALSE; + drupal_process_form($form_id, $form, $form_state); + + // Build the form new that will have our section rendered + $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); + + // Retrieve the fields that we want, we use a switch so if any additional + // Ajax calls are later added + switch ($identifier) { + case 'version': + $wrapper = $form['drupalvb_settings']; + break; + default: + drupal_json(array( + 'status' => FALSE + )); + return; + } + // Normally we would strip wrapping div using: + // unset($wrapper['#prefix'], $wrapper['suffix']); + // However IE causes the entire field to be removed on Ajax result instead of + // being replaced if the wrapping #prefix and #suffix are removed, no idea + // why, so instead we set to empty strings. + $wrapper['#prefix'] = ''; + $wrapper['#suffix'] = ''; + + // Remove CSS error styles + form_set_error(NULL, '', TRUE); + // Silently clear any errors from failed validation in the AHAH processing, + // we do not want required field messages being accumulated because of AHAH + // calls or output back to the user. + drupal_get_messages(); + + // Generate JSON + drupal_json(array( + 'status' => TRUE, + 'data' => drupal_render($wrapper), + )); +} + +/** * Implementation of hook_form_alter(). * * Validate the submitted values of user login forms before Drupal core invokes @@ -166,8 +237,8 @@ // Splice in our validate handler for authentication if user is performing // a vBulletin login. - if (!empty($form_state['post']['name']) && drupalvb_db_is_valid()) { - $username = $form_state['post']['name']; + if (!empty($form_state['values']['name']) && drupalvb_db_is_valid()) { + $username = $form_state['values']['name']; if ($vbuser = db_fetch_array(drupalvb_db_query("SELECT userid, password, salt, email FROM {user} WHERE username = '%s'", drupalvb_htmlspecialchars($username)))) { $key = array_search('user_login_final_validate', $form['#validate']); if ($key !== FALSE) { @@ -472,39 +543,61 @@ function drupalvb_login() { global $user; + // If request is coming from vb4 then set values to vb3 values for auth + if (variable_get('drupalvb_version', 3) >= 4) { + $_POST['name'] = $_POST['vb_login_username']; + $_POST['pass'] = $_POST['vb_login_password']; + unset($_POST['vb_login_username'], $_POST['vb_login_password']); + } + if ($_POST['name']) { - $form_state = array('values' => $_POST); + // If user is logged in then logout to counteract issues with sessions + // expiring at different times between vB and Drupal which would otherwise + // prevent users from logging in to vB if ($user->uid) { - // If the user is already logged in to Drupal, we ensure the same for - // vBulletin. - if (drupalvb_login_validate(array(), $form_state)) { - drupal_goto(!empty($_REQUEST['destination']) ? $_REQUEST['destination'] : 'user/'. $user->uid); + watchdog('drupalvb', t('Session closed for %name before attempt to login.', array('%name' => $user->name))); + + session_destroy(); + // TODO: When already logged in as a Drupal user an error message is not + // set upon unsuccessful drupalvb login - due to not calling + // user_module_invoke()? + + // We don't call user_module_invoke() here as it will redirect when it + // hits drupalvb_logout() which will prevent the login attempt from + // occurring. + + $user = drupal_anonymous_user(); } - else { - // Where do we go from here? user/login won't work, as the user is - // already authenticated in Drupal. + + $form_state = array('values' => $_POST); + + // Attempt to log user in + drupal_execute('user_login', $form_state); + + $errors = form_get_errors(); + + if ($_GET['destination']) { + $destination = urldecode($_GET['destination']); unset($_REQUEST['destination']); - drupal_goto(variable_get('site_frontpage', 'node')); } - } else { - // Otherwise perform the full login procedure. - foreach (user_login_default_validators() as $validator) { - $validator(array(), $form_state); + $destination = ''; } - if (!form_get_errors()) { - user_login_submit(array(), $form_state); - $redirect = (isset($form_state['redirect']) ? $form_state['redirect'] : ''); - drupal_goto(!empty($_REQUEST['destination']) ? $_REQUEST['destination'] : $redirect); + + // Bad login, send to login form + if ($errors) { + if ($destination) { + $destination = 'destination=' . $destination; } + drupal_goto('user/login', $destination); + } + // No errors else { - // Login failed: send back to login form. - unset($_REQUEST['destination']); - drupal_goto('user/login'); + // Redirect back to destination if provided, else Drupal homepage + drupal_goto($destination); } } } -} /** * Log out a user (ensuring a logout in vBulletin); menu callback.