protected function AcquiaPurgeHostingInfo::domainsAddFromSitesPhp in Acquia Purge 7
Source domains from sites/sites.php by reverse parsing it.
@warning The way the sites/sites.php array was designed was to make it a lookup map with the current active URI as lookup resource, it makes that relatively easy to do. However, we want to get all domains that point to the currently chosen site. As the array keys are in the format of '<port>.<domain>.<path>' this is relatively hackish.
1 call to AcquiaPurgeHostingInfo::domainsAddFromSitesPhp()
- AcquiaPurgeHostingInfo::domains in lib/
AcquiaPurgeHostingInfo.php - Initialize $this->domains.
File
- lib/
AcquiaPurgeHostingInfo.php, line 246 - Contains AcquiaPurgeHostingInfo.
Class
- AcquiaPurgeHostingInfo
- Provides technical information accessors for the Acquia Cloud environment.
Code
protected function domainsAddFromSitesPhp() {
$sitesphpskippath = _acquia_purge_variable('acquia_purge_sphpskippath');
$stripports = _acquia_purge_variable('acquia_purge_stripports');
$sitedir = str_replace('sites/', '', conf_path());
$tlds = array();
// Only interpret the $sites array if the file sites/sites.php exists.
if (!file_exists('sites/sites.php')) {
return;
}
// Define the full list of TLD's we have to check against to determine if a
// embedded domain name in '<port>.<domain>.<path>' seems valid for us.
include drupal_get_path('module', 'acquia_purge') . '/acquia_purge.tlds.inc';
// Include the file which will (re)propagate the $sites array for us.
$sites = array();
include 'sites/sites.php';
// Protect ourselves against badly written code inside sites.php.
if (!isset($sites) || empty($sites)) {
return;
}
// Iterate and validate each record in the resulting $sites array.
foreach ($sites as $site => $directory) {
// Skip those that point to a different site directory then we are on.
if ($directory != $sitedir) {
continue;
}
// Split $site that can be defined in the form of '<port>.<domain>.<path>'.
$site = explode('.', $site);
// Strip TCP port's in '<port>....'.
if (is_numeric($site[0]) && in_array((int) $site[0], $stripports)) {
unset($site[0]);
}
// Every record in sites.php that has a TLD in the middle of it, are assumed
// to be in the '<domain>.<path>' format, which means we have a path we
// really need to get rid of. When the last octet isn't in $tlds, we
// assume this scenario to be a reality and start scanning each octet. If
// on of the middle octets then matches a valid TLD, we rewrite the domain.
if (!in_array(end($site), $tlds)) {
if ($sitesphpskippath) {
continue;
}
else {
$replacement = array();
foreach ($site as $octet) {
$replacement[] = $octet;
if (in_array($octet, $tlds) && $octet !== end($site)) {
$site = $replacement;
break;
}
}
}
}
// What's left should be a 99.99% correct domain name we want to see purged.
$this->domains[] = implode('.', $site);
}
}