You are here

protected function WordPressItemMigration::fixLocalLinks in WordPress Migrate 7

Same name and namespace in other branches
  1. 7.2 wordpress_item.inc \WordPressItemMigration::fixLocalLinks()

Replace any hrefs to links of the form http://example.wordpress.com/?=23 to local links to a node.

Parameters

string $body:

2 calls to WordPressItemMigration::fixLocalLinks()
WordPressItemMigration::prepareRow in ./wordpress_item.inc
Data manipulations to be performed before the migrate module applies mappings.
WordPressPage::postImport in ./wordpress_item.inc
Called after completion of the page migration. We review any nodes with links that couldn't be resolved at migration time (presumably because they refer to nodes not yet migrated) and see if we can resolve them now.

File

./wordpress_item.inc, line 500
Support for migrating posts and pages from a WordPress blog into Drupal.

Class

WordPressItemMigration
Intermediate Migration class, implementing behavior common across different types (post_type) of items.

Code

protected function fixLocalLinks($body) {
  $this->linksNeedFixing = FALSE;
  $site_url = reset($this->source
    ->getXml()
    ->xpath('//channel/link'));
  $pattern = '|href="' . $site_url . '/\\?p=([0-9]+)"|i';
  $body = preg_replace_callback($pattern, array(
    $this,
    'replaceLinks',
  ), $body);
  return $body;
}