--- path_redirect.admin.inc Wed Dec 02 12:19:15 2009 +++ path_redirect.admin.inc Fri Dec 04 12:10:57 2009 @@ -64,14 +64,23 @@ $destination = drupal_get_destination(); $rows = array(); $weight = 0; + $per_domain = (module_exists('domain') && variable_get('path_redirect_per_domain', 0)); + if ($per_domain) { + $domains = domain_domains(); + } + foreach ($redirects as $rid => $redirect) { $row = array(); if (isset($header['source'])) { $source_url = path_redirect_build_url($redirect['source'], $redirect['source_query']); + $source_url = $per_domain ? $domains[$redirect['source_domain']]['subdomain'] . '/' . $source_url : $source_url; + $redirect['source'] = $per_domain ? $domains[$redirect['source_domain']]['path'] . $redirect['source'] : $redirect['source']; $row['source'] = l($source_url, $redirect['source'], array('query' => $redirect['source_query'], 'alias' => TRUE)); } if (isset($header['redirect'])) { $redirect_url = path_redirect_build_url($redirect['redirect'], $redirect['query'], $redirect['fragment'], TRUE); + $redirect_url = $per_domain ? $domains[$redirect['redirect_domain']]['subdomain'] . '/' . $redirect_url : $redirect_url; + $redirect['redirect'] = $per_domain ? $domains[$redirect['redirect_domain']]['path'] . $redirect['redirect'] : $redirect['redirect']; $row['redirect'] = l($redirect_url, $redirect['redirect'], array('query' => $redirect['query'], 'fragment' => $redirect['fragment'])); } if (isset($header['type'])) { @@ -342,7 +351,7 @@ $form['source'] = array( '#type' => 'textfield', - '#title' => t('From'), + '#title' => t('From path'), '#description' => t("Enter an interal Drupal path or path alias to redirect (e.g. %example1 or %example2). Fragment anchors (e.g. %anchor) are not allowed.", array('%example1' => 'node/123', '%example2' => 'taxonomy/term/123', '%anchor' => '#anchor')), '#size' => 42, '#maxlength' => 255, @@ -352,9 +361,37 @@ '#autocomplete_path' => db_table_exists('watchdog') ? 'js/path_redirect/autocomplete_404' : '', '#element_validate' => array('path_redirect_validate_source_field'), ); + if (module_exists('domain') && variable_get('path_redirect_per_domain', 0)) { + $current_domain = domain_get_domain(); + + $domains = domain_domains(); + $domain_options = array(); + foreach ($domains as $id => $domain) { + $domain_options[$id] = $domain['subdomain']; + } + + $form['source_domain'] = array( + '#type' => 'select', + '#title' => t('From subdomain'), + '#default_value' => $redirect['domain_id'], + '#options' => $domain_options, + '#weight' => -0.1, + ); + $form['source']['#field_prefix'] = ''; + + $form['redirect_domain'] = array( + '#type' => 'select', + '#title' => t('To subdomain'), + '#default_value' => $redirect['domain_id'], + '#options' => $domain_options, + ); + } + else { + $form['source_domain'] = NULL; + } $form['redirect'] = array( '#type' => 'textfield', - '#title' => t('To'), + '#title' => t('To path'), '#maxlength' => 560, '#default_value' => path_redirect_build_url($redirect['redirect'], $redirect['query'], $redirect['fragment'], TRUE), '#required' => TRUE, @@ -448,6 +485,14 @@ '#default_value' => variable_get('path_redirect_auto_redirect', 1), '#access' => module_exists('path'), ); + if (module_exists('domain')) { + $form['path_redirect_per_domain'] = array( + '#type' => 'checkbox', + '#title' => t('Enable per-domain redirects.'), + '#default_value' => variable_get('path_redirect_per_domain', 0), + '#access' => module_exists('path'), + ); + } $form['path_redirect_purge_inactive'] = array( '#type' => 'select', '#title' => t('Discard redirects that have not been accessed for'), --- path_redirect.install Tue Dec 01 06:40:09 2009 +++ path_redirect.install Thu Dec 03 16:21:35 2009 @@ -24,6 +24,12 @@ 'not null' => TRUE, 'description' => 'The source path to redirect from.', ), + 'source_domain' => array( + 'type' => 'int', + 'size' => 'small', + 'not null' => FALSE, + 'description' => 'The domain ID for the source path.', + ), 'redirect' => array( 'type' => 'varchar', 'length' => 255, @@ -42,6 +48,12 @@ 'not null' => FALSE, 'description' => 'An internal page anchor append to the destination.', ), + 'redirect_domain' => array( + 'type' => 'int', + 'size' => 'small', + 'not null' => FALSE, + 'description' => 'The ID of the domain to redirect to.', + ), 'language' => array( 'description' => 'The language this redirect is for; if blank, the alias will be used for unknown languages.', 'type' => 'varchar', @@ -207,6 +219,16 @@ db_drop_unique_key($ret, 'path_redirect', 'path_language'); db_change_field($ret, 'path_redirect', 'path', 'source', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE)); db_add_unique_key($ret, 'path_redirect', 'source_language', array('source', 'language')); + return $ret; +} + +/** + * Add domain columns to table. + */ +function path_redirect_update_6104() { + $ret = array(); + db_add_field($ret, 'path_redirect', 'source_domain', array('type' => 'int', 'size' => 'small', 'not null' => FALSE, 'description' => 'The domain ID for the source path.')); + db_add_field($ret, 'path_redirect', 'redirect_domain', array('type' => 'int', 'size' => 'small', 'not null' => FALSE, 'description' => 'The ID of the domain to redirect to.')); return $ret; } --- path_redirect.module Wed Dec 02 11:54:25 2009 +++ path_redirect.module Fri Dec 04 11:43:31 2009 @@ -143,8 +143,15 @@ } if ($redirect) { + + $redirect_base_url = NULL; + if (isset($redirect['redirect_domain'])) { + $redirect_domain = domain_lookup($redirect['redirect_domain']); + $redirect_base_url = $redirect_domain['scheme'] . '://' . $redirect_domain['subdomain']; + } + // Create the absolute redirection URL. - $redirect['redirect_url'] = url($redirect['redirect'], array('query' => $redirect['query'], 'fragment' => $redirect['fragment'], 'absolute' => TRUE)); + $redirect['redirect_url'] = url($redirect['redirect'], array('query' => $redirect['query'], 'fragment' => $redirect['fragment'], 'absolute' => TRUE, 'base_url' => $redirect_base_url)); // Update the last used timestamp so that unused redirects can be purged. db_query("UPDATE {path_redirect} SET last_used = %d WHERE rid = %d", time(), $redirect['rid']); @@ -434,6 +441,11 @@ function path_redirect_load_by_source($source, $language = '', $query = array()) { $where = $query ? "(source = '%s' OR source LIKE '%s')" : "source = '%s'"; $args = ($query ? array($source, $source . '?%%') : array($source)) + array($language); + if (module_exists('domain') && variable_get('path_redirect_per_domain', 0)) { + $where .= ' AND source_domain = %d'; + $domain = domain_get_domain(); + $args[] = $domain['domain_id']; + } $rid_query = db_query("SELECT rid FROM {path_redirect} WHERE $where AND language IN ('%s', '') ORDER BY language DESC, source DESC, rid DESC", $args); $rids = array(); while ($rid = db_result($rid_query)) { @@ -484,7 +496,7 @@ } if ($conditions) { foreach ($conditions as $field => $value) { - if (!is_string($field) || !isset($schema['fields'][$field])) { + if (!(is_string($field) || is_numeric($field)) || !isset($schema['fields'][$field])) { continue; } //if ($field == 'langauge' && !is_array($value)) { @@ -496,7 +508,7 @@ $args = array_merge($args, $value); } else { - $conditions[$field] = "$field = " . dB_type_placeholder($type); + $conditions[$field] = "$field = " . db_type_placeholder($type); $args[] = $value; } }