From 2fa8bc5bd350d0d03805a2891257cd355d1eebf9 Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Tue, 19 Jul 2011 21:05:13 +0000 Subject: [PATCH] [gh-157] Merging from testing into staging git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@865 20a16fea-79d4-4915-8869-1ea9d5ebf173 --- sites/all/modules/unl/cron.php | 6 ++++- sites/all/modules/unl/unl.install | 11 +++++++++ sites/all/modules/unl/unl_site_creation.php | 25 +++++++++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/sites/all/modules/unl/cron.php b/sites/all/modules/unl/cron.php index 05f94559..eaebd21e 100644 --- a/sites/all/modules/unl/cron.php +++ b/sites/all/modules/unl/cron.php @@ -327,6 +327,10 @@ function unl_add_site_to_htaccess($site_id, $site_path, $is_alias) { $site_or_alias = 'SITE'; } + if (substr($site_path, -1) != '/') { + $site_path .= '/'; + } + $stub_token = ' # %UNL_CREATION_TOOL_STUB%'; $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess'); $stub_pos = strpos($htaccess, $stub_token); @@ -336,7 +340,7 @@ function unl_add_site_to_htaccess($site_id, $site_path, $is_alias) { $new_htaccess = substr($htaccess, 0, $stub_pos) . " # %UNL_START_{$site_or_alias}_ID_{$site_id}%\n"; foreach (array('misc', 'modules', 'sites', 'themes') as $drupal_dir) { - $new_htaccess .= " RewriteRule $site_path/$drupal_dir/(.*) $drupal_dir/$1\n"; + $new_htaccess .= " RewriteRule $site_path$drupal_dir/(.*) $drupal_dir/$1\n"; } $new_htaccess .= " # %UNL_END_{$site_or_alias}_ID_{$site_id}%\n\n" . $stub_token diff --git a/sites/all/modules/unl/unl.install b/sites/all/modules/unl/unl.install index aa93e9a6..338438c2 100644 --- a/sites/all/modules/unl/unl.install +++ b/sites/all/modules/unl/unl.install @@ -358,3 +358,14 @@ function unl_update_7109() { ->fields(array('title' => '<none>')) ->execute(); } + +/** + * Updates unl sites and site aliases to have trailing slashes. + */ +function unl_update_7110() +{ + db_query("UPDATE {unl_sites} SET site_path = CONCAT(site_path, '/') WHERE SUBSTRING(site_path, -1) != '/'"); + db_query("UPDATE {unl_sites} SET uri = CONCAT(uri, '/') WHERE SUBSTRING(uri, -1) != '/'"); + db_query("UPDATE {unl_sites_aliases} SET base_uri = CONCAT(base_uri, '/') WHERE SUBSTRING(base_uri, -1) != '/'"); + db_query("UPDATE {unl_sites_aliases} SET path = CONCAT(path, '/') WHERE SUBSTRING(path, -1) != '/' AND path != ''"); +} diff --git a/sites/all/modules/unl/unl_site_creation.php b/sites/all/modules/unl/unl_site_creation.php index 892e7e14..d082e128 100644 --- a/sites/all/modules/unl/unl_site_creation.php +++ b/sites/all/modules/unl/unl_site_creation.php @@ -46,8 +46,8 @@ function unl_site_create_validate($form, &$form_state) { if (substr($site_path, 0, 1) == '/') { $site_path = substr($site_path, 1); } - if (substr($site_path, -1) == '/') { - $site_path = substr($site_path, 0, -1); + if (substr($site_path, -1) != '/') { + $site_path .= '/'; } $site_path_parts = explode('/', $site_path); @@ -312,7 +312,7 @@ function unl_site_alias_create($form, &$form_state) { ->execute() ->fetchAll(); foreach ($sites as $site) { - $site_list[$site->site_id] = $site->uri . '/'; + $site_list[$site->site_id] = $site->uri; } $form['root'] = array( @@ -331,7 +331,7 @@ function unl_site_alias_create($form, &$form_state) { $form['root']['base_uri'] = array( '#type' => 'textfield', '#title' => t('Alias Base URL'), - '#description' => t('The base URL for the new alias.'), + '#description' => t('The base URL for the new alias. (This should resolve to the directory containing drupal\'s .htaccess file'), '#default_value' => url('', array('https' => FALSE)), '#required' => TRUE, ); @@ -350,6 +350,23 @@ function unl_site_alias_create($form, &$form_state) { return $form; } +function unl_site_alias_create_validate($form, &$form_state) { + $form_state['values']['base_uri'] = trim($form_state['values']['base_uri']); + $form_state['values']['path'] = trim($form_state['values']['path']); + + if (substr($form_state['values']['base_uri'], -1) != '/') { + $form_state['values']['base_uri'] .= '/'; + } + + if (substr($form_state['values']['path'], -1) != '/') { + $form_state['values']['path'] .= '/'; + } + + if (substr($form_state['values']['path'], 0, 1) == '/') { + $form_state['values']['path'] = substr($form_state['values']['path'], 1); + } +} + function unl_site_alias_create_submit($form, &$form_state) { db_insert('unl_sites_aliases')->fields(array( 'site_id' => $form_state['values']['site'], -- GitLab