· 7 years ago · Oct 19, 2018, 11:16 PM
1diff --git a/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/elc_domain.install b/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/elc_domain.install
2index e2cf397..a010dbb 100644
3--- a/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/elc_domain.install
4+++ b/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/elc_domain.install
5@@ -1,4 +1,5 @@
6 <?php
7+
8 /**
9 * @file
10 * Installation routines for the ELC domain module.
11@@ -10,4 +11,27 @@
12 function elc_domain_enable() {
13 module_load_include('inc', 'elc_domain', 'includes/domain.setup');
14 elc_domain_setup_domain_configuration();
15+ domain_bootstrap_register();
16+}
17+
18+/**
19+ * Implements hook_update_N().
20+ */
21+function elc_domain_update_7000(&$sandbox) {
22+ $msg = array();
23+
24+ if (!module_enable(array('domain_alias'))) {
25+ throw new DrupalUpdateException('The domain_alias module was not found.');
26+ } else {
27+ $msg[] = t('The domain_alias module was installed/enabled.');
28+ }
29+
30+ if (!function_exists('domain_bootstrap_register')) {
31+ throw new DrupalUpdateException('The domain_bootstrap_register function was not found.');
32+ } else {
33+ domain_bootstrap_register();
34+ $msg[] = t('The elc_domain module has been registered with the domain bootstrap process.');
35+ }
36+
37+ return implode("\n<br />\n", $msg);
38 }
39diff --git a/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/elc_domain.module b/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/elc_domain.module
40index f402788..0a9d8db 100644
41--- a/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/elc_domain.module
42+++ b/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/elc_domain.module
43@@ -1,4 +1,5 @@
44 <?php
45+
46 /**
47 * @file
48 * Domain module integration for localized Drupal sites.
49@@ -76,4 +77,35 @@ function elc_domain_domain_warnings_alter(&$forms) {
50 if (!user_access('elc view domain message')) {
51 $forms = array();
52 }
53-}
54\ No newline at end of file
55+}
56+
57+/**
58+ * Implements hook_domain_bootstrap_lookup().
59+ *
60+ * This function looks for a site configuration variable named elc_domain_aliases, and attempts to match
61+ * the current host name with the aliases listed in that array. If it hits upon a match, and that match
62+ * is different than the currently active domain, then it returns a new domain array. If you simply
63+ * return the same domain_id as the currently active domain, the domain module returns an error.
64+ *
65+ * @param $domain
66+ * An array containing current domain (host) name and
67+ * the results of lookup against {domain} table.
68+ *
69+ * @return
70+ * An array containing at least a valid domain_id.
71+ */
72+function elc_domain_domain_bootstrap_lookup($domain) {
73+ global $conf;
74+
75+ if (isset($conf['elc_domain_aliases']) && count($conf['elc_domain_aliases']) > 0) {
76+ list($host, ) = explode(':', $domain['subdomain']);
77+ foreach ($conf['elc_domain_aliases'] as $machine_name => $hosts) {
78+ if (in_array($host, $hosts)) {
79+ $d = domain_machine_name_load($machine_name);
80+ if (isset($d['domain_id']) && $d['domain_id'] != $domain['domain_id']) {
81+ return $d;
82+ }
83+ }
84+ }
85+ }
86+}
87diff --git a/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/includes/bootstrap.inc b/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/includes/bootstrap.inc
88index d0a0a15..d4a5d36 100644
89--- a/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/includes/bootstrap.inc
90+++ b/drupal/drupal-7.9/sites/all/modules/custom/elc_domain/includes/bootstrap.inc
91@@ -29,6 +29,7 @@ function _elc_domain_directory_aliases(&$sites = NULL) {
92 * Add personal site directory aliases to an existing $sites array
93 */
94 function _elc_domain_personal_site_directory_aliases(&$sites = NULL, $username) {
95+ $username = &drupal_static(__FUNCTION__, $username);
96 if (empty($username)) {
97 return;
98 }
99@@ -42,14 +43,52 @@ function _elc_domain_personal_site_directory_aliases(&$sites = NULL, $username)
100 if ($environment != 'eng') {
101 continue;
102 }
103- foreach ($locale as $domains) {
104- array_walk($domains, create_function('&$v, $k', '$v = preg_replace(\'/\.eng\./\', \'.' . $username . '.eng.\', $v);'));
105- foreach ($domains as $domain) {
106- $sites[$domain] = $brand;
107+ foreach ($locale as $urls) {
108+ _elc_domain_substitute_user_domain_alias($urls, $username);
109+ foreach ($urls as $url) {
110+ $sites[$url] = $brand;
111+ }
112+ }
113+ }
114+ }
115+}
116+
117+/**
118+ * Retrieve domain aliases for each brand
119+ */
120+function _elc_domain_get_domain_aliases($key) {
121+ $domains = _elc_domain_retrieve_master_domain_file();
122+ foreach ($domains as $brand => $environments) {
123+ foreach ($environments as $environment => $locale) {
124+ foreach ($locale as $initial => $urls) {
125+ // Create a variable to test against the desired key
126+ $key_test = implode('_', array($brand, $environment, $initial));
127+
128+ if ($key == $key_test) {
129+ // If a sites.local.php files exists, then the directory alias function should be called, and thus we have a static $username variable available
130+ $username = &drupal_static('_elc_domain_personal_site_directory_aliases');
131+
132+ // If a username does exist, then include the tokenized URLs into the list of domains
133+ if (!empty($username)) {
134+ $tmp = $urls;
135+ _elc_domain_substitute_user_domain_alias($urls, $username, $environment);
136+ $urls = array_merge($urls, $tmp);
137+ }
138+
139+ return array_unique($urls);
140 }
141 }
142 }
143 }
144+
145+ return array();
146+}
147+
148+/**
149+ * This is a function to perform URL pattern substitution - mainly used for personal server setup
150+ */
151+function _elc_domain_substitute_user_domain_alias(&$urls, $alias, $env = 'eng') {
152+ return array_walk($urls, create_function('&$v, $k', '$v = preg_replace(\'/\.eng\./\', \'.' . $alias . '.' . $env . '.\', $v);'));
153 }
154
155 /**