Skip to content
Snippets Groups Projects
Commit 010e9e83 authored by Tim Steiner's avatar Tim Steiner
Browse files

Migration tool now supports migrating pages with <base> tags.

git-svn-id: file:///tmp/wdn_thm_drupal/trunk@295 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent 6379a806
No related branches found
No related tags found
No related merge requests found
...@@ -236,9 +236,16 @@ class Unl_Migration_Tool ...@@ -236,9 +236,16 @@ class Unl_Migration_Tool
$dom->loadHTML($html); $dom->loadHTML($html);
$navlinksNode = $dom->getElementById('navigation'); $navlinksNode = $dom->getElementById('navigation');
// Check to see if there's a base tag on this page.
$base_tags = $dom->getElementsByTagName('base');
$page_base = NULL;
if ($base_tags->length > 0) {
$page_base = $base_tags->item(0)->getAttribute('href');
}
$linkNodes = $navlinksNode->getElementsByTagName('a'); $linkNodes = $navlinksNode->getElementsByTagName('a');
foreach ($linkNodes as $linkNode) { foreach ($linkNodes as $linkNode) {
$this->_processLinks($linkNode->getAttribute('href'), '', '<menu>'); $this->_processLinks($linkNode->getAttribute('href'), '', $page_base, '<menu>');
} }
$navlinksUlNode = $navlinksNode->getElementsByTagName('ul')->item(0); $navlinksUlNode = $navlinksNode->getElementsByTagName('ul')->item(0);
...@@ -459,6 +466,13 @@ class Unl_Migration_Tool ...@@ -459,6 +466,13 @@ class Unl_Migration_Tool
$dom = new DOMDocument(); $dom = new DOMDocument();
$dom->loadHTML($html); $dom->loadHTML($html);
// Check to see if there's a base tag on this page.
$base_tags = $dom->getElementsByTagName('base');
$page_base = NULL;
if ($base_tags->length > 0) {
$page_base = $base_tags->item(0)->getAttribute('href');
}
$pageTitle = ''; $pageTitle = '';
$pageTitleNode = $dom->getElementById('pagetitle'); $pageTitleNode = $dom->getElementById('pagetitle');
if ($pageTitleNode) { if ($pageTitleNode) {
...@@ -493,25 +507,28 @@ class Unl_Migration_Tool ...@@ -493,25 +507,28 @@ class Unl_Migration_Tool
$linkNodes = $maincontentNode->getElementsByTagName('a'); $linkNodes = $maincontentNode->getElementsByTagName('a');
foreach ($linkNodes as $linkNode) { foreach ($linkNodes as $linkNode) {
$this->_processLinks($linkNode->getAttribute('href'), $path); $this->_processLinks($linkNode->getAttribute('href'), $path, $page_base);
} }
$linkNodes = $maincontentNode->getElementsByTagName('img'); $linkNodes = $maincontentNode->getElementsByTagName('img');
foreach ($linkNodes as $linkNode) { foreach ($linkNodes as $linkNode) {
$this->_processLinks($linkNode->getAttribute('src'), $path); $this->_processLinks($linkNode->getAttribute('src'), $path, $page_base);
} }
$this->_content[$path] = $maincontentarea; $this->_content[$path] = $maincontentarea;
$this->_pageTitles[$path] = $pageTitle; $this->_pageTitles[$path] = $pageTitle;
} }
private function _processLinks($originalHref, $path, $tag = NULL) private function _processLinks($originalHref, $path, $page_base = NULL, $tag = NULL)
{ {
if (substr($originalHref, 0, 1) == '#') { if (substr($originalHref, 0, 1) == '#') {
return; return;
} }
$href = $this->_makeLinkAbsolute($originalHref, $path); if (!$page_base) {
$path_base = $path;
}
$href = $this->_makeLinkAbsolute($originalHref, $page_base);
if (substr($href, 0, strlen($this->_baseUrl)) == $this->_baseUrl) { if (substr($href, 0, strlen($this->_baseUrl)) == $this->_baseUrl) {
$newPath = substr($href, strlen($this->_baseUrl)); $newPath = substr($href, strlen($this->_baseUrl));
...@@ -529,6 +546,15 @@ class Unl_Migration_Tool ...@@ -529,6 +546,15 @@ class Unl_Migration_Tool
private function _makeLinkAbsolute($href, $path) private function _makeLinkAbsolute($href, $path)
{ {
$path_parts = parse_url($path);
if ($path_parts['scheme']) {
$base_url = $path;
$path = '';
} else {
$base_url = $this->_baseUrl;
}
if (substr($path, -1) == '/') { if (substr($path, -1) == '/') {
$intermediatePath = $path; $intermediatePath = $path;
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment