| 1 |
<?php
|
| 2 |
// $Id: drupalvb.admin-pages.inc,v 1.12 2009/02/01 02:00:25 sun Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Drupal vB system settings.
|
| 7 |
*
|
| 8 |
* Most parts forked from Migrator module, http://drupal.org/project/migrator
|
| 9 |
*/
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Form builder function for DrupalvB integration settings.
|
| 13 |
*
|
| 14 |
* @todo Add vBulletin license.
|
| 15 |
* @todo Add required vBulletin configuration values; remove drupalvb_get_config().
|
| 16 |
*/
|
| 17 |
function drupalvb_settings_integration() {
|
| 18 |
if (!drupalvb_db_is_valid()) {
|
| 19 |
drupal_goto('admin/settings/drupalvb/database');
|
| 20 |
}
|
| 21 |
|
| 22 |
$form = array();
|
| 23 |
|
| 24 |
$form['drupalvb_license'] = array(
|
| 25 |
'#type' => 'textfield',
|
| 26 |
'#title' => t('vBulletin license number'),
|
| 27 |
'#default_value' => variable_get('drupalvb_license', ''),
|
| 28 |
'#size' => 20,
|
| 29 |
'#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.'),
|
| 30 |
);
|
| 31 |
|
| 32 |
$form['drupalvb_dual_login'] = array(
|
| 33 |
'#type' => 'checkbox',
|
| 34 |
'#title' => t('Users login to vBulletin forum when they log into Drupal.'),
|
| 35 |
'#default_value' => variable_get('drupalvb_dual_login', TRUE),
|
| 36 |
'#description' => t('Select to enable the dual login feature.'),
|
| 37 |
);
|
| 38 |
|
| 39 |
$form['drupalvb_acct_generation'] = array(
|
| 40 |
'#type' => 'checkbox',
|
| 41 |
'#title' => t('Create matching vBulletin accounts for new Drupal users.'),
|
| 42 |
'#default_value' => variable_get('drupalvb_acct_generation', TRUE),
|
| 43 |
'#description' => t('Select to enable the matching account generation feature.'),
|
| 44 |
);
|
| 45 |
|
| 46 |
$form['drupalvb_acct_sync'] = array(
|
| 47 |
'#type' => 'checkbox',
|
| 48 |
'#title' => t('Synchronize Drupal account updates and deletions with vBulletin.'),
|
| 49 |
'#default_value' => variable_get('drupalvb_acct_sync', TRUE),
|
| 50 |
'#description' => t('Select to enable the account synchronization feature.'),
|
| 51 |
);
|
| 52 |
|
| 53 |
|
| 54 |
$roles = drupalvb_get_roles();
|
| 55 |
$form['drupalvb_default_usergroup'] = array(
|
| 56 |
'#type' => 'select',
|
| 57 |
'#title' => t('Usergroup for new users'),
|
| 58 |
'#default_value' => variable_get('drupalvb_default_usergroup', 2),
|
| 59 |
'#options' => $roles,
|
| 60 |
'#description' => t('Select the default usergroup for created users.'),
|
| 61 |
);
|
| 62 |
|
| 63 |
$form['drupalvb_default_options'] = array(
|
| 64 |
'#type' => 'textfield',
|
| 65 |
'#title' => t('New User Options'),
|
| 66 |
'#default_value' => variable_get('drupalvb_default_options', '3415'),
|
| 67 |
'#size' => 20,
|
| 68 |
'#maxlength' => 25,
|
| 69 |
'#description' => t('The default options set to new users who register through Drupal.'),
|
| 70 |
);
|
| 71 |
|
| 72 |
return system_settings_form($form);
|
| 73 |
}
|
| 74 |
|
| 75 |
/**
|
| 76 |
* Settings form for remote system database connection.
|
| 77 |
*/
|
| 78 |
function drupalvb_settings_database() {
|
| 79 |
$form = array();
|
| 80 |
$db = parse_url(variable_get('drupalvb_db', is_array($GLOBALS['db_url']) ? $GLOBALS['db_url']['default'] : $GLOBALS['db_url']));
|
| 81 |
$form['db'] = array(
|
| 82 |
'#type' => 'fieldset',
|
| 83 |
'#title' => t('Database connection'),
|
| 84 |
);
|
| 85 |
$form['db']['scheme'] = array(
|
| 86 |
'#type' => 'radios',
|
| 87 |
'#title' => t('Database interface'),
|
| 88 |
'#options' => array('mysql' => 'MySQL', 'mysqli' => 'MySQLi'),
|
| 89 |
'#default_value' => $GLOBALS['db_type'], // was: $db['scheme'],
|
| 90 |
'#disabled' => TRUE,
|
| 91 |
'#description' => t('Due to the database abstraction design in Drupal 5 and 6, only the current default database interface is supported.'),
|
| 92 |
);
|
| 93 |
$form['db']['host'] = array(
|
| 94 |
'#type' => 'textfield',
|
| 95 |
'#title' => t('Host'),
|
| 96 |
'#default_value' => !empty($db['host']) ? $db['host'] : 'localhost',
|
| 97 |
'#required' => TRUE,
|
| 98 |
);
|
| 99 |
$form['db']['path'] = array(
|
| 100 |
'#type' => 'textfield',
|
| 101 |
'#title' => t('Database'),
|
| 102 |
'#default_value' => substr($db['path'], 1),
|
| 103 |
'#required' => TRUE,
|
| 104 |
);
|
| 105 |
$form['db']['user'] = array(
|
| 106 |
'#type' => 'textfield',
|
| 107 |
'#title' => t('Username'),
|
| 108 |
'#default_value' => $db['user'],
|
| 109 |
'#required' => TRUE,
|
| 110 |
);
|
| 111 |
$form['db']['pass'] = array(
|
| 112 |
'#type' => 'textfield',
|
| 113 |
'#title' => t('Password'),
|
| 114 |
'#default_value' => $db['pass'],
|
| 115 |
'#required' => TRUE,
|
| 116 |
);
|
| 117 |
$form['db']['db_prefix'] = array(
|
| 118 |
'#type' => 'textfield',
|
| 119 |
'#title' => t('Table prefix'),
|
| 120 |
'#default_value' => variable_get('drupalvb_db_prefix', 'vb_'),
|
| 121 |
);
|
| 122 |
$form[] = array(
|
| 123 |
'#type' => 'submit',
|
| 124 |
'#value' => t('Save'),
|
| 125 |
);
|
| 126 |
return $form;
|
| 127 |
}
|
| 128 |
|
| 129 |
function drupalvb_settings_database_submit($form, &$form_state) {
|
| 130 |
$initial_import = FALSE;
|
| 131 |
// If there is no database configuration yet, we want to execute an initial
|
| 132 |
// user import later.
|
| 133 |
if (!variable_get('drupalvb_db', 0)) {
|
| 134 |
$initial_import = TRUE;
|
| 135 |
}
|
| 136 |
|
| 137 |
$url = $form_state['values']['scheme'] .'://'. $form_state['values']['user'] .':'. $form_state['values']['pass'] .'@'. $form_state['values']['host'] .'/'. $form_state['values']['path'];
|
| 138 |
variable_set('drupalvb_db', $url);
|
| 139 |
variable_set('drupalvb_db_is_default', (is_array($GLOBALS['db_url']) ? $GLOBALS['db_url']['default'] == $url : $GLOBALS['db_url'] == $url));
|
| 140 |
variable_set('drupalvb_db_prefix', $form_state['values']['db_prefix']);
|
| 141 |
|
| 142 |
if ($initial_import) {
|
| 143 |
// First time setup; initialize DrupalvB's user mapping.
|
| 144 |
module_load_include('inc', 'drupalvb');
|
| 145 |
_drupalvb_init_user_map();
|
| 146 |
}
|
| 147 |
}
|
| 148 |
|
| 149 |
/**
|
| 150 |
* Form builder function for DrupalvB actions.
|
| 151 |
*/
|
| 152 |
function drupalvb_settings_actions() {
|
| 153 |
$form = array();
|
| 154 |
$form['action']['action'] = array(
|
| 155 |
'#type' => 'value',
|
| 156 |
'#title' => 'Action',
|
| 157 |
);
|
| 158 |
$form['action'][] = array(
|
| 159 |
'#type' => 'radio',
|
| 160 |
'#name' => 'action',
|
| 161 |
'#return_value' => 'export',
|
| 162 |
'#title' => t('Export Drupal users to vBulletin'),
|
| 163 |
'#description' => t('<strong>Warning:</strong> This export relies on usernames. If an identical username exists in Drupal and vBulletin, the user account in vBulletin will be overwritten with data from Drupal (specifically: email address and password).'),
|
| 164 |
);
|
| 165 |
$form['action'][] = array(
|
| 166 |
'#type' => 'radio',
|
| 167 |
'#name' => 'action',
|
| 168 |
'#return_value' => 'import',
|
| 169 |
'#title' => t('Import vBulletin users into Drupal'),
|
| 170 |
'#description' => t('Note: Importing all vBulletin users at once is not possible, because vBulletin stores hashed passwords. Instead, Drupal vB implements an external authentication provider to automatically register vBulletin users upon their first login in Drupal. There is no way to automate this for all existing users.'),
|
| 171 |
'#disabled' => TRUE,
|
| 172 |
);
|
| 173 |
$form['submit'] = array(
|
| 174 |
'#type' => 'submit',
|
| 175 |
'#value' => t('Start'),
|
| 176 |
);
|
| 177 |
return $form;
|
| 178 |
}
|
| 179 |
|
| 180 |
/**
|
| 181 |
* Form submit callback for action form.
|
| 182 |
*/
|
| 183 |
function drupalvb_settings_actions_submit($form, &$form_state) {
|
| 184 |
switch ($form_state['values']['action']) {
|
| 185 |
case 'export':
|
| 186 |
drupalvb_export_drupal_users();
|
| 187 |
drupal_set_message(t('Drupal users have been exported to vBulletin.'));
|
| 188 |
break;
|
| 189 |
}
|
| 190 |
}
|
| 191 |
|
| 192 |
/**
|
| 193 |
* Form builder function for DrupalvB variables (Devel).
|
| 194 |
*/
|
| 195 |
function drupalvb_settings_variables() {
|
| 196 |
$form = array();
|
| 197 |
$options = drupalvb_get('options');
|
| 198 |
foreach ($options as $key => $value) {
|
| 199 |
$form['variables'][$key]['name'] = array('#value' => check_plain($key));
|
| 200 |
$form['variables'][$key]['value'] = array('#value' => check_plain($value));
|
| 201 |
}
|
| 202 |
ksort($form['variables']);
|
| 203 |
return $form;
|
| 204 |
}
|
| 205 |
|
| 206 |
/**
|
| 207 |
* Theme vBulletin options similar to Drupal variables (Devel).
|
| 208 |
*/
|
| 209 |
function theme_drupalvb_settings_variables(&$form) {
|
| 210 |
$header = array(t('Name'), t('Value'));
|
| 211 |
$rows = array();
|
| 212 |
foreach (element_children($form['variables']) as $key) {
|
| 213 |
$rows[] = array(
|
| 214 |
drupal_render($form['variables'][$key]['name']),
|
| 215 |
drupal_render($form['variables'][$key]['value']),
|
| 216 |
);
|
| 217 |
}
|
| 218 |
$output = theme('table', $header, $rows);
|
| 219 |
$output .= drupal_render($form);
|
| 220 |
return $output;
|
| 221 |
}
|
| 222 |
|