Skip to content
Snippets Groups Projects
Commit dc5e4073 authored by Tim Steiner's avatar Tim Steiner
Browse files

[gh-147] Merging from testing into staging

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@864 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent e163c243
No related branches found
No related tags found
No related merge requests found
......@@ -606,21 +606,8 @@ function unl_cron() {
$sites_to_create = array();
foreach ($data as $site) {
$full_department = $site->department;
$department = $full_department;
$department = strtr($department, array(' ' => ''));
$department = strtolower($department);
$department = preg_replace('/[^[a-z0-9]/', '', $department);
$site_name = $site->site_name;
$site_name = strtr($site_name, array(' ' => ''));
$site_name = strtolower($site_name);
$site_name = preg_replace('/[^[a-z0-9]/', '', $site_name);
$path = $department . '/' . $site_name;
$db_prefix = unl_create_db_prefix($site);
$path = unl_sanitize_url_part($site->department) . '/' . unl_sanitize_url_part($site->site_name);
$db_prefix = unl_create_db_prefix($site->site_name);
$sites_to_create[] = array(
'site_path' => $path,
......@@ -630,7 +617,7 @@ function unl_cron() {
'site_admin' => $site->site_admin ? $site->site_admin : '',
'migration_url' => $site->migration_url ? $site->migration_url : '',
'migration_path' => $site->migration_path ? $site->migration_path : '',
'department' => $full_department,
'department' => $site->department,
);
db_set_active('wdn_registry');
......@@ -660,30 +647,44 @@ function unl_cron() {
}
// Creates a db_prefix short enough to not go over MySQL's max table name length
function unl_create_db_prefix($site) {
function unl_create_db_prefix($site_name) {
$parent_prefix = '_' . $GLOBALS['databases']['default']['default']['prefix'];
$site_name = strtolower($site->site_name);
$site_name = preg_replace('/[^[a-z0-9]/', '', $site_name);
$site_name = explode(' ', $site_name);
$site_name = strtolower($site_name);
$site_name = preg_replace('/[^[a-z0-9]/', '_', $site_name);
$site_name = explode('_', $site_name);
foreach ($site_name as $site_word) {
$site_words[$site_word] = strlen($site_word);
}
do {
$db_prefix = '';
$db_prefix = array();
$found = FALSE;
foreach ($site_words as $site_word => $length) {
$db_prefix .= substr($site_word, 0, $length);
$db_prefix[] = substr($site_word, 0, $length);
if (max($site_words) == $length && !$found) {
$found = TRUE;
$site_words[$site_word] = $length-1;
}
}
} while (strlen($db_prefix . $parent_prefix) > 32);
$db_prefix = implode('_', $db_prefix);
$db_prefix = preg_replace('/_+/', '_', $db_prefix);
$db_prefix = preg_replace('/(^_)|(_$)/', '', $db_prefix);
} while (strlen($db_prefix . '_' . $parent_prefix) > 32);
return $db_prefix;
}
/**
* Custom function to sanitize user created URLs
*/
function unl_sanitize_url_part($url_part) {
$url_part = preg_replace('/[^a-z0-9]/', '-', $url_part);
$url_part = preg_replace('/-+/', '-', $url_part);
$url_part = preg_replace('/(^-)|(-$)/', '', $url_part);
return $url_part;
}
function unl_get_alternate_base_uris() {
$shared_prefix = unl_get_shared_db_prefix();
if (is_array($GLOBALS['databases']['default']['default']['prefix'])) {
......
......@@ -63,13 +63,17 @@ function unl_site_create_submit($form, &$form_state) {
$site_path = $form_state['values']['site_path'];
$clean_url = $form_state['values']['clean_url'];
$db_prefix = unl_create_db_prefix($site_path);
$site_path = explode('/', $site_path);
foreach (array_keys($site_path) as $i) {
$site_path[$i] = unl_sanitize_url_part($site_path[$i]);
}
$site_path = implode('/', $site_path);
$uri = url($site_path, array('absolute' => TRUE, 'https' => FALSE));
$clean_url = intval($clean_url);
$db_prefix = explode('/', $site_path);
$db_prefix = implode('_', $db_prefix);
db_insert('unl_sites')->fields(array(
'site_path' => $site_path,
'uri' => $uri,
......@@ -262,8 +266,7 @@ function unl_site_remove($site_id) {
}
$uri = $uri[0];
$sites_subdir = _unl_get_sites_subdir($uri);
$sites_subdir = strtr($sites_subdir, array('/' => '.'));
$sites_subdir = unl_get_sites_subdir($uri);
$sites_subdir = DRUPAL_ROOT . '/sites/' . $sites_subdir;
$sites_subdir = realpath($sites_subdir);
......@@ -292,17 +295,6 @@ function unl_site_remove($site_id) {
return TRUE;
}
function _unl_get_sites_subdir($uri) {
$path_parts = parse_url($uri);
if (substr($path_parts['host'], -7) == 'unl.edu') {
$path_parts['host'] = 'unl.edu';
}
$sites_subdir = $path_parts['host'] . $path_parts['path'];
$sites_subdir = strtr($sites_subdir, array('/' => '.'));
return $sites_subdir;
}
function unl_aliases_page() {
$page = array();
$page[] = drupal_get_form('unl_site_alias_create');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment