View source
<?php
function profile_module_manager_admin_settings() {
$form = array();
$form['profile_module_manager_disable_ui_lock'] = array(
'#type' => 'checkbox',
'#default_value' => variable_get('profile_module_manager_disable_ui_lock', 0),
'#title' => t('Disable UI Lock'),
'#description' => t('Disables the lock on ability enable or disable modules required by install profile through the user interface. This also impacts drush.'),
);
$form['profile_module_manager_disable_enabling'] = array(
'#type' => 'checkbox',
'#default_value' => variable_get('profile_module_manager_disable_enabling', 0),
'#title' => t('Disable the ability for users to enable bundles'),
'#description' => t('Turns off the ability for users to enable bundles on the bundles list page.'),
);
$form['profile_module_manager_disable_enabling_text'] = array(
'#type' => 'textarea',
'#cols' => 40,
'#rows' => 5,
'#default_value' => variable_get('profile_module_manager_disable_enabling_text'),
'#title' => t('Bundles Disabled Text'),
'#description' => t('Message that is displayed for users when they can\'t enable bundles.'),
'#states' => array(
'visible' => array(
':input[name="profile_module_manager_disable_enabling"]' => array(
'checked' => TRUE,
),
),
),
);
$bundles = array_keys(profile_module_manager_get_bundles('all'));
$form['profile_module_manager_bundle_ignore'] = array(
'#title' => t('Hidden Bundles'),
'#type' => 'checkboxes',
'#description' => t('You can select which bundles you want to be hidden from the end user on the bundles list page. This can be useful for soft launches or other use cases where you don\'t want certain users to be able to enable the bundle.'),
'#default_value' => variable_get('profile_module_manager_bundle_ignore'),
'#options' => drupal_map_assoc($bundles),
);
$form['actions'] = array(
'#type' => 'actions',
'submit' => array(
'#type' => 'submit',
'#value' => t('Save Configuration'),
),
);
return $form;
}
function profile_module_manager_admin_settings_submit($form, &$form_state) {
$ignore_modules = explode(',', $form_state['values']['profile_module_manager_ignore']);
variable_set('profile_module_manager_ignore', $ignore_modules);
unset($form_state['values']['profile_module_manager_ignore']);
system_settings_form_submit($form, $form_state);
}
function profile_module_manager_bundle_list() {
$output = array();
$bundle_page = array();
if (variable_get('profile_module_manager_disable_enabling', 0) == 1) {
$output = '<p>' . variable_get('profile_module_manager_disable_enabling_text', 'The ability to enable bundles has been turned off.') . '</p>';
return $output;
}
$bundles = profile_module_manager_get_bundles('all');
$admin_bundles = array();
$hidden_bundles = array();
$hidden_bundles_list = variable_get('profile_module_manager_bundle_ignore');
foreach ($hidden_bundles_list as $bundle) {
if ($bundle !== 0) {
$hidden_bundles[] = $bundle;
}
}
foreach ($bundles as $key => $bundle) {
if (!strpos($bundle->name, '_bundle')) {
unset($bundles[$key]);
}
if (in_array($bundle->name, $hidden_bundles)) {
unset($bundles[$key]);
}
if (strpos($bundle->name, '_admin_bundle')) {
unset($bundles[$key]);
$admin_bundles[$key] = $bundle;
}
}
foreach ($admin_bundles as $key => $bundle) {
$bundles[$key] = $bundle;
}
$first_admin_bundle = TRUE;
foreach ($bundles as $key => $bundle) {
$info_file = str_replace(".module", ".info", $bundle->filename);
if (file_exists($info_file)) {
$info = drupal_parse_info_file($info_file);
$enabled = module_exists($bundle->name) ? 1 : 0;
$group = strpos($bundle->name, '_admin_bundle') ? 'group_admin_bundle' : 'group_bundle';
$classes_array = array();
$classes_array[] = 'module-bundle-wrapper';
$classes_array[] = $enabled ? 'bundle-enabled' : 'bundle-disabled';
$vars['title'] = $info['name'];
$vars['description'] = $info['description'];
$actions = array();
$action_vars = array();
if ($enabled) {
$vars['actions'] = theme('profile_module_manager_bundle_actions_enabled', array(
'actions' => $action_vars,
));
}
else {
$action_vars['enable_url'] = current_path() . '/confirm/' . $bundle->name;
if (isset($info['project_demo_url'])) {
$action_vars['demo_url'] = $info['project_demo_url'];
}
$vars['actions'] = theme('profile_module_manager_bundle_actions_disabled', $action_vars);
}
$vars['classes'] = join(' ', $classes_array);
$single_bundle['#markup'] = theme('profile_module_manager_bundle', array(
'bundle' => $vars,
));
$all_bundles[$group][] = $single_bundle;
}
}
foreach ($all_bundles as $group_key => $group) {
$bundle_page['bundle_groups'][]['#markup'] = theme('profile_module_manager_bundle_group', array(
'group' => $group_key,
'bundles' => $group,
));
}
return theme('profile_module_manager_bundle_page', array(
'content' => $bundle_page,
));
}
function profile_module_manager_bundle_confirm($bundle_name) {
$output = '';
if (variable_get('profile_module_manager_disable_enabling', 0) == 1) {
$output = '<p>' . variable_get('profile_module_manager_disable_enabling_text', 'The ability to enable bundles has been turned off.') . '</p>';
return $output;
}
$bundle_path = drupal_get_path('module', $bundle_name);
$bundle = drupal_parse_info_file($bundle_path . '/' . $bundle_name . '.info');
if (isset($bundle['bundle_logout']) && $bundle['bundle_logout'] == 1) {
$interval = REQUEST_TIME - 900;
$items = db_query('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', array(
':interval' => $interval,
))
->fetchAll();
$users = '';
$users_count = count($items) - 1;
foreach ($items as $key => $item) {
if ($key == $users_count && $users_count != 0) {
$users .= 'and ' . $item->name . ',';
}
else {
$users .= $item->name . ', ';
}
}
$output = '<p>You are about to enable the ' . $bundle['name'] . ' Bundle. <strong>NOTE: When this process starts it will logout all users, except: ' . $users . ' from editing the site until the process is complete.</strong></p>';
}
else {
$output = '<p>You are about to enable the ' . $bundle['name'] . ' Bundle.</p>';
}
$output .= '<a href="' . $GLOBALS['base_url'] . '/admin/settings/bundles/list/enable/' . $bundle_name . '" title="Confirm"><div class="btn btn-primary">Confirm</div></a>';
$output .= '<a href="' . $GLOBALS['base_url'] . '/admin/settings/bundles/list/" title="Cancel"><div class="btn btn-default">Cancel</div></a>';
return $output;
}
function profile_module_manager_bundle_enable($bundle) {
if (variable_get('profile_module_manager_disable_enabling', 0) == 1) {
$output = '<p>' . variable_get('profile_module_manager_disable_enabling_text', 'The ability to enable bundles has been turned off.') . '</p>';
return $output;
}
variable_set('profile_module_manager_enable_timer', microtime(TRUE));
if (strpos($bundle, '_bundle')) {
$path = drupal_get_path('module', $bundle) . '/' . $bundle . '.info';
$info = drupal_parse_info_file($path);
$modules_to_enable = array();
if (isset($info['dependencies'])) {
foreach ($info['dependencies'] as $module) {
if (!module_exists($module)) {
$modules_to_enable[] = $module;
}
}
}
if (!module_exists($bundle)) {
$modules_to_enable[] = $bundle;
}
$limit = 3;
$module_chunks = array_chunk($modules_to_enable, $limit, TRUE);
$operations = array();
foreach ($module_chunks as $chunk) {
$operations[] = array(
'profile_module_manager_process_batch',
array(
$chunk,
),
);
}
$batch = array(
'title' => t('Enabling Bundle'),
'operations' => $operations,
'finished' => 'profile_module_manager_batch_finished',
'init_message' => t('Initializing...'),
'progress_message' => t('Operation @current out of @total.'),
'error_message' => t('Bundle failed to be enabled.'),
);
batch_set($batch);
if (isset($info['bundle_logout']) && $info['bundle_logout'] == 1) {
$interval = REQUEST_TIME - 900;
$items = db_query('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', array(
':interval' => $interval,
))
->fetchAll();
$uids = array();
foreach ($items as $item) {
$uids[] = $item->uid;
}
$deleted_users = db_delete('sessions')
->condition('uid', $uids, 'NOT IN')
->execute();
}
batch_process('admin/settings/bundles/list');
}
}