'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', ''), '#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.'), ); // 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_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_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), $roles = drupalvb_get_roles(); $form['drupalvb_users']['drupalvb_default_usergroup'] = array( '#type' => 'select', '#title' => t('Usergroup for new users'), '#default_value' => variable_get('drupalvb_default_usergroup', 2), '#description' => t('Select the default usergroup for created users.'), ); $form['drupalvb_users']['drupalvb_default_options'] = array( '#type' => 'textfield', '#title' => t('New User Options'), '#default_value' => variable_get('drupalvb_default_options', '3415'), } return FALSE; } $vb_options = drupalvb_get('options'); $cookie_prefix = drupalvb_get_cookieprefix(); $cookie_path = $vb_options['cookiepath']; $now = time(); $expire = $now (@ini_get('session.cookie_lifetime') ? ini_get('session.cookie_lifetime') : 60 * 60 * 24 * 365); 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; } function drupalvb_clear_cookies($userid = NULL) { $vb_options = drupalvb_get('options'); $cookie_prefix = drupalvb_get_cookieprefix(); $cookie_path = $vb_options['cookiepath']; $expire = time() - 86400; /** * Get vBulletin configuration. * * @deprecated * No longer used, all configurations set through Drupal variables */ function drupalvb_get_config() { static $config = array(); } /** * 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() { case 'admin/settings/drupalvb': module_load_include('inc', 'drupalvb'); $vb_options = drupalvb_get('options'); $items = array( l(t('View the Forum'), $vb_options['bburl']), 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); } /** * Implementation of hook_init(). */ function drupalvb_init() { drupal_add_css(drupal_get_path('module', 'drupalvb') .'/drupalvb.css'); } /** * Implementation of menu_hook(). */ function drupalvb_menu() { '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'), } /** * 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['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) { 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']) { // 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) { 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(); } $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']); } else { $destination = ''; } // Bad login, send to login form if ($errors) { if ($destination) { $destination = 'destination=' . $destination; } drupal_goto('user/login', $destination); } // No errors else { // Redirect back to destination if provided, else Drupal homepage drupal_goto($destination); } } }