Skip to content

Commit

Permalink
Improve support for sites that have multiple domains
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopetkov committed Oct 25, 2020
1 parent 54957af commit 64fe63b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions classes/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static function updateIndex(): void
{
$app = App::get();

$paths = null;
$urls = null;
$robotsURL = $app->urls->get('/robots.txt');
$result = self::makeRequest($robotsURL);
if ($result['status'] === 200) {
Expand All @@ -47,7 +47,7 @@ static function updateIndex(): void
$dom->loadXML($result['content']);
$elements = $dom->getElementsByTagName('url');
if ($elements->length > 0) {
$paths = [];
$urls = [];
foreach ($elements as $element) {
$lastModDate = '';
$lastmodElements = $element->getElementsByTagName('lastmod');
Expand All @@ -56,8 +56,7 @@ static function updateIndex(): void
}
$locationElements = $element->getElementsByTagName('loc');
if ($locationElements->length === 1) {
$locationPath = str_replace($app->request->base, '', $locationElements->item(0)->nodeValue);
$paths[$locationPath] = $lastModDate;
$urls[$locationElements->item(0)->nodeValue] = $lastModDate;
}
}
}
Expand All @@ -66,9 +65,21 @@ static function updateIndex(): void
}
}
}
if ($paths === null) {
if ($urls === null) {
return;
}
// Find the base URL. Dont get if from $app->request->base because the site may be served by multiple domains
$shortestURL = null;
foreach ($urls as $url => $lastModDate) {
if ($shortestURL === null || strlen($url) < strlen($shortestURL)) {
$shortestURL = $url;
}
}
$baseURL = rtrim($shortestURL, '\/');
$paths = [];
foreach ($urls as $url => $lastModDate) {
$paths[str_replace($baseURL, '', $url)] = $lastModDate;
}

$data = self::getData();
$hasChange = false;
Expand Down

0 comments on commit 64fe63b

Please sign in to comment.