Skip to content
Snippets Groups Projects
Commit 11df61b9 authored by Brett T Bieber's avatar Brett T Bieber
Browse files

Whitespace consistency, tabs to spaces

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x@153 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent b4a9df16
Branches
Tags
No related merge requests found
......@@ -108,12 +108,12 @@ class Unl_Migration_Tool
private function _migrate()
{
ini_set('memory_limit', -1);
// Parse the menu
$this->_processMenu();
// Process all of the pages on the site
ini_set('memory_limit', -1);
// Parse the menu
$this->_processMenu();
// Process all of the pages on the site
do {
set_time_limit(30);
......@@ -126,13 +126,13 @@ class Unl_Migration_Tool
// Fix any links to files that got moved to sites/<site>/files
foreach ($this->_hrefTransform as $path => &$transforms) {
if (array_key_exists('', $transforms)) {
unset($transforms['']);
}
if (array_key_exists('', $transforms)) {
unset($transforms['']);
}
foreach ($transforms as $oldPath => &$newPath) {
if (array_key_exists($newPath, $this->_hrefTransformFiles)) {
$newPath = $this->_hrefTransformFiles[$newPath];
}
if (array_key_exists($newPath, $this->_hrefTransformFiles)) {
$newPath = $this->_hrefTransformFiles[$newPath];
}
}
}
......@@ -140,12 +140,12 @@ class Unl_Migration_Tool
foreach ($this->_content as $path => $content) {
set_time_limit(30);
$hrefTransform = $this->_hrefTransform[$path];
if (is_array($hrefTransform)) {
$hrefTransform = $this->_hrefTransform[$path];
if (is_array($hrefTransform)) {
$content = strtr($content, $hrefTransform);
}
$pageTitle = $this->_pageTitles[$path];
}
$pageTitle = $this->_pageTitles[$path];
$this->_createPage($pageTitle, $content, $path, '' == $path);
}
......@@ -157,9 +157,9 @@ class Unl_Migration_Tool
private function _addSitePath($path)
{
if (($fragmentStart = strrpos($path, '#')) !== FALSE) {
if (($fragmentStart = strrpos($path, '#')) !== FALSE) {
$path = substr($path, 0, $fragmentStart);
}
}
$this->_siteMap[hash('SHA256', $path)] = $path;
}
......@@ -182,7 +182,7 @@ class Unl_Migration_Tool
private function _processMenu()
{
$content = $this->_getUrl($this->_baseUrl);
$content = $this->_getUrl($this->_baseUrl);
$html = $content['content'];
$dom = new DOMDocument();
......@@ -196,28 +196,28 @@ class Unl_Migration_Tool
$navlinksUlNode = $navlinksNode->getElementsByTagName('ul')->item(0);
foreach ($navlinksUlNode->childNodes as $primaryLinkLiNode) {
if (strtolower($primaryLinkLiNode->nodeName) != 'li') {
continue;
}
$primaryLinkNode = $primaryLinkLiNode->getElementsByTagName('a')->item(0);
$menuItem = array('text' => trim($primaryLinkNode->textContent),
'href' => $this->_makeLinkAbsolute($primaryLinkNode->getAttribute('href'), ''));
if (strtolower($primaryLinkLiNode->nodeName) != 'li') {
continue;
}
$primaryLinkNode = $primaryLinkLiNode->getElementsByTagName('a')->item(0);
$menuItem = array('text' => trim($primaryLinkNode->textContent),
'href' => $this->_makeLinkAbsolute($primaryLinkNode->getAttribute('href'), ''));
$childLinksUlNode = $primaryLinkLiNode->getElementsByTagName('ul')->item(0);
if (!$childLinksUlNode) {
$childLinksUlNode = $primaryLinkLiNode->getElementsByTagName('ul')->item(0);
if (!$childLinksUlNode) {
$this->_menu[] = $menuItem;
continue;
}
$childMenu = array();
foreach ($childLinksUlNode->childNodes as $childLinkLiNode) {
if (strtolower($childLinkLiNode->nodeName) != 'li') {
continue;
}
$childLinkNode = $childLinkLiNode->getElementsByTagName('a')->item(0);
$childMenu[] = array('text' => trim($childLinkNode->textContent),
'href' => $this->_makeLinkAbsolute($childLinkNode->getAttribute('href'), ''));
}
$menuItem['children'] = $childMenu;
continue;
}
$childMenu = array();
foreach ($childLinksUlNode->childNodes as $childLinkLiNode) {
if (strtolower($childLinkLiNode->nodeName) != 'li') {
continue;
}
$childLinkNode = $childLinkLiNode->getElementsByTagName('a')->item(0);
$childMenu[] = array('text' => trim($childLinkNode->textContent),
'href' => $this->_makeLinkAbsolute($childLinkNode->getAttribute('href'), ''));
}
$menuItem['children'] = $childMenu;
$this->_menu[] = $menuItem;
}
......@@ -238,85 +238,85 @@ class Unl_Migration_Tool
'weight' => $primaryWeights++
);
$href = $primaryMenu['href'];
if (substr($href, 0, strlen($this->_baseUrl)) == $this->_baseUrl) {
$path = substr($href, strlen($this->_baseUrl));
if (!$path) {
$path = '';
}
if (substr($href, 0, strlen($this->_baseUrl)) == $this->_baseUrl) {
$path = substr($href, strlen($this->_baseUrl));
if (!$path) {
$path = '';
}
if ($fragmentPos = strrpos($path, '#') !== FALSE) {
$item['options']['fragment'] = substr($path, $fragmentPos + 1);
$path = substr($path, 0, $fragmentPos);
}
if (substr($path, -1) == '/') {
$path = substr($path, 0, -1);
$path = substr($path, 0, -1);
}
$nodeId = array_search($path, $this->_nodeMap, TRUE);
if ($nodeId) {
$item['link_path'] = 'node/' . $nodeId;
}
} else {
$nodeId = array_search($path, $this->_nodeMap, TRUE);
if ($nodeId) {
$item['link_path'] = 'node/' . $nodeId;
}
} else {
$item['link_path'] = $href;
}
if ($item['link_path']) {
}
if ($item['link_path']) {
menu_link_save($item);
$this->_log('Created menu item "' . $item['link_title'] . '" linked to ' . $item['link_path'] . '.');
} else {
$this->_log('Error: could not find a node to link to the ' . $item['link_title'] . ' menu item.');
continue;
}
} else {
$this->_log('Error: could not find a node to link to the ' . $item['link_title'] . ' menu item.');
continue;
}
if (!array_key_exists('children', $primaryMenu)) {
continue;
continue;
}
$plid = $item['mlid'];
$parentTitle = $item['link_title'];
$childWeights = 1;
foreach ($primaryMenu['children'] as $childMenu) {
$item = array(
'menu_name' => 'main-menu',
'link_title' => $childMenu['text'],
'link_path' => '',
'plid' => $plid,
$item = array(
'menu_name' => 'main-menu',
'link_title' => $childMenu['text'],
'link_path' => '',
'plid' => $plid,
'weight' => $childWeights++
);
$href = $childMenu['href'];
if (substr($href, 0, strlen($this->_baseUrl)) == $this->_baseUrl) {
$path = substr($href, strlen($this->_baseUrl));
if (!$path) {
$path = '';
}
if (($fragmentPos = strrpos($path, '#')) !== FALSE) {
);
$href = $childMenu['href'];
if (substr($href, 0, strlen($this->_baseUrl)) == $this->_baseUrl) {
$path = substr($href, strlen($this->_baseUrl));
if (!$path) {
$path = '';
}
if (($fragmentPos = strrpos($path, '#')) !== FALSE) {
$item['options']['fragment'] = substr($path, $fragmentPos + 1);
$path = substr($path, 0, $fragmentPos);
}
if (substr($path, -1) == '/') {
$path = substr($path, 0, -1);
}
$path = substr($path, 0, $fragmentPos);
}
if (substr($path, -1) == '/') {
$path = substr($path, 0, -1);
}
$nodeId = array_search($path, $this->_nodeMap, TRUE);
if ($nodeId) {
$item['link_path'] = 'node/' . $nodeId;
}
} else {
$item['link_path'] = $href;
}
if ($item['link_path']) {
menu_link_save($item);
} else {
$item['link_path'] = $href;
}
if ($item['link_path']) {
menu_link_save($item);
$this->_log('Created menu item "' . $parentTitle . ' / ' . $item['link_title'] . '" linked to ' . $item['link_path'] . '.');
} else {
$this->_log('Error: could not find a node to link to the "' . $parentTitle . ' / ' . $item['link_title'] . '" menu.');
}
} else {
$this->_log('Error: could not find a node to link to the "' . $parentTitle . ' / ' . $item['link_title'] . '" menu.');
}
}
}
}
private function _processPage($path)
{
$this->_addProcessedPage($path);
$fullPath = $this->_baseUrl . $path;
$this->_addProcessedPage($path);
$fullPath = $this->_baseUrl . $path;
$url = $this->_baseUrl . $path;
$startToken = '<!-- InstanceBeginEditable name="maincontentarea" -->';
$pageTitleStartToken = '<!-- InstanceBeginEditable name="pagetitle" -->';
......@@ -325,26 +325,26 @@ class Unl_Migration_Tool
$data = $this->_getUrl($url);
if (!$data['content']) {
$this->_log('The file at ' . $fullPath . ' was empty! Ignoring.');
return;
return;
}
if ($data['lastModified']) {
$this->_lastModifications[$path] = $data['lastModified'];
$this->_lastModifications[$path] = $data['lastModified'];
}
if (strpos($data['contentType'], 'html') === FALSE) {
if (!$data['contentType']) {
$this->_log('The file type at ' . $fullPath . ' was not specified. Ignoring.');
return;
}
drupal_mkdir('public://' . dirname($path), NULL, TRUE);
$file = file_save_data($data['content'], 'public://' . $path, FILE_EXISTS_REPLACE);
$this->_hrefTransformFiles[$path] = file_directory_path() . '/' . $path;
return;
if (!$data['contentType']) {
$this->_log('The file type at ' . $fullPath . ' was not specified. Ignoring.');
return;
}
drupal_mkdir('public://' . dirname($path), NULL, TRUE);
$file = file_save_data($data['content'], 'public://' . $path, FILE_EXISTS_REPLACE);
$this->_hrefTransformFiles[$path] = file_directory_path() . '/' . $path;
return;
}
$html = $data['content'];
if (preg_match('/charset=(.*);?/', $data['contentType'], $matches)) {
$charset = $matches[1];
$html = iconv($charset, 'UTF-8', $html);
$charset = $matches[1];
$html = iconv($charset, 'UTF-8', $html);
}
$contentStart = strpos($html, $startToken);
......@@ -364,22 +364,22 @@ class Unl_Migration_Tool
$pageTitle = '';
$pageTitleNode = $dom->getElementById('pagetitle');
if ($pageTitleNode) {
$pageTitleH2Nodes = $pageTitleNode->getElementsByTagName('h2');
if ($pageTitleH2Nodes->length > 0) {
$pageTitle = $pageTitleH2Nodes->item(0)->textContent;
}
$pageTitleH2Nodes = $pageTitleNode->getElementsByTagName('h2');
if ($pageTitleH2Nodes->length > 0) {
$pageTitle = $pageTitleH2Nodes->item(0)->textContent;
}
}
if (!$pageTitle) {
$titleText = '';
$titleNodes = $dom->getElementsByTagName('title');
if ($titleNodes->length > 0) {
$titleText = $titleNodes->item(0)->textContent;
}
$titleParts = explode('|', $titleText);
if (count($titleParts) > 2) {
$pageTitle = trim(array_pop($titleParts));
}
$titleText = '';
$titleNodes = $dom->getElementsByTagName('title');
if ($titleNodes->length > 0) {
$titleText = $titleNodes->item(0)->textContent;
}
$titleParts = explode('|', $titleText);
if (count($titleParts) > 2) {
$pageTitle = trim(array_pop($titleParts));
}
}
if (!$pageTitle) {
......@@ -390,7 +390,7 @@ class Unl_Migration_Tool
$maincontentNode = $dom->getElementById('maincontent');
if (!$maincontentNode) {
$this->_log('The file at ' . $fullPath . ' has no valid maincontentarea. Ignoring.');
return;
return;
}
$linkNodes = $maincontentNode->getElementsByTagName('a');
......@@ -409,14 +409,14 @@ class Unl_Migration_Tool
private function _processLinks($originalHref, $path)
{
if (substr($originalHref, 0, 1) == '#') {
return;
}
if (substr($originalHref, 0, 1) == '#') {
return;
}
$href = $this->_makeLinkAbsolute($originalHref, $path);
if (substr($href, 0, strlen($this->_baseUrl)) == $this->_baseUrl) {
$newPath = substr($href, strlen($this->_baseUrl));
if ($newPath === FALSE) {
$newPath = '';
$newPath = '';
}
$this->_hrefTransform[$path][$originalHref] = $newPath;
$this->_addSitePath($newPath);
......@@ -428,11 +428,11 @@ class Unl_Migration_Tool
if (substr($path, -1) == '/') {
$intermediatePath = $path;
} else {
$intermediatePath = dirname($path);
$intermediatePath = dirname($path);
}
if ($intermediatePath == '.') {
$intermediatePath = '';
}
if ($intermediatePath == '.') {
$intermediatePath = '';
}
if (strlen($intermediatePath) > 0 && substr($intermediatePath, -1) != '/') {
$intermediatePath .= '/';
}
......@@ -447,10 +447,10 @@ class Unl_Migration_Tool
$baseParts = parse_url($this->_baseUrl);
$absoluteUrl = $baseParts['scheme'] . '://' . $baseParts['host'] . $parts['path'];
if ($parts['fragment']) {
$absoluteUrl .= '#' . $parts['fragment'];
$absoluteUrl .= '#' . $parts['fragment'];
}
} else if (substr($href, 0, 1) == '#') {
$absoluteUrl = $this->_baseUrl . $path . $href;
$absoluteUrl = $this->_baseUrl . $path . $href;
} else {
$absoluteUrl = $this->_baseUrl . $intermediatePath . $href;
}
......@@ -473,9 +473,9 @@ class Unl_Migration_Tool
{
if (substr($alias, -1) == '/') {
$alias = substr($alias, 0, -1);
}
$alias = substr($alias, 0, -1);
}
$node = new StdClass();
$node->uid = $GLOBALS['user']->uid;
$node->type = 'page';
......@@ -505,16 +505,16 @@ class Unl_Migration_Tool
'created' => $mtime,
'changed' => $mtime
);
$result = db_update('node')
->fields($mtimes)
->condition('nid', $node->nid)
->execute();
$result = db_update('node')
->fields($mtimes)
->condition('nid', $node->nid)
->execute();
}
$this->_nodeMap[$node->nid] = $alias;
if ($makeFrontPage) {
variable_set('site_frontpage', 'node/' . $node->nid);
variable_set('site_frontpage', 'node/' . $node->nid);
}
$this->_log('Created page "' . $title . '" with node id ' . $node->nid . ' at ' . $alias . '.');
......@@ -523,51 +523,51 @@ class Unl_Migration_Tool
private function _getUrl($url)
{
$url = strtr($url, array(' ' => '%20'));
curl_setopt($this->_curl, CURLOPT_URL, $url);
curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->_curl, CURLOPT_HEADER, TRUE);
$data = curl_exec($this->_curl);
$meta = curl_getinfo($this->_curl);
curl_setopt($this->_curl, CURLOPT_URL, $url);
curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->_curl, CURLOPT_HEADER, TRUE);
$data = curl_exec($this->_curl);
$meta = curl_getinfo($this->_curl);
$rawHeaders = substr($data, 0, $meta['header_size']);
$rawHeaders = trim($rawHeaders);
$rawHeaders = explode("\n", $rawHeaders);
array_shift($rawHeaders);
$headers = array();
foreach ($rawHeaders as $rawHeader) {
$splitPos = strpos($rawHeader, ':');
$headerKey = substr($rawHeader, 0, $splitPos);
$headerValue = substr($rawHeader, $splitPos+1);
$headers[$headerKey] = trim($headerValue);
$splitPos = strpos($rawHeader, ':');
$headerKey = substr($rawHeader, 0, $splitPos);
$headerValue = substr($rawHeader, $splitPos+1);
$headers[$headerKey] = trim($headerValue);
}
$content = substr($data, $meta['header_size']);
if ($meta['http_code'] == 301) {
$location = $headers['Location'];
$path = substr($location, strlen($this->_baseUrl));
$this->_addSitePath($path);
$this->_log('Found a redirect from ' . $url . ' to ' . $location . '. Some links may need to be updated.');
if ($meta['http_code'] == 301) {
$location = $headers['Location'];
$path = substr($location, strlen($this->_baseUrl));
$this->_addSitePath($path);
$this->_log('Found a redirect from ' . $url . ' to ' . $location . '. Some links may need to be updated.');
return FALSE;
} else if ($meta['http_code'] != 200) {
$this->_log('Error: HTTP ' . $meta['http_code'] . ' while fetching ' . $url . '. Possible dead link.');
return FALSE;
}
$data = array(
} else if ($meta['http_code'] != 200) {
$this->_log('Error: HTTP ' . $meta['http_code'] . ' while fetching ' . $url . '. Possible dead link.');
return FALSE;
}
$data = array(
'content' => $content,
'contentType' => $meta['content_type'],
);
if ($this->_frontierPath) {
$mtime = $this->_getModifiedDate($url);
if ($mtime) {
$data['lastModified'] = $mtime;
} else if ($headers['Last-Modified']) {
$data['lastModified'] = strtotime($headers['Last-Modified']);
}
}
if ($this->_frontierPath) {
$mtime = $this->_getModifiedDate($url);
if ($mtime) {
$data['lastModified'] = $mtime;
} else if ($headers['Last-Modified']) {
$data['lastModified'] = strtotime($headers['Last-Modified']);
}
}
return $data;
}
......@@ -575,14 +575,14 @@ class Unl_Migration_Tool
private function _getModifiedDate($url)
{
if (!$this->_frontierConnect()) {
return NULL;
return NULL;
}
$ftpPath = $this->_frontierPath . substr($url, strlen($this->_baseUrl));
if (substr($ftpPath, -1) == '/') {
$ftpPath .= 'index.shtml';
}
$ftpPath = $this->_frontierPath . substr($url, strlen($this->_baseUrl));
if (substr($ftpPath, -1) == '/') {
$ftpPath .= 'index.shtml';
}
$files = ftp_rawlist($this->_frontier, $ftpPath);
$mtime = substr($files[0], 43, 12);
$mtime = strtotime($mtime);
......@@ -591,20 +591,20 @@ class Unl_Migration_Tool
private function _frontierConnect()
{
if (!$this->_frontierPath) {
return NULL;
}
if (!$this->_frontier) {
$this->_frontier = ftp_ssl_connect('frontier.unl.edu');
//TODO: make this a login that only has read access to everything.
$login = ftp_login($this->_frontier, $this->_frontierUser, $this->_frontierPass);
if (!$login) {
$this->_frontier = NULL;
$this->_log('Error: could not connect to frontier with user ' . $this->_frontierUser . '.');
}
}
return $this->_frontier;
if (!$this->_frontierPath) {
return NULL;
}
if (!$this->_frontier) {
$this->_frontier = ftp_ssl_connect('frontier.unl.edu');
//TODO: make this a login that only has read access to everything.
$login = ftp_login($this->_frontier, $this->_frontierUser, $this->_frontierPass);
if (!$login) {
$this->_frontier = NULL;
$this->_log('Error: could not connect to frontier with user ' . $this->_frontierUser . '.');
}
}
return $this->_frontier;
}
private function _frontierScan($path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment