From 010e9e8367a41c8e635cf2554d64cbf739c9b097 Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Fri, 5 Nov 2010 16:42:15 +0000 Subject: [PATCH] Migration tool now supports migrating pages with <base> tags. git-svn-id: file:///tmp/wdn_thm_drupal/trunk@295 20a16fea-79d4-4915-8869-1ea9d5ebf173 --- sites/all/modules/unl/unl_migration.php | 36 +++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/sites/all/modules/unl/unl_migration.php b/sites/all/modules/unl/unl_migration.php index 39c6f911..9cabb8b2 100644 --- a/sites/all/modules/unl/unl_migration.php +++ b/sites/all/modules/unl/unl_migration.php @@ -236,9 +236,16 @@ class Unl_Migration_Tool $dom->loadHTML($html); $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'); foreach ($linkNodes as $linkNode) { - $this->_processLinks($linkNode->getAttribute('href'), '', '<menu>'); + $this->_processLinks($linkNode->getAttribute('href'), '', $page_base, '<menu>'); } $navlinksUlNode = $navlinksNode->getElementsByTagName('ul')->item(0); @@ -459,6 +466,13 @@ class Unl_Migration_Tool $dom = new DOMDocument(); $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 = ''; $pageTitleNode = $dom->getElementById('pagetitle'); if ($pageTitleNode) { @@ -493,25 +507,28 @@ class Unl_Migration_Tool $linkNodes = $maincontentNode->getElementsByTagName('a'); foreach ($linkNodes as $linkNode) { - $this->_processLinks($linkNode->getAttribute('href'), $path); + $this->_processLinks($linkNode->getAttribute('href'), $path, $page_base); } $linkNodes = $maincontentNode->getElementsByTagName('img'); foreach ($linkNodes as $linkNode) { - $this->_processLinks($linkNode->getAttribute('src'), $path); + $this->_processLinks($linkNode->getAttribute('src'), $path, $page_base); } $this->_content[$path] = $maincontentarea; $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) == '#') { 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) { $newPath = substr($href, strlen($this->_baseUrl)); @@ -529,6 +546,15 @@ class Unl_Migration_Tool 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) == '/') { $intermediatePath = $path; } else { -- GitLab